def getOglUseCases(self, xmlOglUseCases: NodeList) -> OglUseCases: """ Parse the XML elements given and build data layer for PyUt actors. Args: xmlOglUseCases: XML 'GraphicUseCase' elements Returns: A dictionary of OglUseCase objects """ oglUseCases: OglUseCases = cast(OglUseCases, {}) for xmlOglUseCase in xmlOglUseCases: pyutUseCase: PyutUseCase = PyutUseCase() # Building OGL UseCase height: int = PyutUtils.strFloatToInt(xmlOglUseCase.getAttribute(PyutXmlConstants.ATTR_HEIGHT)) width: int = PyutUtils.strFloatToInt(xmlOglUseCase.getAttribute(PyutXmlConstants.ATTR_WIDTH)) oglUseCase = OglUseCase(pyutUseCase, width, height) xmlUseCase: Element = xmlOglUseCase.getElementsByTagName(PyutXmlConstants.ELEMENT_MODEL_USE_CASE)[0] pyutUseCase.setId(int(xmlUseCase.getAttribute(PyutXmlConstants.ATTR_ID))) pyutUseCase.setName(xmlUseCase.getAttribute(PyutXmlConstants.ATTR_NAME)) pyutUseCase.setFilename(xmlUseCase.getAttribute(PyutXmlConstants.ATTR_FILENAME)) x: int = PyutUtils.strFloatToInt(xmlOglUseCase.getAttribute(PyutXmlConstants.ATTR_X)) y: int = PyutUtils.strFloatToInt(xmlOglUseCase.getAttribute(PyutXmlConstants.ATTR_Y)) oglUseCase.SetPosition(x, y) oglUseCases[pyutUseCase.getId()] = oglUseCase return oglUseCases
def createNewUseCase(self, x, y): """ Add a new use case at (x, y). @return PyutUseCase : the newly created PyutUseCase """ pyutUseCase: PyutUseCase = PyutUseCase() oglUseCase: OglUseCase = OglUseCase(pyutUseCase) self.addShape(oglUseCase, x, y) self.Refresh() return pyutUseCase
def _getOglUseCases(self, xmlOglUseCases, dicoOglObjects, dicoLink, dicoFather, umlFrame): """ Parse the XML elements given and build data layer for PyUT actors. @param Element[] xmlOglUseCases : XML 'GraphicUseCase' 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 xmlOglUseCase in xmlOglUseCases: pyutUseCase = PyutUseCase() # Building OGL UseCase height = int(xmlOglUseCase.getAttribute('height')) width = int(xmlOglUseCase.getAttribute('width')) oglUseCase = OglUseCase(pyutUseCase, width, height) xmlUseCase = xmlOglUseCase.getElementsByTagName('UseCase')[0] # Backward compatibility (pyut v1.0). If id not present, # auto set by the instantiation of object if xmlUseCase.hasAttribute('id'): pyutUseCase.setId(int(xmlUseCase.getAttribute('id'))) else: oldData = 1 # adding name for this class s = xmlUseCase.getAttribute('name').encode("charmap") pyutUseCase.setName(s) # adding fathers self._getFathers(xmlUseCase.getElementsByTagName("Father"), dicoFather, pyutUseCase.getId()) # Update dicos dicoLink[pyutUseCase.getId()] = self._getLinks(xmlUseCase) dicoOglObjects[pyutUseCase.getId()] = oglUseCase # Update UML Frame x = int(xmlOglUseCase.getAttribute('x')) y = int(xmlOglUseCase.getAttribute('y')) umlFrame.addShape(oglUseCase, x, y) return oldData
def onPaste(self, event: CommandEvent): """ Args: event: """ if len(self._clipboard) == 0: return self.logger.info(f'Pasting {len(self._clipboard)} objects') frame = self._mediator.getUmlFrame() if frame == -1: PyutUtils.displayError(_("No frame to paste into")) return # put the objects in the clipboard and remove them from the diagram x, y = 100, 100 for clipboardObject in self._clipboard: obj: PyutObject = copy(clipboardObject) if isinstance(obj, PyutClass): po: OglObject = OglClass(obj) elif isinstance(obj, PyutNote): po = OglNote(obj) elif isinstance(obj, PyutActor): po = OglActor(obj) elif isinstance(obj, PyutUseCase): po = OglUseCase(obj) else: self.logger.error(f'Error when try to paste object: {obj}') return self.logger.info(f'Pasting: {po=}') self._mediator.getUmlFrame().addShape(po, x, y) x += 20 y += 20 canvas = po.GetDiagram().GetPanel() # the frame that contains the shape # specify the canvas on which we will paint dc: ClientDC = ClientDC(canvas) canvas.PrepareDC(dc) self._treeNotebookHandler.setModified(True) self._mediator.updateTitle() canvas.Refresh()
def _OnMnuEditPaste(self, event: CommandEvent): """ Args: event: """ if len(self._clipboard) == 0: return frame = self._ctrl.getUmlFrame() if frame == -1: PyutUtils.displayError(_("No frame to paste into")) return # put the objects in the clipboard and remove them from the diagram x, y = 100, 100 for obj in self._clipboard: obj = copy(obj) # this is a PyutObject if isinstance(obj, PyutClass): po = OglClass(obj) elif isinstance(obj, PyutNote): po = OglNote(obj) elif isinstance(obj, PyutActor): po = OglActor(obj) elif isinstance(obj, PyutUseCase): po = OglUseCase(obj) else: self.logger.error("Error when try to paste object") return self._ctrl.getUmlFrame().addShape(po, x, y) x += 20 y += 20 canvas = po.GetDiagram().GetPanel() # the canvas that contain the shape # specify the canvas on which we will paint dc = ClientDC(canvas) canvas.PrepareDC(dc) self._mainFileHandlingUI.setModified(True) self._ctrl.updateTitle() canvas.Refresh()
def oglUseCaseToXml(self, oglUseCase: OglUseCase, xmlDoc: Document) -> Element: """ Export an OglUseCase to a minidom Element. Args: oglUseCase: UseCase to convert xmlDoc: xml document Returns: A new minidom element """ root: Element = xmlDoc.createElement( PyutXmlConstants.ELEMENT_GRAPHIC_USE_CASE) self.__appendOglBase(oglUseCase, root) root.appendChild( self._pyutUseCaseToXml(oglUseCase.getPyutObject(), xmlDoc)) return root
def _getOglUseCases(self, xmlOglUseCases, dicoOglObjects, dicoLink, dicoFather, umlFrame): """ Parse the XML elements given and build data layer for PyUT actors. @param Element[] xmlOglUseCases : XML 'GraphicUseCase' 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 xmlOglUseCase in xmlOglUseCases: pyutUseCase = PyutUseCase() # Building OGL UseCase height = float(xmlOglUseCase.getAttribute('height')) width = float(xmlOglUseCase.getAttribute('width')) oglUseCase = OglUseCase(pyutUseCase, width, height) xmlUseCase = xmlOglUseCase.getElementsByTagName('UseCase')[0] pyutUseCase.setId(int(xmlUseCase.getAttribute('id'))) # adding name for this class # pyutUseCase.setName(xmlUseCase.getAttribute('name').encode("charmap")) # Python 3 is already utf-8; don't need to encode anything pyutUseCase.setName(xmlUseCase.getAttribute('name')) # adding associated filename ([email protected]) pyutUseCase.setFilename(xmlUseCase.getAttribute('filename')) # Update dicos dicoOglObjects[pyutUseCase.getId()] = oglUseCase # Update UML Frame x = float(xmlOglUseCase.getAttribute('x')) y = float(xmlOglUseCase.getAttribute('y')) umlFrame.addShape(oglUseCase, x, y)