VC++开发GIS系统(224)移动区之类的设计及实现
发布时间: 2016-06-16
所属分类: VC++开发GIS系统
本文介绍GIS系统中移动一个区所对应类的设计及实现。先看移动区的效果:
移动区类的定义
在_malaPolygon.h中定义移动区的类,代码如下:
/*
* 移动区
*/
class malapolygondll CmalaPolysMove :public CmalaMouseAction
{
public:
CmalaPolysMove(CView* mView, malaScreen *pScreen, CString &fileFullPath);
~CmalaPolysMove();
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;
CString mPath;//文件路径
bool mIsDraw;
malaPoint mPointOri;//起点
vector<malaPoint> mPerPoly;//临时的区
malaScreen *mScreen;
};
- @
mSelected
是否有区被选中 - @
mSPoly
选中的区的点序列 - @
mSPolyPro
选中区属性 - @
mSelectPoly
选中的区 - @
mPath
区文件路径 - @
mIsDraw
记录是否按下鼠标左键(用于橡皮筋绘图) - @
mPointOri
移动的起点 - @
mPerPoly
临时区的点序列 - @
mScreen
屏幕坐标
移动区类实现
在_malaPolygon.cpp中实现上述类的定义
/*
* 移动区实现
*/
CmalaPolysMove::CmalaPolysMove(CView* mView, malaScreen *pScreen, CString &fileFullPath)
{
mBaseView = mView;
mPath = fileFullPath;
mScreen = pScreen;
CmalaPolysSelect obj(mView, pScreen, fileFullPath);
mSelectPoly = obj;
mSelected = FALSE;
mIsDraw = FALSE;
}
CmalaPolysMove::~CmalaPolysMove()
{
if (mSPoly.size())
mSPoly.clear();
}
void CmalaPolysMove::LButtonDown(UINT nFlags, malaPoint point)
{
if (!mSelected)
mSelectPoly.LButtonDown(nFlags, point);
else
{
mIsDraw = TRUE;
mPointOri = point;
}
}
void CmalaPolysMove::LButtonUp(UINT nFlags, malaPoint point)
{
if (!mSelected)
mSelectPoly.LButtonUp(nFlags, point);
else
{
CPolyIO lio;
lio.polyUpdate(mPerPoly, mSPolyPro, mPath);
mBaseView->Invalidate(TRUE);
mIsDraw = FALSE;
mSelected = FALSE;
mSelectPoly.m_Selected = FALSE;
mSPoly.clear();
}
mSelected = mSelectPoly.m_Selected;
if (mSelected)
{
this->mSPoly = mSelectPoly.mSPoly;
this->mSPolyPro = mSelectPoly.mSPolyPro;
mPerPoly = mSPoly;
}
}
void CmalaPolysMove::MouseMove(UINT nFlags, malaPoint point)
{
if (!mSelected)
mSelectPoly.MouseMove(nFlags, point);
else if (mIsDraw)
{
malaCDC dc(mBaseView, *mScreen);
dc.polyDrawAutoX(mPerPoly, mSPolyPro);
for (size_t i = 0; i < mPerPoly.size(); i++)
{
mPerPoly[i].x = mSPoly[i].x + point.x - mPointOri.x;
mPerPoly[i].y = mSPoly[i].y + point.y - mPointOri.y;
}
dc.polyDrawAutoX(mPerPoly, mSPolyPro);
}
}
其中 polyUpdate
函数参考《VC++开发GIS系统(223)移动区之更新区参数》,polyDrawAutoX
函数参考《VC++开发GIS系统(208)输入区之绘制区的函数(多边形与椭圆)》
详细代码可以参考:GitHub
相关阅读
声明
1.本文所分享的所有需要用户下载使用的内容(包括但不限于软件、数据、图片)来自于网络或者麻辣GIS粉丝自行分享,版权归该下载资源的合法拥有者所有,如有侵权请第一时间联系本站删除。
2.下载内容仅限个人学习使用,请切勿用作商用等其他用途,否则后果自负。
手机阅读
公众号关注
知识星球
手机阅读
最新GIS干货
私享圈子