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 topo.shells().next().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 topo.shells().next().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 test_iges_importer_happy_topology(): r"""import iges file containing a box and test topology""" importer = IgesImporter(path_from_file(__file__, "./models_in/box.igs")) topo = Topo(importer.compound) assert topo.number_of_faces() == 6 assert topo.number_of_edges() == 24 # 12 edges * 2 possible orientations ?
def test_iges_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 """ importer = IgesImporter(path_from_file(__file__, "./models_in/2_boxes.igs")) topo = Topo(importer.compound) assert topo.number_of_faces() == 6 * 2 assert topo.number_of_edges() == 24 * 2
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