Exemplo n.º 1
0
        //--------------------------------------------------------------------------------------------------

        double?_ProcessMouseInputForAxis(MouseEventData data)
        {
            var planeDir = WorkspaceController.ActiveViewport.GetRightDirection();

            if (planeDir.IsParallel(_MoveAxis.Direction, 0.1))
            {
                planeDir = WorkspaceController.ActiveViewport.GetUpDirection();
            }
            planeDir.Cross(_MoveAxis.Direction);
            //Console.WriteLine("PlaneDir: {0:0.00} | {1:0.00} | {2:0.00}", planeDir.X(), planeDir.Y(), planeDir.Z());
            var plane = new Pln(new Ax3(_MoveAxis.Location, planeDir, _MoveAxis.Direction));

            Pnt convertedPoint;

            if (WorkspaceController.ActiveViewport.ScreenToPoint(plane, Convert.ToInt32(data.ScreenPoint.X), Convert.ToInt32(data.ScreenPoint.Y), out convertedPoint))
            {
                var extrema = new Extrema_ExtPC(convertedPoint, new GeomAdaptor_Curve(new Geom_Line(_MoveAxis)), 1.0e-10);
                if (extrema.IsDone() && extrema.NbExt() >= 1)
                {
                    var value = extrema.Point(1).Parameter();
                    return(value);
                }
            }
            return(null);
        }
Exemplo n.º 2
0
        //--------------------------------------------------------------------------------------------------

        void ProcessMouseInput(MouseEventData data)
        {
            if (data.DetectedEntities.Count == 1)
            {
                SelectedEntity = data.DetectedEntities[0] as T;
            }
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        //--------------------------------------------------------------------------------------------------

        public override bool OnMouseUp(MouseEventData data, bool shiftSelected)
        {
            if (_Moving)
            {
                _Moving = false;

                if (MoveDelta != Vec2d.Zero)
                {
                    // Commit
                    RaiseFinished();
                    MoveDelta = Vec2d.Zero;

                    // Set new center
                    UpdateTrihedron();
                }

                WorkspaceController.HudManager?.RemoveElement(_Coord2DHudElement);
                _Coord2DHudElement = null;
                WorkspaceController.HudManager?.RemoveElement(_Delta2DHudElement);
                _Coord2DHudElement = null;

                _MergePreviewMarkers.ForEach(m => m.Remove());
                _MergePreviewMarkers.Clear();

                return(true);
            }
            return(base.OnMouseUp(data, shiftSelected));
        }
Exemplo n.º 5
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));
        }
Exemplo n.º 6
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));
        }
Exemplo n.º 7
0
        //--------------------------------------------------------------------------------------------------

        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();
            }
        }
Exemplo n.º 8
0
        //--------------------------------------------------------------------------------------------------

        public override bool OnMouseDown(MouseEventData data)
        {
            if (data.DetectedEntities.Count == 0)
            {
                double u = 0, v = 0;
                if (Gizmo.IsPartDetected(AIS_TranslationGizmo2D.Part.Part_Plane))
                {
                    _MoveConstraintX = false;
                    _MoveConstraintY = false;
                    _Moving          = true;
                }
                else if (Gizmo.IsPartDetected(AIS_TranslationGizmo2D.Part.Part_XAxis))
                {
                    _MoveConstraintX = false;
                    _MoveConstraintY = true;
                    _Moving          = true;
                }
                else if (Gizmo.IsPartDetected(AIS_TranslationGizmo2D.Part.Part_YAxis))
                {
                    _MoveConstraintX = true;
                    _MoveConstraintY = false;
                    _Moving          = true;
                }
                if (_Moving)
                {
                    ElSLib.Parameters(_Sketch.Plane, data.PointOnPlane, ref u, ref v);
                    _MoveStartPoint = new Pnt2d(u, v);
                    return(true);
                }
            }
            return(base.OnMouseDown(data));
        }
        //--------------------------------------------------------------------------------------------------

        public override bool OnMouseUp(MouseEventData data, bool shiftSelected)
        {
            if (!IsFinished)
            {
                _ProcessMouseSelect(data);
            }
            return(true);
        }
Exemplo n.º 10
0
        //--------------------------------------------------------------------------------------------------

        public override bool OnMouseMove(MouseEventData data)
        {
            if (!IsFinished)
            {
                return(base.OnMouseMove(data));
            }
            return(false);
        }
