Exemplo n.º 1
0
    def route(self, ast):
        """
        Route all lines defined in piUML diagram.

        :Parameters:
         ast
            Diagram start node.
        """
        ncache = {}
        lcache = {}

        router = arouter.Router()

        nodes = (n for n in unwind(ast)
                if isinstance(n, Element)
                    and not isinstance(n, Relationship))
        for n in nodes:
            x, y = n.style.pos
            w, h = n.style.size
            shape = (x, y), (x + w, y + h)
            s = router.add(shape)
            ncache[n.id] = s

        lines = (l for l in ast if isinstance(l, Relationship))
        for l in lines:
            h = ncache[l.head.id]
            t = ncache[l.tail.id]
            c = router.connect(h, t)
            lcache[l] = c

        router.route()

        for l, c in list(lcache.items()):
            l.style.edges = tuple(Pos(*p) for p in reversed(router.edges(c)))
Exemplo n.º 2
0
    def test_unwind(self):
        """
        Test unwind
        """
        n1 = Diagram()
        n1.id = 'n1'

        n2 = PackagingElement('a', id='n2')
        n3 = PackagingElement('a', id='n3')
        n4 = Element('a', id='n4')

        n1.children.extend((n2, n3))
        n2.children.append(n4)

        n2.parent = n1
        n3.parent = n1
        n4.parent = n2

        self.assertEquals([n1, n2, n4, n3], list(unwind(n1)))
Exemplo n.º 3
0
def find_node(ast, id):
    for n in unwind(ast):
        if hasattr(n, 'id') and n.id == id:
            return n
    raise ValueError('Cannot find node {}'.format(id))