//-------------------------------------------------------------------------------------------------- void _OnActionFinished(ToolAction toolAction) { if (toolAction == _PointAction) { if (_Segments == null) { _Points.Add(0, _PointAction.Point); _MergePointIndices[0] = _PointAction.MergeCandidateIndex; _UpdateCornerPoints(_PointAction.Point); _Segments = new SketchSegmentLine[4]; _Segments[0] = new SketchSegmentLine(0, 1); _Segments[1] = new SketchSegmentLine(1, 2); _Segments[2] = new SketchSegmentLine(2, 3); _Segments[3] = new SketchSegmentLine(3, 0); _Elements = new SketchEditorSegmentElement[4]; for (int i = 0; i < _Elements.Length; i++) { _Elements[i] = new SketchEditorSegmentElement(_SketchEditorTool, -1, _Segments[i], _SketchEditorTool.Transform, _SketchEditorTool.Sketch.Plane); _Elements[i].IsCreating = true; _Elements[i].OnPointsChanged(_Points, null); } _SketchEditorTool.StatusText = "Select second corner or the rectangle."; _PointAction.Reset(); } else { _SetSecondPoint(_PointAction.Point, _PointAction.MergeCandidateIndex); } } }
//-------------------------------------------------------------------------------------------------- internal void InitElements(Dictionary <int, Pnt2d> tempPoints) { var sketch = _SketchEditorTool.Sketch; var plane = sketch.Plane; foreach (var segmentKvp in sketch.Segments) { var element = new SketchEditorSegmentElement(_SketchEditorTool, segmentKvp.Key, segmentKvp.Value, _SketchEditorTool.Transform, plane); element.OnPointsChanged(tempPoints, sketch.Segments, _MarkerCounts); SegmentElements.Add(element); } foreach (var constraint in sketch.Constraints) { var element = new SketchEditorConstraintElement(_SketchEditorTool, constraint, _SketchEditorTool.Transform, plane); element.OnPointsChanged(tempPoints, sketch.Segments, _MarkerCounts); ConstraintElements.Add(element); } foreach (var pointKvp in sketch.Points) { var element = new SketchEditorPointElement(_SketchEditorTool, pointKvp.Key, pointKvp.Value, _SketchEditorTool.Transform, plane); PointElements.Add(element); } _UpdateElementList(); Elements.ForEach(c => { c.Activate(true); c.UpdateVisual(); }); _SketchEditorTool.WorkspaceController.Invalidate(); }
//-------------------------------------------------------------------------------------------------- void _SetEndPoint(Pnt2d point, int mergeCandidateIndex) { // End point if (_Points[0].Distance(point) < 0.001) { // Minimum length not met _PointAction.Reset(); return; } _Points[1] = point; _Points[2] = point; _MergePointIndices[2] = mergeCandidateIndex; _Segment = new SketchSegmentBezier(0, 1, 2); _Element = new SketchEditorSegmentElement(_SketchEditorTool, -1, _Segment, _SketchEditorTool.Transform, _SketchEditorTool.Sketch.Plane); _Element.IsCreating = true; _Element.OnPointsChanged(_Points, null); _HintLine.Remove(); _HintLine = null; _SketchEditorTool.WorkspaceController.HudManager?.RemoveElement(_ValueHudElement); _ValueHudElement = null; _SketchEditorTool.StatusText = "Select control point for line."; _PointAction.Reset(); pointsFinished++; _SketchEditorTool.WorkspaceController.Invalidate(); _SketchEditorTool.WorkspaceController.UpdateSelection(); }
//-------------------------------------------------------------------------------------------------- void _OnActionFinished(ToolAction toolAction) { if (toolAction == _PointAction) { switch (_PointsCompleted) { case 0: _Points.Add(0, _PointAction.Point); _MergePointIndices[0] = _PointAction.MergeCandidateIndex; _PointsCompleted++; _SketchEditorTool.StatusText = "Select end point for circular arc."; _PointAction.Reset(); break; case 1: if (_Points[0].Distance(_PointAction.Point) < 0.001) { // Minimum length not met _PointAction.Reset(); return; } _Points.Add(1, _PointAction.Point); _MergePointIndices[1] = _PointAction.MergeCandidateIndex; _PointsCompleted++; _Points.Add(2, _PointAction.Point); _Segment = new SketchSegmentArc(0, 1, 2); _Element = new SketchEditorSegmentElement(_SketchEditorTool, -1, _Segment, _SketchEditorTool.Transform, _SketchEditorTool.Sketch.Plane); _Element.IsCreating = true; _Element.OnPointsChanged(_Points, null); _SketchEditorTool.StatusText = "Select rim point for circular arc."; _PointAction.Reset(); break; case 2: if (_Points[0].Distance(_PointAction.Point) < 0.001 || _Points[1].Distance(_PointAction.Point) < 0.001) { // Minimum length not met _PointAction.Reset(); return; } _PointAction.Stop(); _Points[2] = _PointAction.Point; _MergePointIndices[2] = _PointAction.MergeCandidateIndex; _SketchEditorTool.FinishSegmentCreation(_Points, _MergePointIndices, new SketchSegment[] { _Segment }, null); break; } } }
//-------------------------------------------------------------------------------------------------- void _OnActionFinished(ToolAction toolAction) { if (toolAction == _PointAction) { switch (_PointsCompleted) { case 0: _CenterPoint = _PointAction.Point; _Points.Add(0, _PointAction.Point); _MergePointIndices[0] = _PointAction.MergeCandidateIndex; _PointsCompleted++; _SketchEditorTool.StatusText = "Select start point for elliptical arc."; _PointAction.Reset(); break; case 1: if (_CenterPoint.Distance(_PointAction.Point) < 0.001) { // Minimum distance not met _PointAction.Reset(); return; } _StartPoint = _PointAction.Point; _StartPointMergeIndex = _PointAction.MergeCandidateIndex; _PointsCompleted++; _Points.Add(1, _PointAction.Point); _Points.Add(2, _PointAction.Point); _Segment = new SketchSegmentEllipticalArc(1, 2, 0); _Element = new SketchEditorSegmentElement(_SketchEditorTool, -1, _Segment, _SketchEditorTool.Transform, _SketchEditorTool.Sketch.Plane); _Element.IsCreating = true; _Element.OnPointsChanged(_Points, null); _SketchEditorTool.StatusText = "Select end point for elliptical arc."; _PointAction.Reset(); break; case 2: if (!_CalcArcRimPoints(_PointAction.Point, _PointAction.MergeCandidateIndex)) { // Minimum length not met _PointAction.Reset(); return; } _PointAction.Stop(); _SketchEditorTool.FinishSegmentCreation(_Points, _MergePointIndices, new SketchSegment[] { _Segment }, null); break; } } }
//-------------------------------------------------------------------------------------------------- void _OnActionFinished(ToolAction toolAction) { if (toolAction == _PointAction) { if (_Segments == null) { _Points.Add(0, _PointAction.Point); _MergePointIndices[0] = _PointAction.MergeCandidateIndex; _SetSecondPoint(_PointAction.Point); _Segments = new SketchSegmentLine[4]; _Segments[0] = new SketchSegmentLine(0, 1); _Segments[1] = new SketchSegmentLine(1, 2); _Segments[2] = new SketchSegmentLine(2, 3); _Segments[3] = new SketchSegmentLine(3, 0); _Elements = new SketchEditorSegmentElement[4]; for (int i = 0; i < _Elements.Length; i++) { _Elements[i] = new SketchEditorSegmentElement(_SketchEditorTool, -1, _Segments[i], _SketchEditorTool.Transform, _SketchEditorTool.Sketch.Plane); _Elements[i].IsCreating = true; _Elements[i].OnPointsChanged(_Points, null); } _SketchEditorTool.StatusText = "Select second corner or the rectangle."; _PointAction.Reset(); } else { if (Math.Abs(_Points[0].X - _PointAction.Point.X) < 0.001 || Math.Abs(_Points[0].Y - _PointAction.Point.Y) < 0.001) { // Minimum length not met _PointAction.Reset(); return; } _PointAction.Stop(); _SetSecondPoint(_PointAction.Point); _MergePointIndices[1] = -1; _MergePointIndices[2] = _PointAction.MergeCandidateIndex; _MergePointIndices[3] = -1; var constraints = new SketchConstraintPerpendicular[4]; constraints[0] = new SketchConstraintPerpendicular(0, 1); constraints[1] = new SketchConstraintPerpendicular(1, 2); constraints[2] = new SketchConstraintPerpendicular(2, 3); constraints[3] = new SketchConstraintPerpendicular(3, 0); _SketchEditorTool.FinishSegmentCreation(_Points, _MergePointIndices, _Segments, constraints); } } }
//-------------------------------------------------------------------------------------------------- void _OnActionFinished(ToolAction toolAction) { if (toolAction == _PointAction) { if (_Segment == null) { _Points.Add(0, _PointAction.Point); _MergePointIndices[0] = _PointAction.MergeCandidateIndex; _Points.Add(1, _PointAction.Point); _Segment = new SketchSegmentLine(0, 1); _Element = new SketchEditorSegmentElement(_SketchEditorTool, -1, _Segment, _SketchEditorTool.Transform, _SketchEditorTool.Sketch.Plane); _Element.IsCreating = true; _Element.OnPointsChanged(_Points, null); if (_ValueHudElement == null && _SketchEditorTool.WorkspaceController.HudManager != null) { _ValueHudElement = _SketchEditorTool.WorkspaceController.HudManager?.CreateElement <ValueHudElement>(this); _ValueHudElement.Label = "Length:"; _ValueHudElement.Units = ValueUnits.Length; _ValueHudElement.ValueEntered += _ValueHudElement_ValueEntered; } _ValueHudElement?.SetValue(_Segment.Length(_Points)); _SketchEditorTool.StatusText = "Select end point for line."; _PointAction.Reset(); } else { if (_Points[0].Distance(_PointAction.Point) < 0.001) { _PointAction.Reset(); return; } _Points[1] = _PointAction.Point; _MergePointIndices[1] = _PointAction.MergeCandidateIndex; // Accept point _PointAction.Stop(); _SketchEditorTool.FinishSegmentCreation(_Points, _MergePointIndices, new SketchSegment[] { _Segment }, null, _MergePointIndices[1] >= 0 ? -1 : 1); } } }
//-------------------------------------------------------------------------------------------------- void _SetStartPoint(Pnt2d point, int mergeCandidateIndex) { if (_CenterPoint.Distance(point) < 0.001) { // Minimum length not met _PointAction.Reset(); return; } if (_PreviewLine != null) { _PreviewLine.Remove(); _PreviewLine = null; } _HintLines[0].Set(_CenterPoint, point, _SketchEditorTool.Sketch.Plane); if (_ValueHudElement != null) { _SketchEditorTool.WorkspaceController.HudManager?.RemoveElement(_ValueHudElement); _ValueHudElement.ValueEntered -= _ValueHudElement_RadiusEntered; _ValueHudElement = null; } _Points.Add(0, point); _MergePointIndices[0] = mergeCandidateIndex; _PointsCompleted++; _Points.Add(1, point); _Points.Add(2, point); _Segment = new SketchSegmentArc(0, 1, 2); _Element = new SketchEditorSegmentElement(_SketchEditorTool, -1, _Segment, _SketchEditorTool.Transform, _SketchEditorTool.Sketch.Plane); _Element.IsCreating = true; _Element.OnPointsChanged(_Points, null); _SketchEditorTool.StatusText = "Select end point for circular arc."; _PointAction.Reset(); _PointAction.ConstraintPoint += _PointActionOnConstraintPoint; _SketchEditorTool.WorkspaceController.Invalidate(); _SketchEditorTool.WorkspaceController.UpdateSelection(); }
//-------------------------------------------------------------------------------------------------- void _OnActionFinished(ToolAction toolAction) { if (toolAction == _PointAction) { if (_Segment == null) { _Points.Add(0, _PointAction.Point); _MergePointIndices[0] = _PointAction.MergeCandidateIndex; _Points.Add(1, _PointAction.Point); _Segment = new SketchSegmentCircle(0, 1); _Marker = new Marker(_SketchEditorTool.WorkspaceController, Marker.Styles.Bitmap | Marker.Styles.Topmost, Marker.BallImage); _Marker.Set(_PointAction.Point, _SketchEditorTool.Sketch.Plane); _Element = new SketchEditorSegmentElement(_SketchEditorTool, -1, _Segment, _SketchEditorTool.Transform, _SketchEditorTool.Sketch.Plane); _Element.IsCreating = true; _Element.OnPointsChanged(_Points, null); _SketchEditorTool.WorkspaceController.Invalidate(); _SketchEditorTool.StatusText = "Select any rim point of the circle."; _PointAction.Reset(); } else { if (_Points[0].Distance(_PointAction.Point) < 0.001) { // Minimum length not met _PointAction.Reset(); return; } _Points[1] = _PointAction.Point; _MergePointIndices[1] = _PointAction.MergeCandidateIndex; _PointAction.Stop(); _SketchEditorTool.FinishSegmentCreation(_Points, _MergePointIndices, new SketchSegment[] { _Segment }, null); } } }
//-------------------------------------------------------------------------------------------------- void _SetFirstRimPoint(Pnt2d point, int mergeCandidateIndex) { if (_Points[0].Distance(point) < 0.001) { // Min distance not met _PointAction.Reset(); return; } if (_HintCircle != null) { _HintCircle.Remove(); _HintCircle = null; } if (_HintLine != null) { _HintLine.Remove(); _HintLine = null; } _Points[1] = point; _MergePointIndices[1] = mergeCandidateIndex; _PointsCompleted++; _Marker[1] = new Marker(_SketchEditorTool.WorkspaceController, Marker.Styles.Bitmap | Marker.Styles.Topmost, Marker.BallImage); _Marker[1].Set(point, _SketchEditorTool.Sketch.Plane); _Points[2] = point; _Segment = new SketchSegmentEllipse(0, 1, 2); _Element = new SketchEditorSegmentElement(_SketchEditorTool, -1, _Segment, _SketchEditorTool.Transform, _SketchEditorTool.Sketch.Plane); _Element.IsCreating = true; _Element.OnPointsChanged(_Points, null); _SketchEditorTool.StatusText = "Select second rim point of the ellipse."; _PointAction.Reset(); _SketchEditorTool.WorkspaceController.Invalidate(); _SketchEditorTool.WorkspaceController.UpdateSelection(); }
//-------------------------------------------------------------------------------------------------- public bool Continue(int continueWithPoint) { // Start the next line with the first point already catched _Points[0] = _SketchEditorTool.Sketch.Points[continueWithPoint]; _MergePointIndices[0] = continueWithPoint; _Element?.Remove(); _Segment = new SketchSegmentLine(0, 1); _Element = new SketchEditorSegmentElement(_SketchEditorTool, -1, _Segment, _SketchEditorTool.Transform, _SketchEditorTool.Sketch.Plane); _Element.IsCreating = true; _Element.OnPointsChanged(_Points, null); _PointAction = new SketchPointAction(_SketchEditorTool); if (!_SketchEditorTool.WorkspaceController.StartToolAction(_PointAction, false)) { return(false); } _PointAction.Previewed += _OnActionPreview; _PointAction.Finished += _OnActionFinished; return(true); }
//-------------------------------------------------------------------------------------------------- public bool Continue(int continueWithPoint) { // Start the next line with the first point already catched _Points[0] = _SketchEditorTool.Sketch.Points[continueWithPoint]; _MergePointIndices[0] = continueWithPoint; _Segment = null; _Element?.Remove(); _Element = null; _HintLine = new HintLine(_SketchEditorTool.WorkspaceController, HintStyle.ThinDashed | HintStyle.Topmost); _HintLine.Set(_Points[0], _Points[0], _SketchEditorTool.Sketch.Plane); _PointAction = new SketchPointAction(_SketchEditorTool); if (!_SketchEditorTool.WorkspaceController.StartToolAction(_PointAction, false)) { return(false); } _PointsFinished = 1; _SketchEditorTool.StatusText = "Select end point for line."; return(true); }
//-------------------------------------------------------------------------------------------------- internal void OnSketchChanged(Sketch sketch, Sketch.ElementType types) { if (sketch == _SketchEditorTool.Sketch) { if (types.HasFlag(Sketch.ElementType.Point)) { // Check for lost points var lostPoints = PointElements.Where(pc => !sketch.Points.ContainsKey(pc.PointIndex)).ToArray(); foreach (var lostPoint in lostPoints) { lostPoint.Remove(); PointElements.Remove(lostPoint); } } if (types.HasFlag(Sketch.ElementType.Segment)) { // Check for lost segments var lostSegs = SegmentElements.Where(sc => !sketch.Segments.ContainsValue(sc.Segment)).ToArray(); foreach (var lostSeg in lostSegs) { lostSeg.Remove(); SegmentElements.Remove(lostSeg); } } if (types.HasFlag(Sketch.ElementType.Constraint)) { // Check for lost constraints var lostCons = ConstraintElements.Where(cc => !sketch.Constraints.Contains(cc.Constraint)).ToArray(); foreach (var lostCon in lostCons) { lostCon.Remove(); ConstraintElements.Remove(lostCon); } } // Check for new ones if (types.HasFlag(Sketch.ElementType.Point)) { // Check for new points var newPoints = sketch.Points.Where(kvp => !PointElements.Exists(pc => pc.PointIndex == kvp.Key)); foreach (var pointKvp in newPoints) { var element = new SketchEditorPointElement(_SketchEditorTool, pointKvp.Key, pointKvp.Value, _SketchEditorTool.Transform, sketch.Plane); element.UpdateVisual(); element.Activate(true); PointElements.Add(element); } } if (types.HasFlag(Sketch.ElementType.Segment)) { // Check for new segments var newSegs = sketch.Segments.Where(seg => !SegmentElements.Exists(sc => sc.Segment == seg.Value)); foreach (var segmentKvp in newSegs) { var element = new SketchEditorSegmentElement(_SketchEditorTool, segmentKvp.Key, segmentKvp.Value, _SketchEditorTool.Transform, sketch.Plane); element.OnPointsChanged(sketch.Points, sketch.Segments, _MarkerCounts); element.UpdateVisual(); element.Activate(true); SegmentElements.Add(element); } } if (types.HasFlag(Sketch.ElementType.Constraint)) { // Check for new constraints var newCons = sketch.Constraints.Where(con => !ConstraintElements.Exists(cc => cc.Constraint == con)); foreach (var sketchConstraint in newCons) { var element = new SketchEditorConstraintElement(_SketchEditorTool, sketchConstraint, _SketchEditorTool.Transform, sketch.Plane); element.OnPointsChanged(sketch.Points, sketch.Segments, _MarkerCounts); element.UpdateVisual(); element.Activate(true); ConstraintElements.Add(element); } } // Update elements _UpdateElementList(); if (types.HasFlag(Sketch.ElementType.Point)) { OnPointsChanged(sketch.Points, sketch.Segments); } _SketchEditorTool.WorkspaceController.Invalidate(); } }
//-------------------------------------------------------------------------------------------------- void _OnActionFinished(ToolAction toolAction) { if (toolAction == _PointAction) { switch (pointsFinished) { case 0: // Start point _Points.Add(0, _PointAction.Point); _MergePointIndices[0] = _PointAction.MergeCandidateIndex; _HintLine = new HintLine(_SketchEditorTool.WorkspaceController, HintStyle.ThinDashed | HintStyle.Topmost); _HintLine.Set(_PointAction.Point, _PointAction.Point, _SketchEditorTool.Sketch.Plane); _SketchEditorTool.StatusText = "Select end point for line."; _PointAction.Reset(); pointsFinished++; break; case 1: // End point if (_Points[0].Distance(_PointAction.Point) < 0.001) { // Minimum length not met _PointAction.Reset(); return; } _Points.Add(1, _PointAction.Point); _Points.Add(2, _PointAction.Point); _MergePointIndices[2] = _PointAction.MergeCandidateIndex; _Segment = new SketchSegmentBezier(0, 1, 2); _Element = new SketchEditorSegmentElement(_SketchEditorTool, -1, _Segment, _SketchEditorTool.Transform, _SketchEditorTool.Sketch.Plane); _Element.IsCreating = true; _Element.OnPointsChanged(_Points, null); _HintLine.Remove(); _HintLine = null; _SketchEditorTool.StatusText = "Select control point for line."; _PointAction.Reset(); pointsFinished++; break; case 2: // Control point, finished _PointAction.Stop(); _Points[1] = _PointAction.Point; _MergePointIndices[1] = _PointAction.MergeCandidateIndex; _SketchEditorTool.FinishSegmentCreation(_Points, _MergePointIndices, new SketchSegment[] { _Segment }, null, _MergePointIndices[1] >= 0 ? -1 : 2); pointsFinished++; break; } } }
//-------------------------------------------------------------------------------------------------- void _OnActionFinished(ToolAction toolAction) { if (toolAction == _PointAction) { switch (_PointsCompleted) { case 0: _Points.Add(0, _PointAction.Point); _MergePointIndices[0] = _PointAction.MergeCandidateIndex; _PointsCompleted++; _Marker[0] = new Marker(_SketchEditorTool.WorkspaceController, Marker.Styles.Bitmap | Marker.Styles.Topmost, Marker.BallImage); _Marker[0].Set(_PointAction.Point, _SketchEditorTool.Sketch.Plane); _SketchEditorTool.StatusText = "Select first rim point of the ellipse."; _PointAction.Reset(); break; case 1: if (_Points[0].Distance(_PointAction.Point) < 0.001) { // Min distance not met _PointAction.Reset(); return; } if (_HintCircle != null) { _HintCircle.Remove(); _HintCircle = null; } if (_HintLine != null) { _HintLine.Remove(); _HintLine = null; } _Points.Add(1, _PointAction.Point); _MergePointIndices[1] = _PointAction.MergeCandidateIndex; _PointsCompleted++; _Marker[1] = new Marker(_SketchEditorTool.WorkspaceController, Marker.Styles.Bitmap | Marker.Styles.Topmost, Marker.BallImage); _Marker[1].Set(_PointAction.Point, _SketchEditorTool.Sketch.Plane); _Points.Add(2, _PointAction.Point); _Segment = new SketchSegmentEllipse(0, 1, 2); _Element = new SketchEditorSegmentElement(_SketchEditorTool, -1, _Segment, _SketchEditorTool.Transform, _SketchEditorTool.Sketch.Plane); _Element.IsCreating = true; _Element.OnPointsChanged(_Points, null); _SketchEditorTool.StatusText = "Select second rim point of the ellipse."; _PointAction.Reset(); break; case 2: if (_Points[0].Distance(_PointAction.Point) < 0.001 || _Points[1].Distance(_PointAction.Point) < 0.001) { // Min distance not met _PointAction.Reset(); return; } _Points[2] = _PointAction.Point; _MergePointIndices[2] = _PointAction.MergeCandidateIndex; _PointAction.Stop(); _SketchEditorTool.FinishSegmentCreation(_Points, _MergePointIndices, new SketchSegment[] { _Segment }, null); break; } } }