Exemplo n.º 11
0
        //--------------------------------------------------------------------------------------------------

        public override bool OnMouseMove(MouseEventData data)
        {
            if (_Moving)
            {
                // Get new point from parameters
                double u = 0, v = 0;
                ElSLib.Parameters(_Sketch.Plane, data.PointOnPlane, ref u, ref v);
                var newPoint = new Pnt2d(u, v);

                // Calc delta
                MoveDelta = new Vec2d(newPoint.Coord.Subtracted(_MoveStartPoint.Coord));

                // Apply constraints
                ApplyConstraints();
                Snap();
                ApplyConstraints();

                // Calc new 3D center
                var newPos3D = ElSLib.Value(_Center2D.X + MoveDelta.X, _Center2D.Y + MoveDelta.Y, _Sketch.Plane);
                _GizmoPlane.SetLocation(newPos3D);
                Gizmo.SetComponent(_GizmoPlane);

                // Check for point merge candidates
                _MergePreviewMarkers.ForEach(m => m.Remove());
                _MergePreviewMarkers.Clear();
                foreach (var candidate in CheckMergePoints(MoveDelta))
                {
                    var point     = _Sketch.Points[candidate.Value];
                    var geomPoint = new Geom_CartesianPoint(point.X, point.Y, 0);
                    geomPoint.Transform(_Sketch.GetTransformation());
                    var marker = new Marker(WorkspaceController, Marker.Styles.Bitmap | Marker.Styles.Topmost, Marker.RingImage);
                    marker.Set(geomPoint);
                    marker.SetColor(Colors.Highlight);
                    _MergePreviewMarkers.Add(marker);
                }

                data.ForceReDetection = true;

                if (_Coord2DHudElement == null)
                {
                    _Coord2DHudElement = WorkspaceController.HudManager?.CreateElement <Coord2DHudElement>(this);
                    _Delta2DHudElement = WorkspaceController.HudManager?.CreateElement <Delta2DHudElement>(this);
                }
                if (_Coord2DHudElement != null)
                {
                    _Coord2DHudElement.CoordinateX = _Center2D.X + MoveDelta.X;
                    _Coord2DHudElement.CoordinateY = _Center2D.Y + MoveDelta.Y;
                }
                if (_Delta2DHudElement != null)
                {
                    _Delta2DHudElement.DeltaX = MoveDelta.X;
                    _Delta2DHudElement.DeltaY = MoveDelta.Y;
                }
            }

            return(base.OnMouseMove(data));
        }
Exemplo n.º 12
0
        //--------------------------------------------------------------------------------------------------

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

        void ProcessMouseInput(MouseEventData data)
        {
            // Get new point from parameters
            double u = 0, v = 0;

            ElSLib.Parameters(_SketchEditorTool.Sketch.Plane, data.PointOnPlane, ref u, ref v);
            var sketchPoint = new Pnt2d(u, v);

            Point = Snap(sketchPoint);
        }
Exemplo n.º 14
0
        //--------------------------------------------------------------------------------------------------

        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);
        }
Exemplo n.º 16
0
        //--------------------------------------------------------------------------------------------------

        public override bool OnMouseUp(MouseEventData data, bool shiftSelected)
        {
            if (!IsFinished)
            {
                ProcessMouseInput(data);

                if (MergeCandidateIndex >= 0)
                {
                    Point = _SketchEditorTool.Sketch.Points[MergeCandidateIndex];
                }
                IsFinished = true;
            }
            return(true);
        }
        //--------------------------------------------------------------------------------------------------

        public override bool OnMouseDown(MouseEventData data)
        {
            if (data.DetectedAisInteractives.Count == 0 ||
                data.DetectedEntities.Count > 0 && !_TargetBodies.ContainsAny(data.DetectedEntities))
            {
                // Selection of another shape clicking into "nothing" closes the tool
                if ((_TranslateAction == null || !_TranslateAction.IsMoving) &&
                    (_RotateAction == null || !_RotateAction.IsRotating))
                {
                    Stop();
                    return(true);
                }
            }
            return(base.OnMouseDown(data));
        }
        //--------------------------------------------------------------------------------------------------

        void _ProcessMouseSelect(MouseEventData data)
        {
            foreach (var detectedShape in data.DetectedShapes)
            {
                var subshape = Subshapes.FirstOrDefault(sh => sh.Shape.IsEqual(detectedShape));
                if (subshape != null)
                {
                    subshape.IsSelected = !subshape.IsSelected;
                    subshape.AisShape.SetColor(subshape.IsSelected ? Quantity_NameOfColor.Quantity_NOC_RED.ToColor() : Quantity_NameOfColor.Quantity_NOC_BLUE1.ToColor());
                    ChangedSubshape = subshape;
                    RaiseFinished();
                    break;
                }
            }
        }
        //--------------------------------------------------------------------------------------------------

        bool _ProcessMouseInput(MouseEventData data)
        {
            bool anyResult = false;

            double distance;
            double?value = _ProcessMouseInputForAxis(data, out distance);

            if (value.HasValue)
            {
                Value     = value.Value;
                Distance  = distance;
                anyResult = true;
            }

            return(anyResult);
        }
Exemplo n.º 20
0
        //--------------------------------------------------------------------------------------------------

        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);
        }
Exemplo n.º 21
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));
        }
Exemplo n.º 22
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);
        }
Exemplo n.º 23
0
        //--------------------------------------------------------------------------------------------------

        public override bool OnMouseUp(MouseEventData data, bool shiftSelected)
        {
            if (!IsFinished)
            {
                if (!shiftSelected)
                {
                    _SketchEditorTool.Elements.DeselectAll();
                }

                foreach (var detectedObject in data.DetectedAisInteractives)
                {
                    _SketchEditorTool.Elements.Select(detectedObject);
                }

                RaiseFinished();
            }
            return(true);
        }
Exemplo n.º 24
0
        //--------------------------------------------------------------------------------------------------

        void ProcessMouseInput(MouseEventData data)
        {
            // Get new point from parameters
            double u = 0, v = 0;

            ElSLib.Parameters(_SketchEditorTool.Sketch.Plane, data.PointOnPlane, ref u, ref v);
            var sketchPoint = new Pnt2d(u, v);

            Point = Snap(sketchPoint);

            // Recalculate point on working plane
            if (_SketchEditorTool.Sketch.Plane.Location.IsEqual(WorkspaceController.Workspace.WorkingPlane.Location, 0.00001))
            {
                PointOnWorkingPlane = Point;
            }
            else
            {
                ElSLib.Parameters(WorkspaceController.Workspace.WorkingPlane, _SketchEditorTool.Sketch.Plane.Location, ref u, ref v);
                PointOnWorkingPlane = Point.Translated(new Vec2d(u, v));
            }
        }
        //--------------------------------------------------------------------------------------------------

        double?_ProcessMouseInputForAxis(MouseEventData data, out double distance)
        {
            var planeDir = WorkspaceController.ActiveViewport.GetRightDirection();

            planeDir.Cross(_Axis.Direction);
            //Console.WriteLine("PlaneDir: {0:0.00} | {1:0.00} | {2:0.00}", planeDir.X(), planeDir.Y(), planeDir.Z());
            var plane = new Pln(new Ax3(_Axis.Location, planeDir, _Axis.Direction));

            var snapInfo  = WorkspaceController.SnapHandler.Snap(data);
            var snapPoint = WorkspaceController.SnapHandler.SnapOnPlane(snapInfo, plane);

            if (snapPoint != null)
            {
                // Point snapped
                var extrema = new Extrema_ExtPC(ElSLib.Value(snapPoint.Value.X, snapPoint.Value.Y, plane), new GeomAdaptor_Curve(new Geom_Line(_Axis)), 1.0e-10);
                if (extrema.IsDone() && extrema.NbExt() >= 1)
                {
                    var value = extrema.Point(1).Parameter();
                    distance = snapInfo.Point.Distance(_Axis.Location);
                    return(value);
                }
            }
            else
            {
                Pnt convertedPoint;
                if (WorkspaceController.ActiveViewport.ScreenToPoint(plane, Convert.ToInt32(data.ScreenPoint.X), Convert.ToInt32(data.ScreenPoint.Y), out convertedPoint))
                {
                    var extrema = new Extrema_ExtPC(convertedPoint, new GeomAdaptor_Curve(new Geom_Line(_Axis)), 1.0e-10);
                    if (extrema.IsDone() && extrema.NbExt() >= 1)
                    {
                        var value = extrema.Point(1).Parameter();
                        distance = convertedPoint.Distance(_Axis.Location);
                        return(value);
                    }
                }
            }
            distance = 0;
            return(null);
        }
Exemplo n.º 26
0
        //--------------------------------------------------------------------------------------------------

        void ProcessMouseInput(MouseEventData data)
        {
            SelectedEntity = data.DetectedEntities.FirstOrDefault();

            if (data.DetectedShapes.Count == 0)
            {
                SelectedSubshape     = null;
                SelectedSubshapeType = SubshapeTypes.None;
                return;
            }

            var detectedShape = data.DetectedShapes[0];

            if (_SubshapeTypes.HasFlag(SubshapeTypes.Vertex) &&
                (detectedShape.ShapeType() == TopAbs_ShapeEnum.TopAbs_VERTEX))
            {
                SelectedSubshape     = detectedShape;
                SelectedSubshapeType = SubshapeTypes.Vertex;
            }
            else if (_SubshapeTypes.HasFlag(SubshapeTypes.Edge) &&
                     (detectedShape.ShapeType() == TopAbs_ShapeEnum.TopAbs_EDGE))
            {
                SelectedSubshape     = detectedShape;
                SelectedSubshapeType = SubshapeTypes.Edge;
            }
            else if (_SubshapeTypes.HasFlag(SubshapeTypes.Wire) &&
                     (detectedShape.ShapeType() == TopAbs_ShapeEnum.TopAbs_WIRE))
            {
                SelectedSubshape     = detectedShape;
                SelectedSubshapeType = SubshapeTypes.Wire;
            }
            else if (_SubshapeTypes.HasFlag(SubshapeTypes.Face) &&
                     (detectedShape.ShapeType() == TopAbs_ShapeEnum.TopAbs_FACE))
            {
                SelectedSubshape     = detectedShape;
                SelectedSubshapeType = SubshapeTypes.Face;
            }
        }
Exemplo n.º 27
0
        //--------------------------------------------------------------------------------------------------

        void ProcessMouseInput(MouseEventData data)
        {
            if (data.DetectedShapes.Count == 0)
            {
                SelectedSubshape     = null;
                SelectedSubshapeType = SubshapeTypes.None;
                return;
            }

            foreach (var detectedShape in data.DetectedShapes)
            {
                if (_SubshapeTypes.HasFlag(SubshapeTypes.Vertex) &&
                    (detectedShape.ShapeType() == TopAbs_ShapeEnum.TopAbs_VERTEX))
                {
                    SelectedSubshape     = detectedShape;
                    SelectedSubshapeType = SubshapeTypes.Vertex;
                }
                else if (_SubshapeTypes.HasFlag(SubshapeTypes.Edge) &&
                         (detectedShape.ShapeType() == TopAbs_ShapeEnum.TopAbs_EDGE))
                {
                    SelectedSubshape     = detectedShape;
                    SelectedSubshapeType = SubshapeTypes.Edge;
                }
                else if (_SubshapeTypes.HasFlag(SubshapeTypes.Wire) &&
                         (detectedShape.ShapeType() == TopAbs_ShapeEnum.TopAbs_WIRE))
                {
                    SelectedSubshape     = detectedShape;
                    SelectedSubshapeType = SubshapeTypes.Wire;
                }
                else if (_SubshapeTypes.HasFlag(SubshapeTypes.Face) &&
                         (detectedShape.ShapeType() == TopAbs_ShapeEnum.TopAbs_FACE))
                {
                    SelectedSubshape     = detectedShape;
                    SelectedSubshapeType = SubshapeTypes.Face;
                }
            }
        }
Exemplo n.º 28
0
        //--------------------------------------------------------------------------------------------------

        public override bool OnMouseMove(MouseEventData data)
        {
            if (_RotateMode != RotateMode.None)
            {
                Pnt resultPnt;
                if (!WorkspaceController.ActiveViewport.ScreenToPoint(_RotationPlane, (int)data.ScreenPoint.X, (int)data.ScreenPoint.Y, out resultPnt))
                {
                    return(false);
                }

                var planeDelta = ProjLib.Project(_RotationPlane, resultPnt);
                Delta = Dir2d.DX.Angle(new Dir2d(planeDelta.Coord)) - _StartValue;

                // Transform into unrotated frame
                //Debug.WriteLine(">> {0}  {1}  {2}", Delta.x, Delta.y, Delta.z);
                //Delta.Transform(_InverseRotation);
                //Debug.WriteLine("<< {0}  {1}  {2}", Delta.x, Delta.y, Delta.z);

                if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
                {
                    Delta = Maths.RoundToNearest(Delta, 5.0.ToRad());
                }

                _UpdateGizmo();
                data.ForceReDetection = true;

                if (_DeltaHudElement == null)
                {
                    _DeltaHudElement       = WorkspaceController.HudManager?.CreateElement <DeltaHudElement>(this);
                    _DeltaHudElement.Units = ValueUnits.Degree;
                }
                _DeltaHudElement.Delta = Delta.ToDeg();

                return(base.OnMouseMove(data));
            }
            return(false);
        }
Exemplo n.º 29
0
        //--------------------------------------------------------------------------------------------------

        public SnapInfo Snap(MouseEventData mouseEvent)
        {
            if (!InteractiveContext.Current.EditorState.SnappingEnabled)
            {
                return(null);
            }

            SnapInfo info = null;

            if (mouseEvent.DetectedShapes.Count == 1)
            {
                var detectedShape = mouseEvent.DetectedShapes[0];
                if (SupportedSnapModes.HasFlag(SnapMode.Vertex) &&
                    InteractiveContext.Current.EditorState.SnapToVertexSelected &&
                    (detectedShape.ShapeType() == TopAbs_ShapeEnum.TopAbs_VERTEX))
                {
                    // On Vertex
                    var vertex = TopoDS.Vertex(detectedShape);
                    info = new SnapInfo()
                    {
                        Point    = BRep_Tool.Pnt(vertex),
                        SnapMode = SnapMode.Vertex
                    };
                }
                else if (SupportedSnapModes.HasFlag(SnapMode.Edge) &&
                         InteractiveContext.Current.EditorState.SnapToEdgeSelected &&
                         (detectedShape.ShapeType() == TopAbs_ShapeEnum.TopAbs_EDGE))
                {
                    // On Edge
                    var    edge = TopoDS.Edge(detectedShape);
                    double umin = 0, umax = 0;
                    var    curve = BRep_Tool.Curve(edge, ref umin, ref umax);
                    if (curve != null)
                    {
                        var extrema = new GeomAPI_ExtremaCurveCurve(curve,
                                                                    new Geom_Line(_WorkspaceController.ActiveViewport.ViewAxis(Convert.ToInt32(mouseEvent.ScreenPoint.X), Convert.ToInt32(mouseEvent.ScreenPoint.Y))));
                        if (extrema.NbExtrema() >= 1)
                        {
                            Pnt p1 = new Pnt();
                            Pnt p2 = new Pnt();
                            if (extrema.TotalNearestPoints(ref p1, ref p2))
                            {
                                info = new SnapInfo()
                                {
                                    Point    = p1,
                                    SnapMode = SnapMode.Edge
                                };
                            }
                        }
                    }
                }
            }
            else if (mouseEvent.DetectedAisInteractives.Count == 1)
            {
                if (SupportedSnapModes.HasFlag(SnapMode.Vertex) &&
                    InteractiveContext.Current.EditorState.SnapToVertexSelected &&
                    (mouseEvent.DetectedAisInteractives[0] is AIS_Point aisPoint))
                {
                    // On Vertex
                    info = new SnapInfo()
                    {
                        Point    = aisPoint.Component().Pnt(),
                        SnapMode = SnapMode.Vertex
                    };
                }
            }
            else if (SupportedSnapModes.HasFlag(SnapMode.Grid) &&
                     InteractiveContext.Current.EditorState.SnapToGridSelected &&
                     _WorkspaceController.Workspace.V3dViewer.Grid().IsActive())
            {
                // On Grid
                info = new SnapInfo()
                {
                    Point    = _WorkspaceController.ActiveViewport.ProjectToGrid(Convert.ToInt32(mouseEvent.ScreenPoint.X), Convert.ToInt32(mouseEvent.ScreenPoint.Y)),
                    SnapMode = SnapMode.Grid
                };
            }

            if (info != null)
            {
                _WorkspaceController.CursorPosition = info.Point;
            }
            return(info);
        }
Exemplo n.º 30
0
        //--------------------------------------------------------------------------------------------------

        public override bool OnMouseDown(MouseEventData data)
        {
            return(true); // Supress Rubberband Selection
        }