def oglLinkToXml(self, oglLink: OglLink, xmlDoc: Document):
        """
        Export an OgLink to a minidom element
        Args:
            oglLink:    OglLink to convert
            xmlDoc:     xml document

        Returns:
            A new minidom element
        """
        root = xmlDoc.createElement(PyutXmlConstants.ELEMENT_GRAPHIC_LINK)

        # save source and destination anchor points
        x, y = oglLink.GetSource().GetModel().GetPosition()
        simpleX, simpleY = self.__getSimpleCoordinates(x, y)
        root.setAttribute(PyutXmlConstants.ATTR_LINK_SOURCE_ANCHOR_X, simpleX)
        root.setAttribute(PyutXmlConstants.ATTR_LINK_SOURCE_ANCHOR_Y, simpleY)

        x, y = oglLink.GetDestination().GetModel().GetPosition()
        simpleX, simpleY = self.__getSimpleCoordinates(x, y)

        root.setAttribute(PyutXmlConstants.ATTR_LINK_DESTINATION_ANCHOR_X,
                          simpleX)
        root.setAttribute(PyutXmlConstants.ATTR_LINK_DESTINATION_ANCHOR_Y,
                          simpleY)

        root.setAttribute(PyutXmlConstants.ATTR_SPLINE,
                          str(oglLink.GetSpline()))

        if isinstance(oglLink, OglAssociation):

            center = oglLink.getLabels()[CENTER]
            src = oglLink.getLabels()[SRC_CARD]
            dst = oglLink.getLabels()[DEST_CARD]

            assocLabels = {
                PyutXmlConstants.ELEMENT_ASSOC_CENTER_LABEL: center,
                PyutXmlConstants.ELEMENT_ASSOC_SOURCE_LABEL: src,
                PyutXmlConstants.ELEMENT_ASSOC_DESTINATION_LABEL: dst
            }
            for eltName in assocLabels:
                elt: Element = self.__createAssocLabelElement(
                    eltName, xmlDoc, assocLabels[eltName])
                root.appendChild(elt)

        # save control points (not anchors!)
        for x, y in oglLink.GetSegments()[1:-1]:
            item = xmlDoc.createElement(
                PyutXmlConstants.ELEMENT_MODEL_CONTROL_POINT)
            item.setAttribute(PyutXmlConstants.ATTR_X, str(x))
            item.setAttribute(PyutXmlConstants.ATTR_Y, str(y))
            root.appendChild(item)

        # adding the data layer object

        root.appendChild(self._pyutLinkToXml(oglLink.getPyutObject(), xmlDoc))

        return root
Exemple #2
0
    def _OglLink2xml(self, oglLink: OglLink, xmlDoc: Document):
        """
        """
        root = xmlDoc.createElement('GraphicLink')

        # Append OGL object base
        # save src and dst anchor points
        x, y = oglLink.GetSource().GetModel().GetPosition()
        root.setAttribute('srcX', str(x))
        root.setAttribute('srcY', str(y))

        x, y = oglLink.GetDestination().GetModel().GetPosition()
        root.setAttribute('dstX', str(x))
        root.setAttribute('dstY', str(y))

        root.setAttribute('spline', str(oglLink.GetSpline()))

        if isinstance(oglLink, OglAssociation):

            center: OglAssociationLabel = oglLink.centerLabel
            src: OglAssociationLabel = oglLink.sourceCardinality
            dst: OglAssociationLabel = oglLink._destinationCardinality

            label = xmlDoc.createElement("LabelCenter")
            root.appendChild(label)

            label.setAttribute("x", str(center.oglPosition.x))
            label.setAttribute("y", str(center.oglPosition.y))
            label = xmlDoc.createElement("LabelSrc")
            root.appendChild(label)

            label.setAttribute("x", str(src.oglPosition.x))
            label.setAttribute("y", str(src.oglPosition.y))
            label = xmlDoc.createElement("LabelDst")
            root.appendChild(label)

            label.setAttribute("x", str(dst.oglPosition.x))
            label.setAttribute("y", str(dst.oglPosition.y))

        # save control points (not anchors!)
        for x, y in oglLink.GetSegments()[1:-1]:
            item = xmlDoc.createElement('ControlPoint')
            item.setAttribute('x', str(x))
            item.setAttribute('y', str(y))
            root.appendChild(item)

        # adding the data layer object
        root.appendChild(self._PyutLink2xml(oglLink.getPyutObject(), xmlDoc))

        return root