feat: implemented messages and improved constant gams
This commit is contained in:
+85
-33
@@ -4,16 +4,6 @@ import os
|
||||
import common as doc
|
||||
|
||||
|
||||
def doc_app_state(state, tab=" │ "):
|
||||
res = ""
|
||||
if "+Threads" in state:
|
||||
for i, tname in enumerate(state["+Threads"]):
|
||||
if tname[0] == "+":
|
||||
ch = "├─●" if i < len(state["+Threads"]) - 1 else "╰─●"
|
||||
res += f"{tab} {ch} {tname[1:]}\n"
|
||||
return res
|
||||
|
||||
|
||||
def __doc_obj__(label, obj, id):
|
||||
node = f' {id} [label="{label}\n{obj["Class"]} | '
|
||||
return node
|
||||
@@ -177,9 +167,8 @@ def __doc_iogam__(id, obj, edges, thread):
|
||||
|
||||
|
||||
def __doc_constgam__(id, obj, edges, thread):
|
||||
node = f' {id} [label="{id[2:]}\n{obj["Class"]} | '
|
||||
values = ""
|
||||
types = ""
|
||||
node = f" {id} [shape=plaintext, label=<<table cellspacing='0' cellborder='1' cellpadding='4' border='0'>"
|
||||
node += f"<tr><td colspan='2'><b>{id[2:]}</b><br/>{obj['Class']}</td></tr>"
|
||||
|
||||
if "OutputSignals" in obj:
|
||||
for i, (l, sig) in enumerate(obj["OutputSignals"].items()):
|
||||
@@ -193,38 +182,99 @@ def __doc_constgam__(id, obj, edges, thread):
|
||||
thread,
|
||||
)
|
||||
)
|
||||
if i != 0:
|
||||
values += " | "
|
||||
types += " | "
|
||||
values += f'<out_{doc.format_name(l)}> {sig["Default"]}'
|
||||
types += doc.type_to_string(mtype)
|
||||
node += "{{ " + types + " } | {" + values + "}}"
|
||||
node += '", style=filled, fillcolor="#dff"];'
|
||||
node += f'<tr><td bgcolor="#eee">{doc.type_to_string(mtype)}<br/><font point-size="8">{l}</font></td>'
|
||||
node += f'<td port="out_{doc.format_name(l)}">'
|
||||
node += f'{sig["Default"]}</td></tr>'
|
||||
node += "</table>>];\n"
|
||||
return node, edges
|
||||
|
||||
|
||||
def __doc_message_gam__(id, obj, edges, thread):
|
||||
label = id[2:]
|
||||
node = f' {id} [label="{label}\n{obj["Class"]} | '
|
||||
sigs, edges = __doc_common_gam__(id, obj, edges, thread)
|
||||
if sigs:
|
||||
node += sigs + '"];'
|
||||
else:
|
||||
node = ""
|
||||
|
||||
if node:
|
||||
add, edges = __doc_events__(id, obj, edges, thread)
|
||||
node += add
|
||||
return node, edges
|
||||
|
||||
|
||||
def __doc_events__(id, obj, edges, thread):
|
||||
return "", edges
|
||||
nodes = ""
|
||||
for event_id, event in obj["+Events"].items():
|
||||
if event_id[0] == "+":
|
||||
event_id = event_id[1:]
|
||||
trigger = event["EventTrigger"]
|
||||
message_ids = [id[1:] for id in event if id[0] == "+"]
|
||||
for msg_id in message_ids:
|
||||
nodes += f" {id}_{event_id}_{msg_id} [shape=plaintext, label=<"
|
||||
nodes += '<table cellspacing="0" cellborder="1" border="0" cellpadding="4"><tr>'
|
||||
nodes += (
|
||||
"<td bgcolor='#ccc' align='left'><b>When</b></td><td balign='left'>"
|
||||
)
|
||||
for i, (sig, val) in enumerate(trigger.items()):
|
||||
if i > 0:
|
||||
nodes += "<br/>"
|
||||
nodes += f"{sig} == {val}"
|
||||
|
||||
nodes += "</td></tr><tr><td bgcolor='#ccc' align='left'><b>Destination</b></td>"
|
||||
msg = event[f"+{msg_id}"]
|
||||
fn = msg["Function"]
|
||||
nodes += f"<td align='left'>{msg['Destination']}</td></tr>"
|
||||
nodes += "<tr><td bgcolor='#ccc' align='left'><b>Function</b></td><td align='left'>"
|
||||
if fn == "SetOutput":
|
||||
params = msg["+Parameters"]
|
||||
nodes += f"{params['SignalName']} = {params['SignalValue']}"
|
||||
else:
|
||||
nodes += f"{fn} "
|
||||
nodes += "</td></tr></table>>];\n"
|
||||
nodes += f" {id} -> {id}_{event_id}_{msg_id} [arrowhead=box];\n"
|
||||
return nodes, edges
|
||||
|
||||
|
||||
def __sanitize__(expression):
|
||||
if expression[0] == "\n":
|
||||
expression = expression[1:]
|
||||
return expression.replace(">", ">").replace("<", "<").replace("\n", "\n")
|
||||
|
||||
|
||||
def __doc_mathgam__(id, obj, edges, thread):
|
||||
label = id[2:]
|
||||
node = f' {id} [label="{label}\n{obj["Class"]} | '
|
||||
node += __sanitize__(obj["Expression"]) + " | "
|
||||
sigs, edges = __doc_common_gam__(id, obj, edges, thread)
|
||||
if sigs:
|
||||
node += sigs + '"];'
|
||||
else:
|
||||
node = ""
|
||||
return node, edges
|
||||
|
||||
|
||||
__gams_fns__ = {
|
||||
"IOGAM": __doc_iogam__,
|
||||
"ConstantGAM": __doc_constgam__,
|
||||
"TriggeredIOGAM": __doc_triggered_iogam__,
|
||||
"MathExpressionGAM": __doc_mathgam__,
|
||||
"MessageGAM": __doc_message_gam__,
|
||||
}
|
||||
|
||||
|
||||
def __doc_gam__(label, obj, edges, thread):
|
||||
id = f"fn{label}"
|
||||
cls = obj["Class"]
|
||||
if cls in __gams_fns__:
|
||||
return __gams_fns__[cls](id, obj, edges, thread)
|
||||
node = f' {id} [label="{label}\n{obj["Class"]} | '
|
||||
if cls == "ConstantGAM":
|
||||
return __doc_constgam__(id, obj, edges, thread)
|
||||
elif cls == "IOGAM":
|
||||
return __doc_iogam__(id, obj, edges, thread)
|
||||
elif cls == "TriggeredIOGAM":
|
||||
return __doc_triggered_iogam__(id, obj, edges, thread)
|
||||
else:
|
||||
sigs, edges = __doc_common_gam__(id, obj, edges, thread)
|
||||
sigs, edges = __doc_common_gam__(id, obj, edges, thread)
|
||||
if sigs:
|
||||
node += sigs + '"];'
|
||||
else:
|
||||
node = ""
|
||||
if cls == "MessageGAM":
|
||||
extra, edges = __doc_events__(id, obj, edges, thread)
|
||||
return node, edges
|
||||
|
||||
|
||||
@@ -372,6 +422,8 @@ def doc_state(label, state, app):
|
||||
graph += "nodesep = 0.5;\n"
|
||||
graph += "rankdir = LR;\n"
|
||||
graph += "node [shape=Mrecord];\n"
|
||||
graph += f"label=<State: <B>{label[1:]}</B>>;\n"
|
||||
graph += "fontsize=40;\n"
|
||||
graph += "\n"
|
||||
arrows = ""
|
||||
ext = ""
|
||||
@@ -387,10 +439,10 @@ def doc_state(label, state, app):
|
||||
obj = app["+Functions"][f"+{fn}"]
|
||||
node, edges = __doc_gam__(fn, obj, edges, tname[1:])
|
||||
graph += f"{node}\n"
|
||||
graph += f"\n label = < <B>{tname[1:]}</B> >;\n"
|
||||
graph += f"\n label = <Thread: <B>{tname[1:]}</B> >;\n"
|
||||
graph += " fontsize = 24.0;\n"
|
||||
graph += " penwidth = 3;\n"
|
||||
graph += ' color = "#0A0";\n'
|
||||
graph += ' color = "#1A1A1A";\n'
|
||||
graph += "}\n"
|
||||
if "+Data" in app:
|
||||
for key, obj in app["+Data"].items():
|
||||
|
||||
Reference in New Issue
Block a user