📄 mapperdoc.cpp
字号:
// mapperDoc.cpp : implementation of the CMapperDoc class
//
#include "stdafx.h"
#include "mapper.h"
#include "mapperDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMapperDoc
IMPLEMENT_DYNCREATE(CMapperDoc, CDocument)
BEGIN_MESSAGE_MAP(CMapperDoc, CDocument)
//{{AFX_MSG_MAP(CMapperDoc)
ON_COMMAND(ID_MAP_EXPORT_EMP, OnMapExportEmp)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BEGIN_DISPATCH_MAP(CMapperDoc, CDocument)
//{{AFX_DISPATCH_MAP(CMapperDoc)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()
// Note: we add support for IID_IMapper to support typesafe binding
// from VBA. This IID must match the GUID that is attached to the
// dispinterface in the .ODL file.
// {7F1AE9F4-F6CE-4535-B398-2EFF4B192CAD}
static const IID IID_IMapper =
{ 0x7f1ae9f4, 0xf6ce, 0x4535, { 0xb3, 0x98, 0x2e, 0xff, 0x4b, 0x19, 0x2c, 0xad } };
BEGIN_INTERFACE_MAP(CMapperDoc, CDocument)
INTERFACE_PART(CMapperDoc, IID_IMapper, Dispatch)
END_INTERFACE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMapperDoc construction/destruction
CMapperDoc::CMapperDoc()
{
// TODO: add one-time construction code here
EnableAutomation();
AfxOleLockApp();
}
CMapperDoc::~CMapperDoc()
{
AfxOleUnlockApp();
}
BOOL CMapperDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
//需要处理,因为可能要打开其他的文件
if(theApp.GetMapPane()->m_map.m_hWnd)
{
theApp.GetMapPane()->m_map.GetLayers().Clear();
theApp.GetMapPane()->m_map.Refresh();
Eng_SetLegend(theApp.GetMapPane()->m_map,theApp.GetLayerPane()->m_legend);
theApp.m_taEli.RemoveAll();
SetPathName("无标题");
}
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMapperDoc serialization
void CMapperDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
CMapperView* pMap=theApp.GetMapPane();
CMapperLayerView* pLayer=theApp.GetLayerPane();
COleDateTime dt=COleDateTime::GetCurrentTime();
CString s,s1;
CMainFrame *pWnd=(CMainFrame*)theApp.GetMainWnd();
theApp.m_tMapInfo.iLayers=pMap->m_map.GetLayers().GetCount();
strcpy(theApp.m_tHeader.szAuthor,"Mapper");
strcpy(theApp.m_tHeader.szCompany,"ZcSoft");
s.Format("%04d-%02d-%02d %02d:%02d:%02d",dt.GetYear(),dt.GetMonth(),dt.GetDay(),
dt.GetHour(),dt.GetMinute(),dt.GetSecond());
s1=theApp.m_tHeader.szCreateTime;
if(s1=="")
strcpy(theApp.m_tHeader.szCreateTime,s);
strcpy(theApp.m_tHeader.szModifyTime,s);
strcpy(theApp.m_tHeader.szText,"This is a new file!");
theApp.m_tMapInfo.crBack=pMap->m_map.GetBackColor();
ar.Write(&theApp.m_tHeader,sizeof(SMpfHeader));
ar.Write(&theApp.m_tMapInfo,sizeof(SMpfMapInfo));
SMpfLayerInfo mli;
//需要在下次打开时候保持原来顺序
for(int i=(theApp.m_tMapInfo.iLayers-1);i>=0;i--)
{
memset(&mli,0,sizeof(SMpfLayerInfo));
Sub_GetLayerInfo(i,mli);
ar.Write(&mli,sizeof(SMpfLayerInfo));
}
//建立预览图像
CString sPathFile=GetPathName();
sPathFile.MakeLower();
if(sPathFile.Replace(".epf",".bmp")>0)
pMap->m_map.ExportMap(moExportBMP,sPathFile,1);
}
else
{
theApp.m_taEli.RemoveAll();
ar.Read(&theApp.m_tHeader,sizeof(SMpfHeader));
if(theApp.m_tHeader.mpf==20030618)
{
ar.Read(&theApp.m_tMapInfo,sizeof(SMpfMapInfo));
SMpfLayerInfo eli;
for(int i=0;i<theApp.m_tMapInfo.iLayers;i++)
{
ar.Read(&eli,sizeof(SMpfLayerInfo));
theApp.m_taEli.Add(eli);
}
// theApp.m_bOpen=TRUE;
}
}
}
/////////////////////////////////////////////////////////////////////////////
// CMapperDoc diagnostics
#ifdef _DEBUG
void CMapperDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CMapperDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMapperDoc commands
void CMapperDoc::Sub_GetLayerInfo(short iLayer, SMpfLayerInfo &mli)
{
//活动图层的显示信息,不保存选择状态信息
CMoLayers layers(theApp.GetMapPane()->m_map.GetLayers());
short count=layers.GetCount();
if(iLayer>=count)
return;
if(GetLayerType(layers,iLayer)==moMapLayer)
{
CMoMapLayer layer(layers.Item(COleVariant(iLayer)));
CMoSymbol sym=layer.GetSymbol();
strcpy(mli.szType,layer.GetTag().Left(3));
strcpy(mli.szPathFile,layer.GetTag().Mid(3));
mli.iStyle=sym.GetStyle();
mli.iSize=sym.GetSize();
mli.crColor=sym.GetColor();
long iType=layer.GetShapeType();
switch(iType)
{
case moPoint:
mli.crOutlinColor=sym.GetOutlineColor();
mli.bOutline=sym.GetOutline();
break;
case moLine:
break;
case moPolygon:
mli.crOutlinColor=sym.GetOutlineColor();
mli.bOutline=sym.GetOutline();
break;
}
}
if(GetLayerType(layers,iLayer)==moImageLayer)
{
CMoImageLayer layer(layers.Item(COleVariant(iLayer)));
strcpy(mli.szType,layer.GetTag().Left(3));
strcpy(mli.szPathFile,layer.GetTag().Mid(3));
mli.crOutlinColor=layer.GetTransparentColor();
mli.bOutline=layer.GetTransparent();
}
}
void CMapperDoc::OnMapExportEmp()
{
CMapperView* pMap=theApp.GetMapPane();
CMapperLayerView* pLayer=theApp.GetLayerPane();
CString s,s1;
CMainFrame *pWnd=(CMainFrame*)theApp.GetMainWnd();
theApp.m_tMapInfo.iLayers=pMap->m_map.GetLayers().GetCount();
FILE *f;
CFileDialog fd(FALSE,"emp",NULL,OFN_EXPLORER|OFN_HIDEREADONLY|OFN_ALLOWMULTISELECT,
"ES地图文件文件(*.emp)|*.emp||",NULL);
if(fd.DoModal())
{
if((f=fopen(fd.GetPathName(),"wt"))==NULL)
{
AfxMessageBox("无法建立指定文件!终止处理!");
return;
}
SMpfLayerInfo mli;
//需要在下次打开时候保持原来顺序
CString sDir,sFile;
for(int i=(theApp.m_tMapInfo.iLayers-1);i>=0;i--)
{
memset(&mli,0,sizeof(SMpfLayerInfo));
Sub_GetLayerInfo(i,mli);
if(i==(theApp.m_tMapInfo.iLayers-1))
{
//保存路径
Eng_GetPathOfPathFile(mli.szPathFile,sDir);
fprintf(f,"%ld,%s\n",pMap->m_map.GetBackColor(),sDir);
}
Eng_GetFileOfPathFile(mli.szPathFile,sFile);
fprintf(f,"%ld,%s\n",mli.crColor,sFile);
}
fclose(f);
}
AfxMessageBox("输出完毕!");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -