Method ApplyEdit
- Namespace
- OpenCAD2D
- Assembly
- OpenCAD2D.Core.dll
ApplyEdit(string, IReadOnlyList<CadEditRecord>, Action<CadEditScope>)
Applies one edit: the one way the presenter changes the drawing. The gate (EditGate) is asked about
every planned change of an existing entity first, and one refusal refuses the whole edit with nothing written. Then
apply writes the change; if it throws, the drawing is read back as it stood before and the edit
fails with the exception's message. A made edit is one undo step, or part of the open group's
(BeginGroup(string)); the display lists and pick indexes of the spaces it touched are dropped, and
Changed is raised.
public CadEditResult ApplyEdit(string name, IReadOnlyList<CadEditRecord> planned, Action<CadEditScope> apply)
Parameters
namestringThe name of the step: a command's name, as MOVE, or "Properties", "Grip".
plannedIReadOnlyList<CadEditRecord>The changes planned to existing entities, tables and settings, each asked through the gate where it names an entity; may be null or empty for an edit that only adds entities.
applyAction<CadEditScope>Writes the change; an entity it makes is added through Append<T>(CadSpace, T), so that it is recorded.
Returns
- CadEditResult
What came of it.
Remarks
A planned change of an entity whose owner takes its own edits (MoveOnly or
Edit in Owners) is handed to the owner first, as a CadEdit
through TryApply(CadDocument, CadEdit), after the gate let it through: the owner changes the entity and
records its hand edit in edits of its own, which join this one's undo step, so that one undo takes both back. The
action then leaves that entity alone (IsHandled(string)), and is not run at all where the owners
made every planned change. An owner that does not take its edit refuses the whole edit, "The model owner did not
take this edit.", the drawing read back as it was. A mark of handle 2F moved 40 to the right by MOVE reaches its
owner as CadEdit("2F", Move, newValue: "40,0").
The value an owner is given is the planned record's NewValue (and old value), written as CadEditKind says: the presenter's commands, grips and Properties plan them so. A move planned with no value is measured: the action is run once, the entity's box seen to move, and the drawing read back before the owner is asked; so such an action may run twice and is to find its entities through the scope each time. The edits an owner makes while it applies (inside TryApply(CadDocument, CadEdit)) are its own and are not handed back.
Exceptions
- ArgumentNullException
Thrown when the name or the action is null.