Пример #1
0
 def on_search_wpt(self, event):
     dlg = WptSearchDlg()
     dlg.CentreOnParent()
     if dlg.ShowModal() == wx.ID_OK:
         name = dlg.name.GetValue()
         if name:
             way_points = search.find_pos_from_name(name, g.search_api)
             if len(way_points) > 0:
                 folder_name = '地点搜索结果:%s' % name
                 new_folder = g.track_tree.create_child_folder(
                     g.data_root, folder_name)
                 first_wpt = None
                 for point in way_points:
                     wpt = WayPoint(point[0],
                                    point[1],
                                    point[2],
                                    parent=new_folder.uuid,
                                    bmp_index=g.default_wpt_bmp_index)
                     g.add_data(new_folder, wpt)
                     if not first_wpt:
                         first_wpt = wpt
                 g.track_tree.SelectItem(first_wpt.tree_node)
                 g.map_canvas.zoom_to_lon_lat(15, first_wpt.lon,
                                              first_wpt.lat)
                 self.repaint(canvas=const.REDRAW_MAP)
             else:
                 do_log('地名搜索失败...')
         else:
             do_log('地名不能为空...')
     dlg.Destroy()
Пример #2
0
 def on_add_wpt_from_tile(self, event):
     dlg = AddWptFromTileDlg()
     dlg.CentreOnParent()
     if dlg.ShowModal() == wx.ID_OK:
         if dlg.tile_x.GetValue() and dlg.tile_y.GetValue(
         ) and dlg.tile_z.GetValue():
             tile_x = int(dlg.tile_x.GetValue())
             tile_y = int(dlg.tile_y.GetValue())
             zoom = int(dlg.tile_z.GetValue())
             need_jiupian = dlg.need_jiupian.GetValue()
             lon = transform.get_longitude_from_fpx(
                 transform.get_fpx_from_px(tile_x * 256 + 128, zoom))
             lat = transform.get_latitude_from_fpy(
                 transform.get_fpy_from_py(tile_y * 256 + 128, zoom))
             if need_jiupian:
                 lon, lat = jiupian.gcj02_to_wgs84(lon, lat)
             wpt = WayPoint('瓦片-x%d-y%d-z%d' % (tile_x, tile_y, zoom),
                            lon,
                            lat,
                            parent=g.data_root.uuid,
                            bmp_index=g.default_wpt_bmp_index)
             g.add_data(g.data_root, wpt)
             g.track_tree.SelectItem(wpt.tree_node)
             self.repaint(const.REDRAW_COPY)
         else:
             do_log('瓦片x,y,z坐标都必须有值...')
     dlg.Destroy()
Пример #3
0
    def open_track_files(self, paths, parent_folder):
        do_log('正在加载轨迹文件,请稍候...')
        self.CollapseAll()

        first_track = None
        first_wpt = None
        fpx_min_list = []
        fpx_max_list = []
        fpy_min_list = []
        fpy_max_list = []
        for path in paths:
            if path[-4:] == '.kml':
                data_list = parse_kml(path, parent_folder.uuid)
            elif path[-4:] == '.kmz':
                data_list = parse_kmz(path, parent_folder.uuid)
            elif path[-4:] == '.gpx':
                data_list = parse_gpx(path, parent_folder.uuid)
            else:
                do_log('轨迹文件后缀不符...')
                continue
            
            for data in data_list:
                data_parent = g.get_parent_folder(data)
                g.add_data(data_parent, data, commit=False)
                if isinstance(data, TrackLine):
                    fpx_min_list.append(data.fpx_min)
                    fpx_max_list.append(data.fpx_max)
                    fpy_min_list.append(data.fpy_min)
                    fpy_max_list.append(data.fpy_max)
                    if not first_track:
                        first_track = data
                elif isinstance(data, WayPoint):
                    fpx_min_list.append(data.fpx)
                    fpx_max_list.append(data.fpx)
                    fpy_min_list.append(data.fpy)
                    fpy_max_list.append(data.fpy)
                    if not first_wpt:
                        first_wpt = data
        g.db_mgr.commit()

        if fpx_min_list:
            if first_track:
                self.selected_track_line = first_track
                self.SelectItem(first_track.tree_node)
            elif first_wpt:
                self.SelectItem(first_wpt.tree_node)
            g.map_canvas.zoom_to_range(min(fpx_min_list), max(fpx_max_list), min(fpy_min_list), max(fpy_max_list))
            g.frame.repaint(const.REDRAW_NONE)
            do_log('轨迹文件加载完成...')
        else:
            do_log('轨迹文件无内容...')
