def test_step_importer_2_boxes(): r"""Import an step file containing 2 distinct boxes and test topology""" importer = StepImporter(path_from_file(__file__, "./models_in/2_boxes_203.stp")) assert len(importer.shapes) == 1 assert importer.shapes[0].ShapeType() == TopAbs.TopAbs_COMPOUND topo = Topo(importer.shapes[0]) assert topo.number_of_compounds() == 1 assert topo.number_of_comp_solids() == 0 assert topo.number_of_solids() == 2 assert topo.number_of_shells() == 2
def test_step_importer_happy_topology(): r"""import step file containing a box and test topology""" importer = StepImporter(path_from_file(__file__, "./models_in/box_203.stp")) assert len(importer.shapes) == 1 assert isinstance(importer.shapes[0], TopoDS.TopoDS_Shape) assert importer.shapes[0].ShapeType() == TopAbs.TopAbs_SOLID topo = Topo(importer.shapes[0]) assert topo.number_of_compounds() == 0 assert topo.number_of_comp_solids() == 0 assert topo.number_of_solids() == 1 assert topo.number_of_shells() == 1
def test_stl_exporter_overwrite(box_shape): r"""Happy path with a subclass of TopoDS_Shape""" filename = path_from_file(__file__, "./models_out/box.stl") exporter = StlExporter(filename) solid = shape_to_topology(box_shape) assert isinstance(solid, TopoDS.TopoDS_Solid) exporter.set_shape(solid) exporter.write_file() assert os.path.isfile(filename) # read the written box.stl importer = StlImporter(filename) topo = Topo(importer.shape) assert topo.number_of_shells() == 1 # set a sphere and write again with same exporter sphere = BRepPrimAPI.BRepPrimAPI_MakeSphere(10) exporter.set_shape(sphere.Shape()) exporter.write_file() # this creates a file with a sphere only, this is STL specific # check that the file contains the sphere only importer = StlImporter(filename) topo = Topo(importer.shape) assert topo.number_of_shells() == 1 # create a new exporter and overwrite with a box only filename = path_from_file(__file__, "./models_out/box.stl") exporter = StlExporter(filename) solid = shape_to_topology(box_shape) exporter.set_shape(solid) exporter.write_file() assert os.path.isfile(filename) # check the file only contains a box importer = StlImporter(filename) topo = Topo(importer.shape) assert topo.number_of_shells() == 1