Пример #1
0
    def BuildRegions(self, canvas):
        region1 = ogl.ShapeRegion()
        region1.SetText('DividedShape')
        region1.SetProportions(0.0, 0.2)
        region1.SetFormatMode(ogl.FORMAT_CENTRE_HORIZ)
        self.AddRegion(region1)

        region2 = ogl.ShapeRegion()
        region2.SetText('This is Region number two.')
        region2.SetProportions(0.0, 0.3)
        region2.SetFormatMode(ogl.FORMAT_NONE)
        #region2.SetFormatMode(ogl.FORMAT_CENTRE_HORIZ|ogl.FORMAT_CENTRE_VERT)
        self.AddRegion(region2)

        region3 = ogl.ShapeRegion()

        region3.SetText("blah\nblah\nblah blah")
        region3.SetProportions(0.0, 0.5)
        region3.SetFormatMode(ogl.FORMAT_NONE)
        self.AddRegion(region3)

        # Andy Added
        self.region1 = region1  # for external access...
        self.region2 = region2  # for external access...
        self.region3 = region3  # for external access...

        self.SetRegionSizes()
        self.ReformatRegions(canvas)
Пример #2
0
    def __init__(self, x=0.0, y=0.0, canvas=None, port=None, parent_port=None):
    
        ogl.DividedShape.__init__(self, x, y)

        nameRegion = ogl.ShapeRegion()
        nameRegion.SetText(port.name)
        nameRegion.SetProportions(0.0, 0.2)
        nameRegion.SetFormatMode(ogl.FORMAT_CENTRE_HORIZ)
        self.AddRegion(nameRegion)
       
        intRegion = ogl.ShapeRegion()
        ts = port.interface.nameSpace + "::" + port.interface.name
        intRegion.SetText(ts)
        intRegion.SetProportions(0.0, 0.3)
        intRegion.SetFormatMode(ogl.FORMAT_CENTRE_HORIZ)
        self.AddRegion(intRegion)
        self.canvas = canvas
        
        opRegion = ogl.ShapeRegion()
        self.parent_port = parent_port
        ts = ''

        for op in port.interface.operations:
            ts += op.cxxReturnType + " " + op.name + " ("
            for x in range(len(op.params)):
                param = op.params[x]
                ts += param.direction + " " + param.cxxType + " " + param.name
                if x != len(op.params)-1:
                    ts += ", "
                else:
                    ts += ")"
            if (self.parent_port.timingData[op.name]['end'][2] != 0):
                time_diff = (self.parent_port.timingData[op.name]['end'][0]-self.parent_port.timingData[op.name]['end'][3])+((self.parent_port.timingData[op.name]['end'][1]-self.parent_port.timingData[op.name]['end'][4])/1000000.0)
                throughput = self.parent_port.timingData[op.name]['end'][2]/time_diff
                ts += "\n\tThroughput: " + "%.2f" % throughput + " sps"
            if op != port.interface.operations[len(port.interface.operations)-1]:
                ts += "\n"

        opRegion.SetText(ts)
        opRegion.SetProportions(0.0, 0.5)
        opRegion.SetFormatMode(ogl.FORMAT_CENTRE_HORIZ)
        x,y = opRegion.GetSize()
        self.text_region = opRegion
        self.port = port
        self.AddRegion(opRegion)

        self.SetRegionSizes()
        self.ReformatRegions(canvas)
Пример #3
0
 def __init__(self, width, height, canvas, nombre_clase, propiedades,
              atributos, metodos):
     '''Constructor de clase'''
     ogl.DividedShape.__init__(self, width, height)
     # Enter.
     enter = '\n'
     # Tipo de letra.
     tipo_letra = wx.Font(8, wx.MODERN, wx.NORMAL, wx.NORMAL, False)
     # Clase.
     region1 = ogl.ShapeRegion()
     region1.SetText(nombre_clase.strip())
     region1.SetColour('Red')
     region1.SetProportions(0.0, 0.1)
     region1.SetFont(tipo_letra)
     region1.SetFormatMode(ogl.FORMAT_CENTRE_HORIZ)
     self.AddRegion(region1)
     # Propiedades y atributos.
     region2 = ogl.ShapeRegion()
     cadena = ''
     for i in propiedades:
         cadena += '@%s%s' % (i, enter)
     #cadena = cadena + '--------' + enter
     if atributos is not None:
         for i in atributos:
             cadena = cadena + i + enter
     region2.SetText(cadena)
     region2.SetProportions(0.0, 0.4)
     region2.SetFont(tipo_letra)
     region2.SetColour('Green')
     region2.SetFormatMode(ogl.FORMAT_CENTRE_HORIZ)
     self.AddRegion(region2)
     # Métodos.
     region3 = ogl.ShapeRegion()
     cadena = ''
     if metodos is not None:
         for i in metodos:
             cadena = cadena + i + enter
     region3.SetText(cadena)
     region3.SetProportions(0.0, 0.8)
     region3.SetFont(tipo_letra)
     region3.SetColour('Blue')
     region3.SetFormatMode(ogl.FORMAT_CENTRE_HORIZ)
     self.AddRegion(region3)
     # Pintamos las divisiones en el dividedshape.
     self.SetRegionSizes()
     self.ReformatRegions(canvas)
Пример #4
0
    def BuildRegions(self, canvas):
        region1 = ogl.ShapeRegion()
        region1.SetText('wxDividedShapeSmall')
        region1.SetProportions(0.0, 0.9)
        region1.SetFormatMode(ogl.FORMAT_CENTRE_HORIZ)
        self.AddRegion(region1)

        self.region1 = region1  # for external access...

        self.SetRegionSizes()
        self.ReformatRegions(canvas)
Пример #5
0
    def __init__(self, width, height, canvas):
        ogl.DividedShape.__init__(self, width, height)

        region1 = ogl.ShapeRegion()
        region1.SetText('DividedShape')
        region1.SetProportions(0.0, 0.2)
        region1.SetFormatMode(ogl.FORMAT_CENTRE_HORIZ)
        self.AddRegion(region1)

        region2 = ogl.ShapeRegion()
        region2.SetText('This is Region number two.')
        region2.SetProportions(0.0, 0.3)
        region2.SetFormatMode(ogl.FORMAT_CENTRE_HORIZ|ogl.FORMAT_CENTRE_VERT)
        self.AddRegion(region2)

        region3 = ogl.ShapeRegion()
        region3.SetText('Region 3\nwith embedded\nline breaks')
        region3.SetProportions(0.0, 0.5)
        region3.SetFormatMode(ogl.FORMAT_NONE)
        self.AddRegion(region3)

        self.SetRegionSizes()
        self.ReformatRegions(canvas)
Пример #6
0
    def newRegion(self, font, name, textLst, maxWidth, totHeight = 10):
        region = ogl.ShapeRegion()
        dc = wx.ClientDC(self.canvas)
        dc.SetFont(font)

        for text in textLst:
            w, h = dc.GetTextExtent(text)
            if w > maxWidth: maxWidth = w
            totHeight = totHeight + h + 0 # interline padding

        region.SetFont(font)
        region.SetText('\n'.join(textLst))
        #region._text = string.join(textLst, '\n')
        region.SetName(name)

        return region, maxWidth, totHeight
Пример #7
0
    def test_lib_oglShapeRegion(self):
        ogl.OGLInitialize()
        osc = ogl.ShapeCanvas(self.frame)
        self.diagram = ogl.Diagram()
        osc.SetDiagram(self.diagram)
        self.diagram.SetCanvas(osc)

        aShape = ogl.RectangleShape(w=50, h=50)
        aShape.SetCanvas(osc)
        self.diagram.AddShape(aShape)

        region1 = ogl.ShapeRegion()
        region1.SetText('DividedShape')
        region1.SetProportions(0.0, 0.2)
        region1.SetFormatMode(ogl.FORMAT_CENTRE_HORIZ)
        aShape.AddRegion(region1)
Пример #8
0
 def AddText(self,
             text,
             lineColour=None,
             textColour=None,
             prop=0.1,
             format=ogl.FORMAT_NONE):
     if text:
         region = ogl.ShapeRegion()
         if lineColour: region.SetPenColour(wxAssertColour(lineColour))
         else: region.SetPenColour(self.lineColour)
         if textColour: region.SetColour(wxAssertColour(textColour))
         else: region.SetColour(self.textColour)
         region.SetText(text)
         region.SetProportions(0.0, prop)
         region.SetFormatMode(format)
         self.AddRegion(region)
Пример #9
0
    def newRegion(self, font, name, textLst, maxWidth, totHeight = 10):
        # Taken from Boa, but put into the canvas class instead of the scrolled window class.
        region = ogl.ShapeRegion()
        dc = wx.ClientDC(self)  # self is the canvas
        dc.SetFont(font)

        for text in textLst:
            w, h = dc.GetTextExtent(text)
            if w > maxWidth: maxWidth = w
            totHeight = totHeight + h + 0 # interline padding

        region.SetFont(font)
        region.SetText('\n'.join(textLst))
        #region._text = string.join(textLst, '\n')
        region.SetName(name)

        return region, maxWidth, totHeight
Пример #10
0
    def __init__(self, canvas, component, wave_display):
        """__init__(self, canvas, component)

        Constructor for ComponentShape.  Sets up default shape sizes, regions, and constraints."""

        ogl.CompositeShape.__init__(self)
        self.compSizeX = 150
        self.compSizeY = 100
        ogl.DividedShape.__init__(self, self.compSizeX, self.compSizeY)
	
        self.SetCanvas(canvas)
        self.component = component
        self.canvas = canvas
        self.wave_display = wave_display    # Stores reference to encapsulating object - handles tool updates

        self.portSizeX = 10
        self.portSizeY = 10
        self.gaugeSizeX = 50
        self.gaugeSizeY = self.portSizeY
        self.portSpacing = 4
        
        nameRegion = ogl.ShapeRegion()
        nameRegion.SetText(component.name)
        nameRegion.SetProportions(0.0, 0.1)
        nameRegion.SetFormatMode(ogl.FORMAT_CENTRE_HORIZ)
        #nameRegion.SetFont(wx.Font(8, wx.SWISS, wx.BOLD, wx.BOLD))
        self.AddRegion(nameRegion)
        self.SetRegionSizes()
        self.ReformatRegions(canvas)

        self.constraining_shape = ogl.RectangleShape(self.compSizeX, self.compSizeY)
        self.uses_shapes = []
        self.prov_shapes = []
        self.gauge_shapes = []

        self.active_provides_port = None

        self.constraining_shape.SetBrush(wx.GREY_BRUSH)
        self.AddChild(self.constraining_shape)
        
        for p in component.ports:
            self.addPort(p)

        uses_constraints = []
        provides_constraints = []
        uses_constraints = self.createPortConstraints(self.constraining_shape, self.uses_shapes,"RIGHT")
        provides_constraints = self.createPortConstraints(self.constraining_shape, self.prov_shapes,"LEFT")

        for x in uses_constraints:
            self.AddConstraint(x)
        for x in provides_constraints:
            self.AddConstraint(x)
           
        self.setupTimingDisplay()
        self.Recompute()

        # If we don't do this, the shapes will be able to move on their
        # own, instead of moving the composite
        self.constraining_shape.SetDraggable(False)
        for x in self.uses_shapes:
            x.SetDraggable(False)
        for x in self.prov_shapes:
            x.SetDraggable(False)

        # If we don't do this the shape will take all left-clicks for itself
        self.constraining_shape.SetSensitivityFilter(0)
        
        # Setup a wx.Window so that we can support "right-click"ing
        self.window = wx.Window(self.GetCanvas(), id=-1, size=wx.Size(-1,-1))
        self.window.Show(False)

        self.compPopup = wx.Menu(title='')
        self.usesMenu = wx.Menu(title='')
        self.providesMenu = wx.Menu(title='')
        self._init_compPopup_Items(self.compPopup)
Пример #11
0
    def setShapeProperties(self, Shape_, **attrs):
        """
        Установить свойства у объекта фигуры.
        """
        if Shape_:
            # Можно передвигать фигуры?
            is_draggable = self.isDraggable()
            Shape_.SetDraggable(is_draggable, is_draggable)
            Shape_.SetCanvas(self)

            # Установить координаты, если они определены
            if self._default_par.get(Shape_.id, None):
                x, y, width, height = self._default_par[Shape_.id]
                Shape_.SetWidth(width)
                Shape_.SetHeight(height)
                Shape_.SetX(x)
                Shape_.SetY(y)
            else:
                if 'pos' in attrs:
                    x, y = tuple(attrs['pos'])
                else:
                    x, y = self.genAutoLayoutPosXY(attrs)
                Shape_.SetX(x)
                Shape_.SetY(y)

                # Установить размер, если они определены
                if 'size' in attrs:
                    width, height = tuple(attrs['size'])
                else:
                    width, height = (150, 100)
                Shape_.SetWidth(width)
                Shape_.SetHeight(height)

            # Перо
            if 'pen' in attrs:
                pen = attrs['pen']
                if type(pen) in (str, unicode):
                    # Перо задано строковым значением
                    pen = eval(pen, globals(), locals())
                Shape_.SetPen(pen)

            # Заливка
            if 'brush' in attrs:
                brush = attrs['brush']
                if type(brush) in (str, unicode):
                    # Заливка задана строковым значением
                    brush = eval(brush, globals(), locals())
                Shape_.SetBrush(brush)

            is_divided_shape = isinstance(Shape_, parentModule.DividedShape)
            # Заголовок
            if 'title' in attrs:
                title = attrs['title']
                if title:
                    if is_divided_shape:
                        region_title = parentModule.ShapeRegion()
                        region_title.SetName('title')
                        region_title.SetText(title)
                        region_title.SetProportions(
                            0.0, 0.3)  # Треть оставить под заголовок
                        region_title.SetFormatMode(
                            parentModule.FORMAT_CENTRE_HORIZ)
                        region_title.SetFont(Shape_.titleFont)
                        Shape_.AddRegion(region_title)
                    else:
                        for line_txt in title.split('\n'):
                            Shape_.AddText(line_txt)
            # Текст
            if 'text' in attrs:
                text = attrs['text']
                if text:
                    if is_divided_shape:
                        region_text = parentModule.ShapeRegion()
                        region_text.SetName('text')
                        region_text.SetText(text)
                        if attrs.get('text2', None):
                            region_text.SetProportions(
                                0.0, 0.4)  # Оставшееся оставить под текст
                        else:
                            region_text.SetProportions(0.0, 0.7)
                        region_text.SetFormatMode(parentModule.FORMAT_NONE)
                        region_text.SetFont(Shape_.textFont)
                        Shape_.AddRegion(region_text)
                    else:
                        for line_txt in text.split('\n'):
                            Shape_.AddText(line_txt)
            # Описание
            if 'text2' in attrs:
                text2 = attrs['text2']
                if text2:
                    if is_divided_shape:
                        region_descr = parentModule.ShapeRegion()
                        region_descr.SetName('text2')
                        region_descr.SetText(text2)
                        region_descr.SetProportions(
                            0.0, 0.3)  # Оставшееся оставить под текст
                        region_descr.SetFormatMode(parentModule.FORMAT_NONE)
                        font = region_descr.GetFont()
                        region_descr.SetFont(Shape_.text2Font)
                        Shape_.AddRegion(region_descr)

            if is_divided_shape:
                Shape_.SetRegionSizes()
                Shape_.ReformatRegions(self)

        return Shape_