vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ControllableAbility.h
Go to the documentation of this file.
1 #ifndef CONTROLLABLEABILITY_H
2 #define CONTROLLABLEABILITY_H
3 
4 /*
5 
6 I/O CHANGES:
7 
8 16 Feb 2008
9  It is possible to obtain full scene graph path for the selected object (requestSelectionPath())
10 24 Aug 2007
11  Instead of overriding the createInfo() method, you have to override the fillDefaultInfo().
12 */
13 
14 
15 #include <vrecko/Ability.h>
16 #include <vrecko/IOPins.h>
17 #include <osg/Quat>
18 #include <osg/Node>
19 
20 
21 namespace vrecko {
22 
23 
24  #ifndef ANIMATOR_IMP_EXP
25  #ifdef AP_EDITORCONTROLLER_EXPORTS
26  #define EDITORCONTROLLER_IMP_EXP __declspec(dllexport)
27  #else
28  #define EDITORCONTROLLER_IMP_EXP __declspec(dllimport)
29  #endif
30  #endif
31 
32 
33 
34  #define POINTERPOS_REQUEST_NAME "PointerPosition"
35  #define POINTERROT_REQUEST_NAME "PointerRotation"
36  #define POINTERPOS_RAW_REQUEST_NAME "PointerPositionRaw"
37  #define POINTERROT_RAW_REQUEST_NAME "PointerRotationRaw"
38  #define SELECTIONID_REQUEST_NAME "SelectionID"
39  #define SELECTIONPATH_REQUEST_NAME "SelectionPath"
40  // Returns the same "std::vector<osg::Node*>" as
41  // ObjectUtils/ObjectSelector/"SelectionByPointerPos_Path" request
42 
43 #pragma pack(push, 1)
44  struct CABUTTONEVENT {
45  /* Size of the structure. Newer versions could have additional information
46  attached at the end. */
47  unsigned long dwSize;
48  /* ID of the pointer assigned to the button */
50  /* ID of the button that generated the event */
51  int iButtonID;
52  /* New state of the button (pressed = true, not pressed = false) */
53  bool bState;
54  };
55 
57  public:
58  virtual const char* getMessageId() { return "MessageCAButtonEvent"; }
60  };
61 
62 // Constants for CAINFO::dwFlags:
68  #define CAINFO_FLAGS_POINTERLOC_REQUESTOUTPUTS 0x00000001
69 
73  #define CAINFO_FLAGS_SELECTIONID_REQUESTOUTPUT 0x00000002
74 
77  #define CAINFO_FLAGS_ALL_ACTIVEPOINTER_BUTTONS 0x00000004
78 
81  #define CAINFO_FLAGS_ALL_OTHERPOINTER_BUTTONS 0x00000008
82 
86  #define CAINFO_FLAGS_POINTERLOC_RAW_REQUESTOUTPUTS 0x00000010
87 
89  #define CAINFO_FLAGS_NO_AUTO_DEACTIVATE 0x80000000
90 
91 
92  // Constants for CAINFO::dwActiveFlags:
93  /* Constants to set the preference... Should the selection be visible or not?
94  We have to determine the visibility of the selection of the active pointer (ACTPTR)
95  and other pointers (OTHERPTR).
96  The preference could be DONTCARE, FORCESHOW, SHOW, HIDE and FORCEHIDE.
97  Multiple abilities can be active at the same time, so the preferences could be conflicting.
98  The SHOW/HIDE are suggestions, FORCESHOW/FORCEHIDE are stronger suggestions
99  (a single active ability returning FORCESHOW will override any number of FORCEHIDEs) */
100  #define CAINFO_AFLAGS_SELSHOW_ACTPTR__SHIFT 0
101  #define CAINFO_AFLAGS_SELSHOW_ACTPTR__MASK 0x00000007
102  #define CAINFO_AFLAGS_SELSHOW_ACTPTR_DONTCARE 0x00000000
103  #define CAINFO_AFLAGS_SELSHOW_ACTPTR_HIDE 0x00000001 // Side note: The flags are sorted by their priorities
104  #define CAINFO_AFLAGS_SELSHOW_ACTPTR_SHOW 0x00000002 // (The EditorController::SelectionVisibilityUpdate() expects it to be so, so don't change the numbers)
105  #define CAINFO_AFLAGS_SELSHOW_ACTPTR_FORCEHIDE 0x00000003
106  #define CAINFO_AFLAGS_SELSHOW_ACTPTR_FORCESHOW 0x00000004
107  #define CAINFO_AFLAGS_SELSHOW_OTHERPTR__SHIFT 3
108  #define CAINFO_AFLAGS_SELSHOW_OTHERPTR__MASK 0x00000038
109  #define CAINFO_AFLAGS_SELSHOW_OTHERPTR_DONTCARE (CAINFO_AFLAGS_SELSHOW_ACTPTR_DONTCARE >> CAINFO_AFLAGS_SELSHOW_ACTPTR__SHIFT << CAINFO_AFLAGS_SELSHOW_OTHERPTR__SHIFT)
110  #define CAINFO_AFLAGS_SELSHOW_OTHERPTR_SHOW (CAINFO_AFLAGS_SELSHOW_ACTPTR_SHOW >> CAINFO_AFLAGS_SELSHOW_ACTPTR__SHIFT << CAINFO_AFLAGS_SELSHOW_OTHERPTR__SHIFT)
111  #define CAINFO_AFLAGS_SELSHOW_OTHERPTR_HIDE (CAINFO_AFLAGS_SELSHOW_ACTPTR_HIDE >> CAINFO_AFLAGS_SELSHOW_ACTPTR__SHIFT << CAINFO_AFLAGS_SELSHOW_OTHERPTR__SHIFT)
112  #define CAINFO_AFLAGS_SELSHOW_OTHERPTR_FORCEHIDE (CAINFO_AFLAGS_SELSHOW_ACTPTR_FORCEHIDE >> CAINFO_AFLAGS_SELSHOW_ACTPTR__SHIFT << CAINFO_AFLAGS_SELSHOW_OTHERPTR__SHIFT)
113  #define CAINFO_AFLAGS_SELSHOW_OTHERPTR_FORCESHOW (CAINFO_AFLAGS_SELSHOW_ACTPTR_FORCESHOW >> CAINFO_AFLAGS_SELSHOW_ACTPTR__SHIFT << CAINFO_AFLAGS_SELSHOW_OTHERPTR__SHIFT)
114 
115  struct CAINFO__VER1 {
117  unsigned long dwSize;
119  enum CAType {
121  Unknown = 0,
138  DummyCATypeToDWORD = 0xFFFFFFFF,
139  };
142  unsigned long dwFlags;
143  };
144 
145  struct CAINFO__VER2 : public CAINFO__VER1 {
149  unsigned long dwActiveFlags;
150  };
151 
153 
155  #define IS_CAINFO_VER(info, ver) \
156  ((info).dwSize >= sizeof(CAINFO__VER##ver))
157 
158 
159 #pragma pack(pop)
160 
162  public:
163 
164  class MessageCAINFO : public VreckoMessage {
165  public:
166  virtual const char* getMessageId() { return "MessageCAINFO"; }
168  };
169 
170  ControllableAbility(const char *abilityName);
171  virtual ~ControllableAbility();
172 
176  virtual bool initialize(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *parameters = NULL);
177 
180  virtual void update() {}
181 
182  // Called mostly by the VRECKO to handle a received event
183  // CAN be overridden, but it HAS TO CALL the ancestor's method
184  // (if the event is not fully processed by your method)
185 // virtual void processEvent(const std::string &strInputName, void *pValue);
186 
188  virtual bool isActive();
189 
190  protected:
192 
194 
196 
204  osg::Vec3 actPointerPos;
205 
214  osg::Vec3 actPointerPosRaw;
215 
224  osg::Quat actPointerRot;
225 
230  osg::Quat actPointerRotRaw;
231 
236  unsigned long actSelectedObjectID;
237 
246  std::vector<osg::Node*> *actSelectedPath;
247 
251 
252 
253 
259  virtual void createInterface();
260 
265  virtual void destroyInterface();
266 
271  virtual void processButtonPress(CABUTTONEVENT* eventData) {}
272 
277  virtual void processButtonRelease(CABUTTONEVENT* eventData) {}
278 
281  virtual int processNotification(BaseClass *sender, unsigned long notificationType, void *notificationData);
282 
288  virtual bool activate() { return true; }
289 
294  virtual void deactivate();
295 
323  virtual CAINFO* createInfo();
324 
325  CAINFO defaultInfo; // the base info, that will be used in createInfo() method.
326 
333  virtual void fillDefaultInfo() = 0;
334 
339  bool requestPointerLoc(bool bCancelIfNotActive = true);
340 
345  bool requestPointerLocRaw(bool bCancelIfNotActive = true);
346 
352  bool requestSelectionID(bool bCancelIfNotActive = true);
353 
359  bool requestSelectionPath(bool bCancelIfNotActive = true);
360 
363  bool bMenuVisible; // "cached" value, which may be updated in an isMenuCreated() call
364  inline bool isMenuCreated() { return (menu != NULL); }
365 
367  bool isMenuVisible();
368 
370  virtual bool createMenu(const char *menuString, bool bForceCreate = true);
371  virtual void destroyMenu();
372  virtual bool showMenu();
373  virtual bool hideMenu();
374 
377  virtual void processMenuButtonPress(CABUTTONEVENT* eventData);
378 
381  virtual void processMenuButtonRelease(CABUTTONEVENT* eventData);
382 
383 
388  virtual void menuItemClicked(const char* itemID) {};
389 
391  virtual void menuSliderChanged(const char* sliderID, float sliderPos) {};
392 
393  DECLARE_INPUT(ButtonStateChange, MessageCAButtonEvent);
394  DECLARE_INPUT(Menu_Clicked, MessageString);
395 
396  DECLARE_REQUEST_INPUT(ActivePointerID, MessageInt, MessageInt);
397  DECLARE_REQUEST_INPUT(GetInfo, MessageVoid, MessageCAINFO);
398 
399  DECLARE_REQUEST_OUTPUT(PointerPos, MessageInt, MessageVec3);
400  DECLARE_REQUEST_OUTPUT(PointerRot, MessageInt, MessageQuat);
401 
402  DECLARE_REQUEST_OUTPUT(PointerPosRaw, MessageInt, MessageVec3);
403  DECLARE_REQUEST_OUTPUT(PointerRotRaw, MessageInt, MessageQuat);
404 
405  DECLARE_REQUEST_OUTPUT(SelectionID, MessageInt, MessageObjectID);
406  DECLARE_REQUEST_OUTPUT(SelectionPath, MessageInt, MessageNodeList);
407 
408  private:
412  virtual void preInitialize() { };
413 
417  virtual void postInitialize() {}
418 
422  virtual bool loadXMLParameters(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *pParametersNode) { return true; }
423 
424  };
425 
426 }
427 
428 #endif