mainfrm.cpp
来自「用VC+SuperMap开发的校园GIS系统」· C++ 代码 · 共 373 行
CPP
373 行
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "CampusGis.h"
#include "sodatasource.h"
#include "sodatasources.h"
#include "MainFrm.h"
#include "CreateDatasetDlg.h"
#include "AppendDatasetDlg.h"
#include "DatasetCopyDlg.h"
#include "Import1DatasetDlg.h"
#include "ExportDatasetDlg.h"
#include "CampusGisDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_COMMAND(IDD_FILE_WORKSPACE, OnOpenWorkspace)
ON_COMMAND(IDD_FILE_SAVEWORKSPACE, OnSaveworkspace)
ON_COMMAND(ID_FILE_SAVEAS_WORKSPACE, OnSaveasWorkspace)
ON_COMMAND(ID_FILE_CLOSE_WORKSPACE, OnCloseWorkspace)
ON_COMMAND(ID_FILE_NEW, OnFileNew)
ON_COMMAND(ID_CREATEDATASET, OnCreateDataset)
ON_COMMAND(ID_APPENDDATASETROW, OnAppenddatasetRow)
ON_COMMAND(ID_DATASETCOPY, OnDatasetCopy)
ON_COMMAND(ID_IMPORTDATASET, OnImportDataset)
ON_COMMAND(ID_EXPORTDATASET, OnExportDataset)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
m_pQueryDlg=new CQueryDlg();
}
CMainFrame::~CMainFrame()
{
if(m_pQueryDlg)
delete m_pQueryDlg;
m_SuperWorkspace.Close();
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
if(!m_SuperWorkspace.Create("superworkspace",WS_CHILD|WS_VISIBLE,
CRect(0,0,10,10),this,1,NULL,FALSE))
{
TRACE0("Failed to create superworkspace !\n");
return -1; // fail to create
}
if(!m_pQueryDlg->Create(IDD_QUERY,this))
{
TRACE0("Failed to create Query dialog\n");
return -1; //fail to create
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
if(!m_dlgBar.Create(this,IDD_MANAGER,CBRS_FLYBY|CBRS_TOOLTIPS|CBRS_LEFT,
IDD_MANAGER))
{
TRACE0("Failed to create manager dialog \n");
return -1; //fail to create
}
m_dlgBar.SetWindowPos(&m_wndStatusBar,0,0,0,0,NULL);
// m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
// EnableDocking(CBRS_ALIGN_ANY);
// DockControlBar(&m_wndToolBar);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CMDIFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
// define the MainFrame height and width
this->CenterWindow();
cs.cx =800;
cs.cy =600;
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CMDIFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CMDIFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::OnFileOpen()
{
//open the datasource (.sdb) type
CFileDialog dlg(true,NULL,NULL,OFN_OVERWRITEPROMPT,
"SuperMap Objects SDB File(*.sdb)|*.sdb|",NULL);
if(dlg.DoModal()==IDOK)
{
GetpApp()->OpenDocumentFile(dlg.m_ofn.lpstrFile);
this->WorkspManagerRefresh();
this->SupermapRefresh();
}
}
void CMainFrame::OnOpenWorkspace()
{
// open workspace
CFileDialog dlg(true,NULL,NULL,OFN_OVERWRITEPROMPT,
"SuperMapWorkspace File(*.smw)|*.smw|",NULL);
if(dlg.DoModal()==IDOK)
{
try
{
if(!m_SuperWorkspace.Open(dlg.GetPathName(),NULL))
{
AfxMessageBox("Failed to open workspace !");
return;
}
this->WorkspManagerRefresh();
}
catch(...)
{
AfxMessageBox("unknow error !");
}
}
}
void CMainFrame::OnSaveworkspace()
{
// save workspace
if(GetWorkspaceName().IsEmpty())
this->OnSaveasWorkspace();
else
m_SuperWorkspace.Save();
}
void CMainFrame::OnSaveasWorkspace()
{
// save as workspace
CFileDialog dlg(false,"smw",NULL,OFN_OVERWRITEPROMPT,
"SuperMapWorkspace File(*.smw)|*.smw|",NULL);
CString strName;
if(dlg.DoModal()==IDOK)
{
strName=dlg.GetFileName();
// TRACE("strName=%s\n",strName);
AfxMessageBox(strName);
if(!strName.IsEmpty())
m_SuperWorkspace.SaveAs((LPCTSTR)strName,false,false,"");
else
AfxMessageBox("workspace name is empty !");
}
}
CString CMainFrame::GetWorkspaceName() //get workspace's name
{
return m_SuperWorkspace.GetWorkspaceName();
}
void CMainFrame::WorkspManagerRefresh() //refresh manager window
{
GetManager()->Connect(m_SuperWorkspace.GetHandle());
GetManager()->Refresh();
}
void CMainFrame::OnCloseWorkspace()
{
// close workspace
int nRespond;
long nCount =m_SuperWorkspace.GetDatasources().GetCount();
for(long i=1;i<=nCount;i++)
{
CsoDataSource Datasource=m_SuperWorkspace.GetDatasources().GetItem(COleVariant(i,VT_I4));
CString strName="数据源 ";
strName=strName+Datasource.GetAlias();
strName=strName+"已经改变,是否保存?";
if(Datasource.GetModified() && Datasource.GetTransacted())
{
nRespond=MessageBox(strName,"消息框",MB_ICONQUESTION | MB_YESNO);
if(nRespond==IDYES)
Datasource.Commit();
}
//获得活动子帧窗口
CMDIChildWnd* pChild=(CMDIChildWnd*)GetActiveFrame();
CCampusGisDoc *pDoc=(CCampusGisDoc *)pChild->GetActiveDocument();
if(pDoc->m_bHasDatasource)
pDoc->OnCloseDocument();
}
this->WorkspManagerRefresh();
}
void CMainFrame::OnFileNew()
{
//新建数据源
CFileDialog dlg(false,NULL,NULL,OFN_OVERWRITEPROMPT,
"SuperMapDatasource File(*.sdb)|*.sdb|",NULL);
if(dlg.DoModal()==IDOK)
{
CsoDataSource source=m_SuperWorkspace.CreateDataSource(dlg.GetFileName(),
dlg.GetFileTitle(),0,false,false,false,NULL);
if(source)
AfxMessageBox("successed to create datasource !");
this->WorkspManagerRefresh();
}
}
void CMainFrame::OnCreateDataset()
{
//创建数据集
if(m_SuperWorkspace.GetDatasources().GetCount() > 0)
{
CCreateDatasetDlg dlg;
dlg.DoModal();
}
else
AfxMessageBox("工作空间中没有数据源 !");
}
void CMainFrame::OnAppenddatasetRow()
{
// 数据集追加行
if(m_SuperWorkspace.GetDatasources().GetCount() > 0)
{
CAppendDatasetDlg dlg;
dlg.DoModal();
}
else
AfxMessageBox("没有图层,不能追加 !");
}
BOOL CMainFrame::DestroyWindow()
{
try
{
GetManager()->Disconnect();
m_SuperWorkspace.Close();
}
catch(...)
{
TRACE0("workspace close error!");
}
return CMDIFrameWnd::DestroyWindow();
}
void CMainFrame::SupermapRefresh()
{
GetSuperMap()->Connect(m_SuperWorkspace.GetHandle());
GetSuperMap()->Refresh();
}
CSuperWkspManager* CMainFrame::GetManager()
{
CSuperWkspManager *manager=(CSuperWkspManager *)m_dlgBar.GetDlgItem(IDC_MANAGER);
return manager;
}
CSuperMap* CMainFrame::GetSuperMap()
{
CSuperMap *supermap=(CSuperMap *)m_dlgBar.GetDlgItem(IDC_SUPERMAP);
return supermap;
}
CCampusGisApp* CMainFrame::GetpApp()
{
CCampusGisApp *pApp = (CCampusGisApp*)::AfxGetApp();
return pApp;
}
void CMainFrame::OnDatasetCopy()
{
//数据集复制
if(m_SuperWorkspace.GetDatasources().GetCount() > 0)
{
CDatasetCopyDlg dlg;
dlg.DoModal();
}
else
AfxMessageBox("没有数据源可添加!");
}
void CMainFrame::OnImportDataset()
{
ImportDataset();
}
void CMainFrame::ImportDataset()
{
//导入数据集
if(m_SuperWorkspace.GetDatasources().GetCount() > 0)
{
CImport1DatasetDlg dlg;
dlg.DoModal();
}
else
AfxMessageBox("没有数据源,可添加!");
}
void CMainFrame::OnExportDataset()
{
//导出数据集
if(m_SuperWorkspace.GetDatasources().GetCount() > 0)
{
CExportDatasetDlg dlg;
dlg.DoModal();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?