def _PyutSDInstance2xml(self, pyutSDInstance: PyutSDInstance, xmlDoc: Document): """ Exporting an PyutSDInstance to an miniDom Element. @param pyutSDInstance : Class to save @param xmlDoc : xml document @return Element : XML Node """ root = xmlDoc.createElement('SDInstance') eltId = self._idFactory.getID(pyutSDInstance) root.setAttribute('id', str(eltId)) root.setAttribute('instanceName', pyutSDInstance.getInstanceName()) root.setAttribute('lifeLineLength', str(pyutSDInstance.getInstanceLifeLineLength())) return root
def createNewSDInstance(self, x, y): """ Create a new sequence diagram instance """ # Create and add instance pyutSDInstance = PyutSDInstance() oglSDInstance = OglSDInstance(pyutSDInstance, self) self.addShape(oglSDInstance, x, oglSDInstance.GetPosition()[1]) return pyutSDInstance
def _getOglSDInstances(self, xmlOglSDInstances, 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[] xmlOglSDInstances : XML 'GraphicSDInstance' 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 xmlOglSDInstance in xmlOglSDInstances: # Main objects pyutSDInstance = PyutSDInstance() oglSDInstance = OglSDInstance(pyutSDInstance, umlFrame) # Data layer xmlSDInstance = xmlOglSDInstance.getElementsByTagName( 'SDInstance')[0] # Pyut Data pyutSDInstance.setId(int(xmlSDInstance.getAttribute('id'))) # pyutSDInstance.setInstanceName(xmlSDInstance.getAttribute('instanceName').encode("charmap")) # Python 3 is already UTF-8 pyutSDInstance.setInstanceName( xmlSDInstance.getAttribute('instanceName')) pyutSDInstance.setInstanceLifeLineLength( secure_int(xmlSDInstance.getAttribute('lifeLineLength'))) dicoOglObjects[pyutSDInstance.getId()] = oglSDInstance # Adding OGL class to UML Frame x = float(xmlOglSDInstance.getAttribute('x')) y = float(xmlOglSDInstance.getAttribute('y')) w = float(xmlOglSDInstance.getAttribute('width')) h = float(xmlOglSDInstance.getAttribute('height')) oglSDInstance.SetSize(w, h) umlFrame.addShape(oglSDInstance, x, y)
def _pyutSDInstanceToXml(self, pyutSDInstance: PyutSDInstance, xmlDoc: Document) -> Element: """ Exporting a PyutSDInstance to an minidom Element. Args: pyutSDInstance: Class to convert xmlDoc: xml document Returns: A new minidom element """ root: Element = xmlDoc.createElement( PyutXmlConstants.ELEMENT_MODEL_SD_INSTANCE) eltId: int = self._idFactory.getID(pyutSDInstance) root.setAttribute(PyutXmlConstants.ATTR_ID, str(eltId)) root.setAttribute(PyutXmlConstants.ATTR_INSTANCE_NAME, pyutSDInstance.getInstanceName()) root.setAttribute(PyutXmlConstants.ATTR_LIFE_LINE_LENGTH, str(pyutSDInstance.getInstanceLifeLineLength())) return root
def getOglSDInstances(self, xmlOglSDInstances: NodeList, umlFrame: UmlFrame) -> OglSDInstances: """ Parse the given XML elements and build data layer for PyUT sequence diagram instances. Args: xmlOglSDInstances: umlFrame: Because of the way SDInstances are constructed they need access to the diagram frame Returns: A dictionary of OglSDInstance objects """ oglSDInstances: OglSDInstances = cast(OglSDInstances, {}) for xmlOglSDInstance in xmlOglSDInstances: pyutSDInstance: PyutSDInstance = PyutSDInstance() oglSDInstance: OglSDInstance = OglSDInstance( pyutSDInstance, umlFrame) xmlSDInstance = xmlOglSDInstance.getElementsByTagName( PyutXmlConstants.ELEMENT_MODEL_SD_INSTANCE)[0] pyutSDInstance.setId( int(xmlSDInstance.getAttribute(PyutXmlConstants.ATTR_ID))) pyutSDInstance.setInstanceName( xmlSDInstance.getAttribute( PyutXmlConstants.ATTR_INSTANCE_NAME)) lifeLineLength: int = PyutUtils.secureInteger( xmlSDInstance.getAttribute( PyutXmlConstants.ATTR_LIFE_LINE_LENGTH)) pyutSDInstance.setInstanceLifeLineLength(lifeLineLength) # Adding OGL class to UML Frame x = float(xmlOglSDInstance.getAttribute(PyutXmlConstants.ATTR_X)) y = float(xmlOglSDInstance.getAttribute(PyutXmlConstants.ATTR_Y)) w = float( xmlOglSDInstance.getAttribute(PyutXmlConstants.ATTR_WIDTH)) h = float( xmlOglSDInstance.getAttribute(PyutXmlConstants.ATTR_HEIGHT)) oglSDInstance.SetSize(w, h) oglSDInstance.SetPosition(x, y) oglSDInstances[pyutSDInstance.getId()] = oglSDInstance # umlFrame.addShape(oglSDInstance, x, y) # currently SD Instance constructor adds itself return oglSDInstances