📄 appapi.cpp
字号:
#include "stdafx.h"
#include "AppApi.h"
#include "MoStrings.h"
#include "MoRecordset.h"
#include "MoFields.h"
#include "MoField.h"
#include "MoValueMapRenderer.h"
#include "MoSymbol.h"
#include "gissegline.h"
//-----------------------------------------------------------------------------------------
// 得到某个文件名的路径
CString GetFilePath(const CString& strFileName)
{
ASSERT(strFileName.GetLength());
int pos = strFileName.ReverseFind('\\');
if (pos >= 0)
return strFileName.Left(pos);
return "";
}
//-----------------------------------------------------------------------------------------
// 得到应用程序的路径名
CString GetModulePath()
{
char lpFilename[200];
DWORD nSize = 200;
// 得到应用程序的文件名
GetModuleFileName(NULL, lpFilename, nSize);
return GetFilePath(CString(lpFilename));
}
//-----------------------------------------------------------------------------------------
// 显示DAO异常的信息
void DisplayDaoException(CDaoException* e)
{
CString strMsg;
if (e->m_pErrorInfo != NULL)
{
strMsg.Format(
_T("%s (%d)\n\n")
_T("Would you like to see help?"),
(LPCTSTR)e->m_pErrorInfo->m_strDescription,
e->m_pErrorInfo->m_lErrorCode);
// 显示错误信息
if (AfxMessageBox(strMsg, MB_YESNO) == IDYES)
{
WinHelp(GetDesktopWindow(),
e->m_pErrorInfo->m_strHelpFile,
HELP_CONTEXT,
e->m_pErrorInfo->m_lHelpContext);
}
}
else
{
strMsg.Format(
_T("ERROR:CDaoException\n\n")
_T("SCODE_CODE =%d\n")
_T("SCODE_FACILITY =%d\n")
_T("SCODE_SEVERITY =%d\n")
_T("ResultFromScode =%d\n"),
SCODE_CODE (e->m_scode),
SCODE_FACILITY (e->m_scode),
SCODE_SEVERITY (e->m_scode),
ResultFromScode (e->m_scode));
// 显示错误信息
AfxMessageBox(strMsg);
}
}
//-----------------------------------------------------------------------------------------
// 设置多边形图层的颜色
void SetPolygonLayerColor(CMoMapLayer ly, CString szField1,
CString szField2, bool bBorder)
{
CMoStrings strings;
strings.CreateDispatch(TEXT("MapObjects2.Strings"));
CMoStrings strColors;
strColors.CreateDispatch(TEXT("MapObjects2.Strings"));
CMoRecordset rst = ly.GetRecords();
rst.MoveFirst();
while (!rst.GetEof())
{
CString strValue = rst.GetFields().Item(COleVariant
(TEXT(szField1))).GetValueAsString();
strings.Add(strValue);
strValue = rst.GetFields().Item(COleVariant
(TEXT(szField2))).GetValueAsString();
strColors.Add(strValue);
rst.MoveNext();
}
CMoValueMapRenderer rd;
rd.CreateDispatch(TEXT("MapObjects2.ValueMapRenderer"));
ly.SetRenderer(rd);
rd.SetField(szField1);
rd.SetValueCount(strings.GetCount());
for (short i = 0; i < strings.GetCount(); i ++)
{
rd.SetValue((short)i, strings.Item(COleVariant(i)));
CMoSymbol sym = rd.GetSymbol((short)i);
UINT nColor = atoi(strColors.Item(COleVariant(i)));
// 设置符号的颜色
sym.SetColor(nColor);
// 设置符号的外框
sym.SetOutline(bBorder);
}
}
//-----------------------------------------------------------------------------------------
BOOL IsWithin(CMoRectangle rect, CMoPoint pt)
{
BOOL bWithin = FALSE;
bWithin = rect.IsPointIn(pt);
return bWithin;
}
//-----------------------------------------------------------------------------------------
void CutLine(MLine LineSrc,MPoint pt1,MPoint pt2, MLine* LineRes)
{
// 计算到线段的距离
double dMinDistance1 = 10000.0;
double dMinDistance2 = 10000.0;
double dTheDis = 0.0;
MPoint ptRealFrom, ptRealTo;
MPoint ptTemp;
int nPointOrderInMLine1 = 0, nPointOrderInMLine2 = 0;
CGisSegLine SegMLine;
for(int i=0; i<LineSrc.nPointNumber-1; i++)
{
SegMLine.m_ptStartPoint.x = LineSrc.pPoint[i].x;
SegMLine.m_ptStartPoint.y = LineSrc.pPoint[i].y;
SegMLine.m_ptStartPoint.x = LineSrc.pPoint[i+1].x;
SegMLine.m_ptStartPoint.y = LineSrc.pPoint[i+1].y;
SegMLine.GetDistance(&pt1, &ptTemp, &dTheDis);
if(dTheDis < dMinDistance1)
{
dMinDistance1 = dTheDis;
nPointOrderInMLine1 = i;
ptRealFrom = ptTemp;
}
SegMLine.GetDistance(&pt2, &ptTemp, &dTheDis);
if(dTheDis < dMinDistance2)
{
dMinDistance2 = dTheDis;
nPointOrderInMLine2 = i;
ptRealTo = ptTemp;
}
}
if(nPointOrderInMLine2 - nPointOrderInMLine1 >0 )
{
LineRes->nPointNumber = nPointOrderInMLine2 - nPointOrderInMLine1 +2;
LineRes->pPoint = new MPoint[LineRes->nPointNumber];
int i;
LineRes->pPoint[0] = pt1;
for(i=1; i<LineRes->nPointNumber-1; i++)
{
LineRes->pPoint[i] = LineSrc.pPoint[nPointOrderInMLine1+i];
}
LineRes->pPoint[i] = pt2;
}
else
{
LineRes->nPointNumber = nPointOrderInMLine1 - nPointOrderInMLine2 +2;
LineRes->pPoint = new MPoint[LineRes->nPointNumber];
int i;
LineRes->pPoint[0] = pt2;
for(i=1; i<LineRes->nPointNumber-1; i++)
{
LineRes->pPoint[i] = LineSrc.pPoint[nPointOrderInMLine2+i];
}
LineRes->pPoint[i] = pt1;
}
}
//-----------------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -