-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
128 lines (112 loc) · 4.18 KB
/
mainwindow.cpp
File metadata and controls
128 lines (112 loc) · 4.18 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
125
126
127
128
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow), plane(QString()), equals(0), alpha(0), beta(0), gamma(0), currentColor(QColor())
{
ui->setupUi(this);
scene = new Scene();
ui->sceneLayout->addWidget(scene);
ui->horizontalSlider->setMaximum(0);
alpha = 3.0/ui->alphaSpinBox->value();
beta = 2.0/ui->betaSpinBox->value();
gamma = 11.0/ui->gammaSpinBox->value();
QVector<QString> alpha_coef; alpha_coef << "111";
QVector<QString> beta_coef; beta_coef << "110" << "101" << "011";
QVector<QString> gamma_coef; gamma_coef << "113" << "131" << "311";
alphaBox = new MyGroupBox(alpha_coef, "alpha depended", 1, this);
betaBox = new MyGroupBox(beta_coef, "beta depended", 2, this);
gammaBox = new MyGroupBox(gamma_coef, "gamma depended", 3, this);
ui->millerIndecies->addWidget(alphaBox);
ui->millerIndecies->addWidget(betaBox);
ui->millerIndecies->addWidget(gammaBox);
ui->undoButton->setEnabled(false);
ui->clearAllButton->setEnabled(false);
ui->drawButton->setEnabled(false);
connect(alphaBox, SIGNAL(radioButtonSelected(QString,QColor,int)), this, SLOT(clippingPlaneDataSelected(QString,QColor,int)));
connect(betaBox, SIGNAL(radioButtonSelected(QString,QColor,int)), this, SLOT(clippingPlaneDataSelected(QString,QColor,int)));
connect(gammaBox, SIGNAL(radioButtonSelected(QString,QColor,int)), this, SLOT(clippingPlaneDataSelected(QString,QColor,int)));
connect(scene, SIGNAL(clipChanged(int)), this, SLOT(updateSlider(int)));
connect(ui->horizontalSlider, SIGNAL(valueChanged(int)), scene, SLOT(showScene(int)));
}
MainWindow::~MainWindow()
{
delete scene;
delete ui;
}
void MainWindow::on_alphaSpinBox_valueChanged(double arg1)
{
alpha = arg1;
equals = 3.0/(alpha);
}
void MainWindow::on_betaSpinBox_valueChanged(double arg1)
{
beta = arg1;
equals = 2.0/(beta);
}
void MainWindow::on_gammaSpinBox_valueChanged(double arg1)
{
gamma = arg1;
equals = 11.0/(gamma);
}
void MainWindow::clippingPlaneDataSelected(QString str, QColor col, int i)
{
ui->drawButton->setEnabled(true);
switch(i)
{
case 1:
ui->alphaSpinBox->setEnabled(1);
ui->betaSpinBox->setEnabled(0);
ui->gammaSpinBox->setEnabled(0);
betaBox->unSelect();
gammaBox->unSelect();
equals = 3.0 / ui->alphaSpinBox->value();
break;
case 2:
ui->alphaSpinBox->setEnabled(0);
ui->betaSpinBox->setEnabled(1);
ui->gammaSpinBox->setEnabled(0);
equals = 2.0/ui->betaSpinBox->value();
alphaBox->unSelect();
gammaBox->unSelect();
break;
case 3:
ui->alphaSpinBox->setEnabled(0);
ui->betaSpinBox->setEnabled(0);
ui->gammaSpinBox->setEnabled(1);
equals = 11.0/ui->gammaSpinBox->value();
betaBox->unSelect();
alphaBox->unSelect();
break;
}
plane = str;
currentColor = col;
}
void MainWindow::on_drawButton_clicked()
{
ui->undoButton->setEnabled(true);
ui->clearAllButton->setEnabled(true);
array<int, 3> value = {plane[0].digitValue(), plane[1].digitValue(), plane[2].digitValue()};
scene->clipping(value, equals, currentColor);
if(ui->label->text().isEmpty()) { ui->label->setText(tr("<font color = '%1'>{%2}</font>").arg(currentColor.name()).arg(plane)); return; }
ui->label->setText(ui->label->text() + tr(" + <font color = '%1'>{%2}</font>").arg(currentColor.name()).arg(plane));
}
void MainWindow::on_clearAllButton_clicked()
{
scene->clearAll();
ui->label->clear();
}
void MainWindow::on_undoButton_clicked()
{
scene->undo();
QStringList list = ui->label->text().split("+");
list.removeLast();
ui->label->clear();
for(auto i : list) ui->label->setText(ui->label->text() + i);
}
void MainWindow::updateSlider(int value)
{
if(value == 0 ) { ui->undoButton->setEnabled(false); ui->clearAllButton->setEnabled(false); }
ui->horizontalSlider->setMaximum(value);
ui->horizontalSlider->setValue(value);
}