protected override void OnDrag(MouseDevice mouseDevice, double zoom)
        {
            Point  point  = PathFigureUtilities.GetPoint(this.PathEditContext.GetPathFigure(this.Path), this.PathEditContext.PartIndex);
            Point  point1 = this.geometryToDocument.Transform(point);
            Point  viewRootCoordinates = this.GetPointInViewRootCoordinates(mouseDevice, true);
            Vector vector = viewRootCoordinates - point1;
            Vector correspondingVector = ElementUtilities.GetCorrespondingVector(vector, this.geometryToDocument, this.IsShiftDown ? this.AxisConstraint : (AxisConstraint)null);

            if (this.hasMoved || Tolerances.HaveMoved(point1, viewRootCoordinates, zoom))
            {
                this.hasMoved = true;
                PathGeometry       path               = this.Path;
                int                figureIndex        = this.PathEditContext.FigureIndex;
                int                partIndex          = this.PathEditContext.PartIndex;
                PathGeometryEditor pathGeometryEditor = this.BeginEditing();
                PathFigureEditor   pathFigureEditor   = new PathFigureEditor(path.Figures[figureIndex]);
                if (partIndex > 0 || PathFigureUtilities.IsClosed(pathFigureEditor.PathFigure))
                {
                    pathGeometryEditor.SetPoint(figureIndex, partIndex - 1, point - correspondingVector);
                }
                if (pathFigureEditor.GetLastIndexOfDownstreamSegment(partIndex) != partIndex)
                {
                    pathGeometryEditor.SetPoint(figureIndex, partIndex + 1, point + correspondingVector);
                }
                if (partIndex == PathFigureUtilities.PointCount(pathFigureEditor.PathFigure) - 1 && PathFigureUtilities.IsOpen(pathFigureEditor.PathFigure))
                {
                    this.LastTangent = vector;
                }
                this.PathEditorTarget.AddCriticalEdit();
            }
            base.OnDrag(mouseDevice, zoom);
        }
 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);
 }
        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)
        {
            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);
        }
Example #5
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;
                    }
                }
            }
Example #6
0
        protected override void DoUpdateElementPosition(Point pointBegin, Point pointEnd)
        {
            PathGeometry       path = new PathGeometry();
            PathGeometryEditor pathGeometryEditor = new PathGeometryEditor(path);

            pathGeometryEditor.StartFigure(pointBegin);
            pathGeometryEditor.AppendLineSegment(pointEnd);
            using (ScenePathEditorTarget pathEditorTarget = new ScenePathEditorTarget((PathElement)this.EditingElement))
            {
                pathEditorTarget.BeginEditing();
                pathEditorTarget.PathGeometry = path;
                pathEditorTarget.EndEditing(true);
            }
        }
 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();
 }
