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