diff --git a/coretk/coretk/coreclient.py b/coretk/coretk/coreclient.py index ae03922b..318ccb99 100644 --- a/coretk/coretk/coreclient.py +++ b/coretk/coretk/coreclient.py @@ -308,7 +308,6 @@ class CoreClient: logging.info("delete nodes %s", response) def delete_links(self, delete_session=None): - # sid = None if delete_session is None: sid = self.session_id else: @@ -430,23 +429,6 @@ class CoreClient: else: return self.reusable.pop(0) - # def add_node(self, node_type, model, x, y, name, node_id): - # position = core_pb2.Position(x=x, y=y) - # node = core_pb2.Node(id=node_id, type=node_type, position=position, model=model) - # self.node_ids.append(node_id) - # response = self.client.add_node(self.session_id, node) - # logging.info("created node: %s", response) - # if node_type == core_pb2.NodeType.WIRELESS_LAN: - # d = OrderedDict() - # d["basic_range"] = "275" - # d["bandwidth"] = "54000000" - # d["jitter"] = "0" - # d["delay"] = "20000" - # d["error"] = "0" - # r = self.client.set_wlan_config(self.session_id, node_id, d) - # logging.debug("set wlan config %s", r) - # return response.node_id - def add_graph_node(self, session_id, canvas_id, x, y, name): """ Add node, with information filled in, to grpc manager @@ -510,12 +492,13 @@ class CoreClient: """ # keep reference to the core ids core_node_ids = [self.nodes[x].node_id for x in canvas_ids] + node_interface_pairs = [] # delete the nodes for i in canvas_ids: try: - self.nodes.pop(i) - self.reusable.append(i) + n = self.nodes.pop(i) + self.reusable.append(n.node_id) except KeyError: logging.error("coreclient.py INVALID NODE CANVAS ID") @@ -524,16 +507,33 @@ class CoreClient: # delete the edges and interfaces for i in tokens: try: - self.edges.pop(i) + e = self.edges.pop(i) + if e.interface_1 is not None: + node_interface_pairs.append(tuple([e.id1, e.interface_1.id])) + if e.interface_2 is not None: + node_interface_pairs.append(tuple([e.id2, e.interface_2.id])) + except KeyError: logging.error("coreclient.py invalid edge token ") - # delete any configurations + # delete global emane config if there no longer exist any emane cloud + if core_pb2.NodeType.EMANE not in [x.type for x in self.nodes.values()]: + self.emane_config = None + + # delete any mobility configuration, wlan configuration for i in core_node_ids: if i in self.mobilityconfig_management.configurations: - self.mobilityconfig_management.pop(i) + self.mobilityconfig_management.configurations.pop(i) if i in self.wlanconfig_management.configurations: - self.wlanconfig_management.pop(i) + self.wlanconfig_management.configurations.pop(i) + + # delete emane configurations + for i in node_interface_pairs: + if i in self.emaneconfig_management.configurations: + self.emaneconfig_management.configurations.pop(i) + for i in core_node_ids: + if tuple([i, None]) in self.emaneconfig_management.configurations: + self.emaneconfig_management.configurations.pop(tuple([i, None])) def add_preexisting_node(self, canvas_node, session_id, core_node, name): """ diff --git a/coretk/coretk/coretoolbarhelp.py b/coretk/coretk/coretoolbarhelp.py index 5192f2c5..c43a3c14 100644 --- a/coretk/coretk/coretoolbarhelp.py +++ b/coretk/coretk/coretoolbarhelp.py @@ -97,7 +97,10 @@ class CoreToolbarHelp: # get emane config (global configuration) pb_emane_config = self.app.core.emane_config - emane_config = {x: pb_emane_config[x].value for x in pb_emane_config} + if pb_emane_config is not None: + emane_config = {x: pb_emane_config[x].value for x in pb_emane_config} + else: + emane_config = None # get emane configuration list emane_model_configs = self.get_emane_configuration_list() diff --git a/coretk/coretk/dialogs/wlanconfig.py b/coretk/coretk/dialogs/wlanconfig.py index d57c8935..ecd2610b 100644 --- a/coretk/coretk/dialogs/wlanconfig.py +++ b/coretk/coretk/dialogs/wlanconfig.py @@ -24,7 +24,7 @@ class WlanConfigDialog(Dialog): self.config = config self.name = tk.StringVar(value=canvas_node.name) - self.range_var = tk.StringVar(value=config["basic_range"]) + self.range_var = tk.StringVar(value=config["range"]) self.bandwidth_var = tk.StringVar(value=config["bandwidth"]) self.delay_var = tk.StringVar(value=config["delay"]) self.loss_var = tk.StringVar(value=config["error"]) diff --git a/coretk/coretk/graph.py b/coretk/coretk/graph.py index 9ab6b956..af769766 100644 --- a/coretk/coretk/graph.py +++ b/coretk/coretk/graph.py @@ -383,7 +383,14 @@ class CanvasGraph(tk.Canvas): self.node_context.unpost() self.is_node_context_opened = False + # TODO rather than delete, might move the data to somewhere else in order to reuse + # TODO when the user undo def press_delete(self, event): + """ + delete selected nodes and any data that relates to it + :param event: + :return: + """ # hide nodes, links, link information that shows on the GUI to_delete_nodes, to_delete_edge_tokens = ( self.canvas_management.delete_selected_nodes() @@ -395,12 +402,17 @@ class CanvasGraph(tk.Canvas): for token in to_delete_edge_tokens: self.edges.pop(token) + # delete the edge data inside of canvas node + canvas_node_link_to_delete = [] + for canvas_id, node in self.nodes.items(): + for e in node.edges: + if e.token in to_delete_edge_tokens: + canvas_node_link_to_delete.append(tuple([canvas_id, e])) + for nid, edge in canvas_node_link_to_delete: + self.nodes[nid].edges.remove(edge) + + # delete the related data from core self.core.delete_wanted_graph_nodes(to_delete_nodes, to_delete_edge_tokens) - # delete any configuration related to the links and nodes - - # delete selected node - - # delete links connected to the selected nodes def add_node(self, x, y, image, node_name): plot_id = self.find_all()[0]