modifications to support optional geo position edits for nodes and to account for geo updates to sdt

This commit is contained in:
Blake Harnden 2020-03-02 10:01:36 -08:00
parent 9535d40b70
commit ff3b20a962
6 changed files with 51 additions and 22 deletions

View file

@ -475,9 +475,10 @@ class CoreGrpcClient:
self,
session_id: int,
node_id: int,
position: core_pb2.Position,
position: core_pb2.Position = None,
icon: str = None,
source: str = None,
geo: core_pb2.Geo = None,
) -> core_pb2.EditNodeResponse:
"""
Edit a node, currently only changes position.
@ -487,6 +488,7 @@ class CoreGrpcClient:
:param position: position to set node to
:param icon: path to icon for gui to use for node
:param source: application source editing node
:param geo: lon,lat,alt location for node
:return: response with result of success or failure
:raises grpc.RpcError: when session or node doesn't exist
"""
@ -496,6 +498,7 @@ class CoreGrpcClient:
position=position,
icon=icon,
source=source,
geo=geo,
)
return self.stub.EditNode(request)

View file

@ -44,7 +44,9 @@ def add_node_data(node_proto: core_pb2.Node) -> Tuple[NodeTypes, int, NodeOption
position = node_proto.position
options.set_position(position.x, position.y)
options.set_location(position.lat, position.lon, position.alt)
if node_proto.HasField("geo"):
geo = node_proto.geo
options.set_location(geo.lat, geo.lon, geo.alt)
return _type, _id, options

View file

@ -688,21 +688,26 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
node = self.get_node(session, request.node_id, context)
options = NodeOptions()
options.icon = request.icon
x = request.position.x
y = request.position.y
options.set_position(x, y)
lat = request.position.lat
lon = request.position.lon
alt = request.position.alt
options.set_location(lat, lon, alt)
if request.HasField("position"):
x = request.position.x
y = request.position.y
options.set_position(x, y)
lat, lon, alt = None, None, None
has_geo = request.HasField("geo")
if has_geo:
lat = request.geo.lat
lon = request.geo.lon
alt = request.geo.alt
options.set_location(lat, lon, alt)
result = True
try:
session.edit_node(node.id, options)
source = None
if request.source:
source = request.source
node_data = node.data(0, source=source)
session.broadcast_node(node_data)
if not has_geo:
node_data = node.data(0, source=source)
session.broadcast_node(node_data)
except CoreError:
result = False
return core_pb2.EditNodeResponse(result=result)

View file

@ -782,7 +782,8 @@ class Session:
node.canvas = options.canvas
node.icon = options.icon
self.sdt.edit_node(node)
# provide edits to sdt
self.sdt.edit_node(node, options.lon, options.lat, options.alt)
def set_node_position(self, node: NodeBase, options: NodeOptions) -> None:
"""
@ -812,9 +813,11 @@ class Session:
# broadcast updated location when using lat/lon/alt
if using_lat_lon_alt:
self.broadcast_node_location(node)
self.broadcast_node_location(node, lon, lat, alt)
def broadcast_node_location(self, node: NodeBase) -> None:
def broadcast_node_location(
self, node: NodeBase, lon: float, lat: float, alt: float
) -> None:
"""
Broadcast node location to all listeners.
@ -826,6 +829,9 @@ class Session:
id=node.id,
x_position=node.position.x,
y_position=node.position.y,
latitude=lat,
longitude=lon,
altitude=alt,
)
self.broadcast_node(node_data)

View file

@ -255,20 +255,28 @@ class Sdt:
self.cmd(f"sprite {node_type} image {icon}")
self.cmd(f'node {node.id} type {node_type} label on,"{node.name}" {pos}')
def edit_node(self, node: NodeBase) -> None:
def edit_node(self, node: NodeBase, lon: float, lat: float, alt: float) -> None:
"""
Handle updating a node in SDT.
:param node: node to update
:param lon: node longitude
:param lat: node latitude
:param alt: node altitude
:return: nothing
"""
logging.debug("sdt update node: %s - %s", node.id, node.name)
if not self.connect():
return
pos = self.get_node_position(node)
if not pos:
return
self.cmd(f"node {node.id} {pos}")
if all([lat is not None, lon is not None, alt is not None]):
pos = f"pos {lon:.6f},{lat:.6f},{alt:.6f}"
self.cmd(f"node {node.id} {pos}")
else:
pos = self.get_node_position(node)
if not pos:
return
self.cmd(f"node {node.id} {pos}")
def delete_node(self, node_id: int) -> None:
"""

View file

@ -408,6 +408,7 @@ message EditNodeRequest {
Position position = 3;
string icon = 4;
string source = 5;
Geo geo = 6;
}
message EditNodeResponse {
@ -977,6 +978,7 @@ message Node {
string image = 10;
string server = 11;
repeated string config_services = 12;
Geo geo = 13;
}
message Link {
@ -1029,7 +1031,10 @@ message Position {
float x = 1;
float y = 2;
float z = 3;
float lat = 4;
float lon = 5;
float alt = 6;
}
message Geo {
float lat = 1;
float lon = 2;
float alt = 3;
}