Skip to content
Snippets Groups Projects
Commit 35b9a1bf authored by Oscar Gustafsson's avatar Oscar Gustafsson :bicyclist:
Browse files

Added get_sfg and show_sfg methods

parent 48178a0c
Branches
Tags
1 merge request!73Added sfg and show_sfg methods
Pipeline #16841 passed
...@@ -12,7 +12,7 @@ import itertools as it ...@@ -12,7 +12,7 @@ import itertools as it
from graphviz import Digraph from graphviz import Digraph
from b_asic.port import SignalSourceProvider, OutputPort from b_asic.port import SignalSourceProvider, OutputPort
from b_asic.operation import Operation, AbstractOperation, ResultKey, DelayMap, MutableResultMap, MutableDelayMap from b_asic.operation import Operation, AbstractOperation, ResultKey, MutableResultMap, MutableDelayMap
from b_asic.signal import Signal from b_asic.signal import Signal
from b_asic.graph_component import GraphID, GraphIDNumber, GraphComponent, Name, TypeName from b_asic.graph_component import GraphID, GraphIDNumber, GraphComponent, Name, TypeName
from b_asic.special_operations import Input, Output, Delay from b_asic.special_operations import Input, Output, Delay
...@@ -846,3 +846,58 @@ class SFG(AbstractOperation): ...@@ -846,3 +846,58 @@ class SFG(AbstractOperation):
src.index, input_values, results, delays, key_base, bits_override, truncate) src.index, input_values, results, delays, key_base, bits_override, truncate)
results[key] = value results[key] = value
return value return value
def get_sfg(self,format=None, show_id=False) -> Digraph:
"""
Returns a Digraph of the SFG. Can be directly displayed in IPython.
Parameters
----------
format : string, optional
File format of the generated graph. Output formats can be found at https://www.graphviz.org/doc/info/output.html
Most common are "pdf", "eps", "png", and "svg". Default is None which leads to PDF.
show_id : Boolean, optional
If True, the graph_id:s of signals are shown. The default is False.
Returns
-------
Digraph
Digraph of the SFG.
"""
if format is not None:
pg = Digraph(format=format)
else:
pg = Digraph()
pg.attr(rankdir='LR')
for op in self._components_by_id.values():
if isinstance(op, Signal):
if show_id:
pg.edge(op.source.operation.graph_id, op.destination.operation.graph_id, label=op.graph_id)
else:
pg.edge(op.source.operation.graph_id, op.destination.operation.graph_id)
else:
if op.type_name() == Delay.type_name():
pg.node(op.graph_id, shape='square')
else:
pg.node(op.graph_id)
return pg
def show_sfg(self, format=None, show_id=False) -> None:
"""
Shows a visual representation of the SFG using the default system viewer.
Parameters
----------
format : string, optional
File format of the generated graph. Output formats can be found at https://www.graphviz.org/doc/info/output.html
Most common are "pdf", "eps", "png", and "svg". Default is None which leads to PDF.
show_id : Boolean, optional
If True, the graph_id:s of signals are shown. The default is False.
"""
self.get_sfg(format=format, show_id=show_id).view()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment