示例#1
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)
示例#2
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)