📄 mappershape.cpp
字号:
// MapperShape.cpp: implementation of the CMapperShape class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "mapper.h"
#include "MapperShape.h"
#include "pointeditdlg.h"
#include "lineeditdlg.h"
#include "recteditdlg.h"
#include "shapedatadlg.h"
#include "shapetextdlg.h"
#include "PointSetupDlg.h"
#include "LineSetupDlg.h"
#include "PolySetupDlg.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CMapperShape::CMapperShape()
{
m_tSel.index=-1;
m_tSel.type=-1;
m_tPointInfo.bOutline=TRUE;
m_tPointInfo.color=RGB(255,0,0);
m_tPointInfo.outlineColor=RGB(0,0,0);
m_tPointInfo.pts=0;
m_tPointInfo.shape=1;
m_tPointInfo.size=5;
m_tPointInfo.style=0;
strcpy(m_tPointInfo.text,"");
m_tLineInfo=m_tPointInfo;
m_tLineInfo.shape=2;
m_tLineInfo.size=1;
m_tRectInfo=m_tPointInfo;
m_tRectInfo.shape=3;
m_tRectInfo.size=1;
m_tCircleInfo=m_tPointInfo;
m_tCircleInfo.shape=4;
m_tCircleInfo.size=1;
m_tEllipseInfo=m_tPointInfo;
m_tEllipseInfo.shape=5;
m_tEllipseInfo.size=1;
m_tPolyInfo=m_tPointInfo;
m_tPolyInfo.shape=6;
m_tPolyInfo.size=1;
}
CMapperShape::~CMapperShape()
{
mo_ReleasePoints();
mo_ReleaseLines();
mo_ReleaseRects();
mo_ReleaseCircles();
mo_ReleaseEllipses();
mo_ReleasePolys();
mo_ReleaseTexts();
}
void CMapperShape::mo_ReleasePoints()
{
for (int i = 0; i < m_oaPoints.GetSize(); i++)
{
m_oaPoints[i]->ReleaseDispatch();
delete m_oaPoints[i];
}
m_oaPoints.RemoveAll();
}
void CMapperShape::mo_ReleaseLines()
{
for (int i = 0; i < m_oaLines.GetSize(); i++)
{
m_oaLines[i]->ReleaseDispatch();
delete m_oaLines[i];
}
m_oaLines.RemoveAll();
}
void CMapperShape::mo_ReleaseRects()
{
int i;
for (i = 0; i < m_oaRects.GetSize(); i++)
{
m_oaRects[i]->ReleaseDispatch();
delete m_oaRects[i];
}
m_oaRects.RemoveAll();
}
void CMapperShape::mo_ReleaseCircles()
{
int i;
for (i = 0; i < m_oaCircles.GetSize(); i++)
{
m_oaCircles[i]->ReleaseDispatch();
delete m_oaCircles[i];
}
m_oaCircles.RemoveAll();
}
void CMapperShape::mo_ReleaseEllipses()
{
int i;
for (i = 0; i < m_oaEllipses.GetSize(); i++)
{
m_oaEllipses[i]->ReleaseDispatch();
delete m_oaEllipses[i];
}
m_oaEllipses.RemoveAll();
}
void CMapperShape::mo_ReleasePolys()
{
int i;
for (i = 0; i < m_oaPolys.GetSize(); i++)
{
m_oaPolys[i]->ReleaseDispatch();
delete m_oaPolys[i];
}
m_oaPolys.RemoveAll();
}
void CMapperShape::mo_ReleaseTexts()
{
int i;
for (i = 0; i < m_oaTexts.GetSize(); i++)
{
m_oaTexts[i]->line->ReleaseDispatch();
delete m_oaTexts[i]->line;
delete m_oaTexts[i];
}
m_oaTexts.RemoveAll();
}
BOOL CMapperShape::mo_ExportPoints(CString sPathFile)
{
CMoDataConnection conn;
if (!conn.CreateDispatch(TEXT("MapObjects2.DataConnection")))
return FALSE;
conn.SetDatabase(GetFileDirectory(sPathFile));
if (!conn.Connect())
return FALSE;
CMoTableDesc tableDesc;
if (!tableDesc.CreateDispatch(TEXT("MapObjects2.TableDesc")))
return FALSE;
tableDesc.SetFieldCount(3);
tableDesc.SetFieldName(0, TEXT("Name"));
tableDesc.SetFieldType(0, moString);
tableDesc.SetFieldLength(0, 16);
tableDesc.SetFieldName(1, TEXT("Area"));
tableDesc.SetFieldType(1, moDouble);
tableDesc.SetFieldPrecision(1, 15);
tableDesc.SetFieldScale(1, 3); // decimal places
tableDesc.SetFieldName(2, TEXT("Perimeter"));
tableDesc.SetFieldType(2, moDouble);
tableDesc.SetFieldPrecision(2, 15);
tableDesc.SetFieldScale(2, 3); // decimal places
VARIANT va;
VariantInit(&va);
va.vt = VT_BOOL;
va.boolVal = false;
CMoGeoDataset geoDataset(conn.AddGeoDataset(GetFileTitle(sPathFile), moPoint, tableDesc, va, va));
CMoMapLayer layer;
if (!layer.CreateDispatch(TEXT("MapObjects2.MapLayer")))
return FALSE;
layer.SetGeoDataset(geoDataset);
CMoRecordset recs(layer.GetRecords());
CMoFields fields(recs.GetFields());
CString featureName;
for (int i = 0; i < m_oaPoints.GetSize(); i++)
{
recs.AddNew();
SetValue(fields, TEXT("Shape"), LPDISPATCH(*m_oaPoints[i]));
featureName.Format("%s%d", "point", i);
SetValue(fields, TEXT("Name"), featureName);
SetValue(fields, TEXT("Area"), 0.0);
SetValue(fields, TEXT("Perimeter"), 0.0);
recs.Update();
}
mo_ReleasePoints();
return TRUE;
}
BOOL CMapperShape::mo_ExportLines(CString sPathFile)
{
CMoDataConnection conn;
if (!conn.CreateDispatch(TEXT("MapObjects2.DataConnection")))
return FALSE;
conn.SetDatabase(GetFileDirectory(sPathFile));
if (!conn.Connect())
return FALSE;
CMoTableDesc tableDesc;
if (!tableDesc.CreateDispatch(TEXT("MapObjects2.TableDesc")))
return FALSE;
tableDesc.SetFieldCount(3);
tableDesc.SetFieldName(0, TEXT("Name"));
tableDesc.SetFieldType(0, moString);
tableDesc.SetFieldLength(0, 16);
tableDesc.SetFieldName(1, TEXT("Area"));
tableDesc.SetFieldType(1, moDouble);
tableDesc.SetFieldPrecision(1, 15);
tableDesc.SetFieldScale(1, 3); // decimal places
tableDesc.SetFieldName(2, TEXT("Perimeter"));
tableDesc.SetFieldType(2, moDouble);
tableDesc.SetFieldPrecision(2, 15);
tableDesc.SetFieldScale(2, 3); // decimal places
VARIANT va;
VariantInit(&va);
va.vt = VT_BOOL;
va.boolVal = false;
CMoGeoDataset geoDataset(conn.AddGeoDataset(GetFileTitle(sPathFile), moLine, tableDesc, va ,va));
ASSERT(LPDISPATCH(geoDataset));
CMoMapLayer layer;
if (!layer.CreateDispatch(TEXT("MapObjects2.MapLayer")))
return FALSE;
layer.SetGeoDataset(geoDataset);
CMoRecordset recs(layer.GetRecords());
CMoFields fields(recs.GetFields());
CString featureName;
for (int i = 0; i < m_oaLines.GetSize(); i++)
{
recs.AddNew();
SetValue(fields, TEXT("Shape"), LPDISPATCH(*m_oaLines[i]));
featureName.Format("%s%d", "line", i);
SetValue(fields, TEXT("Name"), featureName);
SetValue(fields, TEXT("Area"), 0.0);
SetValue(fields, TEXT("Perimeter"), m_oaLines[i]->GetLength());
recs.Update();
}
mo_ReleaseLines();
return TRUE;
}
BOOL CMapperShape::mo_ExportRects(CString sPathFile)
{
CMoDataConnection conn;
if (!conn.CreateDispatch(TEXT("MapObjects2.DataConnection")))
return FALSE;
conn.SetDatabase(GetFileDirectory(sPathFile));
if (!conn.Connect())
return FALSE;
CMoTableDesc tableDesc;
if (!tableDesc.CreateDispatch(TEXT("MapObjects2.TableDesc")))
return FALSE;
tableDesc.SetFieldCount(3);
tableDesc.SetFieldName(0, TEXT("Name"));
tableDesc.SetFieldType(0, moString);
tableDesc.SetFieldLength(0, 16);
tableDesc.SetFieldName(1, TEXT("Area"));
tableDesc.SetFieldType(1, moDouble);
tableDesc.SetFieldPrecision(1, 15);
tableDesc.SetFieldScale(1, 3); // decimal places
tableDesc.SetFieldName(2, TEXT("Perimeter"));
tableDesc.SetFieldType(2, moDouble);
tableDesc.SetFieldPrecision(2, 15);
tableDesc.SetFieldScale(2, 3); // decimal places
VARIANT va;
VariantInit(&va);
va.vt = VT_BOOL;
va.boolVal = false;
CMoGeoDataset geoDataset(conn.AddGeoDataset(GetFileTitle(sPathFile), moPolygon, tableDesc, va ,va));
CMoMapLayer layer;
if (!layer.CreateDispatch(TEXT("MapObjects2.MapLayer")))
return FALSE;
layer.SetGeoDataset(geoDataset);
CMoRecordset recs(layer.GetRecords());
CMoFields fields(recs.GetFields());
CString featureName;
CMoPolygon poly;
CMoRectangle rect;
VARIANT va1;
VariantInit(&va1);
for (int i = 0; i < m_oaRects.GetSize(); i++)
{
rect.CreateDispatch(TEXT("MapObjects2.Rectangle"));
poly.CreateDispatch(TEXT("MapObjects2.Polygon"));
rect=*m_oaRects[i];
recs.AddNew();
poly=rect.Buffer(0.0,va1);
SetValue(fields, TEXT("Shape"), LPDISPATCH(poly));
featureName.Format("%s%d", "poly", i);
SetValue(fields, TEXT("Name"), featureName);
SetValue(fields, TEXT("Area"), poly.GetArea());
SetValue(fields, TEXT("Perimeter"), poly.GetPerimeter());
recs.Update();
rect.ReleaseDispatch();
poly.ReleaseDispatch();
}
mo_ReleaseRects();
return TRUE;
}
BOOL CMapperShape::mo_ExportCircles(CString sPathFile)
{
CMoDataConnection conn;
if (!conn.CreateDispatch(TEXT("MapObjects2.DataConnection")))
return FALSE;
conn.SetDatabase(GetFileDirectory(sPathFile));
if (!conn.Connect())
return FALSE;
CMoTableDesc tableDesc;
if (!tableDesc.CreateDispatch(TEXT("MapObjects2.TableDesc")))
return FALSE;
tableDesc.SetFieldCount(3);
tableDesc.SetFieldName(0, TEXT("Name"));
tableDesc.SetFieldType(0, moString);
tableDesc.SetFieldLength(0, 16);
tableDesc.SetFieldName(1, TEXT("Area"));
tableDesc.SetFieldType(1, moDouble);
tableDesc.SetFieldPrecision(1, 15);
tableDesc.SetFieldScale(1, 3); // decimal places
tableDesc.SetFieldName(2, TEXT("Perimeter"));
tableDesc.SetFieldType(2, moDouble);
tableDesc.SetFieldPrecision(2, 15);
tableDesc.SetFieldScale(2, 3); // decimal places
VARIANT va;
VariantInit(&va);
va.vt = VT_BOOL;
va.boolVal = false;
CMoGeoDataset geoDataset(conn.AddGeoDataset(GetFileTitle(sPathFile), moPolygon, tableDesc, va ,va));
CMoMapLayer layer;
if (!layer.CreateDispatch(TEXT("MapObjects2.MapLayer")))
return FALSE;
layer.SetGeoDataset(geoDataset);
CMoRecordset recs(layer.GetRecords());
CMoFields fields(recs.GetFields());
CString featureName;
CMoPolygon poly;
CMoEllipse circle;
VARIANT va1;
VariantInit(&va1);
for (int i = 0; i < m_oaCircles.GetSize(); i++)
{
circle.CreateDispatch(TEXT("MapObjects2.Ellipse"));
poly.CreateDispatch(TEXT("MapObjects2.Polygon"));
circle=*m_oaCircles[i];
recs.AddNew();
poly=circle.Buffer(0.0,va1);
SetValue(fields, TEXT("Shape"), LPDISPATCH(poly));
featureName.Format("%s%d", "poly", i);
SetValue(fields, TEXT("Name"), featureName);
SetValue(fields, TEXT("Area"), poly.GetArea());
SetValue(fields, TEXT("Perimeter"), poly.GetPerimeter());
recs.Update();
circle.ReleaseDispatch();
poly.ReleaseDispatch();
}
mo_ReleaseCircles();
return TRUE;
}
BOOL CMapperShape::mo_ExportEllipses(CString sPathFile)
{
CMoDataConnection conn;
if (!conn.CreateDispatch(TEXT("MapObjects2.DataConnection")))
return FALSE;
conn.SetDatabase(GetFileDirectory(sPathFile));
if (!conn.Connect())
return FALSE;
CMoTableDesc tableDesc;
if (!tableDesc.CreateDispatch(TEXT("MapObjects2.TableDesc")))
return FALSE;
tableDesc.SetFieldCount(3);
tableDesc.SetFieldName(0, TEXT("Name"));
tableDesc.SetFieldType(0, moString);
tableDesc.SetFieldLength(0, 16);
tableDesc.SetFieldName(1, TEXT("Area"));
tableDesc.SetFieldType(1, moDouble);
tableDesc.SetFieldPrecision(1, 15);
tableDesc.SetFieldScale(1, 3); // decimal places
tableDesc.SetFieldName(2, TEXT("Perimeter"));
tableDesc.SetFieldType(2, moDouble);
tableDesc.SetFieldPrecision(2, 15);
tableDesc.SetFieldScale(2, 3); // decimal places
VARIANT va;
VariantInit(&va);
va.vt = VT_BOOL;
va.boolVal = false;
CMoGeoDataset geoDataset(conn.AddGeoDataset(GetFileTitle(sPathFile), moPolygon, tableDesc, va ,va));
CMoMapLayer layer;
if (!layer.CreateDispatch(TEXT("MapObjects2.MapLayer")))
return FALSE;
layer.SetGeoDataset(geoDataset);
CMoRecordset recs(layer.GetRecords());
CMoFields fields(recs.GetFields());
CString featureName;
CMoPolygon poly;
CMoEllipse ellipse;
VARIANT va1;
VariantInit(&va1);
for (int i = 0; i < m_oaEllipses.GetSize(); i++)
{
ellipse.CreateDispatch(TEXT("MapObjects2.Ellipse"));
poly.CreateDispatch(TEXT("MapObjects2.Polygon"));
ellipse=*m_oaEllipses[i];
recs.AddNew();
poly=ellipse.Buffer(0.0,va1);
SetValue(fields, TEXT("Shape"), LPDISPATCH(poly));
featureName.Format("%s%d", "poly", i);
SetValue(fields, TEXT("Name"), featureName);
SetValue(fields, TEXT("Area"), poly.GetArea());
SetValue(fields, TEXT("Perimeter"), poly.GetPerimeter());
recs.Update();
ellipse.ReleaseDispatch();
poly.ReleaseDispatch();
}
mo_ReleaseEllipses();
return TRUE;
}
BOOL CMapperShape::mo_ExportPolys(CString sPathFile)
{
CMoDataConnection conn;
if (!conn.CreateDispatch(TEXT("MapObjects2.DataConnection")))
return FALSE;
conn.SetDatabase(GetFileDirectory(sPathFile));
if (!conn.Connect())
return FALSE;
CMoTableDesc tableDesc;
if (!tableDesc.CreateDispatch(TEXT("MapObjects2.TableDesc")))
return FALSE;
tableDesc.SetFieldCount(3);
tableDesc.SetFieldName(0, TEXT("Name"));
tableDesc.SetFieldType(0, moString);
tableDesc.SetFieldLength(0, 16);
tableDesc.SetFieldName(1, TEXT("Area"));
tableDesc.SetFieldType(1, moDouble);
tableDesc.SetFieldPrecision(1, 15);
tableDesc.SetFieldScale(1, 3); // decimal places
tableDesc.SetFieldName(2, TEXT("Perimeter"));
tableDesc.SetFieldType(2, moDouble);
tableDesc.SetFieldPrecision(2, 15);
tableDesc.SetFieldScale(2, 3); // decimal places
VARIANT va;
VariantInit(&va);
va.vt = VT_BOOL;
va.boolVal = false;
CMoGeoDataset geoDataset(conn.AddGeoDataset(GetFileTitle(sPathFile), moPolygon, tableDesc, va ,va));
CMoMapLayer layer;
if (!layer.CreateDispatch(TEXT("MapObjects2.MapLayer")))
return FALSE;
layer.SetGeoDataset(geoDataset);
CMoRecordset recs(layer.GetRecords());
CMoFields fields(recs.GetFields());
CString featureName;
for (int i = 0; i < m_oaPolys.GetSize(); i++)
{
recs.AddNew();
SetValue(fields, TEXT("Shape"), LPDISPATCH(*m_oaPolys[i]));
featureName.Format("%s%d", "poly", i);
SetValue(fields, TEXT("Name"), featureName);
SetValue(fields, TEXT("Area"), m_oaPolys[i]->GetArea());
SetValue(fields, TEXT("Perimeter"), m_oaPolys[i]->GetPerimeter());
recs.Update();
}
mo_ReleasePolys();
return TRUE;
}
BOOL CMapperShape::mo_ExportTexts(CString sPathFile)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -