Example #1
0
    def getOglActors(self, xmlOglActors: NodeList) -> OglActors:
        """
        Parse the XML elements given and build data layer for PyUt actors.

        Args:
            xmlOglActors:       XML 'GraphicActor' elements

        Returns:
            A dictionary of OglActor objects
        """
        oglActors: OglActors = cast(OglActors, {})

        for xmlOglActor in xmlOglActors:
            pyutActor: PyutActor = PyutActor()

            # Building OGL Actor
            height: int = PyutUtils.strFloatToInt(xmlOglActor.getAttribute(PyutXmlConstants.ATTR_HEIGHT))
            width:  int = PyutUtils.strFloatToInt(xmlOglActor.getAttribute(PyutXmlConstants.ATTR_WIDTH))
            oglActor: OglActor = OglActor(pyutActor, width, height)

            xmlActor: Element = xmlOglActor.getElementsByTagName(PyutXmlConstants.ELEMENT_MODEL_ACTOR)[0]

            pyutActor.setId(int(xmlActor.getAttribute(PyutXmlConstants.ATTR_ID)))
            pyutActor.setName(xmlActor.getAttribute(PyutXmlConstants.ATTR_NAME))
            pyutActor.setFilename(xmlActor.getAttribute(PyutXmlConstants.ATTR_FILENAME))

            # Adding properties necessary to place shape on a diagram frame
            x = PyutUtils.strFloatToInt(xmlOglActor.getAttribute(PyutXmlConstants.ATTR_X))
            y = PyutUtils.strFloatToInt(xmlOglActor.getAttribute(PyutXmlConstants.ATTR_Y))
            oglActor.SetPosition(x, y)

            oglActors[pyutActor.getId()] = oglActor

        return oglActors
Example #2
0
    def _getOglActors(self, xmlOglActors, dicoOglObjects, dicoLink, dicoFather,
                      umlFrame):
        """
        Parse the XML elements given and build data layer for PyUT actors.

        @param Element[] xmlOglActors : XML 'GraphicActor' 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
        @since 2.0
        @author Philippe Waelti <*****@*****.**>
        """
        oldData = 0

        for xmlOglActor in xmlOglActors:
            pyutActor = PyutActor()

            # Building OGL Actor
            height = int(xmlOglActor.getAttribute('height'))
            width = int(xmlOglActor.getAttribute('width'))
            oglActor = OglActor(pyutActor, width, height)

            xmlActor = xmlOglActor.getElementsByTagName('Actor')[0]

            # Backward compatibility (pyut v1.0). If id not present,
            # auto set by the instantiation of object
            if xmlActor.hasAttribute('id'):
                pyutActor.setId(int(xmlActor.getAttribute('id')))
            else:
                oldData = 1

            # adding name for this class
            pyutActor.setName(xmlActor.getAttribute('name').encode("charmap"))

            # adding fathers
            self._getFathers(xmlActor.getElementsByTagName("Father"),
                             dicoFather, pyutActor.getId())

            # Update dicos
            dicoLink[pyutActor.getId()] = self._getLinks(xmlActor)
            dicoOglObjects[pyutActor.getId()] = oglActor

            # Update UML Frame
            x = int(xmlOglActor.getAttribute('x'))
            y = int(xmlOglActor.getAttribute('y'))
            umlFrame.addShape(oglActor, x, y)

        return oldData
Example #3
0
    def _pyutActorToXml(self, pyutActor: PyutActor,
                        xmlDoc: Document) -> Element:
        """
        Export an PyutActor to a minidom Element.
        Args:
            pyutActor:  Actor to convert
            xmlDoc:     xml document

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

        actorId = self._idFactory.getID(pyutActor)
        root.setAttribute(PyutXmlConstants.ATTR_ID, str(actorId))
        root.setAttribute(PyutXmlConstants.ATTR_NAME, pyutActor.getName())
        root.setAttribute(PyutXmlConstants.ATTR_FILENAME,
                          pyutActor.getFilename())

        return root
Example #4
0
    def createNewActor(self, x, y):
        """
        Add a new actor at (x, y).

        @return PyutActor : the newly created PyutActor
        """
        pyutActor: PyutActor = PyutActor()
        oglActor: OglActor = OglActor(pyutActor)

        self.addShape(oglActor, x, y)
        self.Refresh()
        return pyutActor
Example #5
0
    def __init__(self, pyutActor=None, w: float = 80.0, h: float = 100.0):
        """
        Constructor.
        @param Float w : Width of the shape
        @param Float h : Height of the shape

        @since 1.0
        @author Philippe Waelti <*****@*****.**>
        """
        # Init associated PyutObject
        if pyutActor is None:
            pyutObject = PyutActor()
        else:
            pyutObject = pyutActor

        super().__init__(pyutObject, w, h)
        self._drawFrame = False
Example #6
0
    def _getOglActors(self, xmlOglActors, dicoOglObjects, dicoLink, dicoFather,
                      umlFrame):
        """
        Parse the XML elements given and build data layer for PyUT actors.

        @param Element[] xmlOglActors : XML 'GraphicActor' 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 xmlOglActor in xmlOglActors:
            pyutActor = PyutActor()

            # Building OGL Actor
            height = float(xmlOglActor.getAttribute('height'))
            width = float(xmlOglActor.getAttribute('width'))
            oglActor = OglActor(pyutActor, width, height)

            xmlActor = xmlOglActor.getElementsByTagName('Actor')[0]

            pyutActor.setId(int(xmlActor.getAttribute('id')))

            # adding name for this class
            # pyutActor.setName(xmlActor.getAttribute('name').encode("charmap"))
            # Python 3 is already UTF-8
            pyutActor.setName(xmlActor.getAttribute('name'))

            # adding associated filename ([email protected])
            pyutActor.setFilename(xmlActor.getAttribute('filename'))

            # Update dicos
            dicoOglObjects[pyutActor.getId()] = oglActor

            # Update UML Frame
            x = float(xmlOglActor.getAttribute('x'))
            y = float(xmlOglActor.getAttribute('y'))
            umlFrame.addShape(oglActor, x, y)
Example #7
0
    def __init__(self, pyutActor=None, w: int = 80, h: int = 100):
        """

        Args:
            pyutActor:

            w:  width of shape
            h:  height of shape
        """

        # Init associated PyutObject
        if pyutActor is None:
            pyutObject = PyutActor()
        else:
            pyutObject = pyutActor

        super().__init__(pyutObject, w, h)
        self._drawFrame = False