Beispiel #1
0
    def __init__(self, pyutClass: PyutClass = None, w: int = 0, h: int = 0):
        """

        Args:
            pyutClass:  a PyutClass object
            w:  Width of the shape
            h:  Height of the shape
        """
        if pyutClass is None:
            pyutObject = PyutClass()
        else:
            pyutObject = pyutClass

        width: int = w
        height: int = h

        # Use preferences to get initial size if not specified
        # Note: auto_resize_shape_on_edit must be False for this size to actually stick
        preferences: PyutPreferences = PyutPreferences()

        if w == 0:
            width = preferences.classDimensions.width
        if h == 0:
            height = preferences.classDimensions.height

        super().__init__(pyutObject, width=width, height=height)

        self._nameFont: Font = Font(DEFAULT_FONT_SIZE, FONTFAMILY_SWISS,
                                    FONTSTYLE_NORMAL, FONTWEIGHT_BOLD)
        self.logger: Logger = getLogger(__name__)
    def _generatePyutClasses(self):

        for className in self._classNames():
            pyutClass: PyutClass = PyutClass(name=className)

            pyutClass = self._addFields(pyutClass)

            for methodName in self._methodNames(className):
                pyutMethod: PyutMethod = PyutMethod(name=methodName)
                if methodName[0:2] == "__":
                    pyutMethod.setVisibility(PyutVisibilityEnum.PRIVATE)
                elif methodName[0] == "_":
                    pyutMethod.setVisibility(PyutVisibilityEnum.PROTECTED)
                else:
                    pyutMethod.setVisibility(PyutVisibilityEnum.PUBLIC)
                pyutMethod = self._addParameters(pyutMethod)
                pyutMethod.sourceCode = self.visitor.methodCode[methodName]

                pyutClass.addMethod(pyutMethod)
            setterProperties: PyutPythonVisitor.Parameters = self.visitor.setterProperties
            getterProperties: PyutPythonVisitor.Parameters = self.visitor.getterProperties
            for propName in self.visitor.propertyNames:

                setterParams: List[str] = setterProperties[propName]
                getterParams: List[str] = getterProperties[propName]
                self.logger.info(f'Processing - {propName=} {setterParams=} {getterParams=}')
                setter, getter = self._createProperties(propName=propName, setterParams=setterParams)
                pyutClass.addMethod(setter)
                pyutClass.addMethod(getter)

            self._pyutClasses[className] = pyutClass
        self.logger.info(f'Generated {len(self._pyutClasses)} classes')
Beispiel #3
0
    def _readFoundationCoreClass(self, coreClass):
        """
        Read one Foundation.Core.Class
        @param coreClass : Foundation.Core.Class element
        @author C.Dutoit
        """
        # Get class name
        className = self._readFoundationCoreClassName(coreClass)
        self.logger.info("Reading class ", className, end=' ')

        # Get class ID
        classID = str(coreClass.getAttribute("xmi.id"))
        self.logger.info("id = ", classID, end=' ')

        # Save class
        pyutClass = PyutClass(className)

        # Get class abstract status
        isAbstract = self._readFoundationCoreClassIsAbstract(coreClass)
        self.logger.info("isAbstract = ", isAbstract)
        if isAbstract:
            pyutClass.setStereotype("Abstract")

        # Get class features
        self._readFoundationCoreClassifierFeature(coreClass, pyutClass)

        # Make the PyutClass visible
        oglClass = OglClass(pyutClass)
        x = (len(self._dicOglClasses) % 10) * 100
        y = len(self._dicOglClasses) / 10 * 100
        self._umlFrame.addShape(oglClass, x, y)
        oglClass.autoResize()
        self._dicOglClasses[classID] = oglClass
Beispiel #4
0
    def _createNewClass(self, x, y):
        """
        Add a new class at (x, y).

        @return PyutClass : the newly created PyutClass
        @since 1.4
        @author L. Burgbacher <*****@*****.**>
        """
        from org.pyut.general.Mediator import getMediator
        from org.pyut.model.PyutClass import PyutClass
        from org.pyut.ogl.OglClass import OglClass

        med = getMediator()
        umlFrame = med.getFileHandling().getCurrentFrame()

        pyutClass = PyutClass(_("NoName"))
        oglClass = OglClass(pyutClass)
        med.classEditor(pyutClass)
        # med.autoResize(pyutClass)

        umlFrame.addShape(oglClass, x, y, withModelUpdate=True)
        med.autoResize(pyutClass)
        umlFrame.Refresh()

        return oglClass
Beispiel #5
0
    def _generatePyutClasses(self):

        for className in self._classNames():
            pyutClass: PyutClass = PyutClass(name=className)

            pyutClass = self._addFields(pyutClass)

            for methodName in self._methodNames(className):
                pyutMethod: PyutMethod = PyutMethod(name=methodName)
                if methodName[0:2] == "__":
                    pyutMethod.setVisibility(PyutVisibilityEnum.PRIVATE)
                elif methodName[0] == "_":
                    pyutMethod.setVisibility(PyutVisibilityEnum.PROTECTED)
                else:
                    pyutMethod.setVisibility(PyutVisibilityEnum.PUBLIC)
                pyutMethod = self._addParameters(pyutMethod)
                pyutMethod.sourceCode = self.visitor.methodCode[methodName]

                pyutClass.addMethod(pyutMethod)

            setterProperties: Parameters = self.visitor.setterProperties
            getterProperties: Parameters = self.visitor.getterProperties

            pyutClass = self._generatePropertiesAsMethods(
                pyutClass, getterProperties, setterProperties)

            if className in self.visitor.dataClassNames:
                self._createDataClassPropertiesAsFields(
                    pyutClass, self.visitor.dataClassProperties)

            self._pyutClasses[className] = pyutClass
        self.logger.info(f'Generated {len(self._pyutClasses)} classes')
Beispiel #6
0
    def _getOglClasses(self, xmlOglClasses, dicoOglObjects, umlFrame, oldData):
        """
        Parse the XMI 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[] xmlOglClasses : XMI 'GraphicClass' elements
        @param {id / srcName, OglObject} dicoOglObjects : OGL objects loaded
        @param UmlFrame umlFrame : Where to draw
        @param int oldData : If old data (v1.0), 1 else 0
        @since 2.0
        @author Philippe Waelti <*****@*****.**>
        """

        pyutClass = PyutClass()

        # adding name for this class
        className = xmlOglClasses.getElementsByTagName("Foundation.Core.ModelElement.name")
        self.logger.debug(f'Ogl class name: {className}')
        if len(className) > 0:
            name = className[0].firstChild
            if name.nodeType == name.TEXT_NODE:
                pyutClass.setName(name.data)

            oglClass = OglClass(pyutClass, 50, 50)

            # adding methods for this class
            pyutClass.setMethods(self._getMethods(xmlOglClasses))

            # adding fields for this class
            pyutClass.fields = self._getFields(xmlOglClasses)

            # for class id
            classId = xmlOglClasses.getAttribute("xmi.id")
            self.logger.debug(f"Class ID: {classId}")

            # for all the classes who are an inheritance link
            for fathers in xmlOglClasses.getElementsByTagName("Foundation.Core.Generalization"):
                linkId = fathers.getAttribute("xmi.idref")
                self.logger.debug(f"parent: {linkId}")
                if linkId not in self.dicoFather:
                    self.dicoFather[linkId] = {}
                self.dicoFather[linkId][classId] = oglClass

            # for all class whos are link
            for links in xmlOglClasses.getElementsByTagName("Foundation.Core.Classifier.associationEnd"):
                for link in links.getElementsByTagName("Foundation.Core.AssociationEnd"):
                    linkId = link.getAttribute("xmi.idref")
                    self.logger.debug(f"linkId: {linkId}")
                    if linkId not in self.dicoLinks:
                        self.dicoLinks[linkId] = oglClass
            pyutClassId = pyutClass.getId()
            self.logger.debug(f'pyutClassId: {pyutClassId}')
            dicoOglObjects[pyutClassId] = oglClass

            umlFrame.addShape(oglClass, 100, 100)
Beispiel #7
0
    def createNewClass(self, x, y):
        """
        Add a new class at (x, y).

        @return PyutClass : the newly created PyutClass
        """
        pyutClass: PyutClass = PyutClass(_("NoName"))
        oglClass: OglClass = OglClass(pyutClass)

        self.addShape(oglClass, x, y)
        self.Refresh()
        return pyutClass
Beispiel #8
0
    def setUp(self):
        self.logger: Logger = TestIDFactory.clsLogger

        self.app: App = TestIDFactory.clsApp

        self._idFactory: IDFactory = IDFactory()

        self._pyutInterface: PyutInterface = PyutInterface()
        self._destinationAnchor: SelectAnchorPoint = SelectAnchorPoint(
            250, 250, AttachmentPoint.NORTH)

        self._pyutClass: PyutClass = PyutClass(name='UnitTestClass')
    def addHierarchy(self, display):
        """
        Hardcoded example of a class diagram, for test purposes.
        Classes come from self introspection !!!
        OK, it's too big, but it's not a feature, just a toy.

        @author L. Burgbacher <*****@*****.**>
        @since 1.4
        """
        # BeginBusyCursor()

        from org.pyut.experimental.PythonMetaClassDataHandler import PythonMetaClassDataHandler

        cg: PythonMetaClassDataHandler = PythonMetaClassDataHandler()
        classes: List[type] = cg.getClassListFromNames(display)

        classNameToOglClass: Dict[str, OglClass] = {}

        # create the Pyut Class objects & associate Ogl graphical classes
        for cl in classes:
            # create objects
            pyutClassDef: PyutClass = PyutClass(cl.__name__)

            klassMethods: List[classmethod] = cg.getMethodsFromClass(cl)

            # add the methods
            methods: List[PyutMethod] = cg.generatePyutMethods(klassMethods)
            methods = sorted(methods, key=PyutMethod.getName)

            pyutClassDef.setMethods(methods)

            oglClassDef = self.addToDiagram(pyutClassDef)
            classNameToOglClass[cl.__name__] = oglClassDef

        # now, search for parent links
        for oglClassDef in classNameToOglClass.values():

            pyutClassDef = oglClassDef.getPyutObject()
            # skip object, it has no parent
            if pyutClassDef.getName() == "object":
                continue

            parentNames = cg.getParentClassNames(classes, pyutClassDef)

            for parent in parentNames:
                dest = classNameToOglClass.get(parent)
                if dest is not None:  # maybe we don't have the parent loaded
                    self.createInheritanceLink(oglClassDef, dest)

        oglClassDefinitions: List[OglClass] = list(
            classNameToOglClass.values())

        self.positionClassHierarchy(oglClassDefinitions)
    def testCreateDataClassPropertiesAsFields(self):

        sampleDataClassProperties: DataClassProperties = [
            DataClassProperty(('DataTestClass', 'w="A String"')),
            DataClassProperty(('DataTestClass', 'x:float=0.0')),
            DataClassProperty(('DataTestClass', 'y:float=42.0')),
            DataClassProperty(('DataTestClass', 'z:int'))
        ]
        pyutClass: PyutClass = PyutClass(name='DataTestClass')

        self.reverseEngineer._createDataClassPropertiesAsFields(
            pyutClass=pyutClass, dataClassProperties=sampleDataClassProperties)
Beispiel #11
0
    def getOglClasses(self, xmlOglClasses: NodeList) -> OglClasses:
        """
        Loads to OGL objects
        Parse the XML elements given and build data model for the Pyut classes.

        Args:
            xmlOglClasses:   XML 'GraphicClass' elements

        Returns:
                The built dictionary uses an ID for the key and an OglClass for the value
        """
        oglObjects: OglClasses = cast(OglClasses, {})

        for xmlOglClass in xmlOglClasses:

            xmlOglClass: Element   = cast(Element, xmlOglClass)
            pyutClass:   PyutClass = PyutClass()

            height: float      = float(xmlOglClass.getAttribute(PyutXmlConstants.ATTR_HEIGHT))
            width:  float      = float(xmlOglClass.getAttribute(PyutXmlConstants.ATTR_WIDTH))
            oglClass: OglClass = OglClass(pyutClass, width, height)

            xmlClass: Element = xmlOglClass.getElementsByTagName(PyutXmlConstants.ELEMENT_MODEL_CLASS)[0]

            pyutClass.setId(int(xmlClass.getAttribute(PyutXmlConstants.ATTR_ID)))
            pyutClass.setName(xmlClass.getAttribute(PyutXmlConstants.ATTR_NAME))
            pyutClass.description = xmlClass.getAttribute(PyutXmlConstants.ATTR_DESCRIPTION)
            if xmlClass.hasAttribute(PyutXmlConstants.ATTR_STEREOTYPE):
                pyutClass.setStereotype(getPyutStereotype(xmlClass.getAttribute(PyutXmlConstants.ATTR_STEREOTYPE)))

            # adding display properties (cd)
            value = PyutUtils.secureBoolean(xmlClass.getAttribute(PyutXmlConstants.ATTR_SHOW_STEREOTYPE))
            pyutClass.setShowStereotype(value)
            value = PyutUtils.secureBoolean(xmlClass.getAttribute(PyutXmlConstants.ATTR_SHOW_METHODS))
            pyutClass.showMethods = value
            value = PyutUtils.secureBoolean(xmlClass.getAttribute(PyutXmlConstants.ATTR_SHOW_FIELDS))
            pyutClass.showFields = value

            pyutClass.setFilename(xmlClass.getAttribute(PyutXmlConstants.ATTR_FILENAME))

            pyutClass.methods = self._getMethods(xmlClass)
            pyutClass.fields  = self._getFields(xmlClass)

            # Adding properties necessary to place shape on a diagram frame
            x = float(xmlOglClass.getAttribute(PyutXmlConstants.ATTR_X))
            y = float(xmlOglClass.getAttribute(PyutXmlConstants.ATTR_Y))

            oglClass.SetPosition(x, y)

            oglObjects[pyutClass.getId()] = oglClass

        return oglObjects
Beispiel #12
0
    def _createNewClass(self) -> OglClass:
        """
        Create a new class

        Returns: the newly created OglClass
        """
        className: str = f'{self._prefs.className}{CreateOglClassCommand.clsCounter}'
        pyutClass: PyutClass = PyutClass(className)
        oglClass: OglClass = OglClass(pyutClass)

        CreateOglClassCommand.clsCounter += 1

        return oglClass
Beispiel #13
0
    def _createNewClass(self) -> OglClass:
        """
        Create a new class

        Returns: the newly created OglClass
        """
        className: str = f'{self._preferences.className}{TestOglToMiniDomV10.clsCounter}'
        pyutClass: PyutClass = PyutClass(className)
        pyutClass.addMethod(self._generateAMethod())
        pyutClass.fileName = '/Users/humberto.a.sanchez.ii/PycharmProjects/PyUt/src/UnitTest.py'
        oglClass: OglClass = OglClass(pyutClass)

        TestOglToMiniDomV10.clsCounter += 1

        return oglClass
    def _generateReadOnlyMethods(self):
        # Note the missing setter for fontSize
        getterProperties: Dict[str, List] = {
            'fontSize': [''],
            'verticalGap': ['']
        }
        setterProperties: Dict[str, List] = {'verticalGap': ['newValue']}
        pyutClass: PyutClass = PyutClass(name='NormalPropertiesClass')

        self.__setMockVisitorPropertyNames()

        pyutClass = self.reverseEngineer._generatePropertiesAsMethods(
            pyutClass=pyutClass,
            getterProperties=getterProperties,
            setterProperties=setterProperties)
        return pyutClass
Beispiel #15
0
    def __init__(self, pyutClass: PyutClass = None, w: float = DEFAULT_CLASS_WIDTH, h: float = DEFAULT_CLASS_HEIGHT):
        """

        Args:
            pyutClass:  a PyutClass object
            w:  Width of the shape
            h:  Height of the shape
        """
        if pyutClass is None:
            pyutObject = PyutClass()
        else:
            pyutObject = pyutClass
        super().__init__(pyutObject, w, h)

        self.logger:    Logger = getLogger(__name__)
        self._nameFont: Font   = Font(DEFAULT_FONT_SIZE, FONTFAMILY_SWISS, FONTSTYLE_NORMAL, FONTWEIGHT_BOLD)
Beispiel #16
0
    def testSerialize(self):

        pyutClass: PyutClass = PyutClass(name='Implementor')
        implementor: OglClass = OglClass(pyutClass=pyutClass)

        attachmentAnchor: SelectAnchorPoint = SelectAnchorPoint(
            x=100, y=100, attachmentPoint=AttachmentPoint.NORTH)

        cOglXFaceCmd: CreateOglInterfaceCommand = CreateOglInterfaceCommand(
            implementor=implementor, attachmentAnchor=attachmentAnchor)

        #
        # Override the created OglInterface2
        #
        oglInterface: OglInterface2 = cOglXFaceCmd._shape
        pyutInterface: PyutInterface = cOglXFaceCmd._pyutInterface

        floatMethod: PyutMethod = TestCommandCommon.createTestMethod(
            'floatMethod', PyutVisibilityEnum.PRIVATE, PyutType('float'))
        intMethod: PyutMethod = TestCommandCommon.createTestMethod(
            'intMethod', PyutVisibilityEnum.PROTECTED, PyutType('int'))

        pyutInterface.methods = [intMethod, floatMethod]
        oglInterface.pyutInterface = pyutInterface

        cOglXFaceCmd._shape = oglInterface
        serializedShape: str = cOglXFaceCmd.serialize()

        self.logger.debug(f'{serializedShape=}')

        self.assertIsNotNone(serializedShape, 'Something must come back')

        self.maxDiff = None
        self.logger.debug(
            f'{len(self._serializedCommand)=}  {len(serializedShape)=}')

        import re
        fixedSerializedShape = re.sub('shapeId=[0-9]*', 'shapeId=2',
                                      serializedShape)

        self.logger.debug(f'{fixedSerializedShape=}')

        expectedValue: str = self._serializedCommand
        actualValue: str = fixedSerializedShape

        self.assertEqual(expectedValue, actualValue, 'Oops, something changed')
Beispiel #17
0
    def __addClass(self, className: str) -> OglClass:
        """
        Add a class to the dictionary of classes

        Args:
            className: Name of the class to be added

        Returns: OglClass instance for the class

        """
        # If the class name exists already, return the instance
        if className in self._classes:
            return self._classes[className]

        # Create the class
        pc: PyutClass = PyutClass(className)  # A new PyutClass
        po: OglClass = OglClass(pc)  # A new OglClass

        self._classes[className] = po

        return po
Beispiel #18
0
    def createClasses(self, name: str, x: int, y: int) -> CreatedClassesType:
        """
        Create a pair of classes (pyutClass and oglClass)

        Args:
            name: Class Name

            x:  x-coordinate on the uml frame  oglClass
            y:  y coordinate on the uml frame  oglClass

        Returns: A named tuple with attributes:  pyutClass and oglClass
        """
        pyutClass: PyutClass = PyutClass()
        pyutClass.setName(name)

        oglClass: OglClass = OglClass(pyutClass, 50, 50)
        # To make this code capable of being debugged
        oglClass.SetPosition(x=x, y=y)
        self.addShape(oglClass, x, y)

        createdClasses: CreatedClassesType = CreatedClassesType(
            pyutClass=pyutClass, oglClass=oglClass)

        return createdClasses
    def createClasses(self, name: str, x: float,
                      y: float) -> CreatedClassesType:
        """
        Create a pair of classes (pyutClass and oglClass)

        Args:
            name: Class Name

            x:  x-coordinate on the uml frame  oglClass
            y:  y coordinate on the uml frame  oglClass

        Returns: A tuple with one of each:  pyutClass and oglClass
        """
        pyutClass: PyutClass = PyutClass()
        pyutClass.setName(name)

        oglClass: OglClass = OglClass(pyutClass, 50, 50)
        # To make this code capable of being debugged
        oglClass.SetPosition(x=x, y=y)
        self.addShape(oglClass, x, y)

        retData: CreatedClassesType = cast(CreatedClassesType,
                                           (pyutClass, oglClass))
        return retData
