//-------------------------------------------------------------------------------------------------- public override bool Start() { _TargetBrep = _TargetShape.GetTransformedBRep(); if (_TargetBrep == null) { return(false); } if (_Mode == ToolMode.ReselectFace) { var visualShape = WorkspaceController.VisualShapes.GetVisualShape(_TargetBody); if (visualShape != null) { visualShape.OverrideBrep = _TargetBrep; WorkspaceController.Invalidate(); } } var toolAction = new SelectSubshapeAction(this, SubshapeTypes.Face, _TargetBody, new FaceSelectionFilter(FaceSelectionFilter.FaceType.Plane)); if (!WorkspaceController.StartToolAction(toolAction)) { return(false); } toolAction.Finished += _OnActionFinished; StatusText = "Select face to imprint."; WorkspaceController.HudManager?.SetCursor(Cursors.SelectFace); return(true); }
//-------------------------------------------------------------------------------------------------- public override bool Start() { _TargetBrep = _TargetShape.GetTransformedBRep(); if (_Mode == ToolMode.Reselect) { var visualShape = WorkspaceController.VisualObjects.Get(_TargetBody) as VisualShape; if (visualShape != null) { visualShape.OverrideBrep = _TargetBrep; WorkspaceController.Invalidate(); } } _Phase = Phase.Face; var toolAction = new SelectSubshapeAction(this, SubshapeTypes.Face, _TargetBody, new OrSelectionFilter(new FaceSelectionFilter(FaceSelectionFilter.FaceType.Plane), new FaceSelectionFilter(FaceSelectionFilter.FaceType.Cone), new FaceSelectionFilter(FaceSelectionFilter.FaceType.Cylinder))); if (!WorkspaceController.StartToolAction(toolAction)) { return(false); } toolAction.Previewed += _OnActionPreview; toolAction.Finished += _OnActionFinished; StatusText = "Select face to taper."; WorkspaceController.HudManager?.SetCursor(Cursors.SelectFace); return(true); }
//-------------------------------------------------------------------------------------------------- #endregion #region Selection void _OnSelectionChanged(ToolAction toolAction) { if (CurrentTool != null) { return; } if (_MoveAction != null) { _MoveAction.Stop(); _MoveAction = null; } _UpdateSelections(); if (SelectedSegments.Any() || SelectedPoints.Any()) { _MoveAction = new MoveSketchPointAction(this); if (!WorkspaceController.StartToolAction(_MoveAction, false)) { return; } _MoveAction.Previewed += _OnMoveActionPreview; _MoveAction.Finished += _OnMoveActionFinished; var segPoints = SelectedSegments.SelectMany(seg => seg.Points); _MoveAction.SetSketchElements(Sketch, SelectedPoints.Union(segPoints).ToList()); } WorkspaceController.Invalidate(); }
//-------------------------------------------------------------------------------------------------- public override bool Start() { if (!_Flags.HasFlag(Flags.ForceManualSelect) && UnfoldSheet.CanFindStartFace(_TargetBody.GetBRep())) { // Auto mode for start face can be used var unfoldSheet = UnfoldSheet.Create(_TargetBody); if (unfoldSheet != null) { ((Tool)this).Stop(); InteractiveContext.Current.UndoHandler.Commit(); InteractiveContext.Current.WorkspaceController.Selection.SelectEntity(_TargetBody); WorkspaceController.Invalidate(); return(false); } } var toolAction = new SelectSubshapeAction(this, SubshapeTypes.Face, _TargetBody, new FaceSelectionFilter(FaceSelectionFilter.FaceType.Plane)); if (!WorkspaceController.StartToolAction(toolAction)) { return(false); } toolAction.Finished += _OnActionFinished; StatusText = "Select start face for unfolding."; WorkspaceController.HudManager?.SetCursor(Cursors.SelectFace); return(true); }
//-------------------------------------------------------------------------------------------------- public override bool Start() { _ModifierShape.PropertyChanged += _ModifierShape_PropertyChanged; if (_ModifierShape.Operands.Count == 0) { return(false); } _Action = new ToggleSubshapesAction(this); if (!WorkspaceController.StartToolAction(_Action)) { return(false); } _Action.Finished += _OnActionFinished; if (!UpdateEdgesToTool()) { return(false); } StatusText = "Select edges to apply modifier on."; WorkspaceController.HudManager?.SetCursor(Cursors.SelectEdge); WorkspaceController.Invalidate(); return(true); }
//-------------------------------------------------------------------------------------------------- void _FinishPivotPoint(ToolAction toolAction) { if (!(toolAction is PointAction pointAction)) { return; } _ClearPreviews(); _Plane = WorkspaceController.Workspace.WorkingPlane; _PointPlane1 = pointAction.PointOnPlane; pointAction.Stop(); pointAction = new PointAction(this); pointAction.Previewed += _PreviewBaseRect; pointAction.Finished += _FinishBaseRect; if (!WorkspaceController.StartToolAction(pointAction)) { return; } _CurrentPhase = Phase.BaseRect; StatusText = "Select opposite corner point."; _MultiValueHudElement = WorkspaceController.HudManager?.CreateElement <MultiValueHudElement>(this); if (_MultiValueHudElement != null) { _MultiValueHudElement.Label1 = "Length:"; _MultiValueHudElement.Units1 = ValueUnits.Length; _MultiValueHudElement.Label2 = "Width:"; _MultiValueHudElement.Units2 = ValueUnits.Length; _MultiValueHudElement.MultiValueEntered += _MultiValueEntered; } }
//-------------------------------------------------------------------------------------------------- void _FinishBaseRect(ToolAction toolAction) { toolAction?.Stop(); var axisPosition = ElSLib.Value(_PointPlane2.X, _PointPlane2.Y, _Plane); var axisValueAction = new AxisValueAction(this, new Ax1(axisPosition, _Plane.Axis.Direction)); axisValueAction.Previewed += _PreviewHeight; axisValueAction.Finished += _FinishHeight; if (!WorkspaceController.StartToolAction(axisValueAction)) { return; } WorkspaceController.HudManager?.RemoveElement(_Coord2DHudElement); _CurrentPhase = Phase.Height; StatusText = "Select height."; WorkspaceController.HudManager?.RemoveElement(_MultiValueHudElement); _ValueHudElement = WorkspaceController.HudManager?.CreateElement <ValueHudElement>(this); if (_ValueHudElement != null) { _ValueHudElement.Label = "Height:"; _ValueHudElement.ValueEntered += _ValueEntered; _ValueHudElement.Units = ValueUnits.Length; } WorkspaceController.HudManager?.SetCursor(Cursors.SetHeight); _PreviewHeight(axisValueAction); }
//-------------------------------------------------------------------------------------------------- public override bool Start() { _SourceBody = WorkspaceController.Selection.SelectedEntities.First() as Body; if (WorkspaceController.Selection.SelectedEntities.Count > 1) { var shapeOperands = WorkspaceController.Selection.SelectedEntities .Skip(1) .OfType <Body>() .Select(body => (IShapeOperand) new BodyShapeOperand(body)) .ToArray(); Execute(_SourceBody, shapeOperands); Stop(); WorkspaceController.Invalidate(); return(false); } else { var toolAction = new SelectEntityAction <Body>(this); toolAction.SetFilter(body => body.Shape?.ShapeType == ShapeType.Solid); if (!WorkspaceController.StartToolAction(toolAction)) { return(false); } toolAction.Previewed += _OnActionPreview; toolAction.Finished += _OnActionFinished; toolAction.Exclude(_SourceBody); UpdateStatusText(null); WorkspaceController.HudManager?.SetCursor(Cursors.SelectShape); return(true); } }
//-------------------------------------------------------------------------------------------------- void _FinishPivotPoint(ToolAction toolAction) { if (!(toolAction is PointAction pointAction)) { return; } _Point = pointAction.Point.Round(); pointAction.Stop(); var axisValueAction = new AxisValueAction(this, new Ax1(_Point, Dir.DZ)); if (!WorkspaceController.StartToolAction(axisValueAction)) { return; } axisValueAction.Previewed += _PreviewRadius; axisValueAction.Finished += _FinishRadius; _CurrentPhase = Phase.Radius; StatusText = "Select Radius."; WorkspaceController.HudManager?.RemoveElement(_Coord2DHudElement); _ValueHudElement = WorkspaceController.HudManager?.CreateElement <ValueHudElement>(this); if (_ValueHudElement != null) { _ValueHudElement.Label = "Radius:"; _ValueHudElement.Units = ValueUnits.Length; _ValueHudElement.ValueEntered += _ValueEntered; } WorkspaceController.HudManager?.SetCursor(Cursors.SetRadius); }
//-------------------------------------------------------------------------------------------------- void _FinishPivotPoint(ToolAction toolAction) { if (!(toolAction is PointAction pointAction)) { return; } _Plane = WorkspaceController.Workspace.WorkingPlane; _PointPlane1 = pointAction.PointOnPlane; _PivotPoint = pointAction.Point; pointAction.Stop(); pointAction = new PointAction(this); if (!WorkspaceController.StartToolAction(pointAction)) { return; } pointAction.Previewed += _PreviewRadius; pointAction.Finished += _FinishRadius; _CurrentPhase = Phase.Radius; StatusText = "Select radius."; _ValueHudElement = WorkspaceController.HudManager?.CreateElement <ValueHudElement>(this); if (_ValueHudElement != null) { _ValueHudElement.Label = "Radius:"; _ValueHudElement.Units = ValueUnits.Length; _ValueHudElement.ValueEntered += _ValueEntered; } WorkspaceController.HudManager?.SetCursor(Cursors.SetRadius); }
//-------------------------------------------------------------------------------------------------- void _FinishRadius(ToolAction toolAction) { toolAction?.Stop(); var axisValueAction = new AxisValueAction(this, new Ax1(_PivotPoint.Round(), _Plane.Axis.Direction)); if (!WorkspaceController.StartToolAction(axisValueAction)) { return; } axisValueAction.Previewed += _PreviewHeight; axisValueAction.Finished += _FinishHeight; _CurrentPhase = Phase.Height; StatusText = "Select height."; if (_ValueHudElement != null) { _ValueHudElement.Label = "Height:"; _ValueHudElement.Value = 0; } WorkspaceController.HudManager?.RemoveElement(_Coord2DHudElement); WorkspaceController.HudManager?.SetCursor(Cursors.SetHeight); _PreviewHeight(axisValueAction); }
//-------------------------------------------------------------------------------------------------- void _OnFaceSelected(SelectSubshapeAction selectAction) { if (selectAction.SelectedSubshapeType == SubshapeTypes.Face) { var face = TopoDS.Face(selectAction.SelectedSubshape); var brepAdaptor = new BRepAdaptor_Surface(face, true); if (brepAdaptor.GetGeomType() != GeomAbs_SurfaceType.GeomAbs_Plane && brepAdaptor.GetGeomType() != GeomAbs_SurfaceType.GeomAbs_Cylinder && brepAdaptor.GetGeomType() != GeomAbs_SurfaceType.GeomAbs_Cone) { StatusText = "Selected face is not a plane, cylinder or cone type surface."; selectAction.Reset(); return; } selectAction.Stop(); _TargetFace = face; _Phase = Phase.BaseEdgeOrVertex; _SubshapesOfFace = new List <TopoDS_Shape>(); var edges = face.Edges().Where( edge => { var analysis = new ShapeAnalysis_Edge(); return(!analysis.IsSeam(edge, face)); }).ToList(); _SubshapesOfFace.AddRange(edges); var vertices = face.Vertices().Where( vertex => { var vertexEdges = edges.Where(edge => edge.Vertices().ContainsSame(vertex)); return(vertexEdges.Count() > 1); }); _SubshapesOfFace.AddRange(vertices); var newAction = new SelectSubshapeAction(this, _SubshapesOfFace); if (!WorkspaceController.StartToolAction(newAction)) { Stop(); return; } newAction.Previewed += _OnActionPreview; newAction.Finished += _OnActionFinished; StatusText = "Select base edge or vertex to define direction of taper."; WorkspaceController.HudManager?.SetCursor(Cursors.SelectEdge); } }
//-------------------------------------------------------------------------------------------------- bool _StartToolAction() { var toolAction = new SelectEntityAction <Body>(this); toolAction.SetFilter((body) => body.Shape.ShapeType == ShapeType.Sketch); if (!WorkspaceController.StartToolAction(toolAction)) { return(false); } toolAction.Finished += _OnActionFinished; toolAction.Exclude(_TargetBody); return(true); }
//-------------------------------------------------------------------------------------------------- public void ToggleFaceSelection() { if (_SelectFaceAction != null) { _SelectFaceAction.Cancel(true); _SelectFaceAction = null; StatusText = ""; WorkspaceController.HudManager?.SetCursor(null); RaisePropertyChanged(nameof(IsSelectingFace)); if (_Component == null) { // No face, no component Stop(); } else { _UpdateReconstructed(); WorkspaceController.Invalidate(); } } else { _ShapeForFaceSelection = _Component?.GetShape() ?? _Body.Shape; var selectionBRep = _ShapeForFaceSelection.GetTransformedBRep(); if (selectionBRep == null) { return; } var visObject = WorkspaceController.VisualObjects.Get(_Body, true) as VisualShape; if (visObject == null) { return; } visObject.OverrideBrep = selectionBRep; _SelectFaceAction = new SelectSubshapeAction(this, SubshapeTypes.Face, _Body, new FaceSelectionFilter(FaceSelectionFilter.FaceType.Plane)); if (!WorkspaceController.StartToolAction(_SelectFaceAction)) { _SelectFaceAction = null; return; } _SelectFaceAction.Finished += _SelectFaceAction_OnFinished; StatusText = "Select plane base face."; WorkspaceController.HudManager?.SetCursor(Cursors.SelectFace); } RaisePropertyChanged(nameof(IsSelectingFace)); }
//-------------------------------------------------------------------------------------------------- public override bool Start() { InteractiveContext.Current.WorkspaceController.Selection.SelectEntity(null, true); var pointAction = new PointAction(this); if (!WorkspaceController.StartToolAction(pointAction)) { return(false); } pointAction.Previewed += _PreviewPivot; pointAction.Finished += _FinishPivotPoint; _CurrentPhase = Phase.PivotPoint; StatusText = "Select corner point."; _Coord2DHudElement = WorkspaceController.HudManager?.CreateElement <Coord2DHudElement>(this); WorkspaceController.HudManager?.SetCursor(Cursors.SetPoint); return(true); }
//-------------------------------------------------------------------------------------------------- public override bool Start() { if (_Mode == ToolMode.Reselect) { var visualShape = WorkspaceController.VisualObjects.Get(_TargetBody) as VisualShape; if (visualShape != null) { visualShape.OverrideBrep = _TargetShape.GetTransformedBRep(); WorkspaceController.Invalidate(); } } SelectSubshapeAction toolAction; switch (_TargetShape.ShapeType) { case ShapeType.Sketch: toolAction = new SelectSubshapeAction(this, SubshapeTypes.Edge, _TargetBody); StatusText = "Select edge as reference for the mirror axis."; WorkspaceController.HudManager?.SetCursor(Cursors.SelectEdge); break; case ShapeType.Solid: toolAction = new SelectSubshapeAction(this, SubshapeTypes.Face, _TargetBody); StatusText = "Select face as reference for the mirror plane."; WorkspaceController.HudManager?.SetCursor(Cursors.SelectFace); break; default: Messages.Error("MultiplyMirror works only on sketch or solid."); return(false); } if (!WorkspaceController.StartToolAction(toolAction)) { return(false); } toolAction.Finished += _OnActionFinished; return(true); }
//-------------------------------------------------------------------------------------------------- public override bool Start() { InteractiveContext.Current.WorkspaceController.Selection.SelectEntity(null, true); if (_InitialCreateMode == CreateMode.Interactive) { var selectionFilter = new OrSelectionFilter(new FaceSelectionFilter(FaceSelectionFilter.FaceType.Plane), new SignatureSelectionFilter(VisualPlane.SelectionSignature)); var toolAction = new SelectSubshapeAction(this, SubshapeTypes.Face, null, selectionFilter); if (!WorkspaceController.StartToolAction(toolAction)) { return(false); } toolAction.Finished += _OnActionFinished; StatusText = "Select face to which the new sketch should be aligned."; WorkspaceController.HudManager?.SetCursor(Cursors.SelectFace); return(true); } switch (_InitialCreateMode) { case CreateMode.WorkplaneXY: _Plane = InteractiveContext.Current.Workspace.WorkingPlane; break; case CreateMode.WorkplaneXZ: _Plane = new Pln(InteractiveContext.Current.Workspace.WorkingPlane.Location, InteractiveContext.Current.Workspace.WorkingPlane.YAxis.Direction.Reversed()); break; case CreateMode.WorkplaneYZ: _Plane = new Pln(InteractiveContext.Current.Workspace.WorkingPlane.Location, InteractiveContext.Current.Workspace.WorkingPlane.XAxis.Direction.Reversed()); break; } Stop(); CreateSketch(); return(false); }
//-------------------------------------------------------------------------------------------------- public override bool Start() { if (_TargetShape.ShapeType == ShapeType.Sketch) { var modifierShape = Extrude.Create(_TargetBody); if (modifierShape != null) { InteractiveContext.Current.UndoHandler.Commit(); } InteractiveContext.Current.WorkspaceController.Invalidate(); Stop(); return(false); } else { if (_Mode == ToolMode.ReselectFace) { var visualShape = WorkspaceController.VisualShapes.GetVisualShape(_TargetBody); if (visualShape != null) { visualShape.OverrideBrep = _TargetShape.GetTransformedBRep(); WorkspaceController.Invalidate(); } } var toolAction = new SelectSubshapeAction(this, SubshapeTypes.Face, _TargetBody); if (!WorkspaceController.StartToolAction(toolAction)) { return(false); } toolAction.Finished += _OnActionFinished; StatusText = "Select face to extrude."; WorkspaceController.HudManager?.SetCursor(Cursors.SelectFace); return(true); } }
//-------------------------------------------------------------------------------------------------- public override bool Start() { if (_TargetBody2 != null) { var boxJoint = BoxJoint.Create(_TargetBody1, _TargetBody2); InteractiveContext.Current.UndoHandler.Commit(); Stop(); WorkspaceController.Invalidate(); return(false); } var toolAction = new SelectEntityAction <Body>(this); if (!WorkspaceController.StartToolAction(toolAction)) { return(false); } toolAction.Previewed += _OnActionPreview; toolAction.Finished += _OnActionFinished; toolAction.Exclude(_TargetBody1); UpdateStatusText(null); WorkspaceController.HudManager?.SetCursor(Cursors.SelectShape); return(true); }
//-------------------------------------------------------------------------------------------------- public override bool Start() { _SelectionContext = WorkspaceController.Selection.OpenContext(SelectionContext.Options.NewSelectedList); var workspace = WorkspaceController.Workspace; var editorSettings = SketchEditorSettingsCache.GetOrCreate(Sketch); if (editorSettings.WorkingContext == null) { editorSettings.WorkingContext = workspace.WorkingContext.Clone(); } workspace.WorkingContext = editorSettings.WorkingContext; WorkspaceController.LockWorkingPlane = true; workspace.WorkingPlane = Sketch.Plane; var vc = WorkspaceController.ActiveViewControlller; _SavedViewParameters = vc.Viewport.GetViewParameters(); vc.LockedToPlane = true; if (editorSettings.ViewParameters != null) { vc.Viewport.RestoreViewParameters(editorSettings.ViewParameters); // Update direction var twist = vc.Viewport.Twist; vc.SetPredefinedView(ViewportController.PredefinedViews.WorkingPlane); vc.Viewport.Twist = twist; } else { _CenterView(); RotateView(0); } vc.Viewport.PropertyChanged += _Viewport_PropertyChanged; EnableClipPlane(editorSettings.ClipPlaneEnabled); if (Sketch.IsVisible) { var visualSketchShape = WorkspaceController.VisualShapes.GetVisualShape(Sketch.Body, true); if (visualSketchShape != null) { visualSketchShape.IsHidden = true; } } _LastGizmoScale = WorkspaceController.ActiveViewport.GizmoScale; _TempPoints = new Dictionary <int, Pnt2d>(Sketch.Points); Transform = Sketch.GetTransformation(); Elements.InitElements(_TempPoints); _UpdateSelections(); Sketch.ElementsChanged += _Sketch_ElementsChanged; _SelectAction = new SelectSketchElementAction(this); if (!WorkspaceController.StartToolAction(_SelectAction)) { return(false); } _SelectAction.Finished += _OnSelectionChanged; StatusText = UnselectedStatusText; return(true); }