How to create a sketch operation


Summary Any edits that are made to an edit sketch should be enclosed inside a sketch operation. Doing so will allow the sketch operation to be added to the operation stack, thereby providing undo/redo capabilities.

In this topic:

 

About Sketch Operations

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/redo capabilities.
Within the lifetime 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 5 vertices, 5 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 edit operation called 'Create'. 

Creating Sketch Operations

IEngineSketchOperation.Start marks the beginning of sketch operation. 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. IEngineSketchOperation.Finish marks the end of a sketch operation at which point it will be added to the operation stack.
There are a number of setup steps required to ensure that sketch operations are correctly added to the operation stack. Refer to How to work with the OperationStack for more details.
The following code sample illustrates how to create a sketch operation that will delete 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:
  • invalEnv is the envelope to be invalidated.  In the 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 that the appropriate listener will be notified.  In the example above 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 example, the deleted vertex will be passed through to the Point parameter of the IEngineEditEvents.OnVertexDeleted event. 

Undo/Redo Sketch Operations

 
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.

Sketch Operation Events

 
The IEngineEditEvents interface exposes a number of events that 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 Runtime
ArcView
ArcEditor
ArcInfo