Create a statechart programmatically

68 views
Skip to first unread message

Smadar Szekely

unread,
Sep 14, 2020, 7:46:35 AM9/14/20
to YAKINDU User
Hello,

What is the best way to create a statechart programmatically, preferably in Java?
Can I update an sct file "on the fly" while playing it in the simulator?

Thanks!

andreas

unread,
Sep 14, 2020, 10:25:09 AM9/14/20
to yakind...@googlegroups.com
Hi Smadar,

yes there is a Java API generated with the Eclipse Modeling Framework that you can use to create a statechart programmatically.
Add a dependency to org.yakindu.sct.model.sgraph in your plugin and you can create Models like this:

public class StatechartBuilder {

public static void main(String[] args) {
Statechart statechart = SGraphFactory.eINSTANCE.createStatechart();
Region main = SGraphFactory.eINSTANCE.createRegion();
statechart.getRegions().add(main);
Entry entry = SGraphFactory.eINSTANCE.createEntry();
entry.setKind(EntryKind.INITIAL);
State stateA = SGraphFactory.eINSTANCE.createState();
stateA.setName("A");
Transition transition1 = SGraphFactory.eINSTANCE.createTransition();
transition1.setSource(entry);
transition1.setTarget(stateA);
State stateB = SGraphFactory.eINSTANCE.createState();
stateB.setName("B");
Transition aToB = SGraphFactory.eINSTANCE.createTransition();
aToB.setSpecification("after 10 s");
aToB.setSource(stateA);
aToB.setTarget(stateB);
}
}

2: If a semantic change is detected, the simulator asks if you want to restart or terminate the simulation.
This could be improved in the way hot code replacement works in your IDE, but it is not implemented yet. 

Best,
Andreas



--
You received this message because you are subscribed to the Google Groups "YAKINDU User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to yakindu-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/yakindu-user/d7a11362-80c3-4f86-84cd-927acb1d9206o%40googlegroups.com.


--
Mit freundlichen Grüßen,

            Andreas Mülder

Smadar Szekely

unread,
Sep 15, 2020, 3:11:08 AM9/15/20
to YAKINDU User
Thanks Andreas, 

This is a great help!

Is there a user guide for this API? For example:
1. In your code below - shouldn't the states be contained in the region?
2. API for loading from / saving to a file?

Best,
Smadar

Paul Boutot

unread,
Sep 22, 2022, 2:23:43 PM9/22/22
to YAKINDU User
Hi,

Just wondering if you were able to programmatically create the statechart? I am looking into doing the same thing in my project.

Regards,
Paul

Reply all
Reply to author
Forward
0 new messages