DrawioConvert Quick Documentation
|
DrawIO to CBD ConversionDrawioConvert is a project that allows conversion from simple, yet structured draw.io diagrams to CBD models that can be interpreted by the CBD simulator. This document will describe how this can be done. Setting up DrawIOIn drawio, select File > Open Library and load CBDLibrary.xml. This provides a set of primitive CBD blocks that can be used in your models. Once included, it can be found at the top of the shapes library. Block Properties
All blocks in the library have some block-specific properties that can be set by the user. Hovering over a component shows all non-empty properties that were set on this shape.
Working with Library BlocksTo guarantee a consistent visual appearance of CBD models, no blocks in the library, except for the Custom Block, can be resized. Every block has zero or more input and output ports. Input ports are represented by the InputPortBlock (black triangle) and output ports by the OutputPortBlock (white triangle). When selecting (left mouse button) a port, a small, movable, yellow/orange diamond-shaped anchor will appear in front of the port's name. The position of this label can be changed by dragging the anchor. The port name can be altered in the Edit Data window. Each CBD block that is not a port may have the following properties:
Optionally, additional class parameters can be provided by adding more properties. Their values will be passed on as default values for the corresponding property as an argument, e.g., to use strings, enclose the value in "..." or '...', for None, leave it empty or literally type "None"... Class parameters that cannot be used are: label (prevented by drawio), id (overwritten by drawio), placeholders (prevented by drawio), symbol (ignored by the converter) and __docstring__ (used for other purposes, see later). Note: Blocks with a variable number of inputs (i.e., the OrBlock and the AndBlock) may still need additional ports to be placed/removed. Creating Custom CBD BlocksA custom hierarchical CBD block is constructed as a network of already provided blocks (which in their own right may be custom hierarchical blocks) using the Custom Block element from CBDLibrary.xml. This is a collapsible component in which a block diagram may be drawn. It has two important properties:
Additional properties can be added to create custom class parameters. The same set of parameters that was discussed above cannot be set, with the exception of __docstring__, which allows adding documentation to custom blocks. The empty rectangle is a container for the custom hierachical block. Blocks can be dragged into the rectangular area and connected. InputPortBlock and OutputPortBlock are used to add inputs and outputs with their name property set to the port's name. The Custom Block component can, in constrast with all other blocks in the library, be resized. This allows for larger hierarchical models to be created, as the basic blocks cannot be resized.
In the figure below, a custom Sine Generator block with no input ports, a single output port and a custom graphical representation is shown.
Next, create a graphical representation of the block (i.e., what an instance block should look like when used in a block diagram), add the corresponding ports and set the property class_name to the same class as that set in the Custom Block. Make sure not to forget to add any class parameters that were added to the Custom Block. Only the Custom Block components will be read by the converter. Anything else is implicitly ignored. Furthermore, when using the -S/--singlefile flag, the script is page-independent, meaning multiple pages may be used inside a single drawio document to maintain a clean overview of the created models. When not using this flag (default), a new model file will be created for each page. ConversionTo generate code from the created drawio files, execute the the __main__.py file with the -F CBD flag. This tells DrawioConvert to use the CBD formalism. Two files will/can be created:
It is possible to use continuous models, where they are discretized to a certain delta. This is customizeable using the -E/--environment flag. I.e. by setting -E delta=0.1, it is possible to execute in steps of 0.1 time-units. Note how -t/--time identifies the total simulation time, not the amount of steps taken. For instance, to create a Python file from the custom Sine Generator, as shown above, the following command can be used: python __main__.py -F CBD -e SineGen -sSrgv sinegen.drawio -E delta=0.1where:
Use the -h/--help flag to get more information on the available flags. |
Maintained by Hans Vangheluwe. | Last Modified: 2023/05/08 02:53:18. |