State Icon Properties

From Flowcode Help
Revision as of 09:07, 4 April 2023 by MartinW (talk | contribs)
Jump to navigationJump to search

State Icon

A State Diagram consists of several state icons interconnected with transitions. Like a transition, a state icon has a display name (i.e. the text displayed on the state within the diagram) and an optional function.


The function is code that is executed when the program flow enters (or remains in) that state icon.

This can be to call a macro, perform a calculation, delay program execution or execute some custom C code.


States will perform their optional function when program flow enters that state through a transition from another state.


States usually have one or more exit transitions: arrows that flow out of the state icon with optional conditions that must be true for program execution to ‘flow’ along that Transition.

These exit Transitions are evaluated in turn until one is found to be true. The evaluation order of these transitions can be set by clicking “Set transition order” or by reconnecting the start end of the transition to the state.


A state without an exit transition will force program execution to remain in that state until the program is stopped by the user.


Each state diagram must contain a single “Entry State” icon which contains the code to be executed when the program enters that macro.

Only one transition can exit this entry state and neither this transition nor the entry state can be deleted from the state diagram.


An Exit State is a special type of state icon that is used to leave the macro and return to the macro that called this macro.


During simulation or when using ICD, the state will be drawn with a thick orange outline when it is executing and when its exit transitions are being evaluated.

First, the state function, if it exists, will be executed.

Next, the transitions will be evaluated and the first one with a true condition is drawn in orange with other transitions (even if they are true) drawn in blue.

The program will then execute this first true transition.

If all transitions leaving the state are false, then they will all be shown as blue and the state with be executed again.

Exit State Icon

To leave a state diagram macro and return to the calling macro, the program flow must enter an exit state icon.

Exit states can perform an optional function (macro call, calculation, delay or execute C code) before the macro is exited.


These work in a similar way to normal state icons, but they cannot have transitions exiting from them – i.e. all transitions that connect to them must be connected with the arrow end of the transition.


In addition, an exit state can optionally return a value if it is within a state diagram macros that has a return type. This can be a literal value or the value of a variable or expression.

Transition

Transitions are lines that connect two states in a state diagram.

These lines have an arrow at one end signifying the direction of program flow through the transition.


Like a state, transitions have a display name (i.e. the text displayed on the state within the diagram) and an optional function (macro call, calculation, delay or execute C code) which is executed when the program flow traverses the transition.


In addition, transitions have a condition which is an expression that evaluates to true (non-zero) or false (zero).

The condition is used during program execution to determine if the program flow should proceed along that transition.

When a state has performed its own optional function, each transition leaving that state has its condition tested in turn to see which path the program flow should continue along.


Transitions have an optional label which can display the name of the transition, its condition, or its function.

Setting the colour of a transition sets the colour of its label.

The colour of the transition line and arrow cannot be altered.


The entry state icon includes a special transition leaving it which should point to the first state to be executed in the state diagram (after the entry state itself).

This transition is always connected to the enter state and cannot be deleted.

Also, it has no properties and so cannot have a label or code.

It is always executed as if its transition condition is true.


During program execution (simulation or ICD), the colour of the transition line changes to blue or orange when its condition is being evaluated – blue signifies the condition is false and the transition will be ignored, and orange signifies that the transition is true and the program flow with execute along this transition.

When the transition is executing, it changes to a thick orange line.

Transition Order

In a state diagram, if a state has multiple transitions leaving it then these need to be evaluated in a set order to ensure program execution is expected and repeatable.

For example, if two transitions leave a state both evaluate to “true”, we need to ensure one of the transitions has priority over the other.


When a state with multiple exit transitions is selected, the order of transition evaluation is displayed, where “1” shows the first transition to be evaluated.

This transition order is also shown if a transition is selected. A state with only one transition leaving it will not show the transition order.

State_Icon1.png

The order can be set on the diagram itself by reconnecting the transitions to the state (the last transition to be connected will have the lowest priority).

Alternatively, the transitions can be reordered by editing the properties of the state icon and clicking “Set transition order” to open the Transition Order dialog.


When using the Transition Order dialog, the applicable transitions are listed using either their name, condition or function.

Highlighting a transition and pressing the up/down arrows will move it higher/lower in the transition order.

The transition at the top of the list will be evaluated first. When transitions are evaluated, the evaluation process stops once a transition has evaluated to true.

All other transitions leaving the state are assumed to be false even if they have not been evaluated yet.