📄 stmobjbrowsedlg.cpp
字号:
// STMObjBrowseDlg.cpp : implementation file
//
#include "stdafx.h"
#include "stmeditor.h"
#include "STMObjBrowseDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSTMObjBrowseDlg dialog
CSTMObjBrowseDlg::CSTMObjBrowseDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSTMObjBrowseDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSTMObjBrowseDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_CurSel=-1;
m_pDoc=NULL;
m_pView=NULL;
}
void CSTMObjBrowseDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSTMObjBrowseDlg)
DDX_Control(pDX, IDC_TABOBJECT, m_tabObject);
DDX_Control(pDX, IDC_LISTTRAFFIC, m_lstTraffic);
DDX_Control(pDX, IDC_LISTSTREET, m_lstStreet);
DDX_Control(pDX, IDC_LISTPATH, m_lstPath);
DDX_Control(pDX, IDC_LISTCROSS, m_lstCross);
DDX_Control(pDX, IDC_LISTBS, m_lstBS);
DDX_Control(pDX, IDC_LISTADDRESS, m_lstAddress);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSTMObjBrowseDlg, CDialog)
//{{AFX_MSG_MAP(CSTMObjBrowseDlg)
ON_BN_CLICKED(IDC_SELECT, OnSelect)
ON_WM_SIZE()
ON_NOTIFY(TCN_SELCHANGE, IDC_TABOBJECT, OnSelchangeTabobject)
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_REFRESH, OnRefresh)
ON_BN_CLICKED(IDC_DELETE, OnDelete)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSTMObjBrowseDlg message handlers
void CSTMObjBrowseDlg::OnSelect()
{
int index=m_ctrlMap[m_CurSel]->GetSelectionMark();
if(index!=-1)
{
switch(m_CurSel)
{
case 0://cross
m_pDoc->SelectCross(index);
break;
case 1://path
m_pDoc->SelectPath(index);
break;
case 2://bus station
m_pDoc->SelectBS(index);
break;
case 3://traffic
m_pDoc->SelectTraffic(index);
break;
case 4://street
m_pDoc->SelectStreet(index);
break;
case 5://address
m_pDoc->SelectAddress(index);
break;
}
m_pView->Invalidate(FALSE);
}
}
BOOL CSTMObjBrowseDlg::OnInitDialog()
{
CDialog::OnInitDialog();
DWORD dwExStyle=m_lstCross.GetExtendedStyle();
dwExStyle|=LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES;
m_lstCross.SetExtendedStyle(dwExStyle);
m_lstPath.SetExtendedStyle(dwExStyle);
m_lstBS.SetExtendedStyle(dwExStyle);
m_lstTraffic.SetExtendedStyle(dwExStyle);
m_lstStreet.SetExtendedStyle(dwExStyle);
m_lstAddress.SetExtendedStyle(dwExStyle);
//cross listctrl
LVCOLUMN col;
col.mask=LVCF_WIDTH|LVCF_TEXT;
col.cchTextMax=10;
col.cx=AfxGetApp()->GetProfileInt("LAYOUT","crossid",50);
col.pszText="ID";
m_lstCross.InsertColumn(0,&col);
col.cx=AfxGetApp()->GetProfileInt("LAYOUT","crossposx",50);
col.pszText="POS:X";
m_lstCross.InsertColumn(1,&col);
col.cx=AfxGetApp()->GetProfileInt("LAYOUT","crossposy",50);
col.pszText="POS:Y";
m_lstCross.InsertColumn(2,&col);
col.cx=AfxGetApp()->GetProfileInt("LAYOUT","crossname",50);
col.pszText="NAME";
m_lstCross.InsertColumn(3,&col);
//path listctrl
col.pszText="ID";
col.cx=AfxGetApp()->GetProfileInt("LAYOUT","pathid",50);
m_lstPath.InsertColumn(0,&col);
col.pszText="ID_BEGIN";
col.cx=AfxGetApp()->GetProfileInt("LAYOUT","pathidbegin",50);
m_lstPath.InsertColumn(1,&col);
col.pszText="ID_END";
col.cx=AfxGetApp()->GetProfileInt("LAYOUT","pathidend",50);
m_lstPath.InsertColumn(2,&col);
//bus station listctrl
col.pszText="ID";
col.cx=AfxGetApp()->GetProfileInt("LAYOUT","bsid",50);
m_lstBS.InsertColumn(0,&col);
col.pszText="ID_PATH";
col.cx=AfxGetApp()->GetProfileInt("LAYOUT","bspathid",50);
m_lstBS.InsertColumn(1,&col);
col.pszText="NAME";
col.cx=AfxGetApp()->GetProfileInt("LAYOUT","bsname",50);
m_lstBS.InsertColumn(2,&col);
//street listctrl
col.pszText="ID";
col.cx=AfxGetApp()->GetProfileInt("LAYOUT","streetid",50);
m_lstStreet.InsertColumn(0,&col);
col.pszText="NAME";
col.cx=AfxGetApp()->GetProfileInt("LAYOUT","streetname",50);
m_lstStreet.InsertColumn(1,&col);
//address listctrl
col.pszText="ID";
col.cx=AfxGetApp()->GetProfileInt("LAYOUT","addressid",50);
m_lstAddress.InsertColumn(0,&col);
col.pszText="NAME";
col.cx=AfxGetApp()->GetProfileInt("LAYOUT","addressname",50);
m_lstAddress.InsertColumn(1,&col);
col.pszText="TYPE";
col.cx=AfxGetApp()->GetProfileInt("LAYOUT","addresstype",50);
m_lstAddress.InsertColumn(2,&col);
col.pszText="POS:X";
col.cx=AfxGetApp()->GetProfileInt("LAYOUT","addressposx",50);
m_lstAddress.InsertColumn(3,&col);
col.pszText="POS:Y";
col.cx=AfxGetApp()->GetProfileInt("LAYOUT","addressposy",50);
m_lstAddress.InsertColumn(4,&col);
//traffic route listctrl
col.pszText="ID";
col.cx=AfxGetApp()->GetProfileInt("LAYOUT","trafficid",50);
m_lstTraffic.InsertColumn(0,&col);
col.pszText="NAME";
col.cx=AfxGetApp()->GetProfileInt("LAYOUT","trafficname",50);
m_lstTraffic.InsertColumn(1,&col);
col.pszText="TYPE";
col.cx=AfxGetApp()->GetProfileInt("LAYOUT","traffictype",50);
m_lstTraffic.InsertColumn(2,&col);
col.pszText="STATIONS";
col.cx=AfxGetApp()->GetProfileInt("LAYOUT","trafficstation",200);
m_lstTraffic.InsertColumn(3,&col);
m_tabObject.InsertItem(0,"CROSS");
m_ctrlMap[0]=&m_lstCross;
m_tabObject.InsertItem(1,"PATH");
m_ctrlMap[1]=&m_lstPath;
m_tabObject.InsertItem(2,"BUS STATION");
m_ctrlMap[2]=&m_lstBS;
m_tabObject.InsertItem(3,"TRAFFIC");
m_ctrlMap[3]=&m_lstTraffic;
m_tabObject.InsertItem(4,"STREET");
m_ctrlMap[4]=&m_lstStreet;
m_tabObject.InsertItem(5,"ADDRESS");
m_ctrlMap[5]=&m_lstAddress;
SendMessage(WM_SIZE);
m_CurSel=0;
// m_tabObject.SetCurSel(m_CurSel);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CSTMObjBrowseDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
if(!m_tabObject.m_hWnd) return;
CRect rc;
GetClientRect(&rc);
rc.right-=80;
m_tabObject.MoveWindow(&rc);
CRect listrc;
m_tabObject.GetClientRect(&listrc);
m_tabObject.AdjustRect(FALSE,&listrc);
m_lstAddress.MoveWindow(&listrc);
m_lstBS.MoveWindow(&listrc);
m_lstCross.MoveWindow(&listrc);
m_lstStreet.MoveWindow(&listrc);
m_lstPath.MoveWindow(&listrc);
m_lstTraffic.MoveWindow(&listrc);
CWnd *button;
rc.left=rc.right+10;
rc.right=rc.left+60;
rc.top+=30;
rc.bottom=rc.top+25;
button=GetDlgItem(IDC_REFRESH);
button->MoveWindow(&rc);
rc.OffsetRect(0,40);
button=GetDlgItem(IDC_SELECT);
button->MoveWindow(&rc);
rc.OffsetRect(0,40);
button=GetDlgItem(IDC_DELETE);
button->MoveWindow(&rc);
rc.OffsetRect(0,40);
button=GetDlgItem(IDCANCEL);
button->MoveWindow(&rc);
}
void CSTMObjBrowseDlg::OnSelchangeTabobject(NMHDR* pNMHDR, LRESULT* pResult)
{
if(m_CurSel!=-1)
m_ctrlMap[m_CurSel]->ShowWindow(SW_HIDE);
m_CurSel=m_tabObject.GetCurSel();
m_ctrlMap[m_CurSel]->ShowWindow(SW_SHOW);
*pResult = 0;
}
void CSTMObjBrowseDlg::OnRefresh()
{
LVITEM lv;
CString buffer;
lv.mask=LVIF_TEXT;
//cross
m_lstCross.DeleteAllItems();
CROSSINFO ci;
lv.cchTextMax=20;
for(int i=0;i<m_pDoc->m_arrCross.GetSize();i++)
{
ci=m_pDoc->m_arrCross.GetAt(i);
lv.iItem=i;
lv.iSubItem=0;
buffer.Format("%d",i);
lv.pszText=(LPTSTR)(LPCTSTR)buffer;
m_lstCross.InsertItem(&lv);
lv.iSubItem=1;
buffer.Format("%d",ci.pos.x);
lv.pszText=(LPTSTR)(LPCTSTR)buffer;
m_lstCross.SetItem(&lv);
lv.iSubItem=2;
buffer.Format("%d",ci.pos.y);
lv.pszText=(LPTSTR)(LPCTSTR)buffer;
m_lstCross.SetItem(&lv);
lv.iSubItem=3;
buffer.Format("%s",ci.name);
lv.pszText=(LPTSTR)(LPCTSTR)buffer;
m_lstCross.SetItem(&lv);
}
//bus station
m_lstBS.DeleteAllItems();
BSINFO bsi;
for(i=0;i<m_pDoc->m_arrBS.GetSize();i++)
{
bsi=m_pDoc->m_arrBS.GetAt(i);
lv.iItem=i;
lv.iSubItem=0;
buffer.Format("%d",i);
lv.pszText=(LPTSTR)(LPCTSTR)buffer;
m_lstBS.InsertItem(&lv);
lv.iSubItem=1;
buffer.Format("%s",bsi.name);
lv.pszText=(LPTSTR)(LPCTSTR)buffer;
m_lstBS.SetItem(&lv);
lv.iSubItem=2;
buffer.Format("%d",bsi.pos.x);
lv.pszText=(LPTSTR)(LPCTSTR)buffer;
m_lstBS.SetItem(&lv);
lv.iSubItem=3;
buffer.Format("%d",bsi.pos.y);
lv.pszText=(LPTSTR)(LPCTSTR)buffer;
m_lstBS.SetItem(&lv);
}
//path
m_lstPath.DeleteAllItems();
PATHINFO pi;
for(i=0;i<m_pDoc->m_arrPath.GetSize();i++)
{
pi=m_pDoc->m_arrPath.GetAt(i);
lv.iItem=i;
lv.iSubItem=0;
buffer.Format("%d",i);
lv.pszText=(LPTSTR)(LPCTSTR)buffer;
m_lstPath.InsertItem(&lv);
lv.iSubItem=1;
buffer.Format("%d",pi.begin_id);
lv.pszText=(LPTSTR)(LPCTSTR)buffer;
m_lstPath.SetItem(&lv);
lv.iSubItem=2;
buffer.Format("%d",pi.end_id);
lv.pszText=(LPTSTR)(LPCTSTR)buffer;
m_lstPath.SetItem(&lv);
}
//traffic
m_lstTraffic.DeleteAllItems();
TRAFFICROUTEINFO tri;
for(i=0;i<m_pDoc->m_arrTR.GetSize();i++)
{
tri=m_pDoc->m_arrTR.GetAt(i);
lv.iItem=i;
lv.cchTextMax=20;
lv.iSubItem=0;
buffer.Format("%d",i);
lv.pszText=(LPTSTR)(LPCTSTR)buffer;
m_lstTraffic.InsertItem(&lv);
lv.iSubItem=1;
buffer.Format("%s",tri.name);
lv.pszText=(LPTSTR)(LPCTSTR)buffer;
m_lstTraffic.SetItem(&lv);
lv.iSubItem=2;
buffer.Format("%d",tri.type);
lv.pszText=(LPTSTR)(LPCTSTR)buffer;
m_lstTraffic.SetItem(&lv);
lv.iSubItem=3;
lv.cchTextMax=500;
buffer="";
ELEINFO ei;
for(int j=0;j<tri.nStations;j++)
{
ei=tri.pEI[j];
if(ei.eleType==ET_BS)
{
buffer+=m_pDoc->m_arrBS.GetAt(ei.index).name;
if(j<tri.nStations-1) buffer+="->";
}
}
m_lstTraffic.SetItem(&lv);
}
//street
m_lstStreet.DeleteAllItems();
STREETINFO si;
for(i=0;i<m_pDoc->m_arrStreet.GetSize();i++)
{
si=m_pDoc->m_arrStreet.GetAt(i);
lv.iItem=i;
lv.cchTextMax=20;
lv.iSubItem=0;
buffer.Format("%d",i);
lv.pszText=(LPTSTR)(LPCTSTR)buffer;
m_lstStreet.InsertItem(&lv);
lv.iSubItem=1;
lv.cchTextMax=50;
buffer.Format("%s",si.name);
m_lstStreet.SetItem(&lv);
}
//address
m_lstAddress.DeleteAllItems();
ADDRESSINFO ai;
for(i=0;i<m_pDoc->m_arrAddress.GetSize();i++)
{
ai=m_pDoc->m_arrAddress.GetAt(i);
lv.iItem=i;
lv.cchTextMax=20;
lv.iSubItem=0;
buffer.Format("%d",i);
lv.pszText=(LPTSTR)(LPCTSTR)buffer;
m_lstAddress.InsertItem(&lv);
lv.iSubItem=1;
lv.cchTextMax=50;
buffer.Format("%s",ai.name);
m_lstAddress.SetItem(&lv);
lv.iSubItem=2;
lv.cchTextMax=10;
buffer.Format("%d",ai.type );
m_lstAddress.SetItem(&lv);
lv.iSubItem=3;
buffer.Format("%d",ai.pos.x);
m_lstAddress.SetItem(&lv);
lv.iSubItem=4;
buffer.Format("%d",ai.pos.y);
m_lstAddress.SetItem(&lv);
}
}
void CSTMObjBrowseDlg::OnDestroy()
{
CDialog::OnDestroy();
HDITEM hditem;
hditem.mask=HDI_WIDTH;
m_lstCross.GetHeaderCtrl()->GetItem(0,&hditem);
AfxGetApp()->WriteProfileInt("LAYOUT","crossid",hditem.cxy);
m_lstCross.GetHeaderCtrl()->GetItem(1,&hditem);
AfxGetApp()->WriteProfileInt("LAYOUT","crossposx",hditem.cxy);
m_lstCross.GetHeaderCtrl()->GetItem(2,&hditem);
AfxGetApp()->WriteProfileInt("LAYOUT","crossposy",hditem.cxy);
m_lstCross.GetHeaderCtrl()->GetItem(3,&hditem);
AfxGetApp()->WriteProfileInt("LAYOUT","crossname",hditem.cxy);
m_lstPath.GetHeaderCtrl()->GetItem(0,&hditem);
AfxGetApp()->WriteProfileInt("LAYOUT","pathid",hditem.cxy);
m_lstPath.GetHeaderCtrl()->GetItem(1,&hditem);
AfxGetApp()->WriteProfileInt("LAYOUT","pathidbegin",hditem.cxy);
m_lstPath.GetHeaderCtrl()->GetItem(2,&hditem);
AfxGetApp()->WriteProfileInt("LAYOUT","pathidend",hditem.cxy);
m_lstBS.GetHeaderCtrl()->GetItem(0,&hditem);
AfxGetApp()->WriteProfileInt("LAYOUT","bsid",hditem.cxy);
m_lstBS.GetHeaderCtrl()->GetItem(1,&hditem);
AfxGetApp()->WriteProfileInt("LAYOUT","bspathid",hditem.cxy);
m_lstBS.GetHeaderCtrl()->GetItem(2,&hditem);
AfxGetApp()->WriteProfileInt("LAYOUT","bsname",hditem.cxy);
m_lstStreet.GetHeaderCtrl()->GetItem(0,&hditem);
AfxGetApp()->WriteProfileInt("LAYOUT","streetid",hditem.cxy);
m_lstStreet.GetHeaderCtrl()->GetItem(1,&hditem);
AfxGetApp()->WriteProfileInt("LAYOUT","streetname",hditem.cxy);
m_lstAddress.GetHeaderCtrl()->GetItem(0,&hditem);
AfxGetApp()->WriteProfileInt("LAYOUT","addressid",hditem.cxy);
m_lstAddress.GetHeaderCtrl()->GetItem(1,&hditem);
AfxGetApp()->WriteProfileInt("LAYOUT","addressname",hditem.cxy);
m_lstAddress.GetHeaderCtrl()->GetItem(2,&hditem);
AfxGetApp()->WriteProfileInt("LAYOUT","addresstype",hditem.cxy);
m_lstAddress.GetHeaderCtrl()->GetItem(3,&hditem);
AfxGetApp()->WriteProfileInt("LAYOUT","addressposx",hditem.cxy);
m_lstAddress.GetHeaderCtrl()->GetItem(4,&hditem);
AfxGetApp()->WriteProfileInt("LAYOUT","addressposy",hditem.cxy);
m_lstTraffic.GetHeaderCtrl()->GetItem(0,&hditem);
AfxGetApp()->WriteProfileInt("LAYOUT","trafficid",hditem.cxy);
m_lstTraffic.GetHeaderCtrl()->GetItem(1,&hditem);
AfxGetApp()->WriteProfileInt("LAYOUT","trafficname",hditem.cxy);
m_lstTraffic.GetHeaderCtrl()->GetItem(2,&hditem);
AfxGetApp()->WriteProfileInt("LAYOUT","traffictype",hditem.cxy);
m_lstTraffic.GetHeaderCtrl()->GetItem(3,&hditem);
AfxGetApp()->WriteProfileInt("LAYOUT","trafficstation",hditem.cxy);
}
void CSTMObjBrowseDlg::OnDelete()
{
int index=m_ctrlMap[m_CurSel]->GetSelectionMark();
if(index!=-1)
{
CRgn effectrgn;
switch(m_CurSel)
{
case 0://cross
m_pDoc->RemoveCross(effectrgn,index);
break;
case 1://path
m_pDoc->RemovePath(effectrgn,index);
m_pDoc->SelectPath(index);
break;
case 2://bus station
m_pDoc->RemoveBS(effectrgn,index);
break;
case 3://traffic
m_pDoc->RemoveTR(index);
break;
case 4://street
m_pDoc->RemoveStreet(index);
break;
case 5://address
m_pDoc->RemoveAddress(effectrgn,index);
break;
}
if(HRGN(effectrgn))
{
CPoint pt=m_pView->GetScrollPosition();
effectrgn.OffsetRgn(-pt.x,-pt.y);
m_pView->InvalidateRgn(&effectrgn,FALSE);
}
OnRefresh();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -