//-------------------------------------------------------------------------------------------------- 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); } }
//-------------------------------------------------------------------------------------------------- void _OnActionPreview(ToolAction toolAction) { if (toolAction == _PointAction) { switch (_PointsCompleted) { case 1: var p1 = _Points[0]; var p2 = _PointAction.Point; _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 (_ValueHudElement == null && _SketchEditorTool.WorkspaceController.HudManager != null) { _ValueHudElement = _SketchEditorTool.WorkspaceController.HudManager?.CreateElement <ValueHudElement>(this); _ValueHudElement.Label = "Radius:"; _ValueHudElement.Units = ValueUnits.Length; _ValueHudElement.ValueEntered += _ValueHudElement_RadiusEntered; } _ValueHudElement?.SetValue(_Segment.Radius(_Points)); } break; } _Coord2DHudElement?.SetValues(_PointAction.PointOnWorkingPlane.X, _PointAction.PointOnWorkingPlane.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 (_PointsFinished) { case 1: _HintLine.Set(_Points[0], _PointAction.Point, _SketchEditorTool.Sketch.Plane); break; case 2: _Points[1] = _PointAction.Point; _Points[2] = _PointAction.Point; _Element.OnPointsChanged(_Points, null); break; case 3: _Points[2] = _PointAction.Point; _Element.OnPointsChanged(_Points, null); break; } _Coord2DHudElement?.SetValues(_PointAction.Point.X, _PointAction.Point.Y); } }
//-------------------------------------------------------------------------------------------------- void _PointAction_Previewed(ToolAction toolAction) { var workingPlane = _SketchEditorTool.WorkspaceController.Workspace.WorkingPlane; var point = _SketchEditorTool.Sketch.Plane.Value(_PointAction.Point); _HintLineH ??= new HintLine(_SketchEditorTool.WorkspaceController, HintStyle.WorkingAxis); _HintLineH.Set(new Ax1(point, workingPlane.XAxis.Direction)); _HintLineV ??= new HintLine(_SketchEditorTool.WorkspaceController, HintStyle.WorkingAxis); _HintLineV.Set(new Ax1(point, workingPlane.YAxis.Direction)); }
//-------------------------------------------------------------------------------------------------- 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 _OnActionPreview(ToolAction toolAction) { if (toolAction == _PointAction) { if (_HintLine != null) { _HintLine.Set(_Points[0], _PointAction.Point, _SketchEditorTool.Sketch.Plane); } else if (_Segment != null) { _Points[1] = _PointAction.Point; _Element.OnPointsChanged(_Points, null); } _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 _OnActionPreview(ToolAction toolAction) { if (toolAction == _PointAction) { switch (_PointsCompleted) { case 1: if (_HintCircle == null) { _HintCircle = new HintCircle(_SketchEditorTool.WorkspaceController, HintStyle.ThinDashed | HintStyle.Topmost); } if (_HintLine == null) { _HintLine = new HintLine(_SketchEditorTool.WorkspaceController, HintStyle.ThinDashed | HintStyle.Topmost); } var p1 = _Points[0]; var p2 = _PointAction.Point; var circ = new gce_MakeCirc2d(p1, p2).Value(); _HintCircle.Set(circ, _SketchEditorTool.Sketch.Plane); _HintLine.Set(p1, p2, _SketchEditorTool.Sketch.Plane); if (_LabelHudElement == null) { _LabelHudElement = _SketchEditorTool.WorkspaceController.HudManager?.CreateElement <LabelHudElement>(this); } _LabelHudElement?.SetValue("Distance: " + _Points[0].Distance(_PointAction.Point).ToRoundedString()); break; case 2: if (_Segment != null) { _Points[2] = _PointAction.Point; _Element.OnPointsChanged(_Points, null); } _LabelHudElement?.SetValue("Distance: " + _Points[0].Distance(_PointAction.Point).ToRoundedString()); break; } _Coord2DHudElement?.SetValues(_PointAction.Point.X, _PointAction.Point.Y); } }
//-------------------------------------------------------------------------------------------------- void _OnActionPreview(ToolAction toolAction) { if (toolAction == _PointAction) { switch (pointsFinished) { case 1: _Points[2] = _PointAction.Point; _HintLine?.Set(_Points[0], _PointAction.Point, _SketchEditorTool.Sketch.Plane); _ValueHudElement?.SetValue(_Points[0].Distance(_Points[2])); break; case 2: _Points[1] = _PointAction.Point; _Element?.OnPointsChanged(_Points, null); break; } _Coord2DHudElement?.SetValues(_PointAction.PointOnWorkingPlane.X, _PointAction.PointOnWorkingPlane.Y); } }
//-------------------------------------------------------------------------------------------------- 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 _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; } } }
//-------------------------------------------------------------------------------------------------- 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)); }