Ejemplo n.º 1
0
    def __init__(self, pyutObject=None, width: float = 0, height: float = 0):
        """
        Constructor

        @param PyutObject pyutObject : Associated PyutObject
        @param int width  : Initial width
        @param int height : Initial height
        @since 1.0
        @author Philippe Waelti <*****@*****.**>
        """
        RectangleShape.__init__(self, 0, 0, width, height)

        self.logger: Logger = getLogger(__name__)
        self._pyutObject = pyutObject
        """
        Associated PyutObject
        """
        # Default font
        self._defaultFont: Font = Font(DEFAULT_FONT_SIZE, FONTFAMILY_SWISS,
                                       FONTSTYLE_NORMAL, FONTWEIGHT_NORMAL)

        # Connected links
        self._oglLinks = []
        # added by P.Dabrowski 20051202 : it's the command to undo/redo a modification on this object.
        self._modifyCommand = None
Ejemplo n.º 2
0
    def Draw(self, dc: DC, withChildren: bool = True):
        """
        Draw the text on the dc.

        Args:
            dc
            withChildren
        """
        if self._visible:
            RectangleShape.Draw(self, dc, False)
            dc.SetTextForeground(self._color)
            dc.SetBackgroundMode(PENSTYLE_SOLID)
            dc.SetTextBackground(self._textBack)
            x, y = self.GetPosition()

            # to draw the text shape with its own font size
            saveFont: Font = dc.GetFont()
            if self.GetFont() is not None:
                dc.SetFont(self.GetFont())

            dc.DrawText(self._text, x, y)
            dc.SetFont(saveFont)

            if withChildren:
                self.DrawChildren(dc)
Ejemplo n.º 3
0
 def OnInstanceBoxResize(self, sizer, width, height):
     """
     Resize the instance box, so all instance
     """
     RectangleShape.Resize(self._instanceBox, sizer, width, height)
     size = self._instanceBox.GetSize()
     self.SetSize(size[0], self.GetSize()[1])
Ejemplo n.º 4
0
    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])
Ejemplo n.º 5
0
    def initTest(self):

        diagramFrame: Diagram = self._diagramFrame.GetDiagram()

        pointShape: PointShape = PointShape(50, 50)
        diagramFrame.AddShape(pointShape)

        for x in range(10):
            for y in range(3):
                pointShape: PointShape = PointShape(300 + x*50, 300 + y*50)
                diagramFrame.AddShape(pointShape)

        rectShape: RectangleShape = RectangleShape(100, 50, 130, 80)
        rectShape.SetDraggable(True)
        diagramFrame.AddShape(rectShape)

        anchor1 = AnchorPoint(50, 100)
        anchor1.SetDraggable(True)
        anchor2 = AnchorPoint(200, 300)
        anchor2.SetDraggable(True)

        lineShape: LineShape = LineShape(anchor1, anchor2)
        lineShape.SetDrawArrow(False)
        lineShape.SetDraggable(True)
        lineShape.SetSpline(False)

        controlPoint: ControlPoint = ControlPoint(50, 150)
        lineShape.AddControl(controlPoint)
        controlPoint = ControlPoint(200, 150)
        lineShape.AddControl(controlPoint)

        diagramFrame.AddShape(lineShape)

        self.drawLollipops()
Ejemplo n.º 6
0
    def SetSelected(self, state=True):

        from org.pyut.general.Mediator import getMediator  # avoid circular import
        from org.pyut.general.Mediator import ACTION_ZOOM_OUT  # avoid circular import

        if getMediator().getCurrentAction() != ACTION_ZOOM_OUT:
            RectangleShape.SetSelected(self, state)
Ejemplo n.º 7
0
    def __init__(self, x=0.0, y=0.0, width=0.0, height=0.0, parent=None):
        """
        Constructor.

        @param double x, y : position of the point
        @param double width, height : size of the rectangle
        @param Shape parent : parent shape
        """
        RectangleShape.__init__(self, x, y, width, height, parent)
        # this is the definition of the shape
        self._defineShape()
        self._angle = 0                                 # angle is in [0..3], by steps of 90 degrees
        self._vShapes = self._SHAPES[0]                 # currently used list of shapes
        self._InitRotations()                           # create the other rotations if necessary
        self._scale = 1.0                               # scale of the shape
        self._sox, self._soy = self._ox, self._oy       # ox, oy with scale == 1
        self._sw, self._sh = self._width, self._height  # width and height with scale == 1
Ejemplo n.º 8
0
    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)
Ejemplo n.º 9
0
    def SetPosition(self, x, y):
        """
        Define new position for the object

        Args:
            x:
            y:
        """
        from org.pyut.general import Mediator
        fileHandling = Mediator.getMediator().getFileHandling()
        if fileHandling is not None:
            fileHandling.setModified(True)
        RectangleShape.SetPosition(self, x, y)
Ejemplo n.º 10
0
    def Draw(self, dc, withChildren=True):
        """
        Draw the shape on the dc.

        @param  dc
        @param withChildren
        """
        if self._visible:
            RectangleShape.Draw(self, dc, False)
            for shape in self._vShapes:
                shape.Draw(dc, self._x, self._y, self._scale)
            if withChildren:
                self.DrawChildren(dc)
Ejemplo n.º 11
0
    def _BeginSelect(self, event: MouseEvent):
        """
        Create a selector box and manage it.

        @param  event
        """
        if not event.ControlDown():
            self.DeselectAllShapes()
        x, y = event.GetX(), event.GetY()  # event position has been modified
        self._selector = rect = RectangleShape(x, y, 0, 0)
        rect.SetDrawFrame(True)
        rect.SetBrush(TRANSPARENT_BRUSH)
        rect.SetMoving(True)
        self._diagram.AddShape(rect)
        self.PrepareBackground()
        self.Bind(EVT_MOTION, self._OnMoveSelector)
Ejemplo n.º 12
0
    def __init__(self, pyutObject, parentFrame):
        """

        Args:
            pyutObject:
            parentFrame:   TODO figure out how NOT to need this;  Do it in the Draw method
        """

        self._parentFrame = parentFrame
        self._instanceYPosition = 50  # Start of instances position

        diagram = self._parentFrame.GetDiagram()

        super().__init__(pyutObject, OglSDInstance.DEFAULT_WIDTH,
                         OglSDInstance.DEFAULT_HEIGHT)

        self.logger: Logger = getLogger(__name__)
        diagram.AddShape(self)
        self.SetDraggable(True)
        self.SetVisible(True)

        self.SetPen(Pen(Colour(200, 200, 255), 1, PENSTYLE_LONG_DASH))
        self.SetPosition(self.GetPosition()[0], self._instanceYPosition)

        dstAnchorPoint, srcAnchorPoint = self._createAnchorPoints()

        self._lifeLineShape: LineShape = self._createLifeLineShape(
            src=srcAnchorPoint, dst=dstAnchorPoint)
        diagram.AddShape(self._lifeLineShape)

        # Instance box
        self._instanceBox: RectangleShape = RectangleShape(0, 0, 100, 50)

        self.AppendChild(self._instanceBox)
        self._instanceBox.SetDraggable(False)
        self._instanceBox.Resize = self.OnInstanceBoxResize
        self._instanceBox.SetResizable(True)
        self._instanceBox.SetParent(self)
        diagram.AddShape(self._instanceBox)

        # Text of the instance box
        text = self._pyutObject.getInstanceName()
        self._instanceBoxText = OglInstanceName(pyutObject, 20.0, 20.0, text,
                                                self._instanceBox)
        self.AppendChild(self._instanceBoxText)
        diagram.AddShape(self._instanceBoxText)
Ejemplo n.º 13
0
    def drawLollipops(self):

        diagramFrame: Diagram = self._diagramFrame.GetDiagram()

        rectShape: RectangleShape = RectangleShape(400, 50, 130, 80)
        rectShape.SetDraggable(True)
        diagramFrame.AddShape(rectShape)

        dw, dh     = rectShape.GetSize()

        eastX, eastY   = dw, dh / 2

        destAnchor = SelectAnchorPoint(parent=rectShape, attachmentPoint=AttachmentPoint.EAST, x=eastX, y=eastY)
        destAnchor.SetDraggable(False)

        lollipopLine: LollipopLine = LollipopLine(destAnchor)

        diagramFrame.AddShape(lollipopLine)