PIE-SDK For C++矢量数据编辑的撤销和回退

1.功能简介

   在数据的编辑过程中难免会出现失误,撤销和回退可以更好的编辑,下面对矢量数据编辑的撤销和回退功能进行介绍。

2.功能实现说明

2.1 实现思路及原理说明

第一步

调用UndoCommandRedoCommand类进行创建

2.2 核心接口与方法

接口/类

方法/属性

说明

SysUI::CMDPluginModule::CreateLibCommand

 

实例化命令

SysUI::ICommandPtr

OnCreate()

命令创建

OnClick()

点击事件

2.3 示例代码

项目路径

百度云盘地址下/PIE示例程序/04数据操作/06矢量数据编辑撤销和回退

数据路径

自定义即可

视频路径

百度云盘地址下/PIE视频教程/04数据操作/06矢量数据编辑撤销和回退.avi

示例代码

void PIEMainWindow::On_ActionStartEditor_Triggered(bool checked)

{

    if (SysCarto::Editor::Instance()->GetEditState() == SysCarto::EditState::StateNotEditing)

    {

        SysCarto::Editor::Instance()->StartEditing();

        SysCarto::FeatureLayerPtr fLayerPtr = m_pCurrentControl->GetActiveView()->GetCurrentLayer();

        if (fLayerPtr == nullptr) return;

        SysCarto::Editor::Instance()->SetMap(m_pMapControl->GetMap());

        SysCarto::Editor::Instance()->SetEditLayer(fLayerPtr);

    }

}

 

void PIEMainWindow::On_ActionStopEditor_Triggered(bool checked)

{

    if (SysCarto::Editor::Instance()->GetEditState() == SysCarto::EditState::StateEditing)

    {

        bool flag= SysCarto::Editor::Instance()->SaveEditing();

        flag=SysCarto::Editor::Instance()->StopEditing(true);

    }

}

 

void PIEMainWindow::On_ActionAddFeature_Triggered(bool checked)

{

    SysCarto::FeatureLayerPtr fLyPtr = m_pCurrentControl->GetActiveView()->GetCurrentLayer();

    if (fLyPtr == nullptr) return;

 

    SysCarto::Editor::Instance()->StartEditOperation("添加元素");

    SysDataSource::FeatureClassPtr featureclass = fLyPtr->GetFeatureClass();

    SysDataSource::FeaturePtr newFeature = featureclass->CreateNewFeature();

 

    SysGeometry::PolygonPtr polygon = new SysGeometry::Polygon();

 

 

    SysGeometry::PointPtr pointPtr1 = new SysGeometry::Point();

    pointPtr1->PutCoords(121.83, 36.01);

    polygon->AddPoint(pointPtr1);

 

    SysGeometry::PointPtr pointPtr2 = new SysGeometry::Point();

    pointPtr2->PutCoords(126.44, 33.32);

    polygon->AddPoint(pointPtr2);

 

    SysGeometry::PointPtr pointPtr3 = new SysGeometry::Point();

    pointPtr3->PutCoords(122.18, 33.59);

    polygon->AddPoint(pointPtr3);

 

    polygon->CloseRings();

 

    SysGeometry::GeometryPtr geoPtr = polygon;

    geoPtr->SetSpatialReference(featureclass->GetFeatureDataset()->GetSpatialReference());

    newFeature->SetGeometry(geoPtr);

 

    featureclass->AddFeature(newFeature);

    bool flag= SysCarto::Editor::Instance()->StopEditOperation();

    m_pCurrentControl->GetActiveView()->PartialRefresh(SysCarto::ViewAll);

}

 

void PIEMainWindow::On_ActionUndo_Triggered(bool checked)

{

    SysUI::ICommandPtr ptrCmd = SysUI::CMDPluginModule::CreateLibCommand("VectorEditor", "VectorEditor_Undo");

    if (ptrCmd == nullptr) return;

    ptrCmd->OnCreate(m_pMapControl);

    ptrCmd->OnClick();

}

 

void PIEMainWindow::On_ActionRedo_Triggered(bool checked)

{

    SysUI::ICommandPtr ptrCmd = SysUI::CMDPluginModule::CreateLibCommand("VectorEditor", "VectorEditor_Redo");

    if (ptrCmd == nullptr) return;

    ptrCmd->OnCreate(m_pMapControl);

    ptrCmd->OnClick();

}

2.4 示例截图

 

 

posted @ 2020-02-27 15:13  PIESAT  阅读(325)  评论(0编辑  收藏  举报