m2t (Model to Text) Plug-in

Code generation Plug-in for UML Class diagrams and Statemachine diagrams.
Generate code for any language you want, sample templates for C++(GR-SAKURA) are included.


How to Install

  1. Download the Plug-in file by clicking the blue Download button at the top of this page.
  2. After the download is complete, drag the downloaded .jar file to an open instance of Astah. A pop-up will appear asking you to confirm installation choose [Yes].
  3. If the pop-up below opens, restart Astah.
    astah plugin menu
    The [Plugin] menu exists in Astah version 7.2 or later. If you are using v7.1 or earlier, read this FAQ.
  4. Launch Astah. If you find the [m2t] under the [Tools], that means the installation has completed successfully!
    m2t plugin
  5. After you installed this plug-in, the folders below are created automatically and the sample template or .astah files are saved in there.

    m2t plugin

How to Use

  1. Go to [Tools] - [m2t] - [Settings] to change the settings.
    (If you'd like to see the sample code with pre-installed template files, click here.) m2t plugin

    1. TemplatesCreate a set of configurations to generate the code. [Add] creates a new configuration and [Remove] will delete one.
    2. Template DirSpecify the directory where template files are installed. To create plural sets of configurations, create a folder to hold them in the directory below.
    - Windows: C:/Users/{username}/.astah/plugins/m2t/templates/
    - Mac: UserHome/.astah/plugins/m2t/templates/
    3. Destination PathSpecify the directory where you want to source code files to be exporeted to.
    4. Template Mappingap the template files. There are three categories to set the template files to.


    This sets how to export classes that do not have stereotypes. Specify file extension and template file.Code will be exported in {Class name}.{File Extension}.


    General setting. Specify file name and template file. Code will be exported with {File name}.


    Output setting for classes with specific stereotypes. Specify the stereotype, file extension and template file. Code will be exported in {Class name}.{File Extension}.
    Ref.How to create template files
  2. Open the file you want to generate the source code of, then go to [Tools] - [m2t] - [Generate].
    m2t plugin
  3. "Code Generation is complete" message appears when it completes successfully.
    m2t plugin

Try m2t plugin with sample files

  1. Open LED-Camp3Sample.asta in ~/.astah/plugins/m2t/
    This .asta file has a Class diagram and StateMachine diagram. Also the "Controller" class has a statemachine diagram nested to it.
    m2t plugin
    m2t plugin
  2. Go to [Tools] - [mt2] - [Generate].
  3. "Code Generation is Complete" dialog appears when it completes. The source code should be exported to the default destination which is the user directory.

Sample source code of Controller.cpp

#include "Controller.h"
	create2 = iRobotCreate2::getInstance();
	timer = Timer::getInstance();
	create2->safeMode();	// initial entry action
	create2->drive(0,0);	// initial entry action

void Controller::transition(Event event){
	case Controller::Wait:
		if((create2->getSensor()->bumpsWheeldrops&1) && ChangeBumperRight==event){
			controller_state = Controller::Forward;
			create2->drive(100,0);	// entry action
			create2->setNextDistance(200);	// entry action
	case Controller::Forward:
			controller_state = Controller::Turn;
			create2->drive(100,-1);	// entry action
			create2->setNextAngle(-180);	// entry action
	case Controller::Turn:
			controller_state = Controller::Wait;
			create2->safeMode();	// entry action
			create2->drive(0,0);	// entry action