Example #8
0
        protected override void OnBegin(PathEditContext pathEditContext, MouseDevice mouseDevice)
        {
            PathGeometryEditor pathGeometryEditor = this.BeginEditing();
            Point  point = PathFigureUtilities.FirstPoint(pathEditContext.GetPathFigure(this.Path));
            Matrix elementTransformToRoot = this.EditingElementTransformToRoot;

            if (VectorUtilities.IsZero(this.LastTangent))
            {
                pathGeometryEditor.CloseFigureWithLineSegment(pathEditContext.FigureIndex);
            }
            else
            {
                Point q = this.GetLastPoint(pathEditContext.FigureIndex) + this.LastTangent;
                pathGeometryEditor.CloseFigureWithCubicBezier(q, point, pathEditContext.FigureIndex);
            }
            this.Initialize(elementTransformToRoot.Transform(point), true, elementTransformToRoot);
            base.OnBegin(pathEditContext, mouseDevice);
        }
        protected override void OnBegin(PathEditContext pathEditContext, MouseDevice mouseDevice)
        {
            int        figureIndex = pathEditContext.FigureIndex;
            PathFigure figure      = this.Path.Figures[figureIndex];

            this.geometryToDocument = this.EditingElementTransformToRoot;
            int num1 = pathEditContext.PartIndex;
            PathFigureEditor pathFigureEditor = new PathFigureEditor(figure, this.PathEditorTarget.PathDiffChangeList, figureIndex);

            if (pathFigureEditor.GetPointKind(num1) != PathPointKind.Cubic)
            {
                PathGeometryEditor pathGeometryEditor = this.BeginEditing();
                pathFigureEditor     = new PathFigureEditor(pathGeometryEditor.PathGeometry.Figures[figureIndex], this.PathEditorTarget.PathDiffChangeList, figureIndex);
                num1                 = pathGeometryEditor.PromoteSegment(figureIndex, num1);
                this.PathEditContext = new PathEditContext(pathEditContext.FigureIndex, num1);
            }
            this.View.ViewModel.PathPartSelectionSet.SetSelection((PathPart) new PathSegment((SceneElement)this.PathEditorTarget.EditingElement, this.PathEditorTarget.PathEditMode, pathEditContext.FigureIndex, this.PathEditContext.PartIndex));
            int   ofUpstreamSegment   = pathFigureEditor.GetFirstIndexOfUpstreamSegment(num1);
            Point viewRootCoordinates = this.GetPointInViewRootCoordinates(mouseDevice, false);

            this.ComputeSegmentParameterAndClosestPoint(pathEditContext.GetPathFigure(this.Path), pathEditContext.PartIndex, viewRootCoordinates);
            this.pathSegmentParameter = Math.Max(this.pathSegmentParameter, ConvertSegmentAction.segmentTolerance);
            this.pathSegmentParameter = Math.Min(this.pathSegmentParameter, 1.0 - ConvertSegmentAction.segmentTolerance);
            double num2 = 3.0 * this.pathSegmentParameter * (1.0 - this.pathSegmentParameter);
            double num3 = num2 * this.pathSegmentParameter;
            double num4 = num2 * (1.0 - this.pathSegmentParameter);
            double num5 = (num4 * num4 + num3 * num3 + num4 * num3) * 2.0;

            this.firstHandleCoef          = (2.0 * num4 + num3) / num5;
            this.secondHandleCoef         = (2.0 * num3 + num4) / num5;
            this.initialFirstCubicHandle  = pathFigureEditor.GetPoint(ofUpstreamSegment + 1);
            this.initialSecondCubicHandle = pathFigureEditor.GetPoint(ofUpstreamSegment + 2);
            if (Math.Min(this.pathSegmentParameter, 1.0 - this.pathSegmentParameter) < ConvertSegmentAction.dampingThreshold)
            {
                this.damping = Math.Min(this.pathSegmentParameter, 1.0 - this.pathSegmentParameter);
                this.damping = Math.Sqrt(this.damping);
            }
            else
            {
                this.damping = 1.0;
            }
            this.hasDragged = false;
            base.OnBegin(pathEditContext, mouseDevice);
        }
Example #10
0
        protected override void OnBegin(PathEditContext pathEditContext, MouseDevice mouseDevice)
        {
            PerformanceUtility.MeasurePerformanceUntilRender(PerformanceEvent.EditPath);
            Vector lastTangent = this.LastTangent;

            base.OnBegin(pathEditContext, mouseDevice);
            PathGeometryEditor pathGeometryEditor     = this.BeginEditing();
            Matrix             elementTransformToRoot = this.EditingElementTransformToRoot;
            Point  lastPoint       = this.GetLastPoint(pathEditContext.FigureIndex);
            Point  point1          = elementTransformToRoot.Transform(lastPoint);
            Vector vector          = this.GetPointInViewRootCoordinates(mouseDevice, true) - point1;
            Size   devicePixelSize = DeviceUtilities.GetDevicePixelSize(this.View.Zoom);

            if (Math.Abs(vector.X) < devicePixelSize.Width / 2.0)
            {
                vector.X = 0.0;
            }
            if (Math.Abs(vector.Y) < devicePixelSize.Height / 2.0)
            {
                vector.Y = 0.0;
            }
            Vector correspondingVector = ElementUtilities.GetCorrespondingVector(vector, elementTransformToRoot, this.IsShiftDown ? this.AxisConstraint : (AxisConstraint)null);
            Point  point2 = lastPoint + correspondingVector;

            if (VectorUtilities.IsZero(lastTangent))
            {
                pathGeometryEditor.AppendLineSegment(point2, pathEditContext.FigureIndex);
            }
            else
            {
                Point q = lastPoint + lastTangent;
                pathGeometryEditor.AppendCubicBezier(q, point2, point2, pathEditContext.FigureIndex);
            }
            int        figureIndex = pathEditContext.FigureIndex;
            PathFigure figure      = this.Path.Figures[figureIndex];

            this.PathEditContext = new PathEditContext(figureIndex, PathFigureUtilities.PointCount(figure) - 1);
            this.Initialize(elementTransformToRoot.Transform(point2), true, elementTransformToRoot);
        }
