def LoadFile(self, filename): extension = os.path.basename(filename).split(".").pop().lower() start_time = time.time() if extension == "step" or extension == "stp": from occaddons.dataexchange.step import StepImporter stepReader = StepImporter(str(filename)) stepReader.read_file() shape = stepReader.get_shapes() elif extension == "stl": from OCC import TopoDS, StlAPI shape = TopoDS.TopoDS_Shape() stl_reader = StlAPI.StlAPI_Reader() stl_reader.Read(shape, str(filename)) elif extension == "iges" or extension == "igs": from OCC import IGESControl i = IGESControl.IGESControl_Controller() i.Init() iges_reader = IGESControl.IGESControl_Reader() iges_reader.ReadFile(str(filename)) iges_reader.TransferRoots() shape = iges_reader.OneShape() elif extension == "brep": from OCC import TopoDS, BRep, BRepTools shape = TopoDS.TopoDS_Shape() builder = BRep.BRep_Builder() BRepTools.breptools_Read(shape, str(filename), builder) else: return True self.canva._display.DisplayShape(shape) end_time = time.time() self.SetTitle("CAD Viewer - pythonOCC %s:%s" % (VERSION, filename)) duration = end_time-start_time print("%s STEP file loaded and displayed in %f seconds." % (filename, duration))
def read_file(self): r"""Read the BREP file and stores the result in a TopoDS_Shape""" shape = TopoDS.TopoDS_Shape() builder = BRep.BRep_Builder() BRepTools.breptools_Read(shape, self._filename, builder) self._shape = shape