protected override void OnBegin(PathEditContext pathEditContext, MouseDevice mouseDevice)
        {
            this.View.ViewModel.PathPartSelectionSet.SetSelection((PathPart) new PathPoint((SceneElement)this.PathEditorTarget.EditingElement, this.PathEditorTarget.PathEditMode, pathEditContext.FigureIndex, pathEditContext.PartIndex));
            this.geometryToDocument = this.EditingElementTransformToRoot;
            int figureIndex = pathEditContext.FigureIndex;
            int num         = pathEditContext.PartIndex;
            PathFigureEditor pathFigureEditor = new PathFigureEditor(pathEditContext.GetPathFigure(this.Path));
            Point            point            = pathFigureEditor.GetPoint(num);
            int downstreamSegment             = pathFigureEditor.GetLastIndexOfDownstreamSegment(num);

            if (pathFigureEditor.GetPointKind(num) != PathPointKind.Cubic && pathFigureEditor.GetPointKind(num) != PathPointKind.Start || pathFigureEditor.GetPointKind(downstreamSegment) != PathPointKind.Cubic)
            {
                PathGeometryEditor pathGeometryEditor = this.BeginEditing();
                num = this.PromoteAdjacentSegments(pathEditContext);
                pathFigureEditor     = new PathFigureEditor(pathGeometryEditor.PathGeometry.Figures[figureIndex]);
                this.PathEditContext = new PathEditContext(figureIndex, num);
                this.View.ViewModel.PathPartSelectionSet.SetSelection((PathPart) new PathPoint((SceneElement)this.PathEditorTarget.EditingElement, this.PathEditorTarget.PathEditMode, this.PathEditContext.FigureIndex, this.PathEditContext.PartIndex));
            }
            if (this.zeroTangents)
            {
                if ((num > 0 || PathFigureUtilities.IsClosed(pathFigureEditor.PathFigure)) && !VectorUtilities.ArePathPointsVeryClose(pathFigureEditor.GetPoint(num), pathFigureEditor.GetPoint(num - 1)))
                {
                    this.BeginEditing().SetPoint(figureIndex, num - 1, point);
                }
                if (pathFigureEditor.GetLastIndexOfDownstreamSegment(num) != num && !VectorUtilities.ArePathPointsVeryClose(pathFigureEditor.GetPoint(num), pathFigureEditor.GetPoint(num + 1)))
                {
                    this.BeginEditing().SetPoint(figureIndex, num + 1, point);
                }
                if (num == PathFigureUtilities.PointCount(pathFigureEditor.PathFigure) - 1 && PathFigureUtilities.IsOpen(pathFigureEditor.PathFigure))
                {
                    this.LastTangent = new Vector(0.0, 0.0);
                }
            }
            base.OnBegin(pathEditContext, mouseDevice);
        }
 protected override void OnDrag(MouseDevice mouseDevice, double zoom)
 {
     if (this.IsActive)
     {
         PathGeometryEditor pathGeometryEditor = this.BeginEditing();
         PathFigureEditor   pathFigureEditor   = new PathFigureEditor(this.PathEditContext.GetPathFigure(this.Path));
         int figureIndex       = this.PathEditContext.FigureIndex;
         int partIndex         = this.PathEditContext.PartIndex;
         int ofUpstreamSegment = pathFigureEditor.GetFirstIndexOfUpstreamSegment(partIndex);
         if (!this.hasDragged)
         {
             Point point1 = pathFigureEditor.GetPoint(ofUpstreamSegment);
             Point point2 = pathFigureEditor.GetPoint(partIndex);
             if (VectorUtilities.ArePathPointsVeryClose(point2, pathFigureEditor.GetPoint(ofUpstreamSegment + 2)) && VectorUtilities.ArePathPointsVeryClose(point1, pathFigureEditor.GetPoint(ofUpstreamSegment + 1)))
             {
                 pathGeometryEditor.SetPoint(figureIndex, ofUpstreamSegment + 1, VectorUtilities.WeightedAverage(point1, point2, 1.0 / 3.0));
                 pathGeometryEditor.SetPoint(figureIndex, ofUpstreamSegment + 2, VectorUtilities.WeightedAverage(point1, point2, 2.0 / 3.0));
                 this.initialFirstCubicHandle  = pathFigureEditor.GetPoint(ofUpstreamSegment + 1);
                 this.initialSecondCubicHandle = pathFigureEditor.GetPoint(ofUpstreamSegment + 2);
             }
             this.hasDragged = true;
         }
         Vector correspondingVector = ElementUtilities.GetCorrespondingVector((this.GetPointInViewRootCoordinates(mouseDevice, false) - this.initialPointerPosition) * this.damping, this.geometryToDocument, this.IsShiftDown ? this.AxisConstraint : (AxisConstraint)null);
         Vector vector1             = correspondingVector * this.firstHandleCoef;
         Vector vector2             = correspondingVector * this.secondHandleCoef;
         pathGeometryEditor.SetPoint(figureIndex, ofUpstreamSegment + 1, this.initialFirstCubicHandle + vector1);
         pathGeometryEditor.SetPoint(figureIndex, ofUpstreamSegment + 2, this.initialSecondCubicHandle + vector2);
     }
     base.OnDrag(mouseDevice, zoom);
 }
Exemple #3
0
        private void SetLineSegmentUsingMinimalDiff(LineSegment currentSegment, LineSegment pathSegment, PropertyReference segmentReference)
        {
            PropertyReference propertyReference = segmentReference.Append(PathElement.LineSegmentPointProperty);

            if (VectorUtilities.ArePathPointsVeryClose(currentSegment.Point, pathSegment.Point))
            {
                return;
            }
            this.targetElement.SetValueAsWpf(propertyReference, (object)pathSegment.Point);
        }
Exemple #4
0
        private void SetPolyLineSegmentUsingMinimalDiff(PolyLineSegment currentSegment, PolyLineSegment pathSegment, PropertyReference segmentReference)
        {
            PropertyReference propertyReference1 = segmentReference.Append(PathElement.PolyLineSegmentPointsProperty);

            for (int index = 0; index < currentSegment.Points.Count; ++index)
            {
                ReferenceStep     step = (ReferenceStep)IndexedClrPropertyReferenceStep.GetReferenceStep((IPlatformMetadata)this.platformMetadata, PlatformTypes.PointCollection, index);
                PropertyReference propertyReference2 = propertyReference1.Append(step);
                if (!VectorUtilities.ArePathPointsVeryClose(currentSegment.Points[index], pathSegment.Points[index]))
                {
                    this.targetElement.SetValueAsWpf(propertyReference2, (object)pathSegment.Points[index]);
                }
            }
        }
Exemple #5
0
 private void SetFigureUsingMinimalDiff(PathFigure pathFigure, PathFigure currentFigure, PropertyReference figureReference)
 {
     if (!VectorUtilities.ArePathPointsVeryClose(currentFigure.StartPoint, pathFigure.StartPoint))
     {
         this.targetElement.SetValueAsWpf(figureReference.Append(PathElement.PathFigureStartPointProperty), (object)pathFigure.StartPoint);
     }
     for (int index = 0; index < pathFigure.Segments.Count; ++index)
     {
         PathSegment       currentSegment    = currentFigure.Segments[index];
         PathSegment       pathSegment       = pathFigure.Segments[index];
         PropertyReference segmentsReference = figureReference.Append(PathElement.PathFigureSegmentsProperty).Append((ReferenceStep)IndexedClrPropertyReferenceStep.GetReferenceStep((IPlatformMetadata)this.platformMetadata, PlatformTypes.PathSegmentCollection, index));
         this.SetSegmentUsingMinimalDiff(pathSegment, currentSegment, segmentsReference);
     }
 }
