VC++开发GIS系统(179)修改线属性之类的设计及实现

前文《VC++开发GIS系统(178)修改线属性之导出线属性对话框》已经实现了导出线属性的对话框,本文的工作是实现修改线属性的类。

类的定义

在_malaLines.h中定义为修改区属性的类,代码如下:

/*
* 修改线属性
*/
class malalinesdll  CmalaLinesModify :public CmalaMouseAction
{
public:
    CmalaLinesModify(CView* mView, malaScreen *pScreen, CString &fileFullPath);
    ~CmalaLinesModify();
    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;
};

m_Selected用来定义线是否被选中,mSLine记录选择的线,mSLinePro记录选择线的属性,m_SelectLine一个选择线对象,用来选择线。

类的实现

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

/*
* 修改线属性实现
*/
CmalaLinesModify::CmalaLinesModify(CView* mView, malaScreen *pScreen, CString &fileFullPath)
{
    mBaseView = mView;
    mPath = fileFullPath;
    m_Screen = pScreen;
    CmalaLinesSelect obj(mView, pScreen, fileFullPath);
    m_SelectLine = obj;
    m_Selected = FALSE;
}

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

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

void CmalaLinesModify::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 (dlgModifyLinePro(mSLinePro))
        {
            CLineIO lio;
            lio.lineUpdate(mSLine, mSLinePro, mPath);
            mBaseView->Invalidate(TRUE);
        }
        mSLine.clear();
        m_Selected = FALSE;
        m_SelectLine.m_Selected = FALSE;
    }

}

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

文中调用的lineUpdate函数可以参考文章《VC++开发GIS系统(173)移动线之更新一条线的属性函数定义及实现

详细代码可以参考:GitHub

VC++开发GIS系统(178)修改线属性之导出线属性对话框 VC++开发GIS系统(180)修改线属性之菜单响应

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

发表评论