Support add/delete pattern & curve
This commit is contained in:
@@ -46,9 +46,9 @@ from .s9_demands import get_demand_schema, get_demand, set_demand
|
||||
from .s10_status import LINK_STATUS_OPEN, LINK_STATUS_CLOSED, LINK_STATUS_ACTIVE
|
||||
from .s10_status import get_status_schema, get_status, set_status
|
||||
|
||||
from .s11_patterns import get_pattern_schema, get_pattern, set_pattern
|
||||
from .s11_patterns import get_pattern_schema, get_pattern, set_pattern, add_pattern, delete_pattern
|
||||
|
||||
from .s12_curves import get_curve_schema, get_curve, set_curve
|
||||
from .s12_curves import get_curve_schema, get_curve, set_curve, add_curve, delete_curve
|
||||
|
||||
from .s13_controls import get_control_schema, get_control, set_control
|
||||
|
||||
|
||||
@@ -39,11 +39,29 @@ def set_pattern_cache(name: str, cs: ChangeSet) -> SqlChangeSet:
|
||||
for f_factor in old['factors']:
|
||||
undo_sql += f"\ninsert into patterns (id, factor) values ({f_id}, {f_factor});"
|
||||
|
||||
redo_cs = g_update_prefix | { 'type': 'pattern' } | new
|
||||
undo_cs = g_update_prefix | { 'type': 'pattern' } | old
|
||||
redo_cs = { 'type': 'pattern' } | new
|
||||
undo_cs = { 'type': 'pattern' } | old
|
||||
|
||||
return SqlChangeSet(redo_sql, undo_sql, redo_cs, undo_cs)
|
||||
|
||||
|
||||
def set_pattern(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return execute_command(name, set_pattern_cache(name, cs))
|
||||
result = set_pattern_cache(name, cs)
|
||||
result.redo_cs |= g_update_prefix
|
||||
result.undo_cs |= g_update_prefix
|
||||
return execute_command(name, result)
|
||||
|
||||
|
||||
def add_pattern(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
result = set_pattern_cache(name, cs)
|
||||
result.redo_cs |= g_add_prefix
|
||||
result.undo_cs |= g_delete_prefix
|
||||
return execute_command(name, result)
|
||||
|
||||
|
||||
def delete_pattern(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
cs.operations[0]['factors'] = []
|
||||
result = set_pattern_cache(name, cs)
|
||||
result.redo_cs |= g_delete_prefix
|
||||
result.undo_cs |= g_add_prefix
|
||||
return execute_command(name, result)
|
||||
|
||||
@@ -43,11 +43,29 @@ def set_curve_cache(name: str, cs: ChangeSet) -> SqlChangeSet:
|
||||
f_x, f_y = xy['x'], xy['y']
|
||||
undo_sql += f"\ninsert into curves (id, x, y) values ({f_id}, {f_x}, {f_y});"
|
||||
|
||||
redo_cs = g_update_prefix | { 'type': 'curve' } | new
|
||||
undo_cs = g_update_prefix | { 'type': 'curve' } | old
|
||||
redo_cs = { 'type': 'curve' } | new
|
||||
undo_cs = { 'type': 'curve' } | old
|
||||
|
||||
return SqlChangeSet(redo_sql, undo_sql, redo_cs, undo_cs)
|
||||
|
||||
|
||||
def set_curve(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return execute_command(name, set_curve_cache(name, cs))
|
||||
result = set_curve_cache(name, cs)
|
||||
result.redo_cs |= g_update_prefix
|
||||
result.undo_cs |= g_update_prefix
|
||||
return execute_command(name, result)
|
||||
|
||||
|
||||
def add_curve(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
result = set_curve_cache(name, cs)
|
||||
result.redo_cs |= g_add_prefix
|
||||
result.undo_cs |= g_delete_prefix
|
||||
return execute_command(name, result)
|
||||
|
||||
|
||||
def delete_curve(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
cs.operations[0]['coords'] = []
|
||||
result = set_curve_cache(name, cs)
|
||||
result.redo_cs |= g_delete_prefix
|
||||
result.undo_cs |= g_add_prefix
|
||||
return execute_command(name, result)
|
||||
|
||||
16
tjnetwork.py
16
tjnetwork.py
@@ -398,6 +398,12 @@ def get_pattern(name: str, id: str) -> dict[str, Any]:
|
||||
def set_pattern(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return api.set_pattern(name, cs)
|
||||
|
||||
def add_pattern(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return api.add_pattern(name, cs)
|
||||
|
||||
def delete_pattern(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return api.delete_pattern(name, cs)
|
||||
|
||||
|
||||
############################################################
|
||||
# curve 12.[CURVES]
|
||||
@@ -413,6 +419,12 @@ def get_curve(name: str, id: str) -> dict[str, Any]:
|
||||
def set_curve(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return api.set_curve(name, cs)
|
||||
|
||||
def add_curve(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return api.add_curve(name, cs)
|
||||
|
||||
def delete_curve(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return api.delete_curve(name, cs)
|
||||
|
||||
|
||||
############################################################
|
||||
# control 12.[CONTROLS]
|
||||
@@ -430,7 +442,7 @@ def set_control(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
|
||||
|
||||
############################################################
|
||||
# rule 12.[CONTROLS]
|
||||
# rule 13.[RULES]
|
||||
############################################################
|
||||
|
||||
def get_rule_schema(name: str) -> dict[str, dict[str, Any]]:
|
||||
@@ -460,7 +472,7 @@ def set_emitter(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
|
||||
|
||||
############################################################
|
||||
# time 21.[EMITTERS]
|
||||
# time 21.[TIMES]
|
||||
############################################################
|
||||
|
||||
def get_time_schema(name: str) -> dict[str, dict[str, Any]]:
|
||||
|
||||
Reference in New Issue
Block a user