Beispiel #1
0
        //--------------------------------------------------------------------------------------------------

        public override bool OnMouseUp(MouseEventData data, bool shiftSelected)
        {
            if (_MoveMode != MoveMode.None)
            {
                _MoveMode = MoveMode.None;
                WorkspaceController.HudManager?.SetCursor(null);

                _AxisHintLine?.Remove();

                WorkspaceController.HudManager?.RemoveElement(_Coord3dHudElement);
                _Coord3dHudElement = null;
                WorkspaceController.HudManager?.RemoveElement(_Delta3DHudElement);
                _Delta3DHudElement = null;

                if (_Delta.SquareMagnitude() > 0)
                {
                    // Commit
                    Stop();
                    IsFinished = true;
                }

                WorkspaceController.Invalidate();
                return(true);
            }
            return(base.OnMouseUp(data, shiftSelected));
        }
Beispiel #2
0
        //--------------------------------------------------------------------------------------------------

        void UpdateMergeMarker()
        {
            if (MergeCandidateIndex >= 0)
            {
                var geomPoint = new Geom_CartesianPoint(_MergeCandidatePoint.X, _MergeCandidatePoint.Y, 0);
                geomPoint.Transform(_SketchEditorTool.Transform);
                if (_MergePreviewMarker == null)
                {
                    _MergePreviewMarker = new Marker(WorkspaceController, Marker.Styles.Bitmap | Marker.Styles.Topmost, Marker.RingImage);
                    _MergePreviewMarker.Set(geomPoint);
                    _MergePreviewMarker.SetColor(Colors.Highlight);
                }
                else
                {
                    _MergePreviewMarker.Set(geomPoint);
                }
            }
            else
            {
                if (_MergePreviewMarker != null)
                {
                    _MergePreviewMarker.Remove();
                    _MergePreviewMarker = null;
                }
            }

            WorkspaceController.Invalidate();
        }
Beispiel #3
0
        //--------------------------------------------------------------------------------------------------

        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));
        }
Beispiel #4
0
        //--------------------------------------------------------------------------------------------------

        public override bool OnMouseMove(MouseEventData data)
        {
            if (!IsFinished)
            {
                ProcessMouseInput(data);

                if (_MarkerType != SelectedElementType)
                {
                    _Marker?.Remove();
                    _Marker     = null;
                    _MarkerType = Sketch.ElementType.None;
                }

                if (SelectedElementType != Sketch.ElementType.None)
                {
                    if (_Marker == null)
                    {
                        _Marker = new Marker(WorkspaceController, Marker.Styles.Bitmap | Marker.Styles.Topmost,
                                             SelectedElementType == Sketch.ElementType.Segment ? Marker.XImage : Marker.RingImage);
                        _Marker.SetColor(Colors.SketchEditorHighlight);
                        _MarkerType = SelectedElementType;
                    }
                    _Marker.Set(_SelectedPoint);
                }

                WorkspaceController.Invalidate();

                return(base.OnMouseMove(data));
            }
            return(false);
        }
        //--------------------------------------------------------------------------------------------------

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

        public override void Stop()
        {
            _HintLine.Remove();

            WorkspaceController.Selection.CloseContext(_SelectionContext);
            _SelectionContext = null;
            WorkspaceController.Invalidate();

            base.Stop();
        }
Beispiel #7
0
        //--------------------------------------------------------------------------------------------------

        public override void Stop()
        {
            if (_OverriddenVisualShape != null)
            {
                _OverriddenVisualShape.OverrideBrep = null;
                WorkspaceController.Invalidate();
                _OverriddenVisualShape = null;
            }
            base.Stop();
        }
        //--------------------------------------------------------------------------------------------------

        public override bool OnMouseUp(MouseEventData data, bool shiftSelected)
        {
            if (!IsFinished)
            {
                ProcessMouseInput(data);
                WorkspaceController.Invalidate();
                IsFinished = true;
            }
            return(true);
        }
        //--------------------------------------------------------------------------------------------------

        public override bool OnMouseMove(MouseEventData data)
        {
            if (!IsFinished)
            {
                if (_ProcessMouseInput(data))
                {
                    WorkspaceController.Invalidate();
                    return(base.OnMouseMove(data));
                }
            }
            return(false);
        }
        //--------------------------------------------------------------------------------------------------

        void _UpdateTransformations(Trsf?transformation)
        {
            var bodyList = _Options.Has(Options.LinkForeignOperands) ? _TargetAndLinkedBodies : _TargetBodies;

            foreach (var targetBody in bodyList)
            {
                var visualShape = WorkspaceController.VisualShapes.GetVisualShape(targetBody);
                if (visualShape != null)
                {
                    visualShape.SetLocalTransformation(transformation);
                    WorkspaceController.Invalidate();
                }
            }
        }
Beispiel #11
0
        //--------------------------------------------------------------------------------------------------

        public override void Stop()
        {
            if (_Marker != null)
            {
                _Marker.Remove();
                _Marker = null;
            }

            WorkspaceController.Selection.CloseContext(_SelectionContext);
            _SelectionContext = null;

            WorkspaceController.Invalidate();

            base.Stop();
        }
        //--------------------------------------------------------------------------------------------------

        public override void Stop()
        {
            if (_Marker != null)
            {
                WorkspaceController.Workspace.AisContext.Remove(_Marker, false);
                _Marker = null;
            }

            _HintLine?.Remove();

            WorkspaceController.Selection.CloseContext(_SelectionContext);
            _SelectionContext = null;
            WorkspaceController.Invalidate();

            base.Stop();
        }
Beispiel #13
0
        //--------------------------------------------------------------------------------------------------

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

        public override bool OnMouseMove(MouseEventData data)
        {
            if (!IsFinished)
            {
                EnsureMarker();

                ProcessMouseInput(data);

                _Marker.SetComponent(new Geom_CartesianPoint(Point));
                WorkspaceController.Workspace.AisContext.RecomputePrsOnly(_Marker, false);

                WorkspaceController.Invalidate();

                return(base.OnMouseMove(data));
            }
            return(false);
        }
Beispiel #15
0
        //--------------------------------------------------------------------------------------------------

        public override bool OnMouseMove(MouseEventData data)
        {
            if (!IsFinished)
            {
                EnsureMarker();

                ProcessMouseInput(data);

                _Marker.SetComponent(new Geom_CartesianPoint(ElSLib.Value(Point.X, Point.Y, _SketchEditorTool.Sketch.Plane)));
                WorkspaceController.Workspace.AisContext.RecomputePrsOnly(_Marker, false);
                WorkspaceController.Invalidate();

                UpdateMergeMarker();

                return(base.OnMouseMove(data));
            }
            return(false);
        }
Beispiel #16
0
        //--------------------------------------------------------------------------------------------------

        public override bool Start()
        {
            if (_TargetShape != _TargetBody?.Shape)
            {
                _OverriddenVisualShape = WorkspaceController.VisualShapes.GetVisualShape(_TargetBody);
                if (_OverriddenVisualShape != null)
                {
                    _OverriddenVisualShape.OverrideBrep = _TargetShape.GetTransformedBRep();
                    WorkspaceController.Invalidate();
                }
            }

            var toolAction = new SelectSubshapeAction(this, SubshapeTypeHelper.GetTypes(_SubshapeType), _TargetBody, _SelectionFilter);

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

            StatusText = _StatusText;

            switch (_SubshapeType)
            {
            case SubshapeType.Vertex:
                WorkspaceController.HudManager?.SetCursor(Cursors.SelectVertex);
                break;

            case SubshapeType.Edge:
                WorkspaceController.HudManager?.SetCursor(Cursors.SelectEdge);
                break;

            case SubshapeType.Wire:
                WorkspaceController.HudManager?.SetCursor(Cursors.SelectWire);
                break;

            case SubshapeType.Face:
                WorkspaceController.HudManager?.SetCursor(Cursors.SelectFace);
                break;
            }
            return(true);
        }
Beispiel #17
0
        //--------------------------------------------------------------------------------------------------

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

        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();
        }
Beispiel #19
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));
        }