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); } }
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))); } }