I have 2 statecharts, one being the parent and the other being the child. When the parent statechart is created, it also creates a child statechart using
import: "Child.ysc"
var child: Child
The parent statechart can easily raise an event in the child statechart, for example:
raise child.goToD
But the problem is that there's no way to reference the same parent in the child statechart to be able to raise an event in the parent. Is there a way to send events to parent statecharts? Or can the child send a reference of itself as an attribute to the parent (for example using this in python) which can then save it in a variable to be accessed for sending those events?
PS: both statecharts have the default domain and not the C/C++ domain
There are basically two approaches.
The first approach is to define an explicit reference from the child statechart to the parent. Like you did for the parent.
import: "Parent.ysc"
var parent : Parent
Please be aware that you have to set the relation explicitly in your C++ code:
child.setParent(&parent);
The second approach is to use out events. The child can define out events like:
interface:
out event dReached
Raise it somewhere in the child statechart:
raise dReached
and use the event as a trigger in the parent:
child.dReached / doSomething()
The generated parent code will care about subscribing and listening to out events emitted by the child.
Mostly I would prefer the second approach. It does not imply bidirectional dependencies between parent and child.