campusgisdoc.cpp

来自「用VC+SuperMap开发的校园GIS系统」· C++ 代码 · 共 180 行

CPP
180
字号
// CampusGisDoc.cpp : implementation of the CCampusGisDoc class
//

#include "stdafx.h"
#include "CampusGis.h"

#include "CampusGisDoc.h"
#include "CampusGisView.h"
#include "afxdlgs.h"
#include "soDataSources.h"
#include "solayers.h"
#include "solayer.h"

#include "MainFrm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CCampusGisDoc

IMPLEMENT_DYNCREATE(CCampusGisDoc, CDocument)

BEGIN_MESSAGE_MAP(CCampusGisDoc, CDocument)
	//{{AFX_MSG_MAP(CCampusGisDoc)
	ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCampusGisDoc construction/destruction

CCampusGisDoc::CCampusGisDoc()
{
	// TODO: add one-time construction code here
	//get the handle of mainframe
	CMainFrame * pFrame=(CMainFrame *)::AfxGetMainWnd();
	//get mainframe's superworkspace object
	m_pSuperWorkspace=&pFrame->m_SuperWorkspace;
	//sign there has no datasource in document
	m_bHasDatasource=FALSE;


}

CCampusGisDoc::~CCampusGisDoc()
{
//	delete m_pManager;
}

BOOL CCampusGisDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)
	//sign there has no datasource in current document
	m_bHasDatasource=FALSE;

	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CCampusGisDoc serialization

void CCampusGisDoc::Serialize(CArchive& ar)
{	
	if (ar.IsStoring())
	{
		// TODO: add storing code here	
	}
	else
	{
		// TODO: add loading code here

	}

}

/////////////////////////////////////////////////////////////////////////////
// CCampusGisDoc diagnostics

#ifdef _DEBUG
void CCampusGisDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CCampusGisDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CCampusGisDoc commands

void CCampusGisDoc::OnFileOpen() 
{
	//open the datasource (.sdb) type 
	CFileDialog dlg(TRUE,NULL,NULL,OFN_OVERWRITEPROMPT,
		"SuperMap Objects SDB File(*.sdb)|*.sdb|",NULL);
	if(dlg.DoModal()==IDOK)
	{
		CCampusGisApp *pApp = (CCampusGisApp *)::AfxGetApp();
		pApp->OpenDocumentFile(dlg.m_ofn.lpstrFile);
		CMainFrame *pFrame=(CMainFrame *)(::AfxGetApp()->GetMainWnd());
		m_pManager=pFrame->GetManager();
//		m_pSupermap=pFrame->GetSuperMap();
//		m_pSupermap->Connect(pFrame->m_SuperWorkspace.GetHandle());
		m_pManager->Connect(pFrame->m_SuperWorkspace.GetHandle());
		m_pManager->Refresh();
//		m_pSupermap->Refresh();
	}
	
}

BOOL CCampusGisDoc::OnOpenDocument(LPCTSTR lpszPathName) 
{
	if (!CDocument::OnOpenDocument(lpszPathName))
		return FALSE;
	CFileFind find;
	if(!find.FindFile(lpszPathName))
	{
		AfxMessageBox("invaild filename !",MB_OK|MB_ICONINFORMATION);
		return FALSE;
	}
	find.FindNextFile();
	//record datasourceAlias so that can be useful when close the datasource
	m_strAliasOfDatasource=find.GetFileTitle();
	//open datasource
	if(!(m_CurDatasource=m_pSuperWorkspace->OpenDataSource(lpszPathName,
		m_strAliasOfDatasource,0,FALSE)))
	{
		AfxMessageBox("failed to open datasource !",MB_OK|MB_ICONSTOP);
		return FALSE;
	}
	//set the datasource auto release,or there will be have error
	m_CurDatasource.m_bAutoRelease=FALSE;
	//set current documet has datasource
	m_bHasDatasource=TRUE;

	return TRUE;
}

void CCampusGisDoc::OnCloseDocument() 
{
	//delete current datasource,or you cant not release datasource file
	CDocument::OnCloseDocument();
	if(m_bHasDatasource)
	{
		m_pSuperWorkspace->GetDatasources().Remove(COleVariant(m_strAliasOfDatasource));
	}
	CMainFrame *pFrame=(CMainFrame *)::AfxGetMainWnd();
	pFrame->WorkspManagerRefresh();
}

CView *CCampusGisDoc::GetView(CRuntimeClass *pClass)
{
	CView* pView;
    POSITION pos=GetFirstViewPosition();

    while(pos!=NULL)
    {
		pView=GetNextView(pos);
		if(pView->IsKindOf(pClass))
		break;
    }
    if(!pView->IsKindOf(pClass))
		return NULL;
    return pView;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?