Beispiel #1
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)
Beispiel #2
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)
Beispiel #3
0
    def read_file(self):
        """
        Read the IGES file and stores the result in a list of TopoDS.TopoDS_Shape

        """
        igescontrol_reader = IGESControl.IGESControl_Reader()
        status = igescontrol_reader.ReadFile(self._filename)
        igescontrol_reader.PrintCheckLoad(False, IFSelect.IFSelect_ItemsByEntity)
        nb_roots = igescontrol_reader.NbRootsForTransfer()
        logger.info("Nb roots for transfer : %i" % nb_roots)

        if status == IFSelect.IFSelect_RetDone and nb_roots != 0:

            igescontrol_reader.PrintCheckTransfer(False, IFSelect.IFSelect_ItemsByEntity)
            ok = igescontrol_reader.TransferRoots()
            logger.info("TransferRoots status : %i" % ok)
            self.nb_shapes = igescontrol_reader.NbShapes()

            for n in range(1, nb_roots + 1):

                logger.debug("Root index %i" % n)

                # for i in range(1, self.nb_shapes + 1):
                a_shape = igescontrol_reader.Shape(n)
                if a_shape.IsNull():
                    msg = "At least one shape in IGES cannot be transferred"
                    logger.warning(msg)
                else:
                    self._shapes.append(a_shape)
                    logger.debug("Appending a %s to list of shapes" %
                                 topo_lut[a_shape.ShapeType()])
        else:
            msg = "Status is not IFSelect.IFSelect_RetDone or No root for transfer"
            logger.error(msg)
            raise ValueError(msg)
Beispiel #4
0
    def write_file(self):
        r"""Write file

        Returns
        -------
        bool

        """
        IGESControl.IGESControl_Controller().Init()
        iges_writer = IGESControl.IGESControl_Writer("write.iges.unit", self._brepmode)
        for shape in self._shapes:
            iges_writer.AddShape(shape)
        iges_writer.ComputeModel()

        write_status = iges_writer.Write(self._filename)

        if write_status == IFSelect.IFSelect_RetDone:
            logger.info("IGES file write successful.")
        else:
            msg = "An error occurred while writing the IGES file"
            logger.error(msg)
            raise ValueError(msg)