Debian Codegraph @

src/Gui/Quarter/QuarterWidget.h

raw
1 #ifndef QUARTER_QUARTERWIDGET_H
2 #define QUARTER_QUARTERWIDGET_H
3
4 /**************************************************************************\
5 * Copyright (c) Kongsberg Oil & Gas Technologies AS
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
11 *
12 * Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 *
15 * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * Neither the name of the copyright holder nor the names of its
20 * contributors may be used to endorse or promote products derived from
21 * this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 \**************************************************************************/
35
36 #include <Inventor/SoRenderManager.h>
37 #include <Inventor/actions/SoGLRenderAction.h>
38
39 #include <QColor>
40 #include <QGraphicsView>
41 #include <QUrl>
42
43 #include "Basic.h"
44
45 class QOpenGLContext;
46 class QOpenGLWidget;
47 class QSurfaceFormat;
48
49 class QMenu;
50 class SoNode;
51 class SoEvent;
52 class SoCamera;
53 class SoEventManager;
54 class SoRenderManager;
55 class SoDirectionalLight;
56 class SoScXMLStateMachine;
57
58 namespace SIM { namespace Coin3D { namespace Quarter {
59
60 class EventFilter;
61 const char DEFAULT_NAVIGATIONFILE [] = "coin:///scxml/navigation/examiner.xml";
62
63 class QUARTER_DLL_API QuarterWidget : public QGraphicsView {
64 typedef QGraphicsView inherited;
65 Q_OBJECT
66
67 public:
68 enum TransparencyType {
69 SCREEN_DOOR = SoGLRenderAction::SCREEN_DOOR,
70 ADD = SoGLRenderAction::ADD,
71 DELAYED_ADD = SoGLRenderAction::DELAYED_ADD,
72 SORTED_OBJECT_ADD = SoGLRenderAction::SORTED_OBJECT_ADD,
73 BLEND = SoGLRenderAction::BLEND,
74 DELAYED_BLEND = SoGLRenderAction::DELAYED_BLEND,
75 SORTED_OBJECT_BLEND = SoGLRenderAction::SORTED_OBJECT_BLEND,
76 SORTED_OBJECT_SORTED_TRIANGLE_ADD = SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_ADD,
77 SORTED_OBJECT_SORTED_TRIANGLE_BLEND = SoGLRenderAction::SORTED_OBJECT_SORTED_TRIANGLE_BLEND,
78 NONE = SoGLRenderAction::NONE,
79 SORTED_LAYERS_BLEND = SoGLRenderAction::SORTED_LAYERS_BLEND
80 };
81
82 enum RenderMode {
83 AS_IS = SoRenderManager::AS_IS,
84 WIREFRAME = SoRenderManager::WIREFRAME,
85 WIREFRAME_OVERLAY = SoRenderManager::WIREFRAME_OVERLAY,
86 POINTS = SoRenderManager::POINTS,
87 HIDDEN_LINE = SoRenderManager::HIDDEN_LINE,
88 BOUNDING_BOX = SoRenderManager::BOUNDING_BOX
89 };
90
91 enum StereoMode {
92 MONO = SoRenderManager::MONO,
93 ANAGLYPH = SoRenderManager::ANAGLYPH,
94 QUAD_BUFFER = SoRenderManager::QUAD_BUFFER,
95 INTERLEAVED_ROWS = SoRenderManager::INTERLEAVED_ROWS,
96 INTERLEAVED_COLUMNS = SoRenderManager::INTERLEAVED_COLUMNS
97 };
98
99 Q_PROPERTY(QUrl navigationModeFile READ navigationModeFile WRITE setNavigationModeFile RESET resetNavigationModeFile) // clazy:exclude=qproperty-without-notify
100 Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor) // clazy:exclude=qproperty-without-notify
101 Q_PROPERTY(bool contextMenuEnabled READ contextMenuEnabled WRITE setContextMenuEnabled) // clazy:exclude=qproperty-without-notify
102 Q_PROPERTY(bool headlightEnabled READ headlightEnabled WRITE setHeadlightEnabled) // clazy:exclude=qproperty-without-notify
103 Q_PROPERTY(bool clearZBuffer READ clearZBuffer WRITE setClearZBuffer) // clazy:exclude=qproperty-without-notify
104 Q_PROPERTY(bool clearWindow READ clearWindow WRITE setClearWindow) // clazy:exclude=qproperty-without-notify
105 Q_PROPERTY(bool interactionModeEnabled READ interactionModeEnabled WRITE setInteractionModeEnabled) // clazy:exclude=qproperty-without-notify
106 Q_PROPERTY(bool interactionModeOn READ interactionModeOn WRITE setInteractionModeOn) // clazy:exclude=qproperty-without-notify
107
108 Q_PROPERTY(TransparencyType transparencyType READ transparencyType WRITE setTransparencyType) // clazy:exclude=qproperty-without-notify
109 Q_PROPERTY(RenderMode renderMode READ renderMode WRITE setRenderMode) // clazy:exclude=qproperty-without-notify
110 Q_PROPERTY(StereoMode stereoMode READ stereoMode WRITE setStereoMode) // clazy:exclude=qproperty-without-notify
111 Q_PROPERTY(qreal devicePixelRatio READ devicePixelRatio NOTIFY devicePixelRatioChanged)
112
113 Q_ENUM(TransparencyType)
114 Q_ENUM(RenderMode)
115 Q_ENUM(StereoMode)
116
117
118 public:
119 explicit QuarterWidget(QWidget * parent = nullptr, const QOpenGLWidget * sharewidget = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
120 explicit QuarterWidget(QOpenGLContext * context, QWidget * parent = nullptr, const QOpenGLWidget * sharewidget = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
121 explicit QuarterWidget(const QSurfaceFormat & format, QWidget * parent = nullptr, const QOpenGLWidget * shareWidget = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
122 ~QuarterWidget() override;
123
124 TransparencyType transparencyType() const;
125 RenderMode renderMode() const;
126 StereoMode stereoMode() const;
127
128 void setBackgroundColor(const QColor & color);
129 QColor backgroundColor() const;
130
131 qreal devicePixelRatio() const;
132
133 void resetNavigationModeFile();
134 void setNavigationModeFile(const QUrl & url = QUrl(QString::fromLatin1(DEFAULT_NAVIGATIONFILE)));
135 const QUrl & navigationModeFile() const;
136 void setupDefaultCursors();
137
138 void setContextMenuEnabled(bool yes);
139 bool contextMenuEnabled() const;
140 QMenu * getContextMenu() const;
141
142 bool headlightEnabled() const;
143 void setHeadlightEnabled(bool onoff);
144 SoDirectionalLight * getHeadlight() const;
145
146 bool clearZBuffer() const;
147 void setClearZBuffer(bool onoff);
148
149 bool clearWindow() const;
150 void setClearWindow(bool onoff);
151
152 bool interactionModeEnabled() const;
153 void setInteractionModeEnabled(bool onoff);
154
155 bool interactionModeOn() const;
156 void setInteractionModeOn(bool onoff);
157
158 void setStateCursor(const SbName & state, const QCursor & cursor);
159 QCursor stateCursor(const SbName & state);
160
161 uint32_t getCacheContextId() const;
162
163 virtual void setSceneGraph(SoNode * root);
164 virtual SoNode * getSceneGraph() const;
165
166 void setSoEventManager(SoEventManager * manager);
167 SoEventManager * getSoEventManager() const;
168
169 void setSoRenderManager(SoRenderManager * manager);
170 SoRenderManager * getSoRenderManager() const;
171
172 EventFilter * getEventFilter() const;
173
174 void addStateMachine(SoScXMLStateMachine * statemachine);
175 void removeStateMachine(SoScXMLStateMachine * statemachine);
176
177 virtual bool processSoEvent(const SoEvent * event);
178 QSize minimumSizeHint() const override;
179
180 QList<QAction *> transparencyTypeActions() const;
181 QList<QAction *> stereoModeActions() const;
182 QList<QAction *> renderModeActions() const;
183
184 public Q_SLOTS:
185 virtual void viewAll();
186 virtual void seek();
187
188 void redraw();
189
190 void setRenderMode(SIM::Coin3D::Quarter::QuarterWidget::RenderMode mode);
191 void setStereoMode(SIM::Coin3D::Quarter::QuarterWidget::StereoMode mode);
192 void setTransparencyType(SIM::Coin3D::Quarter::QuarterWidget::TransparencyType type);
193
194 Q_SIGNALS:
195 void devicePixelRatioChanged(qreal dev_pixel_ratio);
196
197 private Q_SLOTS:
198 void replaceViewport();
199
200 protected:
201 void paintEvent(QPaintEvent*) override;
202 void resizeEvent(QResizeEvent*) override;
203 bool viewportEvent(QEvent* event) override;
204 virtual void actualRedraw();
205 virtual bool updateDevicePixelRatio();
206
207 private:
208 void constructor(const QSurfaceFormat& format, const QOpenGLWidget* sharewidget);
209 friend class QuarterWidgetP;
210 class QuarterWidgetP * pimpl;
211 bool initialized;
212 };
213
214 }}} // namespace
215
216 #endif // QUARTER_QUARTERWIDGET_H