//-------------------------------------------------------------------------------------------------- public bool StartToolAction(ToolAction toolAction, bool exclusive = true) { try { if (exclusive) { while (_ToolActions.Any()) { if (!(CurrentToolAction.IsFinished || CurrentToolAction.Cancel(true))) { Debug.WriteLine("StartToolAction -> CurrentToolAction.Cancel() denied."); return(false); } } } if (toolAction != null) { Console.WriteLine("Starting tool action " + toolAction.GetType().Name); toolAction.WorkspaceController = this; if (!toolAction.Start()) { return(false); } _ToolActions.Insert(0, toolAction); RaisePropertyChanged(nameof(CurrentToolAction)); } return(true); } catch (Exception e) { Console.WriteLine(e); return(false); } }
//-------------------------------------------------------------------------------------------------- void _OnActionFinished(ToolAction toolAction) { _UpdatingBodyProperties = true; var bodyList = _Options.Has(Options.LinkForeignOperands) ? _TargetAndLinkedBodies : _TargetBodies; if (toolAction == _TranslateAction) { foreach (var targetBody in bodyList) { targetBody.Translate(_TranslateAction.Delta); } } else if (toolAction == _RotateAction) { foreach (var targetBody in bodyList) { targetBody.Rotate(_RotateAction.RotationAxis, _RotateAction.Delta); } } InteractiveContext.Current.UndoHandler.Commit(); _UpdateTransformations(null); // Restart _RestartAction(); _UpdatingBodyProperties = false; }
//-------------------------------------------------------------------------------------------------- public void RemoveToolAction(ToolAction toolAction) { if (_ToolActions.Contains(toolAction)) { _ToolActions.Remove(toolAction); RaisePropertyChanged(nameof(CurrentToolAction)); } }
//-------------------------------------------------------------------------------------------------- void _OnActionFinished(ToolAction toolAction) { bool finished = false; var selectAction = toolAction as SelectSubshapeAction; Debug.Assert(selectAction != null); 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) { StatusText = "Selected face is not a plane type surface."; } else { double centerU = brepAdaptor.FirstUParameter() + (brepAdaptor.LastUParameter() - brepAdaptor.FirstUParameter()) / 2; double centerV = brepAdaptor.FirstVParameter() + (brepAdaptor.LastVParameter() - brepAdaptor.FirstVParameter()) / 2; var centerPnt = brepAdaptor.Value(centerU, centerV); WorkspaceController.Workspace.WorkingPlane = new Pln(centerPnt, brepAdaptor.Plane().Axis.Direction); finished = true; } } else if (selectAction.SelectedSubshapeType == SubshapeTypes.Edge) { var edge = TopoDS.Edge(selectAction.SelectedSubshape); double firstParam = 0, lastParam = 0; var curve = BRep_Tool.Curve(edge, ref firstParam, ref lastParam); if (curve != null) { var midpoint = curve.Value(firstParam + (lastParam - firstParam) / 2); WorkspaceController.Workspace.WorkingPlane = new Pln(midpoint, WorkspaceController.Workspace.WorkingPlane.Axis.Direction); finished = true; } } else if (selectAction.SelectedSubshapeType == SubshapeTypes.Vertex) { var vertex = TopoDS.Vertex(selectAction.SelectedSubshape); WorkspaceController.Workspace.WorkingPlane = new Pln(BRep_Tool.Pnt(vertex), WorkspaceController.Workspace.WorkingPlane.Axis.Direction); finished = true; } if (finished) { selectAction.Stop(); Stop(); } else { selectAction.Reset(); } WorkspaceController.Invalidate(); }
//-------------------------------------------------------------------------------------------------- void _OnActionPreview(ToolAction toolAction) { if (toolAction == _TranslateAction) { var transformation = new Trsf(_TranslateAction.Delta); _UpdateTransformations(transformation); } else if (toolAction == _RotateAction) { var transformation = new Trsf(_RotateAction.RotationAxis, _RotateAction.Delta); _UpdateTransformations(transformation); } }
//-------------------------------------------------------------------------------------------------- void _OnActionFinished(ToolAction toolAction) { bool finished = false; var selectAction = toolAction as SelectSubshapeAction; Debug.Assert(selectAction != null); 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) { StatusText = "Selected face is not a plane type surface."; } finished = true; } if (finished) { var subshapeReference = _TargetShape.GetSubshapeReference(_TargetShape.GetTransformedBRep(), selectAction.SelectedSubshape); selectAction.Stop(); Stop(); if (subshapeReference == null) { Messages.Error("A subshape reference could not be produced for this subshape."); return; } _SelectedFunc.Invoke(subshapeReference); } else { selectAction.Reset(); } WorkspaceController.Invalidate(); }