Esempio n. 1
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)
Esempio n. 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)
Esempio n. 3
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
Esempio n. 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)
def split_shape(event=None):
    S = BRepPrimAPI_MakeBox(gp_Pnt(-100,-60,-80),150,200,170).Shape()     
    
    asect = BRepAlgoAPI_Section(S, gp_Pln(1,2,1,-15),False)
    asect.ComputePCurveOn1(True)    
    asect.Approximation(True)    
    asect.Build()    
    R = asect.Shape()    

    asplit = BRepFeat_SplitShape(S)    
    
    for edg in Topo(R).edges():
        face = TopoDS.TopoDS_face(TopoDS.TopoDS_Shape())
        if asect.HasAncestorFaceOn1(edg, face):
            asplit.Add(edg, face)
        
    asplit.Build()    
    display.EraseAll()
    display.DisplayShape(asplit.Shape())    
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()
Esempio n. 7
0
def test_check_shape():
    r"""check_shape() tests"""
    # Null shapes should raise a ValueError
    with pytest.raises(ValueError):
        check_shape(TopoDS.TopoDS_Shape())
    with pytest.raises(ValueError):
        check_shape(TopoDS.TopoDS_Shell())

    builderapi_makeedge = BRepBuilderAPI.BRepBuilderAPI_MakeEdge(
        gp.gp_Pnt(), gp.gp_Pnt(10, 10, 10))
    shape = builderapi_makeedge.Shape()

    # a ValueError should be raised is check_shape() is not give a TopoDS_Shape or subclass
    with pytest.raises(ValueError):
        check_shape(gp.gp_Pnt())
    with pytest.raises(ValueError):
        check_shape(builderapi_makeedge)

    # a TopoDS_Shape should pass the check without raising any exception
    check_shape(shape)

    # a subclass of shape should not raise any exception
    check_shape(next(Topo(shape).edges()))
Esempio n. 8
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
Esempio n. 9
0
from OCC.Display.SimpleGui import *
from OCC import BRep
from OCC.BRepTools import *
from OCC import TopoDS
from OCC.Message import Message_PrinterOStream
import sys

fileName = 'input.brp'
if (len(sys.argv) > 1):
    fileName = sys.argv[1]

brep_instance = BRepTools()
shape = TopoDS.TopoDS_Shape()
builder = BRep.BRep_Builder()
printrerStream = Message_PrinterOStream()
s = printrerStream.GetStream()
brep_instance.Read(shape, str(fileName), builder)
Esempio n. 10
0
 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
Esempio n. 11
0
 def _readSTL(self, inputFileName):
     ts = TopoDS.TopoDS()
     shape = TopoDS.TopoDS_Shape()
     stl_reader = StlAPI.StlAPI_Reader()
     stl_reader.Read(shape, inputFileName)
     return shape