Book a Demo

Author Topic: Generate Code from Interaction and Activity diagrams  (Read 7981 times)

dsanghavi

  • EA Novice
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Generate Code from Interaction and Activity diagrams
« on: January 26, 2018, 02:53:19 am »
I've been trying to generate C code from Interaction and Activity diagrams, however the generated C and header file turn out empty.
I was able to generate code from a State machine following the inbuilt Example project.
 
The help available on EA website is very unclear.

My Interaction diagram is within a class.

https://www.sparxsystems.com/enterprise_architect_user_guide/9.3/standard_uml_models/interaction.html

Am I missing any steps?

There is a statement in this link which states that  Sequence diagram and all its associated messages and interaction fragments to be encapsulated within an Interaction element.
What is this interaction element and how do I use it (where should it be placed? Within the class that contains the sequence diagram or outside the class but inside the package?)

If there are any tutorial videos on Code generation through Interaction and Activity diagrams, kindly let me know.

Thanks,

PeterHeintz

  • EA Practitioner
  • ***
  • Posts: 1001
  • Karma: +59/-18
    • View Profile
Re: Generate Code from Interaction and Activity diagrams
« Reply #1 on: January 26, 2018, 02:57:01 am »
I assume that there are not many people in this forum doing such things. However you will see if you get feedback.
Best regards,

Peter Heintz

willberger

  • EA Novice
  • *
  • Posts: 2
  • Karma: +1/-0
    • View Profile
Re: Generate Code from Interaction and Activity diagrams
« Reply #2 on: April 21, 2018, 04:58:40 am »
Yeah the documentation for this is completely absent.  I finally figured this out.  Here are the steps.

1. Go select a class.
2. Right Click Choose "Add/Interaction/With Sequence Diagram"

This will create a Interaction (Sequence) Diagram for you.

a. Be aware the Interaction is represented as a method/operation in your class.  Click on properties and you can set its name and arguments.

3. Now go back to your class and drag it onto the Interaction.
4. When the Dialog asks you to Drop As:  Choose Not Link, but LifeLine from the option window

Now hit generate code and you will see the (Interaction(Sequence) diagram) in your code.


Nizam

  • Prolab Moderator
  • EA User
  • *
  • Posts: 320
  • Karma: +15/-2
  • Model Sharing - Simplified
    • View Profile
    • Professional Model Collaboration
Re: Generate Code from Interaction and Activity diagrams
« Reply #3 on: April 23, 2018, 08:31:26 am »
Additional info (FWIW)
You can associate the interaction element as the behavior of an operation in which the logic in the interaction diagram is generated as the body of the linked operation (use the behavior tab)

you also have to use 'Replace Code' (Synchronize will not work with behavioral code generation)

tupham

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Generate Code from Interaction and Activity diagrams
« Reply #4 on: April 24, 2018, 01:34:32 pm »
Hi willberger,

I do example as your guideline, it is OK with C# but C is not.

Please give me your idea.

Thank you.

Nizam

  • Prolab Moderator
  • EA User
  • *
  • Posts: 320
  • Karma: +15/-2
  • Model Sharing - Simplified
    • View Profile
    • Professional Model Collaboration
Re: Generate Code from Interaction and Activity diagrams
« Reply #5 on: April 24, 2018, 01:59:36 pm »
Behavioural Code generation is not supported in C language.

tupham

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Generate Code from Interaction and Activity diagrams
« Reply #6 on: April 24, 2018, 02:28:41 pm »
Hi Nizam,
I cannot find any information on EA website about this. I need confirmation information, could you please give me references?
Thank you.

Nizam

  • Prolab Moderator
  • EA User
  • *
  • Posts: 320
  • Karma: +15/-2
  • Model Sharing - Simplified
    • View Profile
    • Professional Model Collaboration
Re: Generate Code from Interaction and Activity diagrams
« Reply #7 on: April 24, 2018, 02:35:08 pm »
Sorry I stand corrected, it works if you enable the Object Oriented Support
Recent help says
•For C(OO), on the 'C Specifications' page of the 'Preferences' dialog set the 'Object Oriented Support' option to True

http://www.sparxsystems.com/enterprise_architect_user_guide/13.0/model_domains/code_generation_from_behaviora.html

tupham

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
    • View Profile
Re: Generate Code from Interaction and Activity diagrams
« Reply #8 on: April 26, 2018, 01:14:14 pm »
Thank you,

More issue, I try generate code C from sequence. It cannot generate reference from another class and display warning as below:

/*Warning: Context reference not set for behavior invocation*/

This is entire code that is generated:
void ClassA_main(ClassA* this)
{
   /*behavior is a Interaction*/
   /*Warning: Context reference not set for behavior invocation*/
   /*Warning: Context reference not set for behavior invocation*/
   if (a>0)
   {
      /*Warning: Context reference not set for behavior invocation*/
   }
   else
   {
      /*Warning: Context reference not set for behavior invocation*/
   }

As above code, I would like when if (a>0) then invoke operation from ClassB. I cannot get this.
Please help me. Thank you.