Display.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package
19 * @author
20 * @date
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24#include "Display.h"
25
26#include <QGridLayout>
27
28#include <Inventor/events/SoLocation2Event.h>
29#include <Inventor/events/SoMouseButtonEvent.h>
30#include <Inventor/nodes/SoDrawStyle.h>
31#include <Inventor/nodes/SoLineSet.h>
32#include <Inventor/nodes/SoMaterial.h>
33#include <Inventor/nodes/SoPickStyle.h>
34#include <Inventor/nodes/SoSeparator.h>
35#include <Inventor/nodes/SoVertexProperty.h>
36
37namespace visionx
38{
39 DisplayWidget::DisplayWidget(QWidget* parent) : QWidget(parent)
40
41 {
42 this->setContentsMargins(1, 1, 1, 1);
43
44 QGridLayout* grid = new QGridLayout(this);
45 grid->setContentsMargins(0, 0, 0, 0);
46 this->setLayout(grid);
47 this->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
48
49 QWidget* view1 = new QWidget(this);
50 view1->setMinimumSize(100, 100);
51 view1->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
52
53 display = new Display(view1);
54 display->show();
55
56 grid->addWidget(view1, 0, 0, 1, 2);
57 }
58
60 {
61
62 delete display;
63 }
64
65 Display*
67 {
68 return display;
69 }
70
71 Display::Display(QWidget* widget) :
72 SoQtExaminerViewer(widget),
73 sceneRootNode(new SoSeparator),
74 contentRootNode(new SoSeparator),
75 camera(new SoPerspectiveCamera)
76 {
77 this->setBackgroundColor(SbColor(80 / 255.0f, 80 / 255.0f, 80 / 255.0f));
78 this->setAccumulationBuffer(false);
79 this->setHeadlight(true);
80 this->setViewing(true);
81 this->setDecoration(false);
82
83 this->setTransparencyType(SoGLRenderAction::SORTED_OBJECT_BLEND);
84 this->setFeedbackVisibility(true);
85
86 //Create scene root node
87 sceneRootNode->ref();
88 this->setSceneGraph(sceneRootNode);
89
90 //Add camera to scene
91 sceneRootNode->addChild(camera);
92 this->setCamera(camera);
93
94 //Give camera standard position
95 camera->position.setValue(SbVec3f(10, -10, 5));
96 camera->pointAt(SbVec3f(0, 0, 0), SbVec3f(0, 0, 1));
97
98 //Add content node
99 sceneRootNode->addChild(this->contentRootNode);
100 }
101
103 {
104 if (sceneRootNode)
105 {
106 sceneRootNode->unref();
107 }
108 }
109
110 SoSeparator*
112 {
113 return this->contentRootNode;
114 }
115
116 void
118 {
119 camera->viewAll(this->contentRootNode, SbViewportRegion());
120 }
121
122 /*
123 //Override the default navigation behaviour of the SoQtExaminerViewer
124 SbBool Display::processSoEvent(const SoEvent* const event)
125 {
126 const SoType type(event->getTypeId());
127
128 //Remapping mouse press events
129 if (type.isDerivedFrom(SoMouseButtonEvent::getClassTypeId()))
130 {
131 SoMouseButtonEvent* const ev = (SoMouseButtonEvent*) event;
132 const int button = ev->getButton();
133 const SbBool press = ev->getState() == SoButtonEvent::DOWN ? TRUE : FALSE;
134
135 //LEFT MOUSE BUTTON
136 if (button == SoMouseButtonEvent::BUTTON1)
137 {
138 //Enable or disable viewing mode while BUTTON1 pressed
139 if (press)
140 {
141 if (!this->isViewing())
142 {
143 this->setViewing(true);
144 }
145 }
146 else
147 {
148 if (this->isViewing())
149 {
150 this->setViewing(false);
151 }
152 }
153
154 if (this->isViewing())
155 {
156 return SoQtExaminerViewer::processSoEvent(ev);
157 }
158 }
159
160 //MOUSE WHEEL UP AND DOWN
161 if (button == SoMouseButtonEvent::BUTTON4 || button == SoMouseButtonEvent::BUTTON5)
162 {
163 //Zooming is allowed, so just use it. We have to temporarily turn viewing mode
164 // on to make SoQtExaminerViewer allow zooming.
165
166 //Swap BUTTON4 and BUTTON5 because zooming out while scrolling up is just retarded
167 ev->setButton(button == SoMouseButtonEvent::BUTTON4 ?
168 SoMouseButtonEvent::BUTTON5 : SoMouseButtonEvent::BUTTON4);
169
170 //Zooming is allowed, so just pass it and temporarily set viewing mode on, if it is not already
171 //(otherwise coin gives us warning messages...)
172 if (!this->isViewing())
173 {
174 if (!this->isViewing())
175 {
176 this->setViewing(true);
177 }
178
179 SoQtExaminerViewer::processSoEvent(ev);
180
181 if (this->isViewing())
182 {
183 this->setViewing(false);
184 }
185 }
186 else
187 {
188 SoQtExaminerViewer::processSoEvent(ev);
189 }
190
191 return TRUE;
192 }
193 }
194
195 // Keyboard handling
196 if (type.isDerivedFrom(SoKeyboardEvent::getClassTypeId()))
197 {
198 const SoKeyboardEvent* const ev = (const SoKeyboardEvent*) event;
199
200 //The escape key and super key (windows key) is used to switch between
201 // viewing modes. We need to disable this behaviour completely.
202
203 //65513 seems to be the super key, which is not available in the enum of keys in coin....
204 if (ev->getKey() == SoKeyboardEvent::ESCAPE || ev->getKey() == 65513)
205 {
206 return TRUE;
207 }
208 else if (ev->getKey() == SoKeyboardEvent::S && ev->getState() == SoButtonEvent::DOWN)
209 {
210 if (!this->isSeekMode())
211 {
212 if (!this->isViewing())
213 {
214 this->setViewing(true);
215 }
216
217 SoQtExaminerViewer::processSoEvent(ev);
218 this->setSeekTime(0.5);
219 this->seekToPoint(ev->getPosition());
220
221 if (this->isViewing())
222 {
223 this->setViewing(false);
224 }
225 }
226 }
227 else if (ev->getKey() == SoKeyboardEvent::R && ev->getState() == SoButtonEvent::DOWN)
228 {
229 camera->viewAll(this->contentRootNode, SbViewportRegion());
230 }
231 else
232 {
233 SoQtExaminerViewer::processSoEvent(ev);
234 }
235
236 SoQtExaminerViewer::processSoEvent(ev);
237 }
238
239
240 if (type.isDerivedFrom(SoLocation2Event::getClassTypeId()))
241 {
242 return SoQtExaminerViewer::processSoEvent(event);
243 }
244
245 //YOU SHALL NOT PASS!
246 return TRUE;
247
248 return SoQtExaminerViewer::processSoEvent(event);
249 }
250
251 */
252} // namespace visionx
Display * getDisplay()
Definition Display.cpp:66
~DisplayWidget() override
Definition Display.cpp:59
DisplayWidget(QWidget *parent=0)
Definition Display.cpp:39
~Display() override
Definition Display.cpp:102
void cameraViewAll()
Definition Display.cpp:117
Display(QWidget *widget)
Definition Display.cpp:71
SoSeparator * getRootNode()
Definition Display.cpp:111
ArmarX headers.