Beispiel #20
0
    def _getOglClasses(self, xmlOglClasses, 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[] xmlOglClasses : XML 'GraphicClass' 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 xmlOglClass in xmlOglClasses:

            pyutClass = PyutClass()
            # Building OGL class
            height = int(xmlOglClass.getAttribute('height'))
            width = int(xmlOglClass.getAttribute('width'))
            oglClass = OglClass(pyutClass, width, height)

            # Data layer class
            xmlClass = xmlOglClass.getElementsByTagName('Class')[0]

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

            # adding name for this class
            pyutClass.setName(xmlClass.getAttribute('name').encode("charmap"))

            # adding description
            pyutClass.setDescription(xmlClass.getAttribute('description'))

            # adding stereotype
            if xmlClass.hasAttribute('stereotype'):
                pyutClass.setStereotype(
                    getPyutStereotype(xmlClass.getAttribute('stereotype')))

            # adding methods for this class
            pyutClass.setMethods(self._getMethods(xmlClass))

            # adding fields for this class
            pyutClass.fields = self._getFields(xmlClass)

            # adding fathers
            self._getFathers(xmlClass.getElementsByTagName("Father"),
                             dicoFather, pyutClass.getId())

            # adding link for this class
            dicoLink[pyutClass.getId()] = self._getLinks(xmlClass)[:]

            dicoOglObjects[pyutClass.getId()] = oglClass

            # Adding OGL class to UML Frame
            x = int(xmlOglClass.getAttribute('x'))
            y = int(xmlOglClass.getAttribute('y'))
            umlFrame.addShape(oglClass, x, y)

        return oldData
Beispiel #21
0
    def _getOglClasses(self, xmlOglClasses, 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[] xmlOglClasses : XML 'GraphicClass' 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 xmlOglClass in xmlOglClasses:

            pyutClass: PyutClass = PyutClass()

            # Building OGL class
            height = float(xmlOglClass.getAttribute('height'))
            width = float(xmlOglClass.getAttribute('width'))
            oglClass = OglClass(pyutClass, width, height)

            # Data layer class
            xmlClass = xmlOglClass.getElementsByTagName('Class')[0]

            pyutClass.setId(int(xmlClass.getAttribute('id')))

            # adding name for this class
            # pyutClass.setName(xmlClass.getAttribute('name').encode("charmap"))
            # Python 3 is already utf-8;  don't need to encode anything
            pyutClass.setName(xmlClass.getAttribute('name'))
            # print "PyutXml/open-4d00d"

            # adding description
            pyutClass.description = xmlClass.getAttribute('description')

            # adding stereotype
            if xmlClass.hasAttribute('stereotype'):
                pyutClass.setStereotype(
                    getPyutStereotype(xmlClass.getAttribute('stereotype')))

            # adding display properties (cd)
            value = secure_bool(xmlClass.getAttribute('showStereotype'))
            pyutClass.setShowStereotype(value)
            value = secure_bool(xmlClass.getAttribute('showMethods'))
            pyutClass.showMethods = value
            value = secure_bool(xmlClass.getAttribute('showFields'))
            pyutClass.showFields = value

            # adding associated filename ([email protected])
            pyutClass.setFilename(xmlClass.getAttribute('filename'))

            # adding methods for this class
            pyutClass.methods = self._getMethods(xmlClass)

            # adding fields for this class
            pyutClass.fields = self._getFields(xmlClass)

            dicoOglObjects[pyutClass.getId()] = oglClass

            # Adding OGL class to UML Frame
            x = float(xmlOglClass.getAttribute('x'))
            y = float(xmlOglClass.getAttribute('y'))

            umlFrame.addShape(oglClass, x, y)
Beispiel #22
0
    def getOglClasses(self, xmlOglClasses: NodeList) -> OglClasses:
        """
        Loads to OGL objects
        Parse the XML elements given and build data model for the Pyut classes.

        Args:
            xmlOglClasses:   XML 'GraphicClass' elements

        Returns:
                The built dictionary uses an ID for the key and an OglClass for the value
        """
        oglObjects: OglClasses = cast(OglClasses, {})

        for element in xmlOglClasses:

            xmlOglClass: Element   = cast(Element, element)
            pyutClass:   PyutClass = PyutClass()

            # Some old files used float sizes and positions
            height: int = PyutUtils.strFloatToInt(xmlOglClass.getAttribute(PyutXmlConstants.ATTR_HEIGHT))
            width:  int = PyutUtils.strFloatToInt(xmlOglClass.getAttribute(PyutXmlConstants.ATTR_WIDTH))

            oglClass: OglClass = OglClass(pyutClass, width, height)

            xmlClass: Element = xmlOglClass.getElementsByTagName(PyutXmlConstants.ELEMENT_MODEL_CLASS)[0]

            pyutClass.setId(int(xmlClass.getAttribute(PyutXmlConstants.ATTR_ID)))
            pyutClass.setName(xmlClass.getAttribute(PyutXmlConstants.ATTR_NAME))
            pyutClass.description = xmlClass.getAttribute(PyutXmlConstants.ATTR_DESCRIPTION)
            if xmlClass.hasAttribute(PyutXmlConstants.ATTR_STEREOTYPE):
                pyutClass.setStereotype(getPyutStereotype(xmlClass.getAttribute(PyutXmlConstants.ATTR_STEREOTYPE)))

            # adding display properties (cd)
            value = PyutUtils.secureBoolean(xmlClass.getAttribute(PyutXmlConstants.ATTR_SHOW_STEREOTYPE))
            pyutClass.setShowStereotype(value)
            value = PyutUtils.secureBoolean(xmlClass.getAttribute(PyutXmlConstants.ATTR_SHOW_METHODS))
            pyutClass.showMethods = value
            value = PyutUtils.secureBoolean(xmlClass.getAttribute(PyutXmlConstants.ATTR_SHOW_FIELDS))
            pyutClass.showFields = value

            displayParametersStr: str = xmlClass.getAttribute(PyutXmlConstants.ATTR_DISPLAY_PARAMETERS)

            self.logger.info(f'{pyutClass.name=} -- {displayParametersStr=}')
            if displayParametersStr is None or displayParametersStr == '':
                pyutClass.displayParameters = PyutDisplayParameters.UNSPECIFIED
            else:
                displayParameters: PyutDisplayParameters = PyutDisplayParameters(displayParametersStr)
                pyutClass.displayParameters = displayParameters

            pyutClass.setFilename(xmlClass.getAttribute(PyutXmlConstants.ATTR_FILENAME))

            pyutClass.methods = self._getMethods(xmlClass)
            pyutClass.fields  = self._getFields(xmlClass)

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

            oglClass.SetPosition(x, y)

            oglObjects[pyutClass.getId()] = oglClass

        return oglObjects