コード例 #1
0
class ExportMethod (object):

    def __init__(self, tol=1.0E-6):
        self.obj = STEPControl_Writer()
        self.obj.SetTolerance(tol)
        Interface_Static_SetCVal("write.step.schema", "AP214")

        """
        self.obj.PrintStatsTransfer:
        what
        0 gives general statistics (number of translated roots, number of warnings, number of fail messages),
        1 gives root results,
        2 gives statistics for all checked entities,
        3 gives the list of translated entities,
        4 gives warning and fail messages,
        5 gives fail messages only. The use of mode depends on the value of what. If what is 0, mode is ignored. 
        
        If what is 1, 2 or 3, mode defines the following:
        0 lists the numbers of IGES or STEP entities in the respective model
        1 gives the number, identifier, type and result type for each IGES or STEP entity and/or its status (fail, warning, etc.)
        2 gives maximum information for each IGES or STEP entity (i.e. checks)
        3 gives the number of entities per type of IGES or STEP entity
        4 gives the number of IGES or STEP entities per result type and/or status
        5 gives the number of pairs (IGES or STEP or result type and status)
        6 gives the number of pairs (IGES or STEP or result type and status) AND the list of entity numbers in the IGES or STEP model. 
        
        If what is 4 or 5, mode defines the warning and fail messages as follows:
        if mode is 0 all warnings and checks per entity are returned
        if mode is 2 the list of entities per warning is returned. If mode is not set, only the list of all entities per warning is given.
        """

    def add_shpe(self, shape):
        """
        STEPControl_AsIs                   translates an Open CASCADE shape to its highest possible STEP representation.
        STEPControl_ManifoldSolidBrep      translates an Open CASCADE shape to a STEP manifold_solid_brep or brep_with_voids entity.
        STEPControl_FacetedBrep            translates an Open CASCADE shape into a STEP faceted_brep entity.
        STEPControl_ShellBasedSurfaceModel translates an Open CASCADE shape into a STEP shell_based_surface_model entity.
        STEPControl_GeometricCurveSet      translates an Open CASCADE shape into a STEP geometric_curve_set entity.
        """
        self.obj.Transfer(shape, STEPControl_AsIs)

    def fileout(self, filename):
        status = self.obj.Write(filename)
        assert(status == IFSelect_RetDone)
コード例 #2
0
ファイル: occ_step.py プロジェクト: tnakaicode/OCCGO
class ExportCAFMethod(object):
    def __init__(self, name="name", tol=1.0E-10):
        self.name = name
        self.schema = 'AP214'
        self.assembly_mode = 1

        self.stp = STEPControl_Writer()
        self.stp.SetTolerance(tol)
        self.app = self.stp.WS().TransferWriter().FinderProcess()
        Interface_Static_SetCVal('write.step.schema', self.schema)
        Interface_Static_SetCVal('write.step.unit', 'MM')
        Interface_Static_SetCVal('write.step.assembly',
                                 str(self.assembly_mode))

        # Interface_Static_SetCVal ("write.step.schema","AP203")
        # Interface_Static_SetIVal ("write.step.schema", 3)
        # Interface_Static_SetRVal

    def Add(self, shape, name="name"):
        """
        STEPControl_AsIs                   translates an Open CASCADE shape to its highest possible STEP representation.
        STEPControl_ManifoldSolidBrep      translates an Open CASCADE shape to a STEP manifold_solid_brep or brep_with_voids entity.
        STEPControl_FacetedBrep            translates an Open CASCADE shape into a STEP faceted_brep entity.
        STEPControl_ShellBasedSurfaceModel translates an Open CASCADE shape into a STEP shell_based_surface_model entity.
        STEPControl_GeometricCurveSet      translates an Open CASCADE shape into a STEP geometric_curve_set entity.
        """
        Interface_Static_SetCVal('write.step.product.name', name)
        self.stp.Transfer(shape, STEPControl_AsIs)
        item = stepconstruct_FindEntity(self.app, shape)
        item.SetName(TCollection_HAsciiString(name))

    def Write(self, filename=None):
        if not filename:
            filename = self.name
        path, ext = os.path.splitext(filename)
        if not ext:
            ext = ".stp"
        status = self.stp.Write(path + ext)
        assert (status == IFSelect_RetDone)
コード例 #3
0
ファイル: step.py プロジェクト: khabya/aoc-xchange
class StepExporter(object):
    r"""STEP file exporter

    Parameters
    ----------
    filename : str
        the file to save to eg. myshape.step
    verbose : bool
        verbosity of the STEP exporter
    schema : ["AP203", "AP214CD"]
        which STEP schema to use, either AP214CD or AP203
    tolerance : float

    """
    def __init__(self,
                 filename,
                 verbose=False,
                 schema="AP214CD",
                 tolerance=1e-4):
        logger.info("StepExporter instantiated with filename : %s" % filename)
        logger.info("StepExporter schema : %s" % schema)
        logger.info("StepExporter tolerance : %s" % str(tolerance))

        if schema not in ["AP203", "AP214CD"]:
            msg = "Unsupported STEP schema"
            logger.error(msg)
            raise StepUnknownSchemaException(msg)

        check_exporter_filename(filename, step_extensions)
        check_overwrite(filename)

        self._filename = filename
        self._shapes = list()
        self.verbose = verbose

        self._stepcontrol_writer = STEPControl_Writer()
        self._stepcontrol_writer.SetTolerance(tolerance)

        Interface_Static_SetCVal("write.step.schema", schema)

    def add_shape(self, a_shape):
        r"""Add a shape to export

        Parameters
        ----------
        a_shape : TopoDS_Shape or subclass

        """
        check_shape(a_shape)  # raises an exception if the shape is not valid
        self._shapes.append(a_shape)

    def write_file(self):
        r"""Write STEP file"""
        for shp in self._shapes:
            transfer_status = self._stepcontrol_writer.Transfer(
                shp, STEPControl_AsIs)
            if transfer_status != IFSelect_RetDone:
                msg = "An error occurred while transferring a " \
                      "shape to the STEP writer"
                logger.error(msg)
                raise StepShapeTransferException(msg)

        write_status = self._stepcontrol_writer.Write(self._filename)

        if self.verbose:
            self._stepcontrol_writer.PrintStatsTransfer()

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