Пример #4
0
 def on_add_wpt_from_coord(self, event):
     dlg = AddWptFromCoordDlg()
     dlg.CentreOnParent()
     if dlg.ShowModal() == wx.ID_OK:
         if dlg.lon.GetValue() and dlg.lat.GetValue():
             lat = float(dlg.lat.GetValue())
             lon = float(dlg.lon.GetValue())
             name = search.find_name_from_pos(lon, lat, g.search_api)
             wpt = WayPoint(name,
                            lon,
                            lat,
                            parent=g.data_root.uuid,
                            bmp_index=g.default_wpt_bmp_index)
             g.add_data(g.data_root, wpt)
             g.track_tree.SelectItem(wpt.tree_node)
             self.repaint(const.REDRAW_COPY)
         else:
             do_log('经纬度坐标都必须有值...')
     dlg.Destroy()
Пример #5
0
    def on_search_route(self, event):
        dlg = RouteSearchDlg()
        dlg.CentreOnParent()
        if dlg.ShowModal() == wx.ID_OK:
            wpt_start = None
            wpt_end = None
            start_idx = dlg.start.GetCurrentSelection()
            if start_idx < 0:
                start_name = dlg.start.GetValue()
                if start_name:
                    way_points = search.find_pos_from_name(
                        start_name, g.search_api)
                    if way_points:
                        wpt_start = WayPoint(way_points[0][0],
                                             way_points[0][1],
                                             way_points[0][2],
                                             bmp_index=g.default_wpt_bmp_index)
                    else:
                        wpt_start = None
            else:
                wpt_start = g.wpt_list[start_idx]

            end_idx = dlg.end.GetCurrentSelection()
            if end_idx < 0:
                end_name = dlg.end.GetValue()
                if end_name:
                    way_points = search.find_pos_from_name(
                        end_name, g.search_api)
                    if way_points:
                        wpt_end = WayPoint(way_points[0][0],
                                           way_points[0][1],
                                           way_points[0][2],
                                           bmp_index=g.default_wpt_bmp_index)
                    else:
                        wpt_end = None
            else:
                wpt_end = g.wpt_list[end_idx]

            if wpt_start and wpt_end:
                routes = search.find_drive_route(
                    (wpt_start.lon, wpt_start.lat), (wpt_end.lon, wpt_end.lat),
                    g.search_api)
                if len(routes) > 0:
                    folder_name = '路径搜索结果:%s --> %s' % (wpt_start.name,
                                                        wpt_end.name)
                    new_folder = g.track_tree.create_child_folder(
                        g.data_root, folder_name)
                    first_track = None
                    for route in routes:
                        track_line = TrackLine(new_folder.uuid,
                                               name='行车路径%05d' %
                                               auto_id.get_id())
                        track_line.load_from_points(route)
                        g.add_data(new_folder, track_line, commit=False)
                        if not first_track:
                            first_track = track_line

                    if not wpt_start.parent:
                        wpt_start.parent = new_folder.uuid
                        g.add_data(new_folder, wpt_start, commit=False)

                    if not wpt_end.parent:
                        wpt_end.parent = new_folder.uuid
                        g.add_data(new_folder, wpt_end, commit=False)

                    g.db_mgr.commit()

                    g.track_tree.selected_track_line = first_track
                    g.track_tree.SelectItem(first_track.tree_node)
                    g.map_canvas.zoom_to_track_line(first_track)
                    do_log('找到%d条行车路线' % len(routes))
                else:
                    do_log('未找到合适的行车路线...')
            else:
                do_log('地名为空或无效...')
        dlg.Destroy()
