private void removeNodeAt(int patchIndex, int coordinateIndex) { EditAction forwardAction; EditAction backwardAction; EditActionParameters parameters = new EditActionParameters() { OldGeometry = _geometry, PatchIndex = patchIndex, NodeIndex = coordinateIndex, }; forwardAction = new EditAction(EditActionType.DeleteNode, parameters, out backwardAction); HistoryEntry pair = new HistoryEntry(forwardAction, backwardAction); _geometry = _history.DoAction(pair, _geometry); }
private void insertNodeAt(int patchIndex, int coordinateIndex, ICoordinate coordinate) { EditAction forwardAction; EditAction backwardAction; EditActionParameters parameters = new EditActionParameters() { OldGeometry = _geometry, PatchIndex = patchIndex, NodeIndex = coordinateIndex, NodePosition = (ICoordinate)coordinate.Clone() }; forwardAction = new EditAction(EditActionType.InsertNode, parameters, out backwardAction); HistoryEntry pair = new HistoryEntry(forwardAction, backwardAction); _geometry = _history.DoAction(pair, _geometry); }
/// <summary> /// Replaces currently editing geometry with the other one. /// </summary> /// <param name="newGeometry">A new instance of IGeometry</param> public void ReplaceGeometry(IGeometry newGeometry) { if (newGeometry == null || newGeometry is Polygon || newGeometry is Polyline) { EditAction forwardAction; EditAction backwardAction; EditActionParameters parameters = new EditActionParameters() { OldGeometry = _geometry, NewGeometry = newGeometry }; forwardAction = new EditAction(EditActionType.ReplaceGeometry, parameters, out backwardAction); HistoryEntry pair = new HistoryEntry(forwardAction, backwardAction); _geometry = _history.DoAction(pair, _geometry); //_geometry = newGeometry; ActiveNodeNumber = -1; } else throw new InvalidCastException("Allows only Polygons and Polylines"); }
/// <summary> /// Inserts a new coordinate patch into the editing geometry. /// </summary> /// <param name="patchIndex">A zero-based index of patch</param> /// <param name="coordinates">A coordinates of inserted patch</param> public void InsertPatch(int patchIndex, IEnumerable<ICoordinate> coordinates) { if (_geometry is Polygon) if ((_geometry as Polygon).Contours.Count < patchIndex) throw new ArgumentOutOfRangeException("Patch index exceeds the number of patches", "patchIndex"); if (_geometry is Polyline) if ((_geometry as Polyline).Paths.Count < patchIndex) throw new ArgumentOutOfRangeException("Patch index exceeds the number of patches", "patchIndex"); EditAction forwardAction; EditAction backwardAction; EditActionParameters parameters = new EditActionParameters() { OldGeometry = _geometry, PatchIndex = patchIndex, PatchCoordinates = coordinates }; forwardAction = new EditAction(EditActionType.InsertPatch, parameters, out backwardAction); HistoryEntry pair = new HistoryEntry(forwardAction, backwardAction); _geometry = _history.DoAction(pair, _geometry); _activePatchIndex = -1; _activeCoordinateIndex = -1; }
/// <summary> /// Updates the position of the active node with the specified value /// </summary> /// <param name="coordinate">New position of the active node</param> /// <param name="commitIntoUndoList">A value indicating whether current update should be commited into undo list</param> /// <returns>true if the position has been updated, false otherwise</returns> public bool UpdateActiveNodePosition(ICoordinate coordinate, bool commitIntoUndoList) { if (ActivePatchIndex == -1) return false; if (commitIntoUndoList) { EditAction forwardAction; EditAction backwardAction; EditActionParameters parameters = new EditActionParameters() { OldGeometry = _geometry, PatchIndex = _activePatchIndex, NodeIndex = _activeCoordinateIndex, NodePosition = (ICoordinate)coordinate.Clone() }; // update active node with the old value // this is necessary for properly generation of the inverse action UpdateActiveNodePosition(oldActiveNodeCoordinate, false); forwardAction = new EditAction(EditActionType.SetNodePosition, parameters, out backwardAction); HistoryEntry pair = new HistoryEntry(forwardAction, backwardAction); _geometry = _history.DoAction(pair, _geometry); oldActiveNodeCoordinate = (ICoordinate)coordinate.Clone(); } else { if (_snapper != null && _snapper.SnapMethod != null) coordinate = _snapper.SnapMethod(coordinate); if (_geometry is Polyline) { Polyline polyline = (Polyline)_geometry; polyline.Paths[_activePatchIndex].Vertices[_activeCoordinateIndex].X = coordinate.X; polyline.Paths[_activePatchIndex].Vertices[_activeCoordinateIndex].Y = coordinate.Y; } if (_geometry is Polygon) { Polygon polygon = (Polygon)_geometry; polygon.Contours[_activePatchIndex].Vertices[_activeCoordinateIndex].X = coordinate.X; polygon.Contours[_activePatchIndex].Vertices[_activeCoordinateIndex].Y = coordinate.Y; } } return true; }
internal IGeometry DoAction(HistoryEntry entry, IGeometry g) { if (_currentEntry != null && _currentEntry.Next != null) { while(_entries.Last != _currentEntry) _entries.RemoveLast(); } if (_currentEntry == null && _entries.Count > 0) _entries.Clear(); _entries.AddLast(entry); _currentEntry = _entries.Last; return entry.Redo(g); }