UML2c Plug-in

The UML2c Plug-in generates C source code and Google C++ Mocking Framework (Google Mock) from Astah's UML Class models.


How to install Plug-in

  1. Download the UML2C Plug-in from here and unzip the file.
  2. Copy "uml2c-x.x.x.jar" and the "uml2c" folder to userhome/.astah/professional or community/plugins.
    astah_UML2C_plugin
  3. Launch Astah. If you find [UML2C plugin] menu under the [Tool] menu, that means the installation has completed successfully.
    UML2C plugin menu

About template files

  • All files with a .vm file extension are template files that are required to generate code and need to be stored in the path below.
    • Windows: %USERPROFILE%\.astah\professional or community\plugins\uml2c\header.vm
    • Mac and Linux: $HOME/.astah/professional or community/plugins/uml2c/header.vm

  • Encoding of template files needs to be in UTF-8.



How to use plugin

  1. Open a class diagram and select a class you want to generate code for. (Click here for sample output.)
  2. Go to [Tool] - [UML2C plugin] - [Generate C skeleton code] or [Generate GoogleMock code].
  3. Astah UML2C Plug-in menu
  4. Specify the output directory.
  5. Astah UML2C plugin
  6. A complete dialog appears when source code is generated successfully. Astah UML2C plugin

Sample code

  • This is a sample diagram in "uml2c-plugin-sample.asta" included in the .zip file.
  • Astah Sample Class Diagram

    Single Instance Module

  • Classes with <<SingleInstance >> stereotype will be exported as single instance module.

  • Astah Sample Class Diagram
    Foo.c
    #include "Foo.h"
    
    
    static EnumSample enumSample[ /* TODO */ ];
    static Bar bar;
    static Abstract *abstracts[ /* TODO */ ];
    static Concrete concretes[ /* TODO */ ];
    
    
    void Foo_Create(void)
    {
    	/* TODO */
    }
    
    void Foo_Destroy(void)
    {
    	/* TODO */
    }
    
    uint32_t Foo_Operation(const char *arg)
    {
    	/* TODO */
    }
    		
    Foo.h
    #ifndef _FOO_H_
    #define _FOO_H_
    #ifdef __cplusplus
    extern "C" {	/* } */
    #endif
    
    
    void Foo_Create(void);
    void Foo_Destroy(void);
    uint32_t Foo_Operation(const char *arg);
    
    
    #ifdef __cplusplus
    }
    #endif
    #endif	/* _FOO_H_ */
    		

    Multi Instance Modules

  • Standard classes will be exported as multi instance modules.

  • Astah Sample Class Diagram
    Bar.c
    #include "Bar.h"
    
    
    void Bar_Create(Bar self, uint64_t id, const char *name)
    {
    	/* TODO */
    }
    
    void Bar_Destroy(Bar self)
    {
    	/* TODO */
    }
    
    uint16_t Bar_Operation(Bar self)
    {
    	/* TODO */
    }
     
    Bar.h
    #ifndef _BAR_H_
    #define _BAR_H_
    #ifdef __cplusplus
    extern "C" {	/* } */
    #endif
    
    typedef struct BarStruct *Bar;
    
    
    void Bar_Create(Bar self, uint64_t id, const char *name);
    void Bar_Destroy(Bar self);
    uint16_t Bar_Operation(Bar self);
    
    #include "BarPrivate.h"
    
    #ifdef __cplusplus
    }
    #endif
    #endif	/* _BAR_H_ */
    
    BarPrivate.h
    #ifndef _BAR_PRIVATE_H_
    #define _BAR_PRIVATE_H_
    #ifdef __cplusplus
    extern "C" {	/* } */
    #endif
    
    
    struct BarStruct {
    	uint64_t id;
    	char *name;
    };
    
    
    #ifdef __cplusplus
    }
    #endif
    #endif	/* _BAR_PRIVATE_H_ */
    


    Per-type dynamic interface (Super Class)

  • Abstract Classes will be exported as per-type dynamic interface.
  • Astah Sample Class Diagram
    Abstract.c
    #include "Abstract.h"
    
    void Abstract_Destroy(Abstract self)
    {
    	/* TODO */
    }
    
    uint8_t Abstract_Operation(Abstract self)
    {
    	/* TODO */
    }
    
    Abstract.h
    		#ifndef _ABSTRACT_H_
    #define _ABSTRACT_H_
    #ifdef __cplusplus
    extern "C" {	/* } */
    #endif
    
    typedef struct AbstractStruct *Abstract;
    
    
    void Abstract_Destroy(Abstract self);
    uint8_t Abstract_Operation(Abstract self);
    
    #include "AbstractPrivate.h"
    
    #ifdef __cplusplus
    }
    #endif
    #endif	/* _ABSTRACT_H_ */
    
    AbstractPrivate.h
    #ifndef _ABSTRACT_PRIVATE_H_
    #define _ABSTRACT_PRIVATE_H_
    #ifdef __cplusplus
    extern "C" {	/* } */
    #endif
    
    
    typedef struct AbstractInterfaceStruct *AbstractInterface;
    
    
    struct AbstractStruct {
    	AbstractInterface vtable;
    	uint64_t id;
    	char *type;
    };
    
    
    typedef struct AbstractInterfaceStruct {
    	void (*Destroy)(Abstract self);
    	uint8_t (*Operation)(Abstract self);
    };
    
    
    #ifdef __cplusplus
    }
    #endif
    #endif	/* _ABSTRACT_PRIVATE_H_ */
    


    This Plug-in works with Astah Professional and Community