-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmainwindow.cpp
executable file
·408 lines (344 loc) · 14.4 KB
/
mainwindow.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
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QGraphicsItem>
#include <QDebug>
#include <stdlib.h>
#include <QMessageBox>
#define RD 0
#define EXTRA 2*R+15
#define DOT 10
#define EXR 5.4
#include "timer.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
QApplication::setStyle("macintosh");
ui->setupUi(this);
// this->setStyleSheet("background-color:gray;");
this->setMinimumSize(1621,924);
this->setMaximumSize(1621,924);
QPen blackPen(Qt::black);
blackPen.setWidth(0.5);
scene = new QGraphicsScene(this);
ui->graphicsView->setScene(scene);
// this->_addLineGraph();
setYouhua = new self_youhua;
hasSet=false;
out = "";
m=1;n=0;
qDebug()<<"---未来无线网络自优化演示软件平台---"<<endl;
QPalette bgpal = palette();
bgpal.setColor (QPalette::Background, QColor (29, 15, 29));
//bgpal.setColor (QPalette::Background, Qt::transparent);
bgpal.setColor (QPalette::Foreground, QColor(255,255,255,255));
setPalette (bgpal);
introwindow = new introduce;
qDebug()<<"Welcome!"<<endl;
introwindow->exec();
this->ui->graphicsView->setToolTip("<html><font color='red'>test</font></html>");
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::myslots()
{
qDebug()<<"myslots";
}
void MainWindow::_addLineGraph()
{
QPen blackPen(Qt::black);
blackPen.setWidth(0.5);
for(int i=-200;i<200;i++){
scene->addLine(-200*(setAlgo->_x)+2*(setAlgo->ratio),i*(setAlgo->_y)+2*(setAlgo->ratio),200*(setAlgo->_x)+2*(setAlgo->ratio),i*(setAlgo->_y)+2*(setAlgo->ratio),blackPen);
scene->addLine(i*(setAlgo->_x)+2*(setAlgo->ratio),200*(setAlgo->_y)+2*(setAlgo->ratio),i*(setAlgo->_x)+2*(setAlgo->ratio),-200*(setAlgo->_y)+2*(setAlgo->ratio),blackPen);
}
}
void MainWindow::on_tab_destroyed()
{
}
void MainWindow::on_pushButton_clicked()
{
this->scene->clear();
out="自配置\n";
this->ui->textEdit->setText(out);
QBrush redBrush(Qt::red);
QBrush blueBrush(Qt::blue);
QBrush yellowBrush(Qt::yellow);
QPen blackPen(Qt::black);
blackPen.setWidth(0.5);
QPen bluePen(Qt::blue);
bluePen.setWidth(0.5);
self_window = new self_set;
qDebug()<<"Welcome!"<<endl;
self_window->exec();
QDateTime time = QDateTime::currentDateTime();//获取系统现在的时间
QString _time = time.toString("yyyy-MM-dd hh:mm:ss ddd"); //设置显示格式
out=out+_time+"\n";
this->ui->textEdit->setText(out);
qDebug()<<this->self_window->_yes;
setAlgo = new Set_algorithm;
if(this->self_window->_yes==true){
this->ui->textEdit->setText(out);
QString ch = (self_window->choice==1)? "平均SINR最高":"能效比最高";
out=out+"\n自配置参数预制如下:\n-----------------------\n";
out=out+"RESP0:"+QString::number(self_window->RESP0)+"\n"+
"优化标准:"+ch+"\n"+
"路损模型参数:\n"+"a="+QString::number(self_window->a)+" b="+QString::number(self_window->b)+"\n"
+"覆盖率:"+QString::number(self_window->coverRate)+"%\n"+
"额定功率:"+QString::number(self_window->power)+"\n"
+"临界信噪比:"+QString::number(self_window->SINR)+"\n"+
"-----------------------\n自配置开始......\n";
this->ui->textEdit->setText(out);
setAlgo->RESP0=self_window->RESP0;
setAlgo->choice=self_window->choice;
setAlgo->coverRate=self_window->coverRate;
setAlgo->power=self_window->power;
setAlgo->SINR = self_window->SINR;
setAlgo->a=self_window->a;
setAlgo->b=self_window->b;
qDebug()<<out;
setAlgo->resultPower = setAlgo->getResultPower();
QString resultPower=QString::number(setAlgo->resultPower)+"\n";
out=out+resultPower;
qDebug()<<out<<endl;
this->ui->textEdit->setText(out);
for(int i=0;i<setAlgo->apList.size();i++){
AP *temp = setAlgo->apList.at(i);
qDebug()<<"x,y:"<<temp->x()<<" "<<temp->y()<<endl;
QString apContent= NULL;
if(temp->frequency==1)
{
tmp=this->scene->addEllipse(temp->x(),temp->y(),(setAlgo->ratio)*EXR,(setAlgo->ratio)*EXR,blackPen,blueBrush);
apContent="<html><h1><font color='red'>基站信息</font></h1><font color='green'>基站频率:"+QString::number(temp->frequency)+"</font><br><font color='green'>基站功率:"+QString::number(setAlgo->resultPower)+"</font><br><font color='green'>网络容量:"+QString::number(temp->total_wifiSpeed)+"</font><br><font color='green'>用户容量:"+QString::number(temp->totalUser)+"</font><br></html>";
tmp->setToolTip(apContent);
}
else if(temp->frequency==6)
{
tmp=this->scene->addEllipse(temp->x(),temp->y(),(setAlgo->ratio)*EXR,(setAlgo->ratio)*EXR,blackPen,redBrush);
apContent="<html><h1><font color='red'>基站信息</font></h1><font color='green'>基站频率:"+QString::number(temp->frequency)+"</font><br><font color='green'>基站功率:"+QString::number(setAlgo->resultPower)+"</font><br><font color='green'>网络容量:"+QString::number(temp->total_wifiSpeed)+"</font><br><font color='green'>用户容量:"+QString::number(temp->totalUser)+"</font><br></html>";
tmp->setToolTip(apContent);
}
else if(temp->frequency==11)
{
tmp=this->scene->addEllipse(temp->x(),temp->y(),(setAlgo->ratio)*EXR,(setAlgo->ratio)*EXR,blackPen,yellowBrush);
apContent="<html><h1><font color='red'>基站信息</font></h1><font color='green'>基站频率:"+QString::number(temp->frequency)+"</font><br><font color='green'>基站功率:"+QString::number(setAlgo->resultPower)+"</font><br><font color='green'>网络容量:"+QString::number(temp->total_wifiSpeed)+"</font><br><font color='green'>用户容量:"+QString::number(temp->totalUser)+"</font><br></html>";
tmp->setToolTip(apContent);
}
}
}
_addLineGraph();
setYouhua->default_aplist = setAlgo->apList;
setYouhua->defalt_ratio = setAlgo->ratio;
hasSet=true;
QString result = "配置结果 功率: "+QString::number(setAlgo->resultPower);
this->ui->textEdit_2->setText(result+(setAlgo->suboutput));
}
void MainWindow::on_pushButton_2_clicked()
{
this->scene->clear();
if(hasSet==false)
{
QMessageBox::information(this,"Error!","请先进行自配置!");
}
else{
qDebug()<<"self_optimizing"<<endl;
self_organizeWindow = new self_optimize_set;
self_organizeWindow->exec();
QBrush redBrush(Qt::red);
QBrush blueBrush(Qt::blue);
QBrush yellowBrush(Qt::yellow);
QPen blackPen(Qt::black);
blackPen.setWidth(0.5);
QPen bluePen(Qt::blue);
bluePen.setWidth(0.5);
setYouhua->initUser();
int result = setYouhua->checkSituation();
qDebug()<<result<<endl;
if(result==0)
{
qDebug()<<"正常"<<endl;
}
for(int i=0;i<setYouhua->default_aplist.size();i++){
AP *temp = setYouhua->default_aplist.at(i);
// qDebug()<<"x,y:"<<temp->x()<<" "<<temp->y()<<endl;
QString apContent= NULL;
if(temp->frequency==1)
{
tmp=this->scene->addEllipse(temp->x(),temp->y(),(setAlgo->ratio)*EXR,(setAlgo->ratio)*EXR,blackPen,blueBrush);
apContent="<html><h1><font color='red'>基站信息</font></h1><font color='green'>基站频率:"+QString::number(temp->frequency)+"</font><br><font color='green'>基站功率:"+QString::number(temp->power)+"</font><br><font color='green'>网络容量:"+QString::number(temp->total_wifiSpeed)+"</font><br><font color='green'>用户容量:"+QString::number(temp->totalUser)+"</font><br></html>";
tmp->setToolTip(apContent);
}
else if(temp->frequency==6)
{
tmp=this->scene->addEllipse(temp->x(),temp->y(),(setAlgo->ratio)*EXR,(setAlgo->ratio)*EXR,blackPen,redBrush);
apContent="<html><h1><font color='red'>基站信息</font></h1><font color='green'>基站频率:"+QString::number(temp->frequency)+"</font><br><font color='green'>基站功率:"+QString::number(temp->power)+"</font><br><font color='green'>网络容量:"+QString::number(temp->total_wifiSpeed)+"</font><br><font color='green'>用户容量:"+QString::number(temp->totalUser)+"</font><br></html>";
tmp->setToolTip(apContent);
}
else if(temp->frequency==11)
{
tmp=this->scene->addEllipse(temp->x(),temp->y(),(setAlgo->ratio)*EXR,(setAlgo->ratio)*EXR,blackPen,yellowBrush);
apContent="<html><h1><font color='red'>基站信息</font></h1><font color='green'>基站频率:"+QString::number(temp->frequency)+"</font><br><font color='green'>基站功率:"+QString::number(temp->power)+"</font><br><font color='green'>网络容量:"+QString::number(temp->total_wifiSpeed)+"</font><br><font color='green'>用户容量:"+QString::number(temp->totalUser)+"</font><br></html>";
tmp->setToolTip(apContent);
}
}
_addLineGraph();
for(int i=0;i<7;i++){
if(self_organizeWindow->event[i]->hasEvent == true){
mytime[i].eventType=self_organizeWindow->event[i]->eventType;
mytime[i].eventContent=self_organizeWindow->event[i]->eventContent;
qDebug()<<i<<"type:"<<mytime[i].eventType;
mytime[i].start_timer();
}
}
}
}
void MainWindow::on_pushButton_3_clicked()
{
graTest = new GraphicsTest;
graTest->exec();
}
void MainWindow::on_action_2_triggered()
{
self_organizeWindow = new self_optimize_set;
self_organizeWindow->exec();
}
void MainWindow::on_action_3_triggered()
{
self_window = new self_set;
self_window->exec();
}
void MainWindow::on_action_8_triggered()
{
self_window = new self_set;
self_window->exec();
}
void MainWindow::setupMainGraph(int M,int N)
{
this->_cleanTheList();
QBrush redBrush(Qt::red);
QBrush blueBrush(Qt::blue);
QBrush yellowBrush(Qt::yellow);
QPen blackPen(Qt::black);
blackPen.setWidth(0.5);
QPen bluePen(Qt::blue);
bluePen.setWidth(0.5);
srand((int)time(NULL));
/*
for(int i=0;i<5;i++){
elipse[i] = scene->addEllipse(-200+i*100+rand()%30,-110+rand()%30,-100,100,blackPen,redBrush);
elipse[i]->setFlag(QGraphicsItem::ItemIsMovable);
}
for(int i=6;i<11;i++){
elipse[i] = scene->addEllipse(-200+(i-5)*100+rand()%30,100+rand()%30,-100,100,blackPen,yelloBrush);
elipse[i]->setFlag(QGraphicsItem::ItemIsMovable);
}
for(int i=12;i<19;i++){
elipse[i] = scene->addEllipse(-200+(i-12)*100+rand()%30,300+rand()%30,-100,100,blackPen,blueBrush);
elipse[i]->setFlag(QGraphicsItem::ItemIsMovable);
}
*/
srand((int)time(NULL));
for(int j=-N;j<=N;j++){
for(int i=-M;i<=M;i++){
blue = new QGraphicsEllipseItem;
blue = scene->addEllipse(2*sqrt(3)*R*i+RD,6*R*j+RD,2*R+EXTRA,2*R+EXTRA,blackPen,blueBrush);
blue->setX(2*sqrt(3)*R*i+RD);
blue ->setY(6*R*j+RD);
blueElipse.append(blue);
}
}
for(int j=-N;j<=N;j++){
for(int i=-M;i<=M;i++){
blue = new QGraphicsEllipseItem;
blue = scene->addEllipse(-sqrt(3)*R+2*sqrt(3)*R*i+RD,-3*R+6*R*j+RD,2*R+EXTRA,2*R+EXTRA,blackPen,blueBrush);
blue->setX(-sqrt(3)*R+2*sqrt(3)*R*i+RD);
blue->setY(-3*R+6*R*j+RD);
blueElipse.append(blue);
}
}
for(int j=-N;j<=N;j++){
for(int i=-M;i<=M;i++){
red = new QGraphicsEllipseItem;
red = scene->addEllipse(2*sqrt(3)*R*i+RD,2*R+6*R*j+RD,2*R+EXTRA,2*R+EXTRA,blackPen,redBrush);
red->setX(2*sqrt(3)*R*i+RD);
red->setY(2*R+6*R*j+RD);
redElipse.append(red);
}
}
for(int j=-N;j<=N;j++){
for(int i=-M;i<=M;i++){
red = new QGraphicsEllipseItem;
red = scene->addEllipse(-sqrt(3)*R+2*sqrt(3)*R*i+RD,-R+6*R*j+RD,2*R+EXTRA,2*R+EXTRA,blackPen,redBrush);
red->setX(-sqrt(3)*R+2*sqrt(3)*R*i+RD);
red->setY(-R+6*R*j+RD);
redElipse.append(red);
}
}
for(int j=-N;j<=N;j++){
for(int i=-M;i<=M;i++){
yellow = new QGraphicsEllipseItem;
yellow = scene->addEllipse(-sqrt(3)*R+2*sqrt(3)*R*i+RD,R+6*R*j+RD,2*R+EXTRA,2*R+EXTRA,blackPen,yellowBrush);
yellow->setX(-sqrt(3)*R+2*sqrt(3)*R*i+RD);
yellow->setY(R+6*R*j+RD);
yellowElipse.append(yellow);
}
}
for(int j=-N;j<=N;j++){
for(int i=-M;i<=M;i++){
yellow = new QGraphicsEllipseItem;
yellow = scene->addEllipse(2*sqrt(3)*R*i+RD,-2*R+6*R*j+RD,2*R+EXTRA,2*R+EXTRA,blackPen,yellowBrush);
yellow ->setX(2*sqrt(3)*R*i+RD);
yellow ->setY(-2*R+6*R*j+RD);
yellowElipse.append(yellow);
}
}
qDebug()<<redElipse.size();
foreach(QGraphicsEllipseItem *red,redElipse){
red->setFlag(QGraphicsItem::ItemIsMovable);
qDebug()<<red->x()<<" "<<red->y()<<endl;
}
qDebug()<<blueElipse.size();
foreach(QGraphicsEllipseItem *blue,blueElipse){
blue->setFlag(QGraphicsItem::ItemIsMovable);
qDebug()<<red->x()<<" "<<red->y()<<endl;
}
foreach(QGraphicsItem *yellow,yellowElipse){
yellow->setFlag(QGraphicsItem::ItemIsMovable);
qDebug()<<yellow->x()<<" "<<yellow->y()<<endl;
}
this->_addLineGraph();
}
void MainWindow::on_pushButton_4_clicked()
{
scene->clear();
MainWindow::setupMainGraph(m,n);
m++;n++;
}
void MainWindow::on_pushButton_5_clicked()
{
scene->clear();
this->_cleanTheList();
this->_addLineGraph();
m=1;n=0;
}
void MainWindow::_cleanTheList()
{
redElipse.clear();
yellowElipse.clear();
blueElipse.clear();
}
void MainWindow::on_graphicsView_rubberBandChanged(const QRect &viewportRect, const QPointF &fromScenePoint, const QPointF &toScenePoint)
{
}
void MainWindow::on_pushButton_6_clicked()
{
out="";
ui->textEdit->setText(out);
}
void MainWindow::on_horizontalScrollBar_valueChanged(int value)
{
double change=value*1.0/100;
ui->graphicsView->scale(change,change);
}