Exemple #6
0
        private void SetQuadraticBezierSegmentUsingMinimalDiff(QuadraticBezierSegment currentSegment, QuadraticBezierSegment pathSegment, PropertyReference segmentReference)
        {
            PropertyReference propertyReference1 = segmentReference.Append(PathElement.QuadraticBezierSegmentPoint1Property);
            PropertyReference propertyReference2 = segmentReference.Append(PathElement.QuadraticBezierSegmentPoint2Property);

            if (!VectorUtilities.ArePathPointsVeryClose(currentSegment.Point1, pathSegment.Point1))
            {
                this.targetElement.SetValueAsWpf(propertyReference1, (object)pathSegment.Point1);
            }
            if (VectorUtilities.ArePathPointsVeryClose(currentSegment.Point2, pathSegment.Point2))
            {
                return;
            }
            this.targetElement.SetValueAsWpf(propertyReference2, (object)pathSegment.Point2);
        }
 protected override void OnEnd()
 {
     if (!this.hasDragged)
     {
         PathFigureEditor pathFigureEditor = new PathFigureEditor(this.PathEditContext.GetPathFigure(this.Path));
         int partIndex         = this.PathEditContext.PartIndex;
         int ofUpstreamSegment = pathFigureEditor.GetFirstIndexOfUpstreamSegment(partIndex);
         if (!VectorUtilities.ArePathPointsVeryClose(pathFigureEditor.GetPoint(ofUpstreamSegment), pathFigureEditor.GetPoint(ofUpstreamSegment + 1)) || !VectorUtilities.ArePathPointsVeryClose(pathFigureEditor.GetPoint(partIndex), pathFigureEditor.GetPoint(ofUpstreamSegment + 2)))
         {
             PathGeometryEditor pathGeometryEditor = this.BeginEditing();
             pathGeometryEditor.SetPoint(this.PathEditContext.FigureIndex, ofUpstreamSegment + 2, pathFigureEditor.GetPoint(partIndex));
             pathGeometryEditor.SetPoint(this.PathEditContext.FigureIndex, ofUpstreamSegment + 1, pathFigureEditor.GetPoint(ofUpstreamSegment));
         }
     }
     base.OnEnd();
 }
        private static void RemoveDegenerateSegments(PathFigure pathFigure, bool removeInvisible)
        {
            PathSegmentCollection segments = pathFigure.Segments;
            Point b          = pathFigure.StartPoint;
            Point startPoint = pathFigure.StartPoint;

            for (int index = 0; index < segments.Count; ++index)
            {
                PathSegment pathSegment = segments[index];
                LineSegment lineSegment;
                if ((lineSegment = pathSegment as LineSegment) != null)
                {
                    if (VectorUtilities.ArePathPointsVeryClose(lineSegment.Point, b) || removeInvisible && !lineSegment.IsStroked && pathFigure.Segments.Count == 1)
                    {
                        segments.RemoveAt(index--);
                    }
                    else
                    {
                        b = lineSegment.Point;
                    }
                }
                else
                {
                    QuadraticBezierSegment quadraticBezierSegment;
                    if ((quadraticBezierSegment = pathSegment as QuadraticBezierSegment) != null)
                    {
                        if (VectorUtilities.ArePathPointsVeryClose(quadraticBezierSegment.Point1, b) && VectorUtilities.ArePathPointsVeryClose(quadraticBezierSegment.Point2, b))
                        {
                            segments.RemoveAt(index--);
                        }
                        else
                        {
                            b = quadraticBezierSegment.Point2;
                        }
                    }
                    else
                    {
                        BezierSegment bezierSegment;
                        if ((bezierSegment = pathSegment as BezierSegment) != null)
                        {
                            if (VectorUtilities.ArePathPointsVeryClose(bezierSegment.Point1, b) && VectorUtilities.ArePathPointsVeryClose(bezierSegment.Point2, b) && VectorUtilities.ArePathPointsVeryClose(bezierSegment.Point3, b))
                            {
                                segments.RemoveAt(index--);
                            }
                            else
                            {
                                b = bezierSegment.Point3;
                            }
                        }
                    }
                }
            }
            if (segments.Count < 1)
            {
                return;
            }
            LineSegment lineSegment1 = segments[segments.Count - 1] as LineSegment;

            if (lineSegment1 == null || !pathFigure.IsClosed || !VectorUtilities.ArePathPointsVeryClose(startPoint, lineSegment1.Point))
            {
                return;
            }
            segments.RemoveAt(segments.Count - 1);
        }
