State Machine Diagram Code Generation - Visual Paradigm
State Machine Diagram Code Generation - Visual Paradigm
State Machine Diagram Code Generation - Visual Paradigm
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
12<br />
<strong>State</strong> <strong>Machine</strong> <strong>Diagram</strong> <strong>Code</strong><br />
<strong>Generation</strong>
SDE-VS User’s Guide (Part 1) Chapter 12 – <strong>State</strong> <strong>Machine</strong> <strong>Diagram</strong> <strong>Code</strong> <strong>Generation</strong><br />
Chapter 12 - <strong>State</strong> <strong>Machine</strong> <strong>Diagram</strong> <strong>Code</strong><br />
<strong>Generation</strong><br />
SDE-VS can assist you in drawing a <strong>State</strong> <strong>Machine</strong> <strong>Diagram</strong>, as well as generate a <strong>State</strong> <strong>Machine</strong> <strong>Diagram</strong> <strong>Code</strong>.<br />
12-2<br />
Figure 12.1 - <strong>State</strong> <strong>Machine</strong> <strong>Diagram</strong><br />
Drawing <strong>State</strong> <strong>Machine</strong> <strong>Diagram</strong><br />
To generate a state machine diagram, you should first have a Class on the class diagram. Select Sub <strong>Diagram</strong>s > <strong>State</strong><br />
<strong>Machine</strong> <strong>Diagram</strong> > Create <strong>State</strong> <strong>Machine</strong> <strong>Diagram</strong> from the pop-down menu of the class to create a sub diagram.<br />
Figure 12.2 - Select Create <strong>State</strong> <strong>Machine</strong> <strong>Diagram</strong>
SDE-VS User’s Guide (Part 1) Chapter 12 – <strong>State</strong> <strong>Machine</strong> <strong>Diagram</strong> <strong>Code</strong> <strong>Generation</strong><br />
You will see an initial pseudo state on the state machine diagram.<br />
Figure 12.3 - <strong>State</strong> machine diagram with an initial<br />
pseudo state<br />
Drag a <strong>State</strong> from the diagram toolbar and drop the diagram.<br />
Figure 12.4 - Drag and drop a <strong>State</strong><br />
Alternatively, you can use the resources of the initial pseudo state.<br />
A diagram can then be created.<br />
Figure 12.5 - Using resources<br />
Figure 12.6 - <strong>Diagram</strong> created<br />
12-3
SDE-VS User’s Guide (Part 1) Chapter 12 – <strong>State</strong> <strong>Machine</strong> <strong>Diagram</strong> <strong>Code</strong> <strong>Generation</strong><br />
Generate <strong>State</strong> <strong>Machine</strong> <strong>Code</strong><br />
The process of creating a <strong>State</strong> <strong>Machine</strong> <strong>Code</strong> is simple.<br />
To generate a state machine code:<br />
1. Select Modeling > <strong>State</strong> <strong>Machine</strong> <strong>Code</strong> >Generate <strong>Code</strong>... from the main menu.<br />
12-4<br />
Figure 12.7 - Select Generate <strong>Code</strong>...<br />
2. The Generate state machine code dialog is displayed.<br />
Figure 12.8 - Generate state machine code dialog<br />
3. Select a language to generate the code in from the drop-down menu.<br />
Figure 12.9 - Select Language
SDE-VS User’s Guide (Part 1) Chapter 12 – <strong>State</strong> <strong>Machine</strong> <strong>Diagram</strong> <strong>Code</strong> <strong>Generation</strong><br />
4.Configure the Output Path. The default output directory is the directory of <strong>Visual</strong> Studio. You may change the output<br />
directory by deselecting the "Generate to Source Folder" item.<br />
Figure 12.10 - Configure an output path<br />
5. The process of generation is shown. You may choose to Close Dialog when finished progress by checking the check box.<br />
Figure 12.11 - Process of generation<br />
6. The code is generated.<br />
Figure 12.12 - <strong>Code</strong> generated<br />
12-5
SDE-VS User’s Guide (Part 1) Chapter 12 – <strong>State</strong> <strong>Machine</strong> <strong>Diagram</strong> <strong>Code</strong> <strong>Generation</strong><br />
Programming with Generated <strong>State</strong> <strong>Machine</strong> <strong>Code</strong><br />
SDE-VS supports the generation of different types of state machine code. Since the steps for generation of codes in different<br />
languages are similar, Java will be used as an example to illustrate the steps.<br />
Before generating the code, you may want to configure the properties of states and transitions.<br />
For state, configure by selecting Open Specification...from the pop-up menu.<br />
12-6<br />
Figure 12.13 - Select Open Specification...<br />
The <strong>State</strong> Specification dialog box is now open, and you can configure the state properties here. You may edit the Entry<br />
property by clicking Edit... .<br />
Figure 12.14 - <strong>State</strong> Specification dialog box
SDE-VS User’s Guide (Part 1) Chapter 12 – <strong>State</strong> <strong>Machine</strong> <strong>Diagram</strong> <strong>Code</strong> <strong>Generation</strong><br />
This is the Activity Specification(Entry) dialog box. After editing to suit your needs, click OK to confirm.<br />
Figure 12.15 - Activity Specification(Entry)<br />
dialog box<br />
<strong>State</strong>'s property has been edited.<br />
Figure 12.16 - <strong>State</strong>'s property edited<br />
12-7
SDE-VS User’s Guide (Part 1) Chapter 12 – <strong>State</strong> <strong>Machine</strong> <strong>Diagram</strong> <strong>Code</strong> <strong>Generation</strong><br />
Similarly, you can edit the transition by selecting the Open Specification... from the pop-up menu.<br />
12-8<br />
Figure 12.17 - Open Specification...<br />
Then, edit the properties of transition in the Transition Specification dialog box.<br />
Figure 12.18 - Transition Specification<br />
dialog box
SDE-VS User’s Guide (Part 1) Chapter 12 – <strong>State</strong> <strong>Machine</strong> <strong>Diagram</strong> <strong>Code</strong> <strong>Generation</strong><br />
The states and transitions properties are configured.<br />
Figure 12.19 - <strong>State</strong> <strong>Machine</strong> <strong>Diagram</strong><br />
Reverse <strong>State</strong> <strong>Machine</strong> <strong>Code</strong><br />
Apart from generation of state machine code, SDE-VS also supports the reversal of the state machine code file, with<br />
extension .sm.<br />
Figure 12.26 - A .sm file<br />
12-9
SDE-VS User’s Guide (Part 1) Chapter 12 – <strong>State</strong> <strong>Machine</strong> <strong>Diagram</strong> <strong>Code</strong> <strong>Generation</strong><br />
To reverse the .sm file:<br />
1. Select Modeling > <strong>State</strong> <strong>Machine</strong> <strong>Code</strong> > Reverse <strong>Code</strong>... from the main menu .<br />
12-10<br />
Figure 12.27 - Select Reverse <strong>Code</strong>...<br />
2. The Reverse <strong>State</strong> <strong>Machine</strong> <strong>Code</strong> dialog box is displayed. Select the Class and <strong>State</strong> <strong>Diagram</strong>.<br />
Figure 12.28 - Reverse <strong>State</strong> <strong>Machine</strong> <strong>Code</strong><br />
dialog box<br />
3. Configure the input file path by typing in the text box or select ... .Select OK to confirm.<br />
Figure 12.29 - Configure the input file path<br />
4. The progress of reversal is shown. You can select to Close Dialog when finished progress by checking the check box.<br />
Figure 12.30- Progress of reversing
SDE-VS User’s Guide (Part 1) Chapter 12 – <strong>State</strong> <strong>Machine</strong> <strong>Diagram</strong> <strong>Code</strong> <strong>Generation</strong><br />
5. The state machine code is now reversed.<br />
Figure 12.31 - <strong>State</strong> machine code is reversed<br />
12-11
SDE-VS User’s Guide (Part 1) Chapter 12 – <strong>State</strong> <strong>Machine</strong> <strong>Diagram</strong> <strong>Code</strong> <strong>Generation</strong><br />
12-12