ClasHStamP: Draw One, Generate Natives Everywhere


Sample Project Download

The sample project is included in the tool so that if you download the tool at the below link:


unzip to any directory, you can see the sample in this folder \samples\TypicalNotations


You need to have Change-Vision’s Astah Professional or Astah UML to use this tool. Refer to Download page to find where and how to aqquire any of them.

Right now, this tool is supported by Windows only, so a Windows PC with Astah Pro/UML runnable is eligible to go to next step.

Because the tool is Java App so that it can be run in Linux/MacOS without any technical problem. The only remain thing is that I have not created proper Shell files for those.

Environment Preparation

You need to specify the directory of your Astah Application for the tool. To do this, open the file samples\TypicalNotations\StartHere.bat and modify the following line:

set ASTAH_HOME=C:\Program Files\astah-professional

Understand the Sample Diagrams

Concept Design

The sample diagram is based on Mr. Shima blog, a cooperator of Astah, which includes almost all notations of UML Statemachine Diagram.

Implementation Design

Right now, this tool has some limitations as following:

so that to implement the above notations, you have to do some minor change like below (with ➊~➍denoted) without modifying the original semantics:

Or much easier for comparison with this animation:

You also can view this diagram in the downloaded project by open \samples\TypicalNotations\Design.asta and browse to path Design/Model/ContextImpl/MainStm

One more thing to be noted that the class driven by state-machine must be derived from a class called Context. This base class name can be changed to anything you want but I will instruct in other documentation.

Generate Source Code

First of all, in the downloaded folder, double click at \samples\TypicalNotations\StartHere.bat to open command line console. After that, if you want C# source code, type run_CSharp.bat and press Enter/Return, there will be some outputs like these:

If there are any error here, please place comment below so I can instruct how to deal with it.

Now, the generated source code will appear in sub-folders like here (in the red frame):

The state-machine code is in ContextImpl.cs file, you can see that it has many switch/case syntax groups to implement state and event decisions. The hierarchical entry/exit implementation shares the same idea with Dmitry Babitsky’s Article on C/C++ Users Journal, so you can refer to that link to understand how it works.

You can do the same thing for other programming languages by using ‘run_*.bat’ respectively.

Execute the Sample

I have included a Visual Studio solution in the download file at \samples\samples.sln but I don’t recommend you to use it, because there might be many of incompatible problems. Instead, you can test the code using any of online IDEs. For me, I am prefer using I have already created some projects for this sample as below, so you can run it right after now.

Test for C# language

Below is an embedded window of project for generated C# source code. You can click on the 📄 icon at left pane to browse the generated directories and files. Click Here for more details about file management including how upload files and folders.

Optional: You can upload the your generated source code files by drag samples\TypicalNotations\CSharp\Interfaces and samples\TypicalNotations\CSharp\Model and drop into the above folder pane.

Click on the Run Button to test the project. You can see the below prompt (note that the state S1 has been entered):

Enter event number('q': quit, 'r':restart): E_

Refer to the Statemachine diagram and enter a number from 0 to 5 to see the transition of the machine, for example, if 1 is input, state transition log will be as below

Enter event number('q': quit, 'r':restart): E_

Meaning that the machine has exited S1 and after that, entered S2 and its default S3 sequentially.

Repeat with other event if you want to traverse all the machine.

Test for Java

Java environment is almose the same as CSharp:

Test for C++

C++ environment is almose the same as CSharp. A little bit different that it has a and files at the root, if you want to create the same environment yourself, you need to copy two files to your folder, and make the executable with $chmod +x command. Refer to this link for more details.

Test for C language

C environment is almose the same as C++:

The C language’ OOP paradigm is based on Shigeo Hanai’s Modern C Language Programming, so you can refer to this book for more details.

Use any IDE to edit operations’ content

One more thing that makes this tool can come along with all phases (not only the starting/design phase) of long-term project is that, it can parse to not overwrite the user code when re-generated code (so called round-trip engineering). It means that it can be used for implement change design or refactoring phases. To do this, implement the code inside the generated method/operation’s frame like this CSharp’s ContextImpl.cs code:

        public override void virtualFunc(
            int param0
            Console.WriteLine("Hi, How are you");
            Console.WriteLine("One more line");                
            Console.WriteLine("Add more your code here");                
        } /* Context.virtualFunc */

Close the Design.asta (this is MANDATORY), and try to regenerate by run_CSharp.bat, you can see that this code will not be lost in the result.


OK, now I think you have understood about the basic of this tool, please refer to other tab for more information about it. Please place some comments if you have any questions. Thank you!

Share this on → Twitter Facebook Google+