VC++开发GIS系统(194)删除线之类的设计及实现

前文《VC++开发GIS系统(193)删除线之IO函数实现》介绍了关于删除这个功能底层的实现,本文具体介绍这个功能的使用方法以及类的设计与实现。

删除线功能描述

操作流程下图:

  1. 选择线
  2. 用户确认
  3. 确认删除

删除线类的设计

在_malaLines.h中定义删除线的类,如下:

/*
* 删除线
*/
class malalinesdll  CmalaLinesDelete :public CmalaMouseAction
{
public:
  CmalaLinesDelete(CView* mView, malaScreen *pScreen, CString &fileFullPath);
  ~CmalaLinesDelete();
  void LButtonDown(UINT nFlags, malaPoint point);
  void LButtonUp(UINT nFlags, malaPoint point);
  void MouseMove(UINT nFlags, malaPoint point);
private:
  bool m_Selected;
  vector<malaPoint> mSLine;//选择的线
  malaLinePro mSLinePro;//选择线的属性
  CmalaLinesSelect m_SelectLine;

  CString mPath;//文件路径
  malaScreen *m_Screen;
};

删除线类的函数实现

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

/*
* 删除线实现
*/
CmalaLinesDelete::CmalaLinesDelete(CView* mView, malaScreen *pScreen, CString &fileFullPath)
{
  mBaseView = mView;
  mPath = fileFullPath;
  m_Screen = pScreen;
  CmalaLinesSelect obj(mView, pScreen, fileFullPath);
  m_SelectLine = obj;
  m_Selected = FALSE;
}

CmalaLinesDelete::~CmalaLinesDelete()
{
  if (mSLine.size())
    mSLine.clear();
}

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

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

  m_Selected = m_SelectLine.m_Selected;

  if (m_Selected)
  {
    this->mSLine = m_SelectLine.mLine;
    this->mSLinePro = m_SelectLine.mLinePro;

    if (MessageBox(mBaseView->m_hWnd, L"删除后将无法恢复,确定删除吗?", L"警告", MB_YESNO | MB_ICONQUESTION) == IDYES)
    {
      //feature.LineDelete(m_linepro.LineID);
      CLineIO lio;
      lio.lineDelete(mSLinePro.lineId,mPath);
      mBaseView->Invalidate(TRUE);
    }
    
    mSLine.clear();
    m_Selected = FALSE;
    m_SelectLine.m_Selected = FALSE;
  }

}

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

其中调用的主要函数为 lineDelete ,其实现可以参考文章《VC++开发GIS系统(193)删除线之IO函数实现

详细代码可以参考:GitHub

VC++开发GIS系统(193)删除线之IO函数实现 VC++开发GIS系统(195)删除线之菜单响应

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

发表评论