Ejemplo n.º 1
0
    def createInterfaceLink(self, src: OglClass,
                            dst: OglClass) -> OglInterface:
        """
        Adds an OglInterface link between src and dst.

        Args:
            src:    source of the link
            dst:    destination of the link

        Returns: the created OglInterface link
        """
        sourceClass: PyutClass = cast(PyutClass, src.getPyutObject())
        destinationClass: PyutClass = cast(PyutClass, dst.getPyutObject())

        pyutLink: PyutLink = PyutLink(linkType=LinkType.INTERFACE,
                                      source=sourceClass,
                                      destination=destinationClass)
        oglInterface: OglInterface = OglInterface(srcShape=src,
                                                  pyutLink=pyutLink,
                                                  dstShape=dst)

        src.addLink(oglInterface)
        dst.addLink(oglInterface)

        self._diagram.AddShape(oglInterface)
        self.Refresh()

        return oglInterface
Ejemplo n.º 2
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.º 3
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.º 4
0
    def createLollipopInterface(self, implementor: OglClass,
                                attachmentAnchor: SelectAnchorPoint):

        from org.pyut.ui.UmlClassDiagramsFrame import UmlClassDiagramsFrame
        from org.pyut.commands.CreateOglInterfaceCommand import CreateOglInterfaceCommand
        from org.pyut.commands.CommandGroup import CommandGroup

        self.logger.info(
            f'implementor: {implementor} attachmentAnchor: {attachmentAnchor}')
        umlFrame: UmlClassDiagramsFrame = self.getFileHandling(
        ).getCurrentFrame()

        self.__removeUnneededAnchorPoints(implementor, attachmentAnchor)
        umlFrame.Refresh()

        pyutInterface: PyutInterface = PyutInterface()
        pyutInterface.addImplementor(implementor.getPyutObject().getName())
        with DlgEditInterface(umlFrame, ID_ANY, pyutInterface) as dlg:
            if dlg.ShowModal() == OK:
                self.logger.info(f'model: {pyutInterface}')
                pyutClass: PyutClass = implementor.getPyutObject()
                pyutClass.addInterface(pyutInterface)

                cmd: CreateOglInterfaceCommand = CreateOglInterfaceCommand(
                    pyutInterface, attachmentAnchor)
                group: CommandGroup = CommandGroup("Create lollipop")

                group.addCommand(cmd)
                umlFrame.getHistory().addCommandGroup(group)
                umlFrame.getHistory().execute()
            else:
                self.logger.info(f'Cancelled')
Ejemplo n.º 5
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
        """
        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)

        return oglLink
Ejemplo n.º 6
0
    def write(self, oglObject: OglClass, file: TextIO):
        """
        Write data to filename.

        Format:
        ```python
        Class Name
        <<stereotype_optional>>
        +method([param[:type]]*)[:type_return]
        +field[:type][=value_initial]
        ```

        Args:
            oglObject:  The Ogl object to edit
            file:       The text file to write to
        """

        o: PyutClass = cast(PyutClass, oglObject.getPyutObject())

        file.write(o.getName() + osLineSep)

        if o.getStereotype() is not None:
            file.write(str(o.getStereotype()) + osLineSep)
        for method in o.methods:
            file.write(method.getString() + osLineSep)
        for field in o.fields:
            file.write(str(field) + osLineSep)

        file.close()
Ejemplo n.º 7
0
    def _OglClass2xml(self, oglClass: OglClass, xmlDoc: Document):
        """
        Exporting an OglClass to an miniDom Element.

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

        # Append OGL object base (size and pos)
        self._appendOglBase(oglClass, root)

        # adding the data layer object
        root.appendChild(self._PyutClass2xml(oglClass.getPyutObject(), xmlDoc))

        return root
Ejemplo n.º 8
0
    def _OglClass2xml(self, oglClass: OglClass, xmlDoc):
        """
        Exporting an OglClass to an miniDom Element.

        @param PyutMethod oglClass : Class to save
        @param xmlDoc : xml Document instance
        @return Element : XML Node
        @author Deve Roux <*****@*****.**>
        """
        # lang.importLanguage()
        root = xmlDoc.createElement("GraphicClass")

        # Append OGL object base (size and pos)
        self._appendOglBase(oglClass, root)

        # adding the data layer object
        root.appendChild(self._PyutClass2xml(oglClass.getPyutObject(), xmlDoc))

        return root
Ejemplo n.º 9
0
    def oglClassToXml(self, oglClass: OglClass, xmlDoc: Document) -> Element:
        """
        Exports an OglClass to a minidom Element.

        Args:
            oglClass:   Graphic Class to save
            xmlDoc:     The document to append to

        Returns:
            The newly created `GraphicClass` element
        """
        root: Element = xmlDoc.createElement(
            PyutXmlConstants.ELEMENT_GRAPHIC_CLASS)

        root = self.__appendOglBase(oglClass, root)

        # adding the data layer object
        root.appendChild(self._pyutClassToXml(oglClass.getPyutObject(),
                                              xmlDoc))

        return root
Ejemplo n.º 10
0
    def read(self, umlObject: OglClass, file: TextIO):
        """
        Read data from file

        format:
        ```python
        class name
        <<stereotype_optional>>
        +method([param[:type]]*)[:type_return]
        +field[:type][=value_initial]
        ```

        for example:

        ParentClass
        +strMethod(strParam : str = bogus) : str
        +intMethod(intParam = 1) : int
        +floatField : float = 1.0
        +booleanField : bool = True

        Args:
            umlObject:
            file:
        """
        className: str = file.readline().strip()
        pyutClass: PyutClass = cast(PyutClass, umlObject.getPyutObject())
        pyutClass.name = className

        # process stereotype if present
        nextStereoType: str = file.readline().strip()
        if nextStereoType[0:2] == "<<":
            pyutClass.setStereotype(nextStereoType[2:-2].strip())
            nextStereoType = file.readline().strip()

        methods: List[PyutMethod] = []
        fields: List[PyutField] = []
        pyutClass.methods = methods
        pyutClass.fields = fields

        # process methods and fields
        visValues: List[str] = PyutVisibilityEnum.values()
        while True:
            if nextStereoType == "":
                break

            # search visibility

            if nextStereoType[0] in visValues:
                visStr = nextStereoType[0]
                vis: PyutVisibilityEnum = PyutVisibilityEnum.toEnum(visStr)
                nextStereoType = nextStereoType[1:]
            else:
                vis = PyutVisibilityEnum.PUBLIC

            pos = nextStereoType.find("(")
            params = []
            if pos != -1:
                # process method
                name = nextStereoType[0:pos].strip()
                nextStereoType = nextStereoType[pos + 1:]
                pos = nextStereoType.find(')')

                returnType: str = ""
                if pos != -1:
                    params = self._findParams(nextStereoType[:pos])
                    nextStereoType = nextStereoType[pos + 1:]
                    pos = nextStereoType.find(":")

                    if pos != -1:
                        returnType = nextStereoType[pos + 1:].strip()
                    else:
                        returnType = ""
                pyutType: PyutType = PyutType(value=returnType)
                method: PyutMethod = PyutMethod(name=name,
                                                visibility=vis,
                                                returns=pyutType)

                method.setParams([PyutParam(x[0], x[1]) for x in params])
                methods.append(method)
            else:
                # process field
                field = self._findParams(nextStereoType)[0]
                if field:
                    fields.append(PyutField(field[0], field[1],
                                            visibility=vis))

            nextStereoType = file.readline().strip()