Exemple #1
0
    def _createAnchorPoints(
            self, srcShape: OglSDInstance, dstShape: OglSDInstance,
            pyutSDMessage: PyutSDMessage) -> Tuple[AnchorPoint, AnchorPoint]:
        """
        Royal ready to heat rice

        Args:
            dstShape:
            srcShape:
            pyutSDMessage

        Returns:  A tuple of anchor points for the source and destination shapes

        """
        srcY: float = pyutSDMessage.getSrcY() - srcShape.getLifeLineShape(
        ).GetPosition()[1]
        dstY: float = pyutSDMessage.getDstY() - dstShape.getLifeLineShape(
        ).GetPosition()[1]

        srcAnchor: AnchorPoint = srcShape.getLifeLineShape().AddAnchor(0, srcY)
        dstAnchor: AnchorPoint = dstShape.getLifeLineShape().AddAnchor(0, dstY)
        srcAnchor.SetStayOnBorder(False)
        dstAnchor.SetStayOnBorder(False)
        srcAnchor.SetStayInside(True)
        dstAnchor.SetStayInside(True)
        srcAnchor.SetVisible(True)
        dstAnchor.SetVisible(True)
        srcAnchor.SetDraggable(True)
        dstAnchor.SetDraggable(True)

        return srcAnchor, dstAnchor
    def _pyutSDMessageToXml(self, pyutSDMessage: PyutSDMessage,
                            xmlDoc: Document) -> Element:
        """
        Exporting a PyutSDMessage to an minidom Element.
        Args:
            pyutSDMessage:  SDMessage to export
            xmlDoc:         xml document

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

        eltId = self._idFactory.getID(pyutSDMessage)
        root.setAttribute(PyutXmlConstants.ATTR_ID, str(eltId))

        # message
        root.setAttribute(PyutXmlConstants.ATTR_MESSAGE,
                          pyutSDMessage.getMessage())

        # time
        idSrc = self._idFactory.getID(pyutSDMessage.getSource())
        idDst = self._idFactory.getID(pyutSDMessage.getDest())
        root.setAttribute(PyutXmlConstants.ATTR_SOURCE_TIME_LINE,
                          str(pyutSDMessage.getSrcTime()))
        root.setAttribute(PyutXmlConstants.ATTR_DESTINATION_TIME_LINE,
                          str(pyutSDMessage.getDstTime()))
        root.setAttribute(PyutXmlConstants.ATTR_SD_MESSAGE_SOURCE_ID,
                          str(idSrc))
        root.setAttribute(PyutXmlConstants.ATTR_SD_MESSAGE_DESTINATION_ID,
                          str(idDst))

        return root
    def createNewLink(self, src, dst, srcPos=None, dstPos=None):
        """
        Adds an OglSDMessage link between src and dst.

        Args:
            src:    source of the link
            dst:    destination of the link
            srcPos: position on source
            dstPos: position on  destination

        Returns: the created OglSDMessage link
        """
        srcTime = src.ConvertCoordToRelative(0, srcPos[1])[1]
        dstTime = dst.ConvertCoordToRelative(0, dstPos[1])[1]
        pyutLink = PyutSDMessage("msg test", src.getPyutObject(), srcTime,
                                 dst.getPyutObject(), dstTime)

        oglLink = OglSDMessage(src, pyutLink, dst)
        pyutLink.setOglObject(oglLink)

        src.addLink(oglLink)
        dst.addLink(oglLink)
        self._diagram.AddShape(oglLink)

        self.Refresh()

        return oglLink
Exemple #4
0
    def _PyutSDMessage2xml(self, pyutSDMessage: PyutSDMessage,
                           xmlDoc: Document):
        """
        Exporting an PyutSDMessage to an miniDom Element.

        @param pyutSDMessage : SDMessage to save
        @param xmlDoc : xml document
        @return Element : XML Node
        """
        root = xmlDoc.createElement('SDMessage')

        # ID
        eltId = self._idFactory.getID(pyutSDMessage)
        root.setAttribute('id', str(eltId))

        # message
        root.setAttribute('message', pyutSDMessage.getMessage())

        # time
        idSrc = self._idFactory.getID(pyutSDMessage.getSource())
        idDst = self._idFactory.getID(pyutSDMessage.getDest())
        root.setAttribute('srcTime', str(pyutSDMessage.getSrcTime()))
        root.setAttribute('dstTime', str(pyutSDMessage.getDstTime()))
        root.setAttribute('srcID', str(idSrc))
        root.setAttribute('dstID', str(idDst))

        return root
Exemple #5
0
    def _createSDMessage(self, src: OglSDInstance, dest: OglSDInstance,
                         srcPos: Point, destPos: Point) -> OglSDMessage:

        srcRelativeCoordinates: Tuple[int, int] = src.ConvertCoordToRelative(
            0, srcPos[1])
        destRelativeCoordinates: Tuple[int, int] = dest.ConvertCoordToRelative(
            0, destPos[1])

        srcY = srcRelativeCoordinates[1]
        destY = destRelativeCoordinates[1]

        pyutSDMessage = PyutSDMessage(CreateOglLinkCommand.NO_NAME_MESSAGE,
                                      src.getPyutObject(), srcY,
                                      dest.getPyutObject(), destY)

        oglLinkFactory = getOglLinkFactory()
        oglSdMessage: OglSDMessage = oglLinkFactory.getOglLink(
            srcShape=src,
            pyutLink=pyutSDMessage,
            destShape=dest,
            linkType=LinkType.SD_MESSAGE,
            srcPos=srcPos,
            dstPos=destPos)

        return oglSdMessage
Exemple #6
0
    def getOglSDMessages(self, xmlOglSDMessages: NodeList, oglSDInstances: OglSDInstances) -> OglSDMessages:
        """
        Parse the given XML elements and build data layer for PyUT sequence diagram messages.

        Args:
            xmlOglSDMessages:
            oglSDInstances:

        Returns:
            A dictionary of OglSDMessage objects
        """
        oglSDMessages: OglSDMessages = cast(OglSDMessages, {})

        for xmlOglSDMessage in xmlOglSDMessages:

            # Data layer class
            xmlPyutSDMessage: Element = xmlOglSDMessage.getElementsByTagName(PyutXmlConstants.ELEMENT_MODEL_SD_MESSAGE)[0]

            # Building OGL
            pyutSDMessage: PyutSDMessage = PyutSDMessage()

            srcID: int = int(xmlPyutSDMessage.getAttribute(PyutXmlConstants.ATTR_SD_MESSAGE_SOURCE_ID))
            dstID: int = int(xmlPyutSDMessage.getAttribute(PyutXmlConstants.ATTR_SD_MESSAGE_DESTINATION_ID))
            srcTime: int = PyutUtils.strFloatToInt(xmlPyutSDMessage.getAttribute(PyutXmlConstants.ATTR_SOURCE_TIME_LINE))
            dstTime: int = PyutUtils.strFloatToInt(xmlPyutSDMessage.getAttribute(PyutXmlConstants.ATTR_DESTINATION_TIME_LINE))
            srcOgl = oglSDInstances[srcID]
            dstOgl = oglSDInstances[dstID]

            oglSDMessage: OglSDMessage = OglSDMessage(srcOgl, pyutSDMessage, dstOgl)
            pyutSDMessage.setOglObject(oglSDMessage)
            pyutSDMessage.setSource(srcOgl.getPyutObject(), srcTime)
            pyutSDMessage.setDestination(dstOgl.getPyutObject(), dstTime)

            # Pyut Data
            pyutSDMessage.setId(int(xmlPyutSDMessage.getAttribute(PyutXmlConstants.ATTR_ID)))
            pyutSDMessage.setMessage(xmlPyutSDMessage.getAttribute(PyutXmlConstants.ATTR_MESSAGE))

            oglSDMessages[pyutSDMessage.getId()] = oglSDMessage

            # Adding OGL class to UML Frame
            # diagram = umlFrame.GetDiagram()
            oglSDInstances[srcID].addLink(oglSDMessage)
            oglSDInstances[dstID].addLink(oglSDMessage)
            # diagram.AddShape(oglSDMessage)

        return oglSDMessages
Exemple #7
0
    def __init__(self, srcShape: OglSDInstance, pyutSDMessage: PyutSDMessage,
                 dstShape: OglSDInstance):
        """

        Args:
            srcShape:   Source shape OglSDInstance
            pyutSDMessage:  PyutSDMessage
            dstShape:   Destination shape OglSDInstance

        """
        self._pyutSDMessage = pyutSDMessage

        super().__init__(srcShape=srcShape,
                         pyutLink=pyutSDMessage,
                         dstShape=dstShape)
        # LineShape.__init__(self, srcAnchor=srcAnchor, dstAnchor=dstAnchor)
        #
        # Override OglLink anchors
        #
        srcAnchor, dstAnchor = self._createAnchorPoints(
            srcShape=srcShape, pyutSDMessage=pyutSDMessage, dstShape=dstShape)
        srcAnchorPosition = srcAnchor.GetPosition()
        dstAnchorPosition = dstAnchor.GetPosition()

        self._srcAnchor: AnchorPoint = srcAnchor
        self._dstAnchor: AnchorPoint = dstAnchor

        oglSource: OglPosition = OglPosition.tupleToOglPosition(
            srcAnchorPosition)
        oglDestination: OglPosition = OglPosition.tupleToOglPosition(
            dstAnchorPosition)
        linkLength: float = self._computeLinkLength(
            srcPosition=oglSource, destPosition=oglDestination)
        dx, dy = self._computeDxDy(srcPosition=oglSource,
                                   destPosition=oglDestination)

        centerMessageX: int = round(-dy * 5 / linkLength)
        centerMessageY: int = round(dx * 5 / linkLength)

        self._messageLabel: TextShape = self.AddText(
            centerMessageX, centerMessageY,
            pyutSDMessage.getMessage())  # font=self._defaultFont

        self.updateMessage()
        self.SetDrawArrow(True)
Exemple #8
0
    def __init__(self, srcShape: OglSDInstance, pyutSDMessage: PyutSDMessage,
                 dstShape: OglSDInstance):
        """

        Args:
            srcShape:   Source shape OglSDInstance
            pyutSDMessage:  PyutSDMessage
            dstShape:   Destination shape OglSDInstance

        """
        self._pyutSDMessage = pyutSDMessage

        super().__init__(srcShape=srcShape,
                         pyutLink=pyutSDMessage,
                         dstShape=dstShape)
        # LineShape.__init__(self, srcAnchor=srcAnchor, dstAnchor=dstAnchor)
        #
        # Override OglLink anchors
        #
        srcAnchor, dstAnchor = self._createAnchorPoints(
            srcShape=srcShape, pyutSDMessage=pyutSDMessage, dstShape=dstShape)
        srcAnchorPosition = srcAnchor.GetPosition()
        dstAnchorPosition = dstAnchor.GetPosition()
        self.clsLogger.debug(
            f'__init__ -  src anchor: {srcAnchorPosition} dest anchor: {dstAnchorPosition}'
        )
        self._srcAnchor: AnchorPoint = srcAnchor
        self._dstAnchor: AnchorPoint = dstAnchor

        linkLength: float = self._computeLinkLength(
            srcPosition=srcAnchorPosition, destPosition=dstAnchorPosition)
        dx, dy = self._computeDxDy(srcPosition=srcAnchorPosition,
                                   destPosition=dstAnchorPosition)

        centerMessageX = -dy * 5 / linkLength
        centerMessageY = dx * 5 / linkLength

        self._messageLabel: TextShape = self.AddText(
            centerMessageX, centerMessageY,
            pyutSDMessage.getMessage())  # font=self._defaultFont

        self.updateMessage()
        self.SetDrawArrow(True)
Exemple #9
0
    def _getOglSDMessages(self, xmlOglSDMessages, dicoOglObjects, dicoLink,
                          dicoFather, umlFrame):
        """
        Parse the XML elements given and build data layer for PyUT classes.
        If file is version 1.0, the dictionary given will contain, for key,
        the name of the OGL object. Otherwise, it will be the ID
        (multi-same-name support from version 1.1). Everything is fixed
        later.

        @param Element[] xmlOglSDMessages : XML 'GraphicSDInstance elements

        @param {id / srcName, OglObject} dicoOglObjects : OGL objects loaded

        @param {id / srcName, OglLink} dicoLink : OGL links loaded

        @param {id / srcName, id / srcName} dicoFather: Inheritance

        @param UmlFrame umlFrame : Where to draw
        """
        for xmlOglSDMessage in xmlOglSDMessages:

            # Data layer class
            xmlPyutSDMessage = xmlOglSDMessage.getElementsByTagName(
                'SDMessage')[0]

            # Building OGL
            pyutSDMessage = PyutSDMessage()
            srcID = int(xmlPyutSDMessage.getAttribute('srcID'))
            dstID = int(xmlPyutSDMessage.getAttribute('dstID'))
            srcTime = int(float(xmlPyutSDMessage.getAttribute('srcTime')))
            dstTime = int(float(xmlPyutSDMessage.getAttribute('dstTime')))
            srcOgl = dicoOglObjects[srcID]
            dstOgl = dicoOglObjects[dstID]
            oglSDMessage = OglSDMessage(srcOgl, pyutSDMessage, dstOgl)
            pyutSDMessage.setOglObject(oglSDMessage)
            pyutSDMessage.setSource(srcOgl.getPyutObject(), srcTime)
            pyutSDMessage.setDestination(dstOgl.getPyutObject(), dstTime)

            # Pyut Data
            pyutSDMessage.setId(int(xmlPyutSDMessage.getAttribute('id')))
            # Python 3 is already UTF-8
            pyutSDMessage.setMessage(xmlPyutSDMessage.getAttribute('message'))

            dicoOglObjects[pyutSDMessage.getId()] = pyutSDMessage

            # Adding OGL class to UML Frame
            diagram = umlFrame.GetDiagram()
            dicoOglObjects[srcID].addLink(oglSDMessage)
            dicoOglObjects[dstID].addLink(oglSDMessage)
            diagram.AddShape(oglSDMessage)