def _generateNodeGraphicsSection(self, oglObject: OglObject) -> str: pos = oglObject.GetPosition() x = pos[0] y = pos[1] z = 0 dimensions = oglObject.GetSize() w = dimensions[0] h = dimensions[1] d = 0 gml = ( f'{GMLExporter.doubleTab}{GMLExporter.GRAPHICS_TOKEN} {GMLExporter.START_TOKEN}\n' f'{GMLExporter.tripleTab}{GMLExporter.X_POSITION_TOKEN} {x}\n' f'{GMLExporter.tripleTab}{GMLExporter.Y_POSITION_TOKEN} {y}\n' f'{GMLExporter.tripleTab}{GMLExporter.Z_POSITION_TOKEN} {z}\n' f'{GMLExporter.tripleTab}{GMLExporter.WIDTH_TOKEN} {w}\n' f'{GMLExporter.tripleTab}{GMLExporter.HEIGHT_TOKEN} {h}\n' f'{GMLExporter.tripleTab}{GMLExporter.DEPTH_TOKEN} {d}\n' f'{GMLExporter.tripleTab}type "rectangle"\n' f'{GMLExporter.tripleTab}width 0.12\n' f'{GMLExporter.tripleTab}fill "#ff0000"\n' f'{GMLExporter.tripleTab}outline "#000000"\n' f'{GMLExporter.doubleTab}{GMLExporter.END_TOKEN}\n' ) return gml
def SetSize(self, width, height): """ """ OglObject.SetSize(self, width, height) # Set lifeline # self._lifeLineX = width/2 # (myX, myY) = self.GetPosition() (myX, myY) = self.GetPosition() (w, h) = self.GetSize() lineDst = self._lifeLineShape.GetDestination() lineSrc = self._lifeLineShape.GetSource() lineSrc.SetDraggable(True) lineDst.SetDraggable(True) lineSrc.SetPosition(w / 2 + myX, 0 + myY) lineDst.SetPosition(w / 2 + myX, height + myY) lineSrc.SetDraggable(False) lineDst.SetDraggable(False) # Update all links positions for link in self._oglLinks: try: link.updatePositions() except (ValueError, Exception) as e: self.logger.error(f'Link update position error: {e}') # Set TextBox RectangleShape.SetSize(self._instanceBox, width, self._instanceBox.GetSize()[1])
def Draw(self, dc: DC, withChildren: bool = False): """ Paint handler, draws the content of the shape. Args: dc: device context to draw to withChildren: Redraw children or not """ OglObject.Draw(self, dc) dc.SetFont(self._textFont) w, h = self.GetSize() baseX, baseY = self.GetPosition() dc.SetClippingRegion(baseX, baseY, w, h) noteContent = cast(PyutText, self.getPyutObject()).content lines = LineSplitter().split(noteContent, dc, w - 2 * OglText.MARGIN) x = baseX + OglText.MARGIN y = baseY + OglText.MARGIN for line in range(len(lines)): dc.DrawText(lines[line], x, y + line * (dc.GetCharHeight() + 5)) dc.DestroyClippingRegion()
def Draw(self, dc: DC, withChildren: bool = False): """ Paint handler, draws the content of the shape. Args: dc: device context to draw to withChildren: Redraw children or not """ OglObject.Draw(self, dc) dc.SetFont(self._defaultFont) w, h = self.GetSize() try: # lines = LineSplitter().split(self.getPyutObject().getName(), dc, w - 2 * MARGIN) # noteName = self.getPyutObject().getName() noteContent = self.getPyutObject().content lines = LineSplitter().split(noteContent, dc, w - 2 * OglNote.MARGIN) except (ValueError, Exception) as e: self.logger.error(f"Unable to display note - {e}") return baseX, baseY = self.GetPosition() dc.SetClippingRegion(baseX, baseY, w, h) x = baseX + OglNote.MARGIN y = baseY + OglNote.MARGIN for line in range(len(lines)): dc.DrawText(lines[line], x, y + line * (dc.GetCharHeight() + 5)) dc.DrawLine(baseX + w - OglNote.MARGIN, baseY, baseX + w, baseY + OglNote.MARGIN) dc.DestroyClippingRegion()
def Draw(self, dc: DC, withChildren: bool = False): """ Draw the actor. @param dc : Device context @param withChildren Draw the children or not @since 1.0 @author Philippe Waelti <*****@*****.**> """ OglObject.Draw(self, dc) # Get current font dc.SetFont(self._defaultFont) # Gets the minimum bounding box for the shape width, height = self.GetSize() # Calculate the top center of the shape x, y = self.GetPosition() # drawing is restricted in the specified region of the device dc.SetClippingRegion(x, y, width, height) # Our sweet actor size actorWidth = width actorHeight = 0.8 * (height - 2.0 * MARGIN) # 80 % of total height sizer = min(actorHeight, actorWidth) # Draw our actor head centerX = x + width // 2 centerY = y + height // 2 x = centerX - 0.2 * sizer y += MARGIN dc.DrawEllipse(x, y, 0.4 * sizer, 0.4 * sizer) # Draw body and arms x = centerX y += 0.4 * sizer dc.DrawLine(x, y, x, y + 0.3 * actorHeight) dc.DrawLine(x - 0.25 * actorWidth, y + 0.15 * actorHeight, x + 0.25 * actorWidth, y + 0.15 * actorHeight) # And the feet y += 0.3 * actorHeight dc.DrawLine(x, y, x - 0.25 * actorWidth, y + 0.3 * actorHeight) dc.DrawLine(x, y, x + 0.25 * actorWidth, y + 0.3 * actorHeight) # Draw our buddy name textWidth, textHeight = dc.GetTextExtent( self.getPyutObject().getName()) y = centerY + 0.5 * height - MARGIN - 0.1 * actorHeight dc.DrawText(self.getPyutObject().getName(), x - 0.5 * textWidth, y) dc.DestroyClippingRegion()
def _appendOglBase(self, oglObject: OglObject, root): """ Saves the position and size of the OGL object in XML node. @param OglObject oglObject : OGL Object @param Element root : XML node to write @author Philippe Waelti <*****@*****.**> """ # Saving size # w, h = oglObject.GetBoundingBoxMin() w, h = oglObject.GetSize() root.setAttribute('width', str(int(w))) root.setAttribute('height', str(int(h))) # Saving position # x = int(oglObject.GetX()) # y = int(oglObject.GetY()) x, y = oglObject.GetTopLeft() root.setAttribute('x', str(x)) root.setAttribute('y', str(y))
def __appendOglBase(self, oglObject: OglObject, root: Element) -> Element: """ Saves the position and size of the OGL object in XML node. Args: oglObject: OGL Object root: XML node to update Returns: The updated element """ # Saving size w, h = oglObject.GetModel().GetSize() root.setAttribute(PyutXmlConstants.ATTR_WIDTH, str(float(w))) root.setAttribute(PyutXmlConstants.ATTR_HEIGHT, str(float(h))) # Saving position x, y = oglObject.GetModel().GetPosition() root.setAttribute(PyutXmlConstants.ATTR_X, str(x)) root.setAttribute(PyutXmlConstants.ATTR_Y, str(y)) return root
def Draw(self, dc, withChildren=False): """ Paint handler, draws the content of the shape. WARNING : Every change here must be reported in autoResize pyutMethod Args: dc: device context to draw to withChildren: """ pyutObject: PyutClass = cast(PyutClass, self.pyutObject) # Draw rectangle shape OglObject.Draw(self, dc) # drawing is restricted in the specified region of the device w, h = self._width, self._height x, y = self.GetPosition() # Get position dc.SetClippingRegion(x, y, w, h) # Draw header (headerX, headerY, headerW, headerH) = self.calculateClassHeader(dc, True) y = headerY + headerH if pyutObject.showFields is True: # Draw line dc.DrawLine(x, y, x + w, y) # Draw fields (fieldsX, fieldsY, fieldsW, fieldsH) = self.calculateClassFields(dc, True, initialY=y) y = fieldsY + fieldsH # Draw line dc.DrawLine(x, y, x + w, y) # # Method needs to be called even though returned values not used -- TODO look at refactoring # if pyutObject.showMethods is True: (methodsX, methodsY, methodsW, methodsH) = self.calculateClassMethods(dc, True, initialY=y, calcWidth=True) # noinspection PyUnusedLocal y = methodsY + methodsH dc.DestroyClippingRegion()
def __appendOglBase(self, oglObject: OglObject, root: Element) -> Element: """ Saves the position and size of the OGL object in XML node. Args: oglObject: OGL Object root: XML node to update Returns: The updated element """ # Saving size w, h = oglObject.GetModel().GetSize() simpleW, simpleH = self.__getSimpleDimensions(w, h) root.setAttribute(PyutXmlConstants.ATTR_WIDTH, simpleW) root.setAttribute(PyutXmlConstants.ATTR_HEIGHT, simpleH) # Saving position x, y = oglObject.GetModel().GetPosition() simpleX, simpleY = self.__getSimpleCoordinates(x, y) root.setAttribute(PyutXmlConstants.ATTR_X, simpleX) root.setAttribute(PyutXmlConstants.ATTR_Y, simpleY) return root
def Draw(self, dc: DC, withChildren=False): """ Draw the actor. @param dc : Device context @param withChildren @since 1.0 @author Philippe Waelti <*****@*****.**> """ OglObject.Draw(self, dc, withChildren) dc.SetFont(self._defaultFont) # Gets the minimum bounding box for the shape width, height = self.GetSize() # Calculate the top left of the shape x, y = self.GetPosition() # Draw ellipse dc.DrawEllipse(x + 1, y + 1, width - 2, height - 2) # Draw text x += round(0.25 * width) y += round(0.25 * height) textWidth: int = round(0.6 * width) # Text area width space: int = round(1.1 * dc.GetCharHeight()) # Space between lines # Drawing is restricted in the specified region of the device dc.SetClippingRegion(x, y, textWidth, round(0.6 * height)) # Split lines lines = LineSplitter().split(self.pyutObject.getName(), dc, textWidth) # Draw text for line in lines: dc.DrawText(line, x, y) y += space dc.DestroyClippingRegion()
def __displayAnOglObject(self, oglObject: OglObject, umlFrame: UmlDiagramsFrame): x, y = oglObject.GetPosition() umlFrame.addShape(oglObject, x, y)
def Resize(self, sizer, width, height): """ Resize the rectangle according to the new position of the sizer. """ OglObject.Resize(self, sizer, width, height)
def SetPosition(self, x, y): """ """ y = self._instanceYPosition OglObject.SetPosition(self, x, y)
def Draw(self, dc: DC, withChildren: bool = False): """ Draw an actor Args: dc: The device context to draw on withChildren: Draw the children or not """ OglObject.Draw(self, dc) # Get current font dc.SetFont(self._defaultFont) # Gets the minimum bounding box for the shape width, height = self.GetSize() # Calculate the top center of the shape x, y = self.GetPosition() # drawing is restricted in the specified region of the device dc.SetClippingRegion(x, y, width, height) # Our sweet actor size actorWidth = width actorHeight = int(0.8 * (height - 2.0 * MARGIN)) # 80 % of total height sizer = min(actorHeight, actorWidth) # Draw our actor head centerX = x + width // 2 centerY = y + height // 2 x = int(centerX - 0.2 * sizer) y += MARGIN percentageSizer: int = int(0.4 * sizer) # dc.DrawEllipse(x, y, 0.4 * sizer, 0.4 * sizer) dc.DrawEllipse(x, y, percentageSizer, percentageSizer) # Draw body and arms x = centerX y += round(0.4 * sizer) # dc.DrawLine(x, y, x, y + 0.3 * actorHeight) # dc.DrawLine(x - 0.25 * actorWidth, y + 0.15 * actorHeight, # x + 0.25 * actorWidth, y + 0.15 * actorHeight) dc.DrawLine(x, y, x, y + round(0.3 * actorHeight)) dc.DrawLine(round(x - 0.25 * actorWidth), round(y + 0.15 * actorHeight), round(x + 0.25 * actorWidth), round(y + 0.15 * actorHeight)) # And the feet # y += round(0.3 * actorHeight) # dc.DrawLine(x, y, x - 0.25 * actorWidth, y + 0.3 * actorHeight) # dc.DrawLine(x, y, x + 0.25 * actorWidth, y + 0.3 * actorHeight) actorFeetPercentage: int = round(0.3 * actorHeight) y += round(actorFeetPercentage) # dc.DrawLine(x, y, x - 0.25 * actorWidth, y + actorFeetPercentage) # dc.DrawLine(x, y, x + 0.25 * actorWidth, y + actorFeetPercentage) dc.DrawLine(x, y, x - round(0.25 * actorWidth), y + actorFeetPercentage) dc.DrawLine(x, y, x + round(0.25 * actorWidth), y + actorFeetPercentage) # Draw our buddy name textWidth, textHeight = dc.GetTextExtent(self.pyutObject.getName()) # y = centerY + 0.5 * height - MARGIN - 0.1 * actorHeight y = round(centerY + 0.5 * height - MARGIN - 0.1 * actorHeight) # dc.DrawText(self.getPyutObject().getName(), x - 0.5 * textWidth, y) dc.DrawText(self.pyutObject.getName(), round(x - 0.5 * textWidth), y) dc.DestroyClippingRegion()