m2t (Model to Text) Plug-in

Code generation Plug-in for UML Class diagram and Statemachine diagram in any language you want. Sample templates for C++(GR-SAKURA) are included.

Our 'm2t (Model to Text)' Plug-in enables you to generate the Source code of UML Class diagram and StateMachine diagram by using Groovy SimpleTemplateEngine.

How to install m2t

  1. Download the m2t (Model to Text) Plug-in (.jar file) from here.
  2. Run Astah and go to [Help] - [Plugin List] menu and click [Install] button.
    anycode plugin
  3. Select the .jar file and restart Astah.
    anycode plugin
  4. You will find the [m2t] menu has been added under the [Tool] menu.
    image 2
  5. After you installed this plug-in, the folders below are created automatically and the sample template or .astah files are saved in there.
  6. - Windows: C:/Users/{username}/.astah/plugins/m2t/
    - Mac: UserHome/.astah/plugins/m2t/
    image 2

How to use m2t

  1. Go to [Tool] - [m2t] - [Settings] to change the settings.
  2. (If you'd like to see the sample code with pre-installed template files, click here.)
    image 2
    • Templates:
    • Create a set of configurations to generate the code. [Add] creates a new configuration and [Remove] will delete one.

    • Template Dir:
    • Specify 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/

    • Destination Path:
    • Specify the directory where you want to source code files to be exporeted to.

    • Template Mapping:
    • Map the template files. There are three categories to set the template files to. (How to create template files)

      - Default: 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}.

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

      - Stereotype: Output setting for classes with specific stereotypes. Specify the stereotype, file extension and
                           template file. Code will be exported in {Class name}.{File Extension}.

  3. Open the file you want to generate the source code of, then go to [Tool] - [m2t] - [Generate].
  4. image 2
  5. "Code Generation is complete" message appears when it completes successfully.
  6. image 2

Try m2t plugin with sample files

  1. Open LED-Camp3Sample.asta in ~/.astah/plugins/m2t/
  2. This .asta file has a Class diagram and StateMachine diagram. Also the "Controller" class has a statemachine diagram nested to it.
    image 2image 2
  3. Go to [Tool] - [mt2] - [Generate].
  4. "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

This Plug-in works with Astah Professional and Community