campusgisview.cpp
来自「用VC+SuperMap开发的校园GIS系统」· C++ 代码 · 共 837 行 · 第 1/2 页
CPP
837 行
// CampusGisView.cpp : implementation of the CCampusGisView class
//
#include "stdafx.h"
#include "CampusGis.h"
#include "CampusGisDoc.h"
#include "CampusGisView.h"
#include "sodatasources.h"
#include "sodatasource.h"
#include "sodatasets.h"
#include "sodataset.h"
#include "solayers.h"
#include "solayer.h"
#include "soselection.h"
#include "sodatasetvector.h"
#include "sogeoline.h"
#include "sostyle.h"
#include "sotrackinglayer.h"
#include "sogeometry.h"
#include "somaps.h"
#include "QueryDlg.h"
#include "MainFrm.h"
#include "ManagerDlg.h"
#include "SpatialInfoDlg.h"
#include "TypeReformDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCampusGisView
IMPLEMENT_DYNCREATE(CCampusGisView, CView)
BEGIN_MESSAGE_MAP(CCampusGisView, CView)
//{{AFX_MSG_MAP(CCampusGisView)
ON_WM_CREATE()
ON_WM_SIZE()
ON_WM_DESTROY()
ON_COMMAND(ID_VIEW_ZOOMIN, OnViewZoomin)
ON_COMMAND(ID_VIEW_ZOOMOUT, OnViewZoomout)
ON_COMMAND(ID_VIEW_ENTIRE, OnViewEntire)
ON_COMMAND(ID_VIEW_PAN, OnViewPan)
ON_COMMAND(ID_VIEW_ZOOMFREE, OnViewZoomfree)
ON_COMMAND(ID_VIEW_REFRESH, OnViewRefresh)
ON_COMMAND(ID_VIEW_CIRCLE_SELECT, OnViewCircleSelect)
ON_COMMAND(ID_VIEW_RECSELECT, OnViewRecselect)
ON_COMMAND(ID_VIEW_POINTSELECT, OnViewPointselect)
ON_COMMAND(ID_VIEW_FIND, OnViewFind)
ON_UPDATE_COMMAND_UI(ID_VIEW_FIND, OnUpdateViewFind)
ON_COMMAND(ID_VIEW_LEGEND, OnViewLegend)
ON_UPDATE_COMMAND_UI(ID_VIEW_LEGEND, OnUpdateViewLegend)
ON_COMMAND(ID_EDIT_UNDO, OnEditUndo)
ON_COMMAND(ID_EDIT_DELETE, OnEditDelete)
ON_COMMAND(ID_EDIT_CUT, OnEditCut)
ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)
ON_COMMAND(ID_JOINOBJECT, OnLinkobject)
ON_COMMAND(ID_ADDNODE, OnAddNode)
ON_COMMAND(ID_EDITNODE, OnEditNode)
ON_COMMAND(ID_CATCHSET, OnCatchSet)
ON_COMMAND(ID_SPATIALINFO, OnSpatialInfo)
ON_COMMAND(ID_PROPREYINFO, OnPropreyInfo)
ON_COMMAND(ID_DELETEDATASET, OnDeleteDataset)
ON_COMMAND(ID_CREATEPOINT, OnCreatePoint)
ON_COMMAND(ID_CREATELINE, OnCreateLine)
ON_COMMAND(ID_PYLONLINE, OnPylonLine)
ON_COMMAND(ID_CREATE_CURVELINE, OnCreateCurveLine)
ON_COMMAND(ID_CREATEPYLON, OnCreatePylon)
ON_COMMAND(ID_CREATEAREA, OnCreateArea)
ON_COMMAND(ID_CREATEXYCIRCLE, OnCreateEllipse)
ON_COMMAND(ID_CREATECOMMONSIGN, OnCreateCommonText)
ON_COMMAND(ID_CREATELINESIGN, OnCreateLineText)
ON_COMMAND(ID_SAVEMAP, OnSaveMap)
ON_COMMAND(ID_FILE_NEW, OnFileNew)
ON_COMMAND(ID_SAVEASMAP, OnSaveasMap)
ON_COMMAND(ID_MAPBILI, OnMapScaleSet)
ON_COMMAND(ID_LINETOREGION, OnLineToRegion)
ON_COMMAND(ID_REGIONTOLINE, OnRegionToLine)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//added by me
BEGIN_EVENTSINK_MAP(CCampusGisView, CView)
//{{AFX_EVENTSINK_MAP(CCampusGisView)
ON_EVENT(CCampusGisView, 1, -601 /* DblClick */, OnDblClickSupermap, VTS_NONE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCampusGisView construction/destruction
CCampusGisView::CCampusGisView()
{
// TODO: add construction code here
m_pInfoDlg=NULL;
m_pLegendDlg=NULL;
m_pSpatialDlg=NULL;
m_pScaleSetDlg=NULL;
}
CCampusGisView::~CCampusGisView()
{
if(m_pInfoDlg)
{
delete m_pInfoDlg;
}
if(m_pLegendDlg)
{
delete m_pLegendDlg;
}
if(m_pScaleSetDlg)
{
delete m_pScaleSetDlg;
}
if(m_pSpatialDlg)
{
delete m_pSpatialDlg;
}
}
BOOL CCampusGisView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CCampusGisView drawing
void CCampusGisView::OnDraw(CDC* pDC)
{
CCampusGisDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CCampusGisView diagnostics
#ifdef _DEBUG
void CCampusGisView::AssertValid() const
{
CView::AssertValid();
}
void CCampusGisView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CCampusGisDoc* CCampusGisView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCampusGisDoc)));
return (CCampusGisDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CCampusGisView message handlers
int CCampusGisView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// create supermap control instance
m_Supermap.Create("supermap",WS_CHILD|WS_VISIBLE,CRect(0,0,10,10),this,1,NULL,FALSE);
return 0;
}
void CCampusGisView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
// adjust supermap window to view window
if(nType==SIZE_RESTORED)
{
CRect rc;
GetClientRect(rc);
if(m_Supermap.GetSafeHwnd())
{
m_Supermap.MoveWindow(rc);
}
}
}
void CCampusGisView::OnInitialUpdate()
{
CView::OnInitialUpdate();
CCampusGisDoc* pDoc=GetDocument();
ASSERT_VALID(pDoc);
//if opened datasource file, add it to supermap window
if(!pDoc->m_bHasDatasource)
return;
//connect supermap control with superworkspace control
if(!m_Supermap.Connect(pDoc->m_pSuperWorkspace->GetHandle()))
return;
//get datasource's datasets from document
CsoDataSource datasource;
datasource=pDoc->m_CurDatasource;
CsoDatasets datasets=datasource.GetDatasets();
//if datasets number is zero ,quit
if(datasets.GetCount()==0)
return;
//add all datasets to supermap window
CsoLayers layers=m_Supermap.GetLayers();
for(long i=1; i<=datasets.GetCount();i++)
{
layers.AddDataset(datasets.GetItem(COleVariant(i,VT_I4 )),FALSE);
}
//refresh supermap window
m_Supermap.Refresh();
//record window's state
m_strDatasourceAlias=pDoc->m_strAliasOfDatasource;
bExist=FALSE;
}
void CCampusGisView::OnDestroy()
{
long LayersCount=m_Supermap.GetLayers().GetCount();
CsoLayer layer=m_Supermap.GetLayers().GetEditableLayer();
try
{
if(LayersCount > 0)
{
m_Supermap.SetAction(5);
layer.SetEditable(0);
m_Supermap.GetLayers().RemoveAll();
}
if(m_pLegendDlg)
m_pLegendDlg->m_Legend.Disconnect();
m_Supermap.Refresh();
m_Supermap.Disconnect();
if(GetDocument()->m_bHasDatasource)
{
GetDocument()->m_pSuperWorkspace->GetDatasources().Remove(COleVariant(m_strDatasourceAlias));
}
CMainFrame *pFrame=(CMainFrame *)::AfxGetMainWnd();
pFrame->WorkspManagerRefresh();
m_Supermap.Close();
}
catch(...)
{
TRACE0("supermap close error !");
}
CView::OnDestroy();
}
void CCampusGisView::OnViewZoomin()
{
//zoomIn map
m_Supermap.SetAction(2);
}
void CCampusGisView::OnViewZoomout()
{
// ZoomOut map
m_Supermap.SetAction(3);
}
void CCampusGisView::OnViewEntire()
{
// TODO: Add your command handler code here
m_Supermap.ViewEntire();
}
void CCampusGisView::OnViewPan()
{
// TODO: Add your command handler code here
m_Supermap.SetAction(1);
}
void CCampusGisView::OnViewZoomfree()
{
// TODO: Add your command handler code here
m_Supermap.SetAction(4);
}
void CCampusGisView::OnViewRefresh()
{
// TODO: Add your command handler code here
m_Supermap.Refresh();
}
void CCampusGisView::OnViewCircleSelect()
{
// TODO: Add your command handler code here
m_Supermap.SetAction(7);
}
void CCampusGisView::OnViewRecselect()
{
// TODO: Add your command handler code here
m_Supermap.SetAction(6);
}
void CCampusGisView::OnViewPointselect()
{
// TODO: Add your command handler code here
m_Supermap.SetAction(5);
}
void CCampusGisView::OnDblClickSupermap()
{
//没有选中地图元素则退出
if(!m_Supermap.GetSelection())
{
AfxMessageBox("没有选中地图元素!");
return;
}
CsoRecordset recordset;
//选中的地图元素不能转换成数据集则退出
if(!(recordset=m_Supermap.GetSelection().ToRecordset(FALSE)))
{
AfxMessageBox("选中的地图元素不能转换成数据集!");
return;
}
//信息对话框已经存在,激活,否则创建
if(m_pInfoDlg)
{
m_pInfoDlg->GetActiveWindow();
}
else
{
m_pInfoDlg=new CInfoDlg();
m_pInfoDlg->Create(IDD_INFO);
}
//将记录集对象的指针传给属性窗口
m_pInfoDlg->InsertRecordset(&recordset);
//设置窗口的显示与位置
m_pInfoDlg->ShowWindow(SW_SHOW);
m_pInfoDlg->SetWindowPos(NULL,0,0,100,100,SWP_NOSIZE|SWP_NOMOVE);
m_pInfoDlg->MoveWindow(200,200,200,300,TRUE);
m_pInfoDlg->SetWindowText("属性窗口:" + m_strDatasourceAlias);
}
void CCampusGisView::OnViewFind()
{
//首先获得查询窗口的指针
CQueryDlg *pQueryDlg;
CMainFrame *pFrame=(CMainFrame *)::AfxGetMainWnd();
pQueryDlg=pFrame->m_pQueryDlg;
if(!pQueryDlg->IsWindowVisible())
{
pQueryDlg->SetParentSupermap(&m_Supermap);
pQueryDlg->RefreshContent();
pQueryDlg->ShowWindow(SW_SHOW);
}
else
{
pQueryDlg->ShowWindow(SW_HIDE);
}
}
void CCampusGisView::OnUpdateViewFind(CCmdUI* pCmdUI)
{
//根据查询窗口是否可见决定工具条的状态
CQueryDlg *pQueryDlg;
CMainFrame * pFrame=(CMainFrame *)::AfxGetMainWnd();
pQueryDlg=pFrame->m_pQueryDlg;
if(pQueryDlg->IsWindowVisible())
pCmdUI->SetCheck(1);
else
pCmdUI->SetCheck(0);
}
void CCampusGisView::OnViewLegend()
{
//首先判断图例窗口是否存在,存在激活即可
//否则创建一个图例窗口,并与地图窗口连接
if(!m_pLegendDlg)
{
m_pLegendDlg=new CLegendDlg;
m_pLegendDlg->Create(IDD_LEGEND,this);
//连接图例和地图窗口
m_pLegendDlg->m_Legend.Connect(m_Supermap.GetHandle());
m_pLegendDlg->m_pSupermap=&m_Supermap;
// CCampusGisDoc *pDoc=GetDocument();
m_pLegendDlg->SetWindowText("图例:" + m_strDatasourceAlias);
m_pLegendDlg->SetWindowPos(NULL,100,100,100,100,SWP_NOSIZE);
m_pLegendDlg->ShowWindow(SW_SHOW);
return;
}
else
{
if(!m_pLegendDlg->IsWindowVisible())
m_pLegendDlg->ShowWindow(SW_SHOW);
else
m_pLegendDlg->ShowWindow(SW_HIDE);
}
m_pLegendDlg->m_Legend.Refresh();
}
void CCampusGisView::OnUpdateViewLegend(CCmdUI* pCmdUI)
{
if(!m_pLegendDlg)
pCmdUI->SetCheck(0);
else
{
pCmdUI->SetCheck(m_pLegendDlg->IsWindowVisible());
return;
}
pCmdUI->SetCheck(0);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?