Generating state machine code

Once the controller class and state machine are modeled, you can generate state machine code for the controller and state machine. With the generated state machine, you can run instant generator to produce other classes, like the model and view classes, and incooperate with the state machine code.

To generate state machine code:

  1. Select Tools > Code > Generate State Machine Code... frrom the toolbar.
  2. In the Generate State Machine dialog box, select the controller class for generating state machine.
  3. Select the state machine in the drop down menu State Diagram for generating code.
  4. Select the programming language of the code.
  5. Specify the output path to save the generated code to.
  6. Optionally configure the generator options.
  7. Click OK to generate.
NOTE: There must be at least one class that contain sub state machine diagram in order to open the Generate State Machine Code dialog box.

An overview of Generate State Machine Code dialog box

An overview of Generate State Machine Code dialog box
An overview of Generate State Machine Code dialog box
No. Name Description
1 Class The controller class for generating state machine.
2 State Diagram The state machine (in the form of state machine diagram) to generate. It must be a sub-class of the chosen controller class.
3 Language The programming language of code to generate.
4 Output Path The output path of state machine code.
5 Options

Options for code generation. Below is a description:

Synchronized transition methods - By checking, it causes the generated code to:

  • Java: add the synchronized keyword to the transition method declarations.
  • VB.net: encapsulate the transition method's body in a SyncLock Me, End SyncLock block.
  • C#: encapsulate the transition method's body in a lock(this) {...} block.

Generate try/catch - Uncheck to not generate try/catch code. You are recommended to keep this checked. Uncheck only in C++ applications where exceptions are not used.

Generate debug message - Adds debug output messages to the generated code.

Re-generate transition methods - Check to overwrite the transition methods in code, including the implementation.

Browse output directory after generate - Open the output path.

Auto create transition operations - If a transition is named, but does not have Operation assigned. By checking this option operation will be created to the parent class, named as the transition name.

Generate sample - Generate sample files to guide you how to work with the generated file.

Generate diagram image - Generate PNG image for chosen state machine diagram.

6 OK Click to start code generation.
7 Cancel Click to close the Generate State Machine Code dialog box.
A description of Generate State Machine Code dialog box

Related Resources

The following resources may help you to learn more about the topic discussed in this page.

 
1. Modeling guidelines Table of Contents 3. Reverse state machine code
 

Technical Support

Have technical issues or suggestions? Please contact Visual Paradigm Support Team.

Sales Support

Have questions related to registration, licensing or payment? Feel free to contact Visual Paradigm Sales Team.

Discussion Forum

Share your suggestions of opinions at VP Discussion Forum.