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 #include <Inventor/events/SoMouseButtonEvent.h>
26 
28 {
29  //Viewer stuff
30  this->setBackgroundColor(SbColor(100 / 255.0f, 100 / 255.0f, 100 / 255.0f));
31  this->setAccumulationBuffer(false);
32  this->setHeadlight(true);
33  this->setViewing(false);
34  this->setDecoration(false);
35 #ifdef WIN32
36 #ifndef _DEBUG
37  this->setAntialiasing(true, 4);
38 #endif
39 #endif
40  this->setTransparencyType(SoGLRenderAction::SORTED_OBJECT_BLEND);
41  this->setFeedbackVisibility(false);
42 
43  //Set up scene
44  SoSeparator* root = new SoSeparator;
45  rotation = new SoRotationXYZ;
46  rotation->axis = SoRotationXYZ::Y;
47  previewRoot = new SoSeparator;
48  root->addChild(rotation);
49  root->addChild(previewRoot);
50  this->setSceneGraph(root);
51 
52  //Setting up sensor
53  timer.reset(new SoTimerSensor);
54  timer->setFunction(timeSensorCallback);
55  timer->setData(this);
56  timer->setBaseTime(SbTime::getTimeOfDay());
57  timer->setInterval(0.02f);
58  timer->schedule();
59 }
60 
62 {
63  previewRoot->removeAllChildren();
64  previewRoot->addChild(object);
65 }
66 
68 {
69  previewRoot->removeAllChildren();
70 }
71 
72 //Override the default navigation behaviour of the SoQtExaminerViewer
73 SbBool scene3D::ObjectPreviewViewer::processSoEvent(const SoEvent* const event)
74 {
75  //Ignore everything
76  return TRUE;
77 }
78 
79 void scene3D::ObjectPreviewViewer::timeSensorCallback(void* data, SoSensor* sensor)
80 {
81  ObjectPreviewViewer* viewer = (ObjectPreviewViewer*) data;
82 
83  if (viewer->previewRoot->getNumChildren() > 0)
84  {
85  viewer->rotation->angle.setValue(viewer->rotation->angle.getValue() + 0.01f);
86  viewer->getCamera()->viewAll(viewer->getSceneGraph(), viewer->getViewportRegion());
87  }
88 }
scene3D::ObjectPreviewViewer::showNoObject
void showNoObject()
Definition: ObjectPreviewViewer.cpp:67
scene3D::ObjectPreviewViewer::setObjectToDisplay
void setObjectToDisplay(SoNode *object)
Definition: ObjectPreviewViewer.cpp:61
scene3D::ObjectPreviewViewer::ObjectPreviewViewer
ObjectPreviewViewer(const controller::ControllerPtr &control, QWidget *widget)
Constructor Creates an Instance of the Class.
Definition: ObjectPreviewViewer.cpp:27
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.