/
SimulationDialog.cpp
2431 lines (2365 loc) · 125 KB
/
SimulationDialog.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
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
* ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from OSMC, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/
/*
* @author Adeel Asghar <adeel.asghar@liu.se>
*/
#include "SimulationDialog.h"
#include "MainWindow.h"
#include "Modeling/ItemDelegate.h"
#include "Options/OptionsDialog.h"
#include "Modeling/MessagesWidget.h"
#include "Debugger/GDB/GDBAdapter.h"
#include "Simulation/SimulationOutputWidget.h"
#include "Plotting/VariablesWidget.h"
#include "Plotting/PlotWindowContainer.h"
#include "Modeling/Commands.h"
#if !defined(WITHOUT_OSG)
#include "Animation/AnimationWindow.h"
#endif
#include "TranslationFlagsWidget.h"
#include <QDebug>
#include <limits>
/*!
* \class SimulationDialog
* \brief Displays a dialog with simulation options.
*/
/*!
* \brief SimulationDialog::SimulationDialog
* \param pParent
*/
SimulationDialog::SimulationDialog(QWidget *pParent)
: QDialog(pParent)
{
resize(550, 550);
setUpForm();
}
SimulationDialog::~SimulationDialog()
{
// kill the clients
foreach (OpcUaClient *pOpcUaClient, mOpcUaClientsMap) {
delete pOpcUaClient;
}
mOpcUaClientsMap.clear();
}
/*!
* \brief SimulationDialog::show
* \param pLibraryTreeItem - pointer to LibraryTreeItem
* \param isReSimulate
* \param simulationOptions
*/
void SimulationDialog::show(LibraryTreeItem *pLibraryTreeItem, bool isReSimulate, SimulationOptions simulationOptions)
{
mpLibraryTreeItem = pLibraryTreeItem;
initializeFields(isReSimulate, simulationOptions);
setVisible(true);
/* restore the window geometry. */
if (OptionsDialog::instance()->getGeneralSettingsPage()->getPreserveUserCustomizations() &&
Utilities::getApplicationSettings()->contains("SimulationDialog/geometry")) {
restoreGeometry(Utilities::getApplicationSettings()->value("SimulationDialog/geometry").toByteArray());
}
}
/*!
* \brief SimulationDialog::directSimulate
* * Directly simulates the model without showing the simulation dialog.
* \param pLibraryTreeItem
* \param launchTransformationalDebugger
* \param launchAlgorithmicDebugger
* \param launchAnimation
* \param enableDataReconciliation
*/
void SimulationDialog::directSimulate(LibraryTreeItem *pLibraryTreeItem, bool launchTransformationalDebugger, bool launchAlgorithmicDebugger, bool launchAnimation, bool enableDataReconciliation)
{
mpLibraryTreeItem = pLibraryTreeItem;
initializeFields(false, SimulationOptions());
mpBuildOnlyCheckBox->setChecked(false);
mpLaunchTransformationalDebuggerCheckBox->setChecked(launchTransformationalDebugger);
mpLaunchAlgorithmicDebuggerCheckBox->setChecked(launchAlgorithmicDebugger);
#if !defined(WITHOUT_OSG)
mpLaunchAnimationCheckBox->setChecked(launchAnimation);
#else
assert(false==launchAnimation);
#endif
/* ticket:4440 OMEdit does not simulate
* Make sure we always simulate when directSimulate() is called.
*/
bool simulateCheckBoxState = mpSimulateCheckBox->isChecked();
bool simuationFlagsCheckState = mpSaveSimulationFlagsAnnotationCheckBox->isChecked();
mpSimulateCheckBox->setChecked(true);
mpLibraryTreeItem->mSimulationOptions.setEnableDataReconciliation(enableDataReconciliation);
if (enableDataReconciliation && mpLibraryTreeItem->mSimulationOptions.getDataReconciliationSaveSetting()) {
mpSaveSimulationFlagsAnnotationCheckBox->setChecked(true);
}
simulate();
mpSimulateCheckBox->setChecked(simulateCheckBoxState);
mpSaveSimulationFlagsAnnotationCheckBox->setChecked(simuationFlagsCheckState);
}
/*!
* \brief SimulationDialog::removeSimulationOutputWidget
* Remove the simulation output widget.
* \param pSimulationOutputWidget
*/
void SimulationDialog::removeSimulationOutputWidget(SimulationOutputWidget* pSimulationOutputWidget)
{
// close the window
// remove the old opc ua instance
int port = pSimulationOutputWidget->getSimulationOptions().getInteractiveSimulationPortNumber();
if (mOpcUaClientsMap.contains(port)) {
OMPlot::PlotWindow *pPlotWindow = mOpcUaClientsMap.value(pSimulationOutputWidget->getSimulationOptions().getInteractiveSimulationPortNumber())->getTargetPlotWindow();
if (pPlotWindow) {
pPlotWindow->parentWidget()->close();
}
delete mOpcUaClientsMap.value(port);
mOpcUaClientsMap.remove(port);
}
// Kill the compilation and simulation processes if they are running.
if (pSimulationOutputWidget->isCompilationProcessRunning() && pSimulationOutputWidget->getCompilationProcess()) {
pSimulationOutputWidget->getCompilationProcess()->kill();
}
if (pSimulationOutputWidget->isSimulationProcessRunning() && pSimulationOutputWidget->getSimulationProcess()) {
pSimulationOutputWidget->getSimulationProcess()->kill();
}
}
/*!
Creates all the controls and set their layout.
*/
void SimulationDialog::setUpForm()
{
// simulation widget heading
mpSimulationHeading = Utilities::getHeadingLabel("");
mpSimulationHeading->setElideMode(Qt::ElideMiddle);
// Horizontal separator
mpHorizontalLine = Utilities::getHeadingLine();
// simulation tab widget
mpSimulationTabWidget = new QTabWidget;
// General Tab
mpGeneralTab = new QWidget;
// General Tab scroll area
mpGeneralTabScrollArea = new VerticalScrollArea;
mpGeneralTabScrollArea->setFrameShape(QFrame::NoFrame);
mpGeneralTabScrollArea->setBackgroundRole(QPalette::Base);
mpGeneralTabScrollArea->setWidget(mpGeneralTab);
// Simulation Interval
mpSimulationIntervalGroupBox = new QGroupBox(tr("Simulation Interval"));
mpStartTimeLabel = new Label(QString("%1:").arg(Helper::startTime));
mpStartTimeTextBox = new QLineEdit;
mpStopTimeLabel = new Label(QString("%1:").arg(Helper::stopTime));
mpStopTimeTextBox = new QLineEdit;
// Output Interval
mpNumberofIntervalsRadioButton = new QRadioButton(tr("Number of Intervals:"));
mpNumberofIntervalsRadioButton->setChecked(true);
connect(mpNumberofIntervalsRadioButton, SIGNAL(toggled(bool)), SLOT(numberOfIntervalsRadioToggled(bool)));
mpNumberofIntervalsSpinBox = new QSpinBox;
mpNumberofIntervalsSpinBox->setRange(0, std::numeric_limits<int>::max());
mpNumberofIntervalsSpinBox->setSingleStep(100);
// Interval
mpIntervalRadioButton = new QRadioButton(tr("Interval:"));
connect(mpIntervalRadioButton, SIGNAL(toggled(bool)), SLOT(intervalRadioToggled(bool)));
mpIntervalTextBox = new QLineEdit;
mpIntervalTextBox->setEnabled(false);
// set the layout for simulation interval groupbox
QGridLayout *pSimulationIntervalGridLayout = new QGridLayout;
pSimulationIntervalGridLayout->setColumnStretch(1, 1);
pSimulationIntervalGridLayout->addWidget(mpStartTimeLabel, 0, 0);
pSimulationIntervalGridLayout->addWidget(mpStartTimeTextBox, 0, 1);
pSimulationIntervalGridLayout->addWidget(new Label(Helper::secs), 0, 2);
pSimulationIntervalGridLayout->addWidget(mpStopTimeLabel, 1, 0);
pSimulationIntervalGridLayout->addWidget(mpStopTimeTextBox, 1, 1);
pSimulationIntervalGridLayout->addWidget(new Label(Helper::secs), 1, 2);
pSimulationIntervalGridLayout->addWidget(mpNumberofIntervalsRadioButton, 2, 0);
pSimulationIntervalGridLayout->addWidget(mpNumberofIntervalsSpinBox, 2, 1, 1, 2);
pSimulationIntervalGridLayout->addWidget(mpIntervalRadioButton, 3, 0);
pSimulationIntervalGridLayout->addWidget(mpIntervalTextBox, 3, 1);
pSimulationIntervalGridLayout->addWidget(new Label(Helper::secs), 3, 2);
mpSimulationIntervalGroupBox->setLayout(pSimulationIntervalGridLayout);
// Integration
mpIntegrationGroupBox = new QGroupBox(tr("Integration"));
mpMethodLabel = new Label(tr("Method:"));
// get the solver methods
QStringList solverMethods, solverMethodsDesc;
MainWindow::instance()->getOMCProxy()->getSolverMethods(&solverMethods, &solverMethodsDesc);
mpMethodComboBox = new QComboBox;
mpMethodComboBox->addItems(solverMethods);
Utilities::setToolTip(mpMethodComboBox, "Integration Methods", solverMethodsDesc);
connect(mpMethodComboBox, SIGNAL(currentIndexChanged(QString)), SLOT(enableDasslIdaOptions(QString)));
mpMehtodHelpButton = new QToolButton;
mpMehtodHelpButton->setIcon(QIcon(":/Resources/icons/link-external.svg"));
mpMehtodHelpButton->setToolTip(tr("Integration help"));
connect(mpMehtodHelpButton, SIGNAL(clicked()), SLOT(showIntegrationHelp()));
// Tolerance
mpToleranceLabel = new Label(tr("Tolerance:"));
mpToleranceTextBox = new QLineEdit;
// jacobian
mpJacobianLabel = new Label(tr("Jacobian:"));
mpJacobianLabel->setToolTip(MainWindow::instance()->getOMCProxy()->getJacobianFlagDetailedDescription());
QStringList jacobianMethods, jacobianMethodsDesc;
MainWindow::instance()->getOMCProxy()->getJacobianMethods(&jacobianMethods, &jacobianMethodsDesc);
mpJacobianComboBox = new QComboBox;
jacobianMethods.prepend("");
jacobianMethodsDesc.prepend("");
mpJacobianComboBox->addItems(jacobianMethods);
Utilities::setToolTip(mpJacobianComboBox, "Jacobians", jacobianMethodsDesc);
// dassl/ida options
mpDasslIdaOptionsGroupBox = new QGroupBox(tr("DASSL/IDA Options"));
// no root finding
mpRootFindingCheckBox = new QCheckBox(tr("Root Finding"));
mpRootFindingCheckBox->setToolTip(tr("Activates the internal root finding procedure of methods: dassl and ida."));
// no restart
mpRestartAfterEventCheckBox = new QCheckBox(tr("Restart After Event"));
mpRestartAfterEventCheckBox->setToolTip(tr("Activates the restart of the integration method after an event is performed, used by the methods: dassl, ida"));
// initial step size
mpInitialStepSizeLabel = new Label(tr("Initial Step Size:"));
mpInitialStepSizeTextBox = new QLineEdit;
// max step size
mpMaxStepSizeLabel = new Label(tr("Maximum Step Size:"));
mpMaxStepSizeTextBox = new QLineEdit;
// max integration order
mpMaxIntegrationOrderLabel = new Label(tr("Maximum Integration Order:"));
mpMaxIntegrationOrderSpinBox = new QSpinBox;
// set the layout for DASSL/Ida options groupbox
QGridLayout *pDasslIdaOptionsGridLayout = new QGridLayout;
pDasslIdaOptionsGridLayout->setColumnStretch(1, 1);
pDasslIdaOptionsGridLayout->addWidget(mpRootFindingCheckBox, 0, 0, 1, 2);
pDasslIdaOptionsGridLayout->addWidget(mpRestartAfterEventCheckBox, 1, 0, 1, 2);
pDasslIdaOptionsGridLayout->addWidget(mpInitialStepSizeLabel, 2, 0);
pDasslIdaOptionsGridLayout->addWidget(mpInitialStepSizeTextBox, 2, 1);
pDasslIdaOptionsGridLayout->addWidget(mpMaxStepSizeLabel, 3, 0);
pDasslIdaOptionsGridLayout->addWidget(mpMaxStepSizeTextBox, 3, 1);
pDasslIdaOptionsGridLayout->addWidget(mpMaxIntegrationOrderLabel, 4, 0);
pDasslIdaOptionsGridLayout->addWidget(mpMaxIntegrationOrderSpinBox, 4, 1);
mpDasslIdaOptionsGroupBox->setLayout(pDasslIdaOptionsGridLayout);
// set the layout for integration groupbox
QGridLayout *pIntegrationGridLayout = new QGridLayout;
pIntegrationGridLayout->setColumnStretch(1, 1);
pIntegrationGridLayout->addWidget(mpMethodLabel, 0, 0);
pIntegrationGridLayout->addWidget(mpMethodComboBox, 0, 1);
pIntegrationGridLayout->addWidget(mpMehtodHelpButton, 0, 2);
pIntegrationGridLayout->addWidget(mpToleranceLabel, 1, 0);
pIntegrationGridLayout->addWidget(mpToleranceTextBox, 1, 1, 1, 2);
pIntegrationGridLayout->addWidget(mpJacobianLabel, 2, 0);
pIntegrationGridLayout->addWidget(mpJacobianComboBox, 2, 1, 1, 2);
pIntegrationGridLayout->addWidget(mpDasslIdaOptionsGroupBox, 3, 0, 1, 3);
mpIntegrationGroupBox->setLayout(pIntegrationGridLayout);
// Compiler Flags
mpCflagsLabel = new Label(tr("C/C++ Compiler Flags (Optional):"));
mpCflagsLabel->setToolTip(tr("Space separated list of C/C++ compiler flags"));
mpCflagsTextBox = new QLineEdit;
// Number of Processors
mpNumberOfProcessorsLabel = new Label(tr("Number of Processors:"));
mpNumberOfProcessorsSpinBox = new QSpinBox;
mpNumberOfProcessorsSpinBox->setMinimum(1);
mpNumberOfProcessorsNoteLabel = new Label(tr("Use 1 processor if you encounter problems during compilation."));
// build only
mpBuildOnlyCheckBox = new QCheckBox(tr("Build Only"));
connect(mpBuildOnlyCheckBox, SIGNAL(toggled(bool)), SLOT(buildOnly(bool)));
// Launch Transformational Debugger checkbox
mpLaunchTransformationalDebuggerCheckBox = new QCheckBox(tr("Launch Transformational Debugger"));
// Launch Algorithmic Debugger checkbox
mpLaunchAlgorithmicDebuggerCheckBox = new QCheckBox(tr("Launch Algorithmic Debugger"));
#if !defined(WITHOUT_OSG)
// Launch Animation
mpLaunchAnimationCheckBox = new QCheckBox(tr("Launch Animation"));
#endif
QGridLayout *pLaunchOptionsLayout = new QGridLayout;
pLaunchOptionsLayout->setAlignment(Qt::AlignTop);
pLaunchOptionsLayout->addWidget(mpBuildOnlyCheckBox, 0, 0);
pLaunchOptionsLayout->addWidget(mpLaunchTransformationalDebuggerCheckBox, 0, 1);
#if !defined(WITHOUT_OSG)
pLaunchOptionsLayout->addWidget(mpLaunchAlgorithmicDebuggerCheckBox, 1, 0);
pLaunchOptionsLayout->addWidget(mpLaunchAnimationCheckBox, 1, 1);
#else
pLaunchOptionsLayout->addWidget(mpLaunchAlgorithmicDebuggerCheckBox, 1, 0, 1, 2);
#endif
// set General Tab Layout
QGridLayout *pGeneralTabLayout = new QGridLayout;
pGeneralTabLayout->setAlignment(Qt::AlignTop);
pGeneralTabLayout->addWidget(mpSimulationIntervalGroupBox, 0, 0, 1, 3);
pGeneralTabLayout->addWidget(mpIntegrationGroupBox, 1, 0, 1, 3);
pGeneralTabLayout->addWidget(mpCflagsLabel, 2, 0);
pGeneralTabLayout->addWidget(mpCflagsTextBox, 2, 1, 1, 2);
pGeneralTabLayout->addWidget(mpNumberOfProcessorsLabel, 3, 0);
pGeneralTabLayout->addWidget(mpNumberOfProcessorsSpinBox, 3, 1);
pGeneralTabLayout->addWidget(mpNumberOfProcessorsNoteLabel, 3, 2);
pGeneralTabLayout->addLayout(pLaunchOptionsLayout, 4, 0, 1, 3);
mpGeneralTab->setLayout(pGeneralTabLayout);
// add General Tab to Simulation TabWidget
mpSimulationTabWidget->addTab(mpGeneralTabScrollArea, Helper::general);
// interactive simulation tab
mpInteractiveSimulationTab = new QWidget;
// interactive simulation
QString interactiveSimulationText = tr("Interactive Simulation");
mpInteractiveSimulationGroupBox = new QGroupBox(interactiveSimulationText);
mpInteractiveSimulationGroupBox->setCheckable(true);
mpInteractiveSimulationStepCheckBox = new QCheckBox(tr("Simulate with steps"));
mpInteractiveSimulationStepCheckBox->setToolTip(tr("Activates communication with the simulation remote every time step.\n"
"Can cause high overhead but values will not be missed."));
mpInteractiveSimulationPortLabel = new Label(tr("Simulation server port: "));
mpInteractiveSimulationPortLabel->setToolTip(tr("Specifies the embedded server port."));
mpInteractiveSimulationPortNumberTextBox = new QLineEdit;
connect(mpInteractiveSimulationGroupBox, SIGNAL(toggled(bool)), SLOT(interactiveSimulation(bool)));
// interactive simulation layout
QGridLayout *pInteractiveSimulationLayout = new QGridLayout;
pInteractiveSimulationLayout->setColumnStretch(1, 1);
pInteractiveSimulationLayout->addWidget(mpInteractiveSimulationStepCheckBox, 0, 0);
pInteractiveSimulationLayout->addWidget(mpInteractiveSimulationPortLabel, 1, 0);
pInteractiveSimulationLayout->addWidget(mpInteractiveSimulationPortNumberTextBox, 1, 1);
mpInteractiveSimulationGroupBox->setLayout(pInteractiveSimulationLayout);
// set interactive simulation Tab Layout
QGridLayout *pInteractiveSimulationTabLayout = new QGridLayout;
pInteractiveSimulationTabLayout->setAlignment(Qt::AlignTop);
pInteractiveSimulationTabLayout->addWidget(mpInteractiveSimulationGroupBox, 0, 0);
mpInteractiveSimulationTab->setLayout(pInteractiveSimulationTabLayout);
// add interactive simulation Tab to Simulation TabWidget
mpSimulationTabWidget->addTab(mpInteractiveSimulationTab, interactiveSimulationText);
// Translation Tab
mpTranslationTab = new QWidget;
mpTranslationFlagsWidget = new TranslationFlagsWidget(this);
// set Translation Tab Layout
QGridLayout *pTranslationTabLayout = new QGridLayout;
pTranslationTabLayout->setAlignment(Qt::AlignTop);
pTranslationTabLayout->addWidget(mpTranslationFlagsWidget, 0, 0);
mpTranslationTab->setLayout(pTranslationTabLayout);
// add Translation Tab to Simulation TabWidget
mpSimulationTabWidget->addTab(mpTranslationTab, Helper::translationFlags);
// Simulation Flags Tab
mpSimulationFlagsTab = new QWidget;
// Simulation Flags Tab scroll area
mpSimulationFlagsTabScrollArea = new QScrollArea;
mpSimulationFlagsTabScrollArea->setFrameShape(QFrame::NoFrame);
mpSimulationFlagsTabScrollArea->setBackgroundRole(QPalette::Base);
mpSimulationFlagsTabScrollArea->setWidgetResizable(true);
mpSimulationFlagsTabScrollArea->setWidget(mpSimulationFlagsTab);
// Model Setup File
mpModelSetupFileLabel = new Label(tr("Model Setup File (Optional):"));
mpModelSetupFileLabel->setToolTip(tr("Specifies a new setup XML file to the generated simulation code."));
mpModelSetupFileTextBox = new QLineEdit;
mpModelSetupFileBrowseButton = new QPushButton(Helper::browse);
connect(mpModelSetupFileBrowseButton, SIGNAL(clicked()), SLOT(browseModelSetupFile()));
mpModelSetupFileBrowseButton->setAutoDefault(false);
// Initialization Methods
mpInitializationMethodLabel = new Label(tr("Initialization Method (Optional):"));
mpInitializationMethodLabel->setToolTip(tr("Specifies the initialization method."));
// get the initialization methods
QStringList initializationMethods, initializationMethodsDesc;
MainWindow::instance()->getOMCProxy()->getInitializationMethods(&initializationMethods, &initializationMethodsDesc);
initializationMethods.prepend("");
initializationMethodsDesc.prepend("");
mpInitializationMethodComboBox = new QComboBox;
mpInitializationMethodComboBox->addItems(initializationMethods);
Utilities::setToolTip(mpInitializationMethodComboBox, "Initialization Methods", initializationMethodsDesc);
// Equation System Initialization File
mpEquationSystemInitializationFileLabel = new Label(tr("Equation System Initialization File (Optional):"));
mpEquationSystemInitializationFileLabel->setToolTip(tr("Specifies an external file for the initialization of the model."));
mpEquationSystemInitializationFileTextBox = new QLineEdit;
mpEquationSystemInitializationFileBrowseButton = new QPushButton(Helper::browse);
connect(mpEquationSystemInitializationFileBrowseButton, SIGNAL(clicked()), SLOT(browseEquationSystemInitializationFile()));
mpEquationSystemInitializationFileBrowseButton->setAutoDefault(false);
// Equation System time
mpEquationSystemInitializationTimeLabel = new Label(tr("Equation System Initialization Time (Optional):"));
mpEquationSystemInitializationTimeLabel->setToolTip(tr("Specifies a time for the initialization of the model."));
mpEquationSystemInitializationTimeTextBox = new QLineEdit;
// clock
mpClockLabel = new Label(tr("Clock (Optional):"));
mpClockComboBox = new QComboBox;
mpClockComboBox->addItems(Helper::clockOptions.split(","));
// Linear Solvers
mpLinearSolverLabel = new Label(tr("Linear Solver (Optional):"));
// get the linear solvers
QStringList linearSolverMethods, linearSolverMethodsDesc;
MainWindow::instance()->getOMCProxy()->getLinearSolvers(&linearSolverMethods, &linearSolverMethodsDesc);
linearSolverMethods.prepend("");
linearSolverMethodsDesc.prepend("");
mpLinearSolverComboBox = new QComboBox;
mpLinearSolverComboBox->addItems(linearSolverMethods);
Utilities::setToolTip(mpLinearSolverComboBox, "Linear Solvers", linearSolverMethodsDesc);
// Non Linear Solvers
mpNonLinearSolverLabel = new Label(tr("Non Linear Solver (Optional):"));
// get the non-linear solvers
QStringList nonLinearSolverMethods, nonLinearSolverMethodsDesc;
MainWindow::instance()->getOMCProxy()->getNonLinearSolvers(&nonLinearSolverMethods, &nonLinearSolverMethodsDesc);
nonLinearSolverMethods.prepend("");
nonLinearSolverMethodsDesc.prepend("");
mpNonLinearSolverComboBox = new QComboBox;
mpNonLinearSolverComboBox->addItems(nonLinearSolverMethods);
Utilities::setToolTip(mpNonLinearSolverComboBox, "Non Linear Solvers", nonLinearSolverMethodsDesc);
// time where the linearization of the model should be performed
mpLinearizationTimeLabel = new Label(tr("Linearization Time (Optional):"));
mpLinearizationTimeTextBox = new QLineEdit;
// output variables
mpOutputVariablesLabel = new Label(tr("Output Variables (Optional):"));
mpOutputVariablesLabel->setToolTip(tr("Comma separated list of variables. Output the variables at the end of the simulation to the standard output."));
mpOutputVariablesTextBox = new QLineEdit;
// measure simulation time checkbox
mpProfilingLabel = new Label(tr("Profiling (enable performance measurements)"));
mpProfilingComboBox = new QComboBox;
OMCInterface::getConfigFlagValidOptions_res profiling = MainWindow::instance()->getOMCProxy()->getConfigFlagValidOptions("profiling");
mpProfilingComboBox->addItems(profiling.validOptions);
mpProfilingComboBox->setCurrentIndex(0);
Utilities::setToolTip(mpProfilingComboBox, profiling.mainDescription, profiling.descriptions);
// cpu-time checkbox
mpCPUTimeCheckBox = new QCheckBox(tr("CPU Time"));
// enable all warnings
mpEnableAllWarningsCheckBox = new QCheckBox(tr("Enable All Warnings"));
// Logging
mpLoggingGroupBox = new QGroupBox(tr("Logging (Optional)"));
// fetch the logging flags information
QStringList logStreamNames, logSteamDescriptions;
MainWindow::instance()->getOMCProxy()->getLogStreams(&logStreamNames, &logSteamDescriptions);
// layout for logging group
mpLoggingGroupLayout = new QGridLayout;
// create log stream checkboxes
int row = 0;
int column = 0;
for (int i = 0 ; i < logStreamNames.size() ; i++) {
QCheckBox *pLogStreamCheckBox = new QCheckBox(logStreamNames[i]);
pLogStreamCheckBox->setToolTip(logSteamDescriptions[i]);
if (column == 0) {
mpLoggingGroupLayout->addWidget(pLogStreamCheckBox, row, column++);
} else if (column == 1) {
mpLoggingGroupLayout->addWidget(pLogStreamCheckBox, row, column++);
} else if (column == 2) {
mpLoggingGroupLayout->addWidget(pLogStreamCheckBox, row, column);
column = 0;
row++;
}
}
mpLoggingGroupBox->setLayout(mpLoggingGroupLayout);
// additional simulation flags
mpAdditionalSimulationFlagsLabel = new Label(tr("Additional Simulation Flags (Optional):"));
mpAdditionalSimulationFlagsLabel->setToolTip(tr("Space separated list of simulation flags e.g., -abortSlowSimulation -alarm=0"));
mpAdditionalSimulationFlagsTextBox = new QLineEdit;
mpSimulationFlagsHelpButton = new QToolButton;
mpSimulationFlagsHelpButton->setIcon(QIcon(":/Resources/icons/link-external.svg"));
mpSimulationFlagsHelpButton->setToolTip(tr("Simulation flags help"));
connect(mpSimulationFlagsHelpButton, SIGNAL(clicked()), SLOT(showSimulationFlagsHelp()));
// additional simulation flags layout
QHBoxLayout *pAdditionalSimulationFlagsTabLayout = new QHBoxLayout;
pAdditionalSimulationFlagsTabLayout->addWidget(mpAdditionalSimulationFlagsTextBox);
pAdditionalSimulationFlagsTabLayout->addWidget(mpSimulationFlagsHelpButton);
// set SimulationFlags Tab Layout
QGridLayout *pSimulationFlagsTabLayout = new QGridLayout;
pSimulationFlagsTabLayout->setAlignment(Qt::AlignTop);
pSimulationFlagsTabLayout->addWidget(mpModelSetupFileLabel, 0, 0);
pSimulationFlagsTabLayout->addWidget(mpModelSetupFileTextBox, 0, 1);
pSimulationFlagsTabLayout->addWidget(mpModelSetupFileBrowseButton, 0, 2);
pSimulationFlagsTabLayout->addWidget(mpInitializationMethodLabel, 1, 0);
pSimulationFlagsTabLayout->addWidget(mpInitializationMethodComboBox, 1, 1, 1, 2);
pSimulationFlagsTabLayout->addWidget(mpEquationSystemInitializationFileLabel, 2, 0);
pSimulationFlagsTabLayout->addWidget(mpEquationSystemInitializationFileTextBox, 2, 1);
pSimulationFlagsTabLayout->addWidget(mpEquationSystemInitializationFileBrowseButton, 2, 2);
pSimulationFlagsTabLayout->addWidget(mpEquationSystemInitializationTimeLabel, 3, 0);
pSimulationFlagsTabLayout->addWidget(mpEquationSystemInitializationTimeTextBox, 3, 1, 1, 2);
pSimulationFlagsTabLayout->addWidget(mpClockLabel, 4, 0);
pSimulationFlagsTabLayout->addWidget(mpClockComboBox, 4, 1, 1, 2);
pSimulationFlagsTabLayout->addWidget(mpLinearSolverLabel, 5, 0);
pSimulationFlagsTabLayout->addWidget(mpLinearSolverComboBox, 5, 1, 1, 2);
pSimulationFlagsTabLayout->addWidget(mpNonLinearSolverLabel, 6, 0);
pSimulationFlagsTabLayout->addWidget(mpNonLinearSolverComboBox, 6, 1, 1, 2);
pSimulationFlagsTabLayout->addWidget(mpLinearizationTimeLabel, 7, 0);
pSimulationFlagsTabLayout->addWidget(mpLinearizationTimeTextBox, 7, 1, 1, 2);
pSimulationFlagsTabLayout->addWidget(mpOutputVariablesLabel, 8, 0);
pSimulationFlagsTabLayout->addWidget(mpOutputVariablesTextBox, 8, 1, 1, 2);
pSimulationFlagsTabLayout->addWidget(mpProfilingLabel, 9, 0);
pSimulationFlagsTabLayout->addWidget(mpProfilingComboBox, 9, 1, 1, 2);
pSimulationFlagsTabLayout->addWidget(mpCPUTimeCheckBox, 10, 0, 1, 3);
pSimulationFlagsTabLayout->addWidget(mpEnableAllWarningsCheckBox, 11, 0, 1, 3);
pSimulationFlagsTabLayout->addWidget(mpLoggingGroupBox, 12, 0, 1, 3);
pSimulationFlagsTabLayout->addWidget(mpAdditionalSimulationFlagsLabel, 13, 0);
pSimulationFlagsTabLayout->addLayout(pAdditionalSimulationFlagsTabLayout, 13, 1, 1, 2);
mpSimulationFlagsTab->setLayout(pSimulationFlagsTabLayout);
// add Output Tab to Simulation TabWidget
mpSimulationTabWidget->addTab(mpSimulationFlagsTabScrollArea, tr("Simulation Flags"));
// Output Tab
mpOutputTab = new QWidget;
// Output Format
mpOutputFormatLabel = new Label(tr("Output Format:"));
mpOutputFormatComboBox = new QComboBox;
mpOutputFormatComboBox->addItems(Helper::ModelicaSimulationOutputFormats.toLower().split(","));
// single precision
mpSinglePrecisionCheckBox = new QCheckBox(tr("Single Precision"));
// Output filename
mpFileNameLabel = new Label(tr("File Name Prefix (Optional):"));
mpFileNameTextBox = new QLineEdit;
mpFileNameTextBox->setToolTip(tr("The name is used as a prefix for the output files. This is just a name not the path.\n"
"If you want to change the output path then update the working directory in Options/Preferences."));
mpResultFileNameLabel = new Label(tr("Result File (Optional):"));
mpResultFileNameTextBox = new QLineEdit;
connect(mpOutputFormatComboBox, SIGNAL(currentIndexChanged(QString)), SLOT(resultFileNameChanged(QString)));
// Variable filter
mpVariableFilterLabel = new Label(tr("Variable Filter (Optional):"));
mpVariableFilterTextBox = new QLineEdit(".*");
// Protected Variabels
mpProtectedVariablesCheckBox = new QCheckBox(tr("Protected Variables"));
// ignore hide result
mpIgnoreHideResultCheckBox = new QCheckBox(tr("Ignore HideResult"));
// Equidistant time grid
mpEquidistantTimeGridCheckBox = new QCheckBox(tr("Equidistant Time Grid"));
// store variables at events
mpStoreVariablesAtEventsCheckBox = new QCheckBox(tr("Store Variables at Events"));
// show generated files checkbox
mpShowGeneratedFilesCheckBox = new QCheckBox(tr("Show Generated Files"));
// set Output Tab Layout
QGridLayout *pOutputTabLayout = new QGridLayout;
pOutputTabLayout->setAlignment(Qt::AlignTop);
pOutputTabLayout->addWidget(mpOutputFormatLabel, 0, 0);
pOutputTabLayout->addWidget(mpOutputFormatComboBox, 0, 1);
pOutputTabLayout->addWidget(mpSinglePrecisionCheckBox, 1, 0, 1, 2);
pOutputTabLayout->addWidget(mpFileNameLabel, 2, 0);
pOutputTabLayout->addWidget(mpFileNameTextBox, 2, 1);
pOutputTabLayout->addWidget(mpResultFileNameLabel, 3, 0);
pOutputTabLayout->addWidget(mpResultFileNameTextBox, 3, 1);
pOutputTabLayout->addWidget(mpVariableFilterLabel, 4, 0);
pOutputTabLayout->addWidget(mpVariableFilterTextBox, 4, 1);
pOutputTabLayout->addWidget(mpProtectedVariablesCheckBox, 5, 0, 1, 2);
pOutputTabLayout->addWidget(mpIgnoreHideResultCheckBox, 6, 0, 1, 2);
pOutputTabLayout->addWidget(mpEquidistantTimeGridCheckBox, 7, 0, 1, 2);
pOutputTabLayout->addWidget(mpStoreVariablesAtEventsCheckBox, 8, 0, 1, 2);
pOutputTabLayout->addWidget(mpShowGeneratedFilesCheckBox, 9, 0, 1, 2);
mpOutputTab->setLayout(pOutputTabLayout);
// add Output Tab to Simulation TabWidget
mpSimulationTabWidget->addTab(mpOutputTab, Helper::output);
// Add the validators
QDoubleValidator *pDoubleValidator = new QDoubleValidator(this);
mpStartTimeTextBox->setValidator(pDoubleValidator);
mpStopTimeTextBox->setValidator(pDoubleValidator);
mpIntervalTextBox->setValidator(pDoubleValidator);
mpToleranceTextBox->setValidator(pDoubleValidator);
QIntValidator *pIntValidator = new QIntValidator(this);
pIntValidator->setRange(0, 65535);
mpInteractiveSimulationPortNumberTextBox->setValidator(pIntValidator);
// create checkboxes
mpSaveExperimentAnnotationCheckBox = new QCheckBox(Helper::saveExperimentAnnotation);
mpSaveSimulationFlagsAnnotationCheckBox = new QCheckBox(Helper::saveOpenModelicaSimulationFlagsAnnotation);
mpSaveTranslationFlagsAnnotationCheckBox = new QCheckBox(Helper::saveOpenModelicaCommandLineOptionsAnnotation);
mpSimulateCheckBox = new QCheckBox(Helper::simulate);
mpSimulateCheckBox->setChecked(true);
// Create the buttons
mpOkButton = new QPushButton(Helper::ok);
mpOkButton->setAutoDefault(true);
connect(mpOkButton, SIGNAL(clicked()), this, SLOT(simulate()));
mpCancelButton = new QPushButton(Helper::cancel);
mpCancelButton->setAutoDefault(false);
connect(mpCancelButton, SIGNAL(clicked()), this, SLOT(reject()));
// adds buttons to the button box
mpButtonBox = new QDialogButtonBox(Qt::Horizontal);
mpButtonBox->addButton(mpOkButton, QDialogButtonBox::ActionRole);
mpButtonBox->addButton(mpCancelButton, QDialogButtonBox::ActionRole);
// Create a layout
QGridLayout *pMainLayout = new QGridLayout;
pMainLayout->addWidget(mpSimulationHeading, 0, 0);
pMainLayout->addWidget(mpHorizontalLine, 1, 0);
pMainLayout->addWidget(mpSimulationTabWidget, 2, 0);
pMainLayout->addWidget(mpSaveExperimentAnnotationCheckBox, 3, 0);
pMainLayout->addWidget(mpSaveTranslationFlagsAnnotationCheckBox, 4, 0);
pMainLayout->addWidget(mpSaveSimulationFlagsAnnotationCheckBox, 5, 0);
pMainLayout->addWidget(mpSimulateCheckBox, 6, 0);
pMainLayout->addWidget(mpButtonBox, 7, 0);
setLayout(pMainLayout);
}
/*!
Validates the simulation values entered by the user.
*/
bool SimulationDialog::validate()
{
if (mpStartTimeTextBox->text().isEmpty()) {
mpStartTimeTextBox->setText("0");
}
if (mpStopTimeTextBox->text().isEmpty()) {
mpStopTimeTextBox->setText("1");
}
if (mpIntervalRadioButton->isChecked() && mpIntervalTextBox->text().isEmpty()) {
mpIntervalTextBox->setText("0.002");
}
if (mpStartTimeTextBox->text().toDouble() > mpStopTimeTextBox->text().toDouble()) {
QMessageBox::critical(MainWindow::instance(), QString("%1 - %2").arg(Helper::applicationName, Helper::error),
GUIMessages::getMessage(GUIMessages::SIMULATION_STARTTIME_LESSTHAN_STOPTIME), Helper::ok);
return false;
}
/* Ticket:5974
* Check if there is already active simulation running of this model.
*/
SimulationOutputWidget *pSimulationOutputWidget = MessagesWidget::instance()->getSimulationOutputWidget(mClassName);
if (pSimulationOutputWidget && (pSimulationOutputWidget->isCompilationProcessRunning() || pSimulationOutputWidget->isSimulationProcessRunning())) {
QMessageBox::critical(MainWindow::instance(), QString("%1 - %2").arg(Helper::applicationName, Helper::error),
tr("Simulation of model <b>%1</b> is already running. Please wait for it to finish or cancel it before running another simulation of the same model.")
.arg(mClassName), Helper::ok);
return false;
}
return true;
}
/*!
Initializes the simulation dialog with the default values.
*/
void SimulationDialog::initializeFields(bool isReSimulate, SimulationOptions simulationOptions)
{
if (!isReSimulate) {
mIsReSimulate = false;
mClassName = mpLibraryTreeItem->getNameStructure();
mFileName = mpLibraryTreeItem->getFileName();
setWindowTitle(QString(Helper::applicationName).append(" - ").append(Helper::simulationSetup).append(" - ").append(mClassName));
mpSimulationHeading->setText(QString(Helper::simulationSetup).append(" - ").append(mClassName));
// apply simulation options
mpLibraryTreeItem->mSimulationOptions.setClassName(mClassName);
/* Fix for ticket:5796
* Set the file name prefix to the model name to avoid the long paths.
*/
if (!mpLibraryTreeItem->mSimulationOptions.isValid()) {
mpLibraryTreeItem->mSimulationOptions.setFileNamePrefix(StringHandler::getLastWordAfterDot(mClassName));
}
applySimulationOptions(mpLibraryTreeItem->mSimulationOptions);
/* Fix for ticket:4975
* If SimulationOptions is invalid it means we are going to simulate this class for the first time.
* So in that case read the experiment and __OpenModelica_simulationFlags annotations and apply them on top of the default.
* If SimulationOptions is valid that means we already simulated that class and in that case we applied the options last time set
* by the user.
*/
if (!mpLibraryTreeItem->mSimulationOptions.isValid()) {
// if the class has experiment annotation then read it.
if (MainWindow::instance()->getOMCProxy()->isExperiment(mClassName)) {
// get the simulation options....
OMCInterface::getSimulationOptions_res simulationOptions_res = MainWindow::instance()->getOMCProxy()->getSimulationOptions(mClassName);
// since we always get simulationOptions so just get the values from array
mpStartTimeTextBox->setText(QString::number(simulationOptions_res.startTime));
mpStopTimeTextBox->setText(QString::number(simulationOptions_res.stopTime));
mpToleranceTextBox->setText(QString::number(simulationOptions_res.tolerance));
mpNumberofIntervalsSpinBox->setValue(simulationOptions_res.numberOfIntervals);
mpIntervalTextBox->setText(QString::number(simulationOptions_res.interval));
}
// apply the global translation flags
TranslationFlagsWidget *pGlobalTranslationFlagsWidget = OptionsDialog::instance()->getSimulationPage()->getTranslationFlagsWidget();
mpTranslationFlagsWidget->getMatchingAlgorithmComboBox()->setCurrentIndex(pGlobalTranslationFlagsWidget->getMatchingAlgorithmComboBox()->currentIndex());
mpTranslationFlagsWidget->getIndexReductionMethodComboBox()->setCurrentIndex(pGlobalTranslationFlagsWidget->getIndexReductionMethodComboBox()->currentIndex());
mpTranslationFlagsWidget->getInitializationCheckBox()->setChecked(pGlobalTranslationFlagsWidget->getInitializationCheckBox()->isChecked());
mpTranslationFlagsWidget->getEvaluateAllParametersCheckBox()->setChecked(pGlobalTranslationFlagsWidget->getEvaluateAllParametersCheckBox()->isChecked());
mpTranslationFlagsWidget->getNLSanalyticJacobianCheckBox()->setChecked(pGlobalTranslationFlagsWidget->getNLSanalyticJacobianCheckBox()->isChecked());
mpTranslationFlagsWidget->getParmodautoCheckBox()->setChecked(pGlobalTranslationFlagsWidget->getParmodautoCheckBox()->isChecked());
mpTranslationFlagsWidget->getOldInstantiationCheckBox()->setChecked(pGlobalTranslationFlagsWidget->getOldInstantiationCheckBox()->isChecked());
mpTranslationFlagsWidget->getAdditionalTranslationFlagsTextBox()->setText(pGlobalTranslationFlagsWidget->getAdditionalTranslationFlagsTextBox()->text());
// if ignoreCommandLineOptionsAnnotation flag is not set then read the __OpenModelica_commandLineOptions annotation
if (!OptionsDialog::instance()->getSimulationPage()->getIgnoreCommandLineOptionsAnnotationCheckBox()->isChecked()) {
QStringList additionalTranslationFlagsList;
QString commandLineOptions = MainWindow::instance()->getOMCProxy()->getNamedAnnotation(mClassName, "__OpenModelica_commandLineOptions");
QStringList commandLineOptionsList = commandLineOptions.split(" ");
foreach (QString commandLineOption, commandLineOptionsList) {
QStringList commandLineOptionList = commandLineOption.split("=");
QString commandLineOptionKey, commandLineOptionValues;
if (commandLineOptionList.size() > 1) {
commandLineOptionKey = commandLineOptionList.at(0);
commandLineOptionValues = commandLineOptionList.at(1);
} else {
commandLineOptionKey = commandLineOption;
commandLineOptionValues = "";
}
QString commandLineOptionKeyFiltered = QString(commandLineOptionKey).remove(QRegExp("\\-|\\--|\\+"));
if (commandLineOptionKeyFiltered.compare("matchingAlgorithm") == 0) {
int currentIndex = mpTranslationFlagsWidget->getMatchingAlgorithmComboBox()->findText(commandLineOptionValues);
if (currentIndex > -1) {
mpTranslationFlagsWidget->getMatchingAlgorithmComboBox()->setCurrentIndex(currentIndex);
}
} else if (commandLineOptionKeyFiltered.compare("indexReductionMethod") == 0) {
int currentIndex = mpTranslationFlagsWidget->getIndexReductionMethodComboBox()->findText(commandLineOptionValues);
if (currentIndex > -1) {
mpTranslationFlagsWidget->getIndexReductionMethodComboBox()->setCurrentIndex(currentIndex);
}
} else if (commandLineOptionKeyFiltered.compare("d") == 0) { // check debug flags i.e., -d=evaluateAllParameters,initialization etc.
QStringList commandLineOptionValuesList = commandLineOptionValues.split(",");
QStringList additionalDebugFlagsList;
foreach (QString commandLineOptionValue, commandLineOptionValuesList) {
commandLineOptionValue = commandLineOptionValue.trimmed();
if (commandLineOptionValue.compare("initialization") == 0) {
mpTranslationFlagsWidget->getInitializationCheckBox()->setChecked(true);
} else if (commandLineOptionValue.compare("evaluateAllParameters") == 0) {
mpTranslationFlagsWidget->getEvaluateAllParametersCheckBox()->setChecked(true);
} else if (commandLineOptionValue.compare("NLSanalyticJacobian") == 0) {
mpTranslationFlagsWidget->getNLSanalyticJacobianCheckBox()->setChecked(true);
} else if (commandLineOptionValue.compare("parmodauto") == 0) {
mpTranslationFlagsWidget->getParmodautoCheckBox()->setChecked(true);
} else if (commandLineOptionValue.compare("newInst") == 0) {
mpTranslationFlagsWidget->getOldInstantiationCheckBox()->setChecked(false);
} else {
additionalDebugFlagsList.append(commandLineOptionValue);
}
}
if (!additionalDebugFlagsList.isEmpty()) {
additionalTranslationFlagsList.append(QString("-d=%1").arg(additionalDebugFlagsList.join(",")));
}
}
}
QString additionalTranslationFlagsText = mpTranslationFlagsWidget->getAdditionalTranslationFlagsTextBox()->text();
if (additionalTranslationFlagsText.isEmpty()) {
mpTranslationFlagsWidget->getAdditionalTranslationFlagsTextBox()->setText(additionalTranslationFlagsList.join(" "));
} else {
mpTranslationFlagsWidget->getAdditionalTranslationFlagsTextBox()->setText(QString("%1 %2").arg(additionalTranslationFlagsText)
.arg(additionalTranslationFlagsList.join(" ")));
}
}
// if ignoreSimulationFlagsAnnotation flag is not set then read the __OpenModelica_simulationFlags annotation
if (!OptionsDialog::instance()->getSimulationPage()->getIgnoreSimulationFlagsAnnotationCheckBox()->isChecked()) {
QMap<QString, QString> additionalSimulationFlags;
// if the class has __OpenModelica_simulationFlags annotation then use its values.
QList<QString> simulationFlags = MainWindow::instance()->getOMCProxy()->getAnnotationNamedModifiers(mClassName, "__OpenModelica_simulationFlags");
foreach (QString simulationFlag, simulationFlags) {
QString value = MainWindow::instance()->getOMCProxy()->getAnnotationModifierValue(mClassName, "__OpenModelica_simulationFlags", simulationFlag);
if (simulationFlag.compare("clock") == 0) {
mpClockComboBox->setCurrentIndex(mpClockComboBox->findText(value));
} else if (simulationFlag.compare("cpu") == 0) {
mpCPUTimeCheckBox->setChecked(true);
} else if (simulationFlag.compare("noRestart") == 0) {
mpRestartAfterEventCheckBox->setChecked(false);
} else if (simulationFlag.compare("noRootFinding") == 0) {
mpRootFindingCheckBox->setChecked(false);
} else if (simulationFlag.compare("single") == 0) {
mpSinglePrecisionCheckBox->setChecked(true);
} else if (simulationFlag.compare("emit_protected") == 0) {
mpProtectedVariablesCheckBox->setChecked(true);
} else if (simulationFlag.compare("ignoreHideResult") == 0) {
mpIgnoreHideResultCheckBox->setChecked(true);
} else if (simulationFlag.compare("f") == 0) {
mpModelSetupFileTextBox->setText(value);
} else if (simulationFlag.compare("iif") == 0) {
mpEquationSystemInitializationFileTextBox->setText(value);
} else if (simulationFlag.compare("iim") == 0) {
mpInitializationMethodComboBox->setCurrentIndex(mpInitializationMethodComboBox->findText(value));
} else if (simulationFlag.compare("iit") == 0) {
mpEquationSystemInitializationTimeTextBox->setText(value);
} else if (simulationFlag.compare("initialStepSize") == 0) {
mpInitialStepSizeTextBox->setText(value);
} else if (simulationFlag.compare("jacobian") == 0) {
mpJacobianComboBox->setCurrentIndex(mpJacobianComboBox->findText(value));
} else if (simulationFlag.compare("l") == 0) {
mpLinearizationTimeTextBox->setText(value);
} else if (simulationFlag.compare("ls") == 0) {
mpLinearSolverComboBox->setCurrentIndex(mpLinearSolverComboBox->findText(value));
} else if (simulationFlag.compare("maxIntegrationOrder") == 0) {
mpMaxIntegrationOrderSpinBox->setValue(value.toInt());
} else if (simulationFlag.compare("maxStepSize") == 0) {
mpMaxStepSizeTextBox->setText(value);
} else if (simulationFlag.compare("nls") == 0) {
mpNonLinearSolverComboBox->setCurrentIndex(mpNonLinearSolverComboBox->findText(value));
} else if (simulationFlag.compare("noEquidistantTimeGrid") == 0) {
mpEquidistantTimeGridCheckBox->setChecked(false);
} else if (simulationFlag.compare("noEventEmit") == 0) {
mpStoreVariablesAtEventsCheckBox->setChecked(false);
} else if (simulationFlag.compare("output") == 0) {
mpOutputVariablesTextBox->setText(value);
} else if (simulationFlag.compare("r") == 0) {
mpResultFileNameTextBox->setText(value);
QRegExp resultFilesRegExp(Helper::omResultFileTypesRegExp);
if (resultFilesRegExp.indexIn(value) != -1) {
int currentIndex = mpOutputFormatComboBox->findText(StringHandler::getLastWordAfterDot(value));
if (currentIndex > -1) {
mpOutputFormatComboBox->setCurrentIndex(currentIndex);
}
}
} else if (simulationFlag.compare("s") == 0) {
mpMethodComboBox->setCurrentIndex(mpMethodComboBox->findText(value));
} else if (simulationFlag.compare("lv") == 0) {
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
QStringList logStreams = value.split(",", Qt::SkipEmptyParts);
#else // QT_VERSION_CHECK
QStringList logStreams = value.split(",", QString::SkipEmptyParts);
#endif // QT_VERSION_CHECK
int i = 0;
while (QLayoutItem* pLayoutItem = mpLoggingGroupLayout->itemAt(i)) {
if (dynamic_cast<QCheckBox*>(pLayoutItem->widget())) {
QCheckBox *pLogStreamCheckBox = dynamic_cast<QCheckBox*>(pLayoutItem->widget());
if (logStreams.contains(pLogStreamCheckBox->text())) {
pLogStreamCheckBox->setChecked(true);
}
}
i++;
}
} else if (simulationFlag.compare("reconcile") == 0) {
mpLibraryTreeItem->mSimulationOptions.setDataReconciliationAlgorithm("dataReconciliation");
} else if (simulationFlag.compare("reconcileBoundaryConditions") == 0) {
mpLibraryTreeItem->mSimulationOptions.setDataReconciliationAlgorithm("dataReconciliationBoundaryConditions");
} else if (simulationFlag.compare("sx") == 0) {
mpLibraryTreeItem->mSimulationOptions.setDataReconciliationMeasurementInputFile(value);
} else if (simulationFlag.compare("cx") == 0) {
mpLibraryTreeItem->mSimulationOptions.setDataReconciliationCorrelationMatrixInputFile(value);
} else if (simulationFlag.compare("eps") == 0) {
mpLibraryTreeItem->mSimulationOptions.setDataReconciliationEpsilon(value);
} else { // put everything else in the Additional Simulation Flags textbox only if the simulation flag is valid
bool isValidSimulationFlag = false;
for (int i = FLAG_UNKNOWN + 1 ; i < FLAG_MAX ; i++) {
if (QString(FLAG_NAME[i]).compare(simulationFlag) == 0) {
additionalSimulationFlags.insert(simulationFlag, value);
isValidSimulationFlag = true;
break;
}
}
if (!isValidSimulationFlag) {
MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, tr("Ignoring unknown simulation flag: %1").arg(simulationFlag),
Helper::simulationKind, Helper::warningLevel));
}
}
}
QStringList additionalSimulationFlagsList;
QMapIterator<QString, QString> additionalSimulationFlagsIterator(additionalSimulationFlags);
additionalSimulationFlagsIterator.toFront();
while (additionalSimulationFlagsIterator.hasNext()) {
additionalSimulationFlagsIterator.next();
if (additionalSimulationFlagsIterator.value().compare("()") == 0) {
additionalSimulationFlagsList.append(QString("-%1").arg(additionalSimulationFlagsIterator.key()));
} else {
additionalSimulationFlagsList.append(QString("-%1=%2")
.arg(additionalSimulationFlagsIterator.key())
.arg(additionalSimulationFlagsIterator.value()));
}
}
mpAdditionalSimulationFlagsTextBox->setText(additionalSimulationFlagsList.join(" "));
}
}
mpCflagsTextBox->setEnabled(true);
mpFileNameTextBox->setEnabled(true);
mpSaveExperimentAnnotationCheckBox->setVisible(true);
mpSaveSimulationFlagsAnnotationCheckBox->setVisible(true);
mpSaveTranslationFlagsAnnotationCheckBox->setVisible(true);
mpSimulateCheckBox->setVisible(true);
} else {
mIsReSimulate = true;
mClassName = simulationOptions.getClassName();
mFileName = simulationOptions.getFileName();
setWindowTitle(QString(Helper::applicationName).append(" - ").append(Helper::reSimulation).append(" - ").append(mClassName));
mpSimulationHeading->setText(QString(Helper::reSimulation).append(" - ").append(mClassName));
// apply simulation options
applySimulationOptions(simulationOptions);
mpInteractiveSimulationGroupBox->setChecked(false);
mpInteractiveSimulationGroupBox->setEnabled(false);
mpCflagsTextBox->setDisabled(true);
mpFileNameTextBox->setDisabled(true);
// save simulation settings
mpSaveExperimentAnnotationCheckBox->setVisible(false);
mpSaveSimulationFlagsAnnotationCheckBox->setVisible(false);
mpSaveTranslationFlagsAnnotationCheckBox->setVisible(false);
mpSimulateCheckBox->setVisible(false);
}
}
/*!
* \brief SimulationDialog::applySimulationOptions
* Apply the simulation options to the SimulationDialog.
* \param simulationOptions
*/
void SimulationDialog::applySimulationOptions(SimulationOptions simulationOptions)
{
// Simulation Interval
mpStartTimeTextBox->setText(simulationOptions.getStartTime());
mpStopTimeTextBox->setText(simulationOptions.getStopTime());
// Number Of Intervals
mpNumberofIntervalsSpinBox->setValue(simulationOptions.getNumberofIntervals());
// Interval
mpIntervalTextBox->setText(QString::number(simulationOptions.getStepSize()));
// Interactive simulation
QString targetLanguage = OptionsDialog::instance()->getSimulationPage()->getTargetLanguageComboBox()->currentText();
if (targetLanguage.compare("C") == 0) {
mpInteractiveSimulationGroupBox->setEnabled(true);
mpInteractiveSimulationGroupBox->setChecked(simulationOptions.isInteractiveSimulation());
mpInteractiveSimulationStepCheckBox->setChecked(simulationOptions.isInteractiveSimulationWithSteps());
mpInteractiveSimulationPortNumberTextBox->setText(QString::number(simulationOptions.getInteractiveSimulationPortNumber()));
} else {
mpInteractiveSimulationGroupBox->setChecked(false);
mpInteractiveSimulationGroupBox->setEnabled(false);
}
// Integration
int currentIndex = mpMethodComboBox->findText(simulationOptions.getMethod(), Qt::MatchExactly);
if (currentIndex > -1) {
mpMethodComboBox->setCurrentIndex(currentIndex);
}
// Tolerance
mpToleranceTextBox->setText(simulationOptions.getTolerance());
// dassl jacobian
currentIndex = mpJacobianComboBox->findText(simulationOptions.getJacobian(), Qt::MatchExactly);
if (currentIndex > -1) {
mpJacobianComboBox->setCurrentIndex(currentIndex);
}
// no root finding
mpRootFindingCheckBox->setChecked(simulationOptions.getRootFinding());
// no restart
mpRestartAfterEventCheckBox->setChecked(simulationOptions.getRestartAfterEvent());
// initial step size
mpInitialStepSizeTextBox->setText(simulationOptions.getInitialStepSize());
// max step size
mpMaxStepSizeTextBox->setText(simulationOptions.getMaxStepSize());
// max integration order
mpMaxIntegrationOrderSpinBox->setValue(simulationOptions.getMaxIntegration());
// Compiler Flags
mpCflagsTextBox->setText(simulationOptions.getCflags());
// Number of Processors
mpNumberOfProcessorsSpinBox->setValue(simulationOptions.getNumberOfProcessors());
// Launch Transformational Debugger checkbox
mpLaunchTransformationalDebuggerCheckBox->setChecked(simulationOptions.getLaunchTransformationalDebugger());
// Launch Algorithmic Debugger checkbox
mpLaunchAlgorithmicDebuggerCheckBox->setChecked(simulationOptions.getLaunchAlgorithmicDebugger());
#if !defined(WITHOUT_OSG)
// Simulate with Animation checkbox
mpLaunchAnimationCheckBox->setChecked(simulationOptions.getSimulateWithAnimation());
#endif
// build only
mpBuildOnlyCheckBox->setChecked(simulationOptions.getBuildOnly());
// Translation Flags
mpTranslationFlagsWidget->applySimulationOptions(simulationOptions);
// Model Setup File
mpModelSetupFileTextBox->setText(simulationOptions.getModelSetupFile());
// Initialization Methods
currentIndex = mpInitializationMethodComboBox->findText(simulationOptions.getInitializationMethod(), Qt::MatchExactly);
if (currentIndex > -1) {
mpInitializationMethodComboBox->setCurrentIndex(currentIndex);
}
// Equation System Initialization File
mpEquationSystemInitializationFileTextBox->setText(simulationOptions.getEquationSystemInitializationFile());
// Equation System time
mpEquationSystemInitializationTimeTextBox->setText(simulationOptions.getEquationSystemInitializationTime());
// clock
currentIndex = mpClockComboBox->findText(simulationOptions.getClock(), Qt::MatchExactly);
if (currentIndex > -1) {
mpClockComboBox->setCurrentIndex(currentIndex);
}
// Linear Solvers
currentIndex = mpLinearSolverComboBox->findText(simulationOptions.getLinearSolver(), Qt::MatchExactly);
if (currentIndex > -1) {
mpLinearSolverComboBox->setCurrentIndex(currentIndex);
}
// Non Linear Solvers
currentIndex = mpNonLinearSolverComboBox->findText(simulationOptions.getNonLinearSolver(), Qt::MatchExactly);
if (currentIndex > -1) {
mpNonLinearSolverComboBox->setCurrentIndex(currentIndex);
}
// time where the linearization of the model should be performed
mpLinearizationTimeTextBox->setText(simulationOptions.getLinearizationTime());
// output variables
mpOutputVariablesTextBox->setText(simulationOptions.getOutputVariables());
// measure simulation time checkbox
currentIndex = mpProfilingComboBox->findText(simulationOptions.getProfiling(), Qt::MatchExactly);
if (currentIndex > -1) {
mpProfilingComboBox->setCurrentIndex(currentIndex);
}
// cpu-time checkbox
mpCPUTimeCheckBox->setChecked(simulationOptions.getCPUTime());
// enable all warnings
mpEnableAllWarningsCheckBox->setChecked(simulationOptions.getEnableAllWarnings());
// Logging
QStringList logStreams = simulationOptions.getLogStreams();
int i = 0;
while (QLayoutItem* pLayoutItem = mpLoggingGroupLayout->itemAt(i)) {
if (dynamic_cast<QCheckBox*>(pLayoutItem->widget())) {
QCheckBox *pLogStreamCheckBox = dynamic_cast<QCheckBox*>(pLayoutItem->widget());
if (logStreams.contains(pLogStreamCheckBox->text())) {
pLogStreamCheckBox->setChecked(true);
} else {
pLogStreamCheckBox->setChecked(false);
}
}
i++;
}
mpAdditionalSimulationFlagsTextBox->setText(simulationOptions.getAdditionalSimulationFlags());
// output format
bool state = mpOutputFormatComboBox->blockSignals(true);
currentIndex = mpOutputFormatComboBox->findText(simulationOptions.getOutputFormat(), Qt::MatchExactly);
if (currentIndex > -1) {
mpOutputFormatComboBox->setCurrentIndex(currentIndex);
}
mpOutputFormatComboBox->blockSignals(state);
// single precision