Previous Next
sde-vs_user_guide Chapter 12 - State Machine Diagram Code Generation

Chapter 12 - State Machine Diagram Code Generation

SDE-VS can assist you in drawing a State Machine Diagram, as well as generate a State Machine Diagram Code.
 Figure 12.1 - State Machine Diagram

Drawing State Machine Diagram

To generate a state machine diagram, you should first have a Class on the class diagram. Select Sub Diagrams > State Machine Diagram > Create State Machine Diagram from the pop-down menu of the class to create a sub diagram.
Figure 12.2 - Select Create State Machine Diagram

You will see an initial pseudo state on the state machine diagram.
Figure 12.3 - State machine diagram with an initial pseudo state

Drag a State from the diagram toolbar and drop the diagram.
Figure 12.4 - Drag and drop a State

Alternatively, you can use the resources of the initial pseudo state.
Figure 12.5 - Using resources

A diagram can then be created.
 Figure 12.6 - Diagram created

Generate State Machine Code

The process of creating a State Machine Code is simple.
To generate a state machine code:
1. Select Modeling > State Machine Code >Generate Code... from the main menu.
Figure 12.7 - Select Generate Code...

2. The Generate state machine code dialog is displayed.
Figure 12.8 - Generate state machine code dialog

3. Select a language to generate the code in from the drop-down menu.
 Figure 12.9 - Select Language

4.Configure the Output Path. The default output directory is the directory of Visual Studio. You may change the output directory by deselecting the "Generate to Source Folder" item.
 Figure 12.10 - Configure an output path

5. The process of generation is shown. You may choose to Close Dialog when finished progress by checking the check box.
 Figure 12.11 - Process of generation

6. The code is generated.
Figure 12.12 - Code generated


Programming with Generated State Machine Code

SDE-VS supports the generation of different types of state machine code. Since the steps for generation of codes in different languages are similar, Java will be used as an example to illustrate the steps.
Before generating the code, you may want to configure the properties of states and transitions.

For state, configure by selecting Open Specification...from the pop-up menu.
Figure 12.13 - Select Open Specification...

The State Specification dialog box is now open, and you can configure the state properties here. You may edit the Entry property by clicking Edit... .
Figure 12.14 - State Specification dialog box

This is the Activity Specification(Entry) dialog box. After editing to suit your needs, click OK to confirm.
Figure 12.15 - Activity Specification(Entry) dialog box

State's property has been edited.
Figure 12.16 - State's property edited

Similarly, you can edit the transition by selecting the Open Specification... from the pop-up menu.
Figure 12.17 - Open Specification...

Then, edit the properties of transition in the Transition Specification dialog box.
Figure 12.18 - Transition Specification dialog box

The states and transitions properties are configured.
Figure 12.19 - State Machine Diagram

Reverse State Machine Code

Apart from generation of state machine code, SDE-VS also supports the reversal of the state machine code file, with extension .sm.
Figure 12.26 - A .sm file

To reverse the .sm file:
1. Select Modeling > State Machine Code > Reverse Code... from the main menu .
Figure 12.27 - Select Reverse Code...

2. The Reverse State Machine Code dialog box is displayed. Select the Class and State Diagram.
Figure 12.28 - Reverse State Machine Code dialog box

3. Configure the input file path by typing in the text box or select ... .Select OK to confirm.
Figure 12.29 - Configure the input file path

4. The progress of reversal is shown. You can select to Close Dialog when finished progress by checking the check box.
Figure 12.30- Progress of reversing

5. The state machine code is now reversed.
Figure 12.31 - State machine code is reversed

Previous Next
Visual Paradigm International Limited
Website: www.visual-paradigm.com
E-mail: support@visual-paradigm.com