1 #include "mainwindow.h"
2 #include <Inventor/nodes/SoSeparator.h>
3 #include <Inventor/nodes/SoRotationXYZ.h>
4 #include <Inventor/nodes/SoMaterial.h>
5 #include <Inventor/nodes/SoCone.h>
6 #include <Inventor/engines/SoGate.h>
7 #include <Inventor/engines/SoElapsedTime.h>
8 #include <Inventor/fields/SoMFFloat.h>
9 #include <Inventor/Qt/viewers/SoQtExaminerViewer.h>
10 #include <QButtonGroup>
11 #include <stdlib.h>
12 
MainWindow(QWidget * parent)13 MainWindow::MainWindow(QWidget *parent)
14   :QMainWindow(parent)
15 {
16   setupUi(this);
17   QButtonGroup *buttonGroup = new QButtonGroup(this->groupBox);
18   buttonGroup->addButton(this->button_x, 0);
19   buttonGroup->addButton(this->button_y, 1);
20   buttonGroup->addButton(this->button_z, 2);
21   QObject::connect(buttonGroup, SIGNAL(buttonClicked(int)), this, SLOT(change_axis(int)));
22   QObject::connect(this->button, SIGNAL(clicked()), this, SLOT(change_color()));
23   QObject::connect(this->checkbox, SIGNAL(clicked()), this, SLOT(rotate()));
24 
25   setupSoQt();
26 }
27 
28 void
change_axis(int axis)29 MainWindow::change_axis(int axis)
30 {
31   this->rotxyz->axis = axis;
32 }
33 
34 void
change_color()35 MainWindow::change_color()
36 {
37   this->material->diffuseColor = SbColor(1.0f*(random()%256)/255,
38                                          1.0f*(random()%256)/255,
39                                          1.0f*(random()%256)/255);
40 }
41 
42 void
rotate()43 MainWindow::rotate()
44 {
45   this->gate->enable = !this->gate->enable.getValue();
46 }
47 
48 void
setupSoQt()49 MainWindow::setupSoQt()
50 {
51   SoSeparator *root = new SoSeparator();
52   this->rotxyz = new SoRotationXYZ();
53   this->gate = new SoGate(SoMFFloat::getClassTypeId());
54   SoElapsedTime *elapsedTime = new SoElapsedTime();
55   this->gate->enable = false;
56   this->gate->input->connectFrom(&elapsedTime->timeOut);
57   this->rotxyz->angle.connectFrom(this->gate->output);
58   this->material = new SoMaterial();
59   this->material->diffuseColor = SbColor(0.0, 1.0, 1.0);
60   SoCone *cone = new SoCone();
61   root->addChild(this->rotxyz);
62   root->addChild(this->material);
63   root->addChild(cone);
64 
65   this->exam = new SoQtExaminerViewer(this->examiner);
66   this->exam->setSceneGraph(root);
67 }
68