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

        public static TopoDS_Shape CreateFacesFromWires(TopoDS_Shape sourceShape, Pln plane)
        {
            var wires = sourceShape.Wires();

            // Create faces from closed wires
            var openWireCount   = 0;
            var closedWireCount = 0;
            var makeFace        = new BRepBuilderAPI_MakeFace(plane);

            foreach (var wire in wires)
            {
                var checkWire = new BRepCheck_Wire(wire);
                if (checkWire.Closed() != BRepCheck_Status.BRepCheck_NoError)
                {
                    openWireCount++;
                    continue;
                }
                makeFace.Add(wire);
                closedWireCount++;
            }

            if (openWireCount > 0)
            {
                Messages.Warning("Source shape has " + openWireCount + " unclosed wires, which will be ignored.");
            }

            if (closedWireCount == 0)
            {
                Messages.Warning("Source shape has no closed wires.");
                return(new TopoDS_Face());
            }

            if (!makeFace.IsDone())
            {
                Messages.Error("Generating faces from source wires failed.");
                return(null);
            }

            // Fix orientation of that faces
            var shapeFix = new ShapeFix_Shape(makeFace.Face());

            shapeFix.Perform();

            return(shapeFix.Shape());
        }
        //--------------------------------------------------------------------------------------------------

        void _PreviewRadius(ToolAction toolAction)
        {
            if (!(toolAction is PointAction pointAction))
            {
                return;
            }

            _ClearPreviews();

            _PointPlane2 = pointAction.PointOnPlane;

            if (_PointPlane1.IsEqual(_PointPlane2, Double.Epsilon))
            {
                return;
            }

            _Radius = new Vec2d(_PointPlane1, _PointPlane2).Magnitude();
            if (_Radius <= Double.Epsilon)
            {
                return;
            }

            var makeCircle = new gce_MakeCirc(_PivotPoint, _Plane.Axis.Direction, _Radius);

            if (!makeCircle.IsDone())
            {
                return;
            }

            var makeEdge = new BRepBuilderAPI_MakeEdge(makeCircle.Value());

            if (!makeEdge.IsDone())
            {
                return;
            }

            var makeWire = new BRepBuilderAPI_MakeWire(makeEdge.Edge());

            if (!makeWire.IsDone())
            {
                return;
            }

            var makeFace = new BRepBuilderAPI_MakeFace(makeWire.Wire(), true);

            if (!makeFace.IsDone())
            {
                return;
            }

            _AisPreviewEdges = new AIS_Shape(makeFace.Face());
            _AisPreviewEdges.SetDisplayMode(0);
            WorkspaceController.Workspace.AisContext.Display(_AisPreviewEdges, false);
            WorkspaceController.Workspace.AisContext.Deactivate(_AisPreviewEdges);

            _AisPreviewSolid = new AIS_Shape(makeFace.Face());
            _AisPreviewSolid.SetDisplayMode(1);
            WorkspaceController.Workspace.AisContext.Display(_AisPreviewSolid, false);
            WorkspaceController.Workspace.AisContext.Deactivate(_AisPreviewSolid);

            StatusText = $"Select radius: {_Radius:0.00}";
            if (_ValueHudElement != null)
            {
                _ValueHudElement.Value = _Radius;
            }

            if (_Coord2DHudElement != null)
            {
                _Coord2DHudElement.CoordinateX = pointAction.PointOnPlane.X;
                _Coord2DHudElement.CoordinateY = pointAction.PointOnPlane.Y;
            }
        }