diff --git a/autodoc/autodoc.py b/autodoc/autodoc.py index a73f05e..c503266 100644 --- a/autodoc/autodoc.py +++ b/autodoc/autodoc.py @@ -24,7 +24,7 @@ def __doc_application__(label, app): mdapp += f"Below are descrbed the states and threads of the real-time application {label[1:]}.\n" mdapp += "\n" - # mdapp += "```\n" + mdapp += "```\n" # mdapp += f'╭{"─"*(len(label)-1)}╮\n' # mdapp += f"│{label[1:]}│\n" # mdapp += f'╰┬{"─"*(len(label)-2)}╯\n' @@ -41,7 +41,7 @@ def __doc_application__(label, app): # if label[0] == "+": # mdapp += f" {ch} {label[1:]}\n" # mdapp += __doc_app_state__(obj, tab) - # mdapp += "```\n" + mdapp += "```\n" for label, obj in states.items(): if label[0] == "+": mdapp += f'\n### State "{label[1:]}"\n' @@ -62,6 +62,7 @@ def document(fname, args, config): mddoc += "author: MARTe AutoDOC\n" mddoc += "titlepage: true\n" mddoc += f"date: {today}\n" + mddoc += "geometry: margin=2cm\n" mddoc += "---\n\n" mddoc += f"# {fname}\n" @@ -78,5 +79,5 @@ def document(fname, args, config): file.write(mddoc) logging.info("Generating pdf...") os.system( - f"pandoc -H pandoc/disable_float.tex --template eisvogel --resource-path={doc.path()} -s {fpath} -o {pdfpath}" + f"pandoc -H pandoc/disable_float.tex --resource-path={doc.path()} -s {fpath} -o {pdfpath}" ) diff --git a/autodoc/doc_state.py b/autodoc/doc_state.py index c0afb8f..5710ecf 100644 --- a/autodoc/doc_state.py +++ b/autodoc/doc_state.py @@ -318,10 +318,10 @@ __gams_fns__ = { } -def __doc_gam__(label, obj, edges, thread): +def __doc_gam__(label, obj, edges, thread, classfilter=True): id = f"fn{label}" cls = obj["Class"] - if cls in __gams_fns__: + if classfilter and cls in __gams_fns__: return __gams_fns__[cls](id, obj, edges, thread) node = f' {id} [label="{label}\n{obj["Class"]} | ' sigs, edges = __doc_common_gam__(id, obj, edges, thread) @@ -473,9 +473,7 @@ def __process_edges__(edges, datasources): return arrows -def doc_state(label, state, app): - global __PATH__ - mdstate = "" +def __state_full_graph__(label, state, app): graph = f"digraph {label[1:]}" + "{\n" graph += "ranksep = 2;\n" graph += "nodesep = 0.05;\n" @@ -485,7 +483,6 @@ def doc_state(label, state, app): graph += "fontsize=40;\n" graph += "\n" arrows = "" - ext = "" edges = [] datasources = {} if "+Threads" in state: @@ -510,14 +507,122 @@ def doc_state(label, state, app): node, edges = __process_ds__(key[1:], obj, edges) graph += node arrows = __process_edges__(edges, datasources) - graph += "\n" + ext + "\n" + arrows + graph += "\n\n" + arrows graph += "}\n" fname = f"{label[1:]}" - with open(os.path.join(doc.path(), f"{fname}.dot"), "w") as file: + gpath = os.path.join(doc.path(), f"{fname}_full.dot") + with open(gpath, "w") as file: file.write(graph) - os.system( - f"dot -Tsvg -o{os.path.join(doc.path(), fname)}.svg {os.path.join(doc.path(), fname)}.dot" - ) - mdstate += f"![{fname} state]({fname}.svg)\n" - return mdstate + return gpath + + +def __simple_gam__(label, obj): + cls = obj["Class"] + id = f"fn{doc.format_name(label)}" + if "InputSignals" in obj: + for _, signal in obj["InputSignals"].items(): + ds = f'ds{doc.format_name(signal["DataSource"])}' + if "OutputSignals" in obj: + for _, signal in obj["OutputSignals"].items(): + ds = f'ds{doc.format_name(signal["DataSource"])}' + return f"{id}[label=<{label}
{cls}>]\n" + + +def __simple_ds__(label, obj, edges): + cls = obj["Class"] + thread = "" + multi_thread = False + sources = [] + targets = [] + id = f"ds{doc.format_name(label)}" + for edge in edges: + if edge[0][0] == label: + if not thread: + thread = edge[-1] + elif thread != edge[-1]: + multi_thread = True + if edge[1][0] == label: + if not thread: + thread = edge[-1] + elif thread != edge[-1]: + multi_thread = True + node = f"{id}[label=<{label}
{cls}>, fillcolor=lightblue]\n" + if thread and not multi_thread: + node = f"subgraph cluster_{thread}" + "{\n " + node + "}" + return node + + +def __simple_id__(name, datasources): + if name in datasources: + return f"ds{doc.format_name(name)}" + return name + + +def __simple_edges__(edges, datasources): + arrows = "" + done = [] + + for source, target, _ in edges: + src_obj = __simple_id__(source[0], datasources) + trg_obj = __simple_id__(target[0], datasources) + if (src_obj, trg_obj) not in done: + arrows += f"{src_obj}:e -> {trg_obj}:w\n" + done.append((src_obj, trg_obj)) + return arrows + + +def __state_simple_graph__(label, state, app): + graph = f"digraph {label[1:]}" + "{\n" + graph += "rankdir = LR;\n" + graph += 'node [shape=rect, style="rounded, filled", fillcolor=white];\n' + graph += f"label={label[1:]}>;\n" + graph += "fontsize=40;\n" + graph += "\n" + arrows = "" + edges = [] + datasources = {} + if "+Threads" in state: + for tname, obj in state["+Threads"].items(): + if tname[0] == "+": + graph += f"subgraph cluster_{tname[1:]}" + "{\n" + if "Functions" in obj: + fns = obj["Functions"] + for fn in fns: + obj = app["+Functions"][f"+{fn}"] + _, edges = __doc_gam__( + fn, obj, edges, tname[1:], classfilter=False + ) + graph += f" {__simple_gam__(fn, obj)}" + graph += f"\n label = {tname[1:]} >;\n" + graph += " fontsize = 24.0;\n" + graph += " penwidth = 3;\n" + graph += ' color = "#1A1A1A";\n' + graph += "}\n" + if "+Data" in app: + for key, obj in app["+Data"].items(): + if key[0] == "+": + datasources[key[1:]] = obj["Class"] + node, edges = __process_ds__(key[1:], obj, edges) + if node: + graph += __simple_ds__(key[1:], obj, edges) + graph += __simple_edges__(edges, datasources) + # arrows = __process_edges__(edges, datasources) + # graph += "\n" + ext + "\n" + arrows + graph += "}\n" + fname = f"{label[1:]}" + + gpath = os.path.join(doc.path(), f"{fname}_simple.dot") + with open(gpath, "w") as file: + file.write(graph) + return gpath + + +def doc_state(label, state, app): + fname = f"{label[1:]}" + src_path = __state_full_graph__(label, state, app) + os.system(f"dot -Tsvg -o{os.path.join(doc.path(), fname)}_full.svg {src_path}") + src_path = __state_simple_graph__(label, state, app) + + os.system(f"dot -Tsvg -o{os.path.join(doc.path(), fname)}.svg {src_path}") + return f"![{fname} state]({fname}.svg)" + "{width=100% height=90%}\n"