Parse [LABELS]
This commit is contained in:
@@ -95,5 +95,38 @@ def delete_label_cache(name: str, cs: ChangeSet) -> SqlChangeSet:
|
||||
return SqlChangeSet(redo_sql, undo_sql, redo_cs, undo_cs)
|
||||
|
||||
|
||||
def delete_label(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return execute_command(name, delete_label_cache(name, cs))
|
||||
class InpLabel:
|
||||
def __init__(self, line: str) -> None:
|
||||
tokens = line.split()
|
||||
|
||||
num = len(tokens)
|
||||
has_desc = tokens[-1].startswith(';')
|
||||
num_without_desc = (num - 1) if has_desc else num
|
||||
|
||||
self.x = float(tokens[0])
|
||||
self.y = float(tokens[1])
|
||||
self.label = str(tokens[2])
|
||||
self.node = str(tokens[3]) if num >= 4 else None
|
||||
|
||||
|
||||
def inp_in_label(section: list[str]) -> ChangeSet:
|
||||
cs = ChangeSet()
|
||||
for s in section:
|
||||
# skip comment
|
||||
if s.startswith(';'):
|
||||
continue
|
||||
obj = InpLabel(s)
|
||||
cs.append({'operation': API_ADD, 'type': 'label', 'x': obj.x, 'y': obj.y, 'label': obj.label, 'node': obj.node})
|
||||
return cs
|
||||
|
||||
|
||||
def inp_out_label(name: str) -> list[str]:
|
||||
lines = []
|
||||
objs = read_all(name, 'select * from labels')
|
||||
for obj in objs:
|
||||
x = obj['x']
|
||||
y = obj['y']
|
||||
label = obj['label']
|
||||
node = obj['node'] if obj['node'] != None else ''
|
||||
lines.append(f'{x} {y} {label} {node}')
|
||||
return lines
|
||||
|
||||
Reference in New Issue
Block a user