diff --git a/waypoint_manager/scripts/lib/waypointlib.py b/waypoint_manager/scripts/lib/waypointlib.py index d8c54ab..e26c893 100644 --- a/waypoint_manager/scripts/lib/waypointlib.py +++ b/waypoint_manager/scripts/lib/waypointlib.py @@ -67,8 +67,6 @@ class FinishPose(): def __init__(self, wp_yaml): - super().__init__() - self.header = {} for key, val in wp_yaml["finish_pose"]["header"].items(): self.header[key] = val @@ -95,6 +93,7 @@ + def get_waypoint_yaml(waypoints: WaypointList, finish_pose: FinishPose): s = ["waypoints:" + "\n"] for point in waypoints.get_waypoint(): @@ -115,6 +114,3 @@ q = quaternion.from_euler_angles([0, 0, finish_pose.yaw]) s.append(" orientation: {" + "x: {}, y: {}, z: {}, w: {}".format(q.x, q.y, q.z, q.w) + "}") return "".join(s) - - - \ No newline at end of file diff --git a/waypoint_manager/scripts/manager_GUI.py b/waypoint_manager/scripts/manager_GUI.py index 01cefa6..eaf7390 100755 --- a/waypoint_manager/scripts/manager_GUI.py +++ b/waypoint_manager/scripts/manager_GUI.py @@ -1,8 +1,10 @@ +from email.errors import MessageError import tkinter as tk import tkinter.filedialog import math import ruamel.yaml from pathlib import Path +from tkinter import messagebox from lib.mymaplib import MyMap from lib.waypointlib import WaypointList, FinishPose, get_waypoint_yaml @@ -117,6 +119,8 @@ +++++ File -> Open -> Map +++++ """ def menu_open_map(self): + if self.mymap is not None: + self.canvas.delete("map_image", "origin") map_path = tkinter.filedialog.askopenfilename( parent=self.master, title="Select map yaml file", @@ -145,11 +149,15 @@ self.mymap.translate(offset_x, offset_y) self.draw_image() # 画像を描画 self.plot_origin() # 原点を示す円を描画 - self.master.title(Path(map_path).name + " - " + self.master.title()) - self.open_menu.entryconfigure("Map", state=tk.DISABLED) + if self.waypoints_filepath is not None: + self.master.title(self.waypoints_filepath.name + " - " + Path(map_path).name) + else: + self.master.title(Path(map_path).name) + # self.open_menu.entryconfigure("Map", state=tk.DISABLED) self.open_menu.entryconfigure("Waypoints", state=tk.NORMAL) - self.message("Please open waypoints file ") - self.menu_open_waypoints() + if self.waypoints is None: + self.message("Please open waypoints file ") + self.menu_open_waypoints() return @@ -157,9 +165,19 @@ +++++ File -> Open -> Waypionts +++++ """ def menu_open_waypoints(self): + if self.waypoints is not None: + yn = messagebox.askyesno("Confirm", "Do you want to save changes to " + str(self.waypoints_filepath)) + if yn: self.save_waypoints(str(self.waypoints_filepath)) # Yes + self.canvas.delete("all") + self.draw_image() + self.plot_origin() + self.master.title(str(self.master.title()).replace(self.waypoints_filepath.name + " - ", "")) + if (self.wp_info_win is not None) and (self.wp_info_win.winfo_exists()): + self.wp_info_win.destroy() + filepath = tkinter.filedialog.askopenfilename( parent=self.master, - title="Select map yaml file", + title="Select waypoints yaml file", initialdir=str(Path(".")), filetypes=[("YAML", ".yaml")] ) @@ -170,7 +188,7 @@ self.finish_pose = FinishPose(wp_yaml) self.waypoints_filepath = Path(filepath) self.plot_waypoints() - self.master.title(Path(filepath).name + " - " + self.master.title()) + self.master.title(self.waypoints_filepath.name + " - " + self.master.title()) self.file_menu.entryconfigure("Save", state=tk.NORMAL) self.file_menu.entryconfigure("Save As", state=tk.NORMAL) self.popup_menu.entryconfigure("Add waypoint here", state=tk.NORMAL) @@ -826,6 +844,7 @@ else: # 既に描画された画像を差し替える self.canvas.itemconfig("map_image", image=self.mymap.get_draw_image((self.canv_w, self.canv_h))) + self.canvas.tag_lower("map_image") return