VC++开发GIS系统(133)复制点之类的定义及实现
发布时间: 2016-01-14
所属分类: VC++开发GIS系统
前文已经实现了移动点的功能,本文继续下一步的工作——复制点。其实复制点的逻辑和移动点相似,过程如下:
- 按下鼠标左键,不松开
- 鼠标移动,选中的点跟随鼠标移动
- 鼠标松开,将选中点的坐标新增到文件中
复制点类CmalaPointsCopy的定义
在_malaPoints.h中定义复制的点的类:CmalaPointsCopy,代码如下:
/*
* 复制点
*/
class malapointsdll CmalaPointsCopy :public CmalaMouseAction
{
public:
CmalaPointsCopy(CView* mView, malaScreen *pScreen, CString &fileFullPath);
~CmalaPointsCopy();
void LButtonDown(UINT nFlags, malaPoint point);
void LButtonUp(UINT nFlags, malaPoint point);
void MouseMove(UINT nFlags, malaPoint point);
private:
bool m_Selected;
malaPoint m_Point;//选择的点
malaPointPro m_PointPro;//选择的点的属性
CmalaPointsSelect m_SelectPnt;
CString mPath;//文件路径
bool m_bDraw;
malaPoint m_ptOrigin;//起点
malaPoint m_perPoint;//临时点
malaScreen *m_Screen;
};
复制点类CmalaPointsCopy的实现
在_malaPoints.cpp中实现上述类的定义,代码如下:
/*
* 复制点实现
*/
CmalaPointsCopy::CmalaPointsCopy(CView* mView, malaScreen *pScreen, CString &fileFullPath)
{
mBaseView = mView;
mPath = fileFullPath;
m_Screen = pScreen;
CmalaPointsSelect obj(mView, pScreen, fileFullPath);
m_SelectPnt = obj;
m_Selected = FALSE;
m_bDraw = FALSE;
}
CmalaPointsCopy::~CmalaPointsCopy()
{
}
void CmalaPointsCopy::LButtonDown(UINT nFlags, malaPoint point)
{
if (!m_Selected)
m_SelectPnt.LButtonDown(nFlags, point);
else
{
m_bDraw = TRUE;
m_ptOrigin = point;
}
}
void CmalaPointsCopy::LButtonUp(UINT nFlags, malaPoint point)
{
if (!m_Selected)
m_SelectPnt.LButtonUp(nFlags, point);
else
{
CPointIO pio;
pio.pointAdd(point, m_PointPro, mPath);
mBaseView->Invalidate(TRUE);
m_bDraw = FALSE;
m_Selected = FALSE;
m_SelectPnt.m_Selected = FALSE;
}
m_Selected = m_SelectPnt.m_Selected;
if (m_Selected)
{
this->m_Point = m_SelectPnt.m_pnt;
this->m_PointPro = m_SelectPnt.m_PntPro;
m_perPoint = m_Point;
}
}
void CmalaPointsCopy::MouseMove(UINT nFlags, malaPoint point)
{
if (!m_Selected)
m_SelectPnt.MouseMove(nFlags, point);
else if (m_bDraw)
{
malaCDC dc(mBaseView, *m_Screen);
dc.pointDrawAutoX(m_perPoint, m_PointPro);
m_perPoint.x = m_ptOrigin.x + point.x - m_ptOrigin.x;
m_perPoint.y = m_ptOrigin.y + point.y - m_ptOrigin.y;
dc.pointDrawAutoX(m_perPoint, m_PointPro);
dc.pointDrawAuto(m_Point, m_PointPro);
}
}
可以看出复制和上文《VC++开发GIS系统(131)移动点之类的设计及实现》相似,不同的是移动点调用的是pointUpdate函数,而复制点调用的是pointAdd函数。
详细代码可以参考:GitHub
相关阅读
声明
1.本文所分享的所有需要用户下载使用的内容(包括但不限于软件、数据、图片)来自于网络或者麻辣GIS粉丝自行分享,版权归该下载资源的合法拥有者所有,如有侵权请第一时间联系本站删除。
2.下载内容仅限个人学习使用,请切勿用作商用等其他用途,否则后果自负。
手机阅读
公众号关注
知识星球
手机阅读
最新GIS干货
私享圈子