/
simulationexperimentviewsimulationwidget.cpp
3999 lines (2984 loc) · 180 KB
/
simulationexperimentviewsimulationwidget.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
/*******************************************************************************
Copyright (C) The University of Auckland
OpenCOR 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.
OpenCOR is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
//==============================================================================
// Simulation Experiment view simulation widget
//==============================================================================
#include "centralwidget.h"
#include "combineinterface.h"
#include "combinesupportplugin.h"
#include "coreguiutils.h"
#include "filemanager.h"
#include "graphpanelswidget.h"
#include "interfaces.h"
#include "progressbarwidget.h"
#include "sedmlinterface.h"
#include "sedmlsupport.h"
#include "sedmlsupportplugin.h"
#include "simulation.h"
#include "simulationexperimentviewcontentswidget.h"
#include "simulationexperimentviewinformationgraphpanelandgraphswidget.h"
#include "simulationexperimentviewinformationparameterswidget.h"
#include "simulationexperimentviewinformationsimulationwidget.h"
#include "simulationexperimentviewinformationsolverswidget.h"
#include "simulationexperimentviewinformationwidget.h"
#include "simulationexperimentviewplugin.h"
#include "simulationexperimentviewsimulationwidget.h"
#include "simulationexperimentviewwidget.h"
#include "simulationmanager.h"
#include "toolbarwidget.h"
#include "usermessagewidget.h"
//==============================================================================
#include <QApplication>
#include <QDesktopServices>
#include <QDesktopWidget>
#include <QDir>
#include <QLabel>
#include <QLayout>
#include <QMainWindow>
#include <QMenu>
#include <QTextEdit>
#include <QTimer>
#include <QToolButton>
//==============================================================================
#include "qwt_wheel.h"
//==============================================================================
#include "sbmlapibegin.h"
#include "sbml/math/FormulaParser.h"
#include "sbmlapiend.h"
//==============================================================================
#include "sedmlapibegin.h"
#include "sedml/SedAlgorithm.h"
#include "sedml/SedDocument.h"
#include "sedml/SedOneStep.h"
#include "sedml/SedPlot2D.h"
#include "sedml/SedRepeatedTask.h"
#include "sedml/SedSimulation.h"
#include "sedml/SedUniformTimeCourse.h"
#include "sedml/SedVectorRange.h"
#include "sedmlapiend.h"
//==============================================================================
namespace OpenCOR {
namespace SimulationExperimentView {
//==============================================================================
SimulationExperimentViewSimulationWidget::SimulationExperimentViewSimulationWidget(SimulationExperimentViewPlugin *pPlugin,
SimulationExperimentViewWidget *pViewWidget,
const QString &pFileName,
QWidget *pParent) :
Widget(pParent),
mPlugin(pPlugin),
mViewWidget(pViewWidget),
mDataStoreInterfaces(QMap<QAction *, DataStoreInterface *>()),
mCellmlBasedViewPlugins(QMap<QAction *, Plugin *>()),
mProgress(-1),
mLockedDevelopmentMode(false),
mRunActionEnabled(true),
mErrorType(General),
mPlots(GraphPanelWidget::GraphPanelPlotWidgets()),
mUpdatablePlotViewports(QMap<GraphPanelWidget::GraphPanelPlotWidget *, bool>()),
mSimulationProperties(QStringList()),
mSolversProperties(QStringList()),
mGraphPanelProperties(QMap<Core::PropertyEditorWidget *, QStringList>()),
mGraphsProperties(QMap<Core::PropertyEditorWidget *, QStringList>()),
mSimulationPropertiesModified(false),
mSolversPropertiesModified(false),
mGraphPanelPropertiesModified(QMap<Core::PropertyEditorWidget *, bool>()),
mGraphsPropertiesModified(QMap<Core::PropertyEditorWidget *, bool>()),
mGraphPanelsWidgetSizes(QIntList()),
mGraphPanelsWidgetSizesModified(false),
mCanUpdatePlotsForUpdatedGraphs(true),
mNeedReloadView(false),
mNeedUpdatePlots(false),
mOldDataSizes(QMap<GraphPanelWidget::GraphPanelPlotGraph *, qulonglong>())
{
// Ask our simulation manager to manage our file and then retrieve the
// corresponding simulation from it
SimulationSupport::SimulationManager *simulationManager = SimulationSupport::SimulationManager::instance();
simulationManager->manage(pFileName);
mSimulation = simulationManager->simulation(pFileName);
connect(mSimulation, SIGNAL(running(const bool &)),
this, SLOT(simulationRunning(const bool &)));
connect(mSimulation, SIGNAL(paused()),
this, SLOT(simulationPaused()));
connect(mSimulation, SIGNAL(stopped(const qint64 &)),
this, SLOT(simulationStopped(const qint64 &)));
connect(mSimulation, SIGNAL(error(const QString &)),
this, SLOT(simulationError(const QString &)));
connect(mSimulation->data(), SIGNAL(modified(const bool &)),
this, SLOT(simulationDataModified(const bool &)));
// Create a tool bar
mToolBarWidget = new Core::ToolBarWidget();
// Create, customise and handle various actions
mRunPauseResumeSimulationAction = Core::newAction(QIcon(":/oxygen/actions/media-playback-start.png"),
Qt::Key_F9, mToolBarWidget);
mStopSimulationAction = Core::newAction(QIcon(":/oxygen/actions/media-playback-stop.png"),
QKeySequence(Qt::CTRL|Qt::Key_F2), mToolBarWidget);
mResetModelParametersAction = Core::newAction(QIcon(":/oxygen/actions/view-refresh.png"),
mToolBarWidget);
mClearSimulationDataAction = Core::newAction(QIcon(":/oxygen/actions/trash-empty.png"),
mToolBarWidget);
mDevelopmentModeAction = Core::newAction(true, QIcon(":/oxygen/actions/run-build-configure.png"),
mToolBarWidget);
mAddGraphPanelAction = Core::newAction(QIcon(":/oxygen/actions/list-add.png"),
mToolBarWidget);
mRemoveGraphPanelAction = Core::newAction(QIcon(":/oxygen/actions/list-remove.png"),
mToolBarWidget);
mRemoveCurrentGraphPanelAction = Core::newAction(mToolBarWidget);
mRemoveAllGraphPanelsAction = Core::newAction(mToolBarWidget);
mCellmlOpenAction = Core::newAction(QIcon(":/CellMLSupport/logo.png"),
mToolBarWidget);
mSedmlExportAction = Core::newAction(QIcon(":/SEDMLSupport/logo.png"),
mToolBarWidget);
mSedmlExportSedmlFileAction = (mSimulation->fileType() == SimulationSupport::Simulation::CellmlFile)?
Core::newAction(mToolBarWidget):
0;
mSedmlExportCombineArchiveAction = (mSimulation->fileType() != SimulationSupport::Simulation::CombineArchive)?
Core::newAction(mToolBarWidget):
0;
mSimulationDataExportAction = Core::newAction(QIcon(":/oxygen/actions/document-export.png"),
mToolBarWidget);
mCellmlOpenAction->setEnabled(mSimulation->fileType() != SimulationSupport::Simulation::CellmlFile);
mSedmlExportAction->setEnabled(mSimulation->fileType() != SimulationSupport::Simulation::CombineArchive);
connect(mRunPauseResumeSimulationAction, SIGNAL(triggered(bool)),
this, SLOT(runPauseResumeSimulation()));
connect(mStopSimulationAction, SIGNAL(triggered(bool)),
this, SLOT(stopSimulation()));
connect(mResetModelParametersAction, SIGNAL(triggered(bool)),
this, SLOT(resetModelParameters()));
connect(mClearSimulationDataAction, SIGNAL(triggered(bool)),
this, SLOT(clearSimulationData()));
connect(mDevelopmentModeAction, SIGNAL(triggered(bool)),
this, SLOT(developmentMode()));
connect(mAddGraphPanelAction, SIGNAL(triggered(bool)),
this, SLOT(addGraphPanel()));
connect(mRemoveGraphPanelAction, SIGNAL(triggered(bool)),
this, SLOT(removeGraphPanel()));
connect(mRemoveCurrentGraphPanelAction, SIGNAL(triggered(bool)),
this, SLOT(removeCurrentGraphPanel()));
connect(mRemoveAllGraphPanelsAction, SIGNAL(triggered(bool)),
this, SLOT(removeAllGraphPanels()));
connect(mCellmlOpenAction, SIGNAL(triggered(bool)),
this, SLOT(openCellmlFile()));
connect(mSedmlExportAction, SIGNAL(triggered(bool)),
this, mSedmlExportSedmlFileAction?
SLOT(sedmlExportSedmlFile()):
SLOT(sedmlExportCombineArchive()));
if (mSedmlExportSedmlFileAction) {
connect(mSedmlExportSedmlFileAction, SIGNAL(triggered(bool)),
this, SLOT(sedmlExportSedmlFile()));
}
if (mSedmlExportCombineArchiveAction) {
connect(mSedmlExportCombineArchiveAction, SIGNAL(triggered(bool)),
this, SLOT(sedmlExportCombineArchive()));
}
// Enable/disable our development mode action depending on whether our file
// is readable/writable and of CellML type
mDevelopmentModeAction->setEnabled( Core::FileManager::instance()->isReadableAndWritable(pFileName)
&& (mSimulation->fileType() == SimulationSupport::Simulation::CellmlFile));
// Create a wheel (and a label to show its value) to specify the delay (in
// milliseconds) between the output of two data points
mDelayWidget = new QwtWheel(mToolBarWidget);
#if defined(Q_OS_WIN) || defined(Q_OS_LINUX)
QWidget *delaySpaceWidget = new QWidget(mToolBarWidget);
#endif
mDelayValueWidget = new QLabel(mToolBarWidget);
mDelayWidget->setBorderWidth(0);
mDelayWidget->setFixedSize(0.07*qApp->desktop()->screenGeometry().width(),
0.5*mDelayWidget->height());
mDelayWidget->setFocusPolicy(Qt::NoFocus);
mDelayWidget->setRange(0.0, 55.0);
mDelayWidget->setWheelBorderWidth(0);
#if defined(Q_OS_WIN) || defined(Q_OS_LINUX)
delaySpaceWidget->setFixedWidth(4);
#endif
connect(mDelayWidget, SIGNAL(valueChanged(double)),
this, SLOT(updateDelayValue(const double &)));
mDelayWidget->setValue(0.0);
// Create various tool buttons
QToolButton *removeGraphPanelToolButton = new QToolButton(mToolBarWidget);
QMenu *removeGraphPanelDropDownMenu = new QMenu(removeGraphPanelToolButton);
removeGraphPanelDropDownMenu->addAction(mRemoveCurrentGraphPanelAction);
removeGraphPanelDropDownMenu->addAction(mRemoveAllGraphPanelsAction);
removeGraphPanelToolButton->setDefaultAction(mRemoveGraphPanelAction);
removeGraphPanelToolButton->setMenu(removeGraphPanelDropDownMenu);
removeGraphPanelToolButton->setPopupMode(QToolButton::MenuButtonPopup);
QToolButton *cellmlOpenToolButton = new QToolButton(mToolBarWidget);
QMenu *cellmlOpenDropDownMenu = new QMenu(cellmlOpenToolButton);
cellmlOpenToolButton->setDefaultAction(mCellmlOpenAction);
cellmlOpenToolButton->setMenu(cellmlOpenDropDownMenu);
cellmlOpenToolButton->setPopupMode(QToolButton::MenuButtonPopup);
foreach (Plugin *cellmlEditingViewPlugin, pViewWidget->cellmlEditingViewPlugins()) {
QAction *action = Core::newAction(Core::mainWindow());
cellmlOpenDropDownMenu->addAction(action);
mCellmlBasedViewPlugins.insert(action, cellmlEditingViewPlugin);
connect(action, SIGNAL(triggered(bool)),
this, SLOT(openCellmlFile()));
}
cellmlOpenDropDownMenu->addSeparator();
foreach (Plugin *cellmlSimulationViewPlugin, pViewWidget->cellmlSimulationViewPlugins()) {
QAction *action = Core::newAction(Core::mainWindow());
cellmlOpenDropDownMenu->addAction(action);
mCellmlBasedViewPlugins.insert(action, cellmlSimulationViewPlugin);
connect(action, SIGNAL(triggered(bool)),
this, SLOT(openCellmlFile()));
}
QToolButton *sedmlExportToolButton = new QToolButton(mToolBarWidget);
QMenu *sedmlExportDropDownMenu = new QMenu(sedmlExportToolButton);
sedmlExportToolButton->setDefaultAction(mSedmlExportAction);
sedmlExportToolButton->setMenu(sedmlExportDropDownMenu);
sedmlExportToolButton->setPopupMode(QToolButton::MenuButtonPopup);
if (mSedmlExportSedmlFileAction)
sedmlExportDropDownMenu->addAction(mSedmlExportSedmlFileAction);
if (mSedmlExportCombineArchiveAction)
sedmlExportDropDownMenu->addAction(mSedmlExportCombineArchiveAction);
QToolButton *simulationDataExportToolButton = new QToolButton(mToolBarWidget);
mSimulationDataExportDropDownMenu = new QMenu(simulationDataExportToolButton);
simulationDataExportToolButton->setDefaultAction(mSimulationDataExportAction);
simulationDataExportToolButton->setMenu(mSimulationDataExportDropDownMenu);
simulationDataExportToolButton->setPopupMode(QToolButton::InstantPopup);
foreach (DataStoreInterface *dataStoreInterface, Core::dataStoreInterfaces()) {
QString dataStoreName = dataStoreInterface->dataStoreName();
QAction *action = mSimulationDataExportDropDownMenu->addAction(dataStoreName+"...");
mDataStoreInterfaces.insert(action, dataStoreInterface);
connect(action, SIGNAL(triggered()),
this, SLOT(simulationDataExport()));
}
updateDataStoreActions();
// Add the various actions, wheel and tool buttons to our tool bar
mToolBarWidget->addAction(mRunPauseResumeSimulationAction);
mToolBarWidget->addAction(mStopSimulationAction);
mToolBarWidget->addSeparator();
mToolBarWidget->addAction(mResetModelParametersAction);
mToolBarWidget->addAction(mClearSimulationDataAction);
mToolBarWidget->addSeparator();
mToolBarWidget->addWidget(mDelayWidget);
#if defined(Q_OS_WIN) || defined(Q_OS_LINUX)
mToolBarWidget->addWidget(delaySpaceWidget);
#endif
mToolBarWidget->addWidget(mDelayValueWidget);
mToolBarWidget->addSeparator();
mToolBarWidget->addAction(mDevelopmentModeAction);
mToolBarWidget->addSeparator();
mToolBarWidget->addAction(mAddGraphPanelAction);
mToolBarWidget->addWidget(removeGraphPanelToolButton);
mToolBarWidget->addSeparator();
mToolBarWidget->addWidget(cellmlOpenToolButton);
mToolBarWidget->addSeparator();
mToolBarWidget->addWidget(sedmlExportToolButton);
mToolBarWidget->addSeparator();
mToolBarWidget->addWidget(simulationDataExportToolButton);
mTopSeparator = Core::newLineWidget(this);
QLayout *layout = createLayout();
layout->addWidget(mToolBarWidget);
layout->addWidget(mTopSeparator);
// Create and add our invalid simulation message widget
mInvalidModelMessageWidget = new Core::UserMessageWidget(":/oxygen/actions/help-about.png", this);
layout->addWidget(mInvalidModelMessageWidget);
// Create our splitter widget and keep track of its movement
// Note: we need to keep track of its movement so that saveSettings() can
// work fine even when mContentsWidget is not visible (which happens
// when a CellML file cannot be run for some reason or another)...
mSplitterWidget = new Core::SplitterWidget(Qt::Vertical, this);
connect(mSplitterWidget, SIGNAL(splitterMoved(int, int)),
this, SLOT(emitSplitterMoved()));
// Create our contents widget
mContentsWidget = new SimulationExperimentViewContentsWidget(pViewWidget, this, this);
mContentsWidget->setObjectName("Contents");
// Keep track of changes to some of our simulation and solvers properties
SimulationExperimentViewInformationWidget *informationWidget = mContentsWidget->informationWidget();
connect(informationWidget->simulationWidget(), SIGNAL(propertyChanged(Core::Property *)),
this, SLOT(simulationPropertyChanged(Core::Property *)));
connect(informationWidget->solversWidget(), SIGNAL(propertyChanged(Core::Property *)),
this, SLOT(solversPropertyChanged(Core::Property *)));
// Keep track of the addition and removal of a graph panel
GraphPanelWidget::GraphPanelsWidget *graphPanelsWidget = mContentsWidget->graphPanelsWidget();
SimulationExperimentViewInformationGraphPanelAndGraphsWidget *graphPanelAndGraphsWidget = informationWidget->graphPanelAndGraphsWidget();
connect(graphPanelsWidget, SIGNAL(graphPanelAdded(OpenCOR::GraphPanelWidget::GraphPanelWidget *, const bool &)),
graphPanelAndGraphsWidget, SLOT(initialize(OpenCOR::GraphPanelWidget::GraphPanelWidget *, const bool &)));
connect(graphPanelsWidget, SIGNAL(graphPanelRemoved(OpenCOR::GraphPanelWidget::GraphPanelWidget *)),
graphPanelAndGraphsWidget, SLOT(finalize(OpenCOR::GraphPanelWidget::GraphPanelWidget *)));
connect(graphPanelsWidget, SIGNAL(graphPanelAdded(OpenCOR::GraphPanelWidget::GraphPanelWidget *, const bool &)),
this, SLOT(graphPanelAdded(OpenCOR::GraphPanelWidget::GraphPanelWidget *, const bool &)));
connect(graphPanelsWidget, SIGNAL(graphPanelRemoved(OpenCOR::GraphPanelWidget::GraphPanelWidget *)),
this, SLOT(graphPanelRemoved(OpenCOR::GraphPanelWidget::GraphPanelWidget *)));
// Keep track of whether a graph panel has been activated
connect(graphPanelsWidget, SIGNAL(graphPanelActivated(OpenCOR::GraphPanelWidget::GraphPanelWidget *)),
graphPanelAndGraphsWidget, SLOT(initialize(OpenCOR::GraphPanelWidget::GraphPanelWidget *)));
// Keep track of whether a graph panel has been resized
connect(graphPanelsWidget, SIGNAL(splitterMoved(int, int)),
this, SLOT(checkGraphPanelsAndGraphs()));
// Keep track of a graph being required
connect(informationWidget->parametersWidget(), SIGNAL(graphRequired(CellMLSupport::CellmlFileRuntimeParameter *, CellMLSupport::CellmlFileRuntimeParameter *)),
this, SLOT(addGraph(CellMLSupport::CellmlFileRuntimeParameter *, CellMLSupport::CellmlFileRuntimeParameter *)));
// Keep track of the addition and removal of a graph
connect(graphPanelsWidget, SIGNAL(graphAdded(OpenCOR::GraphPanelWidget::GraphPanelWidget *, OpenCOR::GraphPanelWidget::GraphPanelPlotGraph *, const OpenCOR::GraphPanelWidget::GraphPanelPlotGraphProperties &)),
graphPanelAndGraphsWidget, SLOT(addGraph(OpenCOR::GraphPanelWidget::GraphPanelWidget *, OpenCOR::GraphPanelWidget::GraphPanelPlotGraph *, const OpenCOR::GraphPanelWidget::GraphPanelPlotGraphProperties &)));
connect(graphPanelsWidget, SIGNAL(graphsRemoved(OpenCOR::GraphPanelWidget::GraphPanelWidget *, const OpenCOR::GraphPanelWidget::GraphPanelPlotGraphs &)),
graphPanelAndGraphsWidget, SLOT(removeGraphs(OpenCOR::GraphPanelWidget::GraphPanelWidget *, const OpenCOR::GraphPanelWidget::GraphPanelPlotGraphs &)));
connect(graphPanelsWidget, SIGNAL(graphAdded(OpenCOR::GraphPanelWidget::GraphPanelWidget *, OpenCOR::GraphPanelWidget::GraphPanelPlotGraph *, const OpenCOR::GraphPanelWidget::GraphPanelPlotGraphProperties &)),
this, SLOT(graphAdded(OpenCOR::GraphPanelWidget::GraphPanelWidget *, OpenCOR::GraphPanelWidget::GraphPanelPlotGraph *, const OpenCOR::GraphPanelWidget::GraphPanelPlotGraphProperties &)));
connect(graphPanelsWidget, SIGNAL(graphsRemoved(OpenCOR::GraphPanelWidget::GraphPanelWidget *, const OpenCOR::GraphPanelWidget::GraphPanelPlotGraphs &)),
this, SLOT(graphsRemoved(OpenCOR::GraphPanelWidget::GraphPanelWidget *, const OpenCOR::GraphPanelWidget::GraphPanelPlotGraphs &)));
// Keep track of the updating of a graph
// Note: ideally, this would, as for the addition and removal of a graph
// (see above), be done through graphPanelsWidget (i.e. a graph would
// let people know that it has been updated and the graph panel with
// which it is associated would forward the signal to
// graphPanelsWidget), but this may result in too many graphUpdated()
// signals being emitted. For example, say that you change the model
// with which a graph is associated, then both the X and Y parameters
// will get updated, and for each of those updates a graphUpdated()
// signal would be emitted by the graph, hence we would end up with
// two signals when only one would have sufficed. Even worse is that
// after having updated the X parameter, the graph would have its X
// parameter coming from the 'new' model while its Y parameter from
// the 'old' model, which could mess things up quite a bit from a
// plotting viewpoint. So, instead, the updating is done through our
// graphs property editor...
connect(graphPanelAndGraphsWidget, SIGNAL(graphUpdated(OpenCOR::GraphPanelWidget::GraphPanelPlotGraph *)),
this, SLOT(graphUpdated(OpenCOR::GraphPanelWidget::GraphPanelPlotGraph *)));
connect(graphPanelAndGraphsWidget, SIGNAL(graphsUpdated(const OpenCOR::GraphPanelWidget::GraphPanelPlotGraphs &)),
this, SLOT(graphsUpdated(const OpenCOR::GraphPanelWidget::GraphPanelPlotGraphs &)));
// Create our simulation output widget with a layout on which we put a
// separating line and our simulation output list view
// Note: the separating line is because we remove, for aesthetical reasons,
// the border of our simulation output list view...
QWidget *simulationOutputWidget = new QWidget(this);
QVBoxLayout *simulationOutputLayout= new QVBoxLayout(simulationOutputWidget);
simulationOutputLayout->setContentsMargins(QMargins());
simulationOutputLayout->setSpacing(0);
simulationOutputWidget->setLayout(simulationOutputLayout);
mOutputWidget = new QTextEdit(this);
mOutputWidget->setAcceptDrops(false);
mOutputWidget->setFrameStyle(QFrame::NoFrame);
mOutputWidget->setReadOnly(true);
simulationOutputLayout->addWidget(Core::newLineWidget(this));
simulationOutputLayout->addWidget(mOutputWidget);
// Populate our splitter and use as much space as possible for it by asking
// for its height to be that of the desktop's, and then add our splitter to
// our Simulation Experiment view widget
mSplitterWidget->addWidget(mContentsWidget);
mSplitterWidget->addWidget(simulationOutputWidget);
mSplitterWidget->setSizes(QIntList() << qApp->desktop()->screenGeometry().height() << 1);
layout->addWidget(mSplitterWidget);
// Create our (thin) simulation progress widget
mBottomSeparator = Core::newLineWidget(this);
mProgressBarWidget = new Core::ProgressBarWidget(this);
mProgressBarWidget->setFixedHeight(3);
mProgressBarWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
layout->addWidget(mBottomSeparator);
layout->addWidget(mProgressBarWidget);
// Make our contents widget our focus proxy
setFocusProxy(mContentsWidget);
// Some further initialisations that are done as part of retranslating the
// GUI (so that they can be updated when changing languages)
retranslateUi();
}
//==============================================================================
SimulationExperimentViewSimulationWidget::~SimulationExperimentViewSimulationWidget()
{
// Ask our simulation manager to unmanage our file
SimulationSupport::SimulationManager::instance()->unmanage(mSimulation->fileName());
}
//==============================================================================
void SimulationExperimentViewSimulationWidget::retranslateUi()
{
// Retranslate our actions
I18nInterface::retranslateAction(mRunPauseResumeSimulationAction, tr("Run Simulation"),
tr("Run the simulation"));
I18nInterface::retranslateAction(mStopSimulationAction, tr("Stop Simulation"),
tr("Stop the simulation"));
I18nInterface::retranslateAction(mResetModelParametersAction, tr("Reset Model Parameters"),
tr("Reset all the model parameters"));
I18nInterface::retranslateAction(mClearSimulationDataAction, tr("Clear Simulation Data"),
tr("Clear the simulation data"));
I18nInterface::retranslateAction(mDevelopmentModeAction, tr("Development Mode"),
tr("Enable/disable the development mode"));
I18nInterface::retranslateAction(mAddGraphPanelAction, tr("Add Graph Panel"),
tr("Add a graph panel"));
I18nInterface::retranslateAction(mRemoveGraphPanelAction, tr("Remove Graph Panel"),
tr("Remove the current graph panel or all the graph panels"));
I18nInterface::retranslateAction(mRemoveCurrentGraphPanelAction, tr("Current"),
tr("Remove the current graph panel"));
I18nInterface::retranslateAction(mRemoveAllGraphPanelsAction, tr("All"),
tr("Remove all the graph panels"));
I18nInterface::retranslateAction(mCellmlOpenAction, tr("Referenced CellML File"),
tr("Open the referenced CellML file"));
I18nInterface::retranslateAction(mSedmlExportAction, tr("SED-ML Export"),
tr("Export the simulation to SED-ML"));
if (mSedmlExportSedmlFileAction) {
I18nInterface::retranslateAction(mSedmlExportSedmlFileAction, tr("SED-ML File..."),
tr("Export the simulation to SED-ML using a SED-ML file"));
}
if (mSedmlExportCombineArchiveAction) {
I18nInterface::retranslateAction(mSedmlExportCombineArchiveAction, tr("COMBINE Archive..."),
tr("Export the simulation to SED-ML using a COMBINE archive"));
}
I18nInterface::retranslateAction(mSimulationDataExportAction, tr("Simulation Data Export"),
tr("Export the simulation data"));
// Retranslate our delay and delay value widgets
updateDelayValue(mDelayWidget->value());
// Note: we do this because we want to display the delay using digit
// grouping, this respecting the current locale...
mDelayWidget->setToolTip(tr("Simulation Delay"));
mDelayValueWidget->setToolTip(mDelayWidget->toolTip());
mDelayWidget->setStatusTip(tr("Delay between two data points"));
mDelayValueWidget->setStatusTip(mDelayWidget->statusTip());
// Retranslate our run/pause action
updateRunPauseAction(mRunActionEnabled);
// Retranslate our data store actions
updateDataStoreActions();
// Retranslate our CellML editing view actions
foreach (QAction *cellmlEditingViewAction, mCellmlBasedViewPlugins.keys()) {
Plugin *plugin = mCellmlBasedViewPlugins.value(cellmlEditingViewAction);
QString viewName = qobject_cast<ViewInterface *>(plugin->instance())->viewName();
I18nInterface::retranslateAction(cellmlEditingViewAction,
tr("%1 View").arg(viewName),
tr("Open the referenced CellML file using the %1 view").arg(viewName));
}
// Retranslate our invalid model message
updateInvalidModelMessageWidget();
// Retranslate our contents widget
mContentsWidget->retranslateUi();
}
//==============================================================================
void SimulationExperimentViewSimulationWidget::updateDataStoreActions()
{
// Update our data store actions
foreach (QAction *action, mDataStoreInterfaces.keys()) {
I18nInterface::retranslateAction(action,
action->text(),
tr("Export the simulation data to %1").arg(mDataStoreInterfaces.value(action)->dataStoreName()));
}
}
//==============================================================================
void SimulationExperimentViewSimulationWidget::output(const QString &pMessage)
{
// Move to the end of the output
// Note: this is just in case the user clicked somewhere in the output and
// we are therefore not at the end of it anymore...
mOutputWidget->moveCursor(QTextCursor::End);
// Output the message and make sure that it's visible
mOutputWidget->insertHtml(pMessage);
mOutputWidget->ensureCursorVisible();
}
//==============================================================================
void SimulationExperimentViewSimulationWidget::updateSimulationMode()
{
// Update our run/pause action
updateRunPauseAction(!mSimulation->isRunning() || mSimulation->isPaused());
// Enable/disable our stop action
bool simulationModeEnabled = mSimulation->isRunning() || mSimulation->isPaused();
mStopSimulationAction->setEnabled(simulationModeEnabled);
// Enable or disable our simulation and solvers widgets
mContentsWidget->informationWidget()->simulationWidget()->setEnabled(!simulationModeEnabled);
mContentsWidget->informationWidget()->solversWidget()->setEnabled(!simulationModeEnabled);
// Enable/disable some actions
mClearSimulationDataAction->setEnabled( mSimulation->results()->size()
&& !simulationModeEnabled);
mSimulationDataExportAction->setEnabled( mSimulationDataExportDropDownMenu->actions().count()
&& mSimulation->results()->size()
&& !simulationModeEnabled);
// Give the focus to our focus proxy, in case we leave our simulation mode
// (so that the user can modify simulation data, etc.)
if (!simulationModeEnabled)
focusProxy()->setFocus();
}
//==============================================================================
void SimulationExperimentViewSimulationWidget::updateRunPauseAction(const bool &pRunActionEnabled)
{
// Update our various actions
static const QIcon StartIcon = QIcon(":/oxygen/actions/media-playback-start.png");
static const QIcon PauseIcon = QIcon(":/oxygen/actions/media-playback-pause.png");
mRunActionEnabled = pRunActionEnabled;
mRunPauseResumeSimulationAction->setIcon(pRunActionEnabled?StartIcon:PauseIcon);
bool simulationPaused = mSimulation && mSimulation->isPaused();
I18nInterface::retranslateAction(mRunPauseResumeSimulationAction,
pRunActionEnabled?
simulationPaused?
tr("Resume Simulation"):
tr("Run Simulation"):
tr("Pause Simulation"),
pRunActionEnabled?
simulationPaused?
tr("Resume the simulation"):
tr("Run the simulation"):
tr("Pause the simulation"));
}
//==============================================================================
void SimulationExperimentViewSimulationWidget::updateInvalidModelMessageWidget()
{
// Update our invalid model message
mInvalidModelMessageWidget->setMessage((mErrorType == InvalidCellmlFile)?
tr("The <strong>%1</strong> view requires a valid CellML file to work...").arg(mPlugin->viewName()):
tr("The <strong>%1</strong> view requires a valid simulation environment to work...").arg(mPlugin->viewName()),
tr("See below for more information."));
}
//==============================================================================
static const auto OutputTab = QStringLiteral(" ");
static const auto OutputGood = QStringLiteral(" style=\"color: green;\"");
static const auto OutputInfo = QStringLiteral(" style=\"color: navy;\"");
static const auto OutputBad = QStringLiteral(" style=\"color: maroon;\"");
static const auto OutputBrLn = QStringLiteral("<br/>\n");
//==============================================================================
void SimulationExperimentViewSimulationWidget::initialize(const bool &pReloadingView)
{
// In the case of a SED-ML file and of a COMBINE archive, we will need
// to further initialise ourselves, to customise graph panels, etc. (see
// SimulationExperimentViewSimulationWidget::furtherInitialize()), so we
// ask our central widget to show its busy widget (which will get hidden
// in CentralWidget::updateGui())
bool isSedmlFile = mSimulation->fileType() == SimulationSupport::Simulation::SedmlFile;
bool isCombineArchive = mSimulation->fileType() == SimulationSupport::Simulation::CombineArchive;
if (isVisible() && (isSedmlFile || isCombineArchive))
Core::centralWidget()->showBusyWidget();
processEvents();
// Note: this ensures that our GUI is all fine before we start disabling
// updates (e.g. when reloading a SED-ML file that references a remote
// CellML file)...
setUpdatesEnabled(false);
// Stop keeping track of certain things (so that updatePlot() doesn't get
// called unnecessarily)
// Note: see the corresponding code towards the end of this method...
SimulationExperimentViewInformationWidget *informationWidget = mContentsWidget->informationWidget();
SimulationExperimentViewInformationSimulationWidget *simulationWidget = informationWidget->simulationWidget();
disconnect(simulationWidget, SIGNAL(propertyChanged(Core::Property *)),
this, SLOT(simulationPropertyChanged(Core::Property *)));
// Reset our progress
mProgress = -1;
// Clean up our output, if needed
if (pReloadingView)
mOutputWidget->document()->clear();
// Output some information about our CellML file
Core::FileManager *fileManagerInstance = Core::FileManager::instance();
QString simulationFileName = mSimulation->fileName();
QString fileName = fileManagerInstance->isNew(simulationFileName)?
tr("File")+" #"+QString::number(fileManagerInstance->newIndex(simulationFileName)):
fileManagerInstance->isRemote(simulationFileName)?
fileManagerInstance->url(simulationFileName):
simulationFileName;
QString information = "<strong>"+fileName+"</strong>"+OutputBrLn;
SEDMLSupport::SedmlFileIssues sedmlFileIssues = mSimulation->sedmlFile()?
mSimulation->sedmlFile()->issues():
SEDMLSupport::SedmlFileIssues();
COMBINESupport::CombineArchiveIssues combineArchiveIssues = mSimulation->combineArchive()?
mSimulation->combineArchive()->issues():
COMBINESupport::CombineArchiveIssues();
bool atLeastOneBlockingSedmlIssue = false;
bool atLeastOneBlockingCombineIssue = false;
if (!combineArchiveIssues.isEmpty()) {
// There is one or several issues with our COMBINE archive, so list
// it/them
foreach (const COMBINESupport::CombineArchiveIssue &combineArchiveIssue, combineArchiveIssues) {
QString issueType;
switch (combineArchiveIssue.type()) {
case COMBINESupport::CombineArchiveIssue::Information:
issueType = tr("Information:");
break;
case COMBINESupport::CombineArchiveIssue::Error:
issueType = tr("Error:");
atLeastOneBlockingCombineIssue = true;
break;
case COMBINESupport::CombineArchiveIssue::Warning:
issueType = tr("Warning:");
break;
case COMBINESupport::CombineArchiveIssue::Fatal:
issueType = tr("Fatal:");
atLeastOneBlockingCombineIssue = true;
break;
}
information += QString(OutputTab+"<span"+OutputBad+"><strong>%1</strong> %2.</span>"+OutputBrLn).arg(issueType, Core::formatMessage(combineArchiveIssue.message()));
}
}
if (!sedmlFileIssues.isEmpty()) {
// There is one or several issues with our SED-ML file, so list it/them
foreach (const SEDMLSupport::SedmlFileIssue &sedmlFileIssue, sedmlFileIssues) {
QString issueType;
switch (sedmlFileIssue.type()) {
case SEDMLSupport::SedmlFileIssue::Information:
issueType = tr("Information:");
break;
case SEDMLSupport::SedmlFileIssue::Error:
issueType = tr("Error:");
atLeastOneBlockingSedmlIssue = true;
break;
case SEDMLSupport::SedmlFileIssue::Warning:
issueType = tr("Warning:");
break;
case SEDMLSupport::SedmlFileIssue::Fatal:
issueType = tr("Fatal:");
atLeastOneBlockingSedmlIssue = true;
break;
}
if (sedmlFileIssue.line() && sedmlFileIssue.column()) {
information += QString(OutputTab+"<span"+OutputBad+"><strong>[%1:%2] %3</strong> %4.</span>"+OutputBrLn).arg(QString::number(sedmlFileIssue.line()),
QString::number(sedmlFileIssue.column()),
issueType, Core::formatMessage(sedmlFileIssue.message()));
} else {
information += QString(OutputTab+"<span"+OutputBad+"><strong>%1</strong> %2.</span>"+OutputBrLn).arg(issueType, Core::formatMessage(sedmlFileIssue.message()));
}
}
}
CellMLSupport::CellmlFileRuntime *runtime = mSimulation->runtime();
bool validRuntime = runtime && runtime->isValid();
CellMLSupport::CellmlFileRuntimeParameter *variableOfIntegration = validRuntime?runtime->variableOfIntegration():0;
if (!atLeastOneBlockingSedmlIssue && !atLeastOneBlockingCombineIssue) {
information += OutputTab+"<strong>"+tr("Runtime:")+"</strong> ";
if (variableOfIntegration) {
// A variable of integration could be retrieved for our CellML file,
// so we can also output the model type
QString additionalInformation = QString();
if (runtime->needNlaSolver())
additionalInformation = "+"+tr("NLA system(s)");
information += "<span"+OutputGood+">"+tr("valid")+"</span>."+OutputBrLn;
information += QString(OutputTab+"<strong>"+tr("Model type:")+"</strong> <span"+OutputInfo+">%1%2</span>."+OutputBrLn).arg((runtime->modelType() == CellMLSupport::CellmlFileRuntime::Ode)?tr("ODE"):tr("DAE"),
additionalInformation);
} else {
// We couldn't retrieve a variable of integration, which means that
// we either don't have a runtime or we have one, but it's not valid
// or it's valid but we really don't have a variable of integration
// Note: in the case of a valid runtime and no variable of
// integration, we really shouldn't consider the runtime to be
// valid, hence we handle this case here...
mErrorType = InvalidCellmlFile;
updateInvalidModelMessageWidget();
information += "<span"+OutputBad+">"+(runtime?tr("invalid"):tr("none"))+"</span>."+OutputBrLn;
if (validRuntime) {
// We have a valid runtime, but no variable of integration,
// which means that the model doesn't contain any ODE or DAE
information += OutputTab+"<span"+OutputBad+"><strong>"+tr("Error:")+"</strong> "+tr("the model must have at least one ODE or DAE")+".</span>"+OutputBrLn;
} else {
// We don't have a valid runtime, so either there are some
// problems with the CellML file, its runtime, or even the
// parent SED-ML file and/or COMBINE archive
// Note: in the case of problems with the SED-ML file and/or
// COMBINE archive, we will already have listed the
// problems, so no need to do anything more in those
// cases...
if (sedmlFileIssues.isEmpty() && combineArchiveIssues.isEmpty()) {
foreach (const CellMLSupport::CellmlFileIssue &issue,
runtime?runtime->issues():mSimulation->cellmlFile()->issues()) {
information += QString(OutputTab+"<span"+OutputBad+"><strong>%1</strong> %2.</span>"+OutputBrLn).arg((issue.type() == CellMLSupport::CellmlFileIssue::Error)?tr("Error:"):tr("Warning:"),
issue.message());
}
}
}
}
}
output(information);
// Check whether we have a valid simulation environment, but only if we
// don't have any blocking SED-ML or COMBINE issues
SimulationExperimentViewInformationSolversWidget *solversWidget = informationWidget->solversWidget();
bool validSimulationEnvironment = false;
if (!atLeastOneBlockingSedmlIssue && !atLeastOneBlockingCombineIssue) {
// Enable/disable our run/pause action depending on whether we have a
// variable of integration
mRunPauseResumeSimulationAction->setEnabled(variableOfIntegration);
// Update our simulation mode or clear our simulation data (should there
// be some) in case we are reloading ourselves
// Note: to clear our simualtion data will also update our simulation
// mode, so we are fine...
if (pReloadingView)
clearSimulationData();
else
updateSimulationMode();
// Initialise our contents widget and make sure that we have the
// required type(s) of solvers
if (variableOfIntegration) {
// Show our contents widget in case it got previously hidden
// Note: indeed, if it was to remain hidden then some
// initialisations wouldn't work (e.g. the solvers widget has
// a property editor, which all properties need to be removed
// and if the contents widget is not visible, then upon
// repopulating the property editor, scrollbars will be shown
// even though they are not needed)...
mContentsWidget->show();
// Check whether we have at least one ODE or DAE solver and, if
// needed, at least one NLA solver
if (runtime->needNlaSolver()) {
if (solversWidget->nlaSolvers().isEmpty()) {
if (runtime->needOdeSolver()) {
if (solversWidget->odeSolvers().isEmpty()) {
simulationError(tr("the model needs both an ODE and an NLA solver, but none are available"),
InvalidSimulationEnvironment);
} else {
simulationError(tr("the model needs both an ODE and an NLA solver, but no NLA solver is available"),
InvalidSimulationEnvironment);
}
} else {
if (solversWidget->daeSolvers().isEmpty()) {
simulationError(tr("the model needs both a DAE and an NLA solver, but none are available"),
InvalidSimulationEnvironment);
} else {
simulationError(tr("the model needs both a DAE and an NLA solver, but no NLA solver is available"),
InvalidSimulationEnvironment);
}
}
} else if ( runtime->needOdeSolver()
&& solversWidget->odeSolvers().isEmpty()) {
simulationError(tr("the model needs both an ODE and an NLA solver, but no ODE solver is available"),
InvalidSimulationEnvironment);
} else if ( runtime->needDaeSolver()
&& solversWidget->daeSolvers().isEmpty()) {
simulationError(tr("the model needs both a DAE and an NLA solver, but no DAE solver is available"),
InvalidSimulationEnvironment);
} else {
validSimulationEnvironment = true;
}
} else if ( runtime->needOdeSolver()
&& solversWidget->odeSolvers().isEmpty()) {
simulationError(tr("the model needs an ODE solver, but none is available"),
InvalidSimulationEnvironment);
} else if ( runtime->needDaeSolver()
&& solversWidget->daeSolvers().isEmpty()) {
simulationError(tr("the model needs a DAE solver, but none is available"),
InvalidSimulationEnvironment);
} else {
validSimulationEnvironment = true;
}
}
}
// Initialise our GUI based on whether we have a valid simulation
// environment
initializeGui(validSimulationEnvironment);
// Some additional initialisations in case we have a valid simulation
// environment
if (validSimulationEnvironment) {
// Initialise our GUI's simulation, solvers, graphs and graph panels
// widgets, but not parameters widget
// Note #1: this will also initialise some of our simulation data (i.e.
// our simulation's starting point and simulation's NLA
// solver's properties), which is needed since we want to be
// able to reset our simulation below...