Ejemplo n.º 1
0
    def generate_iges(self, filename):
        """
        Export the .iges CAD for the propeller with shaft.

        :param string filename: path (with the file extension) where to store 
            the .iges CAD for the propeller and shaft
        :raises RuntimeError: if the solid assembling of blades is not 
            completed successfully
        """
        iges_writer = IGESControl_Writer()
        iges_writer.AddShape(self.sewed_full_body)
        iges_writer.Write(filename)
Ejemplo n.º 2
0
    def write_shape_to_file(self, shape, filename):
        """
        This class method saves the `shape` to the file `filename`.

        :param: TopoDS_Shape shape: loaded shape
        :param string filename: name of the input file.
            It should have proper extension (.iges or .igs)
        """
        self._check_filename_type(filename)
        self._check_extension(filename)
        IGESControl_Controller_Init()
        writer = IGESControl_Writer()
        writer.AddShape(shape)
        writer.Write(filename)
Ejemplo n.º 3
0
def write_iges_file(a_shape, filename):
    """ exports a shape to a STEP file
    a_shape: the topods_shape to export (a compound, a solid etc.)
    filename: the filename
    application protocol: "AP203" or "AP214"
    """
    # a few checks
    assert not a_shape.IsNull()
    if os.path.isfile(filename):
        print("Warning: %s file already exists and will be replaced" %
              filename)
    # creates and initialise the step exporter
    iges_writer = IGESControl_Writer()
    iges_writer.AddShape(a_shape)
    status = iges_writer.Write(filename)

    assert status == IFSelect_RetDone
    assert os.path.isfile(filename)
def binvox_to_iges(binvox_file, voxel_length, voxel_width, voxel_height):
    """function used to change binvox file to iges file
    binvox_file: the binvox file ('chair.binvox' etc.)
    voxel_length: the length of one voxel
    voxel_width: the width of one voxel
    voxel_height: the height of one voxel
    """
    with open(binvox_file, 'rb') as f:
        model = binvox_rw.read_as_3d_array(f)
    voxel = voxel_to_TopoDS(model, voxel_length, voxel_width, voxel_height)

    # creates and initialise the step exporter
    iges_writer = IGESControl_Writer()
    iges_writer.AddShape(voxel)
    status = iges_writer.Write(binvox_file[:-6] + "iges")

    if status != IFSelect_RetDone:
        raise AssertionError("Not done.")
Ejemplo n.º 5
0
def write_iges_file(a_shape, filename):
    """exports a shape to a STEP file
    a_shape: the topods_shape to export (a compound, a solid etc.)
    filename: the filename
    application protocol: "AP203" or "AP214"
    """
    # a few checks
    if a_shape.IsNull():
        raise AssertionError("Shape is null.")
    if os.path.isfile(filename):
        print(f"Warning: {filename} already exists and will be replaced")
    # creates and initialise the step exporter
    iges_writer = IGESControl_Writer()
    iges_writer.AddShape(a_shape)
    status = iges_writer.Write(filename)

    if status != IFSelect_RetDone:
        raise AssertionError("Not done.")
    if not os.path.isfile(filename):
        raise IOError("File not written to disk.")
Ejemplo n.º 6
0
    def write_file(self):
        r"""Write file

        Returns
        -------
        bool

        """
        IGESControl_Controller().Init()
        iges_writer = 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_RetDone:
            logger.info("IGES file write successful.")
        else:
            msg = "An error occurred while writing the IGES file"
            logger.error(msg)
            raise IgesFileWriteException(msg)
