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
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
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
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
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
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
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)
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
def _test_node_success(self, node: Node, ntype): mgr = rvt.make_actions_for(node) a1 = mgr.next_action() assert isinstance(a1, list), msg('list', a1) assert a1[0] == ntype, msg(ntype, a1[0]) mgr.on_success(a1) assert rvt.is_built(node) is True, msg(True, rvt.is_built(node)) for i in range(node.nsucs): a2 = mgr.next_action() assert a2[0] == _Cmd_pipe, msg(_Cmd_pipe, a2[0]) assert a2[2] == _Pipe_CnPt, msg(_Pipe_CnPt, a2[2]) mgr.on_success(a2) for e in node.successors(edges=True): self._edge_stat(e, True, True, not True)
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
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
def _test_node_fail(self, node: Node, ntype): mgr = rvt.make_actions_for(node) a1 = mgr.next_action() assert isinstance(a1, list), msg('list', a1) assert a1[0] == ntype, msg(ntype, a1[0]) mgr.on_fail(a1) assert rvt.is_built(node) is False, msg(False, rvt.is_built(node)) for i in range(node.nsucs): a2 = mgr.next_action() assert a2[0] == _Cmd_pipe, msg(_Cmd_pipe, a2[0]) assert a2[2] == _Pipe_PtPt, msg(_Pipe_PtPt, a2[2]) mgr.on_success(a2) for e in node.successors(edges=True): b, c1, c2 = _edge_status(e) assert b is True, msg(True, b) assert c1 is not True, msg(False, c1) assert c2 is not True, msg(False, c2)
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
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