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/nodes/SoSeparator.h>
29 #include <Inventor/nodes/SoPickStyle.h>
30 #include <Inventor/nodes/SoMaterial.h>
31 #include <Inventor/nodes/SoDrawStyle.h>
32 #include <Inventor/nodes/SoVertexProperty.h>
33 #include <Inventor/nodes/SoLineSet.h>
34 #include <Inventor/events/SoMouseButtonEvent.h>
35 #include <Inventor/events/SoLocation2Event.h>
36 
37 namespace 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 
66  {
67  return display;
68  }
69 
70  Display::Display(QWidget* widget) : SoQtExaminerViewer(widget), sceneRootNode(new SoSeparator), contentRootNode(new SoSeparator), camera(new SoPerspectiveCamera)
71  {
72  this->setBackgroundColor(SbColor(80 / 255.0f, 80 / 255.0f, 80 / 255.0f));
73  this->setAccumulationBuffer(false);
74  this->setHeadlight(true);
75  this->setViewing(true);
76  this->setDecoration(false);
77 
78  this->setTransparencyType(SoGLRenderAction::SORTED_OBJECT_BLEND);
79  this->setFeedbackVisibility(true);
80 
81  //Create scene root node
82  sceneRootNode->ref();
83  this->setSceneGraph(sceneRootNode);
84 
85  //Add camera to scene
86  sceneRootNode->addChild(camera);
87  this->setCamera(camera);
88 
89  //Give camera standard position
90  camera->position.setValue(SbVec3f(10, -10, 5));
91  camera->pointAt(SbVec3f(0, 0, 0), SbVec3f(0, 0, 1));
92 
93  //Add content node
94  sceneRootNode->addChild(this->contentRootNode);
95  }
96 
98  {
99  if (sceneRootNode)
100  {
101  sceneRootNode->unref();
102  }
103  }
104 
105  SoSeparator* Display::getRootNode()
106  {
107  return this->contentRootNode;
108  }
109 
111  {
112  camera->viewAll(this->contentRootNode, SbViewportRegion());
113  }
114 
115  /*
116  //Override the default navigation behaviour of the SoQtExaminerViewer
117  SbBool Display::processSoEvent(const SoEvent* const event)
118  {
119  const SoType type(event->getTypeId());
120 
121  //Remapping mouse press events
122  if (type.isDerivedFrom(SoMouseButtonEvent::getClassTypeId()))
123  {
124  SoMouseButtonEvent* const ev = (SoMouseButtonEvent*) event;
125  const int button = ev->getButton();
126  const SbBool press = ev->getState() == SoButtonEvent::DOWN ? TRUE : FALSE;
127 
128  //LEFT MOUSE BUTTON
129  if (button == SoMouseButtonEvent::BUTTON1)
130  {
131  //Enable or disable viewing mode while BUTTON1 pressed
132  if (press)
133  {
134  if (!this->isViewing())
135  {
136  this->setViewing(true);
137  }
138  }
139  else
140  {
141  if (this->isViewing())
142  {
143  this->setViewing(false);
144  }
145  }
146 
147  if (this->isViewing())
148  {
149  return SoQtExaminerViewer::processSoEvent(ev);
150  }
151  }
152 
153  //MOUSE WHEEL UP AND DOWN
154  if (button == SoMouseButtonEvent::BUTTON4 || button == SoMouseButtonEvent::BUTTON5)
155  {
156  //Zooming is allowed, so just use it. We have to temporarily turn viewing mode
157  // on to make SoQtExaminerViewer allow zooming.
158 
159  //Swap BUTTON4 and BUTTON5 because zooming out while scrolling up is just retarded
160  ev->setButton(button == SoMouseButtonEvent::BUTTON4 ?
161  SoMouseButtonEvent::BUTTON5 : SoMouseButtonEvent::BUTTON4);
162 
163  //Zooming is allowed, so just pass it and temporarily set viewing mode on, if it is not already
164  //(otherwise coin gives us warning messages...)
165  if (!this->isViewing())
166  {
167  if (!this->isViewing())
168  {
169  this->setViewing(true);
170  }
171 
172  SoQtExaminerViewer::processSoEvent(ev);
173 
174  if (this->isViewing())
175  {
176  this->setViewing(false);
177  }
178  }
179  else
180  {
181  SoQtExaminerViewer::processSoEvent(ev);
182  }
183 
184  return TRUE;
185  }
186  }
187 
188  // Keyboard handling
189  if (type.isDerivedFrom(SoKeyboardEvent::getClassTypeId()))
190  {
191  const SoKeyboardEvent* const ev = (const SoKeyboardEvent*) event;
192 
193  //The escape key and super key (windows key) is used to switch between
194  // viewing modes. We need to disable this behaviour completely.
195 
196  //65513 seems to be the super key, which is not available in the enum of keys in coin....
197  if (ev->getKey() == SoKeyboardEvent::ESCAPE || ev->getKey() == 65513)
198  {
199  return TRUE;
200  }
201  else if (ev->getKey() == SoKeyboardEvent::S && ev->getState() == SoButtonEvent::DOWN)
202  {
203  if (!this->isSeekMode())
204  {
205  if (!this->isViewing())
206  {
207  this->setViewing(true);
208  }
209 
210  SoQtExaminerViewer::processSoEvent(ev);
211  this->setSeekTime(0.5);
212  this->seekToPoint(ev->getPosition());
213 
214  if (this->isViewing())
215  {
216  this->setViewing(false);
217  }
218  }
219  }
220  else if (ev->getKey() == SoKeyboardEvent::R && ev->getState() == SoButtonEvent::DOWN)
221  {
222  camera->viewAll(this->contentRootNode, SbViewportRegion());
223  }
224  else
225  {
226  SoQtExaminerViewer::processSoEvent(ev);
227  }
228 
229  SoQtExaminerViewer::processSoEvent(ev);
230  }
231 
232 
233  if (type.isDerivedFrom(SoLocation2Event::getClassTypeId()))
234  {
235  return SoQtExaminerViewer::processSoEvent(event);
236  }
237 
238  //YOU SHALL NOT PASS!
239  return TRUE;
240 
241  return SoQtExaminerViewer::processSoEvent(event);
242  }
243 
244  */
245 }
visionx::Display
Definition: Display.h:36
visionx::Display::Display
Display(QWidget *widget)
Definition: Display.cpp:70
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::DisplayWidget::DisplayWidget
DisplayWidget(QWidget *parent=0)
Definition: Display.cpp:39
visionx::Display::getRootNode
SoSeparator * getRootNode()
Definition: Display.cpp:105
visionx::Display::~Display
~Display() override
Definition: Display.cpp:97
Display.h
visionx::DisplayWidget::getDisplay
Display * getDisplay()
Definition: Display.cpp:65
visionx::DisplayWidget::~DisplayWidget
~DisplayWidget() override
Definition: Display.cpp:59
visionx::Display::cameraViewAll
void cameraViewAll()
Definition: Display.cpp:110