Пример #6
0
    def on_undo(self, event):
        if not g.undo_list:
            self.enable_undo(False)
            return

        undo_action = g.undo_list.pop()
        if undo_action['action'] == 'tree_del_track':
            track_line = undo_action['track']
            parent = g.get_parent_folder(track_line)
            g.add_data(parent, track_line)
            self.enable_undo(False)
            self.repaint(const.REDRAW_TRACK)
            do_log('刚才删除的轨迹“%s”被恢复至文件夹“%s”' % (track_line.name, parent.name))
        elif undo_action['action'] == 'tree_del_folder':
            deleted = undo_action['deleted']
            for data in deleted:
                parent = g.get_parent_folder(data)
                g.add_data(parent, data, commit=False)
            g.db_mgr.commit()
            self.enable_undo(False)
            self.repaint(const.REDRAW_TRACK)
            do_log('刚才删除的文件夹“%s”被恢复')
        elif undo_action['action'] == 'edit_del_track':
            track_line = undo_action['track']
            g.track_edit.InsertStringItem(len(g.edit_track_list),
                                          track_line.name)
            g.edit_track_list.append(track_line)
            self.enable_undo(False)
            self.repaint(const.REDRAW_TRACK)
            do_log('刚才删除的轨迹“%s”已恢复' % track_line.name)
        elif undo_action['action'] == 'del_seg':
            track_line = undo_action['track']
            start_idx = undo_action['start']
            track_line.track_points[start_idx:start_idx] = undo_action[
                'del_seg']
            g.track_edit.selected_track_line = track_line
            track_line.sel_start_idx = start_idx
            track_line.sel_end_idx = undo_action['end']
            track_line.compute_track_line_args()
            self.enable_undo(False)
            self.repaint(const.REDRAW_TRACK)
            do_log('刚才删除的轨迹段(%d点)已恢复' % len(undo_action['del_seg']))
        elif undo_action['action'] == 'del_point':
            track_line = undo_action['track']
            point = undo_action['point']
            index = undo_action['index']
            track_line.track_points[index:index] = [point]
            g.track_edit.selected_track_line = track_line
            track_line.sel_start_idx = index
            track_line.sel_end_idx = index
            track_line.selected_point = point
            track_line.compute_track_line_args()
            self.enable_undo(False)
            self.repaint(const.REDRAW_TRACK)
            do_log('刚才删除的轨迹点已恢复...')
        elif undo_action['action'] == 'split':
            track_org = undo_action['track_org']
            track1 = undo_action['track1']
            track2 = undo_action['track2']
            track_list = g.edit_track_list
            g.track_edit.DeleteItem(track_list.index(track2))
            g.track_edit.DeleteItem(track_list.index(track1))
            track_list.pop(track_list.index(track2))
            track_list.pop(track_list.index(track1))
            g.track_edit.InsertStringItem(len(track_list), track_org.name)
            track_list.append(track_org)
            g.track_edit.set_selected_track_line(track_org)
            self.enable_undo(False)
            self.repaint(const.REDRAW_TRACK)
            do_log('刚才被分割的轨迹已重新合并...')
        elif undo_action['action'] == 'merge':
            org_track_list = undo_action['org_track_list']
            new_track = undo_action['new_track']
            track_list = g.edit_track_list
            g.track_edit.DeleteItem(track_list.index(new_track))
            track_list.pop(track_list.index(new_track))

            for track_line in org_track_list:
                g.track_edit.InsertStringItem(len(track_list), track_line.name)
                track_list.append(track_line)
                track_line.is_checked = False
                for point in track_line.track_points:
                    point.track_line = track_line

            g.track_edit.set_selected_track_line(None)
            self.enable_undo(False)
            self.repaint(const.REDRAW_TRACK)
            do_log('刚才被合并的轨迹已重新分割为多个...')
        elif undo_action['action'] == 'reverse':
            track_line = undo_action['track']
            track_line.track_points.reverse()
            track_line.has_timestamp = undo_action['has_timestamp']
            track_line.compute_track_line_args()
            g.track_edit.set_selected_track_line(track_line)
            self.enable_undo(False)
            self.repaint(canvas=const.REDRAW_TRACK)
            do_log('刚才翻转的轨迹已恢复至原来方向...')
        elif undo_action['action'] == 'del_all_wpts':
            redo_dir = '被删路点恢复%05d' % auto_id.get_id()
            wpt_folder = g.track_tree.create_child_folder(
                g.data_root, redo_dir)
            for wpt in g.wpt_list_deleted:
                wpt.parent = wpt_folder.uuid
                g.add_data(wpt_folder, wpt, commit=False)
            g.db_mgr.commit()
            g.wpt_list_deleted = []
            self.repaint(canvas=const.REDRAW_COPY)
            do_log('刚才被删除的路点统一被恢复至<%s>文件夹...' % redo_dir)
Пример #7
0
 def create_child_folder(self, parent_folder, name):
     child_folder = DataFolder(parent=parent_folder.uuid, name=name)
     g.add_data(parent_folder, child_folder)
     return child_folder