Exemple #1
0
    def test_lib_oglTextShape(self):
        ogl.OGLInitialize()
        osc = ogl.ShapeCanvas(self.frame)
        self.diagram = ogl.Diagram()
        osc.SetDiagram(self.diagram)
        self.diagram.SetCanvas(osc)

        aShape = ogl.TextShape(50, 50)
        aShape.SetCanvas(osc)
        aShape.AddText("Some nice text here")
        self.diagram.AddShape(aShape)
Exemple #2
0
    def createCommentShape(self, node):
        shape = ogl.TextShape(node.width, node.height)

        shape.SetCanvas(self)
        shape.SetPen(wx.BLACK_PEN)
        shape.SetBrush(wx.LIGHT_GREY_BRUSH)
        shape.SetBrush(wx.RED_BRUSH)
        for line in node.comment.split('\n'):
            shape.AddText(line)

        setpos(shape, node.left, node.top)
        #shape.SetDraggable(True, True)
        self.AddShape(shape)
        node.shape = shape
        shape.node = node

        # wire in the event handler for the new shape
        evthandler = UmlShapeHandler(
            None, self.frame, self
        )  # just init the handler with whatever will be convenient for it to know.
        evthandler.SetShape(shape)
        evthandler.SetPreviousHandler(shape.GetEventHandler())
        shape.SetEventHandler(evthandler)
        self.new_evthandler_housekeeping(evthandler)
Exemple #3
0
 def OnCrearTexto(self, event):
     '''Se crea un texto en el OGL'''
     # Pedimos texto.
     texto = self.__pedir_datos(1)
     if texto is None: return
     if len(texto.strip()) == 0:
         wx.MessageBox(t(u"No puede incluir textos vacíos", self.l),
                       t(u"Atención", self.l), wx.OK)
         return
     # Creamos caja.
     shape = ogl.TextShape(120, 45)
     # Coordenadas.
     valor_x = 100.0
     valor_y = 100.0
     # Posición del texto.
     shape.SetX(valor_x)
     shape.SetY(valor_y)
     # Color y brocha...
     shape.SetPen(wx.GREEN_PEN)
     shape.SetBrush(wx.LIGHT_GREY_BRUSH)
     # Líneas del texto.
     for linea in texto.split('\\n'):
         shape.AddText(linea)
     #shape.AddText(texto)
     # Añadimos texto al canvas.
     self.panel.canvas.AddShape(shape)
     # Lo mostramos.
     self.panel.diagram.ShowAll(1)
     self.Refresh()
     # Manejadores de eventos para que funcione...
     evthandler = MyEvtHandler()
     evthandler.SetShape(shape)
     evthandler.SetPreviousHandler(shape.GetEventHandler())
     shape.SetEventHandler(evthandler)
     # Faltaría incluirlo en alguna estructura interna...
     self.mensajes_texto.add_texto(texto, shape)
Exemple #4
0
 def cargar_datos(self, dict_clases):
     '''Cargamos clases en modelo y widget ogl'''
     if len(dict_clases) == 0:
         self.modelo = modelo_clases()
         self.relacion = modelo_relaciones()
         self.relacion_dep = modelo_relaciones_dependencia()
         self.mensajes_texto = modelo_texto_ogl()
         return
     # Obtenemos estrucuras internas.
     modelo = dict_clases['modelo']
     posicion_cajas = dict_clases['posicion_cajas']
     relacion = dict_clases['relacion']
     # [21-10-2011] Caja de texto.
     mensajes_texto = dict_clases['posiciones_texto']
     # Referenciamos el canvas.
     canvas = self.panel.canvas
     # Recorremos el modelo de clases para pintar los dividedshape.
     for k in modelo:
         clase = k[0]
         nombre = clase.nombre
         atributos = list()
         for j in clase.atributos:
             atributos.append(j[0])
         propiedades = list()
         for j in clase.propiedades:
             propiedades.append(j[0])
         metodos = list()
         for j in clase.metodos:
             metodos.append(j[0])
         # Creamos el DividedShape.
         shape = DividedShape(140, 150, canvas, nombre, propiedades,
                              atributos, metodos)
         # Incluimos la referencia del dividedshape en la estructura.
         k[1] = shape
         # Coordenadas.
         for coord in posicion_cajas:
             if nombre == coord[0]:
                 valor_x = coord[1]
                 valor_y = coord[2]
                 break
         # Posición de la caja.
         shape.SetX(valor_x)
         shape.SetY(valor_y)
         # Añadimos la caja al canvas.
         canvas.AddShape(shape)
         # Lo mostramos.
         self.panel.diagram.ShowAll(1)
         # Manejador de eventos del dividedshape.
         evthandler = MyEvtHandler_p(self.panel_principal,
                                     self.panel_principal)
         evthandler.SetShape(shape)
         evthandler.SetPreviousHandler(shape.GetEventHandler())
         shape.SetEventHandler(evthandler)
         # Refrescamos el frame, para que salga todo.
         self.Refresh  # page.panel_c.p_design.Refresh()
     # Incluimos las estructuras.
     self.modelo.set_clases(modelo)
     self.relacion.set_relaciones(relacion)
     # Creamos relaciones de herencia en el OGL.
     for k in relacion:
         npadre = k[1]
         nhijo = k[2]
         padre = self.modelo.get_divided_shape(npadre)
         hijo = self.modelo.get_divided_shape(nhijo)
         # Línea.
         line = ogl.LineShape()
         line.SetCanvas(canvas)
         line.SetPen(wx.BLACK_PEN)
         line.SetBrush(wx.BLACK_BRUSH)
         line.AddArrow(ogl.ARROW_ARROW)
         line.MakeLineControlPoints(2)
         # Marcamos el sentido de la flecha.
         hijo.AddLine(line, padre)
         # Lo añadimos al canvas.
         canvas.AddShape(line)
         line.Show(True)
         # Refrescamos.
         self.Refresh()
     # Obtenemos todos los nombres de las clases.
     lista_clases = list()
     for k in modelo:
         lista_clases.append(k[0].nombre)
     # Recorremos cada clase para dibujar posibles relaciones de dependencia.
     for k in modelo:
         nombre_clase = k[0].nombre
         atributos = k[0].atributos
         clase_hijo = k[1]  # DividedShape actual.
         # Recorremos todos los atributos.
         for h in atributos:
             valor_predet = h[1]
             # Nombre de clase que está en el valor predeterminado del atributo.
             nombre_clase_padre = valor_predet.split("(")[0].strip()
             # Una clase no se puede autoreferenciar.
             if nombre_clase == nombre_clase_padre: continue
             # Referencia del dividedshape de la clase padre.
             clase_padre = self.modelo.get_divided_shape(nombre_clase_padre)
             # Si no existe, seguimos.
             if clase_padre is None: continue
             # Creamos la relación de dependencia.
             self.relacion_dep.crear_relacion(clase_padre, clase_hijo)
             # Pintamos la relación en el OGL.
             line = ogl.LineShape()
             line.SetCanvas(canvas)
             line.SetPen(wx.RED_PEN)  # wx.LIGHT_GREY_PEN)
             line.SetBrush(wx.RED_BRUSH)  #wx.LIGHT_GREY_BRUSH)
             line.AddArrow(ogl.ATTACHMENT_MODE_BRANCHING)
             line.MakeLineControlPoints(2)
             # Marcamos el sentido de la flecha.
             # clase_hijo.AddLine(line, clase_padre)
             clase_padre.AddLine(line, clase_hijo)
             # Lo añadimos al canvas.
             canvas.AddShape(line)
             line.Show(True)
             # Refrescamos.
             self.Refresh()
     # [21-10-2011] Recorremos cajas de texto.
     self.mensajes_texto.eliminar_todo()  # ELIMINAMOS TODO LO DEL BUFFER!!!
     for k in mensajes_texto:
         # Rescatamos datos.
         texto = k[0]
         coor_x = k[1]
         coor_y = k[2]
         width = k[3]
         height = k[4]
         # Creamos una caja de texto.
         shape = ogl.TextShape(width, height)
         # Color y brocha...
         shape.SetPen(wx.GREEN_PEN)
         shape.SetBrush(wx.LIGHT_GREY_BRUSH)
         # Líneas del texto.
         for linea in texto.split('\\n'):
             shape.AddText(linea)
         shape.SetX(coor_x)
         shape.SetY(coor_y)
         # Añadimos la caja al canvas.
         canvas.AddShape(shape)
         # Lo mostramos.
         self.panel.diagram.ShowAll(1)
         # Manejador de eventos.
         evthandler = MyEvtHandler()
         evthandler.SetShape(shape)
         evthandler.SetPreviousHandler(shape.GetEventHandler())
         shape.SetEventHandler(evthandler)
         # Refrescamos el frame, para que salga todo.
         self.Refresh()
         # Incluimos las estructuras.
         self.mensajes_texto.add_texto(texto, shape)
Exemple #5
0
    def __init__(self, parent, log, frame):
        ogl.ShapeCanvas.__init__(self, parent)

        maxWidth  = 1000
        maxHeight = 1000
        self.SetScrollbars(20, 20, maxWidth/20, maxHeight/20)

        self.log = log
        self.frame = frame
        self.SetBackgroundColour("LIGHT BLUE") #wx.WHITE)
        self.diagram = ogl.Diagram()
        self.SetDiagram(self.diagram)
        self.diagram.SetCanvas(self)
        self.shapes = []
        self.save_gdi = []

        rRectBrush = wx.Brush("MEDIUM TURQUOISE", wx.SOLID)
        dsBrush = wx.Brush("WHEAT", wx.SOLID)

        self.MyAddShape(
            CompositeDivisionShape(self), 
            270, 310, wx.BLACK_PEN, wx.BLUE_BRUSH, "Division"
            )
        
        self.MyAddShape(
            CompositeShape(self), 
            100, 260, wx.BLACK_PEN, wx.RED_BRUSH, "Composite"
            )
        
        self.MyAddShape(
            ogl.CircleShape(80), 
            75, 110, wx.Pen(wx.BLUE, 3), wx.GREEN_BRUSH, "Circle"
            )
            
        self.MyAddShape(
            ogl.TextShape(120, 45), 
            160, 35, wx.GREEN_PEN, wx.LIGHT_GREY_BRUSH, "OGL is now a\npure Python lib!"
            )

        self.MyAddShape(
            ogl.RectangleShape(85, 50), 
            305, 60, wx.BLACK_PEN, wx.LIGHT_GREY_BRUSH, "Rectangle"
            )

        self.MyAddShape(
            DrawnShape(),
            500, 80, wx.BLACK_PEN, wx.BLACK_BRUSH, "DrawnShape"
            )

        ds = self.MyAddShape(
            DividedShape(140, 150, self), 
            520, 265, wx.BLACK_PEN, dsBrush, ''
            )

        self.MyAddShape(
            DiamondShape(90, 90), 
            355, 260, wx.Pen(wx.BLUE, 3, wx.DOT), wx.RED_BRUSH, "Polygon"
            )
            
        self.MyAddShape(
            RoundedRectangleShape(95, 70), 
            345, 145, wx.Pen(wx.RED, 2), rRectBrush, "Rounded Rect"
            )

        bmp = images.Test2.GetBitmap()
        mask = wx.Mask(bmp, wx.BLUE)
        bmp.SetMask(mask)
        
        s = ogl.BitmapShape()
        s.SetBitmap(bmp)
        self.MyAddShape(s, 225, 130, None, None, "Bitmap")

        #dc = wx.ClientDC(self)
        #self.PrepareDC(dc)

        for x in range(len(self.shapes)):
            fromShape = self.shapes[x]
            if x+1 == len(self.shapes):
                toShape = self.shapes[0]
            else:
                toShape = self.shapes[x+1]

            line = ogl.LineShape()
            line.SetCanvas(self)
            line.SetPen(wx.BLACK_PEN)
            line.SetBrush(wx.BLACK_BRUSH)
            line.AddArrow(ogl.ARROW_ARROW)
            line.MakeLineControlPoints(2)
            fromShape.AddLine(line, toShape)
            self.diagram.AddShape(line)
            line.Show(True)