📄 stmeditordoc.cpp
字号:
}
ipath=pathindex;
pathEI.index=ipath;
m_arrRoutePath.Add(pathEI);
}
}else //ei.eleType=ET_CROSS
{
if(precross.index!=-1)
{
BOOL bfind=FALSE;
PATHINFO pi;
for(int j=0;j<m_arrPath.GetSize();j++)//find a path
{
pi=m_arrPath.GetAt(j);
if((pi.begin_id==precross.index&&pi.end_id==ei.index)||
(pi.end_id==precross.index&&pi.begin_id==ei.index))
{
bfind=TRUE;
break;
}
}
if(!bfind)
{
bCanAdd=FALSE;
break;
}
if(ipath==-1)// if the find path not add to the path array,add it
{
pathEI.index=j;
m_arrRoutePath.Add(pathEI);
}
}else //precross.index==-1
{
ASSERT(ipath!=-1);
PATHINFO pi=m_arrPath.GetAt(ipath);
if(pi.begin_id!=ei.index&&pi.end_id!=ei.index)
{
bCanAdd=FALSE;
break;
}
}
precross=ei;
ipath=-1;
}
}
if(!bCanAdd) return -1;
int index=m_arrTR.Add(tri);
SelectElements(tri.pEI,tri.nStations);
ELEINFO *ppathEI=m_arrRoutePath.GetData();
AddSelectedElement(ppathEI,m_arrRoutePath.GetSize());
SetModifiedFlag();
return index;
}
void CSTMEditorDoc::RemoveTR(int index)
{
TRAFFICROUTEINFO tri=m_arrTR.GetAt(index);
delete []tri.pEI;
m_arrTR.RemoveAt(index);
SetModifiedFlag();
}
void CSTMEditorDoc::AddSelectedElement(ELEINFO *pEI, int count)
{
for(int i=0;i<count;i++)
m_arrSel.Add(*(pEI+i));
}
void CSTMEditorDoc::RemoveStreetInfo()
{
STREETINFO si;
for(int i=0;i<m_arrStreet.GetSize();i++)
{
si=m_arrStreet.GetAt(i);
delete []si.pPathID;
}
m_arrStreet.RemoveAll();
}
void CSTMEditorDoc::ClearDataBuffer()
{
m_bViewBK=m_bViewCross=m_bViewPath=m_bViewBS=m_bViewAddress=TRUE;
m_Author=m_Name=m_Memory="";
m_bkfilename="";
m_Width=m_Height=2000;
m_Scale=10;
if(m_Picture) m_Picture.Free();
m_arrCross.RemoveAll();
m_arrPath.RemoveAll();
m_arrBS.RemoveAll();
RemoveTrafficRouteInfo();
RemoveStreetInfo();
m_arrAddress.RemoveAll();
m_focusEI.eleType=ET_NULL;
m_focusEI.index=-1;
m_preFocusEI.eleType=ET_NULL;
m_preFocusEI.index=-1;
m_bFocusChanged=FALSE;
m_arrSel.RemoveAll();
}
void CSTMEditorDoc::SelectCross(int index)
{
ELEINFO ei;
ei.eleType=ET_CROSS;
ei.index=index;
SelectElements(&ei,1);
}
void CSTMEditorDoc::SelectPath(int index)
{
ELEINFO ei;
ei.eleType=ET_PATH;
ei.index=index;
SelectElements(&ei,1);
}
void CSTMEditorDoc::SelectBS(int index)
{
ELEINFO ei;
ei.eleType=ET_BS;
ei.index=index;
SelectElements(&ei,1);
}
void CSTMEditorDoc::SelectTraffic(int index)
{
TRAFFICROUTEINFO tri=m_arrTR.GetAt(index);
SelectElements(tri.pEI,tri.nStations);
ELEINFO ei,pathei;
int pathid=-1;
int precrossid=-1;
pathei.eleType=ET_PATH;
for(int i=0;i<tri.nStations;i++)
{
ei=tri.pEI[i];
if(ei.eleType==ET_BS)
{
int temppathid=m_arrBS.GetAt(ei.index).path_id;
if(pathid!=temppathid)
{
pathei.index=temppathid;
AddSelectedElement(&pathei,1);
pathid=temppathid;
}
}else //cross
{
if(pathid==-1)//connect two cross
{
if(precrossid!=-1)
{
PATHINFO pi;
for(int j=0;j<m_arrPath.GetSize();j++)
{
pi=m_arrPath.GetAt(j);
if((pi.begin_id==precrossid&&pi.end_id==ei.index)||
(pi.end_id==precrossid&&pi.begin_id==ei.index))
{
pathei.index=j;
AddSelectedElement(&pathei,1);
break;
}
}
}
}else
{
pathid=-1;
}
precrossid=ei.index;
}
}
}
void CSTMEditorDoc::SelectStreet(int index)
{
STREETINFO si=m_arrStreet.GetAt(index);
ELEINFO *pei=new ELEINFO[si.nPathes];
for(int i=0;i<si.nPathes;i++)
{
pei[i].eleType=ET_PATH;
pei[i].index=si.pPathID[i];
}
SelectElements(pei,si.nPathes);
delete []pei;
}
void CSTMEditorDoc::SelectAddress(int index)
{
ELEINFO ei;
ei.eleType=ET_ADDRESS;
ei.index=index;
SelectElements(&ei,1);
}
void CSTMEditorDoc::Deselect()
{
m_arrSel.RemoveAll();
}
int CSTMEditorDoc::AddStreet(STREETINFO si)
{
ASSERT(si.nPathes>0);
if(si.nPathes>1)
{
PATHINFO prepath,path;
prepath=m_arrPath.GetAt(si.pPathID[0]);
path=m_arrPath.GetAt(si.pPathID[1]);
int precrossid=-1;
if(prepath.begin_id==path.begin_id||prepath.begin_id==path.end_id)
precrossid=prepath.begin_id;
else if(prepath.end_id==path.begin_id||prepath.end_id==path.end_id)
precrossid=prepath.end_id;
if(precrossid==-1) return -1;
for(int i=1;i<si.nPathes;i++)
{
path=m_arrPath.GetAt(si.pPathID[i]);
if(path.begin_id==precrossid)
precrossid=path.end_id;
else if(path.end_id==precrossid)
precrossid=path.begin_id;
else
return -1;
}
}
int index=m_arrStreet.Add(si);
Deselect();
ELEINFO ei;
ei.eleType=ET_PATH;
for(int i=0;i<si.nPathes;i++)
{
ei.index=si.pPathID[i];
AddSelectedElement(&ei,1);
}
SetModifiedFlag();
return index;
}
int CSTMEditorDoc::AddAddress(ADDRESSINFO ai)
{
ADDRESSINFO tmpai;
for(int i=0;i<m_arrAddress.GetSize();i++)
{
tmpai=m_arrAddress.GetAt(i);
if(strcmp(ai.name,tmpai.name)==0)
return -1;
}
int index=m_arrAddress.Add(ai);
ELEINFO ei;
ei.eleType=ET_ADDRESS;
ei.index=index;
SelectElements(&ei,1);
SetModifiedFlag();
return index;
}
RECT CSTMEditorDoc::CalcAddressRect(POINT pt)
{
RECT rc;
rc.left=pt.x-5,rc.right=pt.x+5;
rc.top=pt.y-8,rc.bottom=pt.y+8;
return rc;
}
void CSTMEditorDoc::CalcAddressRgn(CRgn &addressrgn, int index)
{
ADDRESSINFO ai=m_arrAddress.GetAt(index);
RECT rc=CalcAddressRect(ai.pos);
CWindowDC dc(NULL);
CSize txtsize=dc.GetTextExtent(ai.name,strlen(ai.name));
CRect txtrc;
txtrc.left=rc.right,txtrc.top=rc.top;
txtrc.right=txtrc.left+txtsize.cx;
txtrc.bottom=txtrc.top+txtsize.cy;
CRgn hotrgn,txtrgn;
hotrgn.CreateRectRgnIndirect(&rc);
txtrgn.CreateRectRgnIndirect(&txtrc);
AddRgn(addressrgn,hotrgn);
AddRgn(addressrgn,txtrgn);
}
void CSTMEditorDoc::RemoveAddress(CRgn &effectrgn, int index)
{
ASSERT(index<m_arrAddress.GetSize());
ELEINFO selEI;
for(int i=m_arrSel.GetSize()-1;i>=0;i--)
{
selEI=m_arrSel.GetAt(i);
if(selEI.eleType==ET_ADDRESS &&
selEI.index==index)
{
m_arrSel.RemoveAt(i);
}
if(selEI.eleType==ET_ADDRESS &&
selEI.index>index)
{
selEI.index--;
m_arrSel.SetAt(i,selEI);
}
}
CalcAddressRgn(effectrgn,index);
m_arrAddress.RemoveAt(index);
SetModifiedFlag();
}
void CSTMEditorDoc::RemoveStreet(int index)
{
STREETINFO si=m_arrStreet.GetAt(index);
delete []si.pPathID;
m_arrStreet.RemoveAt(index);
SetModifiedFlag();
}
BOOL CSTMEditorDoc::IsPathInTrafficRoute(PATHINFO pi, TRAFFICROUTEINFO tri)
{
BOOL bPathInTR=FALSE;
int begincross_id=-1,endcross_id=-1;
for(int i=0;i<tri.nStations;i++)
{
if(tri.pEI[i].eleType==ET_CROSS)
{
endcross_id=tri.pEI[i].index;
if(begincross_id!=-1)
{
if((pi.begin_id==begincross_id&&pi.end_id==endcross_id)||
(pi.begin_id==begincross_id&&pi.end_id==endcross_id))
{
bPathInTR=TRUE;
break;
}else
{
begincross_id=endcross_id;
}
}else
{
begincross_id=endcross_id;
}
}
}
return bPathInTR;
}
void CSTMEditorDoc::MoveAddress(int index, POINT pt)
{
ADDRESSINFO ai=m_arrAddress.GetAt(index);
ai.pos=pt;
m_arrAddress.SetAt(index,ai);
SetModifiedFlag();
}
//在道路上添加新路口,是数据升级的必要手段
void CSTMEditorDoc::AddCrossToPath(int index, CROSSINFO ci)
{
int crossindex=m_arrCross.Add(ci);
//update traffic route
TRAFFICROUTEINFO tri;
for(int i=0;i<m_arrTR.GetSize();i++)
{
tri=m_arrTR.GetAt(i);
int begin_index,end_index;
if(FindMaxSeg(index,tri,begin_index,end_index))
{
POINT begin_pt,end_pt;
if(tri.pEI[begin_index].eleType==ET_CROSS)
begin_pt=m_arrCross.GetAt(tri.pEI[begin_index].index).pos;
else //ET_BS
begin_pt=m_arrBS.GetAt(tri.pEI[begin_index].index).pos;
if(tri.pEI[end_index].eleType==ET_CROSS)
end_pt=m_arrCross.GetAt(tri.pEI[end_index].index).pos;
else //ET_BS
end_pt=m_arrBS.GetAt(tri.pEI[end_index].index).pos;
POINT tmp_pt1,tmp_pt2;
BOOL bRefx=abs(begin_pt.x-end_pt.x)>abs(begin_pt.y-end_pt.y);
for(int j=begin_index;j<end_index;j++)
{
if(tri.pEI[j].eleType==ET_CROSS)
tmp_pt1=m_arrCross.GetAt(tri.pEI[j].index).pos;
else
tmp_pt1=m_arrBS.GetAt(tri.pEI[j].index).pos;
if(tri.pEI[j+1].eleType==ET_CROSS)
tmp_pt2=m_arrCross.GetAt(tri.pEI[j+1].index).pos;
else
tmp_pt2=m_arrBS.GetAt(tri.pEI[j+1].index).pos;
if((bRefx&&(ci.pos.x-tmp_pt1.x)*(tmp_pt2.x-ci.pos.x)>0)||
(!bRefx&&(ci.pos.y-tmp_pt1.y)*(tmp_pt2.y-ci.pos.y)>0))//find
{
ELEINFO *pEI=new ELEINFO[tri.nStations+1];
memcpy(pEI,tri.pEI,sizeof(ELEINFO)*(j+1));
pEI[j+1].eleType=ET_CROSS;
pEI[j+1].index=crossindex;
memcpy(pEI+j+2,tri.pEI+j+1,sizeof(ELEINFO)*(tri.nStations-j-1));
delete []tri.pEI;
tri.pEI=pEI;
tri.nStations++;
m_arrTR.SetAt(i,tri);
break;
}
}
}
}
//update path array
PATHINFO oldpi=m_arrPath.GetAt(index);
PATHINFO newpi1,newpi2;
newpi1.begin_id=oldpi.begin_id;
newpi1.end_id=crossindex;
newpi2.begin_id=crossindex;
newpi2.end_id=oldpi.end_id;
int pathid1,pathid2;
pathid1=index;
m_arrPath.SetAt(pathid1,newpi1);//replace old path with new path 1
pathid2=AddPath(newpi2); //add new path2 to path array
//update bus station array
POINT oldbegin,oldend;
oldbegin=m_arrCross.GetAt(oldpi.begin_id).pos;
oldend=m_arrCross.GetAt(oldpi.end_id).pos;
BSINFO bsi;
for(i=0;i<m_arrBS.GetSize();i++)
{
bsi=m_arrBS.GetAt(i);
if(bsi.path_id==index)
{
BOOL bRefx=abs(oldbegin.x-oldend.x)>abs(oldbegin.y-oldend.y);
if(bRefx)
{
if((bsi.pos.x-oldbegin.x)*(ci.pos.x-bsi.pos.x)>0)//站牌在begin和ci.point之间
bsi.path_id=pathid1;
else
bsi.path_id=pathid2;
}else
{
if((bsi.pos.y-oldbegin.y)*(ci.pos.y-bsi.pos.y)>0)//站牌在begin和ci.point之间
bsi.path_id=pathid1;
else
bsi.path_id=pathid2;
}
m_arrBS.SetAt(i,bsi);//更正
}
}// finish bus station search
// update street sequence
STREETINFO si;
for(i=0;i<m_arrStreet.GetSize();i++)
{
si=m_arrStreet.GetAt(i);
BOOL bfind=FALSE;
for(int j=0;j<si.nPathes;j++)
{
if(si.pPathID[j]==index)
{
bfind=TRUE;
int *pPathID=new int[si.nPathes+1];
memcpy(pPathID,si.pPathID,sizeof(int)*(j+1));
pPathID[j+1]=pathid2;
memcpy(pPathID+j+2,si.pPathID+j+1,sizeof(int)*(si.nPathes-j-1));
delete []si.pPathID;
si.pPathID=pPathID;
si.nPathes++;
break;
}
}
if(bfind) m_arrStreet.SetAt(i,si);
}//finish update street;
ELEINFO ei;
ei.eleType=ET_CROSS;
ei.index=crossindex;
SelectElements(&ei,1);
GetFocusInfo(ci.pos);
SetModifiedFlag();
}
//查找一条公交线路中经过指定道路的距离最大的两个点
BOOL CSTMEditorDoc::FindMaxSeg(int path_id, TRAFFICROUTEINFO tri,int &begin_index,int &end_index)
{
BOOL bfind=FALSE;
PATHINFO pi=m_arrPath.GetAt(path_id);
int precrossid=-1;
int tmppathid=-1;
for(int i=0;i<tri.nStations;i++)
{
if(tri.pEI[i].eleType==ET_CROSS)
{
int crossid=tri.pEI[i].index;
if(precrossid!=-1)
{
if((pi.begin_id==precrossid&&pi.end_id==crossid) ||
(pi.begin_id==crossid&&pi.end_id==precrossid))
{
end_index=i;
bfind=TRUE;
break;
}else
{
precrossid=crossid;
tmppathid=-1;
begin_index=i;
}
}else
{
if(bfind)
{
end_index=i;
break;
}else
{
begin_index=i;
precrossid=crossid;
}
}
}else
{
BSINFO bsi=m_arrBS.GetAt(tri.pEI[i].index);
tmppathid=bsi.path_id;
if(tmppathid==path_id)
{
if(!bfind) bfind=TRUE;
if(precrossid==-1)
begin_index=i;
end_index=i;
}
}
}
return bfind;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -