Пример #1
0
 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);
 }
Пример #2
0
        private void SetupCollinearHandlesConstraint(int index, bool enforceConstraint)
        {
            PathFigureEditor pathFigureEditor = new PathFigureEditor(this.figure);

            if (!pathFigureEditor.HasDownstreamBezierHandleNeighbor(index) || !pathFigureEditor.HasUpstreamBezierHandleNeighbor(index))
            {
                return;
            }
            Point  point = pathFigureEditor.GetPoint(index);
            Vector a     = pathFigureEditor.GetPoint(index - 1) - point;
            Vector b     = pathFigureEditor.GetPoint(index + 1) - point;

            if (!enforceConstraint || VectorUtilities.HaveOppositeDirections(a, b))
            {
                return;
            }
            double length1 = a.Length;
            double length2 = b.Length;

            if (length1 > length2)
            {
                a.Normalize();
                b = -a * length2;
                pathFigureEditor.SetPoint(index + 1, point + b);
            }
            else
            {
                b.Normalize();
                Vector vector = -b * length1;
                pathFigureEditor.SetPoint(index - 1, point - vector);
            }
        }
Пример #3
0
        private bool ShouldEnforceSmoothness(PathTangentAdorner pathTangentAdorner)
        {
            int              partIndex        = pathTangentAdorner.PartIndex;
            PathEditContext  pathEditContext  = new PathEditContext(pathTangentAdorner.FigureIndex, partIndex);
            PathFigureEditor pathFigureEditor = new PathFigureEditor(pathEditContext.GetPathFigure(this.pathEditorTarget.PathGeometry));
            Point            point1           = pathFigureEditor.GetPoint(pathEditContext.PartIndex);
            bool             flag             = false;

            if (pathFigureEditor.IsFirstCubicBezierHandle(partIndex))
            {
                if (pathFigureEditor.GetPointKind(partIndex - 1) == PathPointKind.Cubic)
                {
                    Point point2 = pathFigureEditor.GetPoint(partIndex - 1);
                    Point point3 = pathFigureEditor.GetPoint(partIndex - 2);
                    flag = VectorUtilities.HaveOppositeDirections(point1 - point2, point3 - point2);
                }
            }
            else if (pathFigureEditor.IsIndexValid(partIndex + 4) && pathFigureEditor.GetPointKind(partIndex + 4) == PathPointKind.Cubic)
            {
                Point point2 = pathFigureEditor.GetPoint(partIndex + 1);
                Point point3 = pathFigureEditor.GetPoint(partIndex + 2);
                flag = VectorUtilities.HaveOppositeDirections(point1 - point2, point3 - point2);
            }
            return(flag);
        }
Пример #4
0
        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);
        }
Пример #5
0
        protected override void DoDelete(PathEditContext pathEditContext)
        {
            PathFigure       pathFigure       = pathEditContext.GetPathFigure(this.Path);
            PathFigureEditor pathFigureEditor = new PathFigureEditor(pathFigure);
            int index1 = PathFigureUtilities.PointCount(pathFigure) - (PathFigureUtilities.IsClosed(pathFigure) ? 0 : 1);

            if (pathFigureEditor.GetPointKind(index1) == PathPointKind.Cubic)
            {
                int index2 = index1 - 3;
                this.LastTangent = pathFigureEditor.GetPoint(index2 + 1) - pathFigureEditor.GetPoint(index2);
            }
            this.BeginEditing().RemoveLastSegmentOfFigure(pathEditContext.FigureIndex);
        }
Пример #6
0
        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);
        }
Пример #7
0
 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();
 }
Пример #8
0
        protected override void OnBegin(PathEditContext pathEditContext, MouseDevice mouseDevice)
        {
            BaseFrameworkElement frameworkElement = this.oldPathEditorTarget.EditingElement.GetCommonAncestor((SceneNode)this.EditingElement) as BaseFrameworkElement;
            Base2DElement        editingElement   = this.oldPathEditorTarget.EditingElement;
            Base2DElement        base2Delement    = (Base2DElement)this.EditingElement;

            if (frameworkElement != base2Delement && !base2Delement.GetComputedTransformToElement((SceneElement)frameworkElement).HasInverse)
            {
                this.End();
            }
            else
            {
                int figureIndex1 = pathEditContext.FigureIndex;
                int num1         = PathFigureUtilities.PointCount(this.oldPathEditContext.GetPathFigure(this.oldPathEditorTarget.PathGeometry));
                if (editingElement != base2Delement)
                {
                    this.PathEditorTarget.EndEditing(false);
                    figureIndex1 += this.oldPathEditorTarget.PathGeometry.Figures.Count;
                    List <PathElement> otherElements = new List <PathElement>();
                    PathElement        mainElement   = (PathElement)editingElement;
                    PathElement        pathElement   = (PathElement)base2Delement;
                    otherElements.Add(pathElement);
                    PathCommandHelper.MakeCompoundPath(mainElement, otherElements, this.EditTransaction);
                    this.UpdateEditTransaction();
                    this.PathEditorTarget = this.oldPathEditorTarget;
                }
                this.PathEditorTarget.BeginEditing();
                PathGeometryEditor geometryEditor = this.PathEditorTarget.CreateGeometryEditor();
                if (pathEditContext.PartIndex != 0)
                {
                    geometryEditor.CreatePathFigureEditor(figureIndex1).Reverse();
                }
                geometryEditor.JoinFigure(this.oldPathEditContext.FigureIndex, figureIndex1);
                int figureIndex2 = this.oldPathEditContext.FigureIndex;
                if (pathEditContext.FigureIndex < this.oldPathEditContext.FigureIndex && editingElement == base2Delement)
                {
                    --figureIndex2;
                }
                this.UpdateEditTransaction();
                this.View.UpdateLayout();
                PathFigureEditor pathFigureEditor = geometryEditor.CreatePathFigureEditor(figureIndex2);
                int downstreamSegment1            = pathFigureEditor.GetLastIndexOfDownstreamSegment(num1 - 1);
                if (pathFigureEditor.GetPointKind(downstreamSegment1) == PathPointKind.Cubic)
                {
                    Vector lastTangent = this.oldPathEditorTarget.LastTangent;
                    pathFigureEditor.SetPoint(downstreamSegment1 - 2, pathFigureEditor.GetPoint(downstreamSegment1 - 2) + lastTangent);
                }
                this.PathEditorTarget.EndEditing(false);
                int downstreamSegment2 = pathFigureEditor.GetLastIndexOfDownstreamSegment(num1 - 1);
                this.PathEditContext = new PathEditContext(figureIndex2, downstreamSegment2);
                int num2 = PathFigureUtilities.PointCount(pathFigureEditor.PathFigure);
                if (pathFigureEditor.GetPointKind(num2 - 1) == PathPointKind.Cubic)
                {
                    this.LastTangent = pathFigureEditor.GetPoint(num2 - 1) - pathFigureEditor.GetPoint(num2 - 2);
                }
                else
                {
                    this.LastTangent = new Vector(0.0, 0.0);
                }
                this.UpdateEditTransaction();
                this.zeroTangents = false;
                this.PathEditorTarget.BeginEditing();
                base.OnBegin(this.PathEditContext, mouseDevice);
            }
        }
Пример #9
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));
                    }
                }
            }
        }
Пример #10
0
 private Point GetPoint(PathFigureEditor pathFigureEditor, int relativeIndex)
 {
     return(pathFigureEditor.GetPoint(this.SegmentIndex, this.SegmentPointIndex + relativeIndex) * this.PathGeometryTransformMatrix);
 }