Sparx Systems Forum
Enterprise Architect => General Board => Topic started by: dsanghavi 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,
-
I assume that there are not many people in this forum doing such things. However you will see if you get feedback.
-
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.
-
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)
-
Hi willberger,
I do example as your guideline, it is OK with C# but C is not.
Please give me your idea.
Thank you.
-
Behavioural Code generation is not supported in C language.
-
Hi Nizam,
I cannot find any information on EA website about this. I need confirmation information, could you please give me references?
Thank you.
-
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
-
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.