ObjectPreviewViewer.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2012-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 MemoryX::gui-plugins::SceneEditor
19  * @date 2015
20  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
21  * GNU General Public License
22  */
23 
24 #include "ObjectPreviewViewer.h"
25 
26 #include <Inventor/events/SoMouseButtonEvent.h>
27 
29  QWidget* widget) :
30  SoQtExaminerViewer(widget), control(control)
31 {
32  //Viewer stuff
33  this->setBackgroundColor(SbColor(100 / 255.0f, 100 / 255.0f, 100 / 255.0f));
34  this->setAccumulationBuffer(false);
35  this->setHeadlight(true);
36  this->setViewing(false);
37  this->setDecoration(false);
38 #ifdef WIN32
39 #ifndef _DEBUG
40  this->setAntialiasing(true, 4);
41 #endif
42 #endif
43  this->setTransparencyType(SoGLRenderAction::SORTED_OBJECT_BLEND);
44  this->setFeedbackVisibility(false);
45 
46  //Set up scene
47  SoSeparator* root = new SoSeparator;
48  rotation = new SoRotationXYZ;
49  rotation->axis = SoRotationXYZ::Y;
50  previewRoot = new SoSeparator;
51  root->addChild(rotation);
52  root->addChild(previewRoot);
53  this->setSceneGraph(root);
54 
55  //Setting up sensor
56  timer.reset(new SoTimerSensor);
57  timer->setFunction(timeSensorCallback);
58  timer->setData(this);
59  timer->setBaseTime(SbTime::getTimeOfDay());
60  timer->setInterval(0.02f);
61  timer->schedule();
62 }
63 
64 void
66 {
67  previewRoot->removeAllChildren();
68  previewRoot->addChild(object);
69 }
70 
71 void
73 {
74  previewRoot->removeAllChildren();
75 }
76 
77 //Override the default navigation behaviour of the SoQtExaminerViewer
78 SbBool
79 scene3D::ObjectPreviewViewer::processSoEvent(const SoEvent* const event)
80 {
81  //Ignore everything
82  return TRUE;
83 }
84 
85 void
86 scene3D::ObjectPreviewViewer::timeSensorCallback(void* data, SoSensor* sensor)
87 {
88  ObjectPreviewViewer* viewer = (ObjectPreviewViewer*)data;
89 
90  if (viewer->previewRoot->getNumChildren() > 0)
91  {
92  viewer->rotation->angle.setValue(viewer->rotation->angle.getValue() + 0.01f);
93  viewer->getCamera()->viewAll(viewer->getSceneGraph(), viewer->getViewportRegion());
94  }
95 }
scene3D::ObjectPreviewViewer::showNoObject
void showNoObject()
Definition: ObjectPreviewViewer.cpp:72
scene3D::ObjectPreviewViewer::setObjectToDisplay
void setObjectToDisplay(SoNode *object)
Definition: ObjectPreviewViewer.cpp:65
scene3D::ObjectPreviewViewer::ObjectPreviewViewer
ObjectPreviewViewer(const controller::ControllerPtr &control, QWidget *widget)
Constructor Creates an Instance of the Class.
Definition: ObjectPreviewViewer.cpp:28
controller::ControllerPtr
std::shared_ptr< Controller > ControllerPtr
Definition: ClassDefinitions.h:41
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
ObjectPreviewViewer.h
control
This file is part of ArmarX.