Example #1
0
def _process_index(node_dict, pts_index, ix, cylinder):
    if ix not in node_dict:
        node_dict[ix] = Node(gutil.tuplify(pts_index[ix]), pt_index=ix)
    other = _other_ix(ix)
    if other not in node_dict:
        node_dict[other] = Node(gutil.tuplify(pts_index[other]), pt_index=other)
    node_dict[ix].connect_to(node_dict[other], is_pipe=True, radius=cylinder.radius)
    return node_dict
Example #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
Example #3
0
def vbranch(node, z):
    for edge in node.successors(edges=True):
        if edge.get('direction_change') is True:
            new_node = Node(node.geom)
            edge.split(new_node)
            FuncPropogator(update_z)(new_node, data=z)
            return node
Example #4
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
Example #5
0
def remove_empty_ndfn(node, **kwargs):
    """
    ptnode1---fknode1===fknode2---ptnode2
    ptnode1--------midnode--------ptnode2

    Handle everything by Giving EdgeSolid types:
        - Geometic         has a MeshSOlid
        - Temp             will be deleted
        - Non-Geometric    must stay but have not geometry - eg duct taps

    if it as 'tap' node aka midnode has many succers,
    need to find the most likely one to do connection to (nearest -face-face distance)
    """
    edges = node.successors(edges=True)
    # select the best face-to-face geometric
    for suc_edge in edges:
        if suc_edge.has_geom is False:
            tgt_ = suc_edge.target
            src_ = suc_edge.source
            midpt = tuple(
                np.array([src_.geom, tgt_.geom]).mean(axis=0).tolist())
            new = Node(midpt)

            return node
    return node
Example #6
0
 def __call__(self, node, **kwargs):
     super(PropMerge, self).__call__(node, **kwargs)
     for k, nodes in self._syms.items():
         if len(nodes) > 1:
             # print(k, nodes)
             geom = np.mean([np.array(n.geom) for n in nodes])
             ndx = Node(geom)
             for n in nodes:
                 n.connect_to(ndx)
Example #7
0
def add_ups(node, h=0.1, **kwargs):
    if node.get('has_head', None) is True:
        nd = np.array(list(node.geom))
        nd[-1] += h
        new = Node(gutil.tuplify(nd), is_head=True)
        node.connect_to(new, remove_head=True, tap_edge=True)
        node.write('has_head', False)
        node.write('head_tee', True)
        new.write('$create', '$head')
    return node
Example #8
0
def drop_fn(node, z):
    """
    o----x


    o
    :param node:
    :param var:
    :param z:
    :return:
    """
    edge = node.predecessors(edges=True)[0]
    new_node = Node(node.geom)
    node.update_geom(set_coord(node.geom, z=z))
    edge.split(new_node)
    node.connect_to(new_node)
    return new_node
Example #9
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
Example #10
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
Example #11
0
def remove_empty_fn(edge, **kwargs):
    """
    ptnode1---fknode1===fknode2---ptnode2
    ptnode1--------midnode--------ptnode2
    """
    if edge.has_geom is False:  # and
        src_ = edge.source
        tgt_ = edge.target
        midpt = tuple(np.array([src_.geom, tgt_.geom]).mean(axis=0).tolist())
        new = Node(midpt)

        # sucs = tgt_.successors(edges=True)
        # sucs = tgt_.successors(edges=True)

        for out_edge in tgt_.successors(edges=True):
            out_edge.reverse()
            out_edge.reconnect(new)
            out_edge.reverse()
            edge = out_edge
        for in_edge in src_.predecessors(edges=True):
            in_edge.reconnect(new)
            edge = in_edge
        return edge
    return edge
Example #12
0
def riser_fn(node, z):
    edge = node.successors(edges=True)[0]
    new_node = Node(node.geom)
    edge.split(new_node)
    new_node = FuncPropogator(update_z)(new_node, data=z)
    return new_node