Beispiel #1
0
 def createSolidPen(self, name, R, G, B, width = 1):
     pen = Pen()
     pen.SetWidth(width)
     pen.SetStyle(PENSTYLE_SOLID)
     pen.SetColour(Colour(R, G, B))
     self._pens[name] = pen
     return
Beispiel #2
0
    def drawElements(self, dc, canvas, tick):
        """
        Draw elements in the list to the given dc
        """
        elements = canvas.GetDrawPairs()  # Uses bounds
        xoff, yoff = canvas.GetRenderOffsets()
        _, reason_brushes = canvas.GetBrushes()
        vis_tick = canvas.GetVisibilityTick()

        needs_brush_purge = False
        for pair in elements:
            if pair.GetVisibilityTick() != vis_tick:
                continue  # Skip drawing - not visible (probably not on screen)

            string_to_display = pair.GetVal()
            e = pair.GetElement()

            # hack: probably should be handled during update calls
            if e.NeedsDatabase() and e.BrushCacheNeedsPurging():
                e.SetBrushesWerePurged()
                needs_brush_purge = True

            if not e.ShouldDraw():
                continue

            dr = e.GetDrawRoutine()
            if dr:
                # Custom routine.
                dr(e, pair, dc, canvas, tick)
                continue

            (c_x, c_y), (
                c_w,
                c_h) = e.GetProperty('position'), e.GetProperty('dimensions')
            (c_x, c_y) = (c_x - xoff, c_y - yoff)

            color = e.GetProperty('color')
            content_type = e.GetProperty('Content')

            c_color = Colour(color[0], color[1], color[2])

            color_rgb = c_color.GetRGB()
            if color_rgb in self.c_pens_map:
                dc.SetPen(self.c_pens_map[color_rgb])
            else:
                c_pen = Pen(c_color, 1)
                self.c_pens_map[color_rgb] = c_pen
                dc.SetPen(c_pen)

            dc.SetClippingRegion(c_x, c_y, c_w, c_h)
            self.drawInfoRectangle(dc, canvas,
                                   (c_x, c_y, c_w, c_h), string_to_display,
                                   pair.IsMissingLocation(), content_type,
                                   (e.GetProperty('color_basis_type'),
                                    e.GetProperty('auto_color_basis')),
                                   (c_x, c_w))
            dc.DestroyClippingRegion()

        if needs_brush_purge:
            canvas.PurgeBrushCache()  # will take care of new render call
Beispiel #3
0
 def createPens(self):
     # PENS
     self.pens = {}
     # margin
     pen = Pen()
     pen.SetWidth(1)
     pen.SetStyle(PENSTYLE_SOLID)
     pen.SetColour(Colour(180, 50, 50))
     self.pens['margin'] = pen
     # cursor
     pen = Pen()
     pen.SetWidth(2)
     pen.SetStyle(PENSTYLE_SOLID)
     pen.SetColour(Colour(255, 255, 255))
     self.pens['cursor'] = pen
     # done
     return
Beispiel #4
0
    def _getGridPen(self) -> Pen:

        gridLineColor: Colour = PyutColorEnum.toWxColor(
            self._prefs.gridLineColor)
        gridLineStyle: PenStyle = PyutPenStyle.toWxPenStyle(
            self._prefs.gridLineStyle)

        pen: Pen = Pen(PenInfo(gridLineColor).Style(gridLineStyle).Width(1.0))

        return pen
Beispiel #5
0
    def __init__(self, srcShape: OglObject, pyutLink: PyutLink, dstShape: OglObject):
        """

        Args:
            srcShape:  Source shape
            pyutLink:  Conceptual links associated with the graphical links.
            dstShape: Destination shape
        """
        super().__init__(srcShape, pyutLink, dstShape)
        self.SetDrawArrow(False)
        self.SetPen(Pen("BLACK", 1, PENSTYLE_LONG_DASH))
Beispiel #6
0
    def DrawSeparator(self, dc, rect, n):
        sepwidth = rect.width - self.padding.x * 2

        if self.separator:
            sepheight = self.separator.Size.height
            seppos = (self.padding.x,
                      rect.y + rect.height // 2 - sepheight // 2)
            self.separator.Draw(dc, RectPS(seppos, (sepwidth, sepheight)))
        else:
            dc.Pen = Pen(self.normalfc, 1)
            seppos = Point(self.padding.x, rect.y + rect.height // 2)
            endpos = seppos + Point(sepwidth, 0)
            dc.DrawLinePoint(seppos, endpos)
Beispiel #7
0
 def __init__(self, *args):
     self.c_pens_map = {}
     self.__reason_brushes = None
     self.__backgroun_brushes = None
     self.__extensions = None
     self.c_font = None
     self.c_bold_font = None
     self.c_char_width = None
     self.c_char_height = None
     self.NUM_REASON_COLORS = 16
     self.NUM_ANNOTATION_COLORS = 32
     self.NUM_ANNOTATION_SYMBOLS = 52
     self.ANNOTATION_SYMBOL_STRING = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
     self.HIGHLIGHTED_PEN = Pen(Colour(255, 0, 0), 2)
Beispiel #8
0
    def Draw(self, dc, withChildren=True):
        """
        Draw overload; update labels
        """
        # Update labels
        self._instanceBoxText.SetText(self._pyutObject.getInstanceName())

        # Call parent's Draw method
        if self.IsSelected():
            self.SetVisible(True)
            self.SetPen(Pen(Colour(200, 200, 255), 1, PENSTYLE_LONG_DASH))

        # Draw
        # OglObject.Draw(self, dc)
        super().Draw(dc=dc, withChildren=withChildren)
Beispiel #9
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)
Beispiel #10
0
    def __init__(self, srcShape: OglClass, pyutLink: PyutLink,
                 dstShape: OglClass):
        """

        Args:
            srcShape:  Source shape
            pyutLink:  Conceptual links associated with the graphical links.
            dstShape: Destination shape
        """
        super().__init__(srcShape, pyutLink, dstShape)

        self.SetPen(Pen("BLACK", 1, PENSTYLE_LONG_DASH))
        self.SetBrush(WHITE_BRUSH)
        self._labels = {CENTER: self.AddText(0, 0, "")}

        # Initialize labels objects
        self.updateLabels()
        self.SetDrawArrow(True)
Beispiel #11
0
 def createPens(self):
     self.pens = {}
     pen = Pen()
     pen.SetWidth(1)
     pen.SetStyle(PENSTYLE_SOLID)
     pen.SetColour(Colour(180, 50, 50))
     self.pens['margin'] = pen
     pen = Pen()
     pen.SetWidth(2)
     pen.SetStyle(PENSTYLE_SOLID)
     pen.SetColour(Colour(255, 255, 255))
     self.pens['cursor'] = pen
     pen = Pen()
     pen.SetStyle(PENSTYLE_TRANSPARENT)
     self.pens['transparent'] = pen
     # done
     return
Beispiel #12
0
    def Start(self):

        # define colors
        self.colours = {}
        self.colours['bkgd'] = Colour(52, 61, 70)
        self.colours['text'] = Colour(255, 255, 255)
        self.colours['numb'] = Colour(160, 160, 160)
        self.colours['sepr'] = Colour(200, 120, 120)
        self.colours['selbgd'] = Colour(92, 101, 110)
        self.colours['seltxt'] = Colour(255, 255, 255)

        # brushes
        self.brushes = {}
        # normal background
        b = Brush()
        b.SetStyle(BRUSHSTYLE_SOLID)
        b.SetColour(self.colours['bkgd'])
        self.brushes['bkgd'] = b

        # selected background
        b = Brush()
        b.SetStyle(BRUSHSTYLE_SOLID)
        b.SetColour(self.colours['selbgd'])
        self.brushes['selbgd'] = b

        # pens
        self.pens = {}
        p = Pen()
        p.SetColour(self.colours['sepr'])
        p.SetWidth(1)
        p.SetStyle(PENSTYLE_SOLID)
        self.pens['sepr'] = p

        # create device context to work on bitmaps
        dc = MemoryDC()

        # define font
        self.fonts = {}
        f = Font()
        f.SetFamily(FONTFAMILY_ROMAN)
        f.SetFaceName("Monospace")
        f.SetEncoding(FONTENCODING_DEFAULT)
        f.SetStyle(FONTSTYLE_NORMAL)
        f.SetWeight(FONTWEIGHT_NORMAL)
        f.SetUnderlined(False)
        f.SetPointSize(10)
        self.fonts['monospace'] = f

        # select font
        f = 'monospace'

        # get font size
        dc.SetFont(self.fonts[f])
        w, h = dc.GetTextExtent(' ')

        # build character dictionary
        self.rawChars = {}
        # standard printable ascii table
        for c in range(32, 126):
            self.rawChars[chr(c)] = None
        # extra characters (UK)
        self.rawChars['£'] = None
        # save character size
        self.rawChars['Size'] = w, h

        # set background color
        dc.SetBackground(self.brushes['bkgd'])

        # build characters bitmaps
        for C in self.rawChars.keys():
            if C == 'Size': continue
            # instanciate character bitmap
            self.rawChars[C] = Bitmap(w, h, BITMAP_SCREEN_DEPTH)
            # select bitmap
            dc.SelectObject(self.rawChars[C])
            # clear bitmap
            dc.Clear()
            # set text color
            dc.SetTextForeground(self.colours['text'])
            # draw character shape and color
            dc.DrawText(C, 0, 0)
        # done
        dc.SelectObject(NullBitmap)

        # build selected dictionary
        self.selChars = {}
        # standard printable ascii table
        for c in range(32, 126):
            self.selChars[chr(c)] = None
        # extra characters (UK)
        self.selChars['£'] = None
        # save character size
        self.selChars['Size'] = w, h

        # set background color
        dc.SetBackground(self.brushes['selbgd'])

        # build selected bitmaps
        for C in self.selChars.keys():
            if C == 'Size': continue
            # instanciate character bitmap
            self.selChars[C] = Bitmap(w, h, BITMAP_SCREEN_DEPTH)
            # select bitmap
            dc.SelectObject(self.selChars[C])
            # clear bitmap
            dc.Clear()
            # set text color
            dc.SetTextForeground(self.colours['seltxt'])
            # draw character shape and color
            dc.DrawText(C, 0, 0)
        # done
        dc.SelectObject(NullBitmap)

        # create bitmap buffer display and clear buffer
        self.bitmapBuffer = Bitmap(
            128 * w,  # bitmap width
            10 * h,  # bitmap height
            BITMAP_SCREEN_DEPTH)  # bitmap depth
        dc.SelectObject(self.bitmapBuffer)
        dc.SetBackground(self.brushes['bkgd'])
        dc.Clear()
        dc.SelectObject(NullBitmap)

        # reference BackgroundBitmap to bitmapBuffer
        self.Panel.BackgroundBitmap = self.bitmapBuffer

        # adjust frame position
        scrw, scrh = 3840, 1200  # screen size
        w, h = self.Panel.BackgroundBitmap.GetSize()
        self.Frame.SetPosition(Point(scrw / 4 - 128 * 8 / 2, 800))

        # draw text string
        dc.SelectObject(self.bitmapBuffer)

        t = list("hello")
        # select buffer
        # draw text
        X = 0
        w, h = self.rawChars['Size']
        for c in t:
            dc.DrawBitmap(self.rawChars[c], X, 0)
            X += w

        t = list("World!")
        # select buffer
        # draw text
        X = 0
        w, h = self.selChars['Size']
        for c in t:
            dc.DrawBitmap(self.selChars[c], X, h)
            X += w

        # release bitmap
        dc.SelectObject(NullBitmap)

        # done
        return