Ejemplo n.º 7
0
Archivo: blade.py Proyecto: o4fr/BladeX
    def generate_iges(self,
                      upper_face=None,
                      lower_face=None,
                      tip=None,
                      maxDeg=1,
                      display=False,
                      errors=None):
        """
        Generate and export the .iges CAD for the blade upper face, lower face,
        and tip. This method requires PythonOCC to be installed.

        :param string upper_face: if string is passed then the method generates
            the blade upper surface using the BRepOffsetAPI_ThruSections
            algorithm, then exports the generated CAD into .iges file holding
            the name <upper_face_string>.iges. Default value is None
        :param string lower_face: if string is passed then the method generates
            the blade lower surface using the BRepOffsetAPI_ThruSections
            algorithm, then exports the generated CAD into .iges file holding
            the name <lower_face_string>.iges. Default value is None
        :param string tip: if string is passed then the method generates
            the blade tip using the BRepOffsetAPI_ThruSections algorithm
            in order to close the blade, then exports the generated CAD into
            .iges file holding the name <tip_string>.iges. Default value is None
        :param int maxDeg: Define the maximal U degree of generated surface.
            Default value is 1
        :param bool display: if True, then display the generated CAD. Default
            value is False
        :param string errors: if string is passed then the method writes out
            the distances between each discrete point used to construct the
            blade and the nearest point on the CAD that is perpendicular to
            that point. Default value is None

        We note that the blade object must have its radial sections be arranged
        in order from the blade root to the blade tip, so that generate_iges
        method can build the CAD surface that passes through the corresponding
        airfoils. Also to be able to identify and close the blade tip.
        """

        from OCC.Core.IGESControl import IGESControl_Writer
        from OCC.Display.SimpleGui import init_display

        if maxDeg <= 0:
            raise ValueError('maxDeg argument must be a positive integer.')

        if upper_face:
            self._check_string(filename=upper_face)
            self._generate_upper_face(maxDeg=maxDeg)
            # Write IGES
            iges_writer = IGESControl_Writer()
            iges_writer.AddShape(self.generated_upper_face)
            iges_writer.Write(upper_face + '.iges')

        if lower_face:
            self._check_string(filename=lower_face)
            self._generate_lower_face(maxDeg=maxDeg)
            # Write IGES
            iges_writer = IGESControl_Writer()
            iges_writer.AddShape(self.generated_lower_face)
            iges_writer.Write(lower_face + '.iges')

        if tip:
            self._check_string(filename=tip)
            self._generate_tip(maxDeg=maxDeg)
            iges_writer = IGESControl_Writer()
            iges_writer.AddShape(self.generated_tip)
            iges_writer.Write(tip + '.iges')

        if errors:
            # Write out errors between discrete points and constructed faces
            self._check_string(filename=errors)
            self._check_errors(upper_face=upper_face, lower_face=lower_face)

            self._write_blade_errors(upper_face=upper_face,
                                     lower_face=lower_face,
                                     errors=errors)

        if display:
            display, start_display, add_menu, add_function_to_menu = init_display(
            )

            ## DISPLAY FACES
            if upper_face:
                display.DisplayShape(self.generated_upper_face, update=True)
            if lower_face:
                display.DisplayShape(self.generated_lower_face, update=True)
            if tip:
                display.DisplayShape(self.generated_tip, update=True)
            start_display()
Ejemplo n.º 8
0
class IgesWrite(object):
    """
    Write shape to an IGES file.

    :param str units: Units to convert IGES file to.
    :param int modecr: Option for writing faces. If 0, faces will be translated
        to IGES 144 (Trimmed Surface) entities. If 1, faces will be translated
        to IGES 510 (Face) entities and the IGES face will contain BRep
        entities.
    """
    def __init__(self, units='inch', modecr=0):
        self._writer = IGESControl_Writer(units, modecr)
        try:
            units = units_dict[units]
        except KeyError:
            units = Settings.units
        Interface_Static.SetCVal('write.step.unit', units)

    @property
    def object(self):
        """
        :return: The IGES writer object.
        :rtype: OCC.Core.IGESControl.IGESControl_Writer
        """
        return self._writer

    def add_shape(self, shape):
        """
        Add the shape to the exported entities.

        :param afem.topology.entities.Shape shape: The shape.

        :return: *True* if shape was transferred, *False* if not.
        :rtype: bool
        """
        return self._writer.AddShape(shape.object)

    def add_geom(self, geom):
        """
        Add the geometry to the exported entities.

        :param OCC.Core.Geom.Geom_Geometry geom: The geometry.

        :return: *True* if shape was transferred, *False* if not.
        :rtype: bool

        .. note::

            The input type in ``Geom_Geometry`` and not the wrapper.
        """
        return self._writer.AddGeom(geom)

    def write(self, fn='afem.igs'):
        """
        Write the IGES file.

        :param str fn: The filename.

        :return: *True* if written, *False* if not.
        :rtype: bool
        """
        return self._writer.Write(fn)
 def write_iges(filename, shape):
     """ IGES writer """
     IGESControl_Controller_Init()
     writer = IGESControl_Writer()
     writer.AddShape(shape)
     writer.Write(filename)