예제 #1
0
def file_to_shape(pth):
    '''get a Shape from an .iges or .step file'''
    assert os.path.isfile(pth), '%s is not a valid directory' % (pth)
    ext = os.path.splitext(pth)[1]
    print 'ext', ext
    assert ext in ['.iges', '.igs', '.stp', '.step', '.brep',
                   '.stl'], '%s is not an readable format' % (ext)

    if ext in ['.iges', '.igs']:
        __i = IGESControl_Controller()
        __i.Init()
        reader = IGESControl_Reader()

    elif ext in ['.step', '.stp']:
        reader = STEPControl_Reader()

    elif ext == '.brep':
        from OCC import TopoDS, BRep, BRepTools
        shape = TopoDS.TopoDS_Shape()
        builder = BRep.BRep_Builder()
        BRepTools.BRepTools().Read(shape, pth, builder)
        return shape

    elif ext == '.stl':
        from OCC import TopoDS, StlAPI
        shape = TopoDS.TopoDS_Shape()
        stl_reader = StlAPI.StlAPI_Reader()
        stl_reader.Read(shape, pth)
        return shape

    reader.ReadFile(pth)
    n_translated = reader.TransferRoots()
    shape = reader.OneShape()
    del reader
    return shape
예제 #2
0
 def LoadFile(self, filename):
     extension = os.path.basename(filename).split(".").pop().lower()
     start_time = time.time()
     if extension =="step" or extension == "stp":
         stepReader = STEPControl.STEPControl_Reader()
         stepReader.ReadFile(str(filename))
         numTranslated = stepReader.TransferRoots()
         shape = stepReader.OneShape()
     elif extension == "stl":
         shape = TopoDS.TopoDS_Shape()
         stl_reader = StlAPI.StlAPI_Reader()
         stl_reader.Read(shape,str(filename))
     elif extension =="iges" or extension =="igs":
         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":
         shape = TopoDS.TopoDS_Shape()
         builder = BRep.BRep_Builder()
         BRepTools.BRepTools().Read(shape,str(filename),builder)
     else:
         return True
     self.canva._3dDisplay.EraseAll()
     self.canva._3dDisplay.DisplayShape(shape)
     wx.SafeYield()
     self.canva._3dDisplay.View_Iso()
     self.canva._3dDisplay.FitAll()
     end_time = time.time()
     self.SetTitle("pythonOCC Interactive Console %s:%s"%(VERSION,filename))
     duration = end_time-start_time
     print "%s STEP file loaded and displayed in %f seconds."%(filename,duration)
예제 #3
0
 def LoadFile(self,filename):
    extension = os.path.basename(filename).split(".").pop().lower()
    start_time = time.time()
    if extension =="step" or extension == "stp":
        from OCC.Utils.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)
예제 #4
0
def readSTLShape(fileName):

    ts = TopoDS.TopoDS()

    log.info("Reading STL:'" + fileName + "'...")
    #read stl file
    shape = TopoDS.TopoDS_Shape()
    stl_reader = StlAPI.StlAPI_Reader()
    stl_reader.Read(shape, fileName)
    return fixShape(shape)
예제 #5
0
def readSTLShape(fileName):
    ts = TopoDS.TopoDS()

    logging.info("Reading STL:'" + fileName + "'...")
    #read stl file
    shape = TopoDS.TopoDS_Shape()
    stl_reader = StlAPI.StlAPI_Reader()
    stl_reader.Read(shape, fileName)
    logging.info("Fixing holes and degenerated Meshes...")
    sf = ShapeFix.ShapeFix_Shape(shape)
    sf.Perform()
    fixedShape = sf.Shape()
    logging.info("Making Solid from the Shell...")
    #bb = BRepBuilderAPI.BRepBuilderAPI_MakeSolid(ts.Shell(fixedShape));
    #bb.Build();
    bb = ShapeFix.ShapeFix_Solid()
    return bb.SolidFromShell(ts.Shell(fixedShape))
    logging.info("Done.")
    return bb.Solid()
예제 #6
0
 def read_file(self):
     r"""Read the STL file and stores the result in a TopoDS_Shape"""
     stl_reader = StlAPI.StlAPI_Reader()
     shape = TopoDS.TopoDS_Shape()
     stl_reader.Read(shape, self._filename)
     self._shape = shape
예제 #7
0
 def _readSTL(self, inputFileName):
     ts = TopoDS.TopoDS()
     shape = TopoDS.TopoDS_Shape()
     stl_reader = StlAPI.StlAPI_Reader()
     stl_reader.Read(shape, inputFileName)
     return shape