Ejemplo n.º 1
0
    def createLink(self,
                   src: OglClass,
                   dst: OglClass,
                   linkType: LinkType = LinkType.AGGREGATION):
        """
        Used to create links;  It is still the caller's responsibility to add the created shape to the
        appropriate diagram

        Args:
            src:        The source OglClass
            dst:        The destination OglClass
            linkType:   The type of link
        """
        sourceClass: PyutClass = cast(PyutClass, src.getPyutObject())
        destinationClass: PyutClass = cast(PyutClass, dst.getPyutObject())

        pyutLink: PyutLink = PyutLink("",
                                      linkType=linkType,
                                      source=sourceClass,
                                      destination=destinationClass)

        oglLinkFactory = getOglLinkFactory()
        oglLink = oglLinkFactory.getOglLink(src, pyutLink, dst, linkType)

        src.addLink(oglLink)
        dst.addLink(oglLink)

        # src.getPyutObject().addLink(pyutLink)       # TODO fix this
        pyutClass: PyutClass = cast(PyutClass, src.getPyutObject())
        pyutClass.addLink(pyutLink)

        return oglLink
Ejemplo n.º 2
0
    def _createInheritanceLink(self, child: OglClass,
                               parent: OglClass) -> OglLink:
        """
        Add a parent link between the child and parent objects.

        Args:
            child:  Child PyutClass
            parent: Parent PyutClass

        Returns:
            The inheritance OglLink
        """
        sourceClass: PyutClass = cast(PyutClass, child.pyutObject)
        destinationClass: PyutClass = cast(PyutClass, parent.pyutObject)
        pyutLink: PyutLink = PyutLink("",
                                      linkType=LinkType.INHERITANCE,
                                      source=sourceClass,
                                      destination=destinationClass)
        oglLink: OglLink = getOglLinkFactory().getOglLink(
            child, pyutLink, parent, LinkType.INHERITANCE)

        child.addLink(oglLink)
        parent.addLink(oglLink)

        # add it to the PyutClass
        # child.getPyutObject().addParent(parent.getPyutObject())
        childPyutClass: PyutClass = cast(PyutClass, child.pyutObject)
        parentPyutClass: PyutClass = cast(PyutClass, parent.pyutObject)

        childPyutClass.addParent(parentPyutClass)

        return oglLink
Ejemplo n.º 3
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
Ejemplo n.º 4
0
    def createInheritanceLink(self, child: OglClass,
                              parent: OglClass) -> OglLink:
        """
        TODO: this is a duplicate of CreateOglLinkCommandCommand._createInheritanceLink (this code adds it to the frame)

        Add a parent link between the child and parent objects.

        Args:
            child:  Child PyutClass
            parent: Parent PyutClass

        Returns:
            The inheritance OglLink
        """
        pyutLink = PyutLink("",
                            linkType=LinkType.INHERITANCE,
                            source=child.getPyutObject(),
                            destination=parent.getPyutObject())
        oglLink = getOglLinkFactory().getOglLink(child, pyutLink, parent,
                                                 LinkType.INHERITANCE)

        child.addLink(oglLink)
        parent.addLink(oglLink)

        # add it to the PyutClass
        # child.getPyutObject().addParent(parent.getPyutObject())
        childPyutClass: PyutClass = child.getPyutObject()
        parentPyutClass: PyutClass = parent.getPyutObject()

        childPyutClass.addParent(parentPyutClass)

        self._diagram.AddShape(oglLink)
        self.Refresh()

        return oglLink
Ejemplo n.º 5
0
    def _createLink(self,
                    src,
                    dst,
                    linkType: LinkType = LinkType.INHERITANCE,
                    srcPos=None,
                    dstPos=None):
        """
        Add a link between src and dst without adding it to the frame.

        Args:
            src:        Source of the link
            dst:        Destination of the link
            linkType:   Type of the link
            srcPos:     Position on source
            dstPos:     Position destination

        Returns:    The created link
        """
        if linkType == LinkType.INHERITANCE:
            return self._createInheritanceLink(src, dst)
        elif linkType == LinkType.SD_MESSAGE:
            return self._createSDMessage(src=src,
                                         dest=dst,
                                         srcPos=srcPos,
                                         destPos=dstPos)
        pyutLink = PyutLink("",
                            linkType=linkType,
                            source=src.getPyutObject(),
                            destination=dst.getPyutObject())

        # Call the factory to create OGL Link
        oglLinkFactory = getOglLinkFactory()
        # oglLink = oglLinkFactory.getOglLink(src, pyutLink, dst, linkType)
        oglLink = oglLinkFactory.getOglLink(srcShape=src,
                                            pyutLink=pyutLink,
                                            destShape=dst,
                                            linkType=linkType)

        src.addLink(oglLink)  # add it to the source OglShape
        dst.addLink(oglLink)  # add it to the destination OglShape

        src.getPyutObject().addLink(pyutLink)  # add it to the PyutClass

        return oglLink
Ejemplo n.º 6
0
    def getOglLinks(self, xmlOglLinks: NodeList,
                    oglClasses: OglObjects) -> OglLinks:
        """
        Extract the link for the OglClasses

        Args:
            xmlOglLinks:    A DOM node list of links
            oglClasses:  The OglClasses

        Returns:
            The OglLinks list
        """
        oglLinks: OglLinks = cast(OglLinks, [])

        for xmlOglLink in xmlOglLinks:
            # src and dst anchor position
            xmlLink: Element = cast(Element, xmlOglLink)

            sx = PyutUtils.secureFloat(
                xmlLink.getAttribute(
                    PyutXmlConstants.ATTR_LINK_SOURCE_ANCHOR_X))
            sy = PyutUtils.secureFloat(
                xmlLink.getAttribute(
                    PyutXmlConstants.ATTR_LINK_SOURCE_ANCHOR_Y))
            dx = PyutUtils.secureFloat(
                xmlLink.getAttribute(
                    PyutXmlConstants.ATTR_LINK_DESTINATION_ANCHOR_X))
            dy = PyutUtils.secureFloat(
                xmlLink.getAttribute(
                    PyutXmlConstants.ATTR_LINK_DESTINATION_ANCHOR_Y))

            spline: bool = PyutUtils.secureBoolean(
                xmlLink.getAttribute(PyutXmlConstants.ATTR_SPLINE))

            # get the associated PyutLink
            srcId, dstId, assocPyutLink = self._getPyutLink(xmlLink)

            try:
                src: OglClass = oglClasses[srcId]
                dst: OglClass = oglClasses[dstId]
            except KeyError as ke:
                self.logger.error(
                    f'Developer Error -- srcId: {srcId} - dstId: {dstId}  error: {ke}'
                )
                continue

            linkType: LinkType = assocPyutLink.getType()
            pyutLink: PyutLink = PyutLink(
                name=assocPyutLink.getName(),
                linkType=linkType,
                cardSrc=assocPyutLink.sourceCardinality,
                cardDest=assocPyutLink.destinationCardinality,
                source=src.getPyutObject(),
                destination=dst.getPyutObject())

            oglLinkFactory = getOglLinkFactory()
            oglLink = oglLinkFactory.getOglLink(src, pyutLink, dst, linkType)
            src.addLink(oglLink)
            dst.addLink(oglLink)

            oglLinks.append(oglLink)

            oglLink.SetSpline(spline)

            # put the anchors at the right position
            srcAnchor = oglLink.GetSource()
            dstAnchor = oglLink.GetDestination()
            srcAnchor.SetPosition(sx, sy)
            dstAnchor.SetPosition(dx, dy)

            # add the control points to the line
            line = srcAnchor.GetLines()[0]  # only 1 line per anchor in pyut
            parent = line.GetSource().GetParent()
            selfLink = parent is line.GetDestination().GetParent()

            controlPoints: ControlPoints = self._generateControlPoints(xmlLink)
            for controlPoint in controlPoints:
                line.AddControl(controlPoint)
                if selfLink:
                    x, y = controlPoint.GetPosition()
                    controlPoint.SetParent(parent)
                    controlPoint.SetPosition(x, y)

            if isinstance(oglLink, OglAssociation):
                self.__furtherCustomizeAssociationLink(xmlLink, oglLink)
            self._reconstituteLinkDataModel(oglLink)

        return oglLinks
