QM  4.4.0
Working with Statecharts

Adding a Statechart

In the Model Explorer right-click on the Class to which you want to add the state machine and select Add State Machine from the popup menu.

blinky_sm_add.gif
Adding a State Machine to a Class
Note
The Add State Machine menu option is only available if a given class directly or indirectly inherits the QP class QHsm. Otherwise the option is "grayed-out".

Resizing a State Machine Diagram

As shown in the screen shot below, you can easily resize the Drawing Canvas of a State Diagram by dragging its right or bottom edges, or by dragging the resize handle in the bottom-right corner of the canvas. In each case the mouse cursor indicates the possible direction of resizing.

bm_diagram-canvas.gif
Resizing the Drawing Canvas

Statechart Property Sheet

Statechart item can be configured by the Statechart-Specific Property Sheet.

sm_statechart_prop.png
Statechart Property Sheet

The statechart-item property sheet contains the following properties:

QS_FUN_DICT

Checkbox that turns on/off the automatic generation of the QS_FUN_DICTIONARY() macros for all states of a given statechart. The dictionary macros are generated in the top-most initial transition of the statechart. Below is an example of generated code with the QS_FUN_DICTIONARY() macros:

/*${SMs::Calc::SM} .........................................................*/
static QState Calc_initial(Calc * const me, QEvt const * const e) {
static struct {
QMState const *target;
QActionHandler act[3];
} const tatbl_ = { /* tran-action table */
&Calc_on_s, /* target state */
{
Q_ACTION_CAST(&Calc_on_e), /* entry */
Q_ACTION_CAST(&Calc_on_i), /* initial tran. */
Q_ACTION_CAST(0) /* zero terminator */
}
};
/*${SMs::Calc::SM::initial} */
BSP_clear();
(void)e; /* unused parameter */
me->his_operand1 = &Calc_operand_neg_s;
me->his_operand2 = &Calc_operand_neg_s;
/* state history attributes */
me->his_test = &Calc_state1_s;
QS_FUN_DICTIONARY(&Calc_on);
QS_FUN_DICTIONARY(&Calc_ready);
QS_FUN_DICTIONARY(&Calc_result);
QS_FUN_DICTIONARY(&Calc_begin);
QS_FUN_DICTIONARY(&Calc_operand1);
QS_FUN_DICTIONARY(&Calc_opEntered);
QS_FUN_DICTIONARY(&Calc_error);
QS_FUN_DICTIONARY(&Calc_operand2);
QS_FUN_DICTIONARY(&Calc_test);
QS_FUN_DICTIONARY(&Calc_state1);
QS_FUN_DICTIONARY(&Calc_final);
QS_FUN_DICTIONARY(&Calc_operand_zero);
QS_FUN_DICTIONARY(&Calc_operand_intgr);
QS_FUN_DICTIONARY(&Calc_operand_frac);
QS_FUN_DICTIONARY(&Calc_operand_neg);
return QM_TRAN_INIT(&tatbl_);
}

Next: Working with States