Create an Event-B project using the ‘folder’ button at the top of the Event-B Explorer view.
Create a machine inside the project using the file button at the top of the Event-B Explorer view.
Right click on the UML-B container and use the Add Statemachine context menu item to add a state-machine. Give the state-machine a name in the pop up dialog.
A state-machine will appear in the contents of the UML-B in the Event-B Explorer view. Double click on it to open the diagram.
To draw a state click on the tool in the palette, (let go,) and then click on the canvas where you want to place the item. First draw an initial and then draw a state. States are given default names. Change the name of the state by selecting it and typing in the properties fields below the diagram.
To draw a transition, select the transition tool in the palette, click on the starting node (do not let go) and then drag to the target node and let go. (When drawing transitions, it is sufficient to click the mouse anywhere in the start/end node. It is not necessary to click on the boundaries). You can not name transitions. They have a label that is automatically constructed from the name of the event(s) that they ‘elaborate’ (as described in the next step).
To link a transition to an existing event, select the transition, and then click on the ‘Link Event’ button in the properties view. Select an event from the list in the pop-up dialog and click OK. In our example, the only event in the machine is the INITIALISATION event. (We refer to this linking as ‘elaborates’).
The transition is automatically labelled with the elaborated event INITIALISATION.
Add another state and a transition starting from the previous state. Select the transition but this time use the Create & Link button. Give a name for the event and click ok.
Note that this is a convenience to save you having to edit the machine to add an event. As soon as the diagram is saved, the event will appear in the machine even though the diagram has not been translated into Event-B.
With the diagram selected (as focus), click the UML-B translate toolbar button (orange gears) to generate the Event-B for the diagram into the machine. The corresponding Event-B should appear in the machine.
An alternative translation is available which is sometimes more elegant. To change the translation, select the diagram canvas and then change the Translation property from ‘Variables’ to ‘Enumeration’. Save the diagram and then re-generate the Event-B. A context is automatically generated to define the Statemachine states as an enumeration and the generated Event-B in the machine changes accordingly.