Example statechart editor with EuGENia

Here’s an example of what can be done with Emfatic and EuGENia. The following annotated Ecore metamodel can be used to create a nice Statechart graphical editor.

Here’s the emfatic source:


@namespace(
 uri="http://www.cs.toronto.edu",
 prefix="statechart")

package statechart;

@gmf.diagram(model.extension="sm", diagram.extension="smd")
class StateMachine{
 val State[*] states;
 val Transition[*] transitions;
}

abstract class State {
 ref NormalState[0..1]#submachine parentState;
}

@gmf.node(label="name", label.icon="false", figure="rounded", border.color="0,0,0")
class NormalState extends State{
 attr String[1] name;
 @gmf.compartment(collapsible="true")
 val State[*]#parentState submachine;
}

@gmf.node(label="name", label.icon="false", figure="ellipse", color="0,0,0", border.color="0,0,0", size="1,1")
class InitialState extends State{
 attr String[1] name="start";
}
@gmf.node(label="name", label.icon="false", figure="rectangle", color="0,0,0", border.color="0,0,0", size="1,1")
class FinalState extends State{
 attr String[1] name="end";
}

@gmf.link(label="name", source="start", target="end", target.decoration="arrow", color="0,0,0")
class Transition{
 attr String[1] name;
 ref State[1] start;
 ref State[1] end;
}

The diagram of the resulting Ecore model is (click to enlarge):

Statechart Metamodel

And once EuGENia has done its magic (instructions here), the resulting editor looks like this (again, click to enlarge):

Screenshot

Moreover, we can add EVL constraints to the metamodel and validate the resulting models according to them. This is a fairly simple example, but it goes a long way to demonstrate how easy it is to create things like this.

Comments

14 comments on “Example statechart editor with EuGENia”
  1. Dimitris Kolovos says:

    Cool! Thanks for sharing this!

  2. Mansooreh says:

    hi there,
    thanks for sharing it. I am working on a project which we need the meta model of StateChart . we have defined one by our own but the problem is we can not make sure all statechart models conform to it. I need a correct metamodel in the format of .ecore. can you help me?

    1. plagal says:

      Of course you cannot create a metamodel to which all possible variations of statecharts will conform! It’s the other way around 🙂

      In my opinion, you need to decide which particular type or types of statecharts you wish to support and take it from there.

      By the way, you might want to check out the metamodel of the UML statecharts, which is a fairly standard form of statecharts. You can find an ecore file here: http://www.emn.fr/z-info/atlanmod/index.php/Ecore#Statecharts_1.0 (In that page, also do a search for “state” you’ll find other metamodels too)

  3. Dear Michalis,
    thanks for your nice example. Have you continued this project? For example, have you added support for concurrency (statechart OR regions within the compound nodes)?

    Regards,
    Pieter

    1. plagal says:

      Hello Pieter,

      I’m not sure what you mean. Are you referring to BPMN-like “swim lanes”?

      But no, I haven’t expanded this metamodel. I’m sure you could easily hack it, though! 🙂

      Best regards,

  4. Pieter Van Gorp says:

    Hi again,
    > Are you referring to BPMN-like “swim lanes”?
    Not really, the AND/OR nodes are more the equivalent to forks/joins (AND splits/joins). For more details, please see http://is.ieis.tue.nl/staff/pvgorp/research/#pn2hsc

    I have been playing some hours with Eugenia and I must say I like the added value to plain GMF but I still find the steps listed under “Running EuGENia” / “Re-running EuGENia” (http://www.eclipse.org/gmt/epsilon/doc/articles/eugenia-gmf-tutorial/) quite tedious. Since in the end, I am only adding info in the EMFattic file, I wonder why I am not just pressing one butting that does all the model derivation, compilation, synchronization, etc.

    Perhaps the workflow has already been improved in a newer version of EuGENia? Please let me know if I am missing some simple usability tricks. Besides that, it seems that some internal details are sometimes left behind: I had extended the EMFattic file, removed all the rest, went through the complete workflow, found some bugs, rolled back to the EMFattic file that you posted here, cleaned all .java files and derived models, went through the workflow again, and then still got error related to the bugs that I had introduced in the extended (but in the meanwhile removed) EMFattic file. I may return to EuGENia later but I think it can use some more testing for now.

    Looking forward to updates,
    Pieter

  5. Pieter Van Gorp says:

    Hi once more, after posting the following, I figured that most probably you had concrete syntax in mind while I was thinking of semantics:
    >> Are you referring to BPMN-like “swim lanes”?
    > Not really, the AND/OR nodes are more the equivalent to forks/joins (AND
    > splits/joins). For more details, please see
    > http://is.ieis.tue.nl/staff/pvgorp/research/#pn2hsc
    So, to revisit your question: indeed the OR regions have some syntactic similarity to swimlanes. See http://wwwhome.cs.utwente.nl/~tcm/usersguide/usersguideimg205.gif for example. What I tried today, was to replace your NormalNodes by ORnodes. I also added an ANDnode concept and updated all associations accordingly. For the EuGENia/GMF part, I decided to simply give the OR node a “dash” style (although strictly speaking only in between OR nodes you need a dashed line I didn’t bother too much). Then again, as reported above, I somehow did not manage to compile/run the end result due to some obscure error for which I did not know where to look first.

    I think a “clean all” and “build all” function in the Eugenia tab for Ecore models would help a lot already.

    Cheers,
    P

  6. Ricardo says:

    Hello!
    Nice article!

    I have a question.
    How do you model in your metamodel that a state chart (or sub state chart) have to have one and only one starting state? (same for ending state).
    I can’t imagine that in your metamodel.

    Thanks a lot.

    1. plagal says:

      Hi Ricardo,

      I *think* that ecore does not support singleton EClasses. A quick googling brings up this thread. I haven’t looked at this deeply, so I might be wrong.

      I’m sure though that you could specify that with OCL on top of the metamodel.

      I hope I’m helping!

      1. Ricardo says:

        Thanks!

        I meant: Why there is no a relationship one-to-one between InitialState and StateMachine? In the same way, why there is no a one-to-many (at least one) between FinalState and StateMachine?

        Thanks a lot.

  7. misrinconesoscuros says:

    Hey,

    I have one question: Is there anyway to get the EuGENia code from an Ecore Diagram? I’ve been looking for an option but I haven’t found anything (yet!)

    Thanks!

    1. plagal says:

      I’d say that all you need to do is to add to the diagram the “@gmf” annotations as comments. I hope that works 🙂

Leave a comment