Custom ArcEngine element editing tool and arcengine editing tool
From: http://blog.sina.com.cn/s/blog_4d780fc10101d2d5.html
First, I first learned about the following interfaces and classes used:
IEngineEditor
IEngineEditTask
IEngineEditLayers
IEngineEditEvents
IEngineEditProperties
ControlsEditingSketchToolClass
ControlsEditingEditToolClass
ControlsEditingCopyCommandClass
ControlsEditingPasteCommandClass
ControlsEditingClearCommandClass
Now we use three interfaces: IEngineEditor, IEngineEditTask, and IEngineEditLayers. The Command and Tool can be used to create, copy, cut, paste, delete, and move elements.
The following describes how to create a graph:
1. Enable Editing Based on workspace and map.
2. Set the target layer.
3. Set the Task Type of the edit operation.
4. Activate SletchTool and ControlsEditingSketchToolClass.
5. Now you can draw a graph in AxMapControl. The point and line type of the image. The SletchTool automatically identifies the target layer based on the type of the Target layer.
The global variable IEngineEditor is used to ensure the value of this variable in other modules.
Private IEngineEditor m_EngineEditor = new EngineEditorClass ();
Private void btnNewFeature_Click (object sender, EventArgs e)
{
If (m_engineEditor.EditState = esriEngineEditState. esriEngineStateNotEditing)
{
// Start editing the workspace of the first feature layer found.
// Set the edited WorkSpace and Edit object Layer
ILayer currentLayer = mMap. get_Layer (0 );
If (currentLayer is IFeatureLayer)
{
IFeatureLayer featureLayer = currentLayer as IFeatureLayer;
IDataset dataset = featureLayer. FeatureClass as IDataset;
IWorkspace workspace = dataset. Workspace;
M_engineEditor.StartEditing (workspace, mMap. Map );
(IEngineEditLayers) m_engineEditor). SetTargetLayer (featureLayer, 0 );
SetCurrentTask (ref m_engineEditor, "new element ");
}
}
}
///
/// Set the edited Task Type
///
///
/// Task Name
Public static void SetCurrentTask (ref IEngineEditor pEngineEditor, string taskName)
{
IEngineEditTask edittask;
If (pEngineEditor. EditState = esriEngineEditState. esriEngineStateEditing)
{
Switch (taskName)
{
Case "new element ":
Edittask = pEngineEditor. GetTaskByUniqueName ("ControlToolsEditing_CreateNewFeatureTask ");
If (edittask! = Null)
{
PEngineEditor. CurrentTask = edittask;
}
Break;
Case "modify image ":
Edittask = pEngineEditor. GetTaskByUniqueName ("ReshapePolylineEditTask_Reshape Polyline_CSharp ");
If (edittask! = Null)
{
PEngineEditor. CurrentTask = edittask;
}
Break;
Case "Modify element ":
Edittask = pEngineEditor. GetTaskByUniqueName ("ControlToolsEditing_ModifyFeatureTask ");
If (edittask! = Null)
{
PEngineEditor. CurrentTask = edittask;
}
Break;
}
}
}
Delete, copy, and paste. After you enable editing for m_EngineEditor, you can directly call the following command.
ControlsEditingEditToolClass // used to select the Element Object
ControlsEditingCopyCommandClass
ControlsEditingPasteCommandClass
ControlsEditingClearCommandClass
Undo and redo Functions
///
/// Scatter Edit
///
/// IMap object
Public void MapUndoEdit (IMap m_pMap)
{
IEngineEditProperties ep = new EngineEditorClass ();
ILayer m_pCurrentLayer = ep. TargetLayer;
If (m_pCurrentLayer = null) return;
IFeatureLayer pFeatureLayer = (IFeatureLayer) m_pCurrentLayer;
IDataset pDataset = (IDataset) pFeatureLayer. FeatureClass;
If (pDataset = null) return;
IWorkspaceEdit pWorkspaceEdit = (IWorkspaceEdit) pDataset. Workspace;
Bool bHasUndos = false;
PWorkspaceEdit. HasUndos (ref bHasUndos );
If (bHasUndos)
PWorkspaceEdit. UndoEditOperation ();
IActiveView pActiveView = (IActiveView) m_pMap;
PActiveView. Refresh ();
}
///
/// Redo
///
/// IMap object
Public void MapRedoEdit (IMap m_pMap)
{
IEngineEditProperties ep = new EngineEditorClass ();
ILayer m_pCurrentLayer = ep. TargetLayer;
If (m_pCurrentLayer = null) return;
IFeatureLayer pFeatureLayer = (IFeatureLayer) m_pCurrentLayer;
IDataset pDataset = (IDataset) pFeatureLayer. FeatureClass;
If (pDataset = null) return;
IWorkspaceEdit pWorkspaceEdit = (IWorkspaceEdit) pDataset. Workspace;
Bool bHasUndos = false;
PWorkspaceEdit. HasUndos (ref bHasUndos );
If (bHasUndos)
PWorkspaceEdit. RedoEditOperation ();
IActiveView pActiveView = (IActiveView) m_pMap;
PActiveView. Refresh ();
}