Ejemplo n.º 7
0
    def _getOglLinks(self, xmlOglLinks, dicoOglObjects, dicoLink, dicoFather,
                     umlFrame):
        """
        To extract the links from an OGL object.
        """
        def secure_float(floatX):
            if floatX is not None:
                return float(floatX)
            return 0.0

        def secure_spline_int(splineX):
            if splineX is None:
                return 0
            elif splineX == "_DeprecatedNonBool: False" or splineX == "False":
                return 0
            elif splineX == "_DeprecatedNonBool: True" or splineX == "True":
                return 1
            else:
                return int(splineX)

        for link in xmlOglLinks:
            # src and dst anchor position
            sx = secure_float(link.getAttribute("srcX"))
            sy = secure_float(link.getAttribute("srcY"))
            dx = secure_float(link.getAttribute("dstX"))
            dy = secure_float(link.getAttribute("dstY"))
            spline = secure_spline_int(link.getAttribute("spline"))

            # create a list of ControlPoints
            ctrlpts = []
            for ctrlpt in link.getElementsByTagName("ControlPoint"):
                x = secure_float(ctrlpt.getAttribute("x"))
                y = secure_float(ctrlpt.getAttribute("y"))
                ctrlpts.append(ControlPoint(x, y))

            # get the associated PyutLink
            srcId, dstId, pyutLink = self._getPyutLink(link)

            # CD 20060218
            src = dicoOglObjects[srcId]
            dst = dicoOglObjects[dstId]
            linkType = pyutLink.getType()
            pyutLink = PyutLink("",
                                linkType=linkType,
                                source=src.getPyutObject(),
                                destination=dst.getPyutObject())

            oglLinkFactory = getOglLinkFactory()
            oglLink = oglLinkFactory.getOglLink(src, pyutLink, dst, linkType)
            src.addLink(oglLink)
            dst.addLink(oglLink)
            umlFrame.GetDiagram().AddShape(oglLink, withModelUpdate=False)

            # create the OglLink
            oglLink.SetSpline(spline)

            # give it the PyutLink
            newPyutLink = pyutLink

            # copy the good information from the read link
            newPyutLink.setBidir(pyutLink.getBidir())
            # newPyutLink.setDestinationCardinality(pyutLink.getDestinationCardinality())
            # newPyutLink.setSourceCardinality(pyutLink.getSourceCardinality())
            newPyutLink.destinationCardinality = pyutLink.destinationCardinality
            newPyutLink.sourceCardinality = pyutLink.sourceCardinality

            newPyutLink.setName(pyutLink.getName())

            # put the anchors at the right position
            srcAnchor = oglLink.GetSource()
            dstAnchor = oglLink.GetDestination()
            srcAnchor.SetPosition(sx, sy)
            dstAnchor.SetPosition(dx, dy)

            # add the control points to the line
            line = srcAnchor.GetLines()[0]  # only 1 line per anchor in pyut
            parent = line.GetSource().GetParent()
            selfLink = parent is line.GetDestination().GetParent()

            for ctrl in ctrlpts:
                line.AddControl(ctrl)
                if selfLink:
                    x, y = ctrl.GetPosition()
                    ctrl.SetParent(parent)
                    ctrl.SetPosition(x, y)

            if isinstance(oglLink, OglAssociation):
                # center = oglLink.getLabels()[CENTER]
                # src = oglLink.getLabels()[SRC_CARD]
                # dst = oglLink.getLabels()[DEST_CARD]

                label = link.getElementsByTagName("LabelCenter")[0]
                x = float(label.getAttribute("x"))
                y = float(label.getAttribute("y"))
                # center.SetPosition(x, y)
                oglLink.centerLabel.oglPosition.x = x
                oglLink.centerLabel.oglPosition.y = y

                label = link.getElementsByTagName("LabelSrc")[0]
                x = float(label.getAttribute("x"))
                y = float(label.getAttribute("y"))
                # src.SetPosition(x, y)
                oglLink.sourceCardinality.oglPosition.x = x
                oglLink.sourceCardinality.oglPosition.y = y

                label = link.getElementsByTagName("LabelDst")[0]
                x = float(label.getAttribute("x"))
                y = float(label.getAttribute("y"))
                dst.SetPosition(x, y)