Ejemplo n.º 1
0
 def read_file(self):
     """
     Read the IGES file and stores the result in a list of TopoDS_Shape
     """
     aReader = IGESControl_Reader()
     status = aReader.ReadFile(self._filename)
     if status == IFSelect_RetDone:
         failsonly = False
         aReader.PrintCheckLoad(failsonly, IFSelect_ItemsByEntity)
         nbr = aReader.NbRootsForTransfer()
         aReader.PrintCheckTransfer(failsonly, IFSelect_ItemsByEntity)
         # ok = aReader.TransferRoots()
         for n in range(1, nbr+1):
             self.nbs = aReader.NbShapes()
             if self.nbs == 0:
                 print("At least one shape in IGES cannot be transfered")
             elif nbr == 1 and self.nbs == 1:
                 aResShape = aReader.Shape(1)
                 if aResShape.IsNull():
                     print("At least one shape in IGES cannot be transferred")
                 self._shapes.append(aResShape)
             else:
                 for i in range(1, self.nbs+1):
                     aShape = aReader.Shape(i)
                     if aShape.IsNull():
                         print("At least one shape in STEP cannot be transferred")
                     else:
                         self._shapes.append(aShape)
         return True
     else:
         print("Error: can't read file %s" % self._filename)
         return False
     return False
Ejemplo n.º 2
0
def read_iges_file(filename,
                   return_as_shapes=False,
                   verbosity=False,
                   visible_only=False):
    """ read the IGES file and returns a compound
    filename: the file path
    return_as_shapes: optional, False by default. If True returns a list of shapes,
                      else returns a single compound
    verbosity: optionl, False by default.
    """
    if not os.path.isfile(filename):
        raise FileNotFoundError("%s not found." % filename)

    iges_reader = IGESControl_Reader()
    iges_reader.SetReadVisible(visible_only)
    status = iges_reader.ReadFile(filename)

    _shapes = []

    if status == IFSelect_RetDone:  # check status
        if verbosity:
            failsonly = False
            iges_reader.PrintCheckLoad(failsonly, IFSelect_ItemsByEntity)
            iges_reader.PrintCheckTransfer(failsonly, IFSelect_ItemsByEntity)
        iges_reader.TransferRoots()
        nbr = iges_reader.NbRootsForTransfer()
        for n in range(1, nbr + 1):
            nbs = iges_reader.NbShapes()
            if nbs == 0:
                print("At least one shape in IGES cannot be transfered")
            elif nbr == 1 and nbs == 1:
                a_res_shape = iges_reader.Shape(1)
                if a_res_shape.IsNull():
                    print("At least one shape in IGES cannot be transferred")
                else:
                    _shapes.append(a_res_shape)
            else:
                for i in range(1, nbs + 1):
                    a_shape = iges_reader.Shape(i)
                    if a_shape.IsNull():
                        print(
                            "At least one shape in STEP cannot be transferred")
                    else:
                        _shapes.append(a_shape)
    # if not return as shapes
    # create a compound and store all shapes
    if not return_as_shapes:
        builder = BRep_Builder()
        compound = TopoDS_Compound()
        builder.MakeCompound(compound)
        for s in _shapes:
            builder.Add(compound, s)
        _shapes = compound
    return _shapes
Ejemplo n.º 3
0
    def read_file(self):
        """
        Read the IGES file and stores the result in a list of TopoDS_Shape

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

        if status == IFSelect_RetDone and nb_roots != 0:

            igescontrol_reader.PrintCheckTransfer(False,
                                                  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_types_dict[a_shape.ShapeType()])
        else:
            msg = "Status is not IFSelect_RetDone or No root for transfer"
            logger.error(msg)
            raise IgesFileReadException(msg)