This repository has been archived by the owner on Sep 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makerdialog.cpp
114 lines (98 loc) · 2.37 KB
/
makerdialog.cpp
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
#include "makerdialog.h"
#include "ui_makerdialog.h"
#include <QtWidgets/QPushButton>
#include <QPainter>
#include <memory.h>
#include <QProcess>
#include "faultformation.h"
#include "platedrift.h"
MakerDialog::MakerDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::MakerDialog)
{
ui->setupUi(this);
modeling = new FaultFormation(terrain);
connect(ui->btn_init, SIGNAL(clicked()), this, SLOT(btn_init_clicked()));
connect(ui->btn_start, SIGNAL(clicked()), this, SLOT(btn_start_clicked()));
connect(ui->btn_step, SIGNAL(clicked()), this, SLOT(btn_step_clicked()));
connect(ui->btn_erosion, SIGNAL(clicked()), this, SLOT(btn_erosion_clicked()));
connect(ui->btn_save, SIGNAL(clicked()), this, SLOT(btn_save_clicked()));
connect(ui->btn_run, SIGNAL(clicked()), this, SLOT(btn_run_clicked()));
QImage gi("grey.bmp", "bmp");
greyimage = gi.scaled(w, h);
greyimage.fill(0);
}
MakerDialog::~MakerDialog()
{
delete ui;
}
void MakerDialog::btn_init_clicked()
{
terrain.reset();
updateimage();
}
void MakerDialog::btn_start_clicked()
{
if(modeling)
{
modeling->start();
updateimage();
}
}
void MakerDialog::btn_step_clicked()
{
if(modeling)
{
modeling->step();
updateimage();
}
}
void MakerDialog::btn_erosion_clicked()
{
if(modeling)
{
modeling->erosion();
updateimage();
}
}
void MakerDialog::btn_save_clicked()
{
greyimage.save("terrainmake.bmp","bmp");
}
void MakerDialog::btn_run_clicked()
{
greyimage.save("terrainmake.bmp","bmp");
QProcess::startDetached("terraintest.exe",QStringList());
}
void MakerDialog::updateimage()
{
for(unsigned int j = 0;j < terrain.getHeight();j++)
{
for(unsigned int i = 0;i < terrain.getWidth();i++)
{
greyimage.setPixel(i, j, (unsigned char)terrain.getData()[j*terrain.getWidth() + i]);
}
}
this->update();
}
void MakerDialog::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.drawImage(200, 200, greyimage);
}
void MakerDialog::setModeling(TerrainModeling *newmodeling)
{
if(modeling != nullptr)
{
delete modeling;
}
modeling = newmodeling;
}
void MakerDialog::on_rdb_fault_clicked()
{
setModeling(new FaultFormation(terrain));
}
void MakerDialog::on_rdb_plate_clicked()
{
setModeling(new PlateDrift(terrain));
}