AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
OsgRenderer.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx 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 <QtOpenGLWidgets/QOpenGLWidget>
32#include <QtUiPlugin/qdesignerexportwidget.h>
33#include <QtUiPlugin/customwidget.h>
34#include <QtGui>
35
36#include <QApplication>
37#include <QMainWindow>
38#include <QLabel>
39#include <QTimer>
40#include <QString>
41#include <QPushButton>
42#include <agx/PopDisableWarnings.h> // End of disabled warnings.
43
44
45#ifdef _MSC_VER
46# pragma warning(push)
47# pragma warning(disable: 4251) // warning C4251: class X needs to have dll-interface to be used by clients of class Y
48#endif
49
50
51namespace agxQt
52{
54 //QDESIGNER_WIDGET_EXPORT
55
56 class AGXQT_EXPORT OsgRenderer : public QOpenGLWidget, protected QOpenGLFunctions
57 {
58 Q_OBJECT
60
61 public:
62 OsgRenderer(QWidget *parent = 0);
64
65 void setEnableResize(bool state);
66
68
69 public slots:
71 void slotEnableRecordingNotifier(bool enable);
72 //signals:
73 // void updated(QTime currentTime);
74
75
76 virtual QSize minimumSizeHint() const;
77 virtual QSize sizeHint() const;
78
79 osgViewer::GraphicsWindow* getGraphicsWindow();
80 osgViewer::Viewer* getViewer();
81
83
84 protected:
85 virtual void initializeGL();
86 virtual void paintGL();
87 virtual void resizeGL(int width, int height);
88
89 virtual void keyPressEvent( QKeyEvent* event );
90 virtual void keyReleaseEvent( QKeyEvent* event );
91
92 virtual void mousePressEvent( QMouseEvent* event );
93 virtual void mouseReleaseEvent( QMouseEvent* event );
94 virtual void mouseMoveEvent( QMouseEvent* event );
95
97 void drawText(QPainter * pianter);
98
99 private:
100 osg::ref_ptr<osgViewer::GraphicsWindowEmbedded> m_gw;
101 osg::ref_ptr<osgViewer::Viewer> m_viewer;
102 osg::ref_ptr<osg::Node> m_root;
103
104 QTimer m_glupdateTimer;
105 bool m_drawRecordNotifier;
106 bool m_firstFrame=true;
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
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)
osgViewer::Viewer * getViewer()
virtual void keyReleaseEvent(QKeyEvent *event)
virtual void mousePressEvent(QMouseEvent *event)
virtual void resizeGL(int width, int height)
virtual QSize minimumSizeHint() const
virtual void mouseReleaseEvent(QMouseEvent *event)
virtual void paintGL()
OsgRenderer(QWidget *parent=0)
[0]
int remapKey(QKeyEvent *event)
Contains classes/utility functions for connecting AGX to QT with OSG.
static QtKeyboardMap s_QtKeyboardMap