VC++开发GIS系统(183)剪断线之类的设计及实现

前文有两篇文章 《VC++开发GIS系统(181)剪断线之判断点是否在线上函数实现》及 《 VC++开发GIS系统(182)剪断线之函数实现 》,其分别介绍了剪断线的核心实现函数,本文记录一下剪断线类的设计及实现。

类的定义

在_malaLines.h中定义剪断线的类,代码如下:

/*
*剪断线
*/
class malalinesdll CmalaLinesCut :public CmalaMouseAction
{
public:
    CmalaLinesCut(CView* mView, malaScreen *pScreen, CString &fileFullPath);
    virtual ~CmalaLinesCut();
    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;//选择的线
    vector<malaPoint> mPLine;//临时的线
    malaLinePro mSLinePro;//选择的点的属性
    CmalaLinesSelect m_SelectLine;
    bool callSel;//控制是否触发选择线

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

类的实现

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

/*
* 剪断线实现
*/
CmalaLinesCut::CmalaLinesCut(CView* mView, malaScreen *pScreen, CString &fileFullPath)
{
    mBaseView = mView;
    mPath = fileFullPath;
    m_Screen = pScreen;
    CmalaLinesSelect obj(mView, pScreen, fileFullPath);
    m_SelectLine = obj;
    m_Selected = FALSE;
    callSel = false;
}

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

void CmalaLinesCut::LButtonDown(UINT nFlags, malaPoint point)
{
    if (!m_Selected&&!callSel)
        m_SelectLine.LButtonDown(nFlags, point);
    else
    {
        malaLogic cutlog;
        if (cutlog.cutLine(point,mSLine,mPLine))
        {
            CLineIO lio;
            lio.lineUpdate(mSLine, mSLinePro,mPath);
            lio.lineAdd(mPLine, mSLinePro,mPath);
            
            malaCDC cutcdc(mBaseView, *m_Screen);
            malaPointPro tPro;
            tPro.pointColor = mSLinePro.lineColor;
            tPro.pointRadio = mSLinePro.lineWidth + 2;
            tPro.pointStyle = 0;
            cutcdc.drawSelectCirclePoint(mSLine[mSLine.size()-1], tPro);

            mSLine.clear();
            mPLine.clear();
            m_Selected = FALSE;
            m_SelectLine.m_Selected = FALSE;
            callSel = true;
        }
        
    }
}

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

    m_Selected = m_SelectLine.m_Selected;

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

}

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

文中调用的 cutLine 函数可以参考文章《VC++开发GIS系统(182)剪断线之函数实现

详细代码可以参考:GitHub

ArcGIS10 地理信息系统教程:从初学到精通和ArcGIS Engine 地理信息系统开发教程相关资料分享 VC++开发GIS系统(184)剪断线之菜单响应

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

发表评论