Exemple #9
0
        protected virtual void CreatePathAdorners(List <Adorner> oldAdornerList, List <Adorner> newAdornerList)
        {
            this.adornerCounts.Clear();
            this.adornerOffsets.Clear();
            PathPartSelectionSet      partSelectionSet = this.PathPartSelectionSet;
            List <PathPointAdorner>   list1            = new List <PathPointAdorner>();
            List <PathSegmentAdorner> list2            = new List <PathSegmentAdorner>();
            List <PathTangentAdorner> list3            = new List <PathTangentAdorner>();
            int index1 = 0;
            int index2 = 0;
            int index3 = 0;

            foreach (Adorner adorner in oldAdornerList)
            {
                PathPointAdorner pathPointAdorner;
                if ((pathPointAdorner = adorner as PathPointAdorner) != null)
                {
                    list1.Add(pathPointAdorner);
                }
                else
                {
                    PathSegmentAdorner pathSegmentAdorner;
                    if ((pathSegmentAdorner = adorner as PathSegmentAdorner) != null)
                    {
                        list2.Add(pathSegmentAdorner);
                    }
                    else
                    {
                        PathTangentAdorner pathTangentAdorner;
                        if ((pathTangentAdorner = adorner as PathTangentAdorner) != null)
                        {
                            list3.Add(pathTangentAdorner);
                        }
                    }
                }
            }
            for (int figureIndex = 0; figureIndex < this.PathGeometry.Figures.Count; ++figureIndex)
            {
                PathFigure       figure           = this.PathGeometry.Figures[figureIndex];
                PathFigureEditor pathFigureEditor = new PathFigureEditor(figure);
                this.adornerOffsets.Add((object)this.AdornerList.Count);
                int length1 = PathFigureUtilities.PointCount(figure);
                int length2 = length1 + (PathFigureUtilities.IsClosed(figure) ? true : false);
                PathSegmentAdorner[] pathSegmentAdornerArray = new PathSegmentAdorner[length2];
                PathPointKind[]      pathPointKindArray      = new PathPointKind[length2];
                pathPointKindArray[0] = pathFigureEditor.GetPointKind(0);
                int num1 = 1;
                for (int index4 = 0; index4 < figure.Segments.Count; ++index4)
                {
                    System.Windows.Media.PathSegment segment = figure.Segments[index4];
                    int pointCount = PathSegmentUtilities.GetPointCount(segment);
                    for (int index5 = 0; index5 < pointCount; ++index5)
                    {
                        pathPointKindArray[num1++] = PathSegmentUtilities.GetPointKind(segment, index5);
                    }
                }
                int index6 = 1;
                for (int segmentIndex = 0; segmentIndex < figure.Segments.Count; ++segmentIndex)
                {
                    int pointCount = PathSegmentUtilities.GetPointCount(figure.Segments[segmentIndex]);
                    for (int segmentPointIndex = 0; segmentPointIndex < pointCount; ++segmentPointIndex)
                    {
                        if (pathPointKindArray[index6] != PathPointKind.BezierHandle)
                        {
                            PathSegmentAdorner pathSegmentAdorner;
                            if (index2 < list2.Count)
                            {
                                pathSegmentAdorner = list2[index2];
                                pathSegmentAdorner.Initialize(figureIndex, index6 % length1, segmentIndex, segmentPointIndex);
                                oldAdornerList.Remove((Adorner)pathSegmentAdorner);
                                ++index2;
                            }
                            else
                            {
                                pathSegmentAdorner = new PathSegmentAdorner(this, figureIndex, index6 % length1, segmentIndex, segmentPointIndex);
                            }
                            if (partSelectionSet != null)
                            {
                                pathSegmentAdorner.IsActive = partSelectionSet.IsSelected((PathPart)(PathSegment)pathSegmentAdorner);
                            }
                            newAdornerList.Add((Adorner)pathSegmentAdorner);
                            pathSegmentAdornerArray[index6] = pathSegmentAdorner;
                        }
                        else
                        {
                            pathSegmentAdornerArray[index6] = (PathSegmentAdorner)null;
                        }
                        ++index6;
                    }
                }
                if (figure.IsClosed && figure.Segments.Count > 0)
                {
                    Point lastPoint = PathSegmentUtilities.GetLastPoint(figure.Segments[figure.Segments.Count - 1]);
                    if (!VectorUtilities.ArePathPointsVeryClose(figure.StartPoint, lastPoint))
                    {
                        PathSegmentAdorner pathSegmentAdorner;
                        if (index2 < list2.Count)
                        {
                            pathSegmentAdorner = list2[index2];
                            pathSegmentAdorner.Initialize(figureIndex, index6 % length1, -1, 0);
                            oldAdornerList.Remove((Adorner)pathSegmentAdorner);
                            ++index2;
                        }
                        else
                        {
                            pathSegmentAdorner = new PathSegmentAdorner(this, figureIndex, index6 % length1, -1, 0);
                        }
                        if (partSelectionSet != null)
                        {
                            pathSegmentAdorner.IsActive = partSelectionSet.IsSelected((PathPart)(PathSegment)pathSegmentAdorner);
                        }
                        newAdornerList.Add((Adorner)pathSegmentAdorner);
                        pathSegmentAdornerArray[index6] = pathSegmentAdorner;
                    }
                }
                this.adornerCounts.Add((object)(this.AdornerList.Count - (int)this.adornerOffsets[this.adornerOffsets.Count - 1]));
                this.adornerTypes.Add((object)PathPart.PartType.PathSegment);
                PathPointAdorner[] pathPointAdornerArray = new PathPointAdorner[length1];
                int index7 = 0;
                for (int segmentIndex = -1; segmentIndex < figure.Segments.Count; ++segmentIndex)
                {
                    int num2 = 1;
                    if (segmentIndex != -1)
                    {
                        num2 = PathSegmentUtilities.GetPointCount(figure.Segments[segmentIndex]);
                    }
                    for (int segmentPointIndex = 0; segmentPointIndex < num2 && index7 < length1; ++segmentPointIndex)
                    {
                        if (pathPointKindArray[index7] == PathPointKind.BezierHandle)
                        {
                            pathPointAdornerArray[index7] = (PathPointAdorner)null;
                        }
                        else
                        {
                            PathPointAdorner pathPointAdorner;
                            if (index1 < list1.Count)
                            {
                                pathPointAdorner = list1[index1];
                                pathPointAdorner.Initialize(figureIndex, index7, segmentIndex, segmentPointIndex);
                                oldAdornerList.Remove((Adorner)pathPointAdorner);
                                ++index1;
                            }
                            else
                            {
                                pathPointAdorner = new PathPointAdorner(this, figureIndex, index7, segmentIndex, segmentPointIndex);
                            }
                            pathPointAdornerArray[index7] = pathPointAdorner;
                            if (partSelectionSet != null)
                            {
                                pathPointAdornerArray[index7].IsActive = partSelectionSet.IsSelected((PathPart)(PathPoint)pathPointAdornerArray[index7]);
                            }
                        }
                        ++index7;
                    }
                }
                int endPointIndex = 0;
                for (int segmentIndex = -1; segmentIndex < figure.Segments.Count; ++segmentIndex)
                {
                    int num2 = 1;
                    if (segmentIndex != -1)
                    {
                        num2 = PathSegmentUtilities.GetPointCount(figure.Segments[segmentIndex]);
                    }
                    for (int segmentPointIndex = 0; segmentPointIndex < num2 && endPointIndex < length1; ++segmentPointIndex)
                    {
                        if (pathPointKindArray[endPointIndex] == PathPointKind.BezierHandle)
                        {
                            PathPointAdorner   pathPointAdorner   = (PathPointAdorner)null;
                            PathSegmentAdorner pathSegmentAdorner = (PathSegmentAdorner)null;
                            if (pathPointKindArray[endPointIndex] == PathPointKind.BezierHandle && endPointIndex + 2 < pathPointKindArray.Length && pathPointKindArray[endPointIndex + 2] == PathPointKind.Cubic)
                            {
                                pathPointAdorner   = pathPointAdornerArray[endPointIndex - 1];
                                pathSegmentAdorner = pathSegmentAdornerArray[endPointIndex + 2];
                            }
                            else if (pathPointKindArray[endPointIndex] == PathPointKind.BezierHandle && endPointIndex + 1 < pathPointKindArray.Length && pathPointKindArray[endPointIndex + 1] == PathPointKind.Cubic)
                            {
                                pathPointAdorner   = pathPointAdornerArray[(endPointIndex + 1) % length1];
                                pathSegmentAdorner = pathSegmentAdornerArray[endPointIndex + 1];
                            }
                            if (pathPointAdorner != null)
                            {
                                PathTangentAdorner pathTangentAdorner;
                                if (index3 < list3.Count)
                                {
                                    pathTangentAdorner = list3[index3];
                                    pathTangentAdorner.Initialize(figureIndex, endPointIndex, segmentIndex, segmentPointIndex, pathPointAdorner, pathSegmentAdorner);
                                    oldAdornerList.Remove((Adorner)pathTangentAdorner);
                                    ++index3;
                                }
                                else
                                {
                                    pathTangentAdorner = new PathTangentAdorner(this, figureIndex, endPointIndex, segmentIndex, segmentPointIndex, pathPointAdorner, pathSegmentAdorner);
                                }
                                newAdornerList.Add((Adorner)pathTangentAdorner);
                            }
                        }
                        ++endPointIndex;
                    }
                }
                foreach (PathPointAdorner pathPointAdorner in pathPointAdornerArray)
                {
                    if (pathPointAdorner != null)
                    {
                        newAdornerList.Add((Adorner)pathPointAdorner);
                    }
                }
                this.adornerOffsets.Add((object)this.AdornerList.Count);
                this.adornerCounts.Add((object)(this.AdornerList.Count - (int)this.adornerOffsets[this.adornerOffsets.Count - 1]));
                this.adornerTypes.Add((object)PathPart.PartType.PathPoint);
            }
        }