VC++开发GIS系统(266)复制注释之类的设计及实现

本文介绍GIS系统中复制一个注释要素所对应类的设计及实现。首先通过下面的动态图展示复制注释的过程。

其实思想和前文《VC++开发GIS系统(264)移动注释之类的设计及实现》类似,只是在鼠标左键松开的时候,调用的保存一条注释函数的函数。

复制注释类的定义

在_malaLabel.h中定义复制注释的类,代码如下:

/*
* 复制注释
*/
class malalabeldll  CmalaLabelsCopy :public CmalaMouseAction
{
public:
  CmalaLabelsCopy(CView* mView, malaScreen *pScreen, CString &fileFullPath);
  ~CmalaLabelsCopy();
  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;//选择的点的属性
  malaLabelPro m_LabelPro;//选择的注释的属性
  CmalaLabelsSelect m_SelectPnt;

  CString mPath;//文件路径

  bool m_bDraw;
  malaPoint m_ptOrigin;//起点
  malaPoint m_perPoint;//临时点
  malaScreen *m_Screen;
};
  • @ m_Selected 是否有注释被选中
  • @ m_Point 选中的注释坐标
  • @ m_PointPro 选择的注释属性
  • @ m_LabelPro 选中的注释属性
  • @ m_SelectPnt 选中的注释
  • @ mPath 注释文件路径
  • @ m_bDraw 记录是否按下鼠标左键(用于橡皮筋绘图)
  • @ mPointOri 移动的起点
  • @ m_perPoint 临时点
  • @ mScreen 屏幕坐标

复制注释类实现

在_malaLabel.cpp中实现上述类的定义

/*
* 复制注释实现
*/
CmalaLabelsCopy::CmalaLabelsCopy(CView* mView, malaScreen *pScreen, CString &fileFullPath)
{
  mBaseView = mView;
  mPath = fileFullPath;
  m_Screen = pScreen;
  CmalaLabelsSelect obj(mView, pScreen, fileFullPath);
  m_SelectPnt = obj;
  m_Selected = FALSE;
  m_bDraw = FALSE;
}

CmalaLabelsCopy::~CmalaLabelsCopy()
{

}

void CmalaLabelsCopy::LButtonDown(UINT nFlags, malaPoint point)
{
  if (!m_Selected)
    m_SelectPnt.LButtonDown(nFlags, point);
  else
  {
    m_bDraw = TRUE;
    m_ptOrigin = point;
  }
}

void CmalaLabelsCopy::LButtonUp(UINT nFlags, malaPoint point)
{
  if (!m_Selected)
    m_SelectPnt.LButtonUp(nFlags, point);
  else
  {
    CLabelIO pio;
    pio.labelAdd(point, m_LabelPro, 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_LabelPro = m_SelectPnt.mLablePro;
    m_perPoint = m_Point;
  }

}

void CmalaLabelsCopy::MouseMove(UINT nFlags, malaPoint point)
{
  if (!m_Selected)
    m_SelectPnt.MouseMove(nFlags, point);
  else if (m_bDraw)
  {
    malaCDC dc(mBaseView, *m_Screen);

    m_PointPro.pointColor = RGB(0, 255, 0);
    m_PointPro.pointRadio = 10;
    m_PointPro.pointStyle = 2;

    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);
  }
}

其中 labelAdd 函数参考《VC++开发GIS系统(255)保存一条注释函数

详细代码可以参考:GitHub

VC++开发GIS系统(265)移动注释之菜单响应 VC++开发GIS系统(267)复制注释之菜单响应

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

发表评论