vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
EditorController.h
Go to the documentation of this file.
1 #ifndef EDITORCONTROLLER_H
2 #define EDITORCONTROLLER_H
3 
4 #include <vrecko/Ability.h>
5 #include <osg/Quat>
6 #include "ControllableAbility.h"
7 #include "AbilityMapper.h"
8 
9 
10 using namespace vrecko;
11 
12 namespace APEditorController
13 {
14 
15 class EditorController: public Ability {
16 public:
17  static const int maxPointers = 2;
18  static const int maxButtonsPerPointer = 4;
19 
22 
23  virtual bool initialize(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *parameters = NULL);
24 
25  virtual void update();
26 
27 
28 protected:
30  public:
31  ECPOINTERBUTTONINFO() { bState = false; cachedInfo = NULL; }
32  ~ECPOINTERBUTTONINFO() { setMappedAbility(NULL); };
33 
34  void setOwner(EditorController *_owner) { owner = _owner; }
35 
36  bool bState; // current state (pressed or released)
37 
39  bool setMappedAbility(const char *strID);
40 
41  std::string& getMappedAbilityID() { return mappedAbilityID; }
42  CAINFO* getMappedAbilityInfo(bool bForceRefresh);
43 
44  protected:
46  std::string mappedAbilityID;
48  };
49 
50  class ECPOINTERINFO {
51  public:
52  ECPOINTERINFO() { actSelection = 0; lastButtonPressed = 0; selPath = NULL; }
53  ~ECPOINTERINFO() { if (selPath) { delete selPath; selPath = NULL; } }
54 
55  osg::Vec3 pos, posRaw;
56  osg::Quat rot, rotRaw;
57 
58  unsigned long actSelection;
59  std::vector<osg::Node*> *selPath;
62 
64 
65  ECPOINTERBUTTONINFO buttons[maxButtonsPerPointer + 1];
68  };
69 
71 
72 // std::string strSelectionID, strP1Selection, strP2Selection;
73 // std::string strP1Visible, strP2Visible;
74 // std::string strSelectionReq;
75 
76  std::string activeAbilityName; // the name of the active ability
77  // "" if no ability is active
78  int activeAbilityPointerID, activeAbilityButtonID; // which pointer and button activated the ability
79 
80  osg::Vec3 actViewPosition;
81  // actual view position
82  ECPOINTERINFO pointers[maxPointers + 1];
83  // Pointer 0 is only a filler, so it is not necessary to "shift" indexes
84 
86  // automatically created editing ability to map other abilities to the buttons
87 // std::string strAbilityMapping;
88 
89  bool createAbilityMapper();
90  void removeAbilityMapper();
91  void setAbilityMapping(AbilityMapper::MAPPING *newMapping);
92  AbilityMapper::MessageMapping *compileAbilityMapping();
93  // retrieves current mapping and sends it to the AbilityMapped
94 
95  unsigned long actSelection;
96 
97  void setNewSelection(unsigned long newSelection);
98 
99  void pointerPosUpdate(int pointerID, const osg::Vec3 &newPos, bool bRaw = false);
100 
101  void pointerRotUpdate(int pointerID, const osg::Quat &newRot, bool bRaw = false);
102 
103  void pointerBtnUpdate(int poinerID, int buttonID, bool newState);
104  void sendPointerBtnToRelevantOutputs(int pointerID, int buttonID);
105 
106  void pointerSelUpdate(int pointerID, unsigned long newSelection);
107  void sendPointerSelectionEvent(int pointerID, unsigned long newSelection);
108 
109  void abilityActivationTest();
110  // Returns whether an ability is active.
111  // AND: If the ability is internally marked as "active" and the real state
112  // is different, then the internal state is also changed.
113 
114  void selectionVisibilityUpdate();
115  // Checks active abilities and sets the correct visibility
116  // of selection of each pointer.
117 
118  virtual int processNotification(BaseClass *sender, unsigned long notificationType, void *notificationData);
119 
120 
121  DECLARE_INPUT(Pointer1Pos, MessageVec3);
122  DECLARE_INPUT(Pointer1Rot, MessageQuat);
123  DECLARE_INPUT(Pointer1PosRaw, MessageVec3);
124  DECLARE_INPUT(Pointer1RotRaw, MessageQuat);
125  DECLARE_INPUT(Pointer1Btn1, MessageBool);
126  DECLARE_INPUT(Pointer1Btn2, MessageBool);
127  DECLARE_INPUT(Pointer1Btn3, MessageBool);
128  DECLARE_INPUT(Pointer1Btn4, MessageBool);
129 
130 
131  DECLARE_INPUT(Pointer2Pos, MessageVec3);
132  DECLARE_INPUT(Pointer2Rot, MessageQuat);
133  DECLARE_INPUT(Pointer2PosRaw, MessageVec3);
134  DECLARE_INPUT(Pointer2RotRaw, MessageQuat);
135  DECLARE_INPUT(Pointer2Btn1, MessageBool);
136  DECLARE_INPUT(Pointer2Btn2, MessageBool);
137  DECLARE_INPUT(Pointer2Btn3, MessageBool);
138  DECLARE_INPUT(Pointer2Btn4, MessageBool);
139 
140  DECLARE_OUTPUT(SelectionID, MessageObjectID);
141  DECLARE_OUTPUT(Pointer1Selection, MessageObjectID);
142  DECLARE_OUTPUT(Pointer1Visible, MessageBool);
143  DECLARE_OUTPUT(Pointer2Selection, MessageObjectID);
144  DECLARE_OUTPUT(Pointer2Visible, MessageBool);
145 
146  // for setting/getting the mapping from the AbilityMapper
147 
151 
152 
153  DECLARE_REQUEST_OUTPUT(SelectionByPointerPos_Path, MessageVec3, MessageNodeList);
154 
155  DECLARE_REQUEST_INPUT(SelectionID, MessageInt, MessageObjectID);
156  DECLARE_REQUEST_INPUT(SelectionPath, MessageInt, MessageNodeList);
157  DECLARE_REQUEST_INPUT(PointerPos, MessageInt, MessageVec3);
158  DECLARE_REQUEST_INPUT(PointerRot, MessageInt, MessageQuat);
159  DECLARE_REQUEST_INPUT(PointerPosRaw, MessageInt, MessageVec3);
160  DECLARE_REQUEST_INPUT(PointerRotRaw, MessageInt, MessageQuat);
161 };
162 
163 }
164 
165 #endif
166