-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
124 lines (97 loc) · 3.68 KB
/
mainwindow.cpp
File metadata and controls
124 lines (97 loc) · 3.68 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <iostream>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
qOsg = new QtOSGWidget(1,1,this);
ui->setupUi(this);
ui->verticalLayout_2->addWidget(qOsg);
this->setWindowTitle(QString("Qt osg step Viewer"));
resize(1024,768);
connect(qOsg,SIGNAL(orientationChanged(std::vector<double>)),this,SLOT(changedOrientation(std::vector<double>)));
connect(this,SIGNAL(colorChanged(QColor)),qOsg,SLOT(changedColor(QColor)));
connect(this,SIGNAL(openFile(std::string)),qOsg,SLOT(openScene(std::string)));
connect(this,SIGNAL(saveFile(std::string)),qOsg,SLOT(saveScene(std::string)));
connect(ui->height_value,SIGNAL(valueChanged(double)),this,SLOT(updateBottle()));
connect(ui->width_value,SIGNAL(valueChanged(double)),this,SLOT(updateBottle()));
connect(ui->thickness_value,SIGNAL(valueChanged(double)),this,SLOT(updateBottle()));
connect(ui->red_slider,SIGNAL(sliderMoved(int)),this,SLOT(changedR(int)));
connect(ui->green_slider,SIGNAL(sliderMoved(int)),this,SLOT(changedG(int)));
connect(ui->blue_slider,SIGNAL(sliderMoved(int)),this,SLOT(changedB(int)));
connect(ui->actionOpen,SIGNAL(triggered(bool)),this,SLOT(createFileDialog()));
connect(ui->actionsave,SIGNAL(triggered(bool)),this,SLOT(saveFileDialog()));
//qOsg->addScene(createScene());
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::changedOrientation(std::vector<double> values)
{
ui->eye_x->setText(QString::number(values[0]));
ui->eye_y->setText(QString::number(values[1]));
ui->eye_z->setText(QString::number(values[2]));
ui->center_x->setText(QString::number(values[3]));
ui->center_y->setText(QString::number(values[4]));
ui->center_z->setText(QString::number(values[5]));
ui->up_x->setText(QString::number(values[6]));
ui->up_y->setText(QString::number(values[7]));
ui->up_z->setText(QString::number(values[8]));
}
void MainWindow::changedR(int value)
{
_color.setRed(value);
_color.setAlpha(255);
emit colorChanged(_color);
}
void MainWindow::changedG(int value)
{
_color.setGreen(value);
_color.setAlpha(255);
emit colorChanged(_color);
}
void MainWindow::changedB(int value)
{
_color.setBlue(value);
_color.setAlpha(255);
emit colorChanged(_color);
}
void MainWindow::createFileDialog()
{
QFileDialog fileDialog(this);
fileDialog.setFileMode(QFileDialog::AnyFile);
fileDialog.setViewMode(QFileDialog::Detail);
QStringList fileNames;
if (fileDialog.exec())
if(fileDialog.selectedFiles().size() != 0)
{
fileNames = fileDialog.selectedFiles();
QString filePath = fileNames.first();
emit openFile(std::string(filePath.toUtf8().constData()));
}
}
void MainWindow::saveFileDialog()
{
QFileDialog fileDialog(this);
fileDialog.setAcceptMode(QFileDialog::AcceptSave);
fileDialog.setFileMode(QFileDialog::AnyFile);
fileDialog.setViewMode(QFileDialog::Detail);
QStringList fileNames;
if (fileDialog.exec())
fileNames = fileDialog.selectedFiles();
QString filePath = fileNames.first();
emit saveFile(std::string(filePath.toUtf8().constData()));
}
void MainWindow::updateBottle()
{
osg::ref_ptr<osg::Group> root;
osg::ref_ptr<osg::Geode> bottle;
double mythickness = ui->thickness_value->value();
double mywidth = ui->width_value->value();
double myheight = ui->height_value->value();
osg::Vec3 myColor = osg::Vec3( 1.0f, 1.0f, 1.0f );
qOsg->getScene()->removeChild(0,1);
qOsg->getScene()->addChild(createBottle(mywidth,myheight,mythickness,myColor/*,viewMatrix*/));
}