Generate code from Visual Paradigm state diagrams#
SinelaboreRT supports state machine models exported from Visual Paradigm via XMI.
When using Visual Paradigm some tool specific things must be taken care of. The following section discusses these points. First take a look how a rather complex state chart looks like in Visual Paradigm.

A rather complex state chart designed in Visual Paradigm
Organising your project#
The code-generator needs to know how to find your state-based class in the exported XMI diagram. The path to your class in your project tree must be specified on the command line using the -t flag.
The following figure shows the project browser window for the ’oven’ example state diagram from the tutorial section. From the figure below you can directly derive the path which is -t 'ModelModel:OvenClass'. The different parts of the path must be separated with colons. The class diagram must not be specified.

Visual Paradigm’s project browser. From the used structure the path can be directly derived.
Exporting your project to XMI#
The main purpose of XMI is to enable easy interchange of metadata between modelling tools. Several UML modelling tools support the import and export of XMI file. The exported XMI file is then used as as input for the code-generator. During the development of the XMI standard different versions were created. The latest are based on a XML schema. The code-generator expects version 2.1 for VP generated XMI files. Therefore select UML 2.1 (XMI 2.1) in the export dialog before exporting.
The code-generator expects your class at a certain hierarchy in the model (model, class model, class). Tools allow to export a XMI downwards from a selected node e.g. the class model. Then the code-generator will not be able to find the right class to generate code from. Therefore make sure that you select the top level node in the project browser before opening the export dialog. The following figure shows the export dialog. You can open it by selecting Project -> Import/Export -> Export Package to XMI.

VP’s export dialog. Ensure that XMI Type is set to UML 2.1
Attaching action and include comments#
You can specify code that is just copied at the beginning of the state machine c-file. Also you can add action code that is called every time the state machine is called. This can be done by using comments starting with the keywords action: and include: (see Adapting the Generated Code). Link these two comments to the class owning the state machine. See the figure below. You must use plain text in the comment. It is not possible to use html comments. See the figure below.

Specify header and action code using comments. Make sure the format of the comment is ’plain text’.
States#
VP allows you to define entry, do and exit activities as well as inner transitions for a state. Also multiline code statements are possible per action. To specify child states you have to add a region to a state first. If you have doubts cross-check in the model view that a state is a child of the parent. See the figures above for an example. If you edit actions the action name should be deleted for clarity. See the figure below.

State definition. Define the action code and eventually an internal event of a state.
Transitions#
Open the property dialog of the transition and add a trigger (i.e. event) that triggers the transition. You must select ’Signal Trigger’ as trigger type. Then close the dialog. Open the properties dialog again. Now you can add an optional action code and guard. It is possible to provide multiple code lines for the transition’s action which is a nice feature. Delete the transition name (’action’ by default) for clarity. To display the action code right click on the diagram and select ’Presentation Options → Transition Display Options → Show Transition Effect Body’. Otherwise the action code is not shown. See the figure below.

Trigger definition. Define signal triggers only and select the one which should trigger the transition. On the tab card ’General’ you can set the guard and action code.
History State and other Pseudo States#
Just add final states or history states from the tool bar into your diagram.
Supported / Unsupported#
The code generator supports a subset of the design elements provided by VP. The supported elements are:
- Hierarchical states
- (Signal-)Events with event name, guard and action
- Initial and final pseudo states
- History states (deep, flat)
- Choices
- Regions in a diagram
The unsupported elements are:
- Constraints
- Syncstates and junctions
- Entry and exit points (not to compare with entry/exit actions within states)
- Terminate and Fork/Join
- Extended history handling
Notes#
If generation fails for a specific XMI export, send us a minimal example model and the error output so we can reproduce and fix the issue quickly.