1 // DasherInterfaceBase.h
3 // Copyright (c) 2002 Iain Murray
5 #ifndef __DasherInterfaceBase_h__
6 #define __DasherInterfaceBase_h__
8 // TODO - there is a list of things to be configurable in my notes
9 // Check that everything that is not self-contained within the GUI is covered.
11 #include "../Common/NoClones.h"
12 #include "../Common/ModuleSettings.h"
13 #include "Alphabet/Alphabet.h"
14 #include "Alphabet/AlphIO.h"
16 #include "ModuleManager.h"
17 #include "ActionButton.h"
19 #include "AutoSpeedControl.h"
21 #include "InputFilter.h"
32 class Dasher::CDasherScreen
;
33 class Dasher::CDasherView
;
34 class Dasher::CDasherInput
;
35 class Dasher::CDasherModel
;
36 class Dasher::CEventHandler
;
41 class CNodeCreationManager
;
47 class CDasherInterfaceBase
;
49 /// The central class in the core of Dasher. Ties together the rest of
50 /// the platform independent stuff and provides a single interface for
53 class Dasher::CDasherInterfaceBase
:private NoClones
56 CDasherInterfaceBase();
57 virtual ~ CDasherInterfaceBase();
60 /// Allocate resources, create alphabets etc. This is a separate
61 /// routine to the constructor to give us a chance to set up
62 /// parameters before things are created.
67 /// @name Access to internal member classes
68 /// Access various classes contained within the interface. These
69 /// should be considered dangerous and use minimised. Eventually to
70 /// be replaced by properly encapsulated equivalents.
74 /// Return a pointer to the current EventHandler (the one
75 /// which the CSettingsStore is using to notify parameter
79 virtual CEventHandler
*GetEventHandler() {
80 return m_pEventHandler
;
84 /// \deprecated In situ alphabet editing is no longer supported
85 /// \todo Document this
88 const CAlphIO::AlphInfo
& GetInfo(const std::string
& AlphID
);
90 /// \todo Document this
92 void SetInfo(const CAlphIO::AlphInfo
& NewInfo
);
94 /// \todo Document this
96 void DeleteAlphabet(const std::string
& AlphID
);
98 /// Get a pointer to the current alphabet object
100 CAlphabet
*GetAlphabet() {
104 /// Gets a pointer to the object doing user logging
106 CUserLogBase
* GetUserLogPtr();
111 /// @name Parameter manipulation
112 /// Members for manipulating the parameters of the core Dasher object.
118 /// Set a boolean parameter.
119 /// \param iParameter The parameter to set.
120 /// \param bValue The new value.
123 void SetBoolParameter(int iParameter
, bool bValue
);
126 /// Set a long integer parameter.
127 /// \param iParameter The parameter to set.
128 /// \param lValue The new value.
131 void SetLongParameter(int iParameter
, long lValue
);
134 /// Set a string parameter.
135 /// \param iParameter The parameter to set.
136 /// \param sValue The new value.
139 void SetStringParameter(int iParameter
, const std::string
& sValue
);
141 /// Get a boolean parameter
142 /// \param iParameter The parameter to get.
143 /// \retval The current value.
145 bool GetBoolParameter(int iParameter
);
147 /// Get a long integer parameter
148 /// \param iParameter The parameter to get.
149 /// \retval The current value.
151 long GetLongParameter(int iParameter
);
153 /// Get a string parameter
154 /// \param iParameter The parameter to get.
155 /// \retval The current value.
157 std::string
GetStringParameter(int iParameter
);
160 /// Reset a parameter to the default value
163 void ResetParameter(int iParmater
);
165 /// \todo Document this
167 void GetFontSizes(std::vector
< int >*FontSizes
) const;
170 /// Obtain the permitted values for a string parameter - used to
171 /// geneate preferences dialogues etc.
174 void GetPermittedValues(int iParameter
, std::vector
<std::string
> &vList
);
177 /// Get a list of settings which apply to a particular module
180 bool GetModuleSettings(const std::string
&strName
, SModuleSettings
**pSettings
, int *iCount
);
185 /// Forward events to listeners in the SettingsUI and Editbox.
186 /// \param pEvent The event to forward.
187 /// \todo Should be protected.
189 virtual void ExternalEventHandler(Dasher::CEvent
* pEvent
) {};
191 /// Interface level event handler. For example, responsible for
192 /// restarting the Dasher model whenever parameter changes make it
194 /// \param pEvent The event.
195 /// \todo Should be protected.
197 void InterfaceEventHandler(Dasher::CEvent
* pEvent
);
200 void PreSetNotify(int iParameter
, const std::string
&sValue
);
203 /// Draw a new Dasher frame, regardless of whether we're paused etc.
204 /// \param iTime Current time in ms.
205 /// \todo See comments in cpp file for some functionality which needs to be re-implemented
207 void NewFrame(unsigned long iTime
, bool bForceRedraw
);
210 /// @name Starting and stopping
211 /// Methods used to instruct dynamic motion of Dasher to start or stop
214 /// Resets the Dasher model. Doesn't actually unpause Dasher.
215 /// \deprecated Use InvalidateContext() instead
220 /// \todo Parameters are ignored (?) - remove from definition.
222 void PauseAt(int MouseX
, int MouseY
); // are required to make
224 /// Halt Dasher. This simply freezes Dasher but does not emit a stop event, so does not result in speech etc.
229 /// \param Time Time in ms, used to keep a constant frame rate
231 void Unpause(unsigned long Time
); // Dasher run at the
237 // -----------------------------------------------------
239 // std::map<int, std::string>& GetAlphabets(); // map<key, value> int is a UID string can change. Store UID in preferences. Display string to user.
240 // std::vector<std::string>& GetAlphabets();
241 // std::vector<std::string>& GetLangModels();
242 // std::vector<std::string>& GetViews();
244 /// Supply a new CDasherScreen object to do the rendering.
245 /// \param NewScreen Pointer to the new CDasherScreen.
247 void ChangeScreen(CDasherScreen
* NewScreen
); // We may change the widgets Dasher uses
249 /// Train Dasher from a file
250 /// \param Filename File to load.
252 int TrainFile(std::string Filename
, int iTotalBytes
, int iOffset
); // all training data must be in UTF-8.
254 /// Set the context in which Dasher makes predictions
255 /// \param strNewContext The new context (UTF-8)
257 void SetContext(std::string strNewContext
);
258 void InvalidateContext(bool bForceStart
);
260 /// @name Status reporting
261 /// Get information about the runtime status of Dasher which might
262 /// be of interest for debugging purposes etc.
265 /// Get the current rate of text entry.
266 /// \retval The rate in characters per minute.
267 /// TODO: Check that this is still used
271 /// Get current refresh rate.
272 /// \retval The rate in frames per second
273 /// TODO: Check that this is still used
277 /// Get the total number of nats (base-e bits) entered.
278 /// \retval The current total
279 /// \todo Obsolete since new logging code?
281 double GetNats() const;
283 /// Reset the count of nats entered.
284 /// \todo Obsolete since new logging code?
288 double GetFramerate();
290 int GetRenderCount();
294 /// @name Control hierarchy and action buttons
295 /// Manipulate the hierarchy of commands presented in control mode etc
298 void RegisterNode( int iID
, const std::string
&strLabel
, int iColour
);
300 void ConnectNode(int iChild
, int iParent
, int iAfter
);
302 void DisconnectNode(int iChild
, int iParent
);
304 void ExecuteCommand(const std::string
&strName
);
306 void AddActionButton(const std::string
&strName
);
310 virtual void WriteTrainFile(const std::string
&strNewText
) {
314 /// Deals with forwarding user input to the core
317 void KeyDown(int iTime
, int iId
);
319 void KeyUp(int iTime
, int iId
);
321 void HandleClickUp(int iTime
, int iX
, int iY
);
323 void HandleClickDown(int iTime
, int iX
, int iY
);
327 // Module management functions
328 void RegisterFactory(CModuleFactory
*pFactory
);
330 void StartShutdown();
332 void AddGameModeString(const std::string
&strText
) {
333 m_deGameModeStrings
.push_back(strText
);
339 void ScheduleRedraw() {
340 m_bRedrawScheduled
= true;
348 /// Notify the core that the UI has been realised. At this point drawing etc. is expected to work
354 /// @name State machine functions
379 void ChangeState(ETransition iTransition
);
383 CDasherModule
*GetModule(long long int iID
);
384 CDasherModule
*GetModuleByName(const std::string
&strName
);
387 // TODO: Make these private (currently used by child class)
388 void WriteTrainFileFull();
389 void WriteTrainFilePartial();
393 // Various 'child' components
394 CAlphabet
*m_Alphabet
;
395 CDasherModel
*m_pDasherModel
;
396 CDasherScreen
*m_DasherScreen
;
397 CDasherView
*m_pDasherView
;
398 CDasherInput
*m_pInput
;
400 CColourIO
*m_ColourIO
;
401 CNodeCreationManager
*m_pNCManager
;
403 std::string strTrainfileBuffer
;
404 std::string strCurrentContext
;
406 CEventHandler
*m_pEventHandler
;
407 CSettingsStore
*m_pSettingsStore
;
408 CUserLogBase
*m_pUserLog
; // Pointer to the object that handles logging user activity
409 CInputFilter
* m_pInputFilter
;
410 CModuleManager m_oModuleManager
;
412 bool m_bGlobalLock
; // The big lock
415 bool m_bRedrawScheduled
;
421 /// \todo Document this
424 void GetAlphabets(std::vector
< std::string
> *AlphabetList
);
427 /// \todo Document this
430 void GetColours(std::vector
< std::string
> *ColourList
);
432 /// @name Platform dependent utility functions
433 /// These functions provide various platform dependent functions
434 /// required by the core. A derived class is created for each
435 /// supported platform which implements these.
439 /// Initialise the SP_SYSTEM_LOC and SP_USER_LOC paths - the exact
440 /// method of doing this will be OS dependent
443 virtual void SetupPaths() = 0;
446 /// Produce a list of filenames for alphabet files
449 virtual void ScanAlphabetFiles(std::vector
<std::string
> &vFileList
) = 0;
452 /// Produce a list of filenames for colour files
455 virtual void ScanColourFiles(std::vector
<std::string
> &vFileList
) = 0;
458 /// Set up the platform dependent UI for the widget (not the wider
459 /// app). Note that the constructor of the derived class will
460 /// probably want to return details of what was created - this will
461 /// have to happen separately, but we'll need to be careful with the
465 virtual void SetupUI() = 0;
468 /// Create any module factories which are specific to the platform
469 /// (eg input device drivers)
472 virtual void CreateLocalFactories() = 0;
475 /// Create settings store object, which will be platform dependent
476 /// TODO: Can this not be done just by selecting which settings
477 /// store implementation to instantiate?
480 virtual void CreateSettingsStore() = 0;
483 /// Obtain the size in bytes of a file - the way to do this is
484 /// dependent on the OS (TODO: Check this - any posix on Windows?)
487 virtual int GetFileSize(const std::string
&strFileName
) = 0;
490 /// Start the callback timer
493 virtual void StartTimer() = 0;
496 /// Shutdown the callback timer (permenantly - this is called once
497 /// Dasher is committed to closing).
500 virtual void ShutdownTimer() = 0;
505 /// Provide a new CDasherInput input device object.
509 void CreateFactories();
510 void CreateInputFilter();
511 void CreateDasherModel();
512 void ChangeAlphabet();
513 void ChangeColours();
515 void Redraw(bool bRedrawNodes
);
516 void SetupActionButtons();
517 void DestroyActionButtons();
518 void PositionActionButtons();
519 bool DrawActionButtons();
521 void LeaveState(EState iState
);
522 void EnterState(EState iState
);
525 /// @name Lock Management
526 /// Functions for locking/unlocking the core. Note that the lock
527 /// flags parameter is currently ignored, but will be used to give
528 /// finer granularity
535 void AddLock(int iLockFlags
);
538 /// Release an existing lock. Note that these functions have minimal
539 /// error checking at the moment, so be careful.
542 void ReleaseLock(int iLockFlags
);
548 EState m_iCurrentState
;
550 std::deque
<std::string
> m_deGameModeStrings
;
552 std::vector
<CActionButton
*> m_vLeftButtons
;
553 std::vector
<CActionButton
*> m_vRightButtons
;
558 #endif /* #ifndef __DasherInterfaceBase_h__ */