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)
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