Streamspace FSM CAD Usage

Multiple spaces(views) are supported. I’d recommend putting events in one space and create one spaces per FSM. Events are linked using strings, not referencing id’s, so you need to be careful not to enter duplicate event names. Events are always found using a global search.


A few notes on the user interface

Colors are assigned using layers (the rightmost button in the PolylineDemo picture below)

Doubleclick on items to edit properties such as layer

Rightclick in the space selection list to create more spaces (white area with PolylineCMD and Events spaces below)


The polyline sample

Adding complex commands can turn into a real headache without proper separation of code responsibility. Using a state machine approach allowed me to create a polyline command that consist of small nifty functions. The command is available using the command “pline”.



Event definitions

Consider a hypothetical line drawing command:



In order to allow a single AssignFirstPoint function, we somehow need to reduce the MouseMove and MouseClick events to it’s common denominator. This is done by creating “complex” events:




State definitions

Define a name, then click OK and select a point to place the state balloon.




Event Handler definitions

Define a name, then click OK and select a point to place the state balloon.



Note: overloading functions and using complex events will not produce desired results.


Code Generation

The default class name is taken from the space name. State entry functions are named using one out of three prefix options. There is an option to create empty state entry options: select it to for example define on_enter_stopped below as:


   void on_enter_stopped()  {}



Revisiting the taperecorder sample, these are the final inputs required to generate the following code:


class player : public state_machine<player>



   player()  {}


   typedef player self_t;


   // state entry functions

   void on_enter_stopped();

   void on_enter_playing();

   void on_enter_paused();


   // state definitions

   typedef state<0, &self_t::on_enter_stopped> stopped;

   typedef state<1, &self_t::on_enter_playing> playing;

   typedef state<2, &self_t::on_enter_paused> paused;


   // event declarations

   struct pause_event;

   struct play_event;

   struct stop_event;


   // event transition functions

   void do_pause(const pause_event &event);

   void do_play(const play_event &event);

   void do_resume(const play_event &event);

   void do_stop(const stop_event &event);


   // state transition table

   friend class state_machine<player>;

   typedef mpl::list<

        transition<stopped, play_event, playing, &player::do_play>

      , transition<playing, pause_event, paused, &player::do_pause>

      , transition<playing, stop_event, stopped, &player::do_stop>

      , transition<paused, play_event, playing, &player::do_resume>

      , transition<paused, stop_event, stopped, &player::do_stop>

   >::type transition_table;


   typedef stopped initial_state;



I hope that you enjoy StreamSpace FSM CAD!


Henrik Vallgren