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); }
public int PromoteAdjacentSegments(PathEditContext pathEditContext) { int partIndex = pathEditContext.PartIndex; int index = partIndex; PathFigureEditor figureEditor = this.PathEditorTarget.CreateFigureEditor(pathEditContext.FigureIndex); bool flag = false; if (figureEditor.GetPointKind(partIndex) != PathPointKind.Cubic && figureEditor.GetPointKind(partIndex) != PathPointKind.Start) { index = this.PromoteSegment(pathEditContext.FigureIndex, partIndex); if (index != partIndex) { flag = true; } } int num = figureEditor.GetLastIndexOfDownstreamSegment(index) % PathFigureUtilities.PointCount(figureEditor.PathFigure); if (index != num && figureEditor.GetPointKind(num) != PathPointKind.Cubic && this.PromoteSegment(pathEditContext.FigureIndex, num) != num) { flag = true; } if (flag) { this.PathEditorTarget.EndEditing(false); this.PathEditorTarget.BeginEditing(); } return(index); }
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); }
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); }
public int PromoteSegment(int figureIndex, int pointIndex) { int num = pointIndex; PathFigureEditor figureEditor = this.PathEditorTarget.CreateFigureEditor(figureIndex); if (figureEditor.GetPointKind(pointIndex) != PathPointKind.Cubic) { num = figureEditor.PromoteSegment(pointIndex); } return(num); }
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); }
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); }
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); } }
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); } }