#include "stdafx.h"
#include "grouptybase.h"
#include "sp_drawView.h"
#include "HmLayer.h"
#include "yc.h"
#include "HuaMian.h"
#include <Shlwapi.h>
#include "TysView.h"
#include "NewGroupPage.h"
#include "dll_draw.h"
#include "DlgGroupScale.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_SERIAL(CGroupTyBase,CTyBase, 0)
float CGroupTyBase::c_xScale=1.0;
float CGroupTyBase::c_yScale=1.0;
BOOL CGroupTyBase::c_bText=true;
BOOL CGroupTyBase::c_bBmp=false;
CGroupTyBase::CGroupTyBase(int vId/*=0*/,CHMLayer* pLayer/*=NULL*/)
:CTyBase(vId,pLayer)
{
m_bCreating=false;
m_ArrChilds.RemoveAll();
m_LayerID=0;
memset(&m_groupTypeInfo,0,sizeof(SGroupInfo));
memset(&m_groupRtuInfo,0,sizeof(S_GROUPRTU));
for (int i=0;i<MAX_GRP_RTU_NUM;i++)
{
m_groupRtuInfo.rtu[i].node_id=-1;
m_groupRtuInfo.rtu[i].line_id=-1;
m_groupRtuInfo.rtu[i].rtu_id=-1;
m_groupRtuInfo.rtu[i].rtu_type=-1;
}
m_xScale=1;
m_yScale=1;
m_bText=c_bText;
m_bBmp=c_bBmp;
}
DRAW_TY CGroupTyBase::GetTyType()
{
return tyGroup;
}
CGroupTyBase::CGroupTyBase(CTyBaseList* pList)
:CTyBase(0,NULL)
{
m_LayerID=0;
m_bCreating=false;
m_ArrChilds.RemoveAll();
m_dwFlag=m_dwFlag|0x1;
memset(&m_groupTypeInfo,0,sizeof(SGroupInfo));
memset(&m_groupRtuInfo,0,sizeof(S_GROUPRTU));
if (pList==NULL) return;
BOOL bRoot;
POSITION pos=pList->GetHeadPosition();
while (pos!=NULL)
{
CTyBase* pTy=pList->GetNext(pos);
pTy->IsGroupTy(bRoot);
if (bRoot==true)
{
assert(false);
continue;
}
AddTy(pTy);
}
m_xScale=1;
m_yScale=1;
m_bText=c_bText;
m_bBmp=c_bBmp;
}
CGroupTyBase::CGroupTyBase(LPCSTR filepath)
:CTyBase(0,NULL)
{
m_bCreating=false;
m_ArrChilds.RemoveAll();
m_LayerID=0;
m_dwFlag=m_dwFlag| 0x1;
memset(&m_groupTypeInfo,0,sizeof(SGroupInfo));
memset(&m_groupRtuInfo,0,sizeof(S_GROUPRTU));
m_xScale=1;
m_yScale=1;
m_bText=c_bText;
m_bBmp=c_bBmp;
if (filepath==NULL) return;
if (PathFileExists(filepath)==false) return;
CFileException fe;
CFile vFile;
char path_buffer[_MAX_PATH];
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
_splitpath(filepath,drive,dir,fname,ext);
if (!vFile.Open(filepath, CFile::modeRead|CFile::shareDenyWrite, &fe))
return;
TRY
{
CWaitCursor wait;
SaveGroupFile(&vFile,false);
if (stricmp(m_groupTypeInfo.Name,fname)!=0)
{
fname[63]=0x0;
strcpy(m_groupTypeInfo.Name,fname);
}
m_Id=0;
int count=m_ArrChilds.GetCount();
for (int i=0;i<count;i++)
{
tagShowProp* pProp=m_ArrChilds.GetAt(i);
assert(pProp!=NULL);
if (pProp==NULL) continue;
if (pProp->pChildTy==NULL) continue;
pProp->pChildTy->m_Id=0;
}
vFile.Close();
}
CATCH_ALL(e)
{
vFile.Close();
}
END_CATCH_ALL
}
CGroupTyBase::~CGroupTyBase(void)
{
RemoveSelf();
int count=m_ArrChilds.GetCount();
for (int i=0;i<count;i++)
{
tagShowProp* pProp=m_ArrChilds.GetAt(i);
assert(pProp!=NULL);
if (pProp==NULL) continue;
if (pProp->pChildTy==NULL) continue;
delete pProp->pChildTy;
delete pProp;
}
m_ArrChilds.RemoveAll();
}
void CGroupTyBase::DisMissGroup(void) //组合图元拆卸
{
if (m_pHMLayer!=NULL)
m_pHMLayer->OnRemoveTy(this);
m_dwFlag=m_dwFlag&0xfffffffe;
int count=m_ArrChilds.GetCount();
for (int i=0;i<count;i++)
{
tagShowProp* pProp=m_ArrChilds.GetAt(i);
assert(pProp!=NULL);
if (pProp==NULL) continue;
if (pProp->pChildTy==NULL) continue;
pProp->pChildTy->DisMissGroup();
delete pProp;
}
m_ArrChilds.RemoveAll();
}
//查找某个子图元的位置,通过子图元的指针
int CGroupTyBase::FindChildTy(CTyBase * pTy)
{
int ret=-1;
int count=m_ArrChilds.GetCount();
for (int i=0;i<count;i++)
{
tagShowProp* pProp=m_ArrChilds.GetAt(i);
assert(pProp!=NULL);
if (pProp==NULL) continue;
if (pTy==pProp->pChildTy)
{
ret=i;
break;
}
}
return ret;
}
//查找某个子图元,通过子图元的显示类型
CTyBase * CGroupTyBase::FindChildTyObj(int vShowPropType)
{
CTyBase * ret=NULL;
int count=m_ArrChilds.GetCount();
for (int i=0;i<count;i++)
{
tagShowProp* pProp=m_ArrChilds.GetAt(i);
assert(pProp!=NULL);
if (pProp==NULL) continue;
if (vShowPropType==pProp->showType)
{
ret=pProp->pChildTy;
break;
}
}
return ret;
}
//获取显示属性量
bool CGroupTyBase::GetPropCode(int vShowPropType,char* codeEname)
{
bool ret=false;
memset(codeEname,0,sizeof(char)*17);
CYC * pTy=(CYC*) FindChildTyObj(vShowPropType);
if (pTy==NULL) return ret;
ret=true;
strcpy(codeEname,pTy->m_yc.ename);
return ret;
}
//查找某个子图元的位置,通过子图元的显示类型
int CGroupTyBase::FindChildTy(int vShowPropType)
{
int ret=-1;
int count=m_ArrChilds.GetCount();
for (int i=0;i<count;i++)
{
tagShowProp* pProp=m_ArrChilds.GetAt(i);
assert(pProp!=NULL);
if (pProp==NULL) continue;
if (vShowPropType==pProp->showType)
{
ret=i;
break;
}
}
return ret;
}
void CGroupTyBase::RemoveChildTy(CTyBase * pTy,CDrawInfoBase * pView)
{
assert(pTy!=NULL);
if (pTy==NULL) return;
if (pView!=NULL)
{
pView->InvalidateTy(this);
}
RectStruct oldRt;
RectStruct newRt;
memset(&oldRt,0,sizeof(RectStruct));
memset(&newRt,0,sizeof(RectStruct));
GetRect(&oldRt.x0,&oldRt.y0,&oldRt.x1,&oldRt.y1);
int pos=FindChildTy(pTy);
if (pos>=0)
{
m_ArrChilds.RemoveAt(pos);
pTy->m_pGroup=NULL;
SetModifiedFlag(true);
}
GetRect(&newRt.x0,&newRt.y0,&newRt.x1,&newRt.y1);
if (m_pHMLayer!=NULL)
m_pHMLayer->OnPositionChangedTy(this,oldRt,newRt);
if (pView!=NULL)
{
pView->InvalidateTy(this);
}
}
/*向容器里增加一个子图元
//参数:
int showType-子图元属性编码
<0-属性无效(组合对象用)
0-主显示属性
>0
*/
void CGroupTyBase::AddTy(CTyBase *pTy,int showType,CDrawInfoBase * pView)
{
assert(pTy!=NULL);
if (pTy==NULL) return;
RectStruct oldRt;
RectStruct newRt;
memset(&oldRt,0,sizeof(RectStruct));
memset(&newRt,0,sizeof(RectStruct));
GetRect(&oldRt.x0,&oldRt.y0,&oldRt.x1,&oldRt.y1);
pTy->m_pGroup=this;
if (pView!=NULL)
{
pView->InvalidateTy(this);
}
if (showType<0)
{
int pos=FindChildTy(pTy);
if (pos<0)
{
tagShowProp* pProp=new tagShowProp;
memset(pProp,0,sizeof(pProp));
pProp->pChildTy=pTy;
pProp->showType=showType;
m_ArrChilds.Add(pProp);
pTy->m_pGroup=this;
SetModifiedFlag(true);
}
}
else
{
int pos=FindChildTy(showType);
if (pos<0)
{
tagShowProp* pProp=new tagShowProp;
memset(pProp,0,sizeof(pProp));
pProp->pChildTy=pTy;
pProp->showType=showType;
if (showType==0)
m_ArrChilds.InsertAt(0,pProp);
else
m_ArrChilds.Add(pProp);
pTy->m_pGroup=this;
SetModifiedFlag(true);
}
}
GetRect(&newRt.x0,&newRt.y0,&newRt.x1,&newRt.y1);
if (m_pHMLayer!=NULL)
m_pHMLayer->OnPositionChangedTy(this,oldRt,newRt);
if (pView!=NULL)
{
pView->InvalidateTy(this);
}
}
//添加子图元进入指定的画面层
void CGroupTyBase::AddChildTyToLayer(CHMLayer* pLayer)
{
if (pLayer==NULL) return;
CTyBase* pTy=NULL;
int count=m_ArrChilds.GetCount();
for (int i=0;i<count;i++)
{
tagShowProp* pProp=m_ArrChilds[i];
assert(pProp!=NULL);
if (pProp==NULL) continue;
pTy=pProp->pChildTy;
assert(pTy!=NULL);
if (pTy==NULL) continue;
if (pTy->m_pHMLayer==NULL)
pLayer->Add(pTy);
}
}
void CGroupTyBase::GetRect(float *minX, float *minY, float *maxX, float *maxY)
{
float minX1=0,minX2=0,minY1=0,minY2=0,maxX1=0,maxX2=0,maxY1=0,maxY2=0;
if ((m_dwFlag&0x1)==0) return; //设备图元还没有装载完毕
bool bFirst=true;
CTyBase* pTy=NULL;
int count=m_ArrChilds.GetCount();
for (int i=0;i<count;i++)
{
tagShowProp* pProp=m_ArrChilds[i];
assert(pProp!=NULL);
if (pProp==NULL) continue;
pTy=pProp->pChildTy;
//assert(pTy!=NULL);
if (pTy==NULL) continue;
if (bFirst)
{
pTy->GetRect(&minX1,&minY1,&maxX1,&maxY1);
if ((minX1==maxX1)&&(maxY1==minY1)&&(minX1==0)&&(minY1==0))
continue;
bFirst=false;
}
else
{
pTy->GetRect(&minX2,&minY2,&maxX2,&maxY2);
if ((minX2==maxX2)&&(maxY2==minY2)&&(minX2==0)&&(minY2==0))
continue;
if (minX2<minX1) minX1=minX2;
if (minY2<minY1) minY1=minY2;
if (maxX2>maxX1) maxX1=maxX2;
if (maxY2>maxY1) maxY1=maxY2;
}
}
if (bFirst==false)
{
*minX=minX1;
*minY=minY1;
*maxX=maxX1;
*maxY=maxY1;
}
}
//BOOL CGroupTyBase::PointInObj(float x, float y,float errRange)
//{
// BOOL ret=false;
// int count=m_ArrChilds.GetCount();
// if (count==0) return ret;
// CTyBase* pTy=NULL;
//
// for (int i=0;i<count;i++)
// {
// pTy=m_ArrChilds[i]->pChildTy;
// assert(pTy!=NULL);
// if (pTy==NULL) continue;
// ret=pTy->PointInObj(x,y,errRange);
// if (ret==true) break;
//
// }
// return ret;
//
//}
BOOL CGroupTyBase::PointInObj(float x, float y,float errRange)
{
assert(errRange>=0);
if (m_bDelete) return FALSE;
BOOL ret=FALSE;
RectStruct rt,rt2,rt3;
GetRect(&rt.x0,&rt.y0,&rt.x1,&rt.y1);
rt2=rt;
rt2.InflateRect(errRange+5,errRange+5);
ret=PointInRect(x,y,rt2);
return ret;
}
void CGroupTyBase::Ty_Serialize(CArchive & ar)
{
int count=0;
if(ar.IsStoring())
{
ar.Write((char *)&m_groupTypeInfo,sizeof(SGroupInfo));
ar.Write((char*)&m_groupRtuInfo,sizeof(S_GROUPRTU));
ar.Write((char *)&m_xScale,sizeof(float));
ar.Write((char *)&m_yScale,sizeof(float));
ar.Write((char *)&m_bText,sizeof(BOOL));
ar.Write((char *)&m_bBmp,sizeof(BOOL));
int num=m_ArrChilds.GetCount();
for (int i=0;i<num;i++)
{
tagShowProp* pProp=m_ArrChilds[i];
assert(pProp!=NULL);
assert(pProp!=NULL);
assert(pProp->pChildTy!=NULL);
if (pProp==NULL) continue;
if (pProp->pChildTy==NULL) continue;
if (pProp->pChildTy->m_bDelete==true) continue;
count++;
}
ar<<count;
for (int i=0;i<num;i++)
{
//CRuntime_Class
//CObject* pObject = pClass->CreateObject();
tagShowProp* pProp=m_ArrChilds[i];
assert(pProp!=NULL);
assert(pProp->pChildTy!=NULL);
if (pProp==NULL) continue;
if (pProp->pChildTy==NULL) continue;
if (pProp->pChildTy->m_bDelete==true) continue;
ar<<pProp->showType;
ar<<pProp->pChildTy;
}
}
else
{
ar.Read((char *)&m_groupTypeInfo,sizeof(SGroupInfo));
m_groupTypeInfo.Name[0]=0x0;
ar.Read((char*)&m_groupRtuInfo,sizeof(S_GROUPRTU));
int i;
for (i=0;i<m_groupRtuInfo.rtu_count;i++)
{
m_groupRtuInfo.rtu[i].node_id=-1;
m_groupRtuInfo.rtu[i].rtu_id=-1;
m_groupRtuInfo.rtu[i].name[0]=0x0;
}
ar.Read((char *)&m_xScale,sizeof(float));
ar.Read((char *)&m_yScale,sizeof(float));
ar.Read((char *)&m_bText,sizeof(BOOL));
ar.Read((char *)&m_bBmp,sizeof(BOOL));
ar>>count;
for (i=0;i<count;i++)
{
tagShowProp* pProp=new tagShowProp;
memset(pProp,0,sizeof(pProp));
ar>>pProp->showType;
ar>>pProp->pChildTy;
pProp->pChildTy = pProp->pChildTy->Clone();
pProp->pChildTy->m_pGroup=this;
m_ArrChilds.Add(pProp);
}
}
}
BOOL CGroupTyBase::IsGroupTy(BOOL& vRoot)
{
vRoot=true;
return true;
}
void CGroupTyBase::DrawBounds(CDC * pDC,CDrawInfoBase *pView)
{
float minX=0,minY=0,maxX=0,maxY=0;
GetRect(&minX,&minY,&maxX,&maxY);
if ((minX==maxX)&&(minY==maxY)&&(minX==0)&&(minY==0))
//无效
return;
CPoint pt1,pt2;
pt1=pView->UPtoLP(minX,minY);
pt2=pView->UPtoLP(maxX,maxY);
CRect rt;
rt.SetRect(pt1,pt2);
rt.NormalizeRect();
rt.InflateRect(5,5);
LOGBRUSH logBrush2;
logBrush2.lbStyle =BS_HATCHED; //BS_SOLID|BS_HATCHED;
logBrush2.lbColor = RGB(200,200,255);
logBrush2.lbHatch=HS_DIAGCROSS;
CPen pen;
pen.CreatePen(PS_SOLID|PS_GEOMETRIC|PS_ENDCAP_ROUND, 4, &logBrush2);
CPen * pOldPen=pDC->SelectObject(&pen);
int holdDrawMode=pDC->SetROP2(R2_COPYPEN);
CBrush brush,*pOldBrush;
LOGBRUSH logbrush;
logbrush.lbStyle=BS_NULL;
brush.CreateBrushIndirect(&logbrush);
pOldBrush=pDC->SelectObject(&brush);
pDC->Rectangle(&rt);
pDC->SelectObject(pOldBrush);
pDC->SetROP2(holdDrawMode);
pDC->SelectObject(pOldPen);
}
void CGroupTyBase::DrawTracker(CDC *pDC, CDrawInfoBase *pView, TrackerState state)
{
//CTyBase::DrawTracker(pDC,pView,state);
ASSERT_VALID(this);
assert(pView!=NULL);
switch (state)
{
case normal:
case active:
break;
case selected:
{
DrawBounds(pDC,pView);
int nHandleCount = GetHandleCount();
for (int nHandle = 1; nHandle <= nHandleCount; nHandle += 1)
{
CRect rt=GetHandleLogRect(nHandle,pView);
pDC->PatBlt(rt.left,rt.top, rt.Width(),rt.Height(), DSTINVERT);
}
}
break;
}
}
//int CGroupTyBase::GetHandleCount()
//{
// return 0;
//}
//获取子图元列表
void CGroupTyBase::GetChildTyList(CTyBaseList& vList)
{
vList.RemoveAll();
int count=m_ArrChilds.GetCount();
for (int i=0;i<count;i++)
{
tagShowProp* pProp=m_ArrChilds[i];
assert(pProp!=NULL);
assert(pProp->pChildTy!=NULL);
if (pProp->pChildTy==NULL) continue;
vList.AddTail(pProp->pChildTy);
}
}
void CGroupTyBase::Ty_Move(float xLen, float yLen,CDrawInfoBase * pView)
{
if (pView!=NULL) pView->InvalidateTy(this);
CTyBase* pTy=NULL;
int count=m_ArrChilds.GetCount();
for (int i=0;i<count;i++)
{
tagShowProp* pProp=m_ArrChilds[i];
assert(pProp!=NULL);
assert(pProp->pChildTy!=NULL);
if (pProp->pChildTy==NULL) continue;
pProp->pChildTy->Move(xLen,yLen,pView);
}
if (pView!=NULL) pView->InvalidateTy(this);
}
//释放所有被选择的子图元
void CGroupTyBase::DeSelectChildTy(CTysView* pView)
{
assert(pView!=NULL);
if (pView==NULL) return;
CTyBase* pTy=NULL;
int count=m_ArrChilds.GetCount();
for (int i=0;i<count;i++)
{
tagShowProp* pProp=m_ArrChilds[i];
assert(pProp!=NULL);
pTy=pProp->pChildTy;
assert(pTy!=NULL);
if (pTy==NULL) continue;
pView->Deselect(pTy);
}
}
void CGroupTyBase::OnChildMoveReCallEvent(CTyBase* pChildTy,float xLen, float yLen,CDrawInfoBase * pView)
{
}
//从某画面层里删除自己
void CGroupTyBase::RemoveSelf()
{
if ((m_dwFlag&0x1)==0) //设备图元还没有装载完毕
{
if (m_pHMLayer!=NULL)
m_pHMLayer->Remove(this);
return;
}
//先在切割表中删除自己
if (m_pHMLayer!=NULL)
m_pHMLayer->OnRemoveTy(this);
CTyBase* pTy=NULL;
int count=m_ArrChilds.GetCount();
for (int i=0;i<count;i++)
{
tagShowProp* pProp=m_ArrChilds[i];
assert(pProp!=NULL);
pTy=pProp->pChildTy;
assert(pTy!=NULL);
if (pTy==NULL) continue;
if (pTy->m_pHMLayer==NULL) continue;
pTy->m_pGroup=NULL;//防止迭代重入
pTy->m_pHMLayer->Remove(pTy);
}
if (m_pHMLayer!=NULL)
m_pHMLayer->Remove(this);
}
///通过菜单删除自己
void CGroupTyBase::SetDelete(CDrawInfoBase * pView)
{
if (m_bDelete==true) return; //对删除嵌套解扣
//先根据当前面积,在切割表中删除自己
if (m_pHMLayer!=NULL)
m_pHMLayer->OnRemoveTy(this);
if (pView!=NULL) pView->InvalidateTy(this);
CTyBaseList vList;
CTyBase* pTy=NULL;
int count=m_ArrChilds.GetCount();
for (int i=0;i<count;i++)
{
tagShowProp* pProp=m_ArrChilds[i];
assert(pProp!=NULL);
pTy=pProp->pChildTy;
assert(pTy!=NULL);
if (pTy==NULL) continue;
vList.AddTail(pTy);
//pTy->SetDelete(bDelete,true,pView);
}
POSITION pos=vList.GetHeadPosition();
while (pos!=NULL)
{
pTy=vList.GetNext(pos);
assert(pTy!=NULL);
if (pTy==NULL) continue;
pTy->SetDelete(pView);
}
vList.RemoveAll();
m_bDelete=true;
if (pView!=NULL) pView->InvalidateTy(this);
}
//通过菜单删除自己,触发的删除事件
void CGroupTyBase::OnDeleteEvent(BOOL bDelete,CDrawInfoBase * pView)
{
}
//存盘
void CGroupTyBase::SaveGroupFile(CFile *file, BOOL Yn)
{
if (file==NULL)
{
assert(false);
return;
}
CTyBase* pTy=NULL;
CTyBaseList vList;
WORD vMVer,vEVer;
int count=0;
DRAW_TY tystyle;
if (Yn==true)
{
vMVer=CHuaMian::m_wMVersion;
vEVer=CHuaMian::m_wEVersion;
file->Write((char*)&vMVer,sizeof(WORD));
file->Write((char*)&vEVer,sizeof(WORD));
file->Write((char *)&m_groupTypeInfo,sizeof(SGroupInfo));
file->Write((char *)&m_groupRtuInfo,sizeof(S_GROUPRTU));
GetChildTyList(vList);
count=vList.GetCount();
file->Write((char*)&count,sizeof(int));
POSITION pos=vList.GetHeadPosition();
while (pos!=NULL)
{
pTy=vList.GetNext(pos);
if (!pTy->m_bDelete)
{
tystyle=pTy->GetTyType();
assert(tystyle!=tyNone);
file->Write((char *)&tystyle,sizeof(tystyle));
pTy->Save(file,vMVer,vEVer,Yn);
}
}
}
else
{
file->Read((char*)&vMVer,sizeof(WORD));
file->Read((char*)&vEVer,sizeof(WORD));
//比较画面文件版本号
if ((vMVer>CHuaMian::m_wMVersion)||((vMVer==CHuaMian::m_wMVersion)
&&((vEVer>CHuaMian::m_wEVersion))))
{
//pException=new CPicFileException();
//pException->m_errno=CPicFileException::HIGHVERSION;
//throw(pException);
assert(false);
return;
}
file->Read((char *)&m_groupTypeInfo,sizeof(SGroupInfo));
file->Read((char *)&m_groupRtuInfo,sizeof(S_GROUPRTU));
file->Read((char *)&count,sizeof(int));
for (int i=0;i<count;i++)
{
file->Read((char *)&tystyle,sizeof(tystyle));
pTy=CTyBase::CreateTy(tystyle);
if (pTy==NULL) return;
pTy->Save(file,vMVer,vEVer,Yn);
AddTy(pTy);
//CGroupTyBase* pGrp=(CGroupTyBase*) pTy;
//CHMLayer * pLayer=NULL;
//pLayer=FindLayer(pGrp->m_LayerID);
//assert(pLayer!=NULL);
//if (pLayer==NULL) continue;
//pGrp->AssemblyChildTy(pLayer);
//pLayer->Add(pTy,true);
}
}
}
//void CGroupTyBase::Ty_Save_Version(CFile *file, BOOL Yn,WORD vMVer,WORD vEVer)
void CGroupTyBase::Ty_Save(CFile* file,WORD mVer,WORD eVer,BOOL Yn)
{
assert(file!=NULL);
assert(m_bDelete==false);
if (file==NULL) return;
int count=0;
//int posNumber;
CTyBase* pTy=NULL;
if (Yn)
{
int iLayerNo=m_pHMLayer->GetLayerID();
file->Write((char *)&iLayerNo,sizeof(int));
file->Write((char *)&m_groupTypeInfo,sizeof(SGroupInfo));
file->Write((char *)&m_groupRtuInfo,sizeof(S_GROUPRTU));
file->Write((char *)&m_xScale,sizeof(float));
file->Write((char *)&m_yScale,sizeof(float));
file->Write((char *)&m_bText,sizeof(BOOL));
file->Write((char *)&m_bBmp,sizeof(BOOL));
char buf[65];
memset(buf,0,sizeof(char));
file->Write(buf,sizeof(char)*65);
//num=m_TyList.GetCount();
int num=m_ArrChilds.GetCount();
for (int i=0;i<num;i++)
{
tagShowProp* pProp=m_ArrChilds[i];
assert(pProp!=NULL);
assert(pProp!=NULL);
assert(pProp->pChildTy!=NULL);
if (pProp==NULL) continue;
if (pProp->pChildTy==NULL) continue;
if (pProp->pChildTy->m_bDelete==true) continue;
count++;
}
file->Write((char *)&count,sizeof(count));
for (int i=0;i<num;i++)
{
//CRuntime_Class
//CObject* pObject = pClass->CreateObject();
tagShowProp* pProp=m_ArrChilds[i];
assert(pProp!=NULL);
assert(pProp->pChildTy!=NULL);
if (pProp==NULL) continue;
pTy=pProp->pChildTy;
if (pTy==NULL) continue;
if (pTy->m_bDelete==true) continue;
file->Write((char *)&(pProp->showType),sizeof(int));
file->Write((char *)&(pTy->m_Id),sizeof(int));
}
}
else
{
file->Read((char *)&(m_LayerID),sizeof(int));
file->Read((char *)&m_groupTypeInfo,sizeof(SGroupInfo));
file->Read((char *)&m_groupRtuInfo,sizeof(S_GROUPRTU));
file->Read((char *)&m_xScale,sizeof(float));
file->Read((char *)&m_yScale,sizeof(float));
file->Read((char *)&m_bText,sizeof(BOOL));
file->Read((char *)&m_bBmp,sizeof(BOOL));
char buf[65];
memset(buf,0,sizeof(char));
file->Read(buf,sizeof(char)*65);
file->Read((char *)&count,sizeof(count));
int tyID;
for (int i=0;i<count;i++)
{
tagShowProp* pProp= new tagShowProp;
file->Read((char *)&(pProp->showType),sizeof(int));
file->Read((char *)&tyID,sizeof(int));
pProp->pChildTy=(CTyBase*)(char*)tyID;
m_ArrChilds.Add(pProp);
}
}
}
//图层装载完毕事件
void CGroupTyBase::OnAfterLoadLayerEvent(void)
{
CTyBase::OnAfterLoadLayerEvent();
assert(m_pHMLayer!=NULL);
if (m_pHMLayer==NULL) return;
int count=m_ArrChilds.GetCount();
int tyID;
CTyBase* pTy;
for (int i=0;i<count;i++)
{
tagShowProp* pProp=m_ArrChilds.GetAt(i);
assert(pProp!=NULL);
tyID=(int)(char*)(pProp->pChildTy);
pTy=m_pHMLayer->FindTyBase(tyID);
assert(pTy!=NULL);
if (pTy==NULL)
{
m_ArrChilds[i]->pChildTy=NULL;
continue;
}
m_ArrChilds[i]->pChildTy=pTy;
pTy->m_pGroup=this;
}
}
//拼装组合图元
void CGroupTyBase::AssemblyChildTy(CHMLayer* pLayer)
{
if (pLayer==NULL) return;
if ((m_dwFlag&0x1)==0) return;
m_dwFlag=m_dwFlag|0x1;
int count=m_ArrChilds.GetCount();
int tyID;
CTyBase* pTy;
for (int i=0;i<count;i++)
{
tagShowProp* pProp=m_ArrChilds.GetAt(i);
assert(pProp!=NULL);
tyID=(int)(char*)(pProp->pChildTy);
CHMLayerList *layers = &(pLayer->m_pHuaMian->m_HMLayerList);
POSITION pos=layers->GetHeadPosition();
while (pos!=NULL)
{
pLayer=layers->GetNext(pos);
if (pLayer!=NULL)
{
pTy=pLayer->FindTyBase(tyID);
if(pTy != NULL)
break;
}
}
//assert(pTy!=NULL);
if (pTy==NULL)
{
m_ArrChilds[i]->pChildTy=NULL;
continue;
}
m_ArrChilds[i]->pChildTy=pTy;
pTy->m_pGroup=this;
}
}
//图元加入层前
void CGroupTyBase::OnAddLayerBeforeEvent(tagAddLayerEvent* pInfo)
{
if (pInfo==NULL) return;
if (pInfo->pLayer==NULL) return;
int count=m_ArrChilds.GetCount();
int tyID;
CTyBase* pTy;
for (int i=0;i<count;i++)
{
tagShowProp* pProp=m_ArrChilds.GetAt(i);
assert(pProp!=NULL);
//tyID=(int)(char*)(pProp->pChildTy);
//pTy=m_pHMLayer->FindTyBase(tyID);
pTy=pProp->pChildTy;
assert(pTy!=NULL);
if (pTy==NULL) continue;
if (pTy->m_pHMLayer==pInfo->pLayer) continue;
pTy->m_pGroup=this;
pInfo->pLayer->Add(pTy,pInfo->blNumberChanged);
}
}
//图元加入层后
void CGroupTyBase::OnAddLayerAfterEvent(tagAddLayerEvent* pInfo)
{
}
//返回组图元的最大外接矩形(文字除外)
void CGroupTyBase::GetGroupRect(float *minX,float *minY,float *maxX,float *maxY)
{
float minX1=0,minX2=0,minY1=0,minY2=0,maxX1=0,maxX2=0,maxY1=0,maxY2=0;
if ((m_dwFlag&0x1)==0) return; //设备图元还没有装载完毕
bool bFirst=true;
CTyBase* pTy=NULL;
int count=m_ArrChilds.GetCount();
for (int i=0;i<count;i++)
{
tagShowProp* pProp=m_ArrChilds[i];
assert(pProp!=NULL);
if (pProp==NULL) continue;
pTy=pProp->pChildTy;
assert(pTy!=NULL);
if (pTy==NULL) continue;
if (pTy->IsTextTy()==true)
continue;
if (bFirst)
{
pTy->GetRect(&minX1,&minY1,&maxX1,&maxY1);
if ((minX1==maxX1)&&(maxY1==minY1)&&(minX1==0)&&(minY1==0))
continue;
bFirst=false;
}
else
{
pTy->GetRect(&minX2,&minY2,&maxX2,&maxY2);
if ((minX2==maxX2)&&(maxY2==minY2)&&(minX2==0)&&(minY2==0))
continue;
if (minX2<minX1) minX1=minX2;
if (minY2<minY1) minY1=minY2;
if (maxX2>maxX1) maxX1=maxX2;
if (maxY2>maxY1) maxY1=maxY2;
}
}
if (bFirst==false)
{
*minX=minX1;
*minY=minY1;
*maxX=maxX1;
*maxY=maxY1;
}
}
void CGroupTyBase::DrawGroup(CDC *pDC, CDrawInfoBase *pView)
{
int count=m_ArrChilds.GetCount();
CTyBase* pTy;
for (int i=0;i<count;i++)
{
tagShowProp* pProp=m_ArrChilds.GetAt(i);
assert(pProp!=NULL);
pTy=pProp->pChildTy;
assert(pTy!=NULL);
if (pTy==NULL) continue;
if (pTy->IsTextTy()==true) continue;
pTy->DrawDC(pDC,pView);
}
}
//自动转换组合图元的点参数
void CGroupTyBase::ParamReplaceGroup(void)
{
CStringList ruleList;
CString str;
str.Format("3,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",m_groupRtuInfo.rtu_count,
m_groupRtuInfo.rtu[0].node_id,m_groupRtuInfo.rtu[0].line_id,m_groupRtuInfo.rtu[0].rtu_id,
m_groupRtuInfo.rtu[1].node_id,m_groupRtuInfo.rtu[1].line_id,m_groupRtuInfo.rtu[1].rtu_id,
m_groupRtuInfo.rtu[2].node_id,m_groupRtuInfo.rtu[2].line_id,m_groupRtuInfo.rtu[2].rtu_id,
m_groupRtuInfo.rtu[3].node_id,m_groupRtuInfo.rtu[3].line_id,m_groupRtuInfo.rtu[3].rtu_id);
ruleList.AddTail(str);
int count=m_ArrChilds.GetCount();
CTyBase* pTy;
for (int i=0;i<count;i++)
{
tagShowProp* pProp=m_ArrChilds.GetAt(i);
assert(pProp!=NULL);
pTy=pProp->pChildTy;
assert(pTy!=NULL);
if (pTy==NULL) continue;
pTy->ParamReplace(ruleList);
}
SetModifiedFlag(true);
}
void CGroupTyBase::OnEditProperties(CDrawInfoBase * pView)
{
CDlgGroupScale dlg;
CPropertySheet Property;
Property.AddPage(&dlg);
Property.SetTitle("组合图元属性..");
//Property.m_psh.dwFlags|=PSH_NOAPPLYNOW;
//dlg.m_psp.dwFlags&=~PSP_HASHELP;
dlg.SetContent(m_xScale,m_yScale,m_bText,m_bBmp);
//dlg.SetGroupInfo(&m_groupTypeInfo);
if(Property.DoModal()==IDOK)
{
float xScale,yScale;
BOOL bText,bBmp;
dlg.GetContent(xScale,yScale,bText,bBmp);
SetModifiedFlag(true);
SetGroupScale(xScale,yScale,bText,bBmp,pView);
c_xScale=m_xScale;
c_yScale=m_yScale;
c_bText=m_bText;
c_bBmp=m_bBmp;
}
}
void CGroupTyBase::OnEditProperties_2(CDrawInfoBase * pView)
{
CNewGroupPage dlg;
CPropertySheet Property;
Property.AddPage(&dlg);
Property.SetTitle("组合图元模板属性..");
Property.m_psh.dwFlags|=PSH_NOAPPLYNOW;
dlg.m_psp.dwFlags&=~PSP_HASHELP;
dlg.SetGroupInfo(&m_groupTypeInfo);
if(Property.DoModal()==IDOK)
{
dlg.GetGroupInfo(&m_groupTypeInfo);
m_groupRtuInfo.rtu_count=m_groupTypeInfo.nRtuCount;
for (int i=0;i<MAX_GRP_RTU_NUM;i++)
{
strcpy(m_groupRtuInfo.rtu[i].name,m_groupTypeInfo.RtuInfo[i].Name);
m_groupRtuInfo.rtu[i].rtu_type=m_groupTypeInfo.RtuInfo[i].nModType;
}
SetModifiedFlag(true);
}
}
//创建组合模板的一个实例
BOOL CGroupTyBase::OnCreateSample(CDrawInfoBase * pView)
{
BOOL ret=false;
if (g_DLL.m_pFunc_ShowFindRtuDlg==NULL) return ret;
S_GROUPRTU rec;
memset(&rec,0,sizeof(S_GROUPRTU));
memcpy(&rec,&m_groupRtuInfo,sizeof(S_GROUPRTU));
ret=true;
if ((*g_DLL.m_pFunc_ShowFindRtuDlg)(&rec)==true)
{
for (int i=0;i<rec.rtu_count;i++)
{
if (rec.rtu[i].rtu_id==-1)
{
ret=false;
continue;
}
}
memcpy(&m_groupRtuInfo,&rec,sizeof(S_GROUPRTU));
ParamReplaceGroup();
}
else
{
ret = false;
}
// ret=true;
return ret;
}
//获取组合图元的单元配置参数
BOOL CGroupTyBase::GetGroupTyRtuParam(S_GROUPRTU& vParam)
{
memcpy(&vParam,&m_groupRtuInfo,sizeof(S_GROUPRTU));
return true;
}
int CGroupTyBase::GetHandleCount()
{
return 8;
}
PointStruct CGroupTyBase::GetHandle(int nHandle)
{
ASSERT_VALID(this);
PointStruct pt;
float x0,y0,x1,y1;
GetRect(&x0,&y0,&x1,&y1);
switch (nHandle)
{
default:
ASSERT(FALSE);
case 1:
pt.x = x0;
pt.y = y0;
break;
case 2:
pt.x = (x1+x0)/2;
pt.y = y0;
break;
case 3:
pt.x = x1;
pt.y = y0;
break;
case 4:
pt.x = x1;
pt.y = (y0+y1)/2;
break;
case 5:
pt.x = x1;
pt.y = y1;
break;
case 6:
pt.x = (x1+x0)/2;
pt.y = y1;
break;
case 7:
pt.x = x0;
pt.y = y1;
break;
case 8:
pt.x = x0;
pt.y = (y0+y1)/2;
break;
}
return pt;
}
HCURSOR CGroupTyBase::GetHandleCursor(int nHandle)
{
ASSERT_VALID(this);
LPCTSTR id;
switch (nHandle)
{
default:
ASSERT(FALSE);
case 1:
case 5:
id=IDC_SIZENWSE;
break;
case 2:
case 6:
id=IDC_SIZENS;
break;
case 3:
case 7:
id=IDC_SIZENESW;
break;
case 4:
case 8:
id=IDC_SIZEWE;
break;
}
return AfxGetApp()->LoadStandardCursor(id);
}
void CGroupTyBase::SetGroupScale(float xScale, float yScale,BOOL bText,BOOL bBmp,CDrawInfoBase *pView)
{
if ((xScale==m_xScale)&&(yScale==m_yScale)&&(m_bText==bText)&&(m_bBmp==bBmp))
{
return;
}
float x0,y0,x1,y1;
GetRect(&x0,&y0,&x1,&y1);
PointStruct point;
memset(&point,0,sizeof(PointStruct));
point.x=x0+(x1-x0)/m_xScale;
point.y=y0+(y1-y0)/m_yScale;
Ty_MoveHandleTo(5,point,pView,0);
m_bText=bText;
m_bBmp=bBmp;
GetRect(&x0,&y0,&x1,&y1);
point.x=x0+(x1-x0)*xScale;
point.y=y0+(y1-y0)*yScale;
Ty_MoveHandleTo(5,point,pView,0);
//m_xScale=xScale;
//m_yScale=yScale;
}
void CGroupTyBase::Ty_MoveHandleTo(int nHandle, PointStruct point, CDrawInfoBase *pView,UINT nFlags)
{
//assert(pView!=NULL);
if (pView!=NULL)
pView->InvalidateTy(this);
CPixelTranslate vTranslate;
tagTranslateInfo vInfo;
memset(&vInfo,0,sizeof(tagTranslateInfo));
GetRect(&vInfo.vSrcX0,&vInfo.vSrcY0,&vInfo.vSrcX1,&vInfo.vSrcY1);
vInfo.vDstX=point.x;
vInfo.vDstY=point.y;
vInfo.nFlags=nFlags;
vInfo.vHandle=nHandle;
vInfo.pView=pView;
vInfo.bText=m_bText;
float xScale=-1,yScale=-1;
vTranslate.GetXYScale(xScale,yScale,vInfo);
// if ((xScale>4)||(xScale<0.01))
// assert(false);
if (xScale>0)
{
xScale=m_xScale*xScale;
if ((xScale>20)||(xScale<0.1))
return;
m_xScale=xScale;
}
if (yScale>0)
{
yScale=m_yScale*yScale;
if ((yScale>20)||(yScale<0.1))
return;
m_yScale=yScale;
}
RectStruct rt1,rt2;
// Ty_MoveHandleTo(nHandle,point,pView,nFlags);
CTyBase* pTy=NULL;
CHMLayer *pLayer = NULL;
int count=m_ArrChilds.GetCount();
for (int i=0;i<count;i++)
{
tagShowProp* pProp=m_ArrChilds[i];
assert(pProp!=NULL);
pTy=pProp->pChildTy;
assert(pTy!=NULL);
if (pTy==NULL) continue;
pTy->GetRect(&rt1.x0,&rt1.y0,&rt1.x1,&rt1.y1);
pTy->OnEvent_GroupMoveHandleTo(&vTranslate,vInfo);
pLayer = pTy->m_pHMLayer;
if (pLayer!=NULL)
{
pTy->GetRect(&rt2.x0,&rt2.y0,&rt2.x1,&rt2.y1);
pLayer->OnPositionChangedTy(pTy,rt1,rt2);
}
}
if (pView!=NULL)
pView->InvalidateTy(this);
}