-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwstrzasymain.cpp
1471 lines (1154 loc) · 58.2 KB
/
wstrzasymain.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
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "wstrzasymain.h"
#include "./ui_wstrzasymain.h"
// Project specific header files above
#include <QMessageBox>
#include <QFileDialog>
#include <QDateTime>
#include <QFile>
#include <QTextStream>
// Qt specific libraries above
// C++ standard libraries below
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
// ************************************************** //
// NOTHING BUT MESS IS WHAT HAVE I DONE! (Look below) //
// ************************************************** //
// In the code, what is called "zdarzenie" is a whole incident class, incl. shock and object data.
// However, in GUI "zdarzenie" is a shock. Please be aware of it.
// Define a repeatable class for an incident (shock and object data (mostly as double bot strings for date, time and address exist too))
class Incident {
private:
// Subclasses for data variables
class Shock {
public: double X, Y, e, t, h;
QString date, time;
};
class Object {
public: double X, Y, wf;
QString address;
};
public:
Shock wstrzas;
Object obiekt;
// Functions which calculate PGVHmax and PGAH10
double PGVHmax() {
double d = sqrt(pow((obiekt.X - wstrzas.X) / 1000, 2) + pow((obiekt.Y - wstrzas.Y) / 1000, 2));
double r = sqrt(pow(d, 2) + pow(wstrzas.h, 2));
double VMD = (1.48 * 0.001 * pow(log10(wstrzas.e), 1.23) - 0.011) * (1.55 * pow(r, 0.135) * exp(-0.77 * r) + 0.04);
return VMD * obiekt.wf;
}
double PGAH10() {
double d = sqrt(pow((obiekt.X - wstrzas.X) / 1000, 2) + pow((obiekt.Y - wstrzas.Y) / 1000, 2));
double r = sqrt(pow(d, 2) + pow(wstrzas.h, 2));
double AMD = (1.33 * 0.001 * pow(log10(wstrzas.e), 2.66) - 0.089) * (1.53 * pow(r, 0.155) * exp(-0.65 * r) + 0.014);
return AMD * obiekt.wf;
}
// Functions which rate the shock level from 0 to 6
int PGVHmax_level() {
double pgv = PGVHmax();
if(wstrzas.t <= 1.5) {
if(pgv <= 0.005) {
return 0;
} else if(pgv <= 0.02) {
return 1;
} else if(pgv <= 0.035) {
return 2;
} else if(pgv <= 0.05) {
return 3;
} else if(pgv <= 0.07) {
return 4;
} else if(pgv <= 0.11) {
return 5;
} else {
return 6;
}
} else if(wstrzas.t <= 3) {
if(pgv <= 0.005) {
return 0;
} else if(pgv <= (((-2 / 3) * wstrzas.t) + 3) / 100) {
return 1;
} else if(pgv <= (((-2 / 3) * wstrzas.t) + 4.5) / 100) {
return 2;
} else if(pgv <= (((-2 / 3) * wstrzas.t) + 6) / 100) {
return 3;
} else if(pgv <= (((-2 / 3) * wstrzas.t) + 8) / 100) {
return 4;
} else if(pgv <= (((-2 / 3) * wstrzas.t) + 12) / 100) {
return 5;
} else {
return 6;
}
} else {
if(pgv <= 0.005) {
return 0;
} else if(pgv <= 0.01) {
return 1;
} else if(pgv <= 0.025) {
return 2;
} else if(pgv <= 0.04) {
return 3;
} else if(pgv <= 0.06) {
return 4;
} else if(pgv <= 0.1) {
return 5;
} else {
return 6;
}
}
}
int PGAH10_level() {
double pga = PGAH10();
if(wstrzas.t <= 1.5) {
if(pga <= 0.15) {
return 0;
} else if(pga <= 0.6) {
return 1;
} else if(pga <= 0.9) {
return 2;
} else if(pga <= 1.2) {
return 3;
} else if(pga <= 1.6) {
return 4;
} else if(pga <= 2.3) {
return 5;
} else {
return 6;
}
} else if(wstrzas.t <= 3) {
if(pga <= 0.15) {
return 0;
} else if(pga <= ((-0.2 * wstrzas.t) + 0.9)) {
return 1;
} else if(pga <= ((-0.2 * wstrzas.t) + 1.2)) {
return 2;
} else if(pga <= ((-0.2 * wstrzas.t) + 1.5)) {
return 3;
} else if(pga <= ((-0.2 * wstrzas.t) + 1.9)) {
return 4;
} else if(pga <= ((-0.2 * wstrzas.t) + 2.6)) {
return 5;
} else {
return 6;
}
} else {
if(pga <= 0.15) {
return 0;
} else if(pga <= 0.3) {
return 1;
} else if(pga <= 0.6) {
return 2;
} else if(pga <= 0.9) {
return 3;
} else if(pga <= 1.3) {
return 4;
} else if(pga <= 2) {
return 5;
} else {
return 6;
}
}
}
// Overall level of a shock; it just takes the bigger return value of the two previous function
int overall_level() {
int V = PGVHmax_level();
int A = PGAH10_level();
if(V > A) {
return V;
} else {
return A;
}
}
};
std::vector<Incident> zdarzenia; // Vector of incidents for multiple calculations at once
Incident dummy_incident; // Will be pushed back as an empty class to the previous vector
std::vector<QString> dataline_q; // Vector of file's lines
std::vector<QString> insert_to_incident_q; // Vector of values in file's line
std::vector<double> insert_to_incident_double; // The same, but excluding address, time and date, which are QStrings. Used for to convert to double for calculation
QString input_file_path = "in.txt"; // Default open file path for the first rile reading mode. Will be modified when "Przeglądaj..." clicked
QString input_object_file_path = "in.txt"; // Default open file path for the second rile reading mode. Also will be modified like the variable above
// Default communicates for "Komunikaty" field
const QString parser_choice_1_communicate = "Format linijki pliku wejściowego dla parsera\nZdarzenia dla obiektów:\n\nE Xz Yz t h (d) (g)\n\nWytłumaczenie skrótów w polu Informacje.";
const QString parser_choice_2_communicate = "Format linijki pliku wejściowego dla parsera\nObiekty dla zdarzenia:\n\nXo Yo Wf (a)\n\nWytłumaczenie skrótów w polu Informacje.";
QString errdump = ""; // Errors about incorrect lines and general alerts and communicated will appear there, and later on in the "Komunikaty" field
QDateTime now; // Used to set today's date in GUI when program is started
WstrzasyMain::WstrzasyMain(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::WstrzasyMain)
{
ui->setupUi(this);
this->setFixedSize(size());
this->setWindowFlags(Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint);
this->ui->onebyone_date->setDate(now.currentDateTime().date());
this->ui->onebyone_time->setTime(now.currentDateTime().time());
this->ui->input_shock_date->setDate(now.currentDateTime().date());
this->ui->input_shock_time->setTime(now.currentDateTime().time());
this->ui->alert_text->setText(parser_choice_1_communicate);
}
WstrzasyMain::~WstrzasyMain()
{
delete ui;
}
void WstrzasyMain::on_inject_object_data_clicked()
{
QFile data(input_object_file_path); // Declare filestream
std::vector<double> incident_data;
QString incident_data_str[7];
incident_data_str[0] = this->ui->input_shock_e->text();
incident_data_str[1] = this->ui->input_shock_x->text();
incident_data_str[2] = this->ui->input_shock_y->text();
incident_data_str[3] = this->ui->input_shock_t->text();
incident_data_str[4] = this->ui->input_shock_h->text();
if(this->ui->input_shock_date->date().day() < 10) { incident_data_str[5] = "0"; }
incident_data_str[5] += (std::to_string(this->ui->input_shock_date->date().day()) + ".");
if(this->ui->input_shock_date->date().month() < 10) { incident_data_str[5] += "0"; }
incident_data_str[5] += (std::to_string(this->ui->onebyone_date->date().month()) + "." + std::to_string(this->ui->onebyone_date->date().year()));
if(this->ui->input_shock_time->time().hour() < 10) { incident_data_str[6] = "0"; }
incident_data_str[6] += (std::to_string(this->ui->onebyone_time->time().hour()) + ":");
if(this->ui->input_shock_time->time().minute() < 10) { incident_data_str[6] += "0"; }
incident_data_str[6] += (std::to_string(this->ui->onebyone_time->time().minute()));
for(int i = 0; i < 5; i++) {
try {
incident_data.push_back(incident_data_str[i].replace(',', '.').toDouble());
} catch (...) {}
}
if(data.open(QFile::ReadOnly) && incident_data.size() == 5) {
// Adjust UI
this->ui->input_shock_e->setEnabled(false);
this->ui->input_shock_x->setEnabled(false);
this->ui->input_shock_y->setEnabled(false);
this->ui->input_shock_t->setEnabled(false);
this->ui->input_shock_h->setEnabled(false);
this->ui->input_shock_date->setEnabled(false);
this->ui->input_shock_time->setEnabled(false);
this->ui->inject_object_data->setEnabled(false);
this->ui->browse_object->setEnabled(false);
this->ui->clear_everything_object->setEnabled(true);
// Read line by line
QTextStream in(&data);
while(!in.atEnd()) {
dataline_q.push_back(in.readLine());
}
// End reading line by line
data.close(); // Close file stream
// Place values into correct places
for(int e = 0; e < dataline_q.size(); e++) {
QStringList dummy = dataline_q[e].split('\t');
for(QString f : dummy) {
f.replace(',', '.');
if(f.contains(' ')) {
QStringList dummy_s = f.split(' ');
for(QString g : dummy_s) {
if(g != "") {
if(insert_to_incident_q.size() < 3) {
insert_to_incident_q.push_back(g);
} else if (insert_to_incident_q.size() == 3) {
insert_to_incident_q.push_back(g);
} else {
insert_to_incident_q[insert_to_incident_q.size() - 1] += (" " + g);
}
}
}
} else {
if(f != "") {
if(insert_to_incident_q.size() < 3) {
insert_to_incident_q.push_back(f);
} else if(insert_to_incident_q.size() == 3) {
insert_to_incident_q.push_back(f);
} else {
insert_to_incident_q[insert_to_incident_q.size() - 1] += (" " + f);
}
}
}
}
if(insert_to_incident_q.size() >= 3) {
for(int i = 0; i < 3; i++) {
try {
insert_to_incident_double.push_back(insert_to_incident_q[i].toDouble());
} catch(...) {}
}
if(insert_to_incident_double.size() == 3) {
zdarzenia.push_back(dummy_incident);
zdarzenia[zdarzenia.size() - 1].wstrzas.e = incident_data[0];
zdarzenia[zdarzenia.size() - 1].wstrzas.X = incident_data[1];
zdarzenia[zdarzenia.size() - 1].wstrzas.Y = incident_data[2];
zdarzenia[zdarzenia.size() - 1].wstrzas.t = incident_data[3];
zdarzenia[zdarzenia.size() - 1].wstrzas.h = incident_data[4];
zdarzenia[zdarzenia.size() - 1].wstrzas.date = incident_data_str[5];
zdarzenia[zdarzenia.size() - 1].wstrzas.time = incident_data_str[6];
zdarzenia[zdarzenia.size() - 1].obiekt.X = insert_to_incident_double[0];
zdarzenia[zdarzenia.size() - 1].obiekt.Y = insert_to_incident_double[1];
zdarzenia[zdarzenia.size() - 1].obiekt.wf = insert_to_incident_double[2];
if(insert_to_incident_q.size() >= 4) {
zdarzenia[zdarzenia.size() - 1].obiekt.address = insert_to_incident_q[3];
}
errdump += ("Linijka " + QString::fromStdString(std::to_string(e + 1)) + " wygląda dobrze.\n\n");
insert_to_incident_double.clear();
insert_to_incident_q.clear();
} else {
errdump += ("Ignorowanie linijki " + QString::fromStdString(std::to_string(e + 1)) + " (niewłaściwa ilość danych).\n\n");
insert_to_incident_double.clear();
insert_to_incident_q.clear();
}
} else if(insert_to_incident_q.size() == 0) {
errdump += ("Ignorowanie linijki " + QString::fromStdString(std::to_string(e + 1)) + " (pusta).\n\n");
insert_to_incident_double.clear();
insert_to_incident_q.clear();
} else {
errdump += ("Ignorowanie linijki " + QString::fromStdString(std::to_string(e + 1)) + " (niewłaściwa ilość danych).\n\n");
insert_to_incident_double.clear();
insert_to_incident_q.clear();
}
}
// End positioning values
// Push data into the input data field
this->ui->input_data->setText("");
this->ui->alert_text->setText(this->ui->alert_text->toPlainText() + "\n\n" + errdump);
int incident_counter = 1;
for(Incident e : zdarzenia) {
if(incident_counter != 1) {
this->ui->input_data->setText(this->ui->input_data->toPlainText() + "\n\n");
}
this->ui->input_data->setText(this->ui->input_data->toPlainText() + "[Obliczenie " + QString::fromStdString(std::to_string(incident_counter)) + "]");
if(e.wstrzas.date != "") {
this->ui->input_data->setText(this->ui->input_data->toPlainText() + "\nData zdarzenia: " + e.wstrzas.date);
}
if(e.wstrzas.time != "") {
this->ui->input_data->setText(this->ui->input_data->toPlainText() + "\nGodzina zdarzenia: " + e.wstrzas.time);
}
this->ui->input_data->setText(this->ui->input_data->toPlainText() + "\nE zdarzenia: " + QString::fromStdString(std::to_string(e.wstrzas.e)));
this->ui->input_data->setText(this->ui->input_data->toPlainText() + "\nX zdarzenia: " + QString::fromStdString(std::to_string(e.wstrzas.X)));
this->ui->input_data->setText(this->ui->input_data->toPlainText() + "\nY zdarzenia: " + QString::fromStdString(std::to_string(e.wstrzas.Y)));
this->ui->input_data->setText(this->ui->input_data->toPlainText() + "\nt zdarzenia: " + QString::fromStdString(std::to_string(e.wstrzas.t)));
this->ui->input_data->setText(this->ui->input_data->toPlainText() + "\nh zdarzenia: " + QString::fromStdString(std::to_string(e.wstrzas.h)));
if(e.obiekt.address != "") {
this->ui->input_data->setText(this->ui->input_data->toPlainText() + "\nAdres obiektu: " + e.obiekt.address);
}
this->ui->input_data->setText(this->ui->input_data->toPlainText() + "\nX obiektu: " + QString::fromStdString(std::to_string(e.obiekt.X)));
this->ui->input_data->setText(this->ui->input_data->toPlainText() + "\nY obiektu: " + QString::fromStdString(std::to_string(e.obiekt.Y)));
this->ui->input_data->setText(this->ui->input_data->toPlainText() + "\nWf obiektu: " + QString::fromStdString(std::to_string(e.obiekt.wf)));
incident_counter++;
}
this->ui->calculate->setEnabled(true);
} else {
data.close();
QMessageBox err_msg;
err_msg.setWindowTitle("Błąd!");
err_msg.setInformativeText("Plik o podanej nazwie nie istnieje, jest niewłaściwy, lub wprowadzono nieprawidłowe dane obiektu.");
err_msg.setStandardButtons(QMessageBox::Close);
err_msg.exec();
}
}
void WstrzasyMain::on_inject_incidents_clicked()
{
QFile data(input_file_path);
std::vector<double> object_data;
QString object_data_str[4];
object_data_str[0] = this->ui->input_object_x->text();
object_data_str[1] = this->ui->input_object_y->text();
object_data_str[2] = this->ui->input_object_wf->text();
object_data_str[3] = this->ui->input_object_address->text();
for(QString e : object_data_str) {
try {
object_data.push_back(e.replace(',', '.').toDouble());
} catch(...) {}
}
if(data.open(QFile::ReadOnly) && object_data.size() == 4) {
// Adjust UI
this->ui->input_object_x->setEnabled(false);
this->ui->input_object_y->setEnabled(false);
this->ui->input_object_wf->setEnabled(false);
this->ui->input_object_address->setEnabled(false);
this->ui->inject_incidents->setEnabled(false);
this->ui->browse_button->setEnabled(false);
this->ui->clear_everything->setEnabled(true);
// Read line by line
QTextStream in(&data);
while(!in.atEnd()) {
dataline_q.push_back(in.readLine());
}
// End reading line by line
data.close(); // Close file stream
// Place values into correct spots
for(int e = 0; e < dataline_q.size(); e++) {
QStringList dummy = dataline_q[e].split('\t');
for(QString f : dummy) {
f.replace(',', '.');
if(f.contains(' ')) {
QStringList dummy_s = f.split(' ');
for(QString g : dummy_s) {
if(g != "") {
insert_to_incident_q.push_back(g);
}
}
} else {
if(f != "") {
insert_to_incident_q.push_back(f);
}
}
}
if(insert_to_incident_q.size() >= 5) {
for(int i = 0; i < 5; i++) {
try {
insert_to_incident_double.push_back(insert_to_incident_q[i].toDouble());
} catch(...) {}
}
if(insert_to_incident_double.size() == 5) {
zdarzenia.push_back(dummy_incident);
zdarzenia[zdarzenia.size() - 1].obiekt.X = object_data[0];
zdarzenia[zdarzenia.size() - 1].obiekt.Y = object_data[1];
zdarzenia[zdarzenia.size() - 1].obiekt.wf = object_data[2];
zdarzenia[zdarzenia.size() - 1].obiekt.address = object_data_str[3];
zdarzenia[zdarzenia.size() -1 ].wstrzas.e = insert_to_incident_double[0];
zdarzenia[zdarzenia.size() -1 ].wstrzas.X = insert_to_incident_double[1];
zdarzenia[zdarzenia.size() -1 ].wstrzas.Y = insert_to_incident_double[2];
zdarzenia[zdarzenia.size() -1 ].wstrzas.t = insert_to_incident_double[3];
zdarzenia[zdarzenia.size() -1 ].wstrzas.h = insert_to_incident_double[4];
if(insert_to_incident_q.size() >= 6) {
zdarzenia[zdarzenia.size() - 1].wstrzas.date = insert_to_incident_q[5];
if(insert_to_incident_q.size() >= 7) {
zdarzenia[zdarzenia.size() - 1].wstrzas.time = insert_to_incident_q[6];
}
}
errdump += ("Linijka " + QString::fromStdString(std::to_string(e + 1)) + " wygląda dobrze.\n\n");
insert_to_incident_double.clear();
insert_to_incident_q.clear();
} else {
errdump += ("Ignorowanie linijki " + QString::fromStdString(std::to_string(e + 1)) + " (niewłaściwa ilość danych).\n\n");
insert_to_incident_double.clear();
insert_to_incident_q.clear();
}
} else if(insert_to_incident_q.size() == 0) {
errdump += ("Ignorowanie linijki " + QString::fromStdString(std::to_string(e + 1)) + " (pusta).\n\n");
insert_to_incident_double.clear();
insert_to_incident_q.clear();
} else {
errdump += ("Ignorowanie linijki " + QString::fromStdString(std::to_string(e + 1)) + " (niewłaściwa ilość danych).\n\n");
insert_to_incident_double.clear();
insert_to_incident_q.clear();
}
}
// End positioning values
// Push data into the input data field
this->ui->input_data->setText("");
this->ui->alert_text->setText(this->ui->alert_text->toPlainText() + "\n\n" + errdump);
int incident_counter = 1;
for(Incident e : zdarzenia) {
if(incident_counter != 1) {
this->ui->input_data->setText(this->ui->input_data->toPlainText() + "\n\n");
}
this->ui->input_data->setText(this->ui->input_data->toPlainText() + "[Obliczenie " + QString::fromStdString(std::to_string(incident_counter)) + "]");
if(e.wstrzas.date != "") {
this->ui->input_data->setText(this->ui->input_data->toPlainText() + "\nData zdarzenia: " + e.wstrzas.date);
}
if(e.wstrzas.time != "") {
this->ui->input_data->setText(this->ui->input_data->toPlainText() + "\nGodzina zdarzenia: " + e.wstrzas.time);
}
this->ui->input_data->setText(this->ui->input_data->toPlainText() + "\nE zdarzenia: " + QString::fromStdString(std::to_string(e.wstrzas.e)));
this->ui->input_data->setText(this->ui->input_data->toPlainText() + "\nX zdarzenia: " + QString::fromStdString(std::to_string(e.wstrzas.X)));
this->ui->input_data->setText(this->ui->input_data->toPlainText() + "\nY zdarzenia: " + QString::fromStdString(std::to_string(e.wstrzas.Y)));
this->ui->input_data->setText(this->ui->input_data->toPlainText() + "\nt zdarzenia: " + QString::fromStdString(std::to_string(e.wstrzas.t)));
this->ui->input_data->setText(this->ui->input_data->toPlainText() + "\nh zdarzenia: " + QString::fromStdString(std::to_string(e.wstrzas.h)));
if(e.obiekt.address != "") {
this->ui->input_data->setText(this->ui->input_data->toPlainText() + "\nAdres obiektu: " + e.obiekt.address);
}
this->ui->input_data->setText(this->ui->input_data->toPlainText() + "\nX obiektu: " + QString::fromStdString(std::to_string(e.obiekt.X)));
this->ui->input_data->setText(this->ui->input_data->toPlainText() + "\nY obiektu: " + QString::fromStdString(std::to_string(e.obiekt.Y)));
this->ui->input_data->setText(this->ui->input_data->toPlainText() + "\nWf obiektu: " + QString::fromStdString(std::to_string(e.obiekt.wf)));
incident_counter++;
}
this->ui->calculate->setEnabled(true);
} else {
data.close();
QMessageBox err_msg;
err_msg.setWindowTitle("Błąd!");
err_msg.setInformativeText("Plik o podanej nazwie nie istnieje, jest niewłaściwy, lub wprowadzono nieprawidłowe dane obiektu.");
err_msg.setStandardButtons(QMessageBox::Close);
err_msg.exec();
}
}
void WstrzasyMain::on_calculate_clicked()
{
this->ui->calculate->setEnabled(false);
this->ui->output_data->setText("");
int incident_counter = 1;
for(Incident e : zdarzenia) {
if(incident_counter != 1) {
this->ui->output_data->setText(this->ui->output_data->toPlainText() + "\n\n");
}
this->ui->output_data->setText(this->ui->output_data->toPlainText() + "[Wyniki obliczenia " + QString::fromStdString(std::to_string(incident_counter)) + "]");
this->ui->output_data->setText(this->ui->output_data->toPlainText() + "\nPGVHmax zdarzenia [m/s]: " + QString::fromStdString(std::to_string(e.PGVHmax())));
this->ui->output_data->setText(this->ui->output_data->toPlainText() + "\nPGAH10 zdarzenia [m/s^2]: " + QString::fromStdString(std::to_string(e.PGAH10())));
this->ui->output_data->setText(this->ui->output_data->toPlainText() + "\nIGSIS-2017 - PGVHmax zdarzenia [0-6]: " + QString::fromStdString(std::to_string(e.PGVHmax_level())));
this->ui->output_data->setText(this->ui->output_data->toPlainText() + "\nIGSIS-2017 - PGAH10 zdarzenia [0-6]: " + QString::fromStdString(std::to_string(e.PGAH10_level())));
this->ui->output_data->setText(this->ui->output_data->toPlainText() + "\nIGSIS-2017 zdarzenia [0-6]: " + QString::fromStdString(std::to_string(e.overall_level())));
incident_counter++;
}
this->ui->save->setEnabled(true);
}
void WstrzasyMain::on_clear_everything_clicked()
{
this->ui->input_filename->setText("in.txt");
input_file_path = "in.txt";
this->ui->browse_button->setEnabled(true);
this->ui->input_object_x->setEnabled(true);
this->ui->input_object_y->setEnabled(true);
this->ui->input_object_wf->setEnabled(true);
this->ui->input_object_address->setEnabled(true);
this->ui->input_object_x->setText("");
this->ui->input_object_y->setText("");
this->ui->input_object_wf->setText("");
this->ui->input_object_address->setText("");
this->ui->save->setEnabled(false);
this->ui->calculate->setEnabled(false);
this->ui->alert_text->setText(parser_choice_1_communicate);
this->ui->input_data->setText("Oczekiwanie na dane wejściowe...");
this->ui->output_data->setText("Oczekiwanie na wykonanie obliczeń...");
zdarzenia.clear();
dataline_q.clear();
insert_to_incident_q.clear();
errdump = "";
this->ui->inject_incidents->setEnabled(true);
this->ui->clear_everything->setEnabled(false);
}
void WstrzasyMain::on_clear_everything_object_clicked()
{
this->ui->input_object_filename->setText("in.txt");
input_object_file_path = "in.txt";
this->ui->browse_object->setEnabled(true);
this->ui->input_shock_e->setEnabled(true);
this->ui->input_shock_x->setEnabled(true);
this->ui->input_shock_y->setEnabled(true);
this->ui->input_shock_t->setEnabled(true);
this->ui->input_shock_h->setEnabled(true);
this->ui->input_shock_date->setEnabled(true);
this->ui->input_shock_time->setEnabled(true);
this->ui->input_shock_e->setText("");
this->ui->input_shock_x->setText("");
this->ui->input_shock_y->setText("");
this->ui->input_shock_t->setText("");
this->ui->input_shock_h->setText("0,5");
this->ui->input_shock_date->setDate(now.currentDateTime().date());
this->ui->input_shock_time->setTime(now.currentDateTime().time());
this->ui->save->setEnabled(false);
this->ui->calculate->setEnabled(false);
this->ui->alert_text->setText(parser_choice_2_communicate);
this->ui->input_data->setText("Oczekiwanie na dane wejściowe...");
this->ui->output_data->setText("Oczekiwanie na wykonanie obliczeń...");
zdarzenia.clear();
dataline_q.clear();
insert_to_incident_q.clear();
errdump = "";
this->ui->inject_object_data->setEnabled(true);
this->ui->clear_everything_object->setEnabled(false);
}
void WstrzasyMain::on_save_clicked()
{
QFileDialog save_file(this);
save_file.setFileMode(QFileDialog::AnyFile);
QString save_filename = save_file.getSaveFileName();
if(save_filename != "") {
if(!save_filename.endsWith(".txt")) {
save_filename += ".txt";
}
QFile output(save_filename);
output.open(QFile::WriteOnly);
QTextStream to_output(&output);
to_output << "Obliczanie stopnia intensywności sejsmicznej dla wstrząsów górniczych wg skali GSIS-2017\n";
to_output << "Program wykonany na podstawie:\n";
to_output << "G. Mutke - Metoda prognozowania parametrów drgań podłoża generowanych wstrząsami górniczymi w obszarze GZW.\nRozprawa doktorska, Główny Instytut Górnictwa, Katowice. (1991)\n\n";
int incident_counter = 1;
QString tmp_ln;
QTextStream ln(&tmp_ln);
if(this->ui->input_tabview->currentIndex() == 0) {
to_output << "Wyniki obliczeń dla poniższego obiektu:\n";
if(zdarzenia[0].obiekt.address != "") {
to_output << "Adres:\t\t\t\t\t" << zdarzenia[0].obiekt.address << "\n";
}
to_output << "Lokalizacja X [m]:\t\t\t" << zdarzenia[0].obiekt.X << "\n";
to_output << "Lokalizacja Y [m]:\t\t\t" << zdarzenia[0].obiekt.Y << "\n";
to_output << "Współczynnik amplifikacji drgań Wf:\t" << zdarzenia[0].obiekt.wf << "\n\n";
to_output << "Wersja czytelna w edytorze tekstu (wersja do skopiowania do arkusza kalkulacyjnego niżej):\n";
to_output << "l.p.\t\tEnergia [J]\tX [m]\t\tY[m]\t\tCzas [s]\tGłębokość [km]\tPGVHmax [m/s]\tPGAH10 [m/s^2]\tIGSIS2017 - PGVHmax [0-6]\tIGSIS2017 - PGAH10 [0-6]\tIGSIS2017 [0-6]\tData\t\tGodzina\n";
for(Incident e : zdarzenia) {
double pgv = e.PGVHmax(); // These variables are used twice so
double pga = e.PGAH10(); // why not reduce the number of calculations?
to_output << incident_counter << "\t\t";
// Shock energy
ln.setRealNumberNotation(QTextStream::SmartNotation);
ln << e.wstrzas.e;
to_output << tmp_ln.replace('.', ',') << "\t";
if(tmp_ln.length() < 8) {
to_output << "\t";
}
tmp_ln = "";
// Shock X
ln << e.wstrzas.X;
to_output << tmp_ln.replace('.', ',') << "\t";
if(tmp_ln.length() < 8) {
to_output << "\t";
}
tmp_ln = "";
// Shock Y
ln << e.wstrzas.Y;
to_output << tmp_ln.replace('.', ',') << "\t";
if(tmp_ln.length() < 8) {
to_output << "\t";
}
tmp_ln = "";
// Shock time
ln << e.wstrzas.t;
to_output << tmp_ln.replace('.', ',') << "\t";
if(tmp_ln.length() < 8) {
to_output << "\t";
}
tmp_ln = "";
// Shock depth
ln << e.wstrzas.h;
to_output << tmp_ln.replace('.', ',') << "\t";
if(tmp_ln.length() < 8) {
to_output << "\t";
}
tmp_ln = "";
// PGVHmax
ln << pgv;
to_output << tmp_ln.replace('.', ',') << "\t";
if(tmp_ln.length() < 8) {
to_output << "\t";
}
tmp_ln = "";
// PGAH10
ln << pga;
to_output << tmp_ln.replace('.', ',') << "\t";
if(tmp_ln.length() < 8) {
to_output << "\t";
}
tmp_ln = "";
// Levels
ln << e.PGVHmax_level();
to_output << tmp_ln.replace('.', ',') << "\t\t\t\t";
tmp_ln = "";
ln << e.PGAH10_level();
to_output << tmp_ln.replace('.', ',') << "\t\t\t\t";
tmp_ln = "";
ln << e.overall_level();
to_output << tmp_ln.replace('.', ',');
tmp_ln = "";
// Optional date and time
if(e.wstrzas.date != "") {
to_output << "\t\t" << e.wstrzas.date;
if(e.wstrzas.time != "") {
to_output << "\t" << e.wstrzas.time;
}
}
// New line
to_output << "\n";
incident_counter++;
}
to_output << "\nWersja do skopiowania do arkusza kalkulacyjnego (mniej czytelna w edytorze tekstu):\n";
to_output << "l.p.\tEnergia [J]\tX [m]\tY [m]\tCzas [s]\tGłębokość [km]\tPGVHmax [m/s]\tPGAH10 [m/s^2]\tIGSIS2017 - PGVHmax [0-6]\tIGSIS2017 - PGAH10 [0-6]\tIGSIS2017 [0-6]\tData\tGodzina\n";
incident_counter = 1;
for(Incident e : zdarzenia) {
double pgv = e.PGVHmax(); // These variables are used twice so
double pga = e.PGAH10(); // why not reduce the number of calculations?
to_output << incident_counter << "\t";
// Shock energy
ln.setRealNumberNotation(QTextStream::SmartNotation);
ln << e.wstrzas.e;
to_output << tmp_ln.replace('.', ',') << "\t";
tmp_ln = "";
// Shock X
ln << e.wstrzas.X;
to_output << tmp_ln.replace('.', ',') << "\t";
tmp_ln = "";
// Shock Y
ln << e.wstrzas.Y;
to_output << tmp_ln.replace('.', ',') << "\t";
tmp_ln = "";
// Shock time
ln << e.wstrzas.t;
to_output << tmp_ln.replace('.', ',') << "\t";
tmp_ln = "";
// Shock depth
ln << e.wstrzas.h;
to_output << tmp_ln.replace('.', ',') << "\t";
tmp_ln = "";
// PGVHmax
ln << pgv;
to_output << tmp_ln.replace('.', ',') << "\t";
tmp_ln = "";
// PGAH10
ln << pga;
to_output << tmp_ln.replace('.', ',') << "\t";
tmp_ln = "";
// Levels
ln << e.PGVHmax_level();
to_output << tmp_ln.replace('.', ',') << "\t";
tmp_ln = "";
ln << e.PGAH10_level();
to_output << tmp_ln.replace('.', ',') << "\t";
tmp_ln = "";
ln << e.overall_level();
to_output << tmp_ln.replace('.', ',');
tmp_ln = "";
// Optional date and time
if(e.wstrzas.date != "") {
to_output << "\t" << e.wstrzas.date;
if(e.wstrzas.time != "") {
to_output << "\t" << e.wstrzas.time;
}
}
// New line
to_output << "\n";
incident_counter++;
}
} else if(this->ui->input_tabview->currentIndex() == 1) {
to_output << "Wyniki obliczeń dla poniższego zdarzenia:\n";
if(zdarzenia[0].wstrzas.date != "") {
to_output << "Data wystąpienia:\t" << zdarzenia[0].wstrzas.date << "\n";
if(zdarzenia[0].wstrzas.time != "") {
to_output << "Godzina wystąpienia:\t" << zdarzenia[0].wstrzas.time << "\n";
}
}
to_output << "Lokalizacja X [m]:\t" << zdarzenia[0].wstrzas.X << "\n";
to_output << "Lokalizacja Y [m]:\t" << zdarzenia[0].wstrzas.Y << "\n";
to_output << "Czas trwania [s]:\t" << zdarzenia[0].wstrzas.t << "\n";
to_output << "Głębokość ogniska [km]:\t" << zdarzenia[0].wstrzas.h << "\n\n";
to_output << "Wersja czytelna w edytorze tekstu (wersja do skopiowania do arkusza kalkulacyjnego niżej):\n";
to_output << "l.p.\t\tX [m]\t\tY [m]\t\tWsp. amplifikacji drgań (Wf)\tPGVHmax [m/s]\tPGAH10 [m/s^2]\tIGSIS2017 - PGVHmax [0-6]\tIGSIS2017 - PGAH10 [0-6]\tIGSIS2017 [0-6]\tAdres obiektu\n";
for(Incident e : zdarzenia) {
double pgv = e.PGVHmax(); // These variables are used twice so
double pga = e.PGAH10(); // why not reduce the number of calculations?
to_output << incident_counter << "\t\t";
// Object X
ln.setRealNumberNotation(QTextStream::SmartNotation);
ln << e.obiekt.X;
to_output << tmp_ln.replace('.', ',') << "\t";
if(tmp_ln.length() < 8) {
to_output << "\t";
}
tmp_ln = "";
// Object Y
ln << e.obiekt.Y;
to_output << tmp_ln.replace('.', ',') << "\t";
if(tmp_ln.length() < 8) {
to_output << "\t";
}
tmp_ln = "";
// Object shock amplification factor
ln << e.obiekt.wf;
to_output << tmp_ln.replace('.', ',') << "\t\t";
if(tmp_ln.length() < 16) {
to_output << "\t";
if(tmp_ln.length() < 8) {
to_output << "\t";
}
}
tmp_ln = "";
// PGVHmax
ln << pgv;
to_output << tmp_ln.replace('.', ',') << "\t";
if(tmp_ln.length() < 8) {
to_output << "\t";
}
tmp_ln = "";
// PGAH10
ln << pga;
to_output << tmp_ln.replace('.', ',') << "\t";
if(tmp_ln.length() < 8) {
to_output << "\t";
}
tmp_ln = "";
// Levels
ln << e.PGVHmax_level();
to_output << tmp_ln.replace('.', ',') << "\t\t\t\t";
tmp_ln = "";
ln << e.PGAH10_level();
to_output << tmp_ln.replace('.', ',') << "\t\t\t\t";
tmp_ln = "";
ln << e.overall_level();
to_output << tmp_ln.replace('.', ',');
tmp_ln = "";
// Optional address
if(e.wstrzas.date != "") {
to_output << "\t\t" << e.obiekt.address;
}
// New line
to_output << "\n";
incident_counter++;
}
to_output << "\nWersja do skopiowania do arkusza kalkulacyjnego (mniej czytelna w edytorze tekstu):\n";
to_output << "l.p.\tX [m]\tY [m]\tWsp. amplifikacji drgań (Wf)\tPGVHmax [m/s]\tPGAH10 [m/s^2]\tIGSIS2017 - PGVHmax [0-6]\tIGSIS2017 - PGAH10 [0-6]\tIGSIS2017 [0-6]\tAdres obiektu\n";
incident_counter = 1;
for(Incident e : zdarzenia) {
double pgv = e.PGVHmax(); // These variables are used twice so
double pga = e.PGAH10(); // why not reduce the number of calculations?
to_output << incident_counter << "\t";