Support inp in coord, vertex, label

This commit is contained in:
WQY\qiong
2023-03-16 00:15:34 +08:00
parent bf1aeff1fa
commit 1d720c5b6c
4 changed files with 39 additions and 6 deletions

View File

@@ -24,6 +24,9 @@ from .s20_mixing import inp_in_mixing_new
from .s21_times import inp_in_time_new
from .s22_report import inp_in_report_new
from .s23_options import inp_in_option_new
from .s24_coordinates import inp_in_coord_new
from .s25_vertices import inp_in_vertex_new
from .s26_labels import inp_in_label_new
from .s27_backdrop import inp_in_backdrop_new
_S = 'S'
@@ -53,9 +56,9 @@ _handler = {
TIMES : (_S, inp_in_time_new),
REPORT : (_S, inp_in_report_new),
OPTIONS : (_S, inp_in_option_new),
COORDINATES : (_L, None),
VERTICES : (_L, None),
LABELS : (_L, None),
COORDINATES : (_L, inp_in_coord_new),
VERTICES : (_L, inp_in_vertex_new),
LABELS : (_L, inp_in_label_new),
BACKDROP : (_S, inp_in_backdrop_new),
#END : 'END',
}
@@ -188,13 +191,12 @@ def parse_file(project: str, inp: str) -> None:
write(project, f"delete from demands where junction = '{junction}';")
demand_junction = junction
if handler != None:
handler(project, line)
f.seek(0)
if is_s and handler != None:
if is_s:
handler(project, sections[s])

View File

@@ -27,6 +27,13 @@ def inp_in_coord(section: list[str]) -> dict[str, dict[str, float]]:
return coords
def inp_in_coord_new(name: str, line: str) -> None:
tokens = line.split()
node = tokens[0]
coord = f"'({tokens[1]}, {tokens[2]})'"
write(name, f"insert into coordinates (node, coord) values ('{node}', {coord});")
def inp_out_coord(name: str) -> list[str]:
lines = []
objs = read_all(name, 'select * from coordinates')

View File

@@ -98,6 +98,14 @@ def inp_in_vertex(section: list[str]) -> ChangeSet:
return cs
def inp_in_vertex_new(name: str, line: str) -> None:
tokens = line.split()
link = tokens[0]
x = float(tokens[1])
y = float(tokens[2])
write(name, f"insert into vertices (link, x, y) values ('{link}', {x}, {y});")
def inp_out_vertex(name: str) -> list[str]:
lines = []
objs = read_all(name, f"select * from vertices order by _order")

View File

@@ -124,6 +124,22 @@ def inp_in_label(section: list[str]) -> ChangeSet:
return cs
def inp_in_label_new(name: str, line: str) -> None:
tokens = line.split()
num = len(tokens)
has_desc = tokens[-1].startswith(';')
num_without_desc = (num - 1) if has_desc else num
x = float(tokens[0])
y = float(tokens[1])
label = str(tokens[2])
node = str(tokens[3]) if num >= 4 else None
node = f"'{node}'" if node != None else 'null'
write(name, f"insert into labels (x, y, label, node) values ({x}, {y}, '{label}', {node});")
def inp_out_label(name: str) -> list[str]:
lines = []
objs = read_all(name, 'select * from labels')