Exemple #1
0
    def export_step(self, fn, label_solids=True, label_faces=False,
                    names=None):
        """
        Export the OpenVSP model as a STEP file using Extended Data Exchange.
        Each OpenVSP component will be a named product in the STEP file
        structure.

        :param str fn: The filename.
        :param bool label_solids: Option to label the solid bodies in the
            STEP entity. The name will be the same as the OpenVSP component.
        :param bool label_faces: Option to label the faces in each of the
            solids. Each face of the solid body will be labeled "Face 1",
            "Face 2", etc.
        :param names: List of Body names that will be included in export. If
            *None* then all are exported.
        :type names: collections.Sequence(str) or None

        :return: None.
        """
        # Initialize the document
        doc = XdeDocument()

        # Get bodies to include
        if names is None:
            bodies = self.all_bodies
        else:
            bodies = [self.get_body(name) for name in names]

        # Gather OpenVSP bodies and names and build single compound
        solids = []
        names = []
        for body in bodies:
            solids.append(body.shape)
            names.append(body.name)
        cmp = Compound.by_shapes(solids)

        # Add main shape and top-level assembly
        main = doc.add_shape(cmp, 'Vehicle')

        # Each body should be a product so names are transferred to other
        # CAD systems
        for name, solid in zip(names, solids):
            doc.add_subshape(main, solid, name)

        # Transfer the document and then modify the STEP item name directly
        # rather than using a label. This only applies when labeling
        # sub-shapes.
        doc.transfer_step()
        if label_solids or label_faces:
            for name, solid in zip(names, solids):
                if label_solids:
                    doc.set_shape_name(solid, name)
                if label_faces:
                    i = 1
                    for f in solid.faces:
                        name = ' '.join(['Face', str(i)])
                        doc.set_shape_name(f, name)
                        i += 1

        doc.write_step(fn)
Exemple #2
0
    def save_model(cls, fn, binary=True):
        """
        Save the model.

        :param str fn: The filename.
        :param bool binary: If *True*, the document will be saved in a binary
            format. If *False*, the document will be saved in an XML format.

        :return: *True* if saved, *False* otherwise.
        :rtype: bool
        """
        group = cls.get_master()

        # Create document and application
        doc = XdeDocument(binary)

        # Store parts as top-level shapes
        # TODO Support group hierarchy
        parts = group.get_parts()
        for part in parts:
            name = doc.add_shape(part.shape, part.name, False)
            name.set_string(part.type)
            name.set_color(part.color)

            # Reference curve
            if part.has_cref:
                edge = EdgeByCurve(part.cref).edge
                name = doc.add_shape(edge, part.name, False)
                name.set_string('CREF')

            # Reference surface
            if part.has_sref:
                face = FaceBySurface(part.sref).face
                name = doc.add_shape(face, part.name, False)
                name.set_string('SREF')

        return doc.save_as(fn)
Exemple #3
0
    def save_bodies(fn, bodies, binary=True):
        """
        Save Body instances.

        :param str fn: The filename.
        :param collections.Sequence(afem.oml.entities.Body) bodies: The Body
            instances
        :param bool binary: If *True*, the document will be saved in a binary
            format. If *False*, the document will be saved in an XML format.

        :return: *True* if saved, *False* otherwise.
        :rtype: bool

        .. note::

            This method only saves the name, shape, reference surface, and
            color of the Body. Other user-defined metadata is currently not
            saved.
        """
        from afem.exchange.xde import XdeDocument
        # Create document
        doc = XdeDocument(binary)

        # Add the bodies
        for body in bodies:
            label = doc.add_shape(body.shape, body.name, False)
            label.set_string('Body')
            label.set_color(body.color)

            # Sref
            if body.sref is not None:
                face = FaceBySurface(body.sref).face
                label = doc.add_shape(face, body.name, False)
                label.set_string('SREF')

        return doc.save_as(fn)