vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DAEnvironment.h
Go to the documentation of this file.
1 #pragma once
2 
3 
4 XERCES_CPP_NAMESPACE_USE
5 
6 #include <vector>
7 
8 
9 #include "DATool.h"
10 //#include "ToolBrush.h"
11 #include "ToolTongs.h"
12 
13 
14 #include "PoA.h"
15 #include "PoB.h"
16 
17 #include "Controller.h"
18 
19 #include "../../vreckoAP/LightsEditor/Lights.h"
20 
21 
22 
23 
24 using namespace vrecko;
25 
26 namespace APDYNAMICART
27 {
28 
29 
31 
49 class DAEnvironment: public Ability {
50 
51 public:
52 
53  DAEnvironment();
54  ~DAEnvironment();
55 
57 
62  //void addPoB(PoB* newPoB, bool movable);
63 
64  void enableGUI( bool enable );
65 
67 
70  Controller* getController(PoAType type);
71 
72  //TODO ? move this to private ?
74  osg::ref_ptr<EnvironmentObject> rightHandEO;
75 
76  //TODO ? move this to private ?
78  osg::ref_ptr<EnvironmentObject> leftHandEO;
79 
80  //returns time elapsed from beginning of painting
81  double getElapsedArtTime();
82 
83  osg::Vec3 getLeftHandPosition() const { return this->LHPosition; }
84  osg::Quat getLeftHandOrientation() const { return this->LHOrientation; }
85  osg::Vec3 getRightHandPosition() const { return this->RHPosition; }
86  osg::Quat getRightHandOrientation() const { return this->RHOrientation; }
87 
88  bool getObjectSelectionActiveRight() const { return _objectSelectionActiveRight; }
89  void setObjectSelectionbyRightHand(bool val) { _objectSelectionActiveRight = val; }
90 
91  bool getAutoRotationActive() const { return _autoRotationActive; }
92  void setAutoRotationActive(bool val) { _autoRotationActive = val; }
93 
94  static DAEnvironment *getInstance() { return _selfPointer; }
95  double getLoadedArtTime() const { return _loadedArtTime; }
96 
97  //obsloleted - replaced by GUI color picker
99 
105  //void chooseColorbyColorChooser(ref_ptr_PoA rp_poa);
106 
112  void listDirectory(const string& dirpath, const string& mask, std::vector<string>* fileNames);
113 
114  void preInitialize();
115  void postInitialize();
116 
117  void CreateMenuAbilities();
118 
119  //obsoleted - replaced by METHOD_INPUTS..,
120  //void processEvent(const std::string &input_name, void *value);
121 
128  typedef bool (*func)(const string& id, void* value, void* userData);
129 
130  void setUpCustomProcessEventCallback(bool (*func)(const std::string &input_name, void *value, void* userData), void* userData) {
131  _callback = func;
132  _userData = userData;
133  }
134 
135 
136  void update();
137 
138  //obsoleted - replaced by METHOD....
143  //void* processRequest(const std::string &strInputName, void *pValue);
144 
145  bool loadXMLParameters(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *parametersNode);
146  XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *saveXMLParameters(XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *);
147 
148 
149 
150 private:
151 
153 
157  static DAEnvironment * _selfPointer;
158 
160  bool _audienceMode;
161 
163 
170  std::vector<Controller* > _controllers;
171 
172  //TODO could there be referenced pointer?
173  Controller* _actualController;
174 
175 
176  // Tracker attributes
177  osg::Vec3 RHPosition;
178  osg::Vec3 RHUntransPos;
179  osg::Quat RHOrientation;
180 
181  osg::Vec3 LHPosition;
182  osg::Quat LHOrientation;
183 
184  osg::Vec3 OldLHPosition;
185  osg::Quat OldLHOrientation;
186 
187 
188  //DA area attributes
189 
191  /*
192  * Owner of this ability
193  *
194  * Contains:
195  * - all PoA objects.
196  * - some PoB objects.
197  * - abilities:
198  * - _controllers
199  * - tools
200  *
201  */
202  EnvironmentObject* _DAArea;
203 
204  osg::Quat DAAreaOrientation;
205  osg::Vec3 DAAreaPosition;
206  osg::Vec3 DAAreaScale;
207 
209  osg::ref_ptr<EnvironmentObject> templateObject;
210 
211 
212  // Selection by pointing
214  unsigned int lastSelectedID_Left;
215  unsigned int lastSelectedID_Right;
216 
218  bool objectPointedRight;
219  bool objectPointedLeft;
220 
223  ref_ptr_PoA lastSelectedPoA_Left;
224 
226  ref_ptr_PoA lastSelectedPoA_Right;
227 
228 
229 
230  // Rendering
231  bool wireframeRendering;
232 
233 
234  //Scaling
235  osg::Vec3 OldScalePosition;
236  osg::Vec3 OldStepScalePosition; // step-wise scaling
237  osg::Vec3 OldScalePositionTrans; // transformed
238 
239  double DAAScaleStep;
240  double minDAAScale;
241  double maxDAAScale; // max Scale Factor
242  double maxHandMovement; // scope of movement of hand
243 
244  //Auto-rotation
245  double autoRotationStep;
246  double ARDefaultAngle;
247  osg::Timer_t lastAutorotationTime, nowAutorotationTime;
248 
249  int _icontoDeactivate;
250 
251 
252  //User settings
253  bool _castShadows;
254  bool _DAAreaManipulationActive;
255  //bool IndirectDAAreaManipulationActive; ///< not used anymore?? (rotation using some kind of gizmo. Enables more precise rotations and rotation around one of basic axes - X,Y,Z )
256  bool _autoRotationActive;
257  bool _globalAxisAutoRotation;
258  bool _scaleChangeActive; // scaling by moving hand
259  bool _colorChooserActive;
260 
261 
263 
267  bool _objectSelectionActiveRight;
268  bool _objectSelectionActiveRight_old;
269 
270  // see _objectSelectionActiveRight
271  bool _objectSelectionActiveLeft;
272  bool _objectSelectionActiveLeft_old;
273 
275  bool _isMainMenuActive;
276 
278  bool _isPoAMenuActive;
279 
280  int stepScaleChangeActive;
281 
282 
283  //Auto-save
284  time_t _autosaveStartTime, _autosaveDeltaTime;
285  int _autoSaveTime;
286  int _lastSaveTime;
287  char _retezec[100];
288 
290  osg::Vec3 displacementDistance;
291  osg::Vec3 displacementStep;
292  int defaultDisplaceAnimTime;
293  int displaceAnimTime;
294 
295  //Menu
296  std::vector<std::string>* fileList;
297 
298  time_t _artWorkStartTime;
299  double _loadedArtTime;
300 
301 
303 
305  bool addController(std::string name, DOMNode* parameters);
306 
308  void clear();
309 
310 
312  std::string DAEnvironment::createMenuStructure();
313 
315  //void evokeColourChooser();
316 
317  //gets
321  inline std::string getAutoRotationString() const;
322 
326  inline std::string getCastShadowString() const;
327 
331  std::string getNewFileName(const std::vector<std::string>* fileList);
335  inline std::string getRenderingMethodString() const;
336 
340  inline std::string getSwitchModeString() const;
341 
342 
344  /*
345  *
346  * \param fileName file to import
347  * \return code error. 0 means everything went good
348  */
349  int importScene( const string& fileName );
350 
352 
355  void guiItemClicked( const char* itemID, const int sensorNumber);
356 
358 
362  void guiSliderChanged(const char* sliderID, float sliderPos);
363 
365  double rescaleDAArea(double dist, double oldValue, double minValue, double maxValue);
366 
368  void ResetDAArea();
369 
371 
384  int loadDAScene(const string& fileName);
385 
387 
392  int loadTemplate(const string& fileName);
393 
395 
399  void saveDAScene(const string& filePath, const string& fileName);
400 
402 
409  void selectObject(bool rightHand, unsigned long selectedID);
410 
412  void showInfo() const;
413 
415  void switchContext(PoAType newContext);
416 
418  void switchModes();
419 
421 
424  void switchRenderingMethod();
425 
429  bool customProcessEvent(const string& input_name, void* value, void* userData, bool (*func)(const string& input_name, void* value, void* userData));
430 
431  func _callback;
432  void* _userData;
433  bool firstTimeUpdate;
434 
435  void scaleDAArea();
436  void daAreaManipulation();
437  void objectSelection();
438 
439  unsigned int checkSelectedObject(int sensorNumber);
440 
441  //Menu
442  APGUI::Menu *mainMenuAbility;
443 
444 
445  // see INIT_INPUT macros for commentary of these...
446 
447  //TODO change these to Sensor_position ??
448  DECLARE_INPUT(Sensor_0_position, MessageVec3);
449  DECLARE_INPUT(Sensor_1_position, MessageVec3);
450  DECLARE_INPUT(Sensor_0_orientation, MessageQuat);
451  DECLARE_INPUT(Sensor_1_orientation, MessageQuat);
452 
453  DECLARE_REQUEST_INPUT(Sensor_0_actionMain, MessageBool, MessageBool);
454  DECLARE_REQUEST_INPUT(Sensor_1_actionMain, MessageBool, MessageBool);
455 
456  //obsoleted
457  //DECLARE_REQUEST_INPUT(PointerPosition, MessageInt, MessageVec3);
458  //DECLARE_REQUEST_INPUT(PointerOrientation, MessageInt, MessageQuat);
459 
460  DECLARE_INPUT(ResetDAArea, MessageBool);
461  DECLARE_INPUT(ScaleDAArea, MessageInt);
462  DECLARE_INPUT(ChangeAutoRotationSpeed, MessageInt);
463 
464  DECLARE_INPUT(SwitchTool, MessageBool);
465 
466  DECLARE_INPUT(Colour, MessageVec4);
467 
468  DECLARE_INPUT(SwitchRenderingMethod, MessageBool);
469  DECLARE_INPUT(QuickLoad, MessageBool);
470  DECLARE_INPUT(QuickSave, MessageBool);
471  DECLARE_INPUT(Autorotation, MessageBool);
472  DECLARE_INPUT(DebugPurposeKey, MessageBool);
473  DECLARE_INPUT(Import, MessageBool);
474 
475  DECLARE_INPUT(MenuItemClicked, MessageString);
476  DECLARE_INPUT(GUIItemClicked, MessageString);
477  DECLARE_INPUT(CreateMenuStructure, MessageInt);
478  DECLARE_INPUT(HidingMenu, MessageBool);
479  DECLARE_INPUT(ExternalDeactivation, MessageObjectID);
480  DECLARE_INPUT(SwitchGUIVisibility, MessageBool);
481 
482  DECLARE_OUTPUT(MenuStructure, MessageString);
483  DECLARE_OUTPUT(SwitchLayout, MessageString);
484 
485 
486  // asking about what object is actually selected - Input Connector should answer
487  DECLARE_REQUEST_OUTPUT(SelectedObjectID, MessageInt, MessageObjectID);
488 
489 
490 
491 };
492 
493 }
494