added saving session location to config, and query location when joining a session
This commit is contained in:
parent
bb7bad89d3
commit
fbbf31f4fa
4 changed files with 79 additions and 46 deletions
|
@ -75,6 +75,15 @@ def check_directory():
|
||||||
"terminal": terminal,
|
"terminal": terminal,
|
||||||
"gui3d": "/usr/local/bin/std3d.sh",
|
"gui3d": "/usr/local/bin/std3d.sh",
|
||||||
},
|
},
|
||||||
|
"location": {
|
||||||
|
"x": 0.0,
|
||||||
|
"y": 0.0,
|
||||||
|
"z": 0.0,
|
||||||
|
"lat": 47.5791667,
|
||||||
|
"lon": -122.132322,
|
||||||
|
"alt": 2.0,
|
||||||
|
"scale": 150.0,
|
||||||
|
},
|
||||||
"servers": [{"name": "example", "address": "127.0.0.1", "port": 50051}],
|
"servers": [{"name": "example", "address": "127.0.0.1", "port": 50051}],
|
||||||
"nodes": [],
|
"nodes": [],
|
||||||
"observers": [{"name": "hello", "cmd": "echo hello"}],
|
"observers": [{"name": "hello", "cmd": "echo hello"}],
|
||||||
|
|
|
@ -60,9 +60,7 @@ class CoreClient:
|
||||||
|
|
||||||
# data for managing the current session
|
# data for managing the current session
|
||||||
self.canvas_nodes = {}
|
self.canvas_nodes = {}
|
||||||
self.location = core_pb2.SessionLocation(
|
self.location = None
|
||||||
x=0, y=0, z=0, lat=47.5791667, lon=-122.132322, alt=2.0, scale=150.0
|
|
||||||
)
|
|
||||||
self.interface_to_edge = {}
|
self.interface_to_edge = {}
|
||||||
self.state = None
|
self.state = None
|
||||||
self.links = {}
|
self.links = {}
|
||||||
|
@ -123,7 +121,7 @@ class CoreClient:
|
||||||
throughputs_belong_to_session
|
throughputs_belong_to_session
|
||||||
)
|
)
|
||||||
|
|
||||||
def join_session(self, session_id):
|
def join_session(self, session_id, query_location=True):
|
||||||
self.master.config(cursor="watch")
|
self.master.config(cursor="watch")
|
||||||
self.master.update()
|
self.master.update()
|
||||||
|
|
||||||
|
@ -148,6 +146,11 @@ class CoreClient:
|
||||||
self.state = session.state
|
self.state = session.state
|
||||||
self.client.events(self.session_id, self.handle_events)
|
self.client.events(self.session_id, self.handle_events)
|
||||||
|
|
||||||
|
# get location
|
||||||
|
if query_location:
|
||||||
|
response = self.client.get_session_location(self.session_id)
|
||||||
|
self.location = response.location
|
||||||
|
|
||||||
# get emane models
|
# get emane models
|
||||||
response = self.client.get_emane_models(self.session_id)
|
response = self.client.get_emane_models(self.session_id)
|
||||||
self.emane_models = response.models
|
self.emane_models = response.models
|
||||||
|
@ -207,7 +210,17 @@ class CoreClient:
|
||||||
"""
|
"""
|
||||||
response = self.client.create_session()
|
response = self.client.create_session()
|
||||||
logging.info("created session: %s", response)
|
logging.info("created session: %s", response)
|
||||||
self.join_session(response.session_id)
|
location_config = self.app.config["location"]
|
||||||
|
self.location = core_pb2.SessionLocation(
|
||||||
|
x=location_config["x"],
|
||||||
|
y=location_config["y"],
|
||||||
|
z=location_config["z"],
|
||||||
|
lat=location_config["lat"],
|
||||||
|
lon=location_config["lon"],
|
||||||
|
alt=location_config["alt"],
|
||||||
|
scale=location_config["scale"],
|
||||||
|
)
|
||||||
|
self.join_session(response.session_id, query_location=False)
|
||||||
|
|
||||||
def delete_session(self, custom_sid=None):
|
def delete_session(self, custom_sid=None):
|
||||||
if custom_sid is None:
|
if custom_sid is None:
|
||||||
|
|
|
@ -6,8 +6,8 @@ from tkinter import font, ttk
|
||||||
|
|
||||||
from coretk.dialogs.dialog import Dialog
|
from coretk.dialogs.dialog import Dialog
|
||||||
|
|
||||||
FRAME_PAD = 5
|
PAD = 5
|
||||||
PADX = 5
|
PIXEL_SCALE = 100
|
||||||
|
|
||||||
|
|
||||||
class SizeAndScaleDialog(Dialog):
|
class SizeAndScaleDialog(Dialog):
|
||||||
|
@ -19,9 +19,7 @@ class SizeAndScaleDialog(Dialog):
|
||||||
"""
|
"""
|
||||||
super().__init__(master, app, "Canvas Size and Scale", modal=True)
|
super().__init__(master, app, "Canvas Size and Scale", modal=True)
|
||||||
self.canvas = self.app.canvas
|
self.canvas = self.app.canvas
|
||||||
self.meter_per_pixel = self.canvas.meters_per_pixel
|
|
||||||
self.section_font = font.Font(weight="bold")
|
self.section_font = font.Font(weight="bold")
|
||||||
|
|
||||||
# get current canvas dimensions
|
# get current canvas dimensions
|
||||||
plot = self.canvas.find_withtag("rectangle")
|
plot = self.canvas.find_withtag("rectangle")
|
||||||
x0, y0, x1, y1 = self.canvas.bbox(plot[0])
|
x0, y0, x1, y1 = self.canvas.bbox(plot[0])
|
||||||
|
@ -29,14 +27,15 @@ class SizeAndScaleDialog(Dialog):
|
||||||
height = abs(y0 - y1) - 2
|
height = abs(y0 - y1) - 2
|
||||||
self.pixel_width = tk.IntVar(value=width)
|
self.pixel_width = tk.IntVar(value=width)
|
||||||
self.pixel_height = tk.IntVar(value=height)
|
self.pixel_height = tk.IntVar(value=height)
|
||||||
self.meters_width = tk.IntVar(value=width * self.meter_per_pixel)
|
location = self.app.core.location
|
||||||
self.meters_height = tk.IntVar(value=height * self.meter_per_pixel)
|
self.x = tk.DoubleVar(value=location.x)
|
||||||
self.scale = tk.IntVar(value=self.meter_per_pixel * 100)
|
self.y = tk.DoubleVar(value=location.y)
|
||||||
self.x = tk.IntVar(value=0)
|
self.lat = tk.DoubleVar(value=location.lat)
|
||||||
self.y = tk.IntVar(value=0)
|
self.lon = tk.DoubleVar(value=location.lon)
|
||||||
self.lat = tk.DoubleVar(value=47.5791667)
|
self.alt = tk.DoubleVar(value=location.alt)
|
||||||
self.lon = tk.DoubleVar(value=-122.132322)
|
self.scale = tk.DoubleVar(value=location.scale)
|
||||||
self.alt = tk.DoubleVar(value=2.0)
|
self.meters_width = tk.IntVar(value=width / PIXEL_SCALE * location.scale)
|
||||||
|
self.meters_height = tk.IntVar(value=height / PIXEL_SCALE * location.scale)
|
||||||
self.save_default = tk.BooleanVar(value=False)
|
self.save_default = tk.BooleanVar(value=False)
|
||||||
self.draw()
|
self.draw()
|
||||||
|
|
||||||
|
@ -49,7 +48,7 @@ class SizeAndScaleDialog(Dialog):
|
||||||
self.draw_buttons()
|
self.draw_buttons()
|
||||||
|
|
||||||
def draw_size(self):
|
def draw_size(self):
|
||||||
label_frame = ttk.Labelframe(self.top, text="Size", padding=FRAME_PAD)
|
label_frame = ttk.Labelframe(self.top, text="Size", padding=PAD)
|
||||||
label_frame.grid(sticky="ew")
|
label_frame.grid(sticky="ew")
|
||||||
label_frame.columnconfigure(0, weight=1)
|
label_frame.columnconfigure(0, weight=1)
|
||||||
|
|
||||||
|
@ -59,13 +58,13 @@ class SizeAndScaleDialog(Dialog):
|
||||||
frame.columnconfigure(1, weight=1)
|
frame.columnconfigure(1, weight=1)
|
||||||
frame.columnconfigure(3, weight=1)
|
frame.columnconfigure(3, weight=1)
|
||||||
label = ttk.Label(frame, text="Width")
|
label = ttk.Label(frame, text="Width")
|
||||||
label.grid(row=0, column=0, sticky="w", padx=PADX)
|
label.grid(row=0, column=0, sticky="w", padx=PAD)
|
||||||
entry = ttk.Entry(frame, textvariable=self.pixel_width)
|
entry = ttk.Entry(frame, textvariable=self.pixel_width)
|
||||||
entry.grid(row=0, column=1, sticky="ew", padx=PADX)
|
entry.grid(row=0, column=1, sticky="ew", padx=PAD)
|
||||||
label = ttk.Label(frame, text="x Height")
|
label = ttk.Label(frame, text="x Height")
|
||||||
label.grid(row=0, column=2, sticky="w", padx=PADX)
|
label.grid(row=0, column=2, sticky="w", padx=PAD)
|
||||||
entry = ttk.Entry(frame, textvariable=self.pixel_height)
|
entry = ttk.Entry(frame, textvariable=self.pixel_height)
|
||||||
entry.grid(row=0, column=3, sticky="ew", padx=PADX)
|
entry.grid(row=0, column=3, sticky="ew", padx=PAD)
|
||||||
label = ttk.Label(frame, text="Pixels")
|
label = ttk.Label(frame, text="Pixels")
|
||||||
label.grid(row=0, column=4, sticky="w")
|
label.grid(row=0, column=4, sticky="w")
|
||||||
|
|
||||||
|
@ -75,35 +74,33 @@ class SizeAndScaleDialog(Dialog):
|
||||||
frame.columnconfigure(1, weight=1)
|
frame.columnconfigure(1, weight=1)
|
||||||
frame.columnconfigure(3, weight=1)
|
frame.columnconfigure(3, weight=1)
|
||||||
label = ttk.Label(frame, text="Width")
|
label = ttk.Label(frame, text="Width")
|
||||||
label.grid(row=0, column=0, sticky="w", padx=PADX)
|
label.grid(row=0, column=0, sticky="w", padx=PAD)
|
||||||
entry = ttk.Entry(frame, textvariable=self.meters_width)
|
entry = ttk.Entry(frame, textvariable=self.meters_width)
|
||||||
entry.grid(row=0, column=1, sticky="ew", padx=PADX)
|
entry.grid(row=0, column=1, sticky="ew", padx=PAD)
|
||||||
label = ttk.Label(frame, text="x Height")
|
label = ttk.Label(frame, text="x Height")
|
||||||
label.grid(row=0, column=2, sticky="w", padx=PADX)
|
label.grid(row=0, column=2, sticky="w", padx=PAD)
|
||||||
entry = ttk.Entry(frame, textvariable=self.meters_height)
|
entry = ttk.Entry(frame, textvariable=self.meters_height)
|
||||||
entry.grid(row=0, column=3, sticky="ew", padx=PADX)
|
entry.grid(row=0, column=3, sticky="ew", padx=PAD)
|
||||||
label = ttk.Label(frame, text="Meters")
|
label = ttk.Label(frame, text="Meters")
|
||||||
label.grid(row=0, column=4, sticky="w")
|
label.grid(row=0, column=4, sticky="w")
|
||||||
|
|
||||||
def draw_scale(self):
|
def draw_scale(self):
|
||||||
label_frame = ttk.Labelframe(self.top, text="Scale", padding=FRAME_PAD)
|
label_frame = ttk.Labelframe(self.top, text="Scale", padding=PAD)
|
||||||
label_frame.grid(sticky="ew")
|
label_frame.grid(sticky="ew")
|
||||||
label_frame.columnconfigure(0, weight=1)
|
label_frame.columnconfigure(0, weight=1)
|
||||||
|
|
||||||
frame = ttk.Frame(label_frame)
|
frame = ttk.Frame(label_frame)
|
||||||
frame.grid(sticky="ew")
|
frame.grid(sticky="ew")
|
||||||
frame.columnconfigure(1, weight=1)
|
frame.columnconfigure(1, weight=1)
|
||||||
label = ttk.Label(frame, text="100 Pixels =")
|
label = ttk.Label(frame, text=f"{PIXEL_SCALE} Pixels =")
|
||||||
label.grid(row=0, column=0, sticky="w", padx=PADX)
|
label.grid(row=0, column=0, sticky="w", padx=PAD)
|
||||||
entry = ttk.Entry(frame, textvariable=self.scale)
|
entry = ttk.Entry(frame, textvariable=self.scale)
|
||||||
entry.grid(row=0, column=1, sticky="ew", padx=PADX)
|
entry.grid(row=0, column=1, sticky="ew", padx=PAD)
|
||||||
label = ttk.Label(frame, text="Meters")
|
label = ttk.Label(frame, text="Meters")
|
||||||
label.grid(row=0, column=2, sticky="w")
|
label.grid(row=0, column=2, sticky="w")
|
||||||
|
|
||||||
def draw_reference_point(self):
|
def draw_reference_point(self):
|
||||||
label_frame = ttk.Labelframe(
|
label_frame = ttk.Labelframe(self.top, text="Reference Point", padding=PAD)
|
||||||
self.top, text="Reference Point", padding=FRAME_PAD
|
|
||||||
)
|
|
||||||
label_frame.grid(sticky="ew")
|
label_frame.grid(sticky="ew")
|
||||||
label_frame.columnconfigure(0, weight=1)
|
label_frame.columnconfigure(0, weight=1)
|
||||||
|
|
||||||
|
@ -118,14 +115,14 @@ class SizeAndScaleDialog(Dialog):
|
||||||
frame.columnconfigure(3, weight=1)
|
frame.columnconfigure(3, weight=1)
|
||||||
|
|
||||||
label = ttk.Label(frame, text="X")
|
label = ttk.Label(frame, text="X")
|
||||||
label.grid(row=0, column=0, sticky="w", padx=PADX)
|
label.grid(row=0, column=0, sticky="w", padx=PAD)
|
||||||
entry = ttk.Entry(frame, textvariable=self.x)
|
entry = ttk.Entry(frame, textvariable=self.x)
|
||||||
entry.grid(row=0, column=1, sticky="ew", padx=PADX)
|
entry.grid(row=0, column=1, sticky="ew", padx=PAD)
|
||||||
|
|
||||||
label = ttk.Label(frame, text="Y")
|
label = ttk.Label(frame, text="Y")
|
||||||
label.grid(row=0, column=2, sticky="w", padx=PADX)
|
label.grid(row=0, column=2, sticky="w", padx=PAD)
|
||||||
entry = ttk.Entry(frame, textvariable=self.y)
|
entry = ttk.Entry(frame, textvariable=self.y)
|
||||||
entry.grid(row=0, column=3, sticky="ew", padx=PADX)
|
entry.grid(row=0, column=3, sticky="ew", padx=PAD)
|
||||||
|
|
||||||
label = ttk.Label(label_frame, text="Translates To")
|
label = ttk.Label(label_frame, text="Translates To")
|
||||||
label.grid()
|
label.grid()
|
||||||
|
@ -137,17 +134,17 @@ class SizeAndScaleDialog(Dialog):
|
||||||
frame.columnconfigure(5, weight=1)
|
frame.columnconfigure(5, weight=1)
|
||||||
|
|
||||||
label = ttk.Label(frame, text="Lat")
|
label = ttk.Label(frame, text="Lat")
|
||||||
label.grid(row=0, column=0, sticky="w", padx=PADX)
|
label.grid(row=0, column=0, sticky="w", padx=PAD)
|
||||||
entry = ttk.Entry(frame, textvariable=self.lat)
|
entry = ttk.Entry(frame, textvariable=self.lat)
|
||||||
entry.grid(row=0, column=1, sticky="ew", padx=PADX)
|
entry.grid(row=0, column=1, sticky="ew", padx=PAD)
|
||||||
|
|
||||||
label = ttk.Label(frame, text="Lon")
|
label = ttk.Label(frame, text="Lon")
|
||||||
label.grid(row=0, column=2, sticky="w", padx=PADX)
|
label.grid(row=0, column=2, sticky="w", padx=PAD)
|
||||||
entry = ttk.Entry(frame, textvariable=self.lon)
|
entry = ttk.Entry(frame, textvariable=self.lon)
|
||||||
entry.grid(row=0, column=3, sticky="ew", padx=PADX)
|
entry.grid(row=0, column=3, sticky="ew", padx=PAD)
|
||||||
|
|
||||||
label = ttk.Label(frame, text="Alt")
|
label = ttk.Label(frame, text="Alt")
|
||||||
label.grid(row=0, column=4, sticky="w", padx=PADX)
|
label.grid(row=0, column=4, sticky="w", padx=PAD)
|
||||||
entry = ttk.Entry(frame, textvariable=self.alt)
|
entry = ttk.Entry(frame, textvariable=self.alt)
|
||||||
entry.grid(row=0, column=5, sticky="ew")
|
entry.grid(row=0, column=5, sticky="ew")
|
||||||
|
|
||||||
|
@ -164,16 +161,31 @@ class SizeAndScaleDialog(Dialog):
|
||||||
frame.grid(sticky="ew")
|
frame.grid(sticky="ew")
|
||||||
|
|
||||||
button = ttk.Button(frame, text="Apply", command=self.click_apply)
|
button = ttk.Button(frame, text="Apply", command=self.click_apply)
|
||||||
button.grid(row=0, column=0, sticky="ew", padx=PADX)
|
button.grid(row=0, column=0, sticky="ew", padx=PAD)
|
||||||
|
|
||||||
button = ttk.Button(frame, text="Cancel", command=self.destroy)
|
button = ttk.Button(frame, text="Cancel", command=self.destroy)
|
||||||
button.grid(row=0, column=1, sticky="ew")
|
button.grid(row=0, column=1, sticky="ew")
|
||||||
|
|
||||||
def click_apply(self):
|
def click_apply(self):
|
||||||
meter_per_pixel = float(self.scale.get()) / 100
|
|
||||||
width, height = self.pixel_width.get(), self.pixel_height.get()
|
width, height = self.pixel_width.get(), self.pixel_height.get()
|
||||||
self.canvas.meters_per_pixel = meter_per_pixel
|
|
||||||
self.canvas.redraw_grid(width, height)
|
self.canvas.redraw_grid(width, height)
|
||||||
if self.canvas.wallpaper:
|
if self.canvas.wallpaper:
|
||||||
self.canvas.redraw()
|
self.canvas.redraw()
|
||||||
|
location = self.app.core.location
|
||||||
|
location.x = self.x.get()
|
||||||
|
location.y = self.y.get()
|
||||||
|
location.lat = self.lat.get()
|
||||||
|
location.lon = self.lon.get()
|
||||||
|
location.alt = self.alt.get()
|
||||||
|
location.scale = self.scale.get()
|
||||||
|
if self.save_default.get():
|
||||||
|
location_config = self.app.config["location"]
|
||||||
|
location_config["x"] = location.x
|
||||||
|
location_config["y"] = location.y
|
||||||
|
location_config["z"] = location.z
|
||||||
|
location_config["lat"] = location.lat
|
||||||
|
location_config["lon"] = location.lon
|
||||||
|
location_config["alt"] = location.alt
|
||||||
|
location_config["scale"] = location.scale
|
||||||
|
self.app.save_config()
|
||||||
self.destroy()
|
self.destroy()
|
||||||
|
|
|
@ -49,7 +49,6 @@ class CanvasGraph(tk.Canvas):
|
||||||
self.edges = {}
|
self.edges = {}
|
||||||
self.drawing_edge = None
|
self.drawing_edge = None
|
||||||
self.grid = None
|
self.grid = None
|
||||||
self.meters_per_pixel = 1.5
|
|
||||||
self.canvas_management = CanvasComponentManagement(self, core)
|
self.canvas_management = CanvasComponentManagement(self, core)
|
||||||
self.setup_bindings()
|
self.setup_bindings()
|
||||||
self.draw_grid()
|
self.draw_grid()
|
||||||
|
|
Loading…
Add table
Reference in a new issue