def getOglNotes(self, xmlOglNotes: NodeList) -> OglNotes: """ Parse the XML elements given and build data layer for PyUt notes. Args: xmlOglNotes: XML 'GraphicNote' elements Returns: The returned dictionary uses a generated ID for the key """ oglNotes: OglNotes = cast(OglNotes, {}) for xmlOglNote in xmlOglNotes: pyutNote: PyutNote = PyutNote() # Building OGL Note height: float = float( xmlOglNote.getAttribute(PyutXmlConstants.ATTR_HEIGHT)) width: float = float( xmlOglNote.getAttribute(PyutXmlConstants.ATTR_WIDTH)) oglNote = OglNote(pyutNote, width, height) xmlNote: Element = xmlOglNote.getElementsByTagName( PyutXmlConstants.ELEMENT_MODEL_NOTE)[0] pyutNote.setId(int(xmlNote.getAttribute(PyutXmlConstants.ATTR_ID))) content: str = xmlNote.getAttribute(PyutXmlConstants.ATTR_NAME) content = content.replace("\\\\\\\\", "\n") pyutNote.content = content pyutNote.setFilename( xmlNote.getAttribute(PyutXmlConstants.ATTR_FILENAME)) # Adding properties necessary to place shape on a diagram frame x: float = float(xmlOglNote.getAttribute(PyutXmlConstants.ATTR_X)) y: float = float(xmlOglNote.getAttribute(PyutXmlConstants.ATTR_Y)) oglNote.SetPosition(x, y) # Update the dictionary oglNotes[pyutNote.getId()] = oglNote return oglNotes
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 _getOglNotes(self, xmlOglNotes, dicoOglObjects, dicoLink, dicoFather, umlFrame): """ Parse the XML elements given and build data layer for PyUT notes. 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[] xmlOglNotes : XML 'GraphicNote' 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 xmlOglNote in xmlOglNotes: pyutNote = PyutNote() # Building OGL Note height = int(xmlOglNote.getAttribute('height')) width = int(xmlOglNote.getAttribute('width')) oglNote = OglNote(pyutNote, width, height) xmlNote = xmlOglNote.getElementsByTagName('Note')[0] # Backward compatibility (pyut v1.0). If id not present, # auto set by the instantiation of object if xmlNote.hasAttribute('id'): pyutNote.setId(int(xmlNote.getAttribute('id'))) else: oldData = 1 # adding name for this class pyutNote.setName(xmlNote.getAttribute('name').encode("charmap")) # adding fathers self._getFathers(xmlNote.getElementsByTagName("Father"), dicoFather, pyutNote.getId()) # Update dicos dicoLink[pyutNote.getId()] = self._getLinks(xmlNote) dicoOglObjects[pyutNote.getId()] = oglNote # Update UML Frame x = int(xmlOglNote.getAttribute('x')) y = int(xmlOglNote.getAttribute('y')) umlFrame.addShape(oglNote, x, y) return oldData
def createNewNote(self, x, y): """ Add a new note at (x, y). @return PyutNote : the newly created PyutNote """ pyutNote: PyutNote = PyutNote("") oglNote: OglNote = OglNote(pyutNote) self.addShape(oglNote, x, y) self.Refresh() return pyutNote
def createNewNote(self, x: int, y: int): """ Add a new note at (x, y). Args: x: y: Returns: the newly created PyutNote """ pyutNote: PyutNote = PyutNote() oglNote: OglNote = OglNote(pyutNote) self.addShape(oglNote, x, y) self.Refresh() return pyutNote
def _getOglNotes(self, xmlOglNotes, dicoOglObjects, dicoLink, dicoFather, umlFrame): """ Parse the XML elements given and build data layer for PyUT notes. 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[] xmlOglNotes : XML 'GraphicNote' 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 xmlOglNote in xmlOglNotes: pyutNote = PyutNote() # Building OGL Note height = float(xmlOglNote.getAttribute('height')) width = float(xmlOglNote.getAttribute('width')) oglNote = OglNote(pyutNote, width, height) xmlNote = xmlOglNote.getElementsByTagName('Note')[0] pyutNote.setId(int(xmlNote.getAttribute('id'))) # adding note content for this class name = xmlNote.getAttribute('name') name = name.replace("\\\\\\\\", "\n") pyutNote.content = name # adding associated filename ([email protected]) pyutNote.setFilename(xmlNote.getAttribute('filename')) # Update dicos dicoOglObjects[pyutNote.getId()] = oglNote # Update UML Frame x = float(xmlOglNote.getAttribute('x')) y = float(xmlOglNote.getAttribute('y')) umlFrame.addShape(oglNote, x, y)
def oglNoteToXml(self, oglNote: OglNote, xmlDoc: Document) -> Element: """ Export an OglNote to a minidom Element. Args: oglNote: Note to convert xmlDoc: xml document Returns: New minidom element """ root: Element = xmlDoc.createElement( PyutXmlConstants.ELEMENT_GRAPHIC_NOTE) self.__appendOglBase(oglNote, root) root.appendChild(self._pyutNoteToXml(oglNote.getPyutObject(), xmlDoc)) return root
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 testSerialize(self): pyutNote: PyutNote = PyutNote(theNoteText='Some note text') pyutNote.fileName = '/Users/hasii/code/PyutNote.java' pyutNote.name = 'UnitTestNote' mockFrame: Mock = Mock(spec=UmlClassDiagramsFrame) mockFrame.GetXOffset.return_value = 0 mockFrame.GetYOffset.return_value = 0 mockFrame.GetCurrentZoom.return_value = 1.0 mockDiagram: Mock = Mock(spec=Diagram) mockDiagram.GetPanel.return_value = mockFrame oglNote: OglNote = OglNote(pyutNote=pyutNote, w=100, h=100) oglNote._diagram = mockDiagram # Normally should not do this; only in unit tess oglNote.SetPosition(1024, 1024) oglNote.SetSize(width=100, height=100) oglNote._id = 3 # too match deserialized file oglLinkedObjectCommand: DeleteOglLinkedObjectCommand = DeleteOglLinkedObjectCommand( shape=oglNote) serializedShape: str = oglLinkedObjectCommand.serialize() self.logger.debug(f'{serializedShape=}') import re fixedSerializedShape = re.sub('shapeId=[0-9]*', 'shapeId=3', serializedShape) self.logger.debug(f'{fixedSerializedShape=}') self.assertIsNotNone(fixedSerializedShape, 'Something must come back') self.maxDiff = None self.assertEqual(self._serializedCommand, fixedSerializedShape, 'Oops, something changed')