def __init__(self, polygon): """构造函数 Args: polygon (list): [polygon_id, layer, vertex_num, <str>vertices] """ self.polygon_id = int(polygon[0]) self.layer = polygon[1] vertex_str_list = polygon[3].strip().strip(';') if vertex_str_list == '': self.vertices = [] self.vertex_num = 0 else: # vertex_list: [[float, float], [float, float], ...] vertex_list = [[float(v.strip()) for v in pt_str.strip().split(',')] for pt_str in vertex_str_list.strip().split(';')] # self.vertices: [DaoPoint, DaoPoint, ...] self.vertices = [DaoPoint(x, y) for x, y in vertex_list] self.vertex_num = len(self.vertices) if self.vertex_num != polygon[2]: log.debug('polygon %d: expect %d vertices, find %d.' % (self.polygon_id, polygon[2], self.vertex_num)) # other attr self.name = '' self.additional = 0 self.parent = None self.children = []
def save(self, path): """保存 sqlite 数据库文件 Args: path (str): 文件路径 """ try: self.db.write_to_file(path) self.command_handler.reset_backup_data() log.debug('Save "%s".' % path) except sqlite3.Error as error: log.error('Failed to save "%s".' % path) log.error(repr(error)) self.show_message(repr(error))
def execute(self, commands): """执行命令 Args: commands (str): 待执行命令 """ log.debug(commands) try: self.command_handler.execute(commands) self.update_polygon_list() except Exception as e: log.error("执行命令出错: %s" % repr(e)) return False else: return True
def open(self, path, quiet=False): """打开 sqlite 数据库文件 Args: path (str): 文件路径 quiet (bool): 报错不弹框 """ if os.path.exists(path): try: self.db.load_tables(path) self.command_handler.reset_backup_data() self.update_polygon_list() self.path = path self.fsm_mgr.change_fsm("empty", "normal") log.debug('Open "%s".' % path) except sqlite3.Error as error: log.error('Failed to open "%s".' % path) log.error(repr(error)) if not quiet: self.show_message(repr(error)) else: log.error("File %s not exists." % path) if not quiet: self.show_message("File %s not exists." % path)