예제 #1
0
        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);
        }
예제 #2
0
        public EditAction(EditActionType actionType, EditActionParameters parameters, out EditAction inverseAction)
        {
            _actionType = actionType;
            _parameters = parameters;

            EditActionParameters invertedParameters = new EditActionParameters();

            inverseAction = null;

            if (actionType == EditActionType.SetNodePosition)
            {
                invertedParameters.PatchIndex = parameters.PatchIndex;
                invertedParameters.NodeIndex = parameters.NodeIndex;

                ICoordinate oldPosition = null;
                if (_parameters.OldGeometry is Polyline)
                    oldPosition = (ICoordinate)(_parameters.OldGeometry as Polyline).Paths[parameters.PatchIndex].Vertices[_parameters.NodeIndex].Clone();

                if (_parameters.OldGeometry is Polygon)
                    oldPosition = (ICoordinate)(_parameters.OldGeometry as Polygon).Contours[parameters.PatchIndex].Vertices[_parameters.NodeIndex].Clone();

                invertedParameters.NodePosition = oldPosition;
                
            }
            else if (actionType == EditActionType.InsertNode)
            {
                invertedParameters.PatchIndex = parameters.PatchIndex;
                invertedParameters.NodeIndex = parameters.NodeIndex;
            }
            else if (actionType == EditActionType.DeleteNode)
            {
                invertedParameters.PatchIndex = parameters.PatchIndex;
                invertedParameters.NodeIndex = parameters.NodeIndex;

                ICoordinate oldPosition = null;
                if (_parameters.OldGeometry is Polyline)
                    oldPosition = (ICoordinate)(_parameters.OldGeometry as Polyline).Paths[parameters.PatchIndex].Vertices[_parameters.NodeIndex].Clone();

                if (_parameters.OldGeometry is Polygon)
                    oldPosition = (ICoordinate)(_parameters.OldGeometry as Polygon).Contours[parameters.PatchIndex].Vertices[_parameters.NodeIndex].Clone();

                invertedParameters.NodePosition = oldPosition;
            }
            else if (actionType == EditActionType.InsertPatch)
            {
                invertedParameters.PatchIndex = parameters.PatchIndex;
            }
            else if (actionType == EditActionType.DeletePatch)
            {
                invertedParameters.PatchIndex = parameters.PatchIndex;

                List<ICoordinate> patchCoordinates = new List<ICoordinate>();
                if (_parameters.OldGeometry is Polyline)
                    foreach (ICoordinate c in (_parameters.OldGeometry as Polyline).Paths[parameters.PatchIndex].Vertices)
                        patchCoordinates.Add((ICoordinate)c.Clone());

                if (_parameters.OldGeometry is Polygon)
                    foreach (ICoordinate c in (_parameters.OldGeometry as Polygon).Contours[parameters.PatchIndex].Vertices)
                        patchCoordinates.Add((ICoordinate)c.Clone());

                invertedParameters.PatchCoordinates = patchCoordinates;
            }
            else if (actionType == EditActionType.ReplaceGeometry)
            {
                invertedParameters.NewGeometry = parameters.OldGeometry;
            }

            _parameters.OldGeometry = null;
            inverseAction = new EditAction(getInvertedAction(actionType), invertedParameters);
        }
예제 #3
0
        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);
        }
예제 #4
0
        /// <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");
        }
예제 #5
0
        /// <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;
        }
예제 #6
0
        /// <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;
        }
예제 #7
0
 public HistoryEntry(EditAction forwardAction, EditAction backwardAction)
 {
     this._forwardAction = forwardAction;
     this._backwardAction = backwardAction;
 }