drawio2cbd module¶
This script generates a Python-consistent CBD from an XML file, as constructed in draw.io / diagrams.net .
| Author: | Randy Paredis |
|---|---|
| Python Version: | 3.6+ |
-
drawio2cbd.IGNORE= ['id', 'label', 'placeholders', 'symbol', 'class_name', 'block_name', '__docstring__']¶ Properties to ignore when parsing.
-
drawio2cbd.PLOT_FORMATS= ['mpl', 'matplotlib', 'bokeh', 'csv', 'off', 'false']¶ Ways to plot the data.
-
exception
drawio2cbd.ParseException(message)¶ Bases:
ExceptionSemantic exceptions when parsing.
-
class
drawio2cbd.Parser(inputfile, outputfile=None, all_=False, ports=False)¶ Bases:
objectParses a draw.io XML file.
Parameters: - inputfile (str) – Filename for the input.
- outputfile (str) – When a string, this is the output filename. When None, the console will be used.
- all (bool) – Whether or not to add empty CBD diagrams to the generated file.
- ports (bool) – Some port names can be identified from the context. By default, the generated code allows the CBD framework to do so. When this param is True, even those ports will explicitly be set.
-
convert(command, entry='main', delta=None, time=10, draw=None, latex=None, plot=None)¶ Does the conversion and creates a file or prints to the console.
Parameters: - command (str) – The command that was used to run this script.
- entry (str) – The main class entry point.
- delta (float) – The timestep size. This is 1 for Discrete-Time CBDs.
- time (int) – How long the simulation should run.
- draw – List of blocks to draw. None indicates the empty list.
- latex – List of blocks to generate LaTeX for. None indicates the empty list.
- plot (str) – The plotting format to use. None indicates no plotting.
-
create_class(root, class_name, **kwargs)¶ Creates a class.
Parameters: - root – The root element for this class. Must be the document. Is used to find links with other classes.
- class_name (str) – The name for the class.
- **kwargs – Additional class parameters as set in the Properties window.
Returns: A class as a string.
-
create_file(command, entry='main', delta=None, time=10, draw=None, latex=None, plot=None)¶ Creates the full file.
Parameters: - command (str) – The command that was used to run this script.
- entry (str) – The main class entry point.
- delta (float) – The timestep size. This is 1 for Discrete-Time CBDs.
- time (int) – How long the simulation should run.
- draw – List of blocks to draw. None indicates the empty list.
- latex – List of blocks to generate LaTeX for. None indicates the empty list.
- plot (str) – The plotting format to use. None indicates no plotting.
Returns: The file as a string.
-
static
decode_and_deflate(data)¶ Draw.io compresses each page as follows: First, all data is url-encoded Next, it is compressed/deflated Finally, it is encoded according to base64.
To obtain the page data, we have to do the reverse.
Returns: Uncompressed and decoded data as a string.
-
parse()¶ Does the actual file parsing.
If the file is compressed, we uncompress and work from there. If it wasn’t compressed, we can work with the whole tree.
Only looks at “Custom Class” shapes that have a “class_name” set.
Returns: An iterator of all classes that must be generated.
-
static
signal(format: str, ct=False)¶ Creates a draw_signals function and corresponing imports, based on the given format. Accepted formats are ‘matplotlib’ (or ‘mpl’ for short), ‘bokeh’ and ‘csv’.
Parameters: - format (str) – How the signal must be outputted. Can be one of [‘matplotlib’, ‘mpl’, ‘bokeh’, ‘csv’]
- ct (bool) – Whether or not the plot indicates a continuous-time simulation. When it does, a line-plot will be used for the plots, otherwise a dotted plot is used. For CSV and XML this attribute has no effect. Defaults to ‘False’.
Returns: A string, including a ‘plot_signal’ function for the generated file.