private PenAction GetAction(PathPartAdorner pathPartAdorner)
        {
            PenAction        penAction        = (PenAction)null;
            PathEditorTarget pathEditorTarget = pathPartAdorner.PathAdornerSet.PathEditorTarget;
            PathFigure       pathFigure       = pathEditorTarget.PathGeometry.Figures[pathPartAdorner.FigureIndex];

            for (int index1 = 0; index1 < pathFigure.Segments.Count; ++index1)
            {
                System.Windows.Media.PathSegment segment = pathFigure.Segments[index1];
                for (int index2 = 0; index2 < PathSegmentUtilities.GetPointCount(segment); ++index2)
                {
                    if (PathSegmentUtilities.GetPointKind(segment, index2) == PathPointKind.Arc)
                    {
                        return((PenAction)null);
                    }
                }
            }
            if (pathPartAdorner is PathPointAdorner)
            {
                penAction = (PenAction) new ConvertPointAction(pathEditorTarget, this.ActiveSceneViewModel);
            }
            else if (pathPartAdorner is PathTangentAdorner || pathPartAdorner is PenTangentAdorner)
            {
                penAction = (PenAction) new TangentDragAction(pathEditorTarget, this.ActiveSceneViewModel, pathPartAdorner is PenTangentAdorner);
            }
            else if (pathPartAdorner is PathSegmentAdorner)
            {
                penAction = (PenAction) new ConvertSegmentAction(pathEditorTarget, this.ActiveSceneViewModel);
            }
            return(penAction);
        }
Esempio n. 2
0
 private static void ReplacePolySegments(PathSegmentCollection pathSegments)
 {
     for (int index1 = 0; index1 < pathSegments.Count; ++index1)
     {
         PathSegment     pathSegment     = pathSegments[index1];
         PolyLineSegment polyLineSegment = pathSegment as PolyLineSegment;
         if (polyLineSegment != null)
         {
             pathSegments.RemoveAt(index1);
             for (int index2 = 0; index2 < polyLineSegment.Points.Count; ++index2)
             {
                 LineSegment lineSegment = PathSegmentUtilities.CreateLineSegment(polyLineSegment.Points[index2], polyLineSegment.IsStroked);
                 pathSegments.Insert(index1, (PathSegment)lineSegment);
                 ++index1;
             }
             --index1;
         }
         PolyQuadraticBezierSegment quadraticBezierSegment1 = pathSegment as PolyQuadraticBezierSegment;
         if (quadraticBezierSegment1 != null)
         {
             pathSegments.RemoveAt(index1);
             int index2 = 0;
             while (index2 < quadraticBezierSegment1.Points.Count - 1)
             {
                 QuadraticBezierSegment quadraticBezierSegment2 = PathSegmentUtilities.CreateQuadraticBezierSegment(quadraticBezierSegment1.Points[index2], quadraticBezierSegment1.Points[index2 + 1], quadraticBezierSegment1.IsStroked);
                 pathSegments.Insert(index1, (PathSegment)quadraticBezierSegment2);
                 ++index1;
                 index2 += 2;
             }
             --index1;
         }
         PolyBezierSegment polyBezierSegment = pathSegment as PolyBezierSegment;
         if (polyBezierSegment != null)
         {
             pathSegments.RemoveAt(index1);
             int index2 = 0;
             while (index2 < polyBezierSegment.Points.Count - 2)
             {
                 BezierSegment bezierSegment = PathSegmentUtilities.CreateBezierSegment(polyBezierSegment.Points[index2], polyBezierSegment.Points[index2 + 1], polyBezierSegment.Points[index2 + 2], polyBezierSegment.IsStroked);
                 pathSegments.Insert(index1, (PathSegment)bezierSegment);
                 ++index1;
                 index2 += 3;
             }
             --index1;
         }
     }
 }
Esempio n. 3
0
 public static void UpdateAllPoints(PathGeometry geometry, Transform transform)
 {
     for (int index1 = 0; index1 < geometry.Figures.Count; ++index1)
     {
         PathFigure       figure           = geometry.Figures[index1];
         PathFigureEditor pathFigureEditor = new PathFigureEditor(figure);
         int index2 = 1;
         if (!PathFigureUtilities.IsClosed(figure) || !PathFigureUtilities.IsCloseSegmentDegenerate(figure))
         {
             pathFigureEditor.SetPoint(0, transform.Transform(figure.StartPoint));
         }
         for (int index3 = 0; index3 < figure.Segments.Count; ++index3)
         {
             System.Windows.Media.PathSegment segment = figure.Segments[index3];
             int pointCount = PathSegmentUtilities.GetPointCount(segment);
             for (int index4 = 0; index4 < pointCount; ++index4)
             {
                 Point point = PathSegmentUtilities.GetPoint(segment, index4);
                 pathFigureEditor.SetPoint(index2, transform.Transform(point));
                 ++index2;
             }
         }
     }
 }
Esempio n. 4
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);
            }
        }
Esempio n. 5
0
        internal static void TranslateSelection(PathEditorTarget pathEditorTarget, ICollection <PathPart> pathParts, Vector offset)
        {
            List <BitArray> list = new List <BitArray>(pathEditorTarget.PathGeometry.Figures.Count);

            for (int index = 0; index < pathEditorTarget.PathGeometry.Figures.Count; ++index)
            {
                list.Add(new BitArray(PathFigureUtilities.PointCount(pathEditorTarget.PathGeometry.Figures[index]), false));
            }
            foreach (PathPart pathPart in (IEnumerable <PathPart>)pathParts)
            {
                PathPoint pathPoint = pathPart as PathPoint;
                if ((PathPart)pathPoint != (PathPart)null)
                {
                    if (pathPoint.PartIndex < list[pathPoint.FigureIndex].Count)
                    {
                        list[pathPoint.FigureIndex][pathPoint.PartIndex] = true;
                    }
                }
                else
                {
                    PathSegment pathSegment = pathPart as PathSegment;
                    if ((PathPart)pathSegment != (PathPart)null)
                    {
                        list[pathSegment.FigureIndex][pathSegment.PartIndex] = true;
                        PathFigure pathFigure = pathEditorTarget.PathGeometry.Figures[pathPart.FigureIndex];
                        if (pathFigure.IsClosed && pathPart.PartIndex == 0)
                        {
                            int num1 = PathFigureUtilities.PointCount(pathFigure);
                            int num2 = 1;
                            if (PathFigureUtilities.IsCloseSegmentDegenerate(pathFigure))
                            {
                                num2 = PathSegmentUtilities.GetPointCount(pathFigure.Segments[pathFigure.Segments.Count - 1]);
                            }
                            list[pathSegment.FigureIndex][num1 - num2] = true;
                        }
                        else
                        {
                            int segmentIndex;
                            int segmentPointIndex;
                            PathFigureUtilities.GetSegmentFromPointIndex(pathFigure, pathPart.PartIndex, out segmentIndex, out segmentPointIndex);
                            int pointCount = PathSegmentUtilities.GetPointCount(pathFigure.Segments[segmentIndex]);
                            int index      = pathSegment.PartIndex - pointCount;
                            if (index >= 0)
                            {
                                list[pathSegment.FigureIndex][index] = true;
                            }
                        }
                    }
                }
            }
            for (int figureIndex = 0; figureIndex < pathEditorTarget.PathGeometry.Figures.Count; ++figureIndex)
            {
                BitArray         bitArray         = list[figureIndex];
                PathFigureEditor pathFigureEditor = new PathFigureEditor(pathEditorTarget.PathGeometry.Figures[figureIndex], pathEditorTarget.PathDiffChangeList, figureIndex);
                int num = PathFigureUtilities.PointCount(pathFigureEditor.PathFigure);
                for (int index = 0; index < num; ++index)
                {
                    if (bitArray[index])
                    {
                        pathFigureEditor.MovePoint(index, offset + pathFigureEditor.GetPoint(index));
                    }
                }
            }
        }