diff --git a/waypoint_manager/scripts/manager_GUI.py b/waypoint_manager/scripts/manager_GUI.py index b24b7ae..ec818a2 100755 --- a/waypoint_manager/scripts/manager_GUI.py +++ b/waypoint_manager/scripts/manager_GUI.py @@ -55,17 +55,17 @@ self.master.configure(menu=self.menu_bar) # 大元に作成したメニューバーを設定 #### 画面上部に、システムからのメッセージを表示するラベルを配置 #### - self.msg_label = tk.Label(self.master, text="Please open map file ", anchor=tk.E) + self.msg_label = tk.Label(self.master, text="Please open map file ", anchor=tk.E, font=("Consolas",13)) self.msg_label.pack(fill=tk.X, padx=5) #### 画面下部に、カーソルの座標やピクセル情報を表示するステータスバーを表示 #### self.status_bar = tk.Frame(self.master) self.mouse_position = tk.Label(self.status_bar, relief=tk.SUNKEN, - text=" (x, y) = ", anchor=tk.W, font=("", 15) + text=" (x, y) = ", anchor=tk.W, font=("Consolas", 15) ) self.mouse_position.pack(side=tk.LEFT, padx=3) self.waypoint_num = tk.Label(self.status_bar, relief=tk.SUNKEN, - text=" Waypoint No. -----", anchor=tk.W, font=("", 15) + text=" Waypoint No. -----", anchor=tk.W, font=("Consolas", 15) ) self.waypoint_num.pack(side=tk.RIGHT, padx=3) self.status_bar.pack(side=tk.BOTTOM, fill=tk.X) @@ -120,7 +120,8 @@ """ def menu_open_map(self): if self.mymap is not None: - self.canvas.delete("map_image", "origin") + self.canvas.delete("all") + self.waypoints.number_dict = {} map_path = tkinter.filedialog.askopenfilename( parent=self.master, title="Select map yaml file", @@ -134,7 +135,11 @@ if not "image" in map_yaml.keys(): self.message("Selected map file is unexpected format.") return - self.mymap = MyMap(Path(map_path), map_yaml) + try: + self.mymap = MyMap(Path(map_path), map_yaml) + except FileNotFoundError: + self.message("Image file is not found.") + return self.message("Read map file " + map_path) ## キャンバスサイズに合わせて画像を表示 scale = 1 @@ -402,16 +407,22 @@ +++++ キャンバスに新たなウェイポイントを描画する +++++ """ def create_waypoint(self, waypoint: dict): - cx, cy = self.real2canvas(float(waypoint["x"]), float(waypoint["y"])) + img_x, img_y = self.mymap.real2image(float(waypoint["x"]), float(waypoint["y"])) + cx, cy = self.mymap.transform(img_x, img_y) x0 = round(cx - self.point_rad) y0 = round(cy - self.point_rad) x1 = round(cx + self.point_rad + 1) y1 = round(cy + self.point_rad + 1) - id = self.canvas.create_oval(x0, y0, x1, y1, fill='#FDD', outline='red', activefill='red') - self.canvas.tag_bind(id, "", lambda event, wp_id=id: self.waypoint_clicked(event, wp_id)) - self.canvas.tag_bind(id, "", lambda event, wp_id=id: self.waypoint_enter(event, wp_id)) - self.canvas.tag_bind(id, "", self.waypoint_leave) - self.canvas.tag_bind(id, "", self.waypoint_click_move) + if (img_x < 0) or (img_y < 0) or (img_x > self.mymap.width()) or (img_y > self.mymap.height()): + id = self.canvas.create_oval(x0, y0, x1, y1, fill='#FEE', outline='#FAA', activefill='#F88') + self.canvas.tag_bind(id, "", lambda event, wp_id=id: self.waypoint_enter(event, wp_id)) + self.canvas.tag_bind(id, "", self.waypoint_leave) + else: + id = self.canvas.create_oval(x0, y0, x1, y1, fill='#FDD', outline='red', activefill='red') + self.canvas.tag_bind(id, "", lambda event, wp_id=id: self.waypoint_clicked(event, wp_id)) + self.canvas.tag_bind(id, "", lambda event, wp_id=id: self.waypoint_enter(event, wp_id)) + self.canvas.tag_bind(id, "", self.waypoint_leave) + self.canvas.tag_bind(id, "", self.waypoint_click_move) return id @@ -465,10 +476,10 @@ """ def waypoint_enter(self, event, wp_id): wp_num = self.waypoints.get_num(wp_id) - self.waypoint_num["text"] = " Waypoint No. {} " .format(str(wp_num)) + self.waypoint_num["text"] = " Waypoint No. {} " .format(str(wp_num)) def waypoint_leave(self, event): - self.waypoint_num["text"] = " Waypoint No. ----- " + self.waypoint_num["text"] = " Waypoint No. ----- " @@ -675,7 +686,7 @@ self.mouse_position["text"] = " Out of map " return x, y = self.mymap.image2real(img_x, img_y) - self.mouse_position["text"] = " ( x, y ) = ( {}, {} ) ".format(x, y) + self.mouse_position["text"] = " ( x, y ) = ( {}, {} ) ".format(x, y) return @@ -705,6 +716,10 @@ if self.setting_finish_pose == 1: x0, y0 = event.x, event.y + img_x, img_y = self.mymap.inv_transform(x0, y0) + if (img_x < 0) or (img_y < 0) or (img_x > self.mymap.width()) or (img_y > self.mymap.height()): + self.message("Click inside the map.") + return x1 = x0 + math.cos(self.finish_pose.yaw) * self.point_rad * 3 y1 = y0 - math.sin(self.finish_pose.yaw) * self.point_rad * 3 self.canvas.create_line(x0, y0, x1, y1, tags="set_finish_pose", @@ -730,7 +745,7 @@ self.finish_pose.y = real_y self.finish_pose.yaw = theta self.setting_finish_pose = 0 - self.message("New finish pose is setted.") + self.message("New finish pose is set.") return @@ -871,8 +886,8 @@ """ def real2canvas(self, x, y): img_x, img_y = self.mymap.real2image(x,y) - real_x, real_y = self.mymap.transform(img_x, img_y) - return real_x, real_y + cx, cy = self.mymap.transform(img_x, img_y) + return cx, cy