Statediagram: C++ code generation issue

Hello all,

when I generate code from a state diagram in C++, activities in states and transitions are automatically related to the class the state diagram belongs to.

For example the activity doSomething(); gets ctxt.doSomething(); in the C++ code.

When I define a guard for a transition, it is just taken literally into the code. So I have to write ctxt.testCondition() in the diagram to get functioning code.

Kind regards from Germany

Stephan

Hi Stephen,

Thanks for your post. Would you mind sending your project file for investigation? Thanks in advance!

Best regards,
Lilian Wong

Hi Lilian,

I just built a small demo project for you to show what I mean.

Kind regards

Stephan

Hi Stephen,

Thanks for replying. I cannot fin any demo project in this post nor my email. Would you mind to attach your demo project (or send it to lilian@visual-paradigm.com )? Thanks in advance!

Best regards,
Lilian Wong

HI Stephen,

Thanks for sending the project file and generated code to my email address. But I can find the code in your code file “TestClass_sm.cpp” (please refer to attached image).

Best regards,
Lilian Wong

guard.png

Hello Lilian,

that’s what I tried to explain: the activity is called as ctxt.doSomething(), but the guard is called without the ctxt in front. Since there is no method isConditionTrue() in the TestClassFSM the compiler refuses to compile this code.

The only way around this seems to be to write ctxt.isConditionTrue() in the model, which introduces implementation details from the state machine compiler into the model.

Kind regards

Stephan Hoffmann

Hi Stephan Hoffmann,

Thanks for replying and I’m sorry for my misunderstanding. I’ve forwarded the issue to our engineers to follow-up. If there is any feedback, I’ll come back to you immediately.

Best regards,
Lilian Wong

Hi Stephan Hoffmann,

Despite it usually starts with ctxt, but it’s not necessary. If we generate ctxt, users cannot remove it from the code. Please add validate code if you need.

Best regards,
Lilian Wong