def test_stl_importer_2_boxes(): r"""Import an iges file containing 2 distinct boxes and test topology Notes ----- This shows the current limitations of the IgesImporter as 2 boxes cannot be distinguished from one another """ # binary STL importer = StlImporter(path_from_file(__file__, "./models_in/2_boxes_binary.stl")) topo = Topo(importer.shape) assert len([i for i in topo.shells()]) == 2 assert next(topo.shells()).Closed() is True assert [i for i in topo.shells()][1].Closed() is True assert topo.number_of_faces() == 108 * 2 assert topo.number_of_edges() == 162 * 2 # ascii STL importer = StlImporter(path_from_file(__file__, "./models_in/2_boxes_ascii.stl")) topo = Topo(importer.shape) assert len([i for i in topo.shells()]) == 2 assert next(topo.shells()).Closed() is True assert [i for i in topo.shells()][1].Closed() is True assert topo.number_of_faces() == 108 * 2 assert topo.number_of_edges() == 162 * 2
def __init__(self): plotocc.__init__(self) self.b1 = gen_ellipsoid(axs=gp_Ax3( gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)), rxyz=[100, 100, 105]) self.b2 = gen_ellipsoid(axs=gp_Ax3( gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)), rxyz=[210, 210, 210]) self.base = BRepAlgoAPI_Cut(self.b2, self.b1).Shape() self.beam = gp_Ax3(gp_Pnt(0, 150, 0), gp_Dir(1, 1.5, 0)) print(self.b1) top = Topo(self.base) print(top.number_of_faces())
def test_iges_exporter_overwrite(box_shape): r"""Happy path with a subclass of TopoDS_Shape""" filename = path_from_file(__file__, "./models_out/box.igs") exporter = IgesExporter(filename) solid = shape_to_topology(box_shape) assert isinstance(solid, TopoDS.TopoDS_Solid) exporter.add_shape(solid) exporter.write_file() assert os.path.isfile(filename) # read the written box.igs importer = IgesImporter(filename) topo_compound = Topo(importer.compound) assert topo_compound.number_of_faces() == 6 assert topo_compound.number_of_edges() == 24 # add a sphere and write again with same exporter sphere = BRepPrimAPI.BRepPrimAPI_MakeSphere(10) exporter.add_shape(sphere.Shape()) exporter.write_file() # this creates a file with a box and a sphere # check that the file contains the box and the sphere importer = IgesImporter(filename) topo_compound = Topo(importer.compound) assert topo_compound.number_of_faces() == 7 # 6 from box + 1 from sphere # create a new exporter and overwrite with a box only filename = path_from_file(__file__, "./models_out/box.igs") exporter = IgesExporter(filename) solid = shape_to_topology(box_shape) exporter.add_shape(solid) exporter.write_file() assert os.path.isfile(filename) # check the file only contains a box importer = IgesImporter(filename) topo_compound = Topo(importer.compound) assert topo_compound.number_of_faces() == 6 # 6 from box
def test_step_exporter_overwrite(box_shape): r"""Happy path with a subclass of TopoDS_Shape""" filename = path_from_file(__file__, "./models_out/box.stp") exporter = StepExporter(filename) solid = shape_to_topology(box_shape) assert isinstance(solid, TopoDS.TopoDS_Solid) exporter.add_shape(solid) exporter.write_file() initial_timestamp = os.path.getmtime(filename) assert os.path.isfile(filename) # read the written box.stp importer = StepImporter(filename) topo_compound = Topo(importer.compound) assert topo_compound.number_of_faces() == 6 assert len([i for i in topo_compound.faces()]) == 6 assert topo_compound.number_of_edges() == 12 # add a sphere and write again with same exporter sphere = BRepPrimAPI.BRepPrimAPI_MakeSphere(10) exporter.add_shape(sphere.Shape()) exporter.write_file() # this creates a file with a box and a sphere intermediate_timestamp = os.path.getmtime(filename) assert intermediate_timestamp >= initial_timestamp # check that the file contains the box and the sphere importer = StepImporter(filename) assert len([i for i in Topo(importer.compound).faces()]) == 7 # 6 from box + 1 from sphere assert len([i for i in Topo(importer.compound).solids()]) == 2 # create a new exporter and overwrite with a box only filename = path_from_file(__file__, "./models_out/box.stp") exporter = StepExporter(filename) solid = shape_to_topology(box_shape) exporter.add_shape(solid) exporter.write_file() assert os.path.isfile(filename) last_timestamp = os.path.getmtime(filename) assert last_timestamp >= intermediate_timestamp # check the file only contains a box importer = StepImporter(filename) assert len([i for i in Topo(importer.compound).faces()]) == 6 # 6 from box assert len([i for i in Topo(importer.compound).solids()]) == 1
def get_face(self, sol): top_api = Topo(sol) print(top_api.number_of_faces()) for face in top_api.faces(): sol_face = face return sol_face
#display.DisplayShape(domain) from OCC.Core.STEPControl import STEPControl_Writer, STEPControl_AsIs step_writer = STEPControl_Writer() step_writer.Transfer(domain, STEPControl_AsIs) stpfile = "foil.stp" step_writer.Write(stpfile) topo = Topo(domain) faces = topo.faces iface = 0 print dir(faces) N = float(topo.number_of_faces()) surfaces = [None for i in range(topo.number_of_faces())] maxima = [-1 for i in range(topo.number_of_faces())] for f in topo.faces(): print str(100. * float(iface) / N) + ' % done' for f2 in d_faces: shp = BRepAlgoAPI_Section(f, d_faces[f2]).Shape() tp = Topo(shp) nedge = tp.number_of_edges() if (nedge > maxima[iface]): surfaces[iface] = f2 maxima[iface] = nedge iface += 1 gmsh_dict = {}
# obj.show_ball() axs = gp_Ax3(gp_Pnt(0, 0, 0), gp_Dir(1, 1, 1)) elp = gen_ellipsoid(axs, [10, 20, 30]) obj.display.DisplayShape(elp, transparency=0.7, color="BLUE") obj.show_axs_pln(axs, scale=20) axs = gp_Ax3(gp_Pnt(30, 0, 0), gp_Dir(1, 1, 0)) elp = gen_ellipsoid(axs, [10, 20, 30]) obj.display.DisplayShape(elp, transparency=0.7, color="BLUE") obj.show_axs_pln(axs, scale=20) #elp = gen_ellipsoid_geom(axs, [10, 20, 30]) top_api = Topo(elp) print(top_api.number_of_faces()) for face in top_api.faces(): elp_face = face print(elp_face) elp_surf = BRep_Tool_Surface(elp_face) print(elp_surf) lin = Geom_Line(gp_Ax1(axs.Location(), gp_Dir(0, 1, 1))) api = GeomAPI_IntCS(lin, elp_surf) obj.display.DisplayShape(lin) print(api.Point(1)) print(api.Point(2)) obj.show()