VC++开发GIS系统(133)复制点之类的定义及实现

前文已经实现了移动点的功能,本文继续下一步的工作——复制点。其实复制点的逻辑和移动点相似,过程如下:

  1. 按下鼠标左键,不松开
  2. 鼠标移动,选中的点跟随鼠标移动
  3. 鼠标松开,将选中点的坐标新增到文件中

复制点类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

VC++开发GIS系统(132)移动点之菜单响应 VC++开发GIS系统(134)复制点之菜单响应

作者:,GIS爱好者。
分享本文,请您带上本文链接
分享到:

发表评论