示例#1
0
def nx_to_nodes(system):
    G, root = system.G, system.root
    seen, q = set(), [root]
    tmp = {}
    while q:
        el = q.pop(0)
        if el not in seen:
            seen.add(el)
            pred = list(G.predecessors(el))
            sucs = list(G.successors(el))

            data = G.nodes[el]
            if 'symbol_id' in data:
                chld = data.pop('children', [])
            nd = Node(el, **data)
            for x in pred:
                if x in tmp:
                    tmp[x].connect_to(nd, **G[x][el])
            for x in sucs:
                if x in tmp:
                    nd.connect_to(tmp[x], **G[el][x])
            tmp[nd.geom] = nd
            q.extend(pred + sucs)

    root_node = tmp[root]
    return root_node
示例#2
0
def vertical(node, z):
    base_g = node.geom
    geom = list(base_g)
    geom[-1] = 0.
    node.update_geom(tuple(geom))
    edge = node.successors(edges=True)[0]
    new_node = Node(base_g)
    edge.split(new_node)

    geom[-1] = z
    rise_node = Node(tuple(geom))
    new_node.connect_to(rise_node)
    return new_node
示例#3
0
def tap_is_input(node_in_tap, node_out1, node_out2, new_pnt):
    tap_edge, pred_node = node_in_tap.predecessors(both=True)[0]
    pt_tuple = gutil.tuplify(new_pnt.numpy)

    if tap_edge.curve.line.length < 1.:
        node_in_tap.geom = pt_tuple
        node_in = node_in_tap
        tap_edge.write('tap_edge', True)
    else:
        node_in = Node(pt_tuple, tee_index=0, tee_mid=True)
        node_in_tap.connect_to(node_in, **tap_edge.tmps, tap_edge=True)

    node_in.write('tap_input', False)
    node_in.write('is_tee', True)
    for n in [node_out1, node_out2]:
        o_edge, o_succ = n.successors(both=True)[0]
        node_in.connect_to(o_succ, **o_edge.tmps)
        o_edge.delete()
    return node_in
示例#4
0
def nxgraph_to_nodes(G):
    root_nodes = []
    seen = set()
    tmp = {}
    for n, data in G.nodes(data=True):
        if n not in seen:
            seen.add(n)
            pred = list(G.predecessors(n))
            sucs = list(G.successors(n))
            node = Node(n, **data)
            if node.get('root', None) is True:
                root_nodes.append(node)

            for x in pred:
                if x in tmp:
                    tmp[x].connect_to(node, **G[x][n])
            for x in sucs:
                if x in tmp:
                    node.connect_to(tmp[x], **G[n][x])
            tmp[n] = node
    return root_nodes