66"""
77import os
88import numpy as np
9- from OCC .BRep import BRep_Tool , BRep_Builder , BRep_Tool_Curve
10- from OCC .BRepAlgo import brepalgo_IsValid
11- from OCC .BRepBuilderAPI import (
9+ from OCC .Core .BRep import BRep_Tool , BRep_Builder , BRep_Tool_Curve
10+ from OCC .Core .BRepMesh import BRepMesh_IncrementalMesh
11+ from OCC .Core .BRepAlgo import brepalgo_IsValid
12+ from OCC .Core .BRepBuilderAPI import (
1213 BRepBuilderAPI_MakeEdge , BRepBuilderAPI_MakeFace ,
1314 BRepBuilderAPI_NurbsConvert , BRepBuilderAPI_MakeWire , BRepBuilderAPI_Sewing )
14- from OCC .BRepOffsetAPI import BRepOffsetAPI_FindContigousEdges
15+ from OCC .Core . BRepOffsetAPI import BRepOffsetAPI_FindContigousEdges
1516from OCC .Display .SimpleGui import init_display
16- from OCC .GeomConvert import (geomconvert_SurfaceToBSplineSurface ,
17+ from OCC .Core . GeomConvert import (geomconvert_SurfaceToBSplineSurface ,
1718 geomconvert_CurveToBSplineCurve )
18- from OCC .gp import gp_Pnt , gp_XYZ
19- from OCC .Precision import precision_Confusion
20- from OCC .ShapeAnalysis import ShapeAnalysis_WireOrder
21- from OCC .ShapeFix import ShapeFix_ShapeTolerance , ShapeFix_Shell
22- from OCC .StlAPI import StlAPI_Writer
23- from OCC .TColgp import TColgp_Array1OfPnt , TColgp_Array2OfPnt
24- from OCC .TopAbs import (TopAbs_FACE , TopAbs_EDGE , TopAbs_WIRE , TopAbs_FORWARD ,
19+ from OCC .Core . gp import gp_Pnt , gp_XYZ
20+ from OCC .Core . Precision import precision_Confusion
21+ from OCC .Core . ShapeAnalysis import ShapeAnalysis_WireOrder
22+ from OCC .Core . ShapeFix import ShapeFix_ShapeTolerance , ShapeFix_Shell
23+ from OCC .Core . StlAPI import StlAPI_Writer
24+ from OCC .Core . TColgp import TColgp_Array1OfPnt , TColgp_Array2OfPnt
25+ from OCC .Core . TopAbs import (TopAbs_FACE , TopAbs_EDGE , TopAbs_WIRE , TopAbs_FORWARD ,
2526 TopAbs_SHELL )
26- from OCC .TopExp import TopExp_Explorer , topexp
27- from OCC .TopoDS import (topods_Face , TopoDS_Compound , topods_Shell , topods_Edge ,
27+ from OCC .Core . TopExp import TopExp_Explorer , topexp
28+ from OCC .Core . TopoDS import (topods_Face , TopoDS_Compound , topods_Shell , topods_Edge ,
2829 topods_Wire , topods , TopoDS_Shape )
2930from matplotlib import pyplot
3031from mpl_toolkits import mplot3d
@@ -112,7 +113,7 @@ def parse(self, filename):
112113 bspline_face = geomconvert_SurfaceToBSplineSurface (brep_face )
113114
114115 # openCascade object
115- occ_face = bspline_face . GetObject ()
116+ occ_face = bspline_face
116117
117118 # extract the Control Points of each face
118119 n_poles_u = occ_face .NbUPoles ()
@@ -185,7 +186,7 @@ def write(self, mesh_points, filename, tolerance=None):
185186 face_aux = topods_Face (nurbs_face )
186187 brep_face = BRep_Tool .Surface (topods_Face (nurbs_face ))
187188 bspline_face = geomconvert_SurfaceToBSplineSurface (brep_face )
188- occ_face = bspline_face . GetObject ()
189+ occ_face = bspline_face
189190
190191 n_poles_u = occ_face .NbUPoles ()
191192 n_poles_v = occ_face .NbVPoles ()
@@ -205,7 +206,7 @@ def write(self, mesh_points, filename, tolerance=None):
205206 # construct the deformed wire for the trimmed surfaces
206207 wire_maker = BRepBuilderAPI_MakeWire ()
207208 tol = ShapeFix_ShapeTolerance ()
208- brep = BRepBuilderAPI_MakeFace (occ_face . GetHandle () ,
209+ brep = BRepBuilderAPI_MakeFace (occ_face ,
209210 self .tolerance ).Face ()
210211 brep_face = BRep_Tool .Surface (brep )
211212
@@ -228,7 +229,7 @@ def write(self, mesh_points, filename, tolerance=None):
228229 wire = wire_maker .Wire ()
229230
230231 # trimming the surfaces
231- brep_surf = BRepBuilderAPI_MakeFace (occ_face . GetHandle () ,
232+ brep_surf = BRepBuilderAPI_MakeFace (occ_face ,
232233 wire ).Shape ()
233234 compound_builder .Add (compound , brep_surf )
234235 n_faces += 1
@@ -303,7 +304,7 @@ def parse_face(topo_face):
303304 h_geom_edge = BRep_Tool_Curve (
304305 topods_Edge (bspline_tshape_edge ))[0 ]
305306 h_bspline_edge = geomconvert_CurveToBSplineCurve (h_geom_edge )
306- bspline_geom_edge = h_bspline_edge . GetObject ()
307+ bspline_geom_edge = h_bspline_edge
307308
308309 nb_poles = bspline_geom_edge .NbPoles ()
309310
@@ -334,7 +335,7 @@ def parse_face(topo_face):
334335 nurbs_face = nurbs_converter .Shape ()
335336 h_geomsurface = BRep_Tool .Surface (topods .Face (nurbs_face ))
336337 h_bsurface = geomconvert_SurfaceToBSplineSurface (h_geomsurface )
337- bsurface = h_bsurface . GetObject ()
338+ bsurface = h_bsurface
338339
339340 # get access to control points (poles)
340341 nb_u = bsurface .NbUPoles ()
@@ -435,7 +436,7 @@ def write_edge(points_edge, topo_edge):
435436 topo_curve = topods_Edge (nurbs_curve )
436437 h_geomcurve = BRep_Tool .Curve (topo_curve )[0 ]
437438 h_bcurve = geomconvert_CurveToBSplineCurve (h_geomcurve )
438- bspline_edge_curve = h_bcurve . GetObject ()
439+ bspline_edge_curve = h_bcurve
439440
440441 # Edge geometric properties
441442 nb_cpt = bspline_edge_curve .NbPoles ()
@@ -734,7 +735,12 @@ def plot(self, plot_file=None, save_fig=False):
734735 stl_writer = StlAPI_Writer ()
735736 # Do not switch SetASCIIMode() from False to True.
736737 stl_writer .SetASCIIMode (False )
737- stl_writer .Write (shape , 'aux_figure.stl' )
738+
739+ # Necessary to write to STL [to check]
740+ stl_mesh = BRepMesh_IncrementalMesh (shape , 0.01 )
741+ stl_mesh .Perform ()
742+
743+ f = stl_writer .Write (shape , 'aux_figure.stl' )
738744
739745 # Create a new plot
740746 figure = pyplot .figure ()
0 commit comments