Create a Fork Transition Using StaMa Visio Shapes |
Explains how to extend a standard transition with additional transition targets to create a fork transition in a StaMa Visio Shapes state diagram.
Fork transitions are transitions that target multiple states within different sub-regions of a composite state like Figure 1.
Fork transitions are composed of the same shapes as two ended transitions and have two or more transition segment shapes that address the target states.
The steps for creating a fork transition are similar to the steps for the two ended transitions in Create a Plain Transition and Control Its Generated Code.
The following description assumes a simple state as the source state and a composite state with two sub-regions containing the target states. A description how to create a composite state with multiple sub-regions can be found in Add a Second, Orthogonal Region to a Composite State.
In the Document Stencil locate the Transition Knot shape and drag it over the border of the intended source state in the state diagram.
Drag the line end of the transition knot over the source state border until a small red rectangle appears on the source state. Drop the transition knot shape.
Properties of the transition like the signal event, a guard condition, a transition action, the priority and a human readable identifier can be set as described in Create a Plain Transition and Control Its Generated Code.
In the Document Stencil locate the Transition Segment shape and drag it over the border of the intended target state in the state diagram.
Drag the line end of the transition segment with the arrow over the target state border until a small red rectangle appears on the source state. Drop the transition segment shape.
When the transition segment is selected, it has a small yellow diamond at its dangling end. Drag the small yellow diamond over the center of the transition knot box until a small red rectangle appears.
Drop (release the mouse button) to connect the dangling line end with the transition knot.
The transition segment may target nested states with any depth.
Repeat the above steps for the second target state.
The diagram should now look as in Figure 5.
An arbitrary number of target states can be added this way. Consistency of the resulting state configuration will be checked at runtime of the generated state machine.
Depending on the order of adding the transition knot and the transition segment they now have an unwanted graphical z-order which causes the transition segment to cross the transition knot box. By lifting the transition knot to the topmost graphical z-order, the transition knot box will cover the transition segment which looks much better.
Open the context menu of the transition knot by right-clicking with the mouse on its line, not on the box. The context menu appears (and the two yellow diamonds).
In the context menu select Bring to front. The part of the transition segment line that crosses the transition knot box disappears.
The diagram should now look as in Figure 1.
The transition knot position, the transition knot connection line routing and transition segment line routing may be adapted as described in Create a Plain Transition and Control Its Generated Code. In order to further arrange the state diagram, the source or target state or the yellow diamond in the center of the transition knot box can be dragged and will not disconnect the transition.
Add a Code Generator shape as described in Generate Code for Enumerations of States, Signal Events and Actions to the diagram.
Generate the code into the target file e.g. by pressing Ctrl+G. Check that the transition has properly been generated, the target file should now contain a piece of code similar to following:
t.Region(SimpleState, false); t.State(CompositeState, null, null); t.Region(StateInSubRegionA, false); t.State(StateInSubRegionA, null, null); t.EndState(); t.EndRegion(); t.Region(StateInSubRegionB, false); t.State(StateInSubRegionB, null, null); t.EndState(); t.EndRegion(); t.EndState(); t.State(SimpleState, null, null); t.Transition(Transi11, new string[] {StateInSubRegionA, StateInSubRegionB}, Event, null, null); t.EndState(); t.EndRegion();