public virtual void UpdateActiveStateFromSelection() { if (this.AdornerList == null) { return; } Hashtable hashtable = new Hashtable(); foreach (Adorner adorner in this.AdornerList) { PathPointAdorner pathPointAdorner = adorner as PathPointAdorner; PathSegmentAdorner pathSegmentAdorner = adorner as PathSegmentAdorner; if (pathPointAdorner != null) { hashtable[(object)(PathPoint)pathPointAdorner] = (object)pathPointAdorner; pathPointAdorner.IsActive = false; } else if (pathSegmentAdorner != null) { hashtable[(object)(PathSegment)pathSegmentAdorner] = (object)pathSegmentAdorner; pathSegmentAdorner.IsActive = false; } } foreach (PathPart pathPart in (IEnumerable <PathPart>) this.PathPartSelectionSet.GetSelectionByElement((SceneElement)this.Element)) { PathPartAdorner pathPartAdorner = (PathPartAdorner)hashtable[(object)pathPart]; if (pathPartAdorner != null) { pathPartAdorner.IsActive = true; } } this.InvalidateRender(); }
public override void UpdateActiveStateFromSelection() { if (this.IsActive) { if (this.AdornerList == null) { return; } if (this.activePointAdornerIndex >= 0 && this.activePointAdornerIndex < this.AdornerList.Count) { PathPointAdorner pathPointAdorner = this.AdornerList[this.activePointAdornerIndex] as PathPointAdorner; if (pathPointAdorner != null) { pathPointAdorner.IsActive = true; } } if (this.activeSegmentAdornerIndex >= 0 && this.activeSegmentAdornerIndex < this.AdornerList.Count) { PathSegmentAdorner pathSegmentAdorner = this.AdornerList[this.activeSegmentAdornerIndex] as PathSegmentAdorner; if (pathSegmentAdorner != null) { pathSegmentAdorner.IsActive = true; } } this.InvalidateRender(); } else { base.UpdateActiveStateFromSelection(); } }
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; }
protected override void CreatePathAdorners(List <Adorner> oldAdornerList, List <Adorner> newAdornerList) { base.CreatePathAdorners(oldAdornerList, newAdornerList); this.lastTangentAdorner = (PenTangentAdorner)null; this.activeSegmentAdornerIndex = -1; this.activePointAdornerIndex = -1; if (!this.IsActive || this.AdornerList.Count <= 0 || (this.PathGeometry == null || this.PathGeometry.Figures.Count <= 0)) { return; } int index1 = this.ActiveFigureIndex; if (index1 < 0 || index1 >= this.PathGeometry.Figures.Count) { index1 = 0; } PathFigure figure = this.PathGeometry.Figures[index1]; int num = !PathFigureUtilities.IsClosed(figure) ? PathFigureUtilities.PointCount(figure) - 1 : 0; PathPointAdorner pathPointAdorner1 = (PathPointAdorner)null; for (int index2 = 0; index2 < this.AdornerList.Count; ++index2) { Adorner adorner = this.AdornerList[index2]; PathPointAdorner pathPointAdorner2 = adorner as PathPointAdorner; if (pathPointAdorner2 != null) { if (pathPointAdorner2.FigureIndex == this.ActiveFigureIndex && pathPointAdorner2.PointIndex == num) { pathPointAdorner2.IsActive = true; pathPointAdorner1 = pathPointAdorner2; this.activePointAdornerIndex = index2; } else { pathPointAdorner2.IsActive = false; } } PathSegmentAdorner pathSegmentAdorner = adorner as PathSegmentAdorner; if (pathSegmentAdorner != null) { if (pathSegmentAdorner.FigureIndex == this.ActiveFigureIndex && pathSegmentAdorner.LastPointIndex == num) { pathSegmentAdorner.IsActive = true; this.activeSegmentAdornerIndex = index2; } else { pathSegmentAdorner.IsActive = false; } } } if (pathPointAdorner1 == null || PathFigureUtilities.IsClosed(this.PathGeometry.Figures[this.ActiveFigureIndex])) { return; } this.lastTangentAdorner = new PenTangentAdorner(pathPointAdorner1); newAdornerList.Add((Adorner)this.lastTangentAdorner); }
protected override bool OnButtonDown(Point pointerPosition) { this.pathPartAdorner = (PathPartAdorner)this.ActiveAdorner; this.isConstrainingAxes = this.IsShiftDown; this.startRootPoint = pointerPosition; this.currentEditingElement = this.pathPartAdorner.Element; bool isShiftDown = this.IsShiftDown; int num = this.IsAltDown ? true : false; bool isControlDown = this.IsControlDown; PathPointAdorner pathPointAdorner = this.pathPartAdorner as PathPointAdorner; PathTangentAdorner pathTangentAdorner = this.pathPartAdorner as PathTangentAdorner; PathSegmentAdorner pathSegmentAdorner = this.pathPartAdorner as PathSegmentAdorner; this.pathEditorTargets.Clear(); if (pathTangentAdorner != null) { pathTangentAdorner.PathAdornerSet.SetActive((PathPartAdorner)pathTangentAdorner, true); this.isEnforcingSmoothness = this.ShouldEnforceSmoothness(pathTangentAdorner); } else { PathPartSelectionSet partSelectionSet = this.ActiveSceneViewModel.PathPartSelectionSet; PathPart pathPart = (PathPart)null; if (pathPointAdorner != null) { pathPart = (PathPart)(PathPoint)pathPointAdorner; } else if (pathSegmentAdorner != null) { pathPart = (PathPart)(PathSegment)pathSegmentAdorner; } if (isShiftDown) { partSelectionSet.ExtendSelection(pathPart); } else if (isControlDown && this.ToolBehaviorContext.ActiveTool is ISelectionTool) { partSelectionSet.ToggleSelection(pathPart); if (!partSelectionSet.IsSelected(pathPart)) { this.currentEditingElement = (BaseFrameworkElement)null; } } else if (!partSelectionSet.IsSelected(pathPart)) { partSelectionSet.Clear(); partSelectionSet.ExtendSelection(pathPart); } if (partSelectionSet.IsSelected(pathPart) && pathSegmentAdorner != null) { this.ComputeSegmentParameter(); } } this.ToolBehaviorContext.SnappingEngine.Start(this.ToolBehaviorContext, (BaseFrameworkElement)null, (IList <BaseFrameworkElement>)null); return(true); }
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); }
private PenAction GetAction(PathPartAdorner adorner) { PenAction penAction = (PenAction)null; PathSegmentAdorner pathSegmentAdorner = adorner as PathSegmentAdorner; PathEditorTarget pathEditorTarget = (PathEditorTarget)null; if (adorner != null) { pathEditorTarget = adorner.PathAdornerSet.PathEditorTarget; } if (pathSegmentAdorner != null) { penAction = (PenAction) new InsertAction(pathEditorTarget, this.ActiveSceneViewModel); } else { PathPointAdorner pathPointAdorner = adorner as PathPointAdorner; if (pathPointAdorner != null) { penAction = (PenAction) new DeletePointAction(pathEditorTarget, this.ActiveSceneViewModel); PathFigure figure1 = pathEditorTarget.PathGeometry.Figures[pathPointAdorner.FigureIndex]; if (PathFigureUtilities.IsOpen(figure1) && !PathFigureUtilities.IsIsolatedPoint(figure1)) { bool flag1 = pathPointAdorner.PointIndex == 0; bool flag2 = pathPointAdorner.PointIndex == PathFigureUtilities.PointCount(figure1) - 1; bool flag3 = pathPointAdorner.PathAdornerSet.PathEditorTarget == this.pathEditorTarget; bool flag4 = this.pathEditContext != null && pathPointAdorner.FigureIndex == this.pathEditContext.FigureIndex; bool flag5 = this.pathEditorTarget != null && pathPointAdorner.PathAdornerSet.PathEditorTarget.PathEditMode == this.pathEditorTarget.PathEditMode; bool flag6 = pathPointAdorner.PathAdornerSet.PathEditorTarget.PathEditMode == PathEditMode.ScenePath; PathFigure figure2 = this.pathEditContext == null || this.pathEditorTarget == null ? (PathFigure)null : this.pathEditContext.GetPathFigure(this.pathEditorTarget.PathGeometry); bool flag7 = figure2 != null && PathFigureUtilities.IsOpen(figure2); bool flag8 = (flag3 && !flag4 || flag5 && flag6) && flag7; if (flag1) { penAction = !flag3 || !flag4 ? (!flag8 ? (PenAction) new ExtendAction(pathEditorTarget, this.ActiveSceneViewModel) : (PenAction) new JoinAction(pathEditorTarget, this.ActiveSceneViewModel, this.pathEditorTarget, this.pathEditContext)) : (PenAction) new CloseAction(pathEditorTarget, this.ActiveSceneViewModel); } else if (flag2) { penAction = !flag3 || !flag4 ? (!flag8 ? (PenAction) new ExtendAction(pathEditorTarget, this.ActiveSceneViewModel) : (PenAction) new JoinAction(pathEditorTarget, this.ActiveSceneViewModel, this.pathEditorTarget, this.pathEditContext)) : (PenAction) new AdjustAction(pathEditorTarget, this.ActiveSceneViewModel); } } if (PathFigureUtilities.IsIsolatedPoint(figure1) && this.pathEditContext == null) { penAction = (PenAction) new ExtendAction(pathEditorTarget, this.ActiveSceneViewModel); } } } if (penAction == null) { penAction = !this.IsActive || this.pathEditorTarget == null || (this.pathEditorTarget.PathGeometry.Figures.Count <= 0 || this.pathEditorTarget.PathGeometry.Figures[this.pathEditorTarget.PathGeometry.Figures.Count - 1].IsClosed) ? (PenAction) new StartAction(this, (PathEditorTarget)null, this.ActiveSceneViewModel) : (PenAction) new AppendAction(this.pathEditorTarget, this.ActiveSceneViewModel); } return(penAction); }
public PathTangentAdorner(PathAdornerSet pathAdornerSet, int figureIndex, int endPointIndex, int segmentIndex, int segmentPointIndex, PathPointAdorner pathPointAdorner, PathSegmentAdorner pathSegmentAdorner) : base(pathAdornerSet, figureIndex, endPointIndex, segmentIndex, segmentPointIndex) { this.Initialize(figureIndex, endPointIndex, segmentIndex, segmentPointIndex, pathPointAdorner, pathSegmentAdorner); }
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); } }
private void MoveSelection() { Matrix matrixToAdornerLayer = this.pathPartAdorner.PathAdornerSet.GetTransformMatrixToAdornerLayer(); Point pointInAdornerLayer = this.GetSnappedPointInAdornerLayer(); PathTangentAdorner pathTangentAdorner = this.pathPartAdorner as PathTangentAdorner; PathEditContext pathEditContext = new PathEditContext(this.pathPartAdorner.FigureIndex, this.pathPartAdorner.PartIndex); if (pathTangentAdorner != null) { this.EnsureEditTransaction(); this.pathEditorTarget.BeginEditing(); if (!this.HasMouseMovedAfterDown) { this.startRootPoint = PathFigureUtilities.GetPoint(this.pathEditorTarget.PathGeometry.Figures[pathEditContext.FigureIndex], pathEditContext.PartIndex, false); this.correspondingPoint = PathFigureUtilities.GetPoint(this.pathEditorTarget.PathGeometry.Figures[pathEditContext.FigureIndex], pathEditContext.PartIndex, true); } Point point = this.IsShiftDown ? this.correspondingPoint : this.startRootPoint; Vector correspondingVector = ElementUtilities.GetCorrespondingVector(pointInAdornerLayer - point * matrixToAdornerLayer, matrixToAdornerLayer, this.IsShiftDown ? this.axisConstraint : (AxisConstraint)null); new PathFigureEditor(pathEditContext.GetPathFigure(this.pathEditorTarget.PathGeometry)).MoveTangent(pathEditContext.PartIndex, point + correspondingVector, this.isEnforcingSmoothness); this.ActiveView.AdornerLayer.InvalidateAdornerVisuals(this.EditingElement); } else { this.EnsureEditTransaction(); PathPointAdorner pathPointAdorner = this.pathPartAdorner as PathPointAdorner; PathSegmentAdorner pathSegmentAdorner = this.pathPartAdorner as PathSegmentAdorner; this.pathPartAdorner.PathAdornerSet.PathEditorTarget.BeginEditing(); if (!this.HasMouseMovedAfterDown) { Point point; if (pathPointAdorner != null) { point = PathFigureUtilities.GetPoint(pathEditContext.GetPathFigure(this.pathEditorTarget.PathGeometry), pathEditContext.PartIndex); } else { PathFigureEditor pathFigureEditor = new PathFigureEditor(pathEditContext.GetPathFigure(this.pathEditorTarget.PathGeometry)); int segmentIndex; int segmentPointIndex; PathFigureUtilities.GetSegmentFromPointIndex(pathEditContext.GetPathFigure(this.pathEditorTarget.PathGeometry), pathEditContext.PartIndex, out segmentIndex, out segmentPointIndex); point = pathFigureEditor.Evaluate(segmentIndex, segmentPointIndex, this.pathSegmentParameter) * pathSegmentAdorner.PathGeometryTransformMatrix; } this.startRootPoint = point; this.previousRootPoint = this.startRootPoint; } Vector correspondingVector = ElementUtilities.GetCorrespondingVector(pointInAdornerLayer - this.startRootPoint * matrixToAdornerLayer, matrixToAdornerLayer, this.IsShiftDown ? this.axisConstraint : (AxisConstraint)null); double zoom = this.ActiveView.Artboard.Zoom; Vector rootToArtboardScale = this.ActiveView.Artboard.ViewRootToArtboardScale; correspondingVector.X /= zoom * rootToArtboardScale.X; correspondingVector.Y /= zoom * rootToArtboardScale.Y; Vector vector = this.startRootPoint - this.previousRootPoint + correspondingVector; this.previousRootPoint = this.startRootPoint + correspondingVector; Vector deltaOffset = matrixToAdornerLayer.Transform(vector); PathPartSelectionSet partSelectionSet = this.ActiveSceneViewModel.PathPartSelectionSet; if (partSelectionSet == null) { return; } foreach (BaseFrameworkElement sceneElement in (IEnumerable <SceneElement>)partSelectionSet.SelectedPaths) { this.MovePathParts(partSelectionSet, sceneElement, PathEditMode.ScenePath, deltaOffset); this.MovePathParts(partSelectionSet, sceneElement, PathEditMode.MotionPath, deltaOffset); this.MovePathParts(partSelectionSet, sceneElement, PathEditMode.ClippingPath, deltaOffset); } } }