def _stepNodes(self, srcShape: Shape, oglCoordinate: OglCoordinate): oldX, oldY = srcShape.GetPosition() newX: int = oglCoordinate.x newY: int = oglCoordinate.y self.logger.info( f'{srcShape} - oldX,oldY: ({oldX},{oldY}) newX,newY: ({newX},{newY})' ) # srcShape.SetPosition(newX, newY)
def SetSelected(self, state: bool = True): """ Select the shape. @param state """ Shape.SetSelected(self, state) if self._resizable: self.ShowSizers(state)
def DrawBorder(self, dc): """ Draw the border of the shape, for fast rendering. """ Shape.DrawBorder(self, dc) sx, sy = self.GetPosition() sx, sy = sx - self._ox, sy - self._oy width, height = self.GetSize() dc.DrawRectangle(sx, sy, width, height)
def Detach(self): """ Detach the shape from its diagram. This is the way to delete a shape. All anchor points are also removed, and link lines too. """ # do not detach a protected shape if self._diagram is not None and not self._protected: Shape.Detach(self) self.ShowSizers(False)
def SetSelected(self, state: bool = True): """ Select the shape (default) or not Args: state: """ Shape.SetSelected(self, state) for ctrl in self._controls: ctrl.SetVisible(state)
def __init__(self, srcAnchor: AnchorPoint, dstAnchor: AnchorPoint): """ Args: srcAnchor: the source anchor of the line. dstAnchor: the destination anchor of the line. """ Shape.__init__(self) self._srcAnchor: AnchorPoint = srcAnchor self._dstAnchor: AnchorPoint = dstAnchor self._controls: ControlPoints = ControlPoints([]) self._drawArrow: bool = True self._arrowSize: int = 8 self._spline: bool = False if srcAnchor: srcAnchor.AddLine(self) if dstAnchor: dstAnchor.AddLine(self)
def DrawBorder(self, dc: DC): """ Draw the border of the shape, for fast rendering. Args: dc """ if self._selected: RectangleShape.DrawBorder(self, dc) else: Shape.DrawBorder(self, dc)
def MoveToFront(self, shape: Shape): """ Move the given shape to the end of the display list => last drawn. Args: shape: The shape to move """ shapes = [shape] + shape.GetAllChildren() for s in shapes: self._shapes.remove(s) self._shapes = self._shapes + shapes
def MoveToBack(self, shape: Shape): """ Move the given shape to the start of the display list => first drawn. Args: shape: The shape to move """ shapes = [shape] + shape.GetAllChildren() for s in shapes: self._shapes.remove(s) self._shapes = shapes + self._shapes
def Detach(self): """ Detach the line and all its line points, including src and dst. """ if self._diagram is not None and not self._protected: Shape.Detach(self) # while loop, because Detach will remove controls from the list on # which we iterate while self._controls: self._controls[0].Detach() self._srcAnchor.RemoveLine(self) self._dstAnchor.RemoveLine(self)
def UpdateModel(self): """ Added by P. Dabrowski <*****@*****.**> (12.11.2005) Updates the model when the shape (view) is moved or resized. """ # change the coordinates of model Shape.UpdateModel(self) # get the size of the shape (view) width, height = self.GetSize() # get the ratio between the model and the shape (view) from # the diagram frame where the shape is displayed. ratio = self.GetDiagram().GetPanel().GetCurrentZoom() # set the new size to the model. self.GetModel().SetSize(round(width//ratio), round(height//ratio))
def UpdateFromModel(self): """ Added by P. Dabrowski <*****@*****.**> (12.11.2005) Updates the shape position and size from the model in the light of a change of state of the diagram frame (here it's only for the zoom) """ # change the position of the shape from the model Shape.UpdateFromModel(self) # get the model size width, height = self.GetModel().GetSize() # get the diagram frame ratio between the shape and the model ratio = self.GetDiagram().GetPanel().GetCurrentZoom() # set the new size to the shape. self._width, self._height = width * ratio, height * ratio
def Draw(self, dc: DC, withChildren=True): """ Draw the point on the dc. Args: dc: withChildren: """ if self._visible or (self._visibleWhenSelected and self._selected): self.__penSaveColor = dc.GetPen().GetColour() Shape.Draw(self, dc, False) self.__resetPenColor(dc) x, y = self.GetPosition() if not self._selected: dc.DrawRectangle(x - 1, y - 1, 3, 3) else: dc.DrawRectangle(x - 3, y - 3, 7, 7) if withChildren: self.DrawChildren(dc)
def Draw(self, dc: DC, withChildren: bool = False): """ Draw the rectangle on the dc. Args: dc: withChildren: Returns: """ if self._visible: Shape.Draw(self, dc, False) if self._drawFrame: sx, sy = self.GetPosition() sx, sy = sx - self._ox, sy - self._oy width, height = self.GetSize() dc.DrawRectangle(sx, sy, width, height) if withChildren: self.DrawChildren(dc) if self._topLeftSizer is not None: self._topLeftSizer.Draw(dc, False)