示例#1
0
    def link_to(self, item):
        canv = self.canvas
        line = ogl.LineShape()
        line.SetCanvas(canv)
        line.SetPen(wx.BLACK_PEN)
        line.SetBrush(wx.BLACK_BRUSH)
        line.AddArrow(ogl.ARROW_ARROW)
        line.MakeLineControlPoints(2)
        self.AddLine(line, item)
        canv.diagram.AddShape(line)
        line.Show(True)
        self.links.append(line)

        dc = wx.ClientDC(canv)
        canv.PrepareDC(dc)

        # for some reason, the shapes have to be moved for the line to show up...
        self.Move(dc, self.GetX(), self.GetY())
示例#2
0
    def test_lib_oglLineShape(self):
        ogl.OGLInitialize()
        osc = ogl.ShapeCanvas(self.frame)
        self.diagram = ogl.Diagram()
        osc.SetDiagram(self.diagram)
        self.diagram.SetCanvas(osc)

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

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

        lShape = ogl.LineShape()
        lShape.SetCanvas(osc)
        lShape.MakeLineControlPoints(2)
        fromShape.AddLine(lShape, toShape)
        self.diagram.AddShape(lShape)
        lShape.Show(True)
示例#3
0
    def DrawAssocLines(self, associations, arrowtype, dc):
        for fromClassname, toClassname in associations:
            #print 'DrawAssocLines', fromClassname, toClassname

            if fromClassname not in self.classnametoshape:
                self._BuildAuxClasses(classestocreate=[fromClassname]) # Emergency creation of some unknown class.
            fromShape = self.classnametoshape[fromClassname]

            if toClassname not in self.classnametoshape:
                self._BuildAuxClasses(classestocreate=[toClassname]) # Emergency creation of some unknown class.
            toShape = self.classnametoshape[toClassname]

            line = ogl.LineShape()
            line.SetCanvas(self)
            line.SetPen(wx.BLACK_PEN)
            line.SetBrush(wx.BLACK_BRUSH)
            line.AddArrow(arrowtype)
            line.MakeLineControlPoints(2)
            fromShape.AddLine(line, toShape)
            self.diagram.AddShape(line)
            line.Show(True)
示例#4
0
 def OnAceptar(self, event):
     '''Event handler de creación de relación'''
     # Obtenemos nombre de clases padre e hijo.
     npadre = self.m_comboBox_padre.GetStringSelection()
     nhijo = self.m_comboBox_hijo.GetStringSelection()
     if len(npadre) == 0 or len(nhijo) == 0: return
     # Padre e hijo no pueden ser el mismo.
     if npadre == nhijo:
         msj = t(u'Una clase no puede heredar de si misma', self.l)
         wx.MessageBox(msj, t(u"Atención", self.l), wx.OK)
         return
     # Si existe la relación, no se puede volver a crear.
     if self.padre.padre.relacion.existe_relacion(npadre, nhijo):
         msj = t(u'¡La relación ya existe!', self.l)
         wx.MessageBox(msj, t(u"Atención", self.l), wx.OK)
         return
     # Obtenemos los dividedshape.
     padre = self.padre.padre.modelo.get_divided_shape(npadre)
     hijo = self.padre.padre.modelo.get_divided_shape(nhijo)
     # Línea.
     line = ogl.LineShape()
     line.SetCanvas(self.padre.padre.panel.canvas)
     # line = ogl.LineShape()
     # line.SetCanvas(self)
     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.
     self.padre.padre.panel.canvas.AddShape(line)
     line.Show(True)
     # Refrescamos el padre.
     self.padre.padre.panel.Refresh()
     # Incluimos la relación.
     self.padre.padre.relacion.crear_relacion(npadre, nhijo)
     # Limpiamos memoria.
     self.padre.Destroy()
示例#5
0
    def CreateUmlEdge(self, edge):
        fromShape = edge['source'].shape
        toShape = edge['target'].shape

        edge_label = edge.get('uml_edge_type', '')
        if edge_label == 'generalisation':
            arrowtype = ogl.ARROW_ARROW
        elif edge_label == 'composition':
            arrowtype = ogl.ARROW_FILLED_CIRCLE
        else:
            arrowtype = None

        line = ogl.LineShape()
        line.SetCanvas(self)
        line.SetPen(wx.BLACK_PEN)
        line.SetBrush(wx.BLACK_BRUSH)
        if arrowtype:
            line.AddArrow(arrowtype)
        line.MakeLineControlPoints(2)

        fromShape.AddLine(line, toShape)
        self.GetDiagram().AddShape(line)
        line.Show(True)
示例#6
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)
示例#7
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)
 def dibujar_cajas(self, datos):
     '''Método para dibujar clases y sus relaciones en OGL'''
     # Hacemos algo de limpieza...
     self.panel.panel.diagram.DeleteAllShapes()
     self.panel.panel.Refresh()
     # Referenciamos el canvas.
     canvas = self.panel.panel.canvas
     # Valores de posición iniciales.
     valor_x = 100.0
     valor_y = 100.0
     # Estructura de referencias a los DividedShape.
     clases = list()
     # Recorremos las clases para dibujar las cajas..
     for k in datos:
         # print k[0]
         # Datos de la clase actual.
         nombre_clase = k[0]
         metodos = k[1]
         atributos = k[2]
         propiedades = k[3]
         # Creamos el DividedShape.
         shape = DividedShape(140, 150, canvas, nombre_clase, propiedades,
                              atributos, metodos)
         # Guardamos la tupla (nombre_clase, referencia del dividedshape).
         clases.append((nombre_clase, shape))
         # Incluimos la referencia del dividedshape en la estructura.
         # Coordenadas.
         shape.SetX(valor_x)
         shape.SetY(valor_y)
         if self.__tope is None:
             tope = proy_por_defecto['ogl_tope_horizontal']
         else:
             tope = self.__tope
         if valor_x > tope:
             valor_x = 100.0
             valor_y += 200.0
         else:
             valor_x += 200.0
         # 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.panel.diagram.ShowAll(1)
         # Manejador de eventos del dividedshape.
         evthandler = MyEvtHandler()
         evthandler.SetShape(shape)
         evthandler.SetPreviousHandler(shape.GetEventHandler())
         shape.SetEventHandler(evthandler)
         # Refrescamos el frame, para que salga todo.
         self.panel.panel.Refresh()
     # Recorremos las clases para dibujar las relaciones entre cajas.
     for k in datos:
         # Datos de la clase actual.
         nombre_clase = k[0]
         clases_padre = k[4]
         clases_inst = k[5]
         # Referencias del hijo.
         nhijo = nombre_clase
         for i in clases:
             if i[0] == nhijo:
                 hijo = i[1]
                 break
         # Creamos relaciones de herencia en el OGL.
         for j in clases_padre:
             # Referencias del padre.
             npadre = j
             for l in clases:
                 if l[0] == npadre:
                     padre = l[1]
                     # 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.panel.panel.Refresh()
         # Creamos relaciones de instanciación de clases en atributos.
         for j in clases_inst:
             # Referencias del padre.
             npadre = j
             for l in clases:
                 if l[0] == npadre:
                     padre = l[1]
                     # Línea.
                     line = ogl.LineShape()
                     line.SetCanvas(canvas)
                     line.SetPen(wx.LIGHT_GREY_PEN)
                     line.SetBrush(wx.LIGHT_GREY_BRUSH)
                     line.AddArrow(ogl.ATTACHMENT_MODE_BRANCHING)
                     line.MakeLineControlPoints(2)
                     # Marcamos el sentido de la flecha.
                     padre.AddLine(line, hijo)
                     # Lo añadimos al canvas.
                     canvas.AddShape(line)
                     line.Show(True)
                     # Refrescamos.
                     self.panel.panel.Refresh()
示例#9
0
 def createLine(self, **attrs):
     """
     Создать новую линию.
     """
     line = parentModule.LineShape()
     return line