File: mainwindow.cpp

package info (click to toggle)
pivy 0.6.10-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,216 kB
  • sloc: python: 36,331; cpp: 787; ansic: 733; makefile: 30; sh: 27; objc: 5
file content (67 lines) | stat: -rw-r--r-- 2,015 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "mainwindow.h"
#include <Inventor/nodes/SoSeparator.h>
#include <Inventor/nodes/SoRotationXYZ.h>
#include <Inventor/nodes/SoMaterial.h>
#include <Inventor/nodes/SoCone.h>
#include <Inventor/engines/SoGate.h>
#include <Inventor/engines/SoElapsedTime.h>
#include <Inventor/fields/SoMFFloat.h>
#include <Inventor/Qt/viewers/SoQtExaminerViewer.h>
#include <QButtonGroup>
#include <stdlib.h>

MainWindow::MainWindow(QWidget *parent)
  :QMainWindow(parent)
{
  setupUi(this);
  QButtonGroup *buttonGroup = new QButtonGroup(this->groupBox);
  buttonGroup->addButton(this->button_x, 0);
  buttonGroup->addButton(this->button_y, 1);
  buttonGroup->addButton(this->button_z, 2);
  QObject::connect(buttonGroup, SIGNAL(buttonClicked(int)), this, SLOT(change_axis(int)));
  QObject::connect(this->button, SIGNAL(clicked()), this, SLOT(change_color()));
  QObject::connect(this->checkbox, SIGNAL(clicked()), this, SLOT(rotate()));
  
  setupSoQt();
}

void
MainWindow::change_axis(int axis)
{
  this->rotxyz->axis = axis;
}

void
MainWindow::change_color()
{
  this->material->diffuseColor = SbColor(1.0f*(random()%256)/255,
                                         1.0f*(random()%256)/255,
                                         1.0f*(random()%256)/255);
}

void
MainWindow::rotate()
{
  this->gate->enable = !this->gate->enable.getValue();
}

void
MainWindow::setupSoQt()
{
  SoSeparator *root = new SoSeparator();
  this->rotxyz = new SoRotationXYZ();
  this->gate = new SoGate(SoMFFloat::getClassTypeId());
  SoElapsedTime *elapsedTime = new SoElapsedTime();
  this->gate->enable = false;
  this->gate->input->connectFrom(&elapsedTime->timeOut);
  this->rotxyz->angle.connectFrom(this->gate->output);
  this->material = new SoMaterial();
  this->material->diffuseColor = SbColor(0.0, 1.0, 1.0);
  SoCone *cone = new SoCone();
  root->addChild(this->rotxyz);
  root->addChild(this->material);
  root->addChild(cone);
    
  this->exam = new SoQtExaminerViewer(this->examiner);
  this->exam->setSceneGraph(root);
}