VC++开发GIS系统(234)边界移点类的设计及实现
发布时间: 2016-06-19
所属分类: VC++开发GIS系统
边界加点的相关操作已经完成,本文介绍另外一个类似的操作:边界移点。主要的功能演示如下:
GIS系统边界移点类的定义
在_malaPolygon.h中定义GIS边界移点的类,代码如下:
/*
*边界移点
*/
class malapolygondll CmalaPolysMovePoint :public CmalaMouseAction
{
public:
CmalaPolysMovePoint(CView* mView, malaScreen *pScreen, CString &fileFullPath);
virtual ~CmalaPolysMovePoint();
void LButtonDown(UINT nFlags, malaPoint point);
void LButtonUp(UINT nFlags, malaPoint point);
void MouseMove(UINT nFlags, malaPoint point);
private:
bool mSelected;
vector<malaPoint> mSPoly;//选择的区
malaPolyPro mSPolyPro;//选择的区的属性
CmalaPolysSelect mSelectPoly;
bool mIsDraw;
int mPos;//标记点位置
malaPoint mPrePoint;//前一个点
malaPoint mNexPoint;//后一个点
malaPoint mPerPoint;//临时点
malaScreen *mScreen;
CString mPath;//文件路径
};
m_Selected
用来定义区是否被选中mSPoly
记录选择的区的点序列mSPolyPro
记录选择区的属性mSelectPoly
一个选择区对象,用来选择区mIsDraw
标记是否按下鼠标左键mPrePoint
选中点的前一个点mNexPoint
选中点的后一个点mPerPoint
临时的点*m_Screen
屏幕坐标变换变量mPath
文件路径
类的实现
在_malaPolygon.cpp中实现上述的类定义,代码如下:
/*
* 边界移点实现
*/
CmalaPolysMovePoint::CmalaPolysMovePoint(CView* mView, malaScreen *pScreen, CString &fileFullPath)
{
mBaseView = mView;
mPath = fileFullPath;
mScreen = pScreen;
CmalaPolysSelect obj(mView, pScreen, fileFullPath);
mSelectPoly = obj;
mSelected = FALSE;
mIsDraw = FALSE;
mPos = 0;
}
CmalaPolysMovePoint::~CmalaPolysMovePoint()
{
if (mSPoly.size())
mSPoly.clear();
}
void CmalaPolysMovePoint::LButtonDown(UINT nFlags, malaPoint point)
{
if (!mSelected)
mSelectPoly.LButtonDown(nFlags, point);
else
{
malaLogic math;
mPos = math.getPointPosInLine(point, mSPoly);
if (mPos >= 0)
{
mIsDraw = TRUE;
if (mPos == 0)
{
mPrePoint = mSPoly[mSPoly.size() - 1];
mNexPoint = mSPoly[1];
}
else if (mPos == mSPoly.size() - 1)
{
mPrePoint = mSPoly[mPos - 1];
mNexPoint = mSPoly[0];
}
else
{
mPrePoint = mSPoly[mPos - 1];
mNexPoint = mSPoly[mPos + 1];
}
mPerPoint = mSPoly[mPos];
}
}
}
void CmalaPolysMovePoint::LButtonUp(UINT nFlags, malaPoint point)
{
if (!mSelected)
mSelectPoly.LButtonUp(nFlags, point);
if (mIsDraw)
{
mIsDraw = FALSE;
mSPoly[mPos] = point;
CPolyIO lio;
lio.polyUpdate(mSPoly, mSPolyPro, mPath);
mSPoly.clear();
mSelectPoly.m_Selected = FALSE;
mBaseView->Invalidate(TRUE);
}
mSelected = mSelectPoly.m_Selected;
if (mSelected)
{
mSPoly = mSelectPoly.mSPoly;
mSPolyPro = mSelectPoly.mSPolyPro;
}
}
void CmalaPolysMovePoint::MouseMove(UINT nFlags, malaPoint point)
{
malaCDC dc(mBaseView, *mScreen);
if (!mSelected)
mSelectPoly.MouseMove(nFlags, point);
if (mIsDraw)
{
malaLinePro m_linepro;
m_linepro.lineColor = mSPolyPro.borderColor;
m_linepro.lineStyle = mSPolyPro.borderStyle;
m_linepro.lineWidth = mSPolyPro.borderWidth;
dc.lineDrawX(mPrePoint, mPerPoint, m_linepro);
dc.lineDrawX(mPrePoint, point, m_linepro);
dc.lineDrawX(mNexPoint, mPerPoint, m_linepro);
dc.lineDrawX(mNexPoint, point, m_linepro);
mPerPoint = point;
}
}
lineDrawX
函数用于橡皮筋绘图,参考文章《VC++开发GIS系统(152)输入线之画直线的函数》。函数 polyUpdate
用于实现更新一个区的属性,可以参考文章《VC++开发GIS系统(223)移动区之更新区参数》
详细代码可以参考:GitHub
相关阅读
声明
1.本文所分享的所有需要用户下载使用的内容(包括但不限于软件、数据、图片)来自于网络或者麻辣GIS粉丝自行分享,版权归该下载资源的合法拥有者所有,如有侵权请第一时间联系本站删除。
2.下载内容仅限个人学习使用,请切勿用作商用等其他用途,否则后果自负。
手机阅读
公众号关注
知识星球
手机阅读
最新GIS干货
私享圈子