Пример #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)
Пример #2
0
def readStepShape(fileName):
    logging.info("Reading STEP file:'" + fileName + "'...")
    stepReader = STEPControl.STEPControl_Reader()
    stepReader.ReadFile(fileName)

    numItems = stepReader.NbRootsForTransfer()
    numTranslated = stepReader.TransferRoots()
    logging.info("Read " + str(numTranslated) + " from File.")
    shape = stepReader.OneShape()
    logging.info("Done.")
    return shape
Пример #3
0
def readStepShape(fileName):
    log.info("Reading STEP file:'" + fileName + "'...")
    stepReader = STEPControl.STEPControl_Reader()

    if not os.path.exists(fileName):
        raise ValueError, "Error: '%s' Does not Exist!" % fileName

    stepReader.ReadFile(fileName)

    numItems = stepReader.NbRootsForTransfer()
    numTranslated = stepReader.TransferRoots()
    log.info("Read " + str(numTranslated) + " from File.")
    shape = stepReader.OneShape()
    print "Step file is of type %d" % shape.ShapeType()
    log.info("Done.")

    return shape
Пример #4
0
    def read_file(self):
        """
        Read the STEP file and stores the result in a _shapes list
        """
        stepcontrol_reader = STEPControl.STEPControl_Reader()
        status = stepcontrol_reader.ReadFile(self._filename)

        if status == IFSelect.IFSelect_RetDone:
            stepcontrol_reader.PrintCheckLoad(False,
                                              IFSelect.IFSelect_ItemsByEntity)
            nb_roots = stepcontrol_reader.NbRootsForTransfer()
            logger.info("%i root(s)" % nb_roots)
            if nb_roots == 0:
                msg = "No root for transfer"
                logger.error(msg)
                raise ValueError(msg)

            stepcontrol_reader.PrintCheckTransfer(
                False, IFSelect.IFSelect_ItemsByEntity)

            self._number_of_shapes = stepcontrol_reader.NbShapes()

            for n in range(1, nb_roots + 1):
                logger.info("Root index %i" % n)
                ok = stepcontrol_reader.TransferRoot(n)
                logger.info("TransferRoots status : %i" % ok)

                if ok:
                    # for i in range(1, self.nb_shapes + 1):
                    a_shape = stepcontrol_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.info("Appending a %s to list of shapes" %
                                    types_lut.topo_lut[a_shape.ShapeType()])
                else:
                    msg = "One shape could not be transferred"
                    logger.warning(msg)
                    warnings.warn(msg)
            return True
        else:
            msg = "Status is not IFSelect.IFSelect_RetDone"
            logger.error(msg)
            raise ValueError(msg)
Пример #5
0
    def fromSTEP(self, filename, verbose=False):
        '''
     Imports a STEP file to a solid

    :param filename: Path of the file to write STEP to
    :type filename: str
    :param verbose: Choose if you want to see the STEP stats
    :type verbose: bool
    '''
        with self._Verboseness(verbose):
            if filename:
                stepReader = STEPControl.STEPControl_Reader()
                status = stepReader.ReadFile(filename)
                if status:
                    nbr = stepReader.NbRootsForTransfer()
                    for n in range(1, nbr + 1):
                        stepReader.TransferRoot(n)
                        nbs = stepReader.NbShapes()
                        if nbs == 1:
                            if stepReader.Shape(1):
                                self.shape = stepReader.Shape(1)
                                return self
Пример #6
0
 def _readSTEP(self, inputFileName):
     stepReader = STEPControl.STEPControl_Reader()
     stepReader.ReadFile(inputFileName)
     numItems = stepReader.NbRootsForTransfer()
     numTranslated = stepReader.TransferRoots()
     return stepReader.OneShape()