//-------------------------------------------------------------------------------------------------- void _OnActionPreview(ToolAction toolAction) { if (toolAction == _PointAction) { switch (_PointsCompleted) { case 1: if (_HintLines[0] == null) { _HintLines[0] = new HintLine(_SketchEditorTool.WorkspaceController, HintStyle.ThinDashed | HintStyle.Topmost); } _HintLines[0].Set(_CenterPoint, _PointAction.Point, _SketchEditorTool.Sketch.Plane); break; case 2: if (_HintLines[1] == null) { _HintLines[1] = new HintLine(_SketchEditorTool.WorkspaceController, HintStyle.ThinDashed | HintStyle.Topmost); } _HintLines[1].Set(_CenterPoint, _PointAction.Point, _SketchEditorTool.Sketch.Plane); if (_Segment != null) { _CalcArcRimPoints(_PointAction.Point); _Element.OnPointsChanged(_Points, null); } break; } _Coord2DHudElement?.SetValues(_PointAction.Point.X, _PointAction.Point.Y); } }
//-------------------------------------------------------------------------------------------------- public override bool Start() { _SelectionContext = WorkspaceController.Selection.OpenContext(); _HintLine = new HintLine(WorkspaceController, HintStyle.ThinDashed); _HintLine.Set(_Axis); return(true); }
//-------------------------------------------------------------------------------------------------- void ProcessMouseInput(MouseEventData data) { var snapInfo = WorkspaceController.SnapHandler.Snap(data); var snapPoint = WorkspaceController.SnapHandler.SnapOnPlane(snapInfo); if (snapPoint != null) { // Point is snapped Point = ElSLib.Value(snapPoint.Value.X, snapPoint.Value.Y, WorkspaceController.Workspace.WorkingPlane); if (snapInfo.SnapMode != SnapMode.Grid) { if (_HintLine == null) { _HintLine = new HintLine(WorkspaceController, HintStyle.ThinDashed); } _HintLine.Set(snapInfo.Point, Point); } else { _HintLine?.Remove(); } } else { Point = data.PointOnPlane; _HintLine?.Remove(); } }
//-------------------------------------------------------------------------------------------------- void _OnActionPreview(ToolAction toolAction) { if (toolAction == _PointAction) { switch (_PointsCompleted) { case 1: var p1 = _Points[0]; var p2 = _PointAction.Point; if (_PreviewLine == null) { _PreviewLine = new HintLine(_SketchEditorTool.WorkspaceController, HintStyle.ThinDashed | HintStyle.Topmost); } _PreviewLine.Set(p1, p2, _SketchEditorTool.Sketch.Plane); break; case 2: if (_Segment != null) { _Points[2] = _PointAction.Point; _Element.OnPointsChanged(_Points, null); if (_LabelHudElement == null) { _LabelHudElement = _SketchEditorTool.WorkspaceController.HudManager?.CreateElement <LabelHudElement>(this); } _LabelHudElement?.SetValue("Radius: " + _Segment.Radius(_Points).ToRoundedString()); } break; } _Coord2DHudElement?.SetValues(_PointAction.Point.X, _PointAction.Point.Y); } }
//-------------------------------------------------------------------------------------------------- public void Stop() { if (_HintCircle != null) { _HintCircle.Remove(); _HintCircle = null; } if (_HintLine != null) { _HintLine.Remove(); _HintLine = null; } for (int i = 0; i < _Marker.Length; i++) { if (_Marker[i] != null) { _Marker[i].Remove(); } _Marker[i] = null; } _Element?.Remove(); _PointAction?.Stop(); _SketchEditorTool.WorkspaceController.HudManager?.RemoveElement(_Coord2DHudElement); _Coord2DHudElement = null; _SketchEditorTool.WorkspaceController.HudManager?.RemoveElement(_ValueHudElement); _ValueHudElement = null; }
//-------------------------------------------------------------------------------------------------- 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(); }
//-------------------------------------------------------------------------------------------------- public override bool OnMouseUp(MouseEventData data, bool shiftSelected) { if (_RotateMode != RotateMode.None) { _RotateMode = RotateMode.None; WorkspaceController.HudManager?.SetCursor(null); _AxisHintLine?.Remove(); _AxisHintLine = null; WorkspaceController.HudManager?.RemoveElement(_DeltaHudElement); _DeltaHudElement = null; if (Delta != 0) { // Commit Stop(); IsFinished = true; } WorkspaceController.Invalidate(); return(true); } return(base.OnMouseUp(data, shiftSelected)); }
//-------------------------------------------------------------------------------------------------- public override void Cleanup() { if (Revolve != null) { Revolve.PropertyChanged -= Revolve_PropertyChanged; } if (_AxisHintLine != null) { _AxisHintLine.Remove(); _AxisHintLine = null; } }
//-------------------------------------------------------------------------------------------------- public void Stop() { _PreviewLine?.Remove(); _PreviewLine = null; _PointAction.Stop(); _Element?.Remove(); _SketchEditorTool.WorkspaceController.HudManager?.RemoveElement(_Coord2DHudElement); _Coord2DHudElement = null; _SketchEditorTool.WorkspaceController.HudManager?.RemoveElement(_ValueHudElement); _ValueHudElement = null; }
//-------------------------------------------------------------------------------------------------- public override bool OnMouseDown(MouseEventData data) { _RotateMode = RotateMode.None; if (data.DetectedEntities.Count == 0 && _Gizmo != null) { if (_Gizmo.IsPartDetected(AIS_RotationGizmo.Part.Part_XAxis)) { _RotateMode = RotateMode.AxisX; RotationAxis = new Ax1(_CoordinateSystem.Location, _CoordinateSystem.XDirection); _RotationPlane = new Pln(new Ax3(_CoordinateSystem.Location, _CoordinateSystem.XDirection, _CoordinateSystem.Direction)); _Gizmo.ForcePartHilighting(AIS_RotationGizmo.Part.Part_XAxis); } else if (_Gizmo.IsPartDetected(AIS_RotationGizmo.Part.Part_YAxis)) { _RotateMode = RotateMode.AxisY; RotationAxis = new Ax1(_CoordinateSystem.Location, _CoordinateSystem.YDirection); _RotationPlane = new Pln(new Ax3(_CoordinateSystem.Location, _CoordinateSystem.YDirection, _CoordinateSystem.Direction)); _Gizmo.ForcePartHilighting(AIS_RotationGizmo.Part.Part_YAxis); } else if (_Gizmo.IsPartDetected(AIS_RotationGizmo.Part.Part_ZAxis)) { _RotateMode = RotateMode.AxisZ; RotationAxis = new Ax1(_CoordinateSystem.Location, _CoordinateSystem.Direction); _RotationPlane = new Pln(new Ax3(_CoordinateSystem.Location, _CoordinateSystem.Direction, _CoordinateSystem.XDirection)); _Gizmo.ForcePartHilighting(AIS_RotationGizmo.Part.Part_ZAxis); } if (_RotateMode != RotateMode.None) { Pnt resultPnt; if (WorkspaceController.ActiveViewport.ScreenToPoint(_RotationPlane, (int)data.ScreenPoint.X, (int)data.ScreenPoint.Y, out resultPnt)) { var planeDelta = ProjLib.Project(_RotationPlane, resultPnt); _StartValue = Dir2d.DX.Angle(new Dir2d(planeDelta.Coord)); } _AxisHintLine = new HintLine(WorkspaceController, HintStyle.ThinDashed); _AxisHintLine.Set(RotationAxis); WorkspaceController.Invalidate(); WorkspaceController.HudManager?.SetCursor(Cursors.Rotate); return(true); } } return(base.OnMouseDown(data)); }
//-------------------------------------------------------------------------------------------------- void UpdateFromShape() { switch (Revolve.Axis) { case Revolve.RevolveAxis.WorldX: Frame = 0; Axis = 0; break; case Revolve.RevolveAxis.WorldY: Frame = 0; Axis = 1; break; case Revolve.RevolveAxis.WorldZ: Frame = 0; Axis = 2; break; case Revolve.RevolveAxis.LocalX: Frame = 1; Axis = 0; break; case Revolve.RevolveAxis.LocalY: Frame = 1; Axis = 1; break; case Revolve.RevolveAxis.LocalZ: Frame = 1; Axis = 2; break; } _OffsetX = Revolve.Offset.X; _OffsetY = Revolve.Offset.Y; _OffsetZ = Revolve.Offset.Z; RaisePropertyChanged(nameof(OffsetX)); RaisePropertyChanged(nameof(OffsetY)); RaisePropertyChanged(nameof(OffsetZ)); if ((_AxisHintLine == null) && (Revolve.IsVisible)) { _AxisHintLine = new HintLine(WorkspaceController, HintStyle.WorkingAxis); } if (_AxisHintLine != null) { if (!Revolve.IsVisible) { _AxisHintLine.Remove(); _AxisHintLine = null; } else { var computeAxis = Revolve.ComputeAxis(); if (computeAxis != null) { _AxisHintLine.Set(computeAxis.Value.Transformed(Revolve.GetTransformation())); } } } }
//-------------------------------------------------------------------------------------------------- void _OnActionPreview(ToolAction toolAction) { if (toolAction == _PointAction) { switch (_PointsCompleted) { case 1: if (_PreviewLine == null) { _PreviewLine = new HintCircle(_SketchEditorTool.WorkspaceController, HintStyle.ThinDashed | HintStyle.Topmost); } if (_HintLines[0] == null) { _HintLines[0] = new HintLine(_SketchEditorTool.WorkspaceController, HintStyle.ThinDashed | HintStyle.Topmost); } var p1 = _CenterPoint; var p2 = _PointAction.Point; var circ = new gce_MakeCirc2d(p1, p2).Value(); _PreviewLine.Set(circ, _SketchEditorTool.Sketch.Plane); _HintLines[0].Set(_CenterPoint, _PointAction.Point, _SketchEditorTool.Sketch.Plane); if (_LabelHudElement == null) { _LabelHudElement = _SketchEditorTool.WorkspaceController.HudManager?.CreateElement <LabelHudElement>(this); } _LabelHudElement?.SetValue("Radius: " + circ.Radius().ToRoundedString()); break; case 2: if (_HintLines[1] == null) { _HintLines[1] = new HintLine(_SketchEditorTool.WorkspaceController, HintStyle.ThinDashed | HintStyle.Topmost); } _HintLines[1].Set(_CenterPoint, _PointAction.Point, _SketchEditorTool.Sketch.Plane); if (_Segment != null) { _CalcArcRimPoints(_PointAction.Point); _Element.OnPointsChanged(_Points, null); } break; } _Coord2DHudElement?.SetValues(_PointAction.Point.X, _PointAction.Point.Y); } }
//-------------------------------------------------------------------------------------------------- void _OnActionFinished(ToolAction toolAction) { if (toolAction == _PointAction) { switch (pointsFinished) { case 0: // Start point _Points[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."; if (_ValueHudElement == null && _SketchEditorTool.WorkspaceController.HudManager != null) { _ValueHudElement = _SketchEditorTool.WorkspaceController.HudManager?.CreateElement <ValueHudElement>(this); _ValueHudElement.Label = "Distance:"; _ValueHudElement.Units = ValueUnits.Length; _ValueHudElement.ValueEntered += _ValueHudElement_ValueEntered; } _PointAction.Reset(); pointsFinished++; break; case 1: _SetEndPoint(_PointAction.Point, _PointAction.MergeCandidateIndex); 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 _UpdateHints() { if (Entity?.Body?.Shape != Entity) { return; } var axis = Entity?.GetRotationAxis()?.Transformed(Entity.Body.GetTransformation()); if (axis == null) { _ClearHints(); return; } if (_HintCircle == null) { _HintCircle = new HintCircle(WorkspaceController, HintStyle.Solid); } _HintCircle.Set(new gp_Circ(axis.Value.ToAx2(), Entity.Radius)); var(startAngle, endAngle) = Entity.GetStartEndAngles(); _HintCircle.SetRange(startAngle, endAngle); if (_HintAngles == null) { _HintAngles = new HintLine[3]; _HintAngles[0] = new HintLine(WorkspaceController, HintStyle.ThinDashed); _HintAngles[1] = new HintLine(WorkspaceController, HintStyle.Solid); _HintAngles[2] = new HintLine(WorkspaceController, HintStyle.Dashed); } var centerPoint = axis.Value.Location; var mainVec = axis.Value.XDirection.ToVec() * Entity.Radius; var localRotAxis = new Ax1(Pnt.Origin, axis.Value.Axis.Direction); _HintAngles[0].Set(centerPoint, centerPoint.Translated(mainVec)); _HintAngles[1].Set(centerPoint, centerPoint.Translated(mainVec.Rotated(localRotAxis, startAngle.ToRad()))); _HintAngles[2].Set(centerPoint, centerPoint.Translated(mainVec.Rotated(localRotAxis, endAngle.ToRad()))); WorkspaceController.Invalidate(); }
//-------------------------------------------------------------------------------------------------- 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 = 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); }
//-------------------------------------------------------------------------------------------------- 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(); }
//-------------------------------------------------------------------------------------------------- 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; } } }
//-------------------------------------------------------------------------------------------------- public override bool OnMouseDown(MouseEventData data) { _MoveMode = MoveMode.None; if (!data.DetectedEntities.Any() && _Gizmo != null) { _Delta = Vec.Zero; if (_Gizmo.IsPartDetected(AIS_TranslationGizmo.Part.Part_XAxis)) { _MoveMode = MoveMode.AxisX; _MoveAxis = new Ax1(_CoordinateSystem.Location, _CoordinateSystem.XDirection); _Gizmo.ForcePartHilighting(AIS_TranslationGizmo.Part.Part_XAxis); } else if (_Gizmo.IsPartDetected(AIS_TranslationGizmo.Part.Part_YAxis)) { _MoveMode = MoveMode.AxisY; _MoveAxis = new Ax1(_CoordinateSystem.Location, _CoordinateSystem.YDirection); _Gizmo.ForcePartHilighting(AIS_TranslationGizmo.Part.Part_YAxis); } else if (_Gizmo.IsPartDetected(AIS_TranslationGizmo.Part.Part_ZAxis)) { _MoveMode = MoveMode.AxisZ; _MoveAxis = new Ax1(_CoordinateSystem.Location, _CoordinateSystem.Direction); _Gizmo.ForcePartHilighting(AIS_TranslationGizmo.Part.Part_ZAxis); } else if (_Gizmo.IsPartDetected(AIS_TranslationGizmo.Part.Part_YZPlane)) { _MoveMode = MoveMode.PlaneYZ; _MovePlane = new Pln(new Ax3(_CoordinateSystem.Location, _CoordinateSystem.XDirection, _CoordinateSystem.Direction)); _Gizmo.ForcePartHilighting(AIS_TranslationGizmo.Part.Part_YAxis); _Gizmo.ForcePartHilighting(AIS_TranslationGizmo.Part.Part_ZAxis); } else if (_Gizmo.IsPartDetected(AIS_TranslationGizmo.Part.Part_XZPlane)) { _MoveMode = MoveMode.PlaneXZ; _MovePlane = new Pln(new Ax3(_CoordinateSystem.Location, _CoordinateSystem.YDirection, _CoordinateSystem.Direction)); _Gizmo.ForcePartHilighting(AIS_TranslationGizmo.Part.Part_XAxis); _Gizmo.ForcePartHilighting(AIS_TranslationGizmo.Part.Part_ZAxis); } else if (_Gizmo.IsPartDetected(AIS_TranslationGizmo.Part.Part_XYPlane)) { _MoveMode = MoveMode.PlaneXY; _MovePlane = new Pln(new Ax3(_CoordinateSystem.Location, _CoordinateSystem.Direction, _CoordinateSystem.XDirection)); _Gizmo.ForcePartHilighting(AIS_TranslationGizmo.Part.Part_XAxis); _Gizmo.ForcePartHilighting(AIS_TranslationGizmo.Part.Part_YAxis); } if ((_MoveMode & MoveMode.Axis) != 0) { var axisDelta = _ProcessMouseInputForAxis(data); if (axisDelta.HasValue) { _MoveStartValue.X = axisDelta.Value; _MoveStartValue.Y = 0; } else { _MoveStartValue.X = 0; _MoveStartValue.Y = 0; } _AxisHintLine = new HintLine(WorkspaceController, HintStyle.ThinDashed); _AxisHintLine.Set(_MoveAxis); WorkspaceController.Invalidate(); WorkspaceController.HudManager?.SetCursor(Cursors.Move); return(true); } if ((_MoveMode & MoveMode.Plane) != 0) { Pnt resultPnt; if (WorkspaceController.ActiveViewport.ScreenToPoint(_MovePlane, (int)data.ScreenPoint.X, (int)data.ScreenPoint.Y, out resultPnt)) { _MoveStartValue = ProjLib.Project(_MovePlane, resultPnt); } WorkspaceController.Invalidate(); WorkspaceController.HudManager?.SetCursor(Cursors.Move); return(true); } } return(base.OnMouseDown(data)); }
//-------------------------------------------------------------------------------------------------- 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; } } }