VC++开发GIS系统(140)删除点之类的定义及实现

前文《VC++开发GIS系统(139)删除点之文件读写函数》开发删除点的基础文件IO接口,本文将派生一个删除点的类,用于实现删除点的操作。过程如下:

  1. 选中点
  2. 删除点
  3. 写入文件。

删除点类 CmalaPointsDelete 的定义

从CmalaMouseAction派生出CmalaPointsDelete类,用来实现删除点,代码如下:

/*
* 删除点
*/
class malapointsdll  CmalaPointsDelete :public CmalaMouseAction
{
public:
    CmalaPointsDelete(CView* mView, malaScreen *pScreen, CString &fileFullPath);
    ~CmalaPointsDelete();
    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;//文件路径
    malaScreen *m_Screen;
};

删除点类 CmalaPointsDelete 的实现

在_malaPoints.cpp中实现上述类的定义,代码如下:

/*
* 删除点实现
*/
CmalaPointsDelete::CmalaPointsDelete(CView* mView, malaScreen *pScreen, CString &fileFullPath)
{
    mBaseView = mView;
    mPath = fileFullPath;
    m_Screen = pScreen;
    CmalaPointsSelect obj(mView, pScreen, fileFullPath);
    m_SelectPnt = obj;
    m_Selected = FALSE;
}

CmalaPointsDelete::~CmalaPointsDelete()
{

}

void CmalaPointsDelete::LButtonDown(UINT nFlags, malaPoint point)
{
    if (!m_Selected)
        m_SelectPnt.LButtonDown(nFlags, point);
}

void CmalaPointsDelete::LButtonUp(UINT nFlags, malaPoint point)
{
    if (!m_Selected)
        m_SelectPnt.LButtonUp(nFlags, point);

    m_Selected = m_SelectPnt.m_Selected;
    if (m_Selected)
    {
        this->m_Point = m_SelectPnt.m_pnt;
        this->m_PointPro = m_SelectPnt.m_PntPro;

        if (MessageBox(mBaseView->m_hWnd, L"删除后将无法恢复,确定删除该点吗?", L"警告", MB_YESNO | MB_ICONQUESTION) == IDYES)
        {
            CPointIO pio;
            pio.pointDelete(m_PointPro, mPath);
            mBaseView->Invalidate(TRUE);
            
        }
        m_Point.x = m_Point.y = 0;
        m_Selected = FALSE;
        m_SelectPnt.m_Selected = FALSE;
        
    }

}

void CmalaPointsDelete::MouseMove(UINT nFlags, malaPoint point)
{
    if (!m_Selected)
        m_SelectPnt.MouseMove(nFlags, point);
}

在LButtonUp的时候先弹出确认对话框,然后调用上文的VC++开发GIS系统(139)删除点之文件读写函数实现删除写入过程。

详细代码可以参考:GitHub

VC++开发GIS系统(139)删除点之文件读写函数 VC++开发GIS系统(141)删除点之菜单响应

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

发表评论