Sometimes in hierarchical state machines you need to transition out of a composite state, but later you wish to come back to the most-recent active substate of this composite state. In UML, this coming back to the most-recent substate is accomplished by the transition to history feature. Actually, the UML specification distinguishes between two types of "transition to history":
H
) is a shorthand notation that represents the most recent active direct substate of its containing state. A transition coming into the shallow-history vertex (called a transition to history) is equivalent to a transition coming into the most recently active direct substate of a state.H*
) is similar to shallow-history except it represents the most recent leaf-substate of the composite state.QM™ supports directly the "transition to history" feature for all QP Framework types (qpc and qpcpp) as well as both QHsm-style state machines and QMsm-style state machines. Also, starting from version 4.0.0, QM supports both the deep history transition type denoted as a circled letter (H+)
and the shallow history transition type denoted as a circled letter (H)
.
In most UML tools, the process of drawing a "transition to history" consists of first adding a history pseudostate (a circle with the letter H
) and then attaching to it a transition to indicate the default substate, before the composite state has ever been visited.
In QM™, however, this process is simplified, because the State Machine Toolbox contains a ready-to-use History Segment tool, which combines a "history pseudostate" with a transition to the "default substate" permanently attached to it.
You select the History Segment tool by clicking on the button the State Machine Toolbox. At this point, when you hover the mouse over the active state diagram, the mouse pointer changes to the history transition tool. To add a history transition, move the mouse to the edge of the desired composite state and press and hold down the left mouse button. At this point the mouse pointer changes to the history transition with the "forbidden" icon (). Next, you need to drag the mouse to an edge of the desired substate of the composite state. (If you release the mouse button without reaching any substate edge, the QM™ tool will delete the transition.) When you drag the mouse pointer over a state edge, the mouse pointer changes to the history transition with an anchor (), which indicates that you can anchor the end of the history transition connector at this edge. To anchor the history transition, release the mouse button.
History Segment can also be added to a Submachine Diagram in a similar way as it can be added to a composite state.
As you keep working on your state diagram, some history transition(s) might easily become invalid. For example, after resizing of a state the target substate of a history transition might fall outside of the state shape, such that it no longer is a substate of the composite state. Such invalid history transitions are shown with dashed line.
Once a composite state has a History Transition at its edge, it can become a target of regular state transitions. All such transitions will then lead to the history of the composite state. There is no limit on the number of such incoming transitions.
To attach a transition to a given history connector, select the desired transition and hover your mouse over its end (this can be either a regular transition , or an internal transition ). Once the mouse pointer changes to a hand, you can drag the transition end to the history connector. When you are over the history connector, the cursor changes into a circle with letter 'H' in it. At this point you release the left mouse button to "drop" the transition end on the history connector. As mentioned above, you can attach multiple transition ends to a given history connector.
To disconnect a given transition from a history connector, you first select this transition by clicking on one of its segments. Then, you hover the mouse cursor over the history connector, until it changes into a circle with letter 'H' in it. You can then drag this transition end to a desired new location, which might be an edge to the new target state, or away from any state edge, at which point it becomes an internal transition (see also transition type).
The History Transition item has a simple Property Sheet that currently does not contain any configurable parameters.
The Transition to History property sheet contains the following properties:
The target property is not editable directly, but rather it is determined geometrically by the end-point of the transition to history. The target property determines the value of the history before the composite state has been visited.
The Is shallow property specifies the type of the transition to history. When the checkbox is unchecked, the history transition is to deep history, which is indicated by the circled (H+)
. When the checkbox is checked, the history transition is to shallow history, which is indicated by the circled (H)
.