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); } }
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; } } } }
protected override void OnDrag(MouseDevice mouseDevice, double zoom) { Point viewRootCoordinates = this.GetPointInViewRootCoordinates(mouseDevice, true); this.PathEditorTarget.BeginEditing(); Vector correspondingVector = ElementUtilities.GetCorrespondingVector(viewRootCoordinates - this.startRootPoint * this.geometryToDocument, this.geometryToDocument, this.IsShiftDown ? this.AxisConstraint : (AxisConstraint)null); PathFigureEditor pathFigureEditor = new PathFigureEditor(this.PathEditContext.GetPathFigure(this.PathEditorTarget.PathGeometry)); if (!this.adjustLastTangent) { pathFigureEditor.SetPoint(this.PathEditContext.PartIndex, this.startRootPoint + correspondingVector); } else { this.LastTangent = correspondingVector; } this.View.AdornerLayer.InvalidateAdornerVisuals(this.EditingElement); base.OnDrag(mouseDevice, zoom); }
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); } }