//--------------------------------------------------------------------------------------------------

        void _RestartAction()
        {
            _ComputeCoordinateSystem();

            if ((_TranslateAction != null) && !_TranslateAction.IsFinished)
            {
                _TranslateAction.Stop();
            }
            if ((_RotateAction != null) && !_RotateAction.IsFinished)
            {
                _RotateAction.Stop();
            }

            if (_Mode == Mode.Translate)
            {
                _TranslateAction = new TranslateAction(this, _CoordinateSystem);
                if (!WorkspaceController.StartToolAction(_TranslateAction, false))
                {
                    return;
                }
                StatusText = "Move body using gizmo, press 'CTRL' to round to grid stepping. Press 'T' for rotation.";
                _TranslateAction.Previewed += _OnActionPreview;
                _TranslateAction.Finished  += _OnActionFinished;
            }
            else if (_Mode == Mode.Rotate)
            {
                _RotateAction = new RotateAction(this, _CoordinateSystem);
                if (!WorkspaceController.StartToolAction(_RotateAction, false))
                {
                    return;
                }
                StatusText = "Rotate body using gizmo, press 'CTRL' to round to 5°. Press 'T' for translation.";
                _RotateAction.Previewed += _OnActionPreview;
                _RotateAction.Finished  += _OnActionFinished;
            }
            WorkspaceController.Invalidate();
        }
        //--------------------------------------------------------------------------------------------------

        public override bool Start()
        {
            var selectionFilters = new List <ISelectionFilter>();
            var allowedTypes     = SubshapeTypes.None;

            if (_Mode.HasFlag(AlignWorkingPlaneModes.AlignToFace))
            {
                allowedTypes |= SubshapeTypes.Face;
                selectionFilters.Add(new FaceSelectionFilter(FaceSelectionFilter.FaceType.Plane));
            }

            if (_Mode.HasFlag(AlignWorkingPlaneModes.AlignToEdge))
            {
                allowedTypes |= SubshapeTypes.Edge;
                selectionFilters.Add(new EdgeSelectionFilter(EdgeSelectionFilter.EdgeType.Any));
            }

            if (_Mode.HasFlag(AlignWorkingPlaneModes.AlignToVertex))
            {
                allowedTypes |= SubshapeTypes.Vertex;
                selectionFilters.Add(new VertexSelectionFilter(VertexSelectionFilter.VertexType.All));
            }

            var toolAction = new SelectSubshapeAction(this, allowedTypes, null,
                                                      selectionFilters.Count > 0 ? new OrSelectionFilter(selectionFilters.ToArray()) : null);

            if (!WorkspaceController.StartToolAction(toolAction))
            {
                return(false);
            }
            toolAction.Finished += _OnActionFinished;

            StatusText = "Select compnent to align to, or select X / Y / Z for default direction.";
            WorkspaceController.HudManager?.SetCursor(Cursors.WorkingPlane);

            return(true);
        }
예제 #3
0
        //--------------------------------------------------------------------------------------------------

        public SnapHandler(WorkspaceController workspaceController)
        {
            _WorkspaceController = workspaceController;
            _WorkspaceController.PropertyChanged += _WorkspaceController_PropertyChanged;
        }
예제 #4
0
파일: Editor.cs 프로젝트: Macad3D/Macad3D
 public abstract void Init(WorkspaceController workspaceController, Entity entity);
예제 #5
0
        //--------------------------------------------------------------------------------------------------

        void _OnActionFinished(ToolAction toolAction)
        {
            bool finished     = false;
            var  selectAction = toolAction as SelectSubshapeAction;

            Debug.Assert(selectAction != null);

            if (selectAction.SelectedEntity is DatumPlane plane)
            {
                WorkspaceController.Workspace.WorkingPlane = new Pln(plane.GetCoordinateSystem());
                finished = true;
            }
            else
            {
                switch (selectAction.SelectedSubshapeType)
                {
                case 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;
                    }

                    break;
                }

                case 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;
                    }

                    break;
                }

                case SubshapeTypes.Vertex:
                {
                    var vertex = TopoDS.Vertex(selectAction.SelectedSubshape);
                    WorkspaceController.Workspace.WorkingPlane = new Pln(BRep_Tool.Pnt(vertex), WorkspaceController.Workspace.WorkingPlane.Axis.Direction);
                    finished = true;
                    break;
                }
                }
            }

            if (finished)
            {
                selectAction.Stop();
                Stop();
            }
            else
            {
                selectAction.Reset();
            }

            WorkspaceController.Invalidate();
        }
예제 #6
0
        //--------------------------------------------------------------------------------------------------

        public virtual void Stop()
        {
            WorkspaceController.RemoveToolAction(this);
        }
예제 #7
0
        //--------------------------------------------------------------------------------------------------

        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));
        }