appkit  1.5.1
RoadNarrows Robotics Application Kit
rnr::StateWin Class Reference

#include <StateWin.h>

Inheritance diagram for rnr::StateWin:
rnr::State rnr::StateWinCamera

Public Member Functions

 StateWin (int nStateId, SessionWin &session, const std::string &strStateName="", const std::string &strRefTag="")
 Initialization constructor. More...
 
 StateWin (int nStateId, SessionWin &session, const std::string &strStateName, const std::string &strRefTag, StateEvent *listStateEvents[])
 List constructor. More...
 
virtual ~StateWin ()
 Destructor.
 
virtual int receiveEvent ()
 Receive next window event. More...
 
virtual void actionEnterState (int nPrevStateId, int nEventId)
 Execute "enter state" action. More...
 
virtual void actionExitState (int nNextStateId, int nEventId)
 Execute "exit state" action. More...
 
virtual void setButtonStates ()
 Set button states. More...
 
SessionWinsession ()
 Get the embedding window session. More...
 
void enableMouseEvents (bool bEnable)
 Enable/disable mouse events. More...
 
void enableKbEvents (bool bEnable)
 Enable/disable keyboard events. More...
 
- Public Member Functions inherited from rnr::State
 State (int nStateId, const std::string &strStateName="", const std::string &strRefTag="")
 Initialization constructor. More...
 
 State (int nStateId, const std::string &strStateName, const std::string &strRefTag, StateEvent *listStateEvents[])
 List constructor. More...
 
virtual ~State ()
 Destructor.
 
int addStateEvents (StateEvent *pStateEvent,...)
 Add a list of state events to this state. More...
 
void addStateEvent (StateEvent *pStateEvent)
 Add state to this state. More...
 
bool deleteStateEvent (int nEventId)
 Delete state event from this state. More...
 
uint_t setTimeOut (uint_t usecTimeOut)
 Set recieve event time out. More...
 
uint_t getTimeOut ()
 Get recieve event time out. More...
 
virtual void queueNextEvent (int nEventId)
 Queue the next event to be "recieved". More...
 
virtual int dispatchEvent (int nPrevStateId, int nEventId)
 Dispatch received event by executing associated action and transitioning to the next state. More...
 
virtual int actionDefault (int nPrevStateId, int nEventId)
 Execute 'default' action. More...
 
int getStateId () const
 Get state id. More...
 
std::string getStateName () const
 Get state name. More...
 
std::string getRefTag () const
 Get state reference tag. More...
 
std::string getEventName (int nEventId)
 Get state event name. More...
 
std::string getActionName (int nEventId)
 Get state action name. More...
 
virtual void printState (FILE *fp=stdout, int indent=0)
 Print out state. More...
 
 State (Session &session, int nInitAction=UIActionNone)
 
virtual int getNextAction (Session &session, int nTimeoutMs)
 
virtual int setNextAction (int nAction)
 Set the next input action to process. More...
 
int getCurAction ()
 Get the currently retrieved input action. More...
 
bool hasFatal ()
 Test if state has fatal condition. More...
 
void setFatal ()
 
bool isModified ()
 
void setModifiedState (bool bModified)
 
void maskHardButton (bool bEnDis)
 Enable/disable masking of hard button input. More...
 
virtual bool isHardButtonPushed (Session &session)
 
virtual void prompt (Session &session)
 Prompt user, given the state. More...
 
virtual void setMenuStates (Session &session)
 
virtual void transQuit (Session &session)
 
virtual void transPrev (Session &session)
 

Protected Member Functions

virtual void initOnceGuiInterface ()
 One-time initialization of the window gui interface. More...
 
virtual void initOnceButtons ()
 One-time button menu initialization. More...
 
virtual void buildGuiInterface ()
 Build the window gui interface. More...
 
virtual void showGuiInterface ()
 Show the window gui interface. More...
 
virtual void destroyGuiInterface ()
 Destroy the window gui interface. More...
 
- Protected Member Functions inherited from rnr::State
void init (int nStateId, const std::string &strStateName="", const std::string &strRefTag="")
 Initialize data. More...
 
virtual std::string getReservedStateName (int nStateId)
 Get the reserved state name. More...
 
virtual void buildInterface (Session &session)
 
virtual void destroyInterface ()
 
virtual void initButtonMenu ()
 

Protected Attributes

SessionWinm_session
 state id
 
bool m_bOneTimeInit
 state's one-time initializaion
 
bool m_bMouseEvents
 enable/disable mouse events
 
bool m_bKbEvents
 enable/disable keyboard events
 
WinButtonMenum_pButtons
 button menu
 
WinCvMouse m_mouse
 mouse
 
- Protected Attributes inherited from rnr::State
int m_nStateId
 state id
 
std::string m_strStateName
 state name
 
std::string m_strRefTag
 state tag (short id string)
 
TransTblMap_T m_mapTransTbl
 state transition table
 
int m_nQueuedEventId
 queue state event
 
bool m_bHasQueuedEvent
 [no] queued state event
 
uint_t m_usecTimeOut
 receive event time out (useconds)
 
Window * m_pWin
 bound window
 
Menu * m_pMenu
 button menu
 
int m_nInitAction
 initial state input action
 
int m_nCurAction
 current state input action
 
bool m_bFatal
 fatal error
 
bool m_bModified
 state [not] modified
 
bool m_bHardBttnEnable
 enable/disable hard button input
 

Friends

class StateEvent
 friend
 

Additional Inherited Members

- Public Types inherited from rnr::State
typedef std::map< int, StateEvent * > TransTblMap_T
 transition table type
 
- Static Public Attributes inherited from rnr::State
static const int StateIdUndef = 0
 undefined state
 
static const int StateIdStart = 1
 start state
 
static const int StateIdPrev = 2
 the previous state
 
static const int StateIdThis = 3
 the current (this) state
 
static const int StateIdTerminate = 4
 terminate state
 
static const int StateIdNumOf = 5
 number of reserved state id's
 

Detailed Description

State base class.

Definition at line 84 of file StateWin.h.

Constructor & Destructor Documentation

rnr::StateWin::StateWin ( int  nStateId,
SessionWin session,
const std::string &  strStateName = "",
const std::string &  strRefTag = "" 
)
inline

Initialization constructor.

Parameters
nStateIdState id. Must be state machine unique.
sessionState's embedding in (derived) window session.
strStateNameState name.
strRefTagState reference id.

Definition at line 95 of file StateWin.h.

References m_bKbEvents, m_bMouseEvents, m_bOneTimeInit, and m_pButtons.

98  :
99  State(nStateId, strStateName, strRefTag),
101  {
102  m_bOneTimeInit = false;
103  m_bMouseEvents = true;
104  m_bKbEvents = false;
105  m_pButtons = NULL;
106  }
WinButtonMenu * m_pButtons
button menu
Definition: StateWin.h:213
bool m_bMouseEvents
enable/disable mouse events
Definition: StateWin.h:211
SessionWin & m_session
state id
Definition: StateWin.h:209
State(int nStateId, const std::string &strStateName="", const std::string &strRefTag="")
Initialization constructor.
Definition: State.h:180
bool m_bOneTimeInit
state&#39;s one-time initializaion
Definition: StateWin.h:210
bool m_bKbEvents
enable/disable keyboard events
Definition: StateWin.h:212
SessionWin & session()
Get the embedding window session.
Definition: StateWin.h:183
rnr::StateWin::StateWin ( int  nStateId,
SessionWin session,
const std::string &  strStateName,
const std::string &  strRefTag,
StateEvent listStateEvents[] 
)
inline

List constructor.

Parameters
nStateIdState id. Must be state machine unique.
sessionState's embedding in (derived) window session.
strStateNameState name.
strRefTagState reference id.
listStateEventsDeclaration list of allocated state events. NULL terminated.

Definition at line 118 of file StateWin.h.

References m_bKbEvents, m_bMouseEvents, m_bOneTimeInit, and m_pButtons.

122  :
123  State(nStateId, strStateName, strRefTag, listStateEvents),
125  {
126  m_bOneTimeInit = false;
127  m_bMouseEvents = true;
128  m_bKbEvents = false;
129  m_pButtons = NULL;
130  }
WinButtonMenu * m_pButtons
button menu
Definition: StateWin.h:213
bool m_bMouseEvents
enable/disable mouse events
Definition: StateWin.h:211
SessionWin & m_session
state id
Definition: StateWin.h:209
State(int nStateId, const std::string &strStateName="", const std::string &strRefTag="")
Initialization constructor.
Definition: State.h:180
bool m_bOneTimeInit
state&#39;s one-time initializaion
Definition: StateWin.h:210
bool m_bKbEvents
enable/disable keyboard events
Definition: StateWin.h:212
SessionWin & session()
Get the embedding window session.
Definition: StateWin.h:183

Member Function Documentation

void StateWin::actionEnterState ( int  nPrevStateId,
int  nEventId 
)
virtual

Execute "enter state" action.

Parameters
nPrevStateIdPrevious state id.
nEventIdReceived event id.

Reimplemented from rnr::State.

Definition at line 115 of file StateWin.cxx.

Referenced by ~StateWin().

116 {
117  if( !m_bOneTimeInit )
118  {
120  }
121 
122  // build (create) interface
124 
125  // bind menu to window
127 
128  // page identifier
130 
131  // enable/disable/toggle menu button states
132  setButtonStates();
133 
134  // set local state context in session
135  m_session.setContext(this);
136 
137  // show interface
139 }
Win & win()
Get the session window object.
Definition: SessionWin.h:167
virtual void initOnceGuiInterface()
One-time initialization of the window gui interface.
Definition: StateWin.h:227
Win * getWin()
Get the session window object.
Definition: SessionWin.h:157
WinButtonMenu * m_pButtons
button menu
Definition: StateWin.h:213
std::string m_strRefTag
state tag (short id string)
Definition: State.h:391
SessionWin & m_session
state id
Definition: StateWin.h:209
virtual void setButtonStates()
Set button states.
Definition: StateWin.h:174
void setContext(void *pContext)
Set state relevant context.
Definition: Session.h:141
bool m_bOneTimeInit
state&#39;s one-time initializaion
Definition: StateWin.h:210
virtual void buildGuiInterface()
Build the window gui interface.
Definition: StateWin.h:251
virtual void showPageRef(int nPageRef)=0
Show page reference number.
virtual void showGuiInterface()
Show the window gui interface.
Definition: StateWin.h:261
virtual void bind(Win *pWin)
Bind the button menu to the given window.
Definition: WinMenu.cxx:167
void StateWin::actionExitState ( int  nNextStateId,
int  nEventId 
)
virtual

Execute "exit state" action.

Parameters
nNextStateIdNext state id.
nEventIdReceived event id.

Reimplemented from rnr::State.

Definition at line 141 of file StateWin.cxx.

Referenced by ~StateWin().

142 {
143  m_pButtons->unbind();
144 
145  m_session.win().showPageRef("");
146 
148 }
Win & win()
Get the session window object.
Definition: SessionWin.h:167
WinButtonMenu * m_pButtons
button menu
Definition: StateWin.h:213
SessionWin & m_session
state id
Definition: StateWin.h:209
virtual void destroyGuiInterface()
Destroy the window gui interface.
Definition: StateWin.h:272
virtual void unbind()
Unbind the menu from the currently bound window.
Definition: WinMenu.cxx:218
virtual void showPageRef(int nPageRef)=0
Show page reference number.
virtual void rnr::StateWin::buildGuiInterface ( )
inlineprotectedvirtual

Build the window gui interface.

This function is called on the "enter state" action.

Reimplemented in rnr::StateWinCamera.

Definition at line 251 of file StateWin.h.

252  {
253  // create new widgets here
254  }
virtual void rnr::StateWin::destroyGuiInterface ( )
inlineprotectedvirtual

Destroy the window gui interface.

This function is called on the "exit state" action.

Definition at line 272 of file StateWin.h.

References rnr::Win::eraseWorkspace(), and rnr::SessionWin::win().

273  {
274  // remove all widgets from workspace
276  }
Win & win()
Get the session window object.
Definition: SessionWin.h:167
SessionWin & m_session
state id
Definition: StateWin.h:209
virtual void eraseWorkspace()=0
Remove all widgets contained in the window&#39;s workspace container.
void rnr::StateWin::enableKbEvents ( bool  bEnable)
inline

Enable/disable keyboard events.

Parameters
bEnableEnable (true) or disable (false) state.

Definition at line 203 of file StateWin.h.

References m_bKbEvents.

204  {
205  m_bKbEvents = bEnable;
206  }
bool m_bKbEvents
enable/disable keyboard events
Definition: StateWin.h:212
void rnr::StateWin::enableMouseEvents ( bool  bEnable)
inline

Enable/disable mouse events.

Parameters
bEnableEnable (true) or disable (false) state.

Definition at line 193 of file StateWin.h.

References m_bMouseEvents.

194  {
195  m_bMouseEvents = bEnable;
196  }
bool m_bMouseEvents
enable/disable mouse events
Definition: StateWin.h:211
virtual void rnr::StateWin::initOnceButtons ( )
inlineprotectedvirtual

One-time button menu initialization.

This function is called on the "enter state" action.

Reimplemented in rnr::StateWinCamera.

Definition at line 241 of file StateWin.h.

Referenced by initOnceGuiInterface().

242  {
243  // initialize button here
244  }
virtual void rnr::StateWin::initOnceGuiInterface ( )
inlineprotectedvirtual

One-time initialization of the window gui interface.

This function is called on the "enter state" action. Another option, is to do these one-time initialization during object construction. However, derived class objects would call the base classes one-time initialization unnecessarily. So, lazy initialization is used to make use of C++ inheritence.

Definition at line 227 of file StateWin.h.

References initOnceButtons().

228  {
229  if( !m_bOneTimeInit )
230  {
231  initOnceButtons();
232  m_bOneTimeInit = true;
233  }
234  }
virtual void initOnceButtons()
One-time button menu initialization.
Definition: StateWin.h:241
bool m_bOneTimeInit
state&#39;s one-time initializaion
Definition: StateWin.h:210
int StateWin::receiveEvent ( )
virtual

Receive next window event.

The receive event may set state internal variables used specifically by the state.

Returns
Returns event id.

Reimplemented from rnr::State.

Definition at line 78 of file StateWin.cxx.

References rnr::UIEventNone.

Referenced by ~StateWin().

79 {
80  int nEventId;
81 
82  // wait
83  nEventId = m_session.win().waitKey(m_usecTimeOut / 1000);
84 
85  // keyboard event
86  if( m_bKbEvents && (nEventId >= 0) )
87  {
88  return nEventId;
89  }
90 
91  // button menu event
92  else if( (m_pButtons != NULL) &&
93  ((nEventId = m_pButtons->getCurrentEvent()) != UIEventNone) )
94  {
96  return nEventId;
97  }
98 
99  // mouse event
100  else if( m_bMouseEvents )
101  {
102  nEventId = m_mouse.getCurrentEvent();
104  }
105 
106  // no event
107  else
108  {
109  nEventId = UIEventNone;
110  }
111 
112  return nEventId;
113 }
Win & win()
Get the session window object.
Definition: SessionWin.h:167
virtual int waitKey(int delay)=0
Wait for keypress or timeout.
WinButtonMenu * m_pButtons
button menu
Definition: StateWin.h:213
bool m_bMouseEvents
enable/disable mouse events
Definition: StateWin.h:211
int getCurrentEvent()
Get the current button menu event.
Definition: WinMenu.h:390
SessionWin & m_session
state id
Definition: StateWin.h:209
no action
Definition: Win.h:115
bool m_bKbEvents
enable/disable keyboard events
Definition: StateWin.h:212
int setCurrentEvent(int nNewEvent)
Set the current button menu event.
Definition: WinMenu.h:402
uint_t m_usecTimeOut
receive event time out (useconds)
Definition: State.h:395
int getCurrentEvent()
Get the current mouse event.
Definition: WinCvMouse.h:114
void setCurrentEvent(int nEvent)
Set the current mouse event.
Definition: WinCvMouse.h:124
WinCvMouse m_mouse
mouse
Definition: StateWin.h:214
SessionWin& rnr::StateWin::session ( )
inline

Get the embedding window session.

Returns
SessionWin (derived) object reference.

Definition at line 183 of file StateWin.h.

References m_session.

184  {
185  return m_session;
186  }
SessionWin & m_session
state id
Definition: StateWin.h:209
virtual void rnr::StateWin::setButtonStates ( )
inlinevirtual

Set button states.

State and/or session data determine the state of the buttons.

Reimplemented in rnr::StateWinCamera.

Definition at line 174 of file StateWin.h.

175  {
176  }
virtual void rnr::StateWin::showGuiInterface ( )
inlineprotectedvirtual

Show the window gui interface.

This function is called on the "enter state" action.

Definition at line 261 of file StateWin.h.

References rnr::Win::showWorkspace(), and rnr::SessionWin::win().

262  {
263  // show all gui widgets in workspace.
265  }
Win & win()
Get the session window object.
Definition: SessionWin.h:167
SessionWin & m_session
state id
Definition: StateWin.h:209
virtual void showWorkspace()=0
Show/refresh all gui widgets in workspace.

The documentation for this class was generated from the following files: