diff --git a/coretk/coretk/coreclient.py b/coretk/coretk/coreclient.py index e6dfb77e..1671a0fe 100644 --- a/coretk/coretk/coreclient.py +++ b/coretk/coretk/coreclient.py @@ -141,15 +141,19 @@ class CoreClient: else: logging.warning("unknown session event: %s", session_event) elif event.HasField("node_event"): - node_event = event.node_event - node_id = node_event.node.id - x = node_event.node.position.x - y = node_event.node.position.y - canvas_node = self.canvas_nodes[node_id] - canvas_node.move(x, y) + self.handle_node_event(event.node_event) else: logging.info("unhandled event: %s", event) + def handle_node_event(self, event): + if event.source == "gui": + return + node_id = event.node.id + x = event.node.position.x + y = event.node.position.y + canvas_node = self.canvas_nodes[node_id] + canvas_node.move(x, y) + def handle_throughputs(self, event): interface_throughputs = event.interface_throughputs for i in interface_throughputs: @@ -164,9 +168,6 @@ class CoreClient: ) def join_session(self, session_id, query_location=True): - # self.master.config(cursor="watch") - # self.master.update() - # update session and title self.session_id = session_id self.master.title(f"CORE Session({self.session_id})") @@ -253,7 +254,6 @@ class CoreClient: self.app.toolbar.runtime_frame.tkraise() else: self.app.toolbar.design_frame.tkraise() - # self.master.config(cursor="") self.app.statusbar.progress_bar.stop() def is_runtime(self): @@ -321,8 +321,7 @@ class CoreClient: def edit_node(self, node_id, x, y): position = core_pb2.Position(x=x, y=y) - response = self.client.edit_node(self.session_id, node_id, position) - logging.info("updated node id %s: %s", node_id, response) + self.client.edit_node(self.session_id, node_id, position, source="gui") def start_session(self): nodes = [x.core_node for x in self.canvas_nodes.values()] diff --git a/coretk/coretk/graph.py b/coretk/coretk/graph.py index d45cce9b..7bfe7ed3 100644 --- a/coretk/coretk/graph.py +++ b/coretk/coretk/graph.py @@ -600,6 +600,9 @@ class CanvasNode: y_offset = y - old_y self.core_node.position.x = x self.core_node.position.y = y + self.canvas.move(self.id, x_offset, y_offset) + self.canvas.move(self.text_id, x_offset, y_offset) + self.antenna_draw.update_antennas_position(x_offset, y_offset) for edge in self.edges: x1, y1, x2, y2 = self.canvas.coords(edge.id) if edge.src == self.id: @@ -608,9 +611,6 @@ class CanvasNode: self.canvas.coords(edge.id, x1, y1, x_offset, y_offset) edge.link_info.recalculate_info() self.canvas.helper.update_wlan_connection(old_x, old_y, x, y, self.wlans) - self.canvas.move(self.id, x_offset, y_offset) - self.canvas.move(self.text_id, x_offset, y_offset) - self.antenna_draw.update_antennas_position(x_offset, y_offset) def on_enter(self, event): if self.app.core.is_runtime() and self.app.core.observer: diff --git a/daemon/core/api/grpc/client.py b/daemon/core/api/grpc/client.py index ceec0448..05380b79 100644 --- a/daemon/core/api/grpc/client.py +++ b/daemon/core/api/grpc/client.py @@ -428,7 +428,7 @@ class CoreGrpcClient: request = core_pb2.GetNodeRequest(session_id=session_id, node_id=node_id) return self.stub.GetNode(request) - def edit_node(self, session_id, node_id, position, icon=None): + def edit_node(self, session_id, node_id, position, icon=None, source=None): """ Edit a node, currently only changes position. @@ -436,12 +436,17 @@ class CoreGrpcClient: :param int node_id: node id :param core_pb2.Position position: position to set node to :param str icon: path to icon for gui to use for node + :param str source: application source editing node :return: response with result of success or failure :rtype: core_pb2.EditNodeResponse :raises grpc.RpcError: when session or node doesn't exist """ request = core_pb2.EditNodeRequest( - session_id=session_id, node_id=node_id, position=position, icon=icon + session_id=session_id, + node_id=node_id, + position=position, + icon=icon, + source=source, ) return self.stub.EditNode(request) diff --git a/daemon/core/api/grpc/server.py b/daemon/core/api/grpc/server.py index c0fe1d94..a914d617 100644 --- a/daemon/core/api/grpc/server.py +++ b/daemon/core/api/grpc/server.py @@ -504,7 +504,7 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer): position=position, services=services, ) - return core_pb2.NodeEvent(node=node_proto) + return core_pb2.NodeEvent(node=node_proto, source=event.source) def _handle_link_event(self, event): """ @@ -800,7 +800,10 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer): result = True try: session.edit_node(node.id, options) - node_data = node.data(0) + source = None + if request.source: + source = request.source + node_data = node.data(0, source=source) session.broadcast_node(node_data) except CoreError: result = False diff --git a/daemon/core/emulator/data.py b/daemon/core/emulator/data.py index ba0dd457..0ed1fa67 100644 --- a/daemon/core/emulator/data.py +++ b/daemon/core/emulator/data.py @@ -76,6 +76,7 @@ NodeData = collections.namedtuple( "altitude", "icon", "opaque", + "source", ], ) NodeData.__new__.__defaults__ = (None,) * len(NodeData._fields) diff --git a/daemon/core/nodes/base.py b/daemon/core/nodes/base.py index 72fc0fe1..a663741e 100644 --- a/daemon/core/nodes/base.py +++ b/daemon/core/nodes/base.py @@ -176,7 +176,7 @@ class NodeBase: self.ifindex += 1 return ifindex - def data(self, message_type, lat=None, lon=None, alt=None): + def data(self, message_type, lat=None, lon=None, alt=None, source=None): """ Build a data object for this node. @@ -184,6 +184,7 @@ class NodeBase: :param str lat: latitude :param str lon: longitude :param str alt: altitude + :param str source: source of node data :return: node data object :rtype: core.emulator.data.NodeData """ @@ -217,6 +218,7 @@ class NodeBase: model=model, server=server, services=services, + source=source, ) return node_data diff --git a/daemon/proto/core/api/grpc/core.proto b/daemon/proto/core/api/grpc/core.proto index ac7cc2ed..57bbf3f4 100644 --- a/daemon/proto/core/api/grpc/core.proto +++ b/daemon/proto/core/api/grpc/core.proto @@ -298,6 +298,7 @@ message Event { message NodeEvent { Node node = 1; + string source = 2; } message LinkEvent { @@ -378,6 +379,7 @@ message EditNodeRequest { int32 node_id = 2; Position position = 3; string icon = 4; + string source = 5; } message EditNodeResponse {