private void OpenFigureAndShiftIndices(int figureIndex, List <int> segmentsByFigure, List <int> pointsByFigure) { PathFigureEditor figureEditor = this.pathEditorTarget.CreateFigureEditor(figureIndex); int pointIndex = segmentsByFigure[0]; figureEditor.Open(pointIndex); if (pointIndex == 0) { int num = PathFigureUtilities.PointCount(figureEditor.PathFigure) - 1; segmentsByFigure[0] = num; } else { int num = PathFigureUtilities.PointCount(figureEditor.PathFigure) - 1 - pointIndex; for (int index = 0; index < segmentsByFigure.Count; ++index) { segmentsByFigure[index] = segmentsByFigure[index] + num; } for (int index = 0; index < pointsByFigure.Count; ++index) { pointsByFigure[index] = pointsByFigure[index] < pointIndex ? pointsByFigure[index] + num : pointsByFigure[index] - pointIndex; } } segmentsByFigure.Sort(); segmentsByFigure.Reverse(); pointsByFigure.Sort(); pointsByFigure.Reverse(); }
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); } }
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); }
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); }
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) { 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); }
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); }
public void Initialize(int figureIndex, int endPointIndex, int segmentIndex, int segmentPointIndex, PathPointAdorner pathPointAdorner, PathSegmentAdorner pathSegmentAdorner) { this.Initialize(figureIndex, endPointIndex, segmentIndex, segmentPointIndex); PathFigureEditor pathFigureEditor = new PathFigureEditor(this.PathAdornerSet.PathGeometry.Figures[figureIndex]); this.pathPointAdorner = pathPointAdorner; this.pathSegmentAdorner = pathSegmentAdorner; }
private void RemovePointsByFigure(int figureIndex, List <int> pointsByFigure) { PathFigureEditor figureEditor = this.pathEditorTarget.CreateFigureEditor(figureIndex); foreach (int pointIndex in pointsByFigure) { figureEditor.RemovePoint(pointIndex); } }
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 void AppendLineSegment(Point p) { PathFigureEditor pathFigureEditor = this.CreatePathFigureEditor(this.path.Figures.Count - 1); if (!PathFigureUtilities.IsOpen(pathFigureEditor.PathFigure)) { throw new InvalidOperationException(ExceptionStringTable.LastFigureMustBeOpenToAppendALineSegment); } pathFigureEditor.LineTo(p); }
public void CloseFigureWithCubicBezier(Point q, Point r, int figureIndex) { PathFigureEditor pathFigureEditor = this.CreatePathFigureEditor(figureIndex); if (!PathFigureUtilities.IsOpen(pathFigureEditor.PathFigure)) { throw new InvalidOperationException(ExceptionStringTable.FigureMustBeOpenToAppendACubicCurve); } pathFigureEditor.CubicCurveToAndCloseFigure(q, r); }
public void AppendQuadraticBezier(Point q, Point r, int figureIndex) { PathFigureEditor pathFigureEditor = this.CreatePathFigureEditor(figureIndex); if (!PathFigureUtilities.IsOpen(pathFigureEditor.PathFigure)) { throw new InvalidOperationException(ExceptionStringTable.LastFigureMustBeOpenToAppendAQuadraticCurve); } pathFigureEditor.QuadraticCurveTo(q, r); }
public void CloseFigureWithLineSegment(int figureIndex) { PathFigureEditor pathFigureEditor = this.CreatePathFigureEditor(figureIndex); if (!PathFigureUtilities.IsOpen(pathFigureEditor.PathFigure)) { throw new InvalidOperationException(ExceptionStringTable.FigureMustBeOpenToAppendALineSegment); } pathFigureEditor.CloseWithLineSegment(); }
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); }
private void ComputeSegmentParameter() { PathSegmentAdorner pathSegmentAdorner = (PathSegmentAdorner)this.pathPartAdorner; Point position = this.ActiveView.Artboard.CalculateTransformFromArtboardToContent().Value.Transform(this.MouseDevice.GetPosition((IInputElement)this.ActiveView.Artboard)); PathFigureEditor pathFigureEditor = new PathFigureEditor(pathSegmentAdorner.PathGeometry.Figures[pathSegmentAdorner.FigureIndex]); Matrix transformMatrix = pathSegmentAdorner.PathAdornerSet.GetTransformMatrix((IViewObject)this.ActiveView.HitTestRoot); Point closestPoint; double distanceSquared; this.pathSegmentParameter = pathFigureEditor.GetClosestPointOfUpstreamSegment(pathSegmentAdorner.LastPointIndex, position, transformMatrix, Tolerances.CurveFlatteningTolerance, out closestPoint, out distanceSquared); }
public override void Draw(DrawingContext ctx, Matrix matrix) { if (!this.IsValid) { return; } PathFigureEditor pathFigureEditor = new PathFigureEditor(this.PathGeometry.Figures[this.FigureIndex]); StreamGeometry streamGeometry = new StreamGeometry(); StreamGeometryContext streamGeometryContext = streamGeometry.Open(); switch (this.PathPointKind) { case PathPointKind.Start: throw new InvalidOperationException(ExceptionStringTable.PathSegmentAdornerIsolatedPointSegment); case PathPointKind.Arc: ArcSegment arcSegment = (ArcSegment)pathFigureEditor.PathFigure.Segments[this.SegmentIndex]; streamGeometryContext.BeginFigure(this.GetPoint(pathFigureEditor, -1), false, false); streamGeometryContext.ArcTo(arcSegment.Point, arcSegment.Size, arcSegment.RotationAngle, arcSegment.IsLargeArc, arcSegment.SweepDirection, true, false); break; case PathPointKind.Line: streamGeometryContext.BeginFigure(this.GetPoint(pathFigureEditor, -1), false, false); streamGeometryContext.LineTo(this.GetPoint(pathFigureEditor, 0), true, false); break; case PathPointKind.Quadratic: streamGeometryContext.BeginFigure(this.GetPoint(pathFigureEditor, -2), false, false); streamGeometryContext.QuadraticBezierTo(this.GetPoint(pathFigureEditor, -1), this.GetPoint(pathFigureEditor, 0), true, false); break; case PathPointKind.Cubic: streamGeometryContext.BeginFigure(this.GetPoint(pathFigureEditor, -3), false, false); streamGeometryContext.BezierTo(this.GetPoint(pathFigureEditor, -2), this.GetPoint(pathFigureEditor, -1), this.GetPoint(pathFigureEditor, 0), true, false); break; case PathPointKind.BezierHandle: throw new InvalidOperationException(ExceptionStringTable.PathSegmentAdornerLastPointIsBezier); default: throw new NotImplementedException(ExceptionStringTable.PathSegmentAdornerUnknownPathPoint); } streamGeometryContext.Close(); MatrixTransform matrixTransform = new MatrixTransform(matrix); matrixTransform.Freeze(); streamGeometry.Transform = (Transform)matrixTransform; streamGeometry.Freeze(); Pen pen = this.IsActive ? this.ThickPathSegmentPen : this.ThinPathSegmentPen; ctx.DrawGeometry((Brush)null, pen, (System.Windows.Media.Geometry)streamGeometry); ctx.DrawGeometry((Brush)null, PathSegmentAdorner.HitTestPen, (System.Windows.Media.Geometry)streamGeometry); }
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) { PerformanceUtility.MeasurePerformanceUntilRender(PerformanceEvent.EditPath); Point viewRootCoordinates = this.GetPointInViewRootCoordinates(mouseDevice, false); PathFigureEditor pathFigureEditor = new PathFigureEditor(pathEditContext.GetPathFigure(this.Path), this.PathEditorTarget.PathDiffChangeList, pathEditContext.FigureIndex); Matrix elementTransformToRoot = this.EditingElementTransformToRoot; int partIndex = pathEditContext.PartIndex; Point closestPoint; double distanceSquared; double ofUpstreamSegment = pathFigureEditor.GetClosestPointOfUpstreamSegment(partIndex, viewRootCoordinates, elementTransformToRoot, Tolerances.CurveFlatteningTolerance, out closestPoint, out distanceSquared); this.InsertPoint(pathEditContext, ofUpstreamSegment); base.OnBegin(pathEditContext, mouseDevice); this.End(); }
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(); }
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); }
public void JoinFigure(int figureIndex, int targetFigureIndex) { PathFigureEditor pathFigureEditor = this.CreatePathFigureEditor(figureIndex); PathFigure figure = this.PathGeometry.Figures[targetFigureIndex]; int count1 = pathFigureEditor.PathFigure.Segments.Count; int num1 = figureIndex < targetFigureIndex ? 0 : -1; int count2 = this.changeList.Changes.Count; pathFigureEditor.Join(figure); while (this.changeList.Changes.Count > count2) { this.changeList.Changes.RemoveAt(this.changeList.Changes.Count - 1); } PathAction pathAction = new PathAction(); pathAction.Action = PathActionType.Join; pathAction.Figure = figureIndex; pathAction.PointIndex = targetFigureIndex; pathAction.PathStructureChanges.Add(new PathStructureChange(count1 - 1, count1, figureIndex, figureIndex + num1, (DependencyProperty)null, BezierSegment.Point1Property, PathChangeType.Copy)); pathAction.PathStructureChanges.Add(new PathStructureChange(PathStructureChange.StartPointIndex, count1, targetFigureIndex, figureIndex + num1, PathFigure.StartPointProperty, BezierSegment.Point2Property, PathChangeType.Copy)); pathAction.PathStructureChanges.Add(new PathStructureChange(PathStructureChange.StartPointIndex, count1, targetFigureIndex, figureIndex + num1, PathFigure.StartPointProperty, BezierSegment.Point3Property, PathChangeType.Move)); int num2 = count1 + 1; for (int oldIndex = 0; oldIndex < this.path.Figures[targetFigureIndex].Segments.Count; ++oldIndex) { pathAction.PathStructureChanges.Add(new PathStructureChange(oldIndex, num2 + oldIndex, targetFigureIndex, figureIndex + num1)); } this.path.Figures.RemoveAt(targetFigureIndex); for (int newFigure = targetFigureIndex; newFigure < this.path.Figures.Count; ++newFigure) { pathAction.PathStructureChanges.Add(new PathStructureChange(PathStructureChange.StartPointIndex, PathStructureChange.StartPointIndex, newFigure + 1, newFigure)); int num3 = this.path.Figures[newFigure].Segments.Count; if (newFigure + 1 == figureIndex) { num3 = count1; } for (int index = 0; index < num3; ++index) { pathAction.PathStructureChanges.Add(new PathStructureChange(index, index, newFigure + 1, newFigure)); } } this.changeList.Changes.Add(pathAction); }
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); }
public PathGeometry ClosedFit(List <Point> input, bool inputMayContainRepeats, double cornerThreshold, double distanceTolerance, bool onlyCubics) { if (input.Count < 3) { throw new ArgumentException(ExceptionStringTable.InputCollectionMustContainAtLeastThreePoints, "input"); } PathGeometry path = this.OpenFit(input, inputMayContainRepeats, cornerThreshold, distanceTolerance, onlyCubics); PathGeometryEditor pathGeometryEditor = new PathGeometryEditor(path); PathFigureEditor pathFigureEditor = new PathFigureEditor(path.Figures[0]); if (onlyCubics) { pathFigureEditor.CloseWithCubicBezier(); this.figure = path.Figures[0]; this.SetupCollinearHandlesConstraint(0, false); } else { pathFigureEditor.CloseWithLineSegment(); } return(path); }
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; } } } }
public PathGeometry OpenFit(List <Point> input, bool inputMayContainRepeats, double cornerThreshold, double distanceTolerance, bool onlyCubics, bool enforceStartTangent, Vector startTangent, bool enforceEndTangent, Vector endTangent) { if (cornerThreshold <= 0.0 || cornerThreshold >= Math.PI) { throw new ArgumentOutOfRangeException("cornerThreshold", (object)cornerThreshold, "Corner threshold must be strictly between zero and Pi."); } if (distanceTolerance <= 0.0) { throw new ArgumentOutOfRangeException("distanceTolerance", (object)distanceTolerance, "Distance tolerance must be strictly greater than zero."); } this.enforceStartTangent = enforceStartTangent; this.enforceEndTangent = enforceEndTangent; if (this.enforceStartTangent && startTangent.LengthSquared < FloatingPointArithmetic.SquaredDistanceTolerance && (this.enforceEndTangent && endTangent.LengthSquared < FloatingPointArithmetic.SquaredDistanceTolerance)) { throw new ArgumentException(ExceptionStringTable.CannotEnforceZeroLengthTangents); } if (this.enforceEndTangent) { endTangent.Normalize(); this.endTangent = endTangent; } if (this.enforceStartTangent) { startTangent.Normalize(); this.startTangent = startTangent; } this.sample = input; if (inputMayContainRepeats && input.Count > 1) { this.sample = new List <Point>(input.Count); this.sample.Add(input[0]); for (int index = 1; index < input.Count; ++index) { if (!VectorUtilities.ArePathPointsVeryClose(input[index], input[index - 1])) { this.sample.Add(input[index]); } } } PathGeometry path = new PathGeometry(); PathGeometryEditor pathGeometryEditor = new PathGeometryEditor(path); if (this.sample.Count > 0) { pathGeometryEditor.StartFigure(this.sample[0]); this.figure = path.Figures[0]; } PathFigureEditor pathFigureEditor = new PathFigureEditor(this.figure); if (this.sample.Count == 2) { if (VectorUtilities.Distance(this.sample[0], this.sample[1]) >= distanceTolerance) { if (onlyCubics) { pathFigureEditor.LinearCubicCurveTo(this.sample[1]); } else { pathFigureEditor.LineTo(this.sample[1]); } } } else if (this.sample.Count > 2) { int lastIndex = this.sample.Count - 1; this.chordLength = VectorUtilities.GetCumulatedChordLength(this.sample, 0, lastIndex); this.distanceTolerance = distanceTolerance; double cosThreshold = Math.Cos(cornerThreshold); int num = 0; int index = 1; while (true) { while (index >= lastIndex || this.IsSamplePointACorner(index, cosThreshold)) { if (index == num + 1) { if (onlyCubics) { pathFigureEditor.LinearCubicCurveTo(this.sample[index]); } else { pathFigureEditor.LineTo(this.sample[index]); } } else { this.OpenFit2DFromTo(num, this.GetUnitTangentVectorFirst(num), index, this.GetUnitTangentVectorLast(index), onlyCubics); } num = index; ++index; if (num >= lastIndex) { goto label_33; } } ++index; } } label_33: return(path); }
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)); } } } }
private void OpenFit2DFromTo(int first, Vector unitTangentFirst, int last, Vector unitTangentLast, bool onlyCubics) { int length = last - first + 1; int num1 = length - 1; PathFigureEditor pathFigureEditor = new PathFigureEditor(this.figure); if (length == 2) { if (onlyCubics) { double num2 = VectorUtilities.Distance(this.sample[first], this.sample[last]) / 3.0; Point p1 = this.sample[first] + unitTangentFirst * num2; Point p2 = this.sample[last] - unitTangentLast * num2; pathFigureEditor.CubicCurveTo(p1, p2, this.sample[last]); } else { pathFigureEditor.LineTo(this.sample[last]); } } else if (length == 3) { int index1 = first + 1; Vector vector1 = this.sample[first] - this.sample[index1]; Vector vector2 = this.sample[last] - this.sample[index1]; Vector vector3 = vector1; vector3.Normalize(); Vector vector4 = vector2; vector4.Normalize(); Vector vector5 = vector3 + vector4; Vector vector6; if (VectorUtilities.IsZero(vector5)) { vector6 = this.sample[last] - this.sample[first]; vector6.Normalize(); } else { vector6 = VectorUtilities.UnitNormal(vector5); } if (VectorUtilities.Dot(vector6, this.sample[last] - this.sample[first]) < 0.0) { vector6 *= -1.0; } this.OpenFit2DFromTo(first, unitTangentFirst, index1, vector6, onlyCubics); int index2 = PathFigureUtilities.PointCount(this.figure) - 1; this.OpenFit2DFromTo(index1, vector6, last, unitTangentLast, onlyCubics); this.SetupCollinearHandlesConstraint(index2, onlyCubics); } else { double[][] numArray1 = new double[length][]; for (int index = 0; index < length; ++index) { numArray1[index] = new double[4]; } double num2 = 1.0 / (this.chordLength[last] - this.chordLength[first]); double[] numArray2 = new double[length]; for (int index = 0; index <= num1; ++index) { numArray2[index] = (this.chordLength[first + index] - this.chordLength[first]) * num2; } double[] numArray3 = new double[4]; numArray3[0] = 1.0; for (int index1 = 0; index1 <= num1; ++index1) { numArray3[1] = 1.0 - numArray2[index1]; for (int index2 = 2; index2 <= 3; ++index2) { numArray3[index2] = numArray3[index2 - 1] * numArray3[1]; } numArray1[index1][0] = numArray3[3]; double num3 = numArray2[index1]; int index3 = 1; while (index3 <= 3) { numArray1[index1][index3] = (double)BezierCurveFitter.pascalTriangle[3][index3] * num3 * numArray3[3 - index3]; ++index3; num3 *= numArray2[index1]; } } double[][] numArray4 = new double[4][]; for (int index = 0; index < 4; ++index) { numArray4[index] = new double[4]; } for (int index1 = 0; index1 <= 3; ++index1) { for (int index2 = 0; index2 <= index1; ++index2) { for (int index3 = 0; index3 <= num1; ++index3) { numArray4[index1][index2] += numArray1[index3][index2] * numArray1[index3][index1]; } if (index1 != index2) { numArray4[index2][index1] = numArray4[index1][index2]; } } } double[][] m = new double[2][] { new double[2] { numArray4[1][1], numArray4[1][2] * VectorUtilities.Dot(unitTangentFirst, unitTangentLast) }, new double[2] { numArray4[1][2], numArray4[2][2] } }; double[] v = new double[2]; Vector[] vectorArray = new Vector[4]; for (int index1 = 0; index1 < 4; ++index1) { for (int index2 = 0; index2 <= num1; ++index2) { vectorArray[index1].X += numArray1[index2][index1] * this.sample[index2 + first].X; vectorArray[index1].Y += numArray1[index2][index1] * this.sample[index2 + first].Y; } } Vector vector1 = new Vector(this.sample[first].X, this.sample[first].Y); Vector vector2 = new Vector(this.sample[last].X, this.sample[last].Y); Vector b1 = (numArray4[1][0] + numArray4[1][1]) * vector1 + (numArray4[1][2] + numArray4[1][3]) * vector2 - vectorArray[1]; v[0] = -VectorUtilities.Dot(unitTangentFirst, b1); Vector b2 = (numArray4[2][0] + numArray4[2][1]) * vector1 + (numArray4[2][2] + numArray4[2][3]) * vector2 - vectorArray[2]; v[1] = -VectorUtilities.Dot(unitTangentLast, b2); bool flag = BezierCurveFitter.Solve2By2LinearSystem(m, v); int firstBadVertexInQ = 0; if (flag && v[0] > 0.0 && v[1] < 0.0) { Point[] controlPoints = new Point[4]; controlPoints[0] = this.sample[first]; controlPoints[1] = controlPoints[0] + v[0] * unitTangentFirst; controlPoints[3] = this.sample[last]; controlPoints[2] = controlPoints[3] + v[1] * unitTangentLast; List <Point> list = new List <Point>(128); BezierCurveFlattener.FlattenCubic(controlPoints, this.distanceTolerance, list, false); double[] cumulatedChordLength = VectorUtilities.GetCumulatedChordLength(list, 0, list.Count - 1); if (VectorUtilities.ArePolylinesClose(list, cumulatedChordLength, 0, list.Count - 1, this.sample, this.chordLength, first, last, this.distanceTolerance, ref firstBadVertexInQ)) { pathFigureEditor.CubicCurveTo(controlPoints[1], controlPoints[2], controlPoints[3]); return; } } int num4 = (first + last) / 2; Vector tangentVectorAtSplit = this.GetUnitTangentVectorAtSplit(num4); this.OpenFit2DFromTo(first, unitTangentFirst, num4, tangentVectorAtSplit, onlyCubics); int index4 = PathFigureUtilities.PointCount(this.figure) - 1; this.OpenFit2DFromTo(num4, tangentVectorAtSplit, last, unitTangentLast, onlyCubics); this.SetupCollinearHandlesConstraint(index4, onlyCubics); } }
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); } }
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); } }