Stateflow User's Guide Previous page   Next Page

Explicit Order Mode

Implicit ordering rules are complex and hard to master. Additionally, when you modify a diagram for cosmetic purposes, rearranging transitions may inadvertently change execution. This is why you have an option to switch from implicit ordering of transitions to a user-defined, or explicit, ordering. In this mode, you control the order in which transitions are tested for execution.

To control the order of transitions, you have to perform the following steps:

  1. Switching to Explicit Order Mode
  2. Changing the Transition Order

When you switch to explicit transition ordering, Stateflow stops evaluating the implicit rules. All the existing transitions in a diagram retain their current order numbers until you explicitly change them. All the newly created transitions for a source are automatically numbered in the order you create them, starting with the next available number for the source.

You can change the order of outgoing transitions for a source by explicitly renumbering them. When you change a transition number, Stateflow automatically renumbers the other outgoing transitions for the source by preserving their relative order. This is similar to taking a book out of a stack and then putting it back in a different place: the order of the other books is unchanged, and the books are renumbered accordingly. This behavior is consistent with the automatic renumbering rules for the Simulink ports.

For example, if you have a source with five outgoing transitions, as shown below, changing transition 4 to 2 results in the following automatic renumbering.

Automatic Renumbering of Transitions During Explicit Reordering

Switching to Explicit Order Mode

You switch to explicit ordering of transitions by setting your chart property preferences.

  1. In the Stateflow diagram editor, from the File menu, select Chart Properties.
  1. The properties dialog for the chart appears, as shown:

  1. Select the User specified transition execution order check box.
  2. Click OK to apply the change and close the dialog.

Now you can change the transition execution order for any source in the chart.

Switching between modes.   If you switch back to implicit order mode after having explicitly reordered the transitions, the transition order is reset to follow the implicit rules.

Similarly, if you eventually change back to explicit order mode, without making any changes to the diagram, Stateflow restores the previous explicit transition order. Whenever you switch from one transition ordering mode to another, Stateflow displays the warnings about the changes in transition numbers in the diagnostic viewer.

Changing the Transition Order

You change the order of transitions originating from a source by explicitly renumbering them.

  1. Right-click a transition and select Execution Order.

  1. A context menu of available transition numbers appears, with a checkmark next to the current number for this transition. For example, if there are five transitions originating from a source, and you are modifying the execution order for transition 4, the context menu will contain numbers from 1 to 5, with a checkmark next to number 4, as shown in the following illustration.

  1. Select the new transition number. Stateflow automatically renumbers the other transitions for the source by preserving the relative transition order, as shown in the illustration Automatic Renumbering of Transitions During Explicit Reordering.
  2. Repeat this procedure to renumber the other transitions as necessary.

Another way to access the transition order number is through its properties:

  1. Right-click a transition and select Properties. The properties dialog for the transition appears.
  2. Click in the Execution order box. A drop-down list of valid transition numbers appears, as shown in the following illustration.

  3. Select the new transition number and click Apply. If the explicit order mode is enabled, Stateflow assigns the new number to the current transition and automatically renumbers the other transitions. If Stateflow is in the implicit order mode, an error dialog is displayed and the old number is retained.

Previous page  Implicit Order Mode Entering, Executing, and Exiting a State Next page

© 1994-2005 The MathWorks, Inc.