VC++开发GIS系统(232)边界加点类的设计及实现

本文为GIS系统中边界加点这个操作设计一个专有的类,心实现边界加点的功能。功能演示如下:

GIS系统边界加点类的定义

在_malaPolygon.h中定义GIS边界加点的类,代码如下:

/*
*边界加点
*/
class malapolygondll CmalaPolysAddPoint :public CmalaMouseAction
{
public:
  CmalaPolysAddPoint(CView* mView, malaScreen *pScreen, CString &fileFullPath);
  virtual ~CmalaPolysAddPoint();
  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;
  bool callSel;//控制是否触发选择线

  malaScreen *mScreen;
  CString mPath;//文件路径
};
  • m_Selected 用来定义区是否被选中
  • mSPoly 记录选择的区的点序列
  • mSPolyPro 记录选择区的属性
  • mSelectPoly 一个选择区对象,用来选择区
  • callSel 控制是否触发选择线
  • *m_Screen 屏幕坐标变换变量
  • mPath 文件路径

类的实现

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

/*
* 边界加点实现
*/
CmalaPolysAddPoint::CmalaPolysAddPoint(CView* mView, malaScreen *pScreen, CString &fileFullPath)
{
  mBaseView = mView;
  mPath = fileFullPath;
  mScreen = pScreen;
  CmalaPolysSelect obj(mView, pScreen, fileFullPath);
  mSelectPoly = obj;
  mSelected = FALSE;
  callSel = false;
}

CmalaPolysAddPoint::~CmalaPolysAddPoint()
{
  if (mSPoly.size())
    mSPoly.clear();
}

void CmalaPolysAddPoint::LButtonDown(UINT nFlags, malaPoint point)
{
  if (!mSelected&&!callSel)
    mSelectPoly.LButtonDown(nFlags, point);
  if (mSelected&&!callSel)
  {
    malaLogic cutlog;
    if (cutlog.addPointPoly(point, mSPoly))
    {
      CPolyIO lio;
      lio.polyUpdate(mSPoly, mSPolyPro, mPath);

      //绘制选中标志
      malaCDC cutcdc(mBaseView, *mScreen);
      for (size_t k = 0; k < mSPoly.size(); k++)
      {
        malaPointPro tpPointPro;
        tpPointPro.pointRadio = mSPolyPro.borderWidth + 2;
        tpPointPro.pointColor = mSPolyPro.borderColor;

        cutcdc.drawSelectRectPoint(mSPoly[k], tpPointPro);
      }

      mSPoly.clear();
      mSelected = FALSE;
      mSelectPoly.m_Selected = FALSE;
      callSel = true;
    }

  }

}

void CmalaPolysAddPoint::LButtonUp(UINT nFlags, malaPoint point)
{
  if (!mSelected&&!callSel)
    mSelectPoly.LButtonUp(nFlags, point);

  mSelected = mSelectPoly.m_Selected;

  if (mSelected)
  {
    this->mSPoly = mSelectPoly.mSPoly;
    this->mSPolyPro = mSelectPoly.mSPolyPro;
  }

}

void CmalaPolysAddPoint::MouseMove(UINT nFlags, malaPoint point)
{
  if (!mSelected&&!callSel)
    mSelectPoly.MouseMove(nFlags, point);
}

其中 addPointPoly 是该功能的核心函数,参考文章《VC++开发GIS系统(231)边界加点函数实现》。函数 polyUpdate 用于实现更新一个区的属性,可以参考文章《VC++开发GIS系统(223)移动区之更新区参数

详细代码可以参考:GitHub

VC++开发GIS系统(231)边界加点函数实现 VC++开发GIS系统(233)边界加点之菜单响应

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

发表评论