code-generationstate-machinemagic-draw

Is it possible to generate complete C/C++/Java code from a State machine in Magic Draw?


I want to generate code from my state machine in Magic Draw. Magic Draw supports code generation for classes but does not include an option for state machine. I tried using SinelaboreRT software. However, it generates limited code. We need to manually add 'Main' function and other functions defined inside states. I wanted to know if it is possible to generate an executable or a C/C++/Java code file with all the code mentioned inside states as well a 'Main' function?


Solution

  • Yes, there are three main options that I am aware of 1) make your own code generator, 2) buy a commercial code generator e.g. LieberLieber provides what appears to be a fairly sophisticated one, or 3) use one of the open source code generators such as Papyrus-RT.

    The first option isn't actually that difficult depending on your target language and framework. For my work at MITRE, I have written a generator to take properly formed Magicdraw models and create deploy-able Spring microservices. I used the Spring state machine library to simplify the STM code generation.