Ejemplo n.º 1
0
        //--------------------------------------------------------------------------------------------------

        double _FindEdgeParam(TopoDS_Edge edge, SelectSubshapeAction selectAction)
        {
            // Calculate parameter on the edge
            double umin = 0, umax = 0;
            var    curve    = BRep_Tool.Curve(edge, ref umin, ref umax);
            var    viewAxis = selectAction.LastMouseEventData.PickAxis;
            var    extrema  = new GeomAPI_ExtremaCurveCurve(curve, new Geom_Line(viewAxis));

            if (extrema.NbExtrema() > 0)
            {
                double param1 = 0, param2 = 0;
                extrema.LowerDistanceParameters(ref param1, ref param2);
                return(param1);
            }
            else
            {
                return(Taper.CalculateBaseParameter(edge, 0.5));
            }
        }
Ejemplo n.º 2
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);
        }