modifications to support optional geo position edits for nodes and to account for geo updates to sdt
This commit is contained in:
parent
9535d40b70
commit
ff3b20a962
6 changed files with 51 additions and 22 deletions
|
@ -475,9 +475,10 @@ class CoreGrpcClient:
|
||||||
self,
|
self,
|
||||||
session_id: int,
|
session_id: int,
|
||||||
node_id: int,
|
node_id: int,
|
||||||
position: core_pb2.Position,
|
position: core_pb2.Position = None,
|
||||||
icon: str = None,
|
icon: str = None,
|
||||||
source: str = None,
|
source: str = None,
|
||||||
|
geo: core_pb2.Geo = None,
|
||||||
) -> core_pb2.EditNodeResponse:
|
) -> core_pb2.EditNodeResponse:
|
||||||
"""
|
"""
|
||||||
Edit a node, currently only changes position.
|
Edit a node, currently only changes position.
|
||||||
|
@ -487,6 +488,7 @@ class CoreGrpcClient:
|
||||||
:param position: position to set node to
|
:param position: position to set node to
|
||||||
:param icon: path to icon for gui to use for node
|
:param icon: path to icon for gui to use for node
|
||||||
:param source: application source editing node
|
:param source: application source editing node
|
||||||
|
:param geo: lon,lat,alt location for node
|
||||||
:return: response with result of success or failure
|
:return: response with result of success or failure
|
||||||
:raises grpc.RpcError: when session or node doesn't exist
|
:raises grpc.RpcError: when session or node doesn't exist
|
||||||
"""
|
"""
|
||||||
|
@ -496,6 +498,7 @@ class CoreGrpcClient:
|
||||||
position=position,
|
position=position,
|
||||||
icon=icon,
|
icon=icon,
|
||||||
source=source,
|
source=source,
|
||||||
|
geo=geo,
|
||||||
)
|
)
|
||||||
return self.stub.EditNode(request)
|
return self.stub.EditNode(request)
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,9 @@ def add_node_data(node_proto: core_pb2.Node) -> Tuple[NodeTypes, int, NodeOption
|
||||||
|
|
||||||
position = node_proto.position
|
position = node_proto.position
|
||||||
options.set_position(position.x, position.y)
|
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
|
return _type, _id, options
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -688,21 +688,26 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
||||||
node = self.get_node(session, request.node_id, context)
|
node = self.get_node(session, request.node_id, context)
|
||||||
options = NodeOptions()
|
options = NodeOptions()
|
||||||
options.icon = request.icon
|
options.icon = request.icon
|
||||||
x = request.position.x
|
if request.HasField("position"):
|
||||||
y = request.position.y
|
x = request.position.x
|
||||||
options.set_position(x, y)
|
y = request.position.y
|
||||||
lat = request.position.lat
|
options.set_position(x, y)
|
||||||
lon = request.position.lon
|
lat, lon, alt = None, None, None
|
||||||
alt = request.position.alt
|
has_geo = request.HasField("geo")
|
||||||
options.set_location(lat, lon, alt)
|
if has_geo:
|
||||||
|
lat = request.geo.lat
|
||||||
|
lon = request.geo.lon
|
||||||
|
alt = request.geo.alt
|
||||||
|
options.set_location(lat, lon, alt)
|
||||||
result = True
|
result = True
|
||||||
try:
|
try:
|
||||||
session.edit_node(node.id, options)
|
session.edit_node(node.id, options)
|
||||||
source = None
|
source = None
|
||||||
if request.source:
|
if request.source:
|
||||||
source = request.source
|
source = request.source
|
||||||
node_data = node.data(0, source=source)
|
if not has_geo:
|
||||||
session.broadcast_node(node_data)
|
node_data = node.data(0, source=source)
|
||||||
|
session.broadcast_node(node_data)
|
||||||
except CoreError:
|
except CoreError:
|
||||||
result = False
|
result = False
|
||||||
return core_pb2.EditNodeResponse(result=result)
|
return core_pb2.EditNodeResponse(result=result)
|
||||||
|
|
|
@ -782,7 +782,8 @@ class Session:
|
||||||
node.canvas = options.canvas
|
node.canvas = options.canvas
|
||||||
node.icon = options.icon
|
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:
|
def set_node_position(self, node: NodeBase, options: NodeOptions) -> None:
|
||||||
"""
|
"""
|
||||||
|
@ -812,9 +813,11 @@ class Session:
|
||||||
|
|
||||||
# broadcast updated location when using lat/lon/alt
|
# broadcast updated location when using lat/lon/alt
|
||||||
if 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.
|
Broadcast node location to all listeners.
|
||||||
|
|
||||||
|
@ -826,6 +829,9 @@ class Session:
|
||||||
id=node.id,
|
id=node.id,
|
||||||
x_position=node.position.x,
|
x_position=node.position.x,
|
||||||
y_position=node.position.y,
|
y_position=node.position.y,
|
||||||
|
latitude=lat,
|
||||||
|
longitude=lon,
|
||||||
|
altitude=alt,
|
||||||
)
|
)
|
||||||
self.broadcast_node(node_data)
|
self.broadcast_node(node_data)
|
||||||
|
|
||||||
|
|
|
@ -255,20 +255,28 @@ class Sdt:
|
||||||
self.cmd(f"sprite {node_type} image {icon}")
|
self.cmd(f"sprite {node_type} image {icon}")
|
||||||
self.cmd(f'node {node.id} type {node_type} label on,"{node.name}" {pos}')
|
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.
|
Handle updating a node in SDT.
|
||||||
|
|
||||||
:param node: node to update
|
:param node: node to update
|
||||||
|
:param lon: node longitude
|
||||||
|
:param lat: node latitude
|
||||||
|
:param alt: node altitude
|
||||||
:return: nothing
|
:return: nothing
|
||||||
"""
|
"""
|
||||||
logging.debug("sdt update node: %s - %s", node.id, node.name)
|
logging.debug("sdt update node: %s - %s", node.id, node.name)
|
||||||
if not self.connect():
|
if not self.connect():
|
||||||
return
|
return
|
||||||
pos = self.get_node_position(node)
|
|
||||||
if not pos:
|
if all([lat is not None, lon is not None, alt is not None]):
|
||||||
return
|
pos = f"pos {lon:.6f},{lat:.6f},{alt:.6f}"
|
||||||
self.cmd(f"node {node.id} {pos}")
|
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:
|
def delete_node(self, node_id: int) -> None:
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -408,6 +408,7 @@ message EditNodeRequest {
|
||||||
Position position = 3;
|
Position position = 3;
|
||||||
string icon = 4;
|
string icon = 4;
|
||||||
string source = 5;
|
string source = 5;
|
||||||
|
Geo geo = 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
message EditNodeResponse {
|
message EditNodeResponse {
|
||||||
|
@ -977,6 +978,7 @@ message Node {
|
||||||
string image = 10;
|
string image = 10;
|
||||||
string server = 11;
|
string server = 11;
|
||||||
repeated string config_services = 12;
|
repeated string config_services = 12;
|
||||||
|
Geo geo = 13;
|
||||||
}
|
}
|
||||||
|
|
||||||
message Link {
|
message Link {
|
||||||
|
@ -1029,7 +1031,10 @@ message Position {
|
||||||
float x = 1;
|
float x = 1;
|
||||||
float y = 2;
|
float y = 2;
|
||||||
float z = 3;
|
float z = 3;
|
||||||
float lat = 4;
|
}
|
||||||
float lon = 5;
|
|
||||||
float alt = 6;
|
message Geo {
|
||||||
|
float lat = 1;
|
||||||
|
float lon = 2;
|
||||||
|
float alt = 3;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue