2

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?

hkdhanesha
  • 25
  • 5

2 Answers2

1

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.

Randall Hudson
  • 196
  • 1
  • 7
1

I personally found most convenient way to create state machine from models is UML or any other DSL is the combination of

Eclipse Papyrus / Eclipse XText / Eclipse XTend

there is also new kind in the block, if you don't want to work Eclipse based

Langium

but they are suffering at the moment little bit from being new but I will advice you check them every 6 months, they seem promising.

If you want to see how is it done, I have several blogs about it.

UML Based:

Akka Finite State Machine Generation Blog2 Papyrus and Spring State Machine

DSL Based:

XText and Spring State Machine

posthumecaver
  • 1,584
  • 4
  • 16
  • 29