cherish
GLWidget.h
1 #ifndef GLWIDGET
2 #define GLWIDGET
3 
4 #include <QOpenGLWidget>
5 #include <QTabletEvent>
6 #include <QUndoStack>
7 #include <QStack>
8 #include <QPixmap>
9 #include <QScopedPointer>
10 #include <QDragEnterEvent>
11 #include <QDragLeaveEvent>
12 #include <QDragMoveEvent>
13 #include <QDropEvent>
14 
15 #include <osg/ref_ptr>
16 #include <osg/observer_ptr>
17 #include <osgViewer/GraphicsWindow>
18 #include <osgViewer/CompositeViewer>
19 #include <osgViewer/Viewer>
20 #include <osg/Camera>
21 #include <osg/Image>
22 #include <osg/GraphicsContext>
23 
24 #include "RootScene.h"
25 #include "Settings.h"
26 #include "../libSGControls/Manipulator.h"
27 #include "../libSGControls/EventHandler.h"
28 #include "../libSGControls/ViewerCommand.h"
29 
33 class Viewer : public osgViewer::Viewer {
34 public:
35  virtual void setUpThreading()
36  {
37  if (_threadingModel == osgViewer::ViewerBase::SingleThreaded){
38  if (_threadsRunning) this->stopThreading();
39  else {
40  if (!_threadsRunning) this->startThreading();
41  }
42  }
43  }
44 
45 };
46 
47 class EventHandler;
48 
52 class GLWidget : public QOpenGLWidget
53 {
54  Q_OBJECT
55 public:
57  GLWidget(RootScene* root, QUndoStack* stack, QWidget* parent=0, Qt::WindowFlags f = 0);
58 
60  osg::Camera* getCamera() const;
61 
62 protected:
63  void setCameraView();
64 public:
67  void setCameraView(const osg::Vec3d& eye, const osg::Vec3d& center, const osg::Vec3d& up, const double& fov2);
68 
70  void getCameraView(osg::Vec3d& eye, osg::Vec3d& center, osg::Vec3d& up, double& fov) const;
71 
73  void setMouseMode(const cher::MOUSE_MODE& mode);
74 
76  const cher::MOUSE_MODE getMouseMode() const;
77 
79  cher::MOUSE_MODE getMousePrevious() const;
80 
81 signals:
83  void autoSwitchMode(cher::MOUSE_MODE mode);
84 
86  void mouseModeSet(cher::MOUSE_MODE mode);
87 
89  void FOVSet(double fov);
90 
92  void importPhoto(const QString& path, const QString& fileName);
93 
94 public:
96  void setTabletActivity(bool active);
97 
100  QPixmap getScreenShot(const osg::Vec3d& eye, const osg::Vec3d& center, const osg::Vec3d& up);
101 
102 public slots:
103 
105  void onFOVChangedSlider(double fov);
106 
108  void onOrthoSet(bool ortho);
109 
110 protected:
111  // Widget's events that need to be over-ridden
112  virtual void initializeGL();
113  virtual void paintGL();
114  virtual void resizeGL(int w, int h);
115 
116  virtual void keyPressEvent(QKeyEvent* event);
117  virtual void keyReleaseEvent(QKeyEvent* event);
118 
119  virtual void mouseMoveEvent(QMouseEvent* event);
120  virtual void mousePressEvent(QMouseEvent* event);
121  virtual void mouseDoubleClickEvent(QMouseEvent* event);
122  virtual void mouseReleaseEvent(QMouseEvent* event);
123  virtual void wheelEvent(QWheelEvent* event);
124  virtual void tabletEvent(QTabletEvent* event);
125 
126  virtual bool event(QEvent* event);
127 
128 protected:
129  // Drag and drop related (from PhotoWidget)
130  void dragEnterEvent(QDragEnterEvent* event);
131  void dragLeaveEvent(QDragLeaveEvent* event);
132  void dragMoveEvent(QDragMoveEvent* event);
133  void dropEvent(QDropEvent* event);
134 
135 public:
136  virtual void onHome();
137 private:
138  virtual void onResize(int w, int h);
139 
140  osgGA::EventQueue* getEventQueue() const; // for osg to process mouse and keyboard events
141  // for more info see reference osgGA::EventQueue and osgGA::GUIEventAdapter
142  // the later's enums are used in EventHandler.h
143 
144  osg::ref_ptr<osg::GraphicsContext::Traits> m_traits;
145  osg::ref_ptr<osgViewer::GraphicsWindowEmbedded> m_graphicsWindow;
146  osg::ref_ptr<Viewer> m_viewer;
147  osg::observer_ptr<RootScene> m_RootScene;
148 
149  QTabletEvent::TabletDevice m_TabletDevice;
150 
151  bool m_DeviceDown; // pen touches the device?
152  bool m_DeviceActive; // pen is in device approximation?
153 
154  cher::MOUSE_MODE m_mouseMode;
155  cher::MOUSE_MODE m_mousePrevious;
156  osg::ref_ptr<Manipulator> m_manipulator;
157  osg::ref_ptr<EventHandler> m_EH;
158 
159  //QStack<osg::Matrixd> m_stackView;
160 
161  QUndoStack* m_viewStack;
162  osg::Vec3d m_eye, m_center, m_up; /* for prev/next views */
163 };
164 
165 #endif // GLWIDGET
166 
An OpenSceneGraph events that were passed from Qt&#39;s interface - GLWidget. Event handler is where all ...
Definition: EventHandler.h:47
An overridden osgViewer::Viewer class that avoids setting the CPU affinity to core 0 by overwriting s...
Definition: GLWidget.h:33
Contains all the entities that will appear on the scene: both user scene and utility entities (i...
Definition: RootScene.h:46
MOUSE_MODE
Definition: Settings.h:97
A proxy class connecting QOpenGLWidget with the content of RootScene; and also to transmit events...
Definition: GLWidget.h:52
Settings is a configuration variables file for Cherish: enums, consts, defaults. Contains settings su...