feat: added comments

This commit is contained in:
Martino Ferrari
2024-03-14 18:53:26 +01:00
parent c2422d5022
commit afa7660b96
2 changed files with 109 additions and 51 deletions
+109 -50
View File
@@ -88,80 +88,118 @@ def __doc_triggered_iogam__(name, obj, edges, thread):
return node, edges
__set_keys__ = (
"Alias",
"Type",
"DataSource",
"NumberOfElements",
"NumberOfDimensions",
"Ranges",
)
def __doc_iogam__(id, obj, edges, thread):
node = ""
if "InputSignals" in obj and "OutputSignals" in obj:
inputs, outputs = obj["InputSignals"], obj["OutputSignals"]
output_names = list(outputs.keys())
input_names = list(inputs.keys())
j = 0
input_size = 0
output_size = 0
i = 0
irow = ""
orow = ""
out_i = 0
in_i = 0
counter = 0
while i < len(inputs) and j < len(outputs):
irelcount = 0
orelcount = 0
while in_i < len(inputs) and out_i < len(outputs):
irows = []
orows = []
bold = False
while input_size <= output_size and i < len(inputs):
in_label = input_names[i]
while input_size <= output_size and in_i < len(inputs):
in_label = input_names[in_i]
input = inputs[in_label]
if irow:
irow += " | "
input_size += doc.signal_byte_size(input)
i += 1
in_i += 1
alias = doc.signal_alias(in_label, input)
mtype = doc.signal_type(input)
if mtype[2]:
bold = True
irow += f"<in_{irelcount}> {doc.type_to_string(mtype)}"
irow = f"{doc.type_to_string(mtype)}"
for key, val in input.items():
if key not in __set_keys__:
bold = True
irow += f"<br/>{key}: {val}"
datasrc = input["DataSource"]
edges.append(
doc.edge(
doc.signal(datasrc, alias, mtype),
doc.signal(f"{id}_{counter}", f"{irelcount}", mtype),
doc.signal(f"{id}_{counter}", f"{len(irows)}", mtype),
thread,
)
)
irelcount += 1
while output_size < input_size and j < len(outputs):
out_label = output_names[j]
irows.append(irow)
while output_size < input_size and out_i < len(outputs):
out_label = output_names[out_i]
output = outputs[out_label]
output_size += doc.signal_byte_size(output)
if orow:
orow += " | "
j += 1
out_i += 1
alias = doc.signal_alias(out_label, output)
mtype = doc.signal_type(output)
if mtype[2]:
bold = True
orow += f"<out_{orelcount}> {doc.type_to_string(mtype)}"
orow = f"{doc.type_to_string(mtype)}"
for key, val in output.items():
if key not in __set_keys__:
bold = True
orow += f"<br/>{key}: {val}"
datasrc = output["DataSource"]
edges.append(
doc.edge(
doc.signal(f"{id}_{counter}", f"{orelcount}", mtype),
doc.signal(f"{id}_{counter}", f"{len(orows)}", mtype),
doc.signal(datasrc, alias, mtype),
thread,
)
)
orelcount += 1
orows.append(orow)
fill = "#fff"
fsize = 14.0
if bold or irelcount > 1 or orelcount > 1:
total = max(len(orows), len(irows))
if bold or total > 1:
fill = "#333"
bold = True
else:
irow = f"<in_{irelcount-1}> "
orow = f"<out_{orelcount-1}>"
fill = "#666"
fsize = 0.0
node += f'{id}_{counter} [tooltip=" IOGAM::{id} " label="'
node += "{ {" + irow + "} | {" + orow + "} }"
node += f'", fillcolor="{fill}", color="#666", style=filled,'
node += f' fontcolor="#fff", fontsize={fsize}, height=0, width=0];\n'
irow = ""
orow = ""
inode = f"{id}_{counter} [shape=plaintext,"
inode += f'tooltip=" IOGAM::{id} ", label=<'
inode += "<table cellspacing='0' cellborder='1'"
inode += f" cellpadding='4' border='0' bgcolor='{fill}'>"
if bold:
for i in range(total):
inode += "<tr>"
if i < len(irows):
inode += f'<td port="in_{i}" bgcolor="{fill}"'
if len(orows) > len(irows):
inode += f' rowspan="{len(orows)}"'
inode += ">"
inode += '<font color="#fff">'
inode += irows[i]
inode += "</font></td>"
if i < len(orows):
inode += f'<td port="out_{i}" bgcolor="{fill}"'
if len(orows) < len(irows):
inode += f' rowspan="{len(irows)}"'
inode += ">"
inode += '<font color="#fff">'
inode += orows[i]
inode += "</font></td>"
inode += "</tr>"
else:
inode += "<tr><td port='in_0'></td>"
inode += "<td port='out_0'></td></tr>"
inode += "</table>>"
inode += "];\n"
node += inode
irows = []
orows = []
counter += 1
return node, edges
@@ -192,9 +230,24 @@ def __doc_constgam__(id, obj, edges, thread):
def __doc_message_gam__(id, obj, edges, thread):
label = id[2:]
node = f' {id} [label="{label}&#92;n{obj["Class"]} | '
sigs, edges = __doc_common_gam__(id, obj, edges, thread)
if sigs:
node += sigs + '"];'
inputs = ""
if "InputSignals" in obj:
for i, (l, sig) in enumerate(obj["InputSignals"].items()):
alias = doc.signal_alias(l, sig)
mtype = doc.signal_type(sig)
datasrc = sig["DataSource"]
edges.append(
doc.edge(
doc.signal(datasrc, alias, mtype),
doc.signal(id, l, mtype),
thread,
)
)
if i != 0:
inputs += " | "
inputs += f"<in_{doc.format_name(l)}> {l}"
if inputs:
node += inputs + '"];'
else:
node = ""
@@ -233,7 +286,8 @@ def __doc_events__(id, obj, edges, thread):
else:
nodes += f"{fn} "
nodes += "</td></tr></table>>];\n"
nodes += f" {id} -> {id}_{event_id}_{msg_id} [arrowhead=box];\n"
nodes += f" {id}:e -> {id}_{event_id}_{msg_id}:w"
nodes += " [arrowhead=box, constraint=true];\n"
return nodes, edges
@@ -370,20 +424,23 @@ def __process_ds__(name, obj, edges):
for sig in sigs:
if sig not in order:
lost.append(sig)
node = f'{name} [label="{name}&#92;n{cls} | '
node = f"{name} [shape=plaintext; label=<"
node += (
'<table border="0" cellpadding="4" cellborder="1" cellspacing="0">\n'
)
node += f"<tr><td><b>{name}</b><br/>{cls}</td></tr>\n"
for i, sig_name in enumerate(order):
if i > 0:
node += " | "
node += f'<tr><td port="{doc.format_name(sig_name)}">'
sig_type = sigs[sig_name]
node += f"<{doc.format_name(sig_name)}> {sig_name} ({doc.type_to_string(sig_type)})"
node += f"{sig_name} ({doc.type_to_string(sig_type)})"
node += "</td></tr>\n"
for sig_name in lost:
logging.warning(f"Lost signal {name}:{sig_name}")
if node:
node += " | "
node += f'<tr><td port="{doc.format_name(sig_name)}">'
sig_type = sigs[sig_name]
node += f"<{doc.format_name(sig_name)}> {sig_name} ({doc.type_to_string(sig_type)})"
node += '", color=blue];\n'
node += f"{sig_name} ({doc.type_to_string(sig_type)})"
node += "</td></tr>\n"
node += "</table>>, color=blue];\n"
if not multi_thread and node:
node = f"subgraph cluster_{thread}" + "{\n" + node + "};\n"
return node, edges
@@ -398,6 +455,7 @@ def __process_edges__(edges, datasources):
trg_sig = doc.format_name(target[1])
a = f"{src_obj}"
b = f"{trg_obj}"
ranked = True
if src_obj in datasources:
a += f":{src_sig}"
else:
@@ -410,7 +468,8 @@ def __process_edges__(edges, datasources):
in_type = doc.type_to_string(source[2])
out_type = doc.type_to_string(target[2])
mtype = in_type if in_type == out_type else f"{in_type} -> {out_type}"
arrows += f'{a} -> {b} [tooltip=" {mtype} ", labelfloat=false];\n'
arrows += f'{a}:e -> {b}:w [tooltip=" {mtype} ", labelfloat=false'
arrows += f", constraint={ranked}];\n"
return arrows
@@ -418,8 +477,8 @@ def doc_state(label, state, app):
global __PATH__
mdstate = ""
graph = f"digraph {label[1:]}" + "{\n"
graph += "ranksep = 1;\n"
graph += "nodesep = 0.5;\n"
graph += "ranksep = 2;\n"
graph += "nodesep = 0.05;\n"
graph += "rankdir = LR;\n"
graph += "node [shape=Mrecord];\n"
graph += f"label=<State: <B>{label[1:]}</B>>;\n"