Example #1
0
            private void RemovePointsAndSegmentsFromOpenFigure(int figureIndex, List <int> segmentsByFigure, List <int> pointsByFigure)
            {
                PathGeometryEditor geometryEditor = this.pathEditorTarget.CreateGeometryEditor();
                int index1 = 0;
                int index2 = 0;

                while (index1 < segmentsByFigure.Count || index2 < pointsByFigure.Count)
                {
                    int pointIndex1 = -1;
                    int pointIndex2 = -1;
                    if (index1 < segmentsByFigure.Count)
                    {
                        pointIndex1 = segmentsByFigure[index1];
                    }
                    if (index2 < pointsByFigure.Count)
                    {
                        pointIndex2 = pointsByFigure[index2];
                    }
                    int num = PathFigureUtilities.PointCount(geometryEditor.PathGeometry.Figures[figureIndex]) - 1;
                    if (pointIndex2 == num || pointIndex1 == num)
                    {
                        geometryEditor.RemoveLastSegmentOfFigure(figureIndex);
                        if (pointIndex2 == num)
                        {
                            ++index2;
                        }
                        if (pointIndex1 == num)
                        {
                            ++index1;
                        }
                    }
                    else if (pointIndex1 > pointIndex2)
                    {
                        geometryEditor.SplitFigure(figureIndex, pointIndex1);
                        geometryEditor.RemoveLastSegmentOfFigure(figureIndex);
                        ++index1;
                    }
                    else if (pointIndex1 < pointIndex2)
                    {
                        geometryEditor.RemovePoint(figureIndex, pointIndex2);
                        ++index2;
                    }
                    else
                    {
                        geometryEditor.SplitFigure(figureIndex, pointIndex2);
                        geometryEditor.RemoveLastSegmentOfFigure(figureIndex);
                        geometryEditor.RemoveFirstSegmentOfFigure(geometryEditor.PathGeometry.Figures.Count - 1);
                        ++index2;
                        ++index1;
                    }
                }
            }
        protected override void OnDrag(MouseDevice mouseDevice, double zoom)
        {
            this.currentTangentPoint = this.GetPointInViewRootCoordinates(mouseDevice, true);
            Vector correspondingVector = ElementUtilities.GetCorrespondingVector(this.currentTangentPoint - this.currentNodePoint, this.geometryToDocument, this.IsShiftDown ? this.AxisConstraint : (AxisConstraint)null);
            Vector lastTangent         = this.LastTangent;

            this.LastTangent = correspondingVector;
            PathFigure       pathFigure       = this.PathEditContext.GetPathFigure(this.Path);
            PathFigureEditor pathFigureEditor = pathFigure == null ? (PathFigureEditor)null : new PathFigureEditor(pathFigure);

            if (pathFigureEditor != null && !PathFigureUtilities.IsIsolatedPoint(pathFigureEditor.PathFigure))
            {
                PathGeometryEditor pathGeometryEditor = this.BeginEditing();
                bool  flag   = PathFigureUtilities.IsClosed(pathFigureEditor.PathFigure);
                int   index  = PathFigureUtilities.PointCount(pathFigureEditor.PathFigure) - (flag ? 0 : 1);
                Point point1 = pathFigureEditor.GetPoint(index - 1);
                Point point2 = pathFigureEditor.GetPoint(index);
                if (pathFigureEditor.GetPointKind(index) == PathPointKind.Line)
                {
                    pathGeometryEditor.RemoveLastSegmentOfFigure(this.PathEditContext.FigureIndex);
                    if (flag)
                    {
                        pathGeometryEditor.CloseFigureWithCubicBezier(point1, point2, this.PathEditContext.FigureIndex);
                    }
                    else
                    {
                        pathGeometryEditor.AppendCubicBezier(point1, point2, point2, this.PathEditContext.FigureIndex);
                    }
                    pathFigureEditor = new PathFigureEditor(this.PathEditContext.GetPathFigure(this.Path));
                }
                if (!this.IsAltDown)
                {
                    if (!this.areTangentsSymmetric)
                    {
                        double length = this.LastTangent.Length;
                        if (length > 0.0)
                        {
                            int    num1 = PathFigureUtilities.PointCount(pathFigureEditor.PathFigure);
                            double num2 = (pathFigureEditor.GetPoint(num1 - 1) - pathFigureEditor.GetPoint(num1 - 2)).Length / length;
                            pathGeometryEditor.SetPoint(this.PathEditContext.FigureIndex, num1 - 2, point2 - num2 * this.LastTangent);
                        }
                    }
                    else
                    {
                        int pointIndex = PathFigureUtilities.PointCount(pathFigureEditor.PathFigure) - (PathFigureUtilities.IsClosed(pathFigureEditor.PathFigure) ? 1 : 2);
                        pathGeometryEditor.SetPoint(this.PathEditContext.FigureIndex, pointIndex, point2 - this.LastTangent);
                    }
                }
                if (PathFigureUtilities.IsClosed(pathFigureEditor.PathFigure) && pathFigureEditor.GetPointKind(3) == PathPointKind.Cubic && this.areTangentsSymmetric)
                {
                    pathGeometryEditor.SetPoint(this.PathEditContext.FigureIndex, 1, point2 + this.LastTangent);
                }
                this.PathEditorTarget.AddCriticalEdit();
            }
            base.OnDrag(mouseDevice, zoom);
        }