In this topic
- About sketch operations
- Creating sketch operations
- Undo and redo sketch operations
- Sketch operation events
Sketch operations are operations that work with the edit sketch. Changes to the edit sketch should be made within sketch operations so that they can be added to the operation stack, thereby providing undo and redo capabilities.
Within the life span of the edit session, any sketch operations added to the operation stack are temporary. When the sketch is finished, the sketch operations are removed and replaced with a single edit operation. For example, when digitizing a new polyline with five vertices, five individual sketch operations will be added to the operation stack (each called Add Vertex). By finishing the sketch, these sketch operations will be replaced by a single Create edit operation.
A sketch operation begins with IEngineSketchOperation.Start. Use the IEngineSketchOperation.SetMenuString method to name the operation so that it can be identified on the operation stack and used as a ToolTip for the Undo and Redo commands. A sketch operation ends with IEngineSketchOperation.Finish at which point it will be added to the operation stack.
There are required setup steps to ensure that sketch operations are correctly added to the operation stack. For more information, see How to work with the operation stack.
The following code example shows how to create a sketch operation that deletes the last vertex in the edit sketch:[Java]
IEngineSketchOperation sketchOp = new EngineSketchOperation(); IEngineEditor engineEditor = new EngineEditor(); IEngineEditSketch editSketch = (IEngineEditSketch)engineEditor; // Clone the original edit sketch envelope. Used to invalidate display. IEnvelope invalidateEnv = (IEnvelope)((IClone)editSketch.getGeometry().getEnvelope()) .esri_clone(); // Start the edit sketch operation. sketchOp.start(engineEditor); // Set the MenuString to identify the edit sketch operation. sketchOp.setMenuString("Delete Vertex"); // Get the point collection from the edit sketch. IPointCollection pointCol = (IPointCollection)editSketch.getGeometry(); // Clone the vertex to be removed. IClone vertexToRemove = (IClone)pointCol.getPoint(pointCol.getPointCount() - 1); vertexToRemove.esri_clone(); // Remove the last vertex and refresh the sketch. pointCol.removePoints(pointCol.getPointCount() - 1, 1); editSketch.setGeometryByRef((IGeometry)pointCol); editSketch.refreshSketch(); // Finish the sketch operation. sketchOp.finish(invalidateEnv, esriEngineSketchOperationType.esriEngineSketchOperationVertexDeleted, vertexToRemove);
The arguments supplied to the IEngineSketchOperation.Finish method are important. See the following:
- invalEnv is the envelope to be invalidated. In the previous code example, the pre-modified envelope of the edit sketch is used to avoid potentially leaving artifacts on the screen after deleting the last vertex.
- opType is an esriEngineSketchOperationType constant that ensures the appropriate listener will be notified. In the previous code example, specifying esriEngineSketchOperationVertexDeleted ensures that the IEngineEditEvents.OnVertexDeleted event will be fired.
- Data is the vertex that the action was performed on and will be passed to appropriate events. In the previous code example, the deleted vertex will be passed through to the Point parameter of the IEngineEditEvents.OnVertexDeleted event.
To undo or redo an individual sketch operation, the IEngineSketchOperation.Undo or IEngineSketchOperation.Redo methods can be used.
To undo or redo multiple sketch operations, access the operation stack using IToolbarControl2.OperationStack, then call the IOperationStack.Undo or IOperationStack.Redo methods, respectively.
The IEngineEditEvents interface exposes the following events, which allow the application to respond to sketch operations:
See Also:How to create an edit session
How to listen to edit events
How to work with the operation stack
Sample: Reshape polyline edit task
sample: Editing custom application
|Development licensing||Deployment licensing|
|Engine Developer Kit||Engine|
|ArcGIS for Desktop Basic|
|ArcGIS for Desktop Standard|
|ArcGIS for Desktop Advanced|