Example #11
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);
            }
        }
Example #12
0
        private void SetPathUsingMapping(PathGeometry path)
        {
            SceneViewModel viewModel = this.targetElement.ViewModel;

            using (viewModel.AnimationProxyManager != null ? viewModel.AnimationProxyManager.ExpandAllProxiesInActiveContainer() : (IDisposable)null)
            {
                foreach (PathAction action in this.changeList.Changes)
                {
                    System.Windows.Media.Geometry geometry = this.targetElement.GetLocalOrDefaultValueAsWpf((IPropertyId)this.pathProperty) as System.Windows.Media.Geometry;
                    if (geometry == null && this.targetElement.IsValueExpression((IPropertyId)this.pathProperty))
                    {
                        geometry = this.targetElement.ViewModel.DefaultView.ConvertToWpfValue(this.targetElement.ViewModel.CreateInstance(this.targetElement.GetLocalValueAsSceneNode((IPropertyId)this.pathProperty).DocumentNodePath)) as System.Windows.Media.Geometry;
                        if (geometry == null)
                        {
                            geometry = this.targetElement.GetComputedValueAsWpf((IPropertyId)this.pathProperty) as System.Windows.Media.Geometry;
                            if (geometry == null)
                            {
                                return;
                            }
                        }
                    }
                    PathGeometry oldGeometry = new PathGeometry();
                    oldGeometry.AddGeometry(geometry.Clone());
                    PathGeometry pathGeometry = new PathGeometry();
                    pathGeometry.AddGeometry(geometry);
                    PathFigureEditor   pathFigureEditor   = new PathFigureEditor(pathGeometry.Figures[action.Figure]);
                    PathGeometryEditor pathGeometryEditor = new PathGeometryEditor(pathGeometry);
                    switch (action.Action)
                    {
                    case PathActionType.InsertPoint:
                        pathFigureEditor.SubdivideSegment(action.PointIndex, action.Parameter);
                        break;

                    case PathActionType.DeletePoint:
                        pathFigureEditor.RemovePoint(action.PointIndex);
                        break;

                    case PathActionType.DeleteSegment:
                        if (action.Segment == 0 && pathFigureEditor.PathFigure.Segments.Count > 1)
                        {
                            pathFigureEditor.RemoveFirstSegment();
                            break;
                        }
                        pathFigureEditor.RemoveLastSegment();
                        break;

                    case PathActionType.PromoteSegment:
                        pathFigureEditor.PromoteSegment(action.PointIndex);
                        break;

                    case PathActionType.Rotate:
                        pathFigureEditor.Rotate();
                        break;

                    case PathActionType.Open:
                        pathFigureEditor.Open(action.PointIndex);
                        break;

                    case PathActionType.Split:
                        pathFigureEditor.Split(action.PointIndex);
                        break;

                    case PathActionType.SplitAndAdd:
                        pathGeometryEditor.SplitFigure(action.Figure, action.PointIndex);
                        break;

                    case PathActionType.RemoveFigure:
                        pathGeometryEditor.RemoveFigure(action.Figure);
                        break;

                    case PathActionType.AppendSegment:
                        PathAppendLineAction appendLineAction;
                        if ((appendLineAction = action as PathAppendLineAction) != null)
                        {
                            Point point = appendLineAction.Point;
                            if (action.Figure < path.Figures.Count && action.Segment < path.Figures[action.Figure].Segments.Count)
                            {
                                LineSegment lineSegment = path.Figures[action.Figure].Segments[action.Segment] as LineSegment;
                                if (lineSegment != null)
                                {
                                    point = lineSegment.Point;
                                }
                            }
                            pathFigureEditor.LineTo(point);
                            break;
                        }
                        PathAppendQuadraticBezierAction quadraticBezierAction;
                        if ((quadraticBezierAction = action as PathAppendQuadraticBezierAction) != null)
                        {
                            Point point1 = quadraticBezierAction.Point1;
                            Point point2 = quadraticBezierAction.Point2;
                            if (action.Figure < path.Figures.Count && action.Segment < path.Figures[action.Figure].Segments.Count)
                            {
                                QuadraticBezierSegment quadraticBezierSegment = path.Figures[action.Figure].Segments[action.Segment] as QuadraticBezierSegment;
                                if (quadraticBezierSegment != null)
                                {
                                    point1 = quadraticBezierSegment.Point1;
                                    point2 = quadraticBezierSegment.Point2;
                                }
                            }
                            pathFigureEditor.QuadraticCurveTo(point1, point2);
                            break;
                        }
                        PathAppendBezierAction appendBezierAction;
                        if ((appendBezierAction = action as PathAppendBezierAction) != null)
                        {
                            Point point1 = appendBezierAction.Point1;
                            Point point2 = appendBezierAction.Point2;
                            Point point3 = appendBezierAction.Point3;
                            if (action.Figure < path.Figures.Count && action.Segment < path.Figures[action.Figure].Segments.Count)
                            {
                                BezierSegment bezierSegment = path.Figures[action.Figure].Segments[action.Segment] as BezierSegment;
                                if (bezierSegment != null)
                                {
                                    point1 = bezierSegment.Point1;
                                    point2 = bezierSegment.Point2;
                                    point3 = bezierSegment.Point3;
                                }
                            }
                            pathFigureEditor.CubicCurveTo(point1, point2, point3);
                            break;
                        }
                        break;

                    case PathActionType.Close:
                        pathFigureEditor.CloseWithLineSegment();
                        break;

                    case PathActionType.Join:
                        pathGeometryEditor.JoinFigure(action.Figure, action.PointIndex);
                        break;

                    case PathActionType.Reverse:
                        pathFigureEditor.Reverse();
                        break;
                    }
                    this.targetElement.SetLocalValueAsWpf((IPropertyId)this.pathProperty, (object)pathGeometry);
                    this.ApplyAnimationChanges(oldGeometry, pathGeometry, action);
                    if (action.Action == PathActionType.PromoteSegment && action.Segment < pathGeometry.Figures[action.Figure].Segments.Count)
                    {
                        this.targetElement.ViewModel.Document.OnUpdatedEditTransaction();
                        this.SetKeyframesForSegment(path, action.Figure, action.Segment);
                    }
                }
                this.RemoveInvalidAnimations(PathGeometryUtilities.GetPathGeometryFromGeometry((System.Windows.Media.Geometry) this.targetElement.GetLocalOrDefaultValueAsWpf((IPropertyId)this.pathProperty)));
            }
        }
Example #13
0
        private void SubdivideSegment(PathGeometry oldGeometry, int figure, int segment, int pointIndex, double parameter, Dictionary <TimelineSceneNode, StoryboardTimelineSceneNode> subdivisionProperties)
        {
            PropertyReference propertyReference1 = new PropertyReference(this.pathProperty).Append(PathElement.FiguresProperty).Append((ReferenceStep)IndexedClrPropertyReferenceStep.GetReferenceStep((IPlatformMetadata)this.platformMetadata, PlatformTypes.PathFigureCollection, figure));
            PropertyReference propertyReference2 = propertyReference1.Append(PathElement.PathFigureSegmentsProperty);
            PropertyReference propertyReference3 = segment != oldGeometry.Figures[figure].Segments.Count ? propertyReference2.Append((ReferenceStep)IndexedClrPropertyReferenceStep.GetReferenceStep((IPlatformMetadata)this.platformMetadata, PlatformTypes.PathSegmentCollection, segment)) : propertyReference1.Append(PathElement.PathFigureStartPointProperty);
            PropertyReference propertyReference4;

            if (segment == 0)
            {
                propertyReference4 = propertyReference1.Append(PathElement.PathFigureStartPointProperty);
            }
            else
            {
                ReferenceStep step = (ReferenceStep)IndexedClrPropertyReferenceStep.GetReferenceStep((IPlatformMetadata)this.platformMetadata, PlatformTypes.PathSegmentCollection, segment - 1);
                propertyReference4 = propertyReference2.Append(step).Append(this.LastPointProperty(oldGeometry.Figures[figure].Segments[segment - 1]));
            }
            PropertyReference propertyReference5 = (PropertyReference)null;

            if (segment == oldGeometry.Figures[figure].Segments.Count - 1 && PathFigureUtilities.IsClosed(oldGeometry.Figures[figure]) && PathFigureUtilities.IsCloseSegmentDegenerate(oldGeometry.Figures[figure]))
            {
                propertyReference5 = propertyReference1.Append(PathElement.PathFigureStartPointProperty);
            }
            foreach (StoryboardTimelineSceneNode timelineSceneNode1 in this.targetElement.ViewModel.AnimationEditor.EnumerateStoryboardsForContainer(this.targetElement.StoryboardContainer))
            {
                Dictionary <double, List <KeyFrameSceneNode> > keyFrames1 = new Dictionary <double, List <KeyFrameSceneNode> >();
                foreach (KeyValuePair <TimelineSceneNode, StoryboardTimelineSceneNode> keyValuePair in subdivisionProperties)
                {
                    if (keyValuePair.Value == timelineSceneNode1)
                    {
                        KeyFrameAnimationSceneNode keyFrameNode = keyValuePair.Key as KeyFrameAnimationSceneNode;
                        if (keyFrameNode != null)
                        {
                            this.RecordKeyFrames(keyFrames1, keyFrameNode);
                        }
                    }
                }
                Dictionary <double, List <KeyFrameSceneNode> > keyFrames2 = new Dictionary <double, List <KeyFrameSceneNode> >();
                foreach (TimelineSceneNode timelineSceneNode2 in (IEnumerable <TimelineSceneNode>)timelineSceneNode1.Children)
                {
                    if (timelineSceneNode2.TargetElement == this.targetElement && timelineSceneNode2.TargetProperty != null && (propertyReference3.Equals((object)timelineSceneNode2.TargetProperty) || propertyReference3.IsPrefixOf(timelineSceneNode2.TargetProperty) || propertyReference4.Equals((object)timelineSceneNode2.TargetProperty) || propertyReference5 != null && propertyReference5.Equals((object)timelineSceneNode2.TargetProperty)))
                    {
                        KeyFrameAnimationSceneNode keyFrameNode = timelineSceneNode2 as KeyFrameAnimationSceneNode;
                        if (keyFrameNode != null)
                        {
                            this.RecordKeyFrames(keyFrames2, keyFrameNode);
                        }
                    }
                }
                foreach (KeyValuePair <double, List <KeyFrameSceneNode> > keyValuePair in keyFrames2)
                {
                    PathGeometry       path = oldGeometry.Clone();
                    PathGeometryEditor pathGeometryEditor = new PathGeometryEditor(path);
                    foreach (KeyFrameSceneNode keyFrameSceneNode in keyValuePair.Value)
                    {
                        PropertyReference propertyReference6 = this.targetElement.ViewModel.DefaultView.ConvertToWpfPropertyReference(keyFrameSceneNode.TargetProperty.Subreference(1));
                        object            valueToSet         = this.targetElement.ViewModel.DefaultView.ConvertToWpfValue(keyFrameSceneNode.Value);
                        propertyReference6.SetValue((object)path, valueToSet);
                    }
                    pathGeometryEditor.SubdivideSegment(figure, pointIndex, parameter);
                    List <KeyFrameSceneNode> list;
                    if (keyFrames1.TryGetValue(keyValuePair.Key, out list))
                    {
                        foreach (KeyFrameSceneNode keyFrameSceneNode in list)
                        {
                            object obj = this.targetElement.ViewModel.DefaultView.ConvertFromWpfValue(this.targetElement.ViewModel.DefaultView.ConvertToWpfPropertyReference(keyFrameSceneNode.TargetProperty.Subreference(1)).GetCurrentValue((object)path));
                            keyFrameSceneNode.Value = obj;
                        }
                    }
                }
            }
        }