Book a Demo

Author Topic: Generating Code From a State Machine  (Read 2812 times)

dcomer

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Generating Code From a State Machine
« on: September 23, 2010, 02:22:58 am »
I'm attempting to generate code from a state machine per the help topic, "SW Code Generation - State Machine Diagrams". Unfortunaley I am having no success. I wonder if someone that has done this can help.

So far, and at first I thought it odd, that as the help mentions "To be able to generate code from behavioral models, all behavioral constructs should be contained within a Class". So, I drew the same state machine shown in the help in a class and attempted to generate code - no joy. So I thought, perhaps each state should be in a class and the classes connected? To me, it makes more sense to have both the state machine and classes defined and then when the code generation is invoked, EA would put the two together but this also does not seem to be the case.

So, I wonder if anyone has put that help topic to task and may have an axample project they can send or give me advise on how to procceed. I have a project that I've attempted but there appears to be now way to post a zip file directly to the form.

Thanks,

Dave

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Generating Code From a State Machine
« Reply #1 on: September 23, 2010, 03:08:55 pm »
Dave,

I think the state machine should be owned by the class, and the states should be owned by the state machine.

I'm not sure, but I think the code generation based on state machines is pretty basic in EA.

Have you checked out AMUSE? I haven't used it myself, but it looks promising.

Geert

philchudley

  • EA User
  • **
  • Posts: 750
  • Karma: +22/-0
  • EA Consultant / Trainer - Sparx Europe
    • View Profile
Re: Generating Code From a State Machine
« Reply #2 on: September 23, 2010, 09:00:29 pm »
Following on from Geert's reference to AMUSE, I have used the product quite a lot, and yes it is useful not only for validating state machines but also for generating C# code

You can even reference your own .NET dlls

Suggest your trial it and see

Cheers
Phil
Models are great!
Correct models are even greater!

philchudley

  • EA User
  • **
  • Posts: 750
  • Karma: +22/-0
  • EA Consultant / Trainer - Sparx Europe
    • View Profile
Re: Generating Code From a State Machine
« Reply #3 on: September 23, 2010, 09:02:06 pm »
Sorry missed a point. Geert is absolutely correct in stating that for code generation, a state machine must be a direct child of the class. (Right-click the class in the Project Browser and choose Add)

Cheers
Phil
Models are great!
Correct models are even greater!

dcomer

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Generating Code From a State Machine
« Reply #4 on: September 23, 2010, 10:28:04 pm »
Thanks Phil and Geert for your reference to AMUSE. Also, thanks phil for the suggestion. Never dawned on me to make the state machine a direct child and I will see if this works. AMUSE does sound good. I' ll have a look.

My key concern is state machine design with very clean forward and reverse engineering that is as seamless as possible with MS Visual Studio (My company is MS centric in PC applications). SPARX EA is reasonably priced, and seems to pay attention to the MS world. VS2010 has vastly improved UML modeling capabilities but the cost is very high. You must have VS2010 ultimate (~$11k MSDN retail). I've always like the SPARX approach and really hope the developers take note that this tool needs more emphasis on state machine design. The manual is minimal in this regard and there should be a complete example with the topic. That said, I will add a request to the SPARX formally, but in the mean time, see how far I can get with your help.

Dave
« Last Edit: September 23, 2010, 10:28:37 pm by dcomer »