-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmainwindow.cpp
3578 lines (2996 loc) · 134 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
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
/**
* @file
* Main Window
*
* All REvoSim code is released under the GNU General Public License.
* See LICENSE.md files in the programme directory.
*
* All REvoSim code is Copyright 2018 by Mark Sutton, Russell Garwood,
* and Alan R.T. Spencer.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version. This program is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY.
*/
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "reseed.h"
#include "analyser.h"
#include "fossrecwidget.h"
#include "resizecatcher.h"
#include <QTextStream>
#include <QInputDialog>
#include <QComboBox>
#include <QDialogButtonBox>
#include <QFormLayout>
#include <QGraphicsPixmapItem>
#include <QDockWidget>
#include <QDebug>
#include <QTimer>
#include <QFileDialog>
#include <QFormLayout>
#include <QStringList>
#include <QMessageBox>
#include <QActionGroup>
#include <QDataStream>
#include <QStringList>
#include <QFile>
#include <QXmlStreamReader>
#include <QDesktopServices>
#include "analysistools.h"
#include "version.h"
#include "math.h"
#ifndef M_SQRT1_2 //not defined in all versions
#define M_SQRT1_2 0.7071067811865475
#endif
SimManager *TheSimManager;
MainWindow *MainWin;
#include <QThread>
/*
To do for paper:
Coding:
-- Load and Save don't include everything - they need to!
-- Timer on calculting species - add progress bar and escape warning if needed to prevent crash
-- Add Keyboard shortcuts where required
Visualisation:
-- Settles - does this work at all?
-- Fails - check green scaling
To remove prior to release, but after all changes are complete:
-- Dual reseed
-- Remove all custom logging options (RJG is using these for research and projects, so needs to keep them in master fork).
-- Fossil record - down the line we need to work out that this actually does check it actually works. For release, just remove option
-- Entirely lose the Analysis Tools menu, and analysis docker. Phylogeny settings will become part of settings.
To do in revisions:
-- Further comment code
-- Standardise case throughout the code, and also variable names in a sensible fashion
-- Rename "generations" variable "iterations", which is more correct
To do long term:
-- Add variable mutation rate depent on population density:
---- Count number of filled slots (do as percentage of filled slots)
---- Use percentage to dictate probability of mutation (between 0 and 1), following standard normal distribution
---- But do this both ways around so really full mutation rate can be either very high, or very low
*/
class Sleeper : public QThread
{
public:
static void usleep(unsigned long usecs){QThread::usleep(usecs);}
static void msleep(unsigned long msecs){QThread::msleep(msecs);}
static void sleep(unsigned long secs){QThread::sleep(secs);}
};
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
a = new Analyser; // so can delete next time!
ui->setupUi(this);
MainWin=this;
//RJG - Output version, but also date compiled for clarity
QString version;
version.sprintf("%d.%d.%d",MAJORVERSION,MINORVERSION,PATCHVERSION);
setWindowTitle(QString(PRODUCTNAME)+" v"+version+" - compiled - "+__DATE__);
setWindowIcon(QIcon (":/icon.png"));
//Install filter to catch resize events to central widget and deliver to mainwindow (handle dock resizes)
ResizeCatcher *rescatch = new ResizeCatcher(this);
ui->centralWidget->installEventFilter(rescatch);
//ARTS - Toolbar buttons
//RJG - docker toggles
startButton = new QAction(QIcon(QPixmap(":/toolbar/startButton-Enabled.png")), QString("Run"), this);
runForButton = new QAction(QIcon(QPixmap(":/toolbar/runForButton-Enabled.png")), QString("Run for..."), this);
runForBatchButton = new QAction(QIcon(QPixmap(":/toolbar/runForBatchButton-Enabled.png")), QString("Batch..."), this);
pauseButton = new QAction(QIcon(QPixmap(":/toolbar/pauseButton-Enabled.png")), QString("Pause"), this);
stopButton = new QAction(QIcon(QPixmap(":/toolbar/stopButton-Enabled.png")), QString("Stop"), this);
resetButton = new QAction(QIcon(QPixmap(":/toolbar/resetButton-Enabled.png")), QString("Reset"), this);
reseedButton = new QAction(QIcon(QPixmap(":/toolbar/resetButton_knowngenome-Enabled.png")), QString("Reseed"), this);
settingsButton = new QAction(QIcon(QPixmap(":/toolbar/globesettingsButton-Enabled-white.png")), QString("Settings"), this);
aboutButton = new QAction(QIcon(QPixmap(":/toolbar/aboutButton-Enabled-white.png")), QString("About"), this);
//ARTS - Toolbar default settings
//RJG - docker toggles defaults
startButton->setEnabled(false);
runForButton->setEnabled(false);
pauseButton->setEnabled(false);
stopButton->setEnabled(false);
reseedButton->setEnabled(false);
runForBatchButton->setEnabled(false);
settingsButton->setCheckable(true);
//ARTS - Toolbar layout
ui->toolBar->addAction(startButton);
ui->toolBar->addSeparator();
ui->toolBar->addAction(runForButton);
ui->toolBar->addSeparator();
ui->toolBar->addAction(runForBatchButton);
ui->toolBar->addSeparator();
ui->toolBar->addAction(pauseButton);
ui->toolBar->addSeparator();
ui->toolBar->addAction(stopButton);
ui->toolBar->addSeparator();
ui->toolBar->addAction(resetButton);
ui->toolBar->addSeparator();
ui->toolBar->addAction(reseedButton);
ui->toolBar->addSeparator();
ui->toolBar->addAction(settingsButton);
//Spacer
QWidget* empty = new QWidget();
empty->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred);
empty->setMaximumWidth(10);
empty->setMaximumHeight(5);
ui->toolBar->addWidget(empty);
ui->toolBar->addSeparator();
ui->toolBar->addAction(aboutButton);
//RJG - Connect button signals to slot.
//Note for clarity:
//Reset = start again with random individual.
//Reseed = start again with user defined genome
QObject::connect(startButton, SIGNAL(triggered()), this, SLOT(on_actionStart_Sim_triggered()));
QObject::connect(runForButton, SIGNAL(triggered()), this, SLOT(on_actionRun_for_triggered()));
QObject::connect(pauseButton, SIGNAL(triggered()), this, SLOT(on_actionPause_Sim_triggered()));
QObject::connect(stopButton, SIGNAL(triggered()), this, SLOT(on_actionStop_Sim_triggered()));
QObject::connect(resetButton, SIGNAL(triggered()), this, SLOT(on_actionReset_triggered()));
QObject::connect(reseedButton, SIGNAL(triggered()), this, SLOT(on_actionReseed_triggered()));
QObject::connect(runForBatchButton, SIGNAL(triggered()), this, SLOT(on_actionBatch_triggered()));
QObject::connect(settingsButton, SIGNAL(triggered()), this, SLOT(on_actionSettings_triggered()));
QObject::connect(aboutButton, SIGNAL (triggered()), this, SLOT (on_actionAbout_triggered()));
QObject::connect(ui->actionSave_settings, SIGNAL (triggered()), this, SLOT (save_settings()));
QObject::connect(ui->actionLoad_settings, SIGNAL (triggered()), this, SLOT (load_settings()));
QObject::connect(ui->actionCount_peaks, SIGNAL(triggered()), this, SLOT(on_actionCount_Peaks_triggered()));
//RJG - set up settings docker.
simulationSettingsDock = createSimulationSettingsDock();
//----RJG - second settings docker.
organismSettingsDock = createOrganismSettingsDock();
//RJG - Third settings docker
outputSettingsDock = createOutputSettingsDock();
simulationSettingsDock->setObjectName("simulationSettingsDock");
organismSettingsDock->setObjectName("organismSettingsDock");
outputSettingsDock->setObjectName("outputSettingsDock");
//RJG - Make docks tabbed
tabifyDockWidget(organismSettingsDock,simulationSettingsDock);
tabifyDockWidget(simulationSettingsDock,outputSettingsDock);
//ARST - Hide docks by default
organismSettingsDock->hide();
simulationSettingsDock->hide();
outputSettingsDock->hide();
//ARTS - Add Genome Comparison UI
ui->genomeComparisonDock->hide();
genoneComparison = new GenomeComparison;
QVBoxLayout *genomeLayout = new QVBoxLayout;
genomeLayout->addWidget(genoneComparison);
ui->genomeComparisonContent->setLayout(genomeLayout);
//MDS - as above for fossil record dock and report dock
ui->fossRecDock->hide();
FRW = new FossRecWidget();
QVBoxLayout *frwLayout = new QVBoxLayout;
frwLayout->addWidget(FRW);
ui->fossRecDockContents->setLayout(frwLayout);
ui->reportViewerDock->hide();
viewgroup2 = new QActionGroup(this);
// These actions were created via qt designer
viewgroup2->addAction(ui->actionNone);
viewgroup2->addAction(ui->actionSorted_Summary);
viewgroup2->addAction(ui->actionGroups);
viewgroup2->addAction(ui->actionGroups2);
viewgroup2->addAction(ui->actionSimple_List);
QObject::connect(viewgroup2, SIGNAL(triggered(QAction *)), this, SLOT(report_mode_changed(QAction *)));
//create scenes, add to the GVs
envscene = new EnvironmentScene;
ui->GV_Environment->setScene(envscene);
envscene->mw=this;
popscene = new PopulationScene;
popscene->mw=this;
ui->GV_Population->setScene(popscene);
//add images to the scenes
env_item= new QGraphicsPixmapItem();
envscene->addItem(env_item);
env_item->setZValue(0);
pop_item = new QGraphicsPixmapItem();
popscene->addItem(pop_item);
pop_image=new QImage(gridX, gridY, QImage::Format_Indexed8);
QVector <QRgb> clut(256);
for (int ic=0; ic<256; ic++) clut[ic]=qRgb(ic,ic,ic);
pop_image->setColorTable(clut);
pop_image->fill(0);
env_image=new QImage(gridX, gridY, QImage::Format_RGB32);
env_image->fill(0);
pop_image_colour=new QImage(gridX, gridY, QImage::Format_RGB32);
env_image->fill(0);
env_item->setPixmap(QPixmap::fromImage(*env_image));
pop_item->setPixmap(QPixmap::fromImage(*pop_image));
//ARTS - Population Window dropdown must be after settings dock setup
// 0 = Population count
// 1 = Mean fitnessFails (R-Breed, G=Settle)
// 2 = Coding genome as colour
// 3 = NonCoding genome as colour
// 4 = Gene Frequencies
// 5 = Breed Attempts
// 6 = Breed Fails
// 7 = Settles
// 8 = Settle Fails
// 9 = Breed Fails 2
// 10 = Species
ui->populationWindowComboBox->addItem("Population count",QVariant(0));
ui->populationWindowComboBox->addItem("Mean fitnessFails (R-Breed, G=Settle)",QVariant(1));
ui->populationWindowComboBox->addItem("Coding genome as colour",QVariant(2));
ui->populationWindowComboBox->addItem("NonCoding genome as colour",QVariant(3));
ui->populationWindowComboBox->addItem("Gene Frequencies",QVariant(4));
//ui->populationWindowComboBox->addItem("Breed Attempts",QVariant(5));
//ui->populationWindowComboBox->addItem("Breed Fails",QVariant(6));
ui->populationWindowComboBox->addItem("Settles",QVariant(7));
ui->populationWindowComboBox->addItem("Settle Fails",QVariant(8));
//ui->populationWindowComboBox->addItem("Breed Fails 2",QVariant(9));
ui->populationWindowComboBox->addItem("Species",QVariant(10));
//ARTS -Population Window dropdown set current index. Note this value is the index not the data value.
ui->populationWindowComboBox->setCurrentIndex(2);
TheSimManager = new SimManager;
pauseflag = false;
//RJG - load default environment image to allow program to run out of box (quicker for testing)
EnvFiles.append(":/EvoSim_default_env.png");
CurrentEnvFile=0;
TheSimManager->loadEnvironmentFromFile(1);
FinishRun();//sets up enabling
TheSimManager->SetupRun();
NextRefresh=0;
Report();
//RJG - Set batch variables
batch_running=false;
runs=-1;
batch_iterations=-1;
batch_target_runs=-1;
showMaximized();
//RJG - seed pseudorandom numbers
qsrand(QTime::currentTime().msec());
//RJG - Now load randoms into program - portable rand is just plain pseudorandom number - initially used in makelookups (called from simmanager contructor) to write to randoms array
int seedoffset = TheSimManager->portable_rand();
QFile rfile(":/randoms.dat");
if (!rfile.exists()) QMessageBox::warning(this,"Oops","Error loading randoms. Please do so manually.");
rfile.open(QIODevice::ReadOnly);
rfile.seek(seedoffset);
//RJG - overwrite pseudorandoms with genuine randoms
int i=rfile.read((char *)randoms,65536);
if (i!=65536) QMessageBox::warning(this,"Oops","Failed to read 65536 bytes from file - random numbers may be compromised - try again or restart program");
//RJG - fill cumulative_normal_distribution with numbers for variable breeding
//These are a cumulative standard normal distribution from -3 to 3, created using the math.h complementary error function
//Then scaled to zero to 32 bit rand max, to allow for probabilities within each iteration through a random number
float x=-3., inc=(6./32.);
for(int cnt=0;cnt<33;cnt++)
{
double NSDF=(0.5 * erfc(-(x) * M_SQRT1_2));
cumulative_normal_distribution[cnt]=4294967296*NSDF;
x+=inc;
}
//RJG - fill pathogen probability distribution as required so pathogens can kill critters
//Start with linear, may want to change down the line.
for(int cnt=0;cnt<65;cnt++)
pathogen_prob_distribution[cnt]=(4294967296/2)+(cnt*(4294967295/128));
}
MainWindow::~MainWindow()
{
delete ui;
delete TheSimManager;
}
QDockWidget *MainWindow::createSimulationSettingsDock()
{
simulationSettingsDock = new QDockWidget("Simulation", this);
simulationSettingsDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
simulationSettingsDock->setFeatures(QDockWidget::DockWidgetMovable);
simulationSettingsDock->setFeatures(QDockWidget::DockWidgetFloatable);
addDockWidget(Qt::RightDockWidgetArea, simulationSettingsDock);
QGridLayout *settings_grid = new QGridLayout;
settings_grid->setAlignment(Qt::AlignTop);
// Environment Settings
QGridLayout *environmentSettingsGrid = new QGridLayout;
QLabel *environment_label= new QLabel("Environmental Settings");
environment_label->setStyleSheet("font-weight: bold");
environmentSettingsGrid->addWidget(environment_label,0,1,1,2);
QPushButton *changeEnvironmentFilesButton = new QPushButton("&Change Enviroment Files");
changeEnvironmentFilesButton->setObjectName("changeEnvironmentFilesButton");
changeEnvironmentFilesButton->setToolTip("<font>REvoSim allow you to customise the enviroment by loading one or more image files.</font>");
environmentSettingsGrid->addWidget(changeEnvironmentFilesButton,1,1,1,2);
connect(changeEnvironmentFilesButton, SIGNAL (clicked()), this, SLOT(on_actionEnvironment_Files_triggered()));
QLabel *environment_rate_label = new QLabel("Environment refresh rate:");
environment_rate_label->setToolTip("<font>This is the rate of change for the selected enviromental images.</font>");
environment_rate_spin = new QSpinBox;
environment_rate_spin->setToolTip("<font>This is the rate of change for the selected enviromental images.</font>");
environment_rate_spin->setMinimum(0);
environment_rate_spin->setMaximum(100000);
environment_rate_spin->setValue(envchangerate);
environmentSettingsGrid->addWidget(environment_rate_label,2,1);
environmentSettingsGrid->addWidget(environment_rate_spin,2,2);
//RJG - Note in order to use a lamda not only do you need to use C++11, but there are two valueChanged signals for spinbox - and int and a string. Need to cast it to an int
connect(environment_rate_spin,(void(QSpinBox::*)(int))&QSpinBox::valueChanged,[=](const int &i ) { envchangerate=i; });
QLabel *environment_mode_label = new QLabel("Environment mode:");
environmentSettingsGrid->addWidget(environment_mode_label,3,1,1,2);
QGridLayout *environmentModeGrid = new QGridLayout;
environmentModeStaticButton = new QRadioButton("Static");
environmentModeStaticButton->setToolTip("<font>'Static' uses a single environment image.</font>");
environmentModeOnceButton = new QRadioButton("Once");
environmentModeOnceButton->setToolTip("<font>'Once' uses each image only once, simulation stops after last image.</font>");
environmentModeLoopButton = new QRadioButton("Loop");
environmentModeLoopButton->setToolTip("<font>'Loop' uses each image in order in a loop</font>");
environmentModeBounceButton = new QRadioButton("Bounce");
environmentModeBounceButton->setToolTip("<font>'Bounce' rebounds between the first and last image in a loop.</font>");
QButtonGroup* environmentModeButtonGroup = new QButtonGroup;
environmentModeButtonGroup->addButton(environmentModeStaticButton,ENV_MODE_STATIC);
environmentModeButtonGroup->addButton(environmentModeOnceButton,ENV_MODE_ONCE);
environmentModeButtonGroup->addButton(environmentModeLoopButton,ENV_MODE_LOOP);
environmentModeButtonGroup->addButton(environmentModeBounceButton,ENV_MODE_BOUNCE);
environmentModeLoopButton->setChecked(true);
environmentModeGrid->addWidget(environmentModeStaticButton,1,1,1,2);
environmentModeGrid->addWidget(environmentModeOnceButton,1,2,1,2);
environmentModeGrid->addWidget(environmentModeLoopButton,2,1,1,2);
environmentModeGrid->addWidget(environmentModeBounceButton,2,2,1,2);
connect(environmentModeButtonGroup, (void(QButtonGroup::*)(int))&QButtonGroup::buttonClicked,[=](const int &i) { environment_mode_changed(i,false); });
environmentSettingsGrid->addLayout(environmentModeGrid,4,1,1,2);
interpolateCheckbox = new QCheckBox("Interpolate between images");
interpolateCheckbox->setChecked(enviroment_interpolate);
interpolateCheckbox->setToolTip("<font>Turning this ON will iterpolate the environment between individual images.</font>");
environmentSettingsGrid->addWidget(interpolateCheckbox,5,1,1,2);
connect(interpolateCheckbox,&QCheckBox::stateChanged,[=](const bool &i) { enviroment_interpolate=i; });
toroidal_checkbox = new QCheckBox("Toroidal enviroment");
toroidal_checkbox->setChecked(toroidal);
toroidal_checkbox->setToolTip("<font>Turning this ON will allow dispersal of progeny in an unbounded warparound enviroment. Progeny leaving one side of the population window will immediately reappear on the opposite side.</font>");
environmentSettingsGrid->addWidget(toroidal_checkbox,6,1,1,2);
connect(toroidal_checkbox,&QCheckBox::stateChanged,[=](const bool &i) { toroidal=i; });
// Simulation Size Settings
QGridLayout *simulationSizeSettingsGrid = new QGridLayout;
QLabel *simulation_size_label= new QLabel("Simulation size");
simulation_size_label->setStyleSheet("font-weight: bold");
simulationSizeSettingsGrid->addWidget(simulation_size_label,0,1,1,2);
QLabel *gridX_label = new QLabel("Grid X:");
gridX_spin = new QSpinBox;
gridX_spin->setMinimum(1);
gridX_spin->setMaximum(256);
gridX_spin->setValue(gridX);
simulationSizeSettingsGrid->addWidget(gridX_label,2,1);
simulationSizeSettingsGrid->addWidget(gridX_spin,2,2);
connect(gridX_spin,(void(QSpinBox::*)(int))&QSpinBox::valueChanged,[=](const int &i) { int oldrows=gridX; gridX=i;redoImages(oldrows,gridY);});
QLabel *gridY_label = new QLabel("Grid Y:");
gridY_spin = new QSpinBox;
gridY_spin->setMinimum(1);
gridY_spin->setMaximum(256);
gridY_spin->setValue(gridY);
simulationSizeSettingsGrid->addWidget(gridY_label,3,1);
simulationSizeSettingsGrid->addWidget(gridY_spin,3,2);
connect(gridY_spin,(void(QSpinBox::*)(int))&QSpinBox::valueChanged,[=](const int &i) {int oldcols=gridY; gridY=i;redoImages(gridX,oldcols);});
QLabel *slots_label = new QLabel("Slots:");
slots_spin = new QSpinBox;
slots_spin->setMinimum(1);
slots_spin->setMaximum(256);
slots_spin->setValue(slotsPerSq);
simulationSizeSettingsGrid->addWidget(slots_label,4,1);
simulationSizeSettingsGrid->addWidget(slots_spin,4,2);
connect(slots_spin,(void(QSpinBox::*)(int))&QSpinBox::valueChanged,[=](const int &i) { slotsPerSq=i;redoImages(gridX,gridY); });
// Simulation Settings
QGridLayout *simulationSettingsGrid = new QGridLayout;
QLabel *simulation_settings_label= new QLabel("Simulation settings");
simulation_settings_label->setStyleSheet("font-weight: bold");
simulationSettingsGrid->addWidget(simulation_settings_label,0,1,1,2);
QLabel *target_label = new QLabel("Fitness target:");
target_spin = new QSpinBox;
target_spin->setMinimum(1);
target_spin->setMaximum(96);
target_spin->setValue(target);
simulationSettingsGrid->addWidget(target_label,1,1);
simulationSettingsGrid->addWidget(target_spin,1,2);
connect(target_spin,(void(QSpinBox::*)(int))&QSpinBox::valueChanged,[=](const int &i) { target=i; });
QLabel *energy_label = new QLabel("Energy input:");
energy_spin = new QSpinBox;
energy_spin->setMinimum(1);
energy_spin->setMaximum(20000);
energy_spin->setValue(food);
simulationSettingsGrid->addWidget(energy_label,2,1);
simulationSettingsGrid->addWidget(energy_spin,2,2);
connect(energy_spin,(void(QSpinBox::*)(int))&QSpinBox::valueChanged,[=](const int &i) { food=i; });
QLabel *settleTolerance_label = new QLabel("Settle tolerance:");
settleTolerance_spin = new QSpinBox;
settleTolerance_spin->setMinimum(1);
settleTolerance_spin->setMaximum(30);
settleTolerance_spin->setValue(settleTolerance);
simulationSettingsGrid->addWidget(settleTolerance_label,3,1);
simulationSettingsGrid->addWidget(settleTolerance_spin,3,2);
connect(settleTolerance_spin,(void(QSpinBox::*)(int))&QSpinBox::valueChanged,[=](const int &i) { settleTolerance=i; });
recalcFitness_checkbox = new QCheckBox("Recalculate fitness");
recalcFitness_checkbox->setChecked(toroidal);
simulationSettingsGrid->addWidget(recalcFitness_checkbox,4,1,1,2);
connect(recalcFitness_checkbox,&QCheckBox::stateChanged,[=](const bool &i) { recalcFitness=i; });
//Phylogeny Settings
QGridLayout *phylogenySettingsGrid = new QGridLayout;
QLabel *phylogeny_settings_label= new QLabel("Phylogeny settings");
phylogeny_settings_label->setStyleSheet("font-weight: bold");
phylogenySettingsGrid->addWidget(phylogeny_settings_label,0,1,1,1);
QGridLayout *phylogeny_grid = new QGridLayout;
phylogeny_off_button = new QRadioButton("Off");
basic_phylogeny_button = new QRadioButton("Basic");
phylogeny_button = new QRadioButton("Phylogeny");
phylogeny_and_metrics_button = new QRadioButton("Phylogeny and metrics");
QButtonGroup* phylogeny_button_group = new QButtonGroup;
phylogeny_button_group->addButton(phylogeny_off_button,SPECIES_MODE_NONE);
phylogeny_button_group->addButton(basic_phylogeny_button,SPECIES_MODE_BASIC);
phylogeny_button_group->addButton(phylogeny_button,SPECIES_MODE_PHYLOGENY);
phylogeny_button_group->addButton(phylogeny_and_metrics_button,SPECIES_MODE_PHYLOGENY_AND_METRICS);
basic_phylogeny_button->setChecked(true);
phylogeny_grid->addWidget(phylogeny_off_button,1,1,1,2);
phylogeny_grid->addWidget(basic_phylogeny_button,1,2,1,2);
phylogeny_grid->addWidget(phylogeny_button,2,1,1,2);
phylogeny_grid->addWidget(phylogeny_and_metrics_button,2,2,1,2);
connect(phylogeny_button_group, (void(QButtonGroup::*)(int))&QButtonGroup::buttonClicked,[=](const int &i) { species_mode_changed(i); });
phylogenySettingsGrid->addLayout(phylogeny_grid,1,1,1,2);
//ARTS - Dock Grid Layout
settings_grid->addLayout(environmentSettingsGrid,0,1);
settings_grid->addLayout(simulationSizeSettingsGrid,1,1);
settings_grid->addLayout(simulationSettingsGrid,2,1);
settings_grid->addLayout(phylogenySettingsGrid,3,1);
QWidget *settings_layout_widget = new QWidget;
settings_layout_widget->setLayout(settings_grid);
settings_layout_widget->setMinimumWidth(300);
simulationSettingsDock->setWidget(settings_layout_widget);
simulationSettingsDock->adjustSize();
return simulationSettingsDock;
}
QDockWidget *MainWindow::createOutputSettingsDock()
{
outputSettingsDock = new QDockWidget("Output", this);
outputSettingsDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
outputSettingsDock->setFeatures(QDockWidget::DockWidgetMovable);
outputSettingsDock->setFeatures(QDockWidget::DockWidgetFloatable);
addDockWidget(Qt::RightDockWidgetArea, outputSettingsDock);
QGridLayout *output_settings_grid = new QGridLayout;
output_settings_grid->setAlignment(Qt::AlignTop);
//ARTS - Output Save Path
QGridLayout *savePathGrid = new QGridLayout;
QLabel *savePathLabel = new QLabel("Output save path");
savePathLabel->setObjectName("savePathLabel");
savePathGrid->addWidget(savePathLabel,1,1,1,2);
QString program_path(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation));
program_path.append("/");
path = new QLineEdit(program_path);
savePathGrid->addWidget(path,2,1,1,2);
QPushButton *changePathButton = new QPushButton("&Change");
changePathButton->setObjectName("changePathButton");
savePathGrid->addWidget(changePathButton,3,1,1,2);
connect(changePathButton, SIGNAL (clicked()), this, SLOT(changepath_triggered()));
//ARTS - Refresh/Polling Rate
QGridLayout *pollingRateGrid = new QGridLayout;
QLabel *pollingRateLabel = new QLabel("Refresh/Polling Rate");
pollingRateLabel->setObjectName("pollingRateLabel");
pollingRateGrid->addWidget(pollingRateLabel,1,1,1,2);
RefreshRate=50;
QLabel *refreshRateLabel = new QLabel("Refresh/polling rate:");
refreshRateLabel->setObjectName("refreshRateLabel");
refreshRateSpin = new QSpinBox;
refreshRateSpin->setMinimum(1);
refreshRateSpin->setMaximum(10000);
refreshRateSpin->setValue(RefreshRate);
pollingRateGrid->addWidget(refreshRateLabel,2,1);
pollingRateGrid->addWidget(refreshRateSpin,2,2);
connect(refreshRateSpin,(void(QSpinBox::*)(int))&QSpinBox::valueChanged,[=](const int &i) { RefreshRate=i; });
//ARTS - Logging: Population & Environment
QGridLayout *images_grid = new QGridLayout;
QLabel *imagesLabel= new QLabel("Logging: Population/Enivronment");
imagesLabel->setObjectName("imagesLabel");
images_grid->addWidget(imagesLabel,1,1,1,2);
QLabel *imagesInfoLabel= new QLabel("Turn on/off these logging options to save images of the population/environment windows every refresh/poll.");
imagesInfoLabel->setObjectName("imagesInfoLabel");
imagesInfoLabel->setWordWrap(true);
images_grid->addWidget(imagesInfoLabel,2,1,1,2);
save_population_count = new QCheckBox("Population count");
images_grid->addWidget(save_population_count,3,1,1,1);
save_mean_fitness = new QCheckBox("Mean fitness");
images_grid->addWidget(save_mean_fitness,3,2,1,1);
save_coding_genome_as_colour = new QCheckBox("Coding genome");
images_grid->addWidget(save_coding_genome_as_colour,4,1,1,1);
save_non_coding_genome_as_colour = new QCheckBox("Noncoding genome");
images_grid->addWidget(save_non_coding_genome_as_colour,4,2,1,1);
save_species = new QCheckBox("Species");
images_grid->addWidget(save_species,5,1,1,1);
save_gene_frequencies = new QCheckBox("Gene frequencies");
images_grid->addWidget(save_gene_frequencies,5,2,1,1);
save_settles = new QCheckBox("Settles");
images_grid->addWidget(save_settles,6,1,1,1);
save_fails_settles = new QCheckBox("Fails + settles");
images_grid->addWidget(save_fails_settles,6,2,1,1);
save_environment = new QCheckBox("Environment");
images_grid->addWidget(save_environment,7,1,1,1);
QCheckBox *saveAllImagesCheckbox = new QCheckBox("All");
saveAllImagesCheckbox->setObjectName("saveAllImagesCheckbox");
images_grid->addWidget(saveAllImagesCheckbox,7,2,1,1);
QObject::connect(saveAllImagesCheckbox, SIGNAL (toggled(bool)), this, SLOT(save_all_checkbox_state_changed(bool)));
//ARTS - Logging to text file
QGridLayout *fileLoggingGrid = new QGridLayout;
QLabel *outputSettingsLabel= new QLabel("Logging: To Text File(s)");
outputSettingsLabel->setObjectName("outputSettingsLabel");
fileLoggingGrid->addWidget(outputSettingsLabel,1,1,1,2);
QLabel *textLogInfoLabel= new QLabel("Turn on/off this option to write to a text log file every refresh/poll.");
textLogInfoLabel->setObjectName("textLogInfoLabel");
textLogInfoLabel->setWordWrap(true);
fileLoggingGrid->addWidget(textLogInfoLabel,2,1,1,2);
logging_checkbox = new QCheckBox("Write Text Log Files");
logging_checkbox->setChecked(logging);
fileLoggingGrid->addWidget(logging_checkbox,3,1,1,2);
connect(logging_checkbox,&QCheckBox::stateChanged,[=](const bool &i) { logging=i; });
QLabel *textLogInfo1Label= new QLabel("After a batched run has finished a more detailed log file (includding trees) can be automatically created.");
textLogInfo1Label->setObjectName("textLogInfo1Label");
textLogInfo1Label->setWordWrap(true);
fileLoggingGrid->addWidget(textLogInfo1Label,4,1,1,2);
autodump_checkbox= new QCheckBox("Create automatically detailed log on batch runs");
autodump_checkbox->setChecked(true);
fileLoggingGrid->addWidget(autodump_checkbox,5,1,1,2);
QLabel *textLogInfo2Label= new QLabel("...you can also manually create this detailed log file after any run.");
textLogInfo2Label->setObjectName("textLogInfo2Label");
textLogInfo2Label->setWordWrap(true);
fileLoggingGrid->addWidget(textLogInfo2Label,6,1,1,2);
QPushButton *dump_nwk = new QPushButton("Write data (including tree) for current run");
fileLoggingGrid->addWidget(dump_nwk,7,1,1,2);
connect(dump_nwk , SIGNAL (clicked()), this, SLOT(dump_run_data()));
QLabel *textLogInfo3Label= new QLabel("More advanced options on what is included in the log files:");
textLogInfo3Label->setObjectName("textLogInfo3Label");
textLogInfo3Label->setWordWrap(true);
fileLoggingGrid->addWidget(textLogInfo3Label,8,1,1,2);
exclude_without_issue_checkbox = new QCheckBox("Exclude species without issue");
exclude_without_issue_checkbox->setChecked(allowexcludewithissue);
fileLoggingGrid->addWidget(exclude_without_issue_checkbox,9,1,1,1);
connect(exclude_without_issue_checkbox,&QCheckBox::stateChanged,[=](const bool &i) { allowexcludewithissue=i; });
QLabel *Min_species_size_label = new QLabel("Minimum species size:");
QSpinBox *Min_species_size_spin = new QSpinBox;
Min_species_size_spin->setMinimum(0);
Min_species_size_spin->setMaximum(10000);
Min_species_size_spin->setValue(minspeciessize);
fileLoggingGrid->addWidget(Min_species_size_label,10,1);
fileLoggingGrid->addWidget(Min_species_size_spin,10,2);
connect(Min_species_size_spin,(void(QSpinBox::*)(int))&QSpinBox::valueChanged,[=](const int &i) { minspeciessize=i; });
//ARTS - Advanced
QGridLayout *advancedLoggingGrid = new QGridLayout;
QLabel *advancedSettingsLabel= new QLabel("Advanced");
advancedSettingsLabel->setObjectName("advancedSettingsLabel");
advancedLoggingGrid->addWidget(advancedSettingsLabel,1,1,1,2);
QLabel *guiInfoLabel= new QLabel("If you turn off GUI update you cannot log the population/environment windows using saved images.");
guiInfoLabel->setObjectName("guiInfoLabel");
guiInfoLabel->setWordWrap(true);
advancedLoggingGrid->addWidget(guiInfoLabel,2,1,1,2);
gui_checkbox = new QCheckBox("Don't update GUI on refresh/poll");
gui_checkbox->setChecked(gui);
advancedLoggingGrid->addWidget(gui_checkbox,3,1,1,2);
QObject::connect(gui_checkbox ,SIGNAL (toggled(bool)), this, SLOT(gui_checkbox_state_changed(bool)));
//ARTS - Dock Grid Layout
output_settings_grid->addLayout(savePathGrid,1,1,1,2);
output_settings_grid->addLayout(pollingRateGrid,2,1,1,2);
output_settings_grid->addLayout(images_grid,3,1,1,2);
output_settings_grid->addLayout(fileLoggingGrid,4,1,1,2);
output_settings_grid->addLayout(advancedLoggingGrid,5,1,1,2);
QWidget *output_settings_layout_widget = new QWidget;
output_settings_layout_widget->setLayout(output_settings_grid);
outputSettingsDock->setWidget(output_settings_layout_widget);
return outputSettingsDock;
}
QDockWidget *MainWindow::createOrganismSettingsDock() {
organismSettingsDock = new QDockWidget("Organism", this);
organismSettingsDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
organismSettingsDock->setFeatures(QDockWidget::DockWidgetMovable);
organismSettingsDock->setFeatures(QDockWidget::DockWidgetFloatable);
addDockWidget(Qt::RightDockWidgetArea, organismSettingsDock);
QGridLayout *org_settings_grid = new QGridLayout;
org_settings_grid->setAlignment(Qt::AlignTop);
QLabel *org_settings_label= new QLabel("Organism settings");
org_settings_label->setStyleSheet("font-weight: bold");
org_settings_grid->addWidget(org_settings_label,1,1,1,2);
QLabel *mutate_label = new QLabel("Chance of mutation:");
mutate_spin = new QSpinBox;
mutate_spin->setMinimum(0);
mutate_spin->setMaximum(255);
mutate_spin->setValue(mutate);
org_settings_grid->addWidget(mutate_label,2,1);
org_settings_grid->addWidget(mutate_spin,2,2);
connect(mutate_spin,(void(QSpinBox::*)(int))&QSpinBox::valueChanged,[=](const int &i) {mutate=i;});
variable_mutation_checkbox = new QCheckBox("Variable mutation");
org_settings_grid->addWidget(variable_mutation_checkbox,3,1,1,1);
variable_mutation_checkbox->setChecked(variableMutate);
connect(variable_mutation_checkbox,&QCheckBox::stateChanged,[=](const bool &i) { variableMutate=i; mutate_spin->setEnabled(!i); });
QLabel *startAge_label = new QLabel("Start age:");
startAge_spin = new QSpinBox;
startAge_spin->setMinimum(1);
startAge_spin->setMaximum(1000);
startAge_spin->setValue(startAge);
org_settings_grid->addWidget(startAge_label,4,1);
org_settings_grid->addWidget(startAge_spin,4,2);
connect(startAge_spin,(void(QSpinBox::*)(int))&QSpinBox::valueChanged,[=](const int &i) {startAge=i;});
QLabel *breed_settings_label= new QLabel("Breed settings");
breed_settings_label->setStyleSheet("font-weight: bold");
org_settings_grid->addWidget(breed_settings_label,5,1,1,2);
QLabel *breedThreshold_label = new QLabel("Breed threshold:");
breedThreshold_spin = new QSpinBox;
breedThreshold_spin->setMinimum(1);
breedThreshold_spin->setMaximum(5000);
breedThreshold_spin->setValue(breedThreshold);
org_settings_grid->addWidget(breedThreshold_label,6,1);
org_settings_grid->addWidget(breedThreshold_spin,6,2);
connect(breedThreshold_spin,(void(QSpinBox::*)(int))&QSpinBox::valueChanged,[=](const int &i) {breedThreshold=i;});
QLabel *breedCost_label = new QLabel("Breed cost:");
breedCost_spin = new QSpinBox;
breedCost_spin->setMinimum(1);
breedCost_spin->setMaximum(10000);
breedCost_spin->setValue(breedCost);
org_settings_grid->addWidget(breedCost_label,7,1);
org_settings_grid->addWidget(breedCost_spin,7,2);
connect(breedCost_spin,(void(QSpinBox::*)(int))&QSpinBox::valueChanged,[=](const int &i) {breedCost=i;});
QLabel *maxDiff_label = new QLabel("Max difference to breed:");
maxDiff_spin = new QSpinBox;
maxDiff_spin->setMinimum(1);
maxDiff_spin->setMaximum(31);
maxDiff_spin->setValue(maxDiff);
org_settings_grid->addWidget(maxDiff_label,8,1);
org_settings_grid->addWidget(maxDiff_spin,8,2);
connect(maxDiff_spin,(void(QSpinBox::*)(int))&QSpinBox::valueChanged,[=](const int &i) {maxDiff=i;});
breeddiff_checkbox = new QCheckBox("Use max diff to breed");
org_settings_grid->addWidget(breeddiff_checkbox,9,1,1,1);
breeddiff_checkbox->setChecked(breeddiff);
connect(breeddiff_checkbox,&QCheckBox::stateChanged,[=](const bool &i) { breeddiff=i;});
breedspecies_checkbox = new QCheckBox("Breed only within species");
org_settings_grid->addWidget(breedspecies_checkbox,10,1,1,1);
breedspecies_checkbox->setChecked(breedspecies);
connect(breedspecies_checkbox,&QCheckBox::stateChanged,[=](const bool &i) { breedspecies=i;});
QLabel *breed_mode_label= new QLabel("Breed mode:");
org_settings_grid->addWidget(breed_mode_label,11,1,1,2);
sexual_radio = new QRadioButton("Sexual");
asexual_radio = new QRadioButton("Asexual");
variableBreed_radio = new QRadioButton("Variable");
QButtonGroup *breeding_button_group = new QButtonGroup;
breeding_button_group->addButton(sexual_radio,0);
breeding_button_group->addButton(asexual_radio,1);
breeding_button_group->addButton(variableBreed_radio,2);
sexual_radio->setChecked(sexual);
asexual_radio->setChecked(asexual);
variableBreed_radio->setChecked(variableBreed);
org_settings_grid->addWidget(sexual_radio,12,1,1,2);
org_settings_grid->addWidget(asexual_radio,13,1,1,2);
org_settings_grid->addWidget(variableBreed_radio,14,1,1,2);
connect(breeding_button_group, (void(QButtonGroup::*)(int))&QButtonGroup::buttonClicked,[=](const int &i)
{
if(i==0){sexual=true;asexual=false;variableBreed=false;}
if(i==1){sexual=false;asexual=true;variableBreed=false;}
if(i==2){sexual=false;asexual=false;variableBreed=true;}
});
QLabel *settle_settings_label= new QLabel("Settle settings");
settle_settings_label->setStyleSheet("font-weight: bold");
org_settings_grid->addWidget(settle_settings_label,15,1,1,2);
QLabel *dispersal_label = new QLabel("Dispersal:");
dispersal_spin = new QSpinBox;
dispersal_spin->setMinimum(1);
dispersal_spin->setMaximum(200);
dispersal_spin->setValue(dispersal);
org_settings_grid->addWidget(dispersal_label,16,1);
org_settings_grid->addWidget(dispersal_spin,16,2);
connect(dispersal_spin,(void(QSpinBox::*)(int))&QSpinBox::valueChanged,[=](const int &i) {dispersal=i;});
nonspatial_checkbox = new QCheckBox("Nonspatial settling");
org_settings_grid->addWidget(nonspatial_checkbox,17,1,1,2);
nonspatial_checkbox->setChecked(nonspatial);
connect(nonspatial_checkbox,&QCheckBox::stateChanged,[=](const bool &i) {nonspatial=i;});
QLabel *pathogen_settings_label= new QLabel("Pathogen settings");
pathogen_settings_label->setStyleSheet("font-weight: bold");
org_settings_grid->addWidget(pathogen_settings_label,18,1,1,2);
pathogens_checkbox = new QCheckBox("Pathogens layer");
org_settings_grid->addWidget(pathogens_checkbox,19,1,1,2);
pathogens_checkbox->setChecked(path_on);
connect(pathogens_checkbox,&QCheckBox::stateChanged,[=](const bool &i) {path_on=i;});
QLabel *pathogen_mutate_label = new QLabel("Pathogen mutation:");
pathogen_mutate_spin = new QSpinBox;
pathogen_mutate_spin->setMinimum(1);
pathogen_mutate_spin->setMaximum(255);
pathogen_mutate_spin->setValue(pathogen_mutate);
org_settings_grid->addWidget(pathogen_mutate_label,20,1);
org_settings_grid->addWidget(pathogen_mutate_spin,20,2);
connect(pathogen_mutate_spin,(void(QSpinBox::*)(int))&QSpinBox::valueChanged,[=](const int &i) {pathogen_mutate=i;});
QLabel *pathogen_frequency_label = new QLabel("Pathogen frequency:");
pathogen_frequency_spin = new QSpinBox;
pathogen_frequency_spin->setMinimum(1);
pathogen_frequency_spin->setMaximum(1000);
pathogen_frequency_spin->setValue(pathogen_frequency);
org_settings_grid->addWidget(pathogen_frequency_label,21,1);
org_settings_grid->addWidget(pathogen_frequency_spin,21,2);
connect(pathogen_frequency_spin,(void(QSpinBox::*)(int))&QSpinBox::valueChanged,[=](const int &i) {pathogen_frequency=i;});
QWidget *org_settings_layout_widget = new QWidget;
org_settings_layout_widget->setLayout(org_settings_grid);
organismSettingsDock->setWidget(org_settings_layout_widget);
return organismSettingsDock;
}
// ---- RJG: Change the save path for various stuff.
void MainWindow::changepath_triggered()
{
QString dirname = QFileDialog::getExistingDirectory(this,"Select directory in which files should be saved.");
if (dirname.length()!=0)
{
dirname.append("/");
path->setText(dirname);
}
}
//ARTS - adds a null loop to the simulation iteration run when pause button/command is issued
// this loop is removed on the next tiggered() signal send from either one.
int MainWindow::waitUntilPauseSignalIsEmitted() {
QEventLoop loop;
QObject::connect(pauseButton, SIGNAL(triggered()),&loop, SLOT(quit()));
QObject::connect(ui->actionPause_Sim, SIGNAL(triggered()),&loop, SLOT(quit()));
return loop.exec();
}
void MainWindow::on_actionAbout_triggered()
{
About adialogue;
adialogue.exec();
}
//RJG - Reset simulation (i.e. fill the centre pixel with a genome (unless dual seed is selected), then set up a run).
void MainWindow::on_actionReset_triggered()
{
// Reset the information bar
resetInformationBar();
//RJG - This resets all the species logging stuff as well as setting up the run
TheSimManager->SetupRun();
NextRefresh=0;
//ARTS - Update views based on the new reset simulation
RefreshReport();
//UpdateTitles();
RefreshPopulations();
}
void MainWindow::resetInformationBar()
{
//ARTS - reset the bottom information bar
ui->LabelBatch->setText(tr("1/1"));
ui->LabelIteration->setText(tr("0"));
ui->LabelIterationsPerHour->setText(tr("0.00"));
ui->LabelCritters->setText(tr("0"));
ui->LabelSpeed->setText(tr("0.00"));
ui->LabelFitness->setText(tr("0.00%"));
ui->LabelSpecies->setText(tr("-"));
QString environment_scene_value;
environment_scene_value.sprintf("%d/%d",CurrentEnvFile+1,EnvFiles.count());
ui->LabelEnvironment->setText(environment_scene_value);
}
//RJG - Reseed provides options to either reset using a random genome, or a user defined one - drawn from the genome comparison docker.
void MainWindow::on_actionReseed_triggered()
{
reseed reseed_dialogue;
reseed_dialogue.exec();
on_actionReset_triggered();
}
void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
//ARTS - "Run" action
void MainWindow::on_actionStart_Sim_triggered()
{
if (CurrentEnvFile==-1)
{
QMessageBox::critical(0,"","Cannot start simulation without environment");
if (on_actionEnvironment_Files_triggered() == false) {
return;
}
}
RunSetUp();
ui->LabelBatch->setText(tr("1/1"));
while (stopflag==false)
{
while(pauseflag == true){
waitUntilPauseSignalIsEmitted();
pauseflag = false;
}
Report();
qApp->processEvents();
if (ui->actionGo_Slow->isChecked()) Sleeper::msleep(30);
//ARTS - set Stop flag to returns true if reached end... but why? It will fire the FinishRun() function at the end.
if (TheSimManager->iterate(environment_mode,enviroment_interpolate)) stopflag=true;
FRW->MakeRecords();
}
FinishRun();
}
//ARTS - "Run For..." action
void MainWindow::on_actionRun_for_triggered()
{
if (CurrentEnvFile==-1)
{
QMessageBox::critical(0,"","Cannot start simulation without environment");
if (on_actionEnvironment_Files_triggered() == false) {
return;
}
}
bool ok = false;
int i, num_iterations;
num_iterations = QInputDialog::getInt(this, "",tr("Iterations: "), 1000, 1, 10000000, 1, &ok);
i = num_iterations;
if (!ok) return;
ui->LabelBatch->setText(tr("1/1"));
RunSetUp();
while (stopflag==false && i>0)
{
while(pauseflag == true){
waitUntilPauseSignalIsEmitted();
pauseflag = false;
}
Report();
qApp->processEvents();
if (TheSimManager->iterate(environment_mode,enviroment_interpolate)) stopflag=true;
FRW->MakeRecords();
i--;
}