Esempio n. 1
0
        //--------------------------------------------------------------------------------------------------

        public static List <TopoDS_Edge> Edges(this TopoDS_Shape shape, bool distinct = true)
        {
            var edges = new List <TopoDS_Edge>();

            var exp = new TopExp_Explorer(shape, TopAbs_ShapeEnum.TopAbs_EDGE, TopAbs_ShapeEnum.TopAbs_SHAPE);

            while (exp.More())
            {
                var edge = TopoDS.Edge(exp.Current());
                exp.Next();

                if (distinct)
                {
                    var otherEdgeIndex = edges.FindIndex(e => e.IsSame(edge));
                    if (otherEdgeIndex >= 0)
                    {
                        if (edges[otherEdgeIndex].Orientation() == TopAbs_Orientation.TopAbs_REVERSED &&
                            edge.Orientation() == TopAbs_Orientation.TopAbs_FORWARD)
                        {
                            // Replace with forward edge, this is prefered
                            edges[otherEdgeIndex] = edge;
                        }

                        // Edge already present or replaced, skip adding
                        continue;
                    }
                }

                edges.Add(edge);
            }
            return(edges);
        }
Esempio n. 2
0
        public static void DisplayTemporaryDimension(Document animationDocument, Node extrusion, bool enableSelection)
        {
            var subShape = new NodeBuilder(animationDocument, FunctionNames.SubShape);

            subShape[0].Reference = extrusion;
            subShape[1].Integer   = 1;
            subShape[2].Integer   = (int)TopAbsShapeEnum.TopAbs_EDGE;
            subShape.ExecuteFunction();

            if (subShape.Shape == null)
            {
                return;
            }

            var edge          = TopoDS.Edge(subShape.Shape);
            var pnt           = new Point3D();
            var computedPoint = GeomUtils.CalculateEdgeMidPoint(edge);

            if (computedPoint != null)
            {
                pnt = (Point3D)computedPoint;
            }

            var dimension = new NodeBuilder(animationDocument, FunctionNames.Dimension);

            dimension[0].Reference          = subShape.Node;
            dimension[1].TransformedPoint3D = pnt;
            dimension.EnableSelection       = enableSelection;
            dimension.ExecuteFunction();

            subShape.Visibility = ObjectVisibility.Hidden;
        }
Esempio n. 3
0
        private static void AddFaceFilletVertex(TopoDSShape face, int filletChamferType, double radius,
                                                SceneSelectedEntity firstEntity, SceneSelectedEntity secondEntity,
                                                BRepFilletAPIMakeFillet2d fillet)
        {
            var firstWire          = GeomUtils.ExtractShapeType(face, firstEntity.ShapeType, firstEntity.ShapeCount);
            var secondWire         = GeomUtils.ExtractShapeType(face, secondEntity.ShapeType, secondEntity.ShapeCount);
            var listOfCommonVertex = GeomUtils.CommonVertexes(firstWire, secondWire);

            if (listOfCommonVertex.Count >= 1)
            {
                // If operation type is fillet
                if (filletChamferType == (int)FilletChamferTypes.SimpleFillet2D)
                {
                    foreach (var vertex in listOfCommonVertex)
                    {
                        fillet.AddFillet(vertex, radius);
                    }
                }
                else
                {
                    // If operation type is chamfer
                    fillet.AddChamfer(TopoDS.Edge(firstWire), listOfCommonVertex[0], radius,
                                      GeomUtils.DegreesToRadians(45));
                }
            }
            else
            {
                return;
            }

            return;
        }
Esempio n. 4
0
        public static void DisplayTemporaryDimension(Document animationDocument, Node baseNode, Node extrusion, Mouse3DPosition mouseData, bool enableSelection)
        {
            var subShape = new NodeBuilder(animationDocument, FunctionNames.SubShape);

            subShape[0].Reference = extrusion;
            subShape[1].Integer   = 1;
            subShape[2].Integer   = (int)TopAbsShapeEnum.TopAbs_EDGE;
            subShape.ExecuteFunction();

            if (subShape.Shape == null)
            {
                return;
            }

            var edge            = TopoDS.Edge(subShape.Shape);
            var baseNodeBuilder = new NodeBuilder(baseNode);
            var gravityCenter   = GeomUtils.ExtractGravityCenter(baseNodeBuilder.Shape);

            var firstPoint           = new Point3D();
            var firstPointCalculated = GeomUtils.CalculateEdgeFirstPoint(edge);

            if (firstPointCalculated != null)
            {
                firstPoint = (Point3D)firstPointCalculated;
            }

            var secondPoint           = new Point3D();
            var secondPointCalculated = GeomUtils.CalculateEdgeLastPoint(edge);

            if (secondPointCalculated != null)
            {
                secondPoint = (Point3D)secondPointCalculated;
            }

            var middlePoint = GeomUtils.ComputeMidPoint(firstPoint, secondPoint);

            // Translate the dimenion text at some distance from the extrude
            var vector = new gpVec(firstPoint.GpPnt, gravityCenter.GpPnt);

            vector.Reverse();
            vector.Normalize();
            vector.Multiply(2);
            middlePoint = GeomUtils.BuildTranslation(middlePoint, vector);

            subShape.Visibility = ObjectVisibility.Hidden;

            // Build a distance dimension just for animation purposes
            var animationBuilder = new NodeBuilder(animationDocument, FunctionNames.PointsDimension);

            animationBuilder[0].TransformedPoint3D = firstPoint;
            animationBuilder[1].TransformedPoint3D = secondPoint;
            animationBuilder[2].TransformedPoint3D = middlePoint;
            animationBuilder[3].Integer            = (int)DsgPrsArrowSide.DsgPrs_AS_FIRSTPT_LASTAR;
            animationBuilder[4].Real         = 1;
            animationBuilder.EnableSelection = false;
            animationBuilder.Color           = Color.Black;
            animationBuilder.ExecuteFunction();
        }
        //--------------------------------------------------------------------------------------------------

        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();
        }
Esempio n. 6
0
        public static TopoDSShape ExtractSubShape(
            TopoDSShape originalShape,
            int facePosition,
            TopAbsShapeEnum shapeType)
        {
            if (originalShape == null)
            {
                return(null);
            }
            // Find the face
            var baseEx = new TopExpExplorer();

            baseEx.Init(originalShape, shapeType, TopAbsShapeEnum.TopAbs_SHAPE);

            while (baseEx.More && (facePosition != 1))
            {
                baseEx.Next();
                facePosition--;
            }
            //if (!baseEx.More())
            //    return null;
            TopoDSShape shape = null;

            switch (shapeType)
            {
            case TopAbsShapeEnum.TopAbs_VERTEX:
                shape = TopoDS.Vertex(baseEx.Current);
                break;

            case TopAbsShapeEnum.TopAbs_EDGE:
                shape = TopoDS.Edge(baseEx.Current);
                break;

            case TopAbsShapeEnum.TopAbs_WIRE:
                shape = TopoDS.Wire(baseEx.Current);
                break;

            case TopAbsShapeEnum.TopAbs_FACE:
                shape = TopoDS.Face(baseEx.Current);
                break;

            case TopAbsShapeEnum.TopAbs_SOLID:
            case TopAbsShapeEnum.TopAbs_COMPOUND:
                return(originalShape);
            }
            return(shape);
        }
        private void GetLength(ref object resultvalue)
        {
            if (Builder[0].ReferenceBuilder.FunctionName == FunctionNames.Circle)
            {
                var radius = Builder[0].ReferenceBuilder.Dependency[1].Real;
                resultvalue = radius * 2;
                return;
            }
            var referenceShape = ShapeUtils.ExtractSubShape(Builder[0].ReferenceData);
            var edge           = TopoDS.Edge(referenceShape);
            var curve          = new BRepAdaptorCurve(edge);
            var firstPoint     = curve.Value(curve.FirstParameter);
            var lastPoint      = curve.Value(curve.LastParameter);
            var length         = firstPoint.Distance(lastPoint);

            resultvalue = length;
        }
Esempio n. 8
0
        /// <summary>
        ///   Detects the referenced shape type and generates an appropiate
        ///   dimension for it
        /// </summary>
        public static AISInteractiveObject CreateDependency(TopoDSShape referenceShape, gpPnt textLocation, DsgPrsArrowSide arrowType, bool isOffset = false, gpPnt offset = null)
        {
            if (referenceShape == null || referenceShape.ShapeType != TopAbsShapeEnum.TopAbs_EDGE)
            {
                return(null);
            }

            var curve = new BRepAdaptorCurve(TopoDS.Edge(referenceShape));

            if (curve.GetType == GeomAbsCurveType.GeomAbs_Circle)
            {
                return(BuildCircleDimension(referenceShape, textLocation));
            }
            return(curve.GetType == GeomAbsCurveType.GeomAbs_Line
                       ? BuildLineDimension(TopoDS.Edge(referenceShape), textLocation, null, arrowType, isOffset, offset)
                       : null);
        }
Esempio n. 9
0
        private static AISInteractiveObject BuildCircleDimension(TopoDSShape referenceShape, gpPnt textLocation)
        {
            var edge  = TopoDS.Edge(referenceShape);
            var curve = new BRepAdaptorCurve(edge);

            if (curve.GetType != GeomAbsCurveType.GeomAbs_Circle)
            {
                return(null);
            }

            // For a circle use a diameter dimension
            var circle   = curve.Circle;
            var diameter = 2.0 * circle.Radius;
            var text     = new TCollectionExtendedString(String.Format("{0:0.00}", diameter));
            var rd       = new AISDiameterDimension(referenceShape, diameter, text, textLocation,
                                                    DsgPrsArrowSide.DsgPrs_AS_BOTHAR, true, ArrowSize);

            rd.SetColor(QuantityNameOfColor.Quantity_NOC_RED);
            return(rd);
        }
        public override bool Execute()
        {
            var edgeNode      = Dependency[0].Reference;
            var edgeIndexNode = Dependency[0].ReferenceData.ShapeCount;

            if (ShapeUtils.ExtractShape(edgeNode) == null)
            {
                return(false);
            }
            var edge =
                TopoDS.Edge(ShapeUtils.ExtractSubShape(edgeNode, edgeIndexNode, TopAbsShapeEnum.TopAbs_EDGE));
            var distance = Dependency[1].Real;

            var referenceShape           = Dependency[2].Reference;
            var referebceShapePointIndex = Dependency[3].Integer;

            if (referenceShape == null)
            {
                return(false);
            }
            var point = NodeBuilderUtils.GetNodePoint(referenceShape[referebceShapePointIndex]);

            if (point != null)
            {
                var projectionPoint = GeomUtils.ProjectPointOnEdge(edge, ((Point3D)point).GpPnt);
                var newPoint        = new Point3D(projectionPoint);
                var currentDistance = projectionPoint.Distance(((Point3D)point).GpPnt);
                if (Math.Abs(currentDistance - distance) > 0.01)
                {
                    var scale = currentDistance / distance;
                    if (Math.Abs(scale - 1) > Precision.Confusion)
                    {
                        newPoint = TreeUtils.ScaleSegment(newPoint, ((Point3D)point), scale);
                    }
                }

                NodeBuilderUtils.SetupNodePoint(referenceShape[referebceShapePointIndex], newPoint);
            }
            return(true);
        }
Esempio n. 11
0
        //--------------------------------------------------------------------------------------------------

        #endregion

        #region Property List

        void _InitProperties()
        {
            if (_Properties != null)
            {
                return;
            }

            _Properties = new List <BRepTopologyTreeProperty>();
            try
            {
                _AddDefaultProperties();

                switch (BrepShape.ShapeType())
                {
                case TopAbs_ShapeEnum.TopAbs_SHELL:
                    _AddShellProperties(BrepShape as TopoDS_Shell ?? TopoDS.Shell(BrepShape));
                    break;

                case TopAbs_ShapeEnum.TopAbs_FACE:
                    _AddFaceProperties(BrepShape as TopoDS_Face ?? TopoDS.Face(BrepShape));
                    break;

                case TopAbs_ShapeEnum.TopAbs_WIRE:
                    _AddWireProperties(BrepShape as TopoDS_Wire ?? TopoDS.Wire(BrepShape));
                    break;

                case TopAbs_ShapeEnum.TopAbs_EDGE:
                    _AddEdgeProperties(BrepShape as TopoDS_Edge ?? TopoDS.Edge(BrepShape));
                    break;

                case TopAbs_ShapeEnum.TopAbs_VERTEX:
                    _AddVertexProperties(BrepShape as TopoDS_Vertex ?? TopoDS.Vertex(BrepShape));
                    break;
                }
            }
            catch (Exception e)
            {
                Messages.Exception($"Error getting properties for B-Rep shape {Name}", e);
            }
        }
Esempio n. 12
0
        private static void BuildParallelAxisList(TopoDSShape solidShape, SolverGeometricObject solverObject,
                                                  double angle)
        {
            var listOfEdges = GeomUtils.ExtractEdges(solidShape);

            if (listOfEdges.Count <= 0)
            {
                return;
            }
            var extractedAxises = new List <SolverParallelAxis>();

            foreach (var edge in listOfEdges)
            {
                var curve = new BRepAdaptorCurve(TopoDS.Edge(edge));
                if (curve.GetType != GeomAbsCurveType.GeomAbs_Line)
                {
                    continue;
                }
                var buildAxis = new SolverParallelAxis(edge);
                var isParallelWithPreviousAxes = false;
                foreach (var axis in extractedAxises)
                {
                    if (!axis.IsParallel(buildAxis.Vector, angle))
                    {
                        continue;
                    }
                    isParallelWithPreviousAxes = true;
                    break;
                }
                if (!isParallelWithPreviousAxes)
                {
                    extractedAxises.Add(buildAxis);
                }
            }
            foreach (var extractedAxis in extractedAxises)
            {
                solverObject.ParallelAxis.Add(extractedAxis);
            }
        }
Esempio n. 13
0
        public override bool Execute()
        {
            var referenceShape = ShapeUtils.ExtractSubShape(Dependency[0].ReferenceData);
            var refBuilder     = new NodeBuilder(Dependency[0].Reference);
            var builder        = Builder;

            builder.Visibility = refBuilder.Visibility;
            var     textLocation = Dependency[1].TransformedPoint3D.GpPnt;
            var     arrowType    = Dependency[2].Integer == 1 ? DsgPrsArrowSide.DsgPrs_AS_NONE : DsgPrsArrowSide.DsgPrs_AS_BOTHAR;
            Point3D offset       = new Point3D(textLocation);
            bool    isOffset     = false;

            if (Dependency[3].Integer == 1)
            {
                isOffset = true;
                Dependency[3].Integer = 0;
                var edge = TopoDS.Edge(referenceShape);
                var calculatedMidpoint = GeomUtils.CalculateEdgeMidPoint(edge);
                if (calculatedMidpoint != null)
                {
                    offset = new Point3D(textLocation.X - calculatedMidpoint.Value.X,
                                         textLocation.Y - calculatedMidpoint.Value.Y,
                                         textLocation.Z - calculatedMidpoint.Value.Z);
                    Dependency[4].Node.Set <Point3DInterpreter>().Value = offset;
                }
            }
            var interactive = DimensionUtils.CreateDependency(referenceShape, offset.GpPnt, arrowType, isOffset, Dependency[4].TransformedPoint3D.GpPnt);

            if (interactive == null)
            {
                return(false);
            }
            Interactive = interactive;

            return(true);
        }
Esempio n. 14
0
        /// <summary>
        ///   Apply fillet on a list of wires. The common endpoints of wires are considered the fillet vertexes.
        /// </summary>
        private static TopoDSWire ApplyFilletOnWires(IEnumerable <SceneSelectedEntity> filletNodes, double radius,
                                                     int filletChamferType)
        {
            // This method processes only fillet2D and chamfer2D operations
            if ((filletChamferType != (int)FilletChamferTypes.SimpleFillet2D) &&
                (filletChamferType != (int)FilletChamferTypes.SimpleChamfer2D))
            {
                return(null);
            }

            try
            {
                // Make a face fom the wires
                var wires = new List <SceneSelectedEntity>();
                foreach (var node in filletNodes)
                {
                    wires.Add(node);
                }
                var face = MakeFaceFunction.ComposeWires(wires, true);

                if ((face == null) || (face.IsNull))
                {
                    return(null);
                }

                var fillet = new BRepFilletAPIMakeFillet2d();
                // Initialize a fillet with the face made from the 2 wires
                fillet.Init(face);

                // Fillet the common vertexes
                Node previousNode = null;
                foreach (var node in filletNodes)
                {
                    if (previousNode != null)
                    {
                        var wire1 = previousNode.Get <NamedShapeInterpreter>().Shape;
                        var wire2 = node.Node.Get <NamedShapeInterpreter>().Shape;
                        var listOfCommonVertex = GeomUtils.CommonVertexes(wire1, wire2);
                        if (listOfCommonVertex.Count >= 1)
                        {
                            foreach (var vertex in listOfCommonVertex)
                            {
                                if (filletChamferType == (int)FilletChamferTypes.SimpleFillet2D)
                                {
                                    // If the operation is a fillet
                                    fillet.AddFillet(vertex, radius);
                                }
                                else
                                {
                                    // Map all edges to faces
                                    var map = new TopToolsIndexedDataMapOfShapeListOfShape(1);
                                    TopExp.MapShapesAndAncestors(wire1, TopAbsShapeEnum.TopAbs_VERTEX,
                                                                 TopAbsShapeEnum.TopAbs_EDGE, map);

                                    // Locate an ancestor face
                                    for (var i = 1; i <= map.Extent; i++)
                                    {
                                        var localVertex = TopoDS.Vertex(map.FindKey(i));
                                        if (!vertex.IsSame(localVertex))
                                        {
                                            continue;
                                        }
                                        // We found an ancestor edge
                                        var edge = TopoDS.Edge(map.FindFromIndex(i).First);
                                        // Add the vertex and edge on the chamfer algorithm
                                        //fillet.AddChamfer(TopoDS.Edge(edge), TopoDS.Edge(edge2), radius, radius);
                                        fillet.AddChamfer(TopoDS.Edge(edge), vertex, radius,
                                                          GeomUtils.DegreesToRadians(45));
                                    }
                                }
                            }
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    previousNode = node.Node;
                }

                // Test if the operation succeeded
                if (fillet.Status != ChFi2dConstructionError.ChFi2d_IsDone)
                {
                    return(null);
                }

                var shape = fillet.Shape;
                if ((shape == null) || (shape.IsNull))
                {
                    return(null);
                }

                var aMap = new TopToolsIndexedMapOfShape(1);
                TopExp.MapShapes(fillet.Shape, TopAbsShapeEnum.TopAbs_WIRE, aMap);
                if (aMap.Extent != 1)
                {
                    return(null);
                }

                var newWire = new BRepBuilderAPIMakeWire();
                var ex      = new BRepToolsWireExplorer(TopoDS.Wire(aMap.FindKey(1)));
                for (; ex.More; ex.Next())
                {
                    newWire.Add(ex.Current);
                }

                return(newWire.Wire);
            }
            catch (Exception ex)
            {
                Log.Error("Apply Fillet2D error: " + ex.Message);
            }

            return(null);
        }
Esempio n. 15
0
        private static TopoDSShape ApplyFillet(double thickness, TopoDSShape body, int edgeNumber, int operationType)
        {
            try
            {
                // Create fillet
                var aEdgeExplorer = new TopExpExplorer(body, TopAbsShapeEnum.TopAbs_EDGE,
                                                       TopAbsShapeEnum.TopAbs_SHAPE);

                var         number = 1;
                TopoDSShape shape  = null;
                while (aEdgeExplorer.More)
                {
                    if ((edgeNumber == 0) || (edgeNumber == number))
                    {
                        var anEdge = TopoDS.Edge(aEdgeExplorer.Current);

                        if (operationType == (int)FilletChamferTypes.SimpleFillet)
                        {
                            var fillet = new BRepFilletAPIMakeFillet(body, ChFi3dFilletShape.ChFi3d_Rational);
                            // Add edge to fillet algorithm
                            fillet.Add(thickness, anEdge);
                            // Check if valid contour
                            try
                            {
                                if (fillet.StripeStatus(fillet.Contour(anEdge)) != ChFiDSErrorStatus.ChFiDS_Ok)
                                {
                                    return(null);
                                }
                            }
                            catch (Exception)
                            {
                                Log.Info("Exception on applying fillet");
                            }
                            shape = fillet.Shape;
                        }
                        else
                        {
                            var chamfer = new BRepFilletAPIMakeChamfer(body);
                            var aMap    = new TopToolsIndexedDataMapOfShapeListOfShape(1);
                            TopExp.MapShapesAndAncestors(body, TopAbsShapeEnum.TopAbs_EDGE, TopAbsShapeEnum.TopAbs_FACE,
                                                         aMap);
                            // Locate an ancestor face
                            for (var i = 1; i < aMap.Extent; i++)
                            {
                                var localEdge = TopoDS.Edge(aMap.FindKey(i));
                                if (!anEdge.IsSame(localEdge))
                                {
                                    continue;
                                }
                                // We found an ancestor face
                                var face = TopoDS.Face(aMap.FindFromIndex(i).First);
                                // Add the edge and face on the chmafer algorithm
                                chamfer.Add(thickness, thickness, anEdge, face);
                            }
                            shape = chamfer.Shape;
                        }
                    }

                    aEdgeExplorer.Next();
                    number++;
                }

                // Check the shape validity

                if ((shape == null) || (shape.IsNull))
                {
                    return(null);
                }

                return(shape);
            }
            catch (Exception ex)
            {
                Log.Info("Apply fillet error: " + ex.Message);
            }
            return(null);
        }
Esempio n. 16
0
        //--------------------------------------------------------------------------------------------------

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

            Debug.Assert(selectAction != null);

            SubshapeReference subshapeRef = null;

            switch (_TargetShape.ShapeType)
            {
            case ShapeType.Sketch:
                if (selectAction.SelectedSubshapeType == SubshapeTypes.Edge)
                {
                    subshapeRef = _TargetShape.GetSubshapeReference(_TargetShape.GetTransformedBRep(), TopoDS.Edge(selectAction.SelectedSubshape));
                }
                break;

            case ShapeType.Solid:
                if (selectAction.SelectedSubshapeType == SubshapeTypes.Face)
                {
                    subshapeRef = _TargetShape.GetSubshapeReference(_TargetShape.GetTransformedBRep(), TopoDS.Face(selectAction.SelectedSubshape));
                }
                break;

            default:
                return;
            }

            if (subshapeRef != null)
            {
                selectAction.Stop();
                Stop();

                if (_Mode == ToolMode.CreateNew)
                {
                    var mirror = Mirror.Create(_TargetBody, subshapeRef);
                    if (mirror != null)
                    {
                        InteractiveContext.Current.UndoHandler.Commit();
                        //InteractiveContext.Current.WorkspaceController.Selection.SelectEntity(_TargetBody);
                    }
                }
                else if (_Mode == ToolMode.Reselect)
                {
                    // Reselected face or edge
                    _ModifierToChange.ReferenceShape = subshapeRef;
                    _ModifierToChange.Invalidate();
                    InteractiveContext.Current.UndoHandler.Commit();
                }
            }
            else
            {
                selectAction.Reset();
            }

            WorkspaceController.Invalidate();
        }
Esempio n. 17
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);
        }
Esempio n. 18
0
        //--------------------------------------------------------------------------------------------------

        public static TopoDS_Edge ToEdge(this TopoDS_Shape shape)
        {
            return(shape == null ? null : TopoDS.Edge(shape));
        }