AGX Dynamics  2.35.0.1
OsgRenderer.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef AGXQT_OSGRENDERER_H
18 #define AGXQT_OSGRENDERER_H
19 
20 #include <agxQt/export.h>
21 #include <agx/Math.h>
22 
23 #include <iostream>
24 
25 #include <agx/PushDisableWarnings.h> // Disabling warnings. Include agx/PopDisableWarnings.h below!
26 #include <osgViewer/ViewerEventHandlers>
27 #include <osgViewer/Viewer>
28 #include <osgViewer/CompositeViewer>
29 #include <osgGA/GUIEventAdapter>
30 
31 #include <QtOpenGL/QGLWidget>
32 #include <QtDesigner/QDesignerExportWidget>
33 #include <QDesignerCustomWidgetInterface>
34 #include <QtDesigner>
35 #include <QtGui>
36 
37 #include <QApplication>
38 #include <QMainWindow>
39 #include <QLabel>
40 #include <QTimer>
41 #include <QString>
42 #include <QPushButton>
43 #include <QtQuick/QQuickItem>
44 #include <QtQuick/QQuickWindow>
45 #include <agx/PopDisableWarnings.h> // End of disabled warnings.
46 
47 
48 #ifdef _MSC_VER
49 # pragma warning(push)
50 # pragma warning(disable: 4251) // warning C4251: class X needs to have dll-interface to be used by clients of class Y
51 #endif
52 
53 
54 namespace agxQt
55 {
57  //QDESIGNER_WIDGET_EXPORT
58 
59  class AGXQT_EXPORT OsgRenderer : public QGLWidget
60  {
61  Q_OBJECT
63 
64  public:
65  OsgRenderer(QWidget *parent = 0);
67 
68  void setEnableResize(bool state);
69 
70  public slots:
72  void slotEnableRecordingNotifier(bool enable);
73  //signals:
74  // void updated(QTime currentTime);
75 
76 
77  virtual QSize minimumSizeHint() const;
78  virtual QSize sizeHint() const;
79 
80  osgViewer::GraphicsWindow* getGraphicsWindow();
81  osgViewer::Viewer* getViewer();
82 
84 
85  protected:
86  virtual void initializeGL();
87  virtual void paintGL();
88  virtual void resizeGL(int width, int height);
89 
90  virtual void keyPressEvent( QKeyEvent* event );
91  virtual void keyReleaseEvent( QKeyEvent* event );
92 
93  virtual void mousePressEvent( QMouseEvent* event );
94  virtual void mouseReleaseEvent( QMouseEvent* event );
95  virtual void mouseMoveEvent( QMouseEvent* event );
96 
98  void drawText(QPainter * pianter);
99 
100  private:
101  osg::ref_ptr<osgViewer::GraphicsWindowEmbedded> m_gw;
102  osg::ref_ptr<osgViewer::Viewer> m_viewer;
103  osg::ref_ptr<osg::Node> m_root;
104 
105  QTimer m_glupdateTimer;
106  bool m_drawRecordNotifier;
107 
109  };
111 
112 
114  {
115 
116  public:
118  {
119  mKeyMap[Qt::Key_Escape ] = osgGA::GUIEventAdapter::KEY_Escape;
120  mKeyMap[Qt::Key_Delete ] = osgGA::GUIEventAdapter::KEY_Delete;
121  mKeyMap[Qt::Key_Home ] = osgGA::GUIEventAdapter::KEY_Home;
122  mKeyMap[Qt::Key_Enter ] = osgGA::GUIEventAdapter::KEY_KP_Enter;
123  mKeyMap[Qt::Key_End ] = osgGA::GUIEventAdapter::KEY_End;
124  mKeyMap[Qt::Key_Return ] = osgGA::GUIEventAdapter::KEY_Return;
125  mKeyMap[Qt::Key_PageUp ] = osgGA::GUIEventAdapter::KEY_Page_Up;
126  mKeyMap[Qt::Key_PageDown ] = osgGA::GUIEventAdapter::KEY_Page_Down;
127  mKeyMap[Qt::Key_Left ] = osgGA::GUIEventAdapter::KEY_Left;
128  mKeyMap[Qt::Key_Right ] = osgGA::GUIEventAdapter::KEY_Right;
129  mKeyMap[Qt::Key_Up ] = osgGA::GUIEventAdapter::KEY_Up;
130  mKeyMap[Qt::Key_Down ] = osgGA::GUIEventAdapter::KEY_Down;
131  mKeyMap[Qt::Key_Backspace ] = osgGA::GUIEventAdapter::KEY_BackSpace;
132  mKeyMap[Qt::Key_Tab ] = osgGA::GUIEventAdapter::KEY_Tab;
133  mKeyMap[Qt::Key_Space ] = osgGA::GUIEventAdapter::KEY_Space;
134  mKeyMap[Qt::Key_Delete ] = osgGA::GUIEventAdapter::KEY_Delete;
135  mKeyMap[Qt::Key_Alt ] = osgGA::GUIEventAdapter::KEY_Alt_L;
136  mKeyMap[Qt::Key_Shift ] = osgGA::GUIEventAdapter::KEY_Shift_L;
137  mKeyMap[Qt::Key_Control ] = osgGA::GUIEventAdapter::KEY_Control_L;
138  mKeyMap[Qt::Key_Meta ] = osgGA::GUIEventAdapter::KEY_Meta_L;
139 
140  mKeyMap[Qt::Key_F1 ] = osgGA::GUIEventAdapter::KEY_F1;
141  mKeyMap[Qt::Key_F2 ] = osgGA::GUIEventAdapter::KEY_F2;
142  mKeyMap[Qt::Key_F3 ] = osgGA::GUIEventAdapter::KEY_F3;
143  mKeyMap[Qt::Key_F4 ] = osgGA::GUIEventAdapter::KEY_F4;
144  mKeyMap[Qt::Key_F5 ] = osgGA::GUIEventAdapter::KEY_F5;
145  mKeyMap[Qt::Key_F6 ] = osgGA::GUIEventAdapter::KEY_F6;
146  mKeyMap[Qt::Key_F7 ] = osgGA::GUIEventAdapter::KEY_F7;
147  mKeyMap[Qt::Key_F8 ] = osgGA::GUIEventAdapter::KEY_F8;
148  mKeyMap[Qt::Key_F9 ] = osgGA::GUIEventAdapter::KEY_F9;
149  mKeyMap[Qt::Key_F10 ] = osgGA::GUIEventAdapter::KEY_F10;
150  mKeyMap[Qt::Key_F11 ] = osgGA::GUIEventAdapter::KEY_F11;
151  mKeyMap[Qt::Key_F12 ] = osgGA::GUIEventAdapter::KEY_F12;
152  mKeyMap[Qt::Key_F13 ] = osgGA::GUIEventAdapter::KEY_F13;
153  mKeyMap[Qt::Key_F14 ] = osgGA::GUIEventAdapter::KEY_F14;
154  mKeyMap[Qt::Key_F15 ] = osgGA::GUIEventAdapter::KEY_F15;
155  mKeyMap[Qt::Key_F16 ] = osgGA::GUIEventAdapter::KEY_F16;
156  mKeyMap[Qt::Key_F17 ] = osgGA::GUIEventAdapter::KEY_F17;
157  mKeyMap[Qt::Key_F18 ] = osgGA::GUIEventAdapter::KEY_F18;
158  mKeyMap[Qt::Key_F19 ] = osgGA::GUIEventAdapter::KEY_F19;
159  mKeyMap[Qt::Key_F20 ] = osgGA::GUIEventAdapter::KEY_F20;
160 
161  mKeyMap[Qt::Key_hyphen ] = '-';
162  mKeyMap[Qt::Key_Equal ] = '=';
163 
164  mKeyMap[Qt::Key_division ] = osgGA::GUIEventAdapter::KEY_KP_Divide;
165  mKeyMap[Qt::Key_multiply ] = osgGA::GUIEventAdapter::KEY_KP_Multiply;
166  mKeyMap[Qt::Key_Minus ] = '-';
167  mKeyMap[Qt::Key_Plus ] = '+';
168  //mKeyMap[Qt::Key_H ] = osgGA::GUIEventAdapter::KEY_KP_Home;
169  //mKeyMap[Qt::Key_ ] = osgGA::GUIEventAdapter::KEY_KP_Up;
170  //mKeyMap[92 ] = osgGA::GUIEventAdapter::KEY_KP_Page_Up;
171  //mKeyMap[86 ] = osgGA::GUIEventAdapter::KEY_KP_Left;
172  //mKeyMap[87 ] = osgGA::GUIEventAdapter::KEY_KP_Begin;
173  //mKeyMap[88 ] = osgGA::GUIEventAdapter::KEY_KP_Right;
174  //mKeyMap[83 ] = osgGA::GUIEventAdapter::KEY_KP_End;
175  //mKeyMap[84 ] = osgGA::GUIEventAdapter::KEY_KP_Down;
176  //mKeyMap[85 ] = osgGA::GUIEventAdapter::KEY_KP_Page_Down;
177  mKeyMap[Qt::Key_Insert ] = osgGA::GUIEventAdapter::KEY_KP_Insert;
178  //mKeyMap[Qt::Key_Delete ] = osgGA::GUIEventAdapter::KEY_KP_Delete;
179  }
180 
182  {
183  }
184 
185  int remapKey(QKeyEvent* event)
186  {
187  KeyMap::iterator itr = mKeyMap.find(event->key());
188  if (itr == mKeyMap.end())
189  {
190  return int(*(event->text().toLatin1().data()));
191  }
192  else
193  return itr->second;
194  }
195 
196  private:
197  typedef std::map<unsigned int, int> KeyMap;
198  KeyMap mKeyMap;
199  };
200 
202 }
203 
204 
205 #ifdef _MSC_VER
206 # pragma warning(pop)
207 #endif
208 
209 
210 #endif
#define AGXQT_EXPORT
[0] //! [1]
Definition: OsgRenderer.h:60
virtual QSize sizeHint() const
virtual void initializeGL()
void slotEnableRecordingNotifier(bool enable)
virtual void keyPressEvent(QKeyEvent *event)
void drawText(QPainter *pianter)
osgViewer::GraphicsWindow * getGraphicsWindow()
void setEnableResize(bool state)
virtual void mouseMoveEvent(QMouseEvent *event)
virtual void keyReleaseEvent(QKeyEvent *event)
virtual void mousePressEvent(QMouseEvent *event)
virtual void resizeGL(int width, int height)
osgViewer::Viewer * getViewer()
virtual QSize minimumSizeHint() const
virtual void mouseReleaseEvent(QMouseEvent *event)
virtual void paintGL()
OsgRenderer(QWidget *parent=0)
[0]
int remapKey(QKeyEvent *event)
Definition: OsgRenderer.h:185
Contains classes/utility functions for connecting AGX to QT with OSG.
static QtKeyboardMap s_QtKeyboardMap
Definition: OsgRenderer.h:201