-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrid_window.C
More file actions
174 lines (158 loc) · 4.33 KB
/
grid_window.C
File metadata and controls
174 lines (158 loc) · 4.33 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# include <grid_window.H>
Grid_Window::Grid_Window(QWidget * parent) :
QWidget(parent), simulator(NULL), editable(true), routing_algorithm(A_Minimum_Deflection)
{
conf = Configuration::get_instance();
try
{
conf->load();
}
catch(...)
{
conf->save();
}
ui.setupUi(this);
simulator = new Simulator();
panel = new Grid_Panel(simulator->get_grid(), this);
ui.vlayout->addWidget(panel, Qt::AlignCenter);
panel->add_listener(this);
simulator->add_listener(this);
connect(ui.chk_in, SIGNAL(clicked()), this, SLOT(check_in_clicked()));
connect(ui.chk_out, SIGNAL(clicked()), this, SLOT(check_out_clicked()));
connect(ui.btn_start, SIGNAL(clicked()), this, SLOT(execute()));
connect(ui.btn_configure, SIGNAL(clicked()), this, SLOT(configure()));
connect(ui.btn_statistics, SIGNAL(clicked()), this, SLOT(view_statistics()));
}
Grid_Window::~Grid_Window()
{
delete simulator;
}
void Grid_Window::panel_clicked()
{
if (not editable)
return;
Grid::Node * s = panel->get_selected();
if (s == NULL)
{
ui.chk_in->setChecked(false);
ui.chk_in->setEnabled(false);
ui.chk_out->setChecked(false);
ui.chk_out->setEnabled(false);
}
else
{
ui.chk_in->setChecked(s->is_in());
ui.chk_in->setEnabled(true);
ui.chk_out->setChecked(s->is_out());
ui.chk_out->setEnabled(true);
}
}
void Grid_Window::check_in_clicked()
{
Grid::Node * s = panel->get_selected();
s->is_in() = ui.chk_in->isChecked();
if (s->is_in())
simulator->add_entrance(s);
else
simulator->remove_entrance(s);
panel->update();
}
void Grid_Window::check_out_clicked()
{
Grid::Node * s = panel->get_selected();
s->is_out() = ui.chk_out->isChecked();
if (s->is_out())
simulator->add_exit(s);
else
simulator->remove_exit(s);
panel->update();
}
void Grid_Window::step()
{
panel->update();
}
void Grid_Window::start()
{
editable = false;
ui.btn_start->setEnabled(false);
ui.chk_in->setEnabled(false);
ui.chk_out->setEnabled(false);
ui.btn_configure->setEnabled(false);
ui.btn_statistics->setEnabled(false);
}
void Grid_Window::stop()
{
editable = true;
ui.btn_start->setEnabled(true);
ui.btn_configure->setEnabled(true);
ui.btn_statistics->setEnabled(true);
ui.chk_in->setEnabled(panel->get_selected() != NULL);
ui.chk_out->setEnabled(panel->get_selected() != NULL);
}
void Grid_Window::execute()
{
try
{
switch (routing_algorithm)
{
case A_Minimum_Deflection:
simulator->step<Minimum_Deflection>();
break;
default:
QMessageBox::critical(this,
"Error",
"Algoritmo de enrutamiento invalido");
}
QMessageBox::information(this,
"Trabajo realizado",
"La corrida de la simulacion ha finalizado, haga click en el boton estadisticas para ver los resultados");
}
catch(const std::exception & e)
{
QMessageBox::critical(this, "Error", e.what());
}
}
void Grid_Window::configure()
{
conf_panel = new Configuration_Panel(this);
connect(conf_panel, SIGNAL(change()), this, SLOT(configuration_changed()));
editable = false;
ui.btn_start->setEnabled(false);
ui.chk_in->setEnabled(false);
ui.chk_out->setEnabled(false);
ui.btn_configure->setEnabled(false);
conf_panel->show();
}
void Grid_Window::configuration_changed()
{
delete simulator;
simulator = new Simulator();
delete panel;
panel = new Grid_Panel(simulator->get_grid());
ui.vlayout->addWidget(panel, Qt::AlignCenter);
panel->add_listener(this);
simulator->add_listener(this);
ui.btn_statistics->setEnabled(false);
}
void Grid_Window::view_statistics()
{
stat_panel = new Statistics_Panel(simulator->get_grid(), simulator->get_packages_list(), this);
editable = false;
ui.btn_start->setEnabled(false);
ui.chk_in->setEnabled(false);
ui.chk_out->setEnabled(false);
ui.btn_configure->setEnabled(false);
ui.btn_statistics->setEnabled(false);
stat_panel->show();
}
void Grid_Window::closeEvent(QCloseEvent * evt)
{
if (QMessageBox::question(this,
QString("Seguridad"),
QString("Seguro que desea salir?"),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
{
evt->ignore();
return;
}
}