-
Notifications
You must be signed in to change notification settings - Fork 298
/
MainWindow.cpp
4515 lines (4350 loc) · 195 KB
/
MainWindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* 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 "MainWindow.h"
/* Keep PlotWindowContainer on top to include OSG first */
#include "Plotting/PlotWindowContainer.h"
#include "Modeling/ModelWidgetContainer.h"
#include "Options/OptionsDialog.h"
#include "Modeling/MessagesWidget.h"
#include "OMS/OMSProxy.h"
#include "Modeling/LibraryTreeWidget.h"
#include "Modeling/ModelicaClassDialog.h"
#include "OMS/ModelDialog.h"
#include "Debugger/GDB/GDBAdapter.h"
#include "Debugger/StackFrames/StackFramesWidget.h"
#include "Debugger/Locals/LocalsWidget.h"
#include "Modeling/DocumentationWidget.h"
#include "Plotting/VariablesWidget.h"
#include "Search/SearchWidget.h"
#if !defined(WITHOUT_OSG)
#include "Animation/ThreeDViewer.h"
#include "Animation/ViewerWidget.h"
#endif
#include "Util/Helper.h"
#include "Simulation/SimulationOutputWidget.h"
#include "TLM/FetchInterfaceDataDialog.h"
#include "TLM/TLMCoSimulationOutputWidget.h"
#include "OMS/OMSSimulationDialog.h"
#include "Debugger/DebuggerConfigurationsDialog.h"
#include "Debugger/Attach/AttachToProcessDialog.h"
#include "TransformationalDebugger/TransformationsWidget.h"
#include "Options/NotificationsDialog.h"
#include "Simulation/SimulationDialog.h"
#include "TLM/TLMCoSimulationDialog.h"
#include "FMI/ImportFMUDialog.h"
#include "FMI/ImportFMUModelDescriptionDialog.h"
#include "Git/CommitChangesDialog.h"
#include "Git/RevertCommitsDialog.h"
#include "Git/CleanDialog.h"
#include "Git/GitCommands.h"
#include "Traceability/TraceabilityInformationURI.h"
#include "Traceability/TraceabilityGraphViewWidget.h"
#include "Plotting/DiagramWindow.h"
#include "Interfaces/InformationInterface.h"
#include "Interfaces/ModelInterface.h"
#include "omc_config.h"
#include <QtSvg/QSvgGenerator>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), mExitApplicationStatus(false)
{
// Make sure we honor the system's proxy settings
QNetworkProxyFactory::setUseSystemConfiguration(true);
// This is a very convoluted way of asking for the default system font in Qt
QFont systmFont("Monospace");
systmFont.setStyleHint(QFont::System);
Helper::systemFontInfo = QFontInfo(systmFont);
// This is a very convoluted way of asking for the default monospace font in Qt
QFont monospaceFont("Monospace");
monospaceFont.setStyleHint(QFont::TypeWriter);
Helper::monospacedFontInfo = QFontInfo(monospaceFont);
/*! @note Register the RecentFile, FindTextOM and DebuggerConfiguration struct in the Qt's meta system
* Don't remove/move the following lines.
* Because RecentFile, FindTextOM and DebuggerConfiguration structs should be registered before reading the recentFilesList, FindTextOM and
* DebuggerConfiguration section respectively from the settings file.
*/
qRegisterMetaTypeStreamOperators<RecentFile>("RecentFile");
qRegisterMetaTypeStreamOperators<FindTextOM>("FindTextOM");
qRegisterMetaTypeStreamOperators<DebuggerConfiguration>("DebuggerConfiguration");
/*! @note The above three lines registers the structs as QMetaObjects. Do not remove/move them. */
setObjectName("MainWindow");
setWindowTitle(Helper::applicationName + " - " + Helper::applicationIntroText);
setWindowIcon(QIcon(":/Resources/icons/modeling.png"));
setMinimumSize(400, 300);
resize(800, 600);
setContentsMargins(1, 1, 1, 1);
}
MainWindow *MainWindow::mpInstance = 0;
/*!
* \brief MainWindow::instance
* Creates an instance of MainWindow. If we already have an instance then just return it.
* \return
*/
MainWindow *MainWindow::instance()
{
if (!mpInstance) {
mpInstance = new MainWindow;
}
return mpInstance;
}
/*!
* \brief MainWindow::setUpMainWindow
* Creates all the GUI widgets.
* \param threadData
*/
void MainWindow::setUpMainWindow(threadData_t *threadData)
{
if (!isTestsuiteRunning()) {
// Reopen the standard output stream.
QString outputFileName = Utilities::tempDirectory() + "/omeditoutput.txt";
#ifdef Q_OS_WIN
_wfreopen((wchar_t*)outputFileName.utf16(), L"w", stdout);
#else
freopen(outputFileName.toUtf8().constData(), "w", stdout);
#endif
setbuf(stdout, NULL); // used non-buffered stdout
// Reopen the standard error stream.
QString errorFileName = Utilities::tempDirectory() + "/omediterror.txt";
#ifdef Q_OS_WIN
_wfreopen((wchar_t*)errorFileName.utf16(), L"w", stderr);
#else
freopen(outputFileName.toUtf8().constData(), "w", stderr);
#endif
setbuf(stderr, NULL); // used non-buffered stderr
}
SplashScreen::instance()->showMessage(tr("Initializing"), Qt::AlignRight, Qt::white);
// Create an object of MessagesWidget.
MessagesWidget::create();
// Create MessagesDockWidget dock
mpMessagesDockWidget = new QDockWidget(tr("Messages Browser"), this);
mpMessagesDockWidget->setObjectName("Messages");
mpMessagesDockWidget->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
mpMessagesDockWidget->setWidget(MessagesWidget::instance());
addDockWidget(Qt::BottomDockWidgetArea, mpMessagesDockWidget);
mpMessagesDockWidget->hide();
connect(MessagesWidget::instance(), SIGNAL(MessageAdded()), SLOT(showMessagesBrowser()));
// Create the OMCProxy object.
mpOMCProxy = new OMCProxy(threadData, this);
if (getExitApplicationStatus()) {
return;
}
SplashScreen::instance()->showMessage(tr("Reading Settings"), Qt::AlignRight, Qt::white);
// Get the number of processors.
mNumberOfProcessors = mpOMCProxy->numProcessors();
// create an object of OMSProxy
OMSProxy::create();
// Create an object of OptionsDialog
OptionsDialog::create();
SplashScreen::instance()->showMessage(tr("Loading Widgets"), Qt::AlignRight, Qt::white);
// apply MessagesWidget settings
MessagesWidget::instance()->applyMessagesSettings();
// Create an object of QProgressBar
mpProgressBar = new QProgressBar;
mpProgressBar->setMaximumWidth(300);
mpProgressBar->setTextVisible(false);
mpProgressBar->setVisible(false);
// Position Label
mpPositionLabel = new Label;
mpPositionLabel->setMinimumWidth(75);
// create the perspective tabs
mpPerspectiveTabbar = new QTabBar;
mpPerspectiveTabbar->setDocumentMode(true);
mpPerspectiveTabbar->setShape(QTabBar::RoundedSouth);
// welcome perspective
mpPerspectiveTabbar->addTab(QIcon(":/Resources/icons/omedit.png"), tr("Welcome"));
QShortcut *pWelcomeShortcut = new QShortcut(QKeySequence("Ctrl+f1"), this);
connect(pWelcomeShortcut, SIGNAL(activated()), SLOT(switchToWelcomePerspectiveSlot()));
mpPerspectiveTabbar->setTabToolTip(0, tr("Changes to welcome perspective (%1)").arg(pWelcomeShortcut->key().toString()));
// modeling perspective
mpPerspectiveTabbar->addTab(QIcon(":/Resources/icons/modeling.png"), tr("Modeling"));
QShortcut *pModelingShortcut = new QShortcut(QKeySequence("Ctrl+f2"), this);
connect(pModelingShortcut, SIGNAL(activated()), SLOT(switchToModelingPerspectiveSlot()));
mpPerspectiveTabbar->setTabToolTip(1, tr("Changes to modeling perspective (%1)").arg(pModelingShortcut->key().toString()));
// plotting perspective
mpPerspectiveTabbar->addTab(QIcon(":/Resources/icons/omplot.png"), tr("Plotting"));
QShortcut *pPlottingShortcut = new QShortcut(QKeySequence("Ctrl+f3"), this);
connect(pPlottingShortcut, SIGNAL(activated()), SLOT(switchToPlottingPerspectiveSlot()));
mpPerspectiveTabbar->setTabToolTip(2, tr("Changes to plotting perspective (%1)").arg(pPlottingShortcut->key().toString()));
// algorithmic debugging perspective
mpPerspectiveTabbar->addTab(QIcon(":/Resources/icons/debugger.svg"), tr("Debugging"));
QShortcut *pAlgorithmicDebuggingShortcut = new QShortcut(QKeySequence("Ctrl+f5"), this);
connect(pAlgorithmicDebuggingShortcut, SIGNAL(activated()), SLOT(switchToAlgorithmicDebuggingPerspectiveSlot()));
mpPerspectiveTabbar->setTabToolTip(3, tr("Changes to debugging perspective (%1)").arg(pAlgorithmicDebuggingShortcut->key().toString()));
// change the perspective when perspective tab bar selection is changed
connect(mpPerspectiveTabbar, SIGNAL(currentChanged(int)), SLOT(perspectiveTabChanged(int)));
// Create an object of QStatusBar
mpStatusBar = new QStatusBar();
mpStatusBar->setObjectName("statusBar");
mpStatusBar->setContentsMargins(0, 0, 0, 0);
// add items to statusbar
mpStatusBar->addPermanentWidget(mpProgressBar);
mpStatusBar->addPermanentWidget(mpPositionLabel);
mpStatusBar->addPermanentWidget(mpPerspectiveTabbar);
// set status bar for MainWindow
setStatusBar(mpStatusBar);
// Create an object of LibraryWidget
mpLibraryWidget = new LibraryWidget(this);
// Create LibraryDockWidget
mpLibraryDockWidget = new QDockWidget(tr("Libraries Browser"), this);
//mpLibraryDockWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
mpLibraryDockWidget->setObjectName("Libraries");
mpLibraryDockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
mpLibraryDockWidget->setWidget(mpLibraryWidget);
addDockWidget(Qt::LeftDockWidgetArea, mpLibraryDockWidget);
mpLibraryWidget->getLibraryTreeView()->setFocus(Qt::ActiveWindowFocusReason);
// Create an object of SearchWidget
mpSearchWidget = new SearchWidget(this);
mpSearchDockWidget = new QDockWidget(tr("Search Browser"),this);
mpSearchDockWidget->setObjectName("Search");
mpSearchDockWidget->setAllowedAreas(Qt::BottomDockWidgetArea | Qt::TopDockWidgetArea);
mpSearchDockWidget->setWidget(mpSearchWidget);
addDockWidget(Qt::BottomDockWidgetArea, mpSearchDockWidget);
mpSearchDockWidget->hide();
// create the GDB adapter instance
GDBAdapter::create();
// create stack frames widget
mpStackFramesWidget = new StackFramesWidget(this);
// Create stack frames dock widget
mpStackFramesDockWidget = new QDockWidget(tr("Stack Frames Browser"), this);
mpStackFramesDockWidget->setObjectName("StackFrames");
mpStackFramesDockWidget->setWidget(mpStackFramesWidget);
addDockWidget(Qt::TopDockWidgetArea, mpStackFramesDockWidget);
// create breakpoints widget
mpBreakpointsWidget = new BreakpointsWidget(this);
// Create breakpoints dock widget
mpBreakpointsDockWidget = new QDockWidget(tr("BreakPoints Browser"), this);
mpBreakpointsDockWidget->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
mpBreakpointsDockWidget->setObjectName("BreakPoints");
mpBreakpointsDockWidget->setWidget(mpBreakpointsWidget);
addDockWidget(Qt::TopDockWidgetArea, mpBreakpointsDockWidget);
// create locals widget
mpLocalsWidget = new LocalsWidget(this);
// Create locals dock widget
mpLocalsDockWidget = new QDockWidget(tr("Locals Browser"), this);
mpLocalsDockWidget->setObjectName("Locals");
mpLocalsDockWidget->setWidget(mpLocalsWidget);
addDockWidget(Qt::RightDockWidgetArea, mpLocalsDockWidget);
// Create target output widget
mpTargetOutputWidget = new TargetOutputWidget(this);
// Create GDB console dock widget
mpTargetOutputDockWidget = new QDockWidget(tr("Output Browser"), this);
mpTargetOutputDockWidget->setObjectName("OutputBrowser");
mpTargetOutputDockWidget->setWidget(mpTargetOutputWidget);
addDockWidget(Qt::BottomDockWidgetArea, mpTargetOutputDockWidget);
// Create GDB console widget
mpGDBLoggerWidget = new GDBLoggerWidget(this);
// Create GDB console dock widget
mpGDBLoggerDockWidget = new QDockWidget(tr("Debugger CLI"), this);
mpGDBLoggerDockWidget->setObjectName("DebuggerLog");
mpGDBLoggerDockWidget->setWidget(mpGDBLoggerWidget);
addDockWidget(Qt::BottomDockWidgetArea, mpGDBLoggerDockWidget);
// put the GDB logger dock widget and output dock widget as tabbed items.
tabifyDockWidget(mpGDBLoggerDockWidget, mpTargetOutputDockWidget);
// create an object of DocumentationWidget
mpDocumentationWidget = new DocumentationWidget(this);
// Create DocumentationWidget dock
mpDocumentationDockWidget = new QDockWidget(tr("Documentation Browser"), this);
mpDocumentationDockWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
mpDocumentationDockWidget->setObjectName("Documentation");
mpDocumentationDockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
mpDocumentationDockWidget->setWidget(mpDocumentationWidget);
addDockWidget(Qt::RightDockWidgetArea, mpDocumentationDockWidget);
mpDocumentationDockWidget->hide();
connect(mpDocumentationDockWidget, SIGNAL(visibilityChanged(bool)), SLOT(documentationDockWidgetVisibilityChanged(bool)));
// Create an object of PlotWindowContainer
mpPlotWindowContainer = new PlotWindowContainer(this);
// create an object of VariablesWidget
mpVariablesWidget = new VariablesWidget(this);
// Create VariablesWidget dock
mpVariablesDockWidget = new QDockWidget(Helper::variablesBrowser, this);
mpVariablesDockWidget->setObjectName("Variables");
mpVariablesDockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
addDockWidget(Qt::RightDockWidgetArea, mpVariablesDockWidget);
mpVariablesDockWidget->setWidget(mpVariablesWidget);
// create traceability graph view widget
// mpTraceabilityGraphViewWidget = new TraceabilityGraphViewWidget(this);
mpTraceabilityInformationURI = new TraceabilityInformationURI(this);
#if !defined(WITHOUT_OSG)
/* Ticket #4252
* Do not create an object of ThreeDViewer by default.
* Only create it when user really use it.
*/
mpThreeDViewer = 0;
// Create ThreeDViewer dock
mpThreeDViewerDockWidget = new QDockWidget(tr("3D Viewer Browser"), this);
mpThreeDViewerDockWidget->setObjectName("3DViewer");
mpThreeDViewerDockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
addDockWidget(Qt::RightDockWidgetArea, mpThreeDViewerDockWidget);
mpThreeDViewerDockWidget->hide();
connect(mpThreeDViewerDockWidget, SIGNAL(visibilityChanged(bool)), SLOT(threeDViewerDockWidgetVisibilityChanged(bool)));
#endif
// set the corners for the dock widgets
setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
//Create Actions, Toolbar and Menus
SplashScreen::instance()->showMessage(tr("Creating Widgets"), Qt::AlignRight, Qt::white);
setAcceptDrops(true);
createActions();
createToolbars();
createMenus();
// enable/disable re-simulation toolbar based on variables browser visibiltiy.
connect(mpVariablesDockWidget, SIGNAL(visibilityChanged(bool)), this, SLOT(enableReSimulationToolbar(bool)));
// Create simulation dialog when needed
mpSimulationDialog = 0;
// Create TLM co-simulation dialog when needed
mpTLMCoSimulationDialog = 0;
// Create the OMSimulator simulation dialog when needed
mpOMSSimulationDialog = 0;
// Create an object of ModelWidgetContainer
mpModelWidgetContainer = new ModelWidgetContainer(this);
// Create an object of WelcomePageWidget
mpWelcomePageWidget = new WelcomePageWidget(this);
updateRecentFileActions();
// OMSens plugin
mpOMSensPlugin = 0;
// create the Git commands instance
//mpGitCommands = new GitCommands(this);
GitCommands::create();
//Create a centralwidget for the main window
QWidget *pCentralwidget = new QWidget;
mpCentralStackedWidget = new QStackedWidget;
mpCentralStackedWidget->addWidget(mpWelcomePageWidget);
mpCentralStackedWidget->addWidget(mpModelWidgetContainer);
mpCentralStackedWidget->addWidget(mpPlotWindowContainer);
// set the layout
QGridLayout *pCentralgrid = new QGridLayout;
pCentralgrid->setVerticalSpacing(4);
pCentralgrid->setContentsMargins(0, 1, 0, 0);
pCentralgrid->addWidget(mpCentralStackedWidget, 0, 0);
pCentralwidget->setLayout(pCentralgrid);
//Set the centralwidget
setCentralWidget(pCentralwidget);
// Load and add user defined Modelica libraries into the Library Widget.
mpLibraryWidget->getLibraryTreeModel()->addModelicaLibraries();
// set command line options
if (OptionsDialog::instance()->getDebuggerPage()->getGenerateOperationsCheckBox()->isChecked()) {
mpOMCProxy->setCommandLineOptions("-d=infoXmlOperations");
}
OptionsDialog::instance()->saveSimulationSettings();
// restore OMEdit widgets state
QSettings *pSettings = Utilities::getApplicationSettings();
if (OptionsDialog::instance()->getGeneralSettingsPage()->getPreserveUserCustomizations()) {
restoreGeometry(pSettings->value("application/geometry").toByteArray());
bool restoreMessagesWidget = !MessagesWidget::instance()->getAllMessageWidget()->getMessagesTextBrowser()->toPlainText().isEmpty();
restoreState(pSettings->value("application/windowState").toByteArray());
pSettings->beginGroup("algorithmicDebugger");
/* restore stackframes list and locals columns width */
mpStackFramesWidget->getStackFramesTreeWidget()->header()->restoreState(pSettings->value("stackFramesTreeState").toByteArray());
mpBreakpointsWidget->getBreakpointsTreeView()->header()->restoreState(pSettings->value("breakPointsTreeState").toByteArray());
mpLocalsWidget->getLocalsTreeView()->header()->restoreState(pSettings->value("localsTreeState").toByteArray());
pSettings->endGroup();
if (restoreMessagesWidget) {
showMessagesBrowser();
}
}
switchToWelcomePerspective();
// read last Open Directory location
if (pSettings->contains("lastOpenDirectory")) {
StringHandler::setLastOpenDirectory(pSettings->value("lastOpenDirectory").toString());
}
// read the grid lines
if (pSettings->contains("modeling/gridLines")) {
mpShowGridLinesAction->setChecked(pSettings->value("modeling/gridLines").toBool());
}
// create the auto save timer
mpAutoSaveTimer = new QTimer(this);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
mpAutoSaveTimer->setTimerType(Qt::PreciseTimer);
#endif
mpAutoSaveTimer->setInterval(OptionsDialog::instance()->getGeneralSettingsPage()->getAutoSaveIntervalSpinBox()->value() * 1000);
connect(mpAutoSaveTimer, SIGNAL(timeout()), SLOT(autoSave()));
// read auto save settings
if (OptionsDialog::instance()->getGeneralSettingsPage()->getEnableAutoSaveGroupBox()->isChecked()) {
mpAutoSaveTimer->start();
}
}
#if !defined(WITHOUT_OSG)
/*!
* \brief MainWindow::isThreeDViewerInitialized
* Returns true if ThreeDViewer is initialized.
* \return
*/
bool MainWindow::isThreeDViewerInitialized()
{
return mpThreeDViewer ? true : false;
}
/*!
* \brief MainWindow::getThreeDViewer
* Returns the ThreeDViewer object. Initializes it if its not initialized.
* \return
*/
ThreeDViewer* MainWindow::getThreeDViewer()
{
// create an object of ThreeDViewer
if (!mpThreeDViewer) {
mpThreeDViewer = new ThreeDViewer(this);
mpThreeDViewerDockWidget->setWidget(mpThreeDViewer);
}
return mpThreeDViewer;
}
#endif
/*!
* \brief MainWindow::isModelingPerspectiveActive
* Returns true if the Modeling perspective is active.
* \return
*/
bool MainWindow::isModelingPerspectiveActive()
{
return mpPerspectiveTabbar->currentIndex() == 1;
}
/*!
* \brief MainWindow::isPlottingPerspectiveActive
* Returns true if the Plotting perspective is active.
* \return
*/
bool MainWindow::isPlottingPerspectiveActive()
{
return mpPerspectiveTabbar->currentIndex() == 2;
}
/*!
* \brief MainWindow::isDebuggingPerspectiveActive
* Returns true if the Debugging perspective is active.
* \return
*/
bool MainWindow::isDebuggingPerspectiveActive()
{
return mpPerspectiveTabbar->currentIndex() == 3;
}
/*!
* \brief MainWindow::addRecentFile
* Adds the currently opened file to the recentFilesList settings.
* \param fileName
* \param encoding
*/
void MainWindow::addRecentFile(const QString &fileName, const QString &encoding)
{
QSettings *pSettings = Utilities::getApplicationSettings();
QList<QVariant> files = pSettings->value("recentFilesList/files").toList();
// remove the already present RecentFile instance from the list.
foreach (QVariant file, files)
{
RecentFile recentFile = qvariant_cast<RecentFile>(file);
QFileInfo file1(recentFile.fileName);
QFileInfo file2(fileName);
if (file1.absoluteFilePath().compare(file2.absoluteFilePath()) == 0)
files.removeOne(file);
}
RecentFile recentFile;
recentFile.fileName = fileName;
recentFile.encoding = encoding;
files.prepend(QVariant::fromValue(recentFile));
while (files.size() > MaxRecentFiles)
files.removeLast();
pSettings->setValue("recentFilesList/files", files);
updateRecentFileActions();
}
/*!
* \brief MainWindow::updateRecentFileActions
* Updates the actions of the recent files menu items.
*/
void MainWindow::updateRecentFileActions()
{
/* first set all recent files actions visibility to false. */
for (int i = 0; i < MaxRecentFiles; ++i)
mpRecentFileActions[i]->setVisible(false);
/* read the new recent files list */
QSettings *pSettings = Utilities::getApplicationSettings();
QList<QVariant> files = pSettings->value("recentFilesList/files").toList();
int numRecentFiles = qMin(files.size(), (int)MaxRecentFiles);
for (int i = 0; i < numRecentFiles; ++i)
{
RecentFile recentFile = qvariant_cast<RecentFile>(files[i]);
mpRecentFileActions[i]->setText(recentFile.fileName);
QStringList dataList;
dataList << recentFile.fileName << recentFile.encoding;
mpRecentFileActions[i]->setData(dataList);
mpRecentFileActions[i]->setVisible(true);
}
mpWelcomePageWidget->addRecentFilesListItems();
}
/*!
* \brief MainWindow::closeEvent
* Event triggered re-implemented method that closes the main window.
* Proposes the user to save the unsaved classes.
* Asks for quit depending on the settings value.
* \param event
*/
void MainWindow::closeEvent(QCloseEvent *event)
{
SaveChangesDialog *pSaveChangesDialog = new SaveChangesDialog(this);
if (pSaveChangesDialog->exec()) {
if (askForExit()) {
beforeClosingMainWindow();
event->accept();
} else {
event->ignore();
}
} else {
event->ignore();
}
}
/*!
* \brief MainWindow::askForExit
* Asks the user before exiting.
* \return
*/
int MainWindow::askForExit()
{
if (!OptionsDialog::instance()->getNotificationsPage()->getQuitApplicationCheckBox()->isChecked() && !isTestsuiteRunning()) {
NotificationsDialog *pNotificationsDialog = new NotificationsDialog(NotificationsDialog::QuitApplication, NotificationsDialog::QuestionIcon, this);
return pNotificationsDialog->exec();
}
return true;
}
/*!
* \brief MainWindow::beforeClosingMainWindow
* Called before closing the MainWindow
* Deletes the object.
* Saves the window state and geometry in the settings file.
*/
void MainWindow::beforeClosingMainWindow()
{
mpOMCProxy->quitOMC();
delete mpOMCProxy;
// delete the OMSProxy object
OMSProxy::destroy();
delete mpModelWidgetContainer;
if (mpSimulationDialog) {
delete mpSimulationDialog;
}
if (mpTLMCoSimulationDialog) {
delete mpTLMCoSimulationDialog;
}
if (mpOMSSimulationDialog) {
delete mpOMSSimulationDialog;
}
/* save the TransformationsWidget last window geometry and splitters state. */
QSettings *pSettings = Utilities::getApplicationSettings();
QHashIterator<QString, TransformationsWidget*> transformationsWidgets(mTransformationsWidgetHash);
if (mTransformationsWidgetHash.size() > 0) {
transformationsWidgets.toBack();
transformationsWidgets.previous();
TransformationsWidget *pTransformationsWidget = transformationsWidgets.value();
if (pTransformationsWidget) {
pSettings->beginGroup("transformationalDebugger");
pSettings->setValue("geometry", pTransformationsWidget->saveGeometry());
pSettings->setValue("variablesNestedHorizontalSplitter", pTransformationsWidget->getVariablesNestedHorizontalSplitter()->saveState());
pSettings->setValue("variablesNestedVerticalSplitter", pTransformationsWidget->getVariablesNestedVerticalSplitter()->saveState());
pSettings->setValue("variablesHorizontalSplitter", pTransformationsWidget->getVariablesHorizontalSplitter()->saveState());
pSettings->setValue("equationsNestedHorizontalSplitter", pTransformationsWidget->getEquationsNestedHorizontalSplitter()->saveState());
pSettings->setValue("equationsNestedVerticalSplitter", pTransformationsWidget->getEquationsNestedVerticalSplitter()->saveState());
pSettings->setValue("equationsHorizontalSplitter", pTransformationsWidget->getEquationsHorizontalSplitter()->saveState());
pSettings->setValue("transformationsVerticalSplitter", pTransformationsWidget->getTransformationsVerticalSplitter()->saveState());
pSettings->endGroup();
}
}
/* delete the TransformationsWidgets */
transformationsWidgets.toFront();
while (transformationsWidgets.hasNext()) {
transformationsWidgets.next();
TransformationsWidget *pTransformationsWidget = transformationsWidgets.value();
delete pTransformationsWidget;
}
mTransformationsWidgetHash.clear();
/* save stackframes list and locals columns width */
pSettings->beginGroup("algorithmicDebugger");
pSettings->setValue("stackFramesTreeState", mpStackFramesWidget->getStackFramesTreeWidget()->header()->saveState());
pSettings->setValue("breakPointsTreeState", mpBreakpointsWidget->getBreakpointsTreeView()->header()->saveState());
pSettings->setValue("localsTreeState", mpLocalsWidget->getLocalsTreeView()->header()->saveState());
pSettings->endGroup();
/* save OMEdit MainWindow geometry state */
pSettings->setValue("application/geometry", saveGeometry());
pSettings->setValue("application/windowState", saveState());
// save last Open Directory location
pSettings->setValue("lastOpenDirectory", StringHandler::getLastOpenDirectory());
// save the grid lines
pSettings->setValue("modeling/gridLines", mpShowGridLinesAction->isChecked());
// save the splitter state of welcome page
pSettings->setValue("welcomePage/splitterState", mpWelcomePageWidget->getSplitter()->saveState());
// Delete the FMU directories we created while importing
if (OptionsDialog::instance()->getFMIPage()->getDeleteFMUDirectoryAndModelCheckBox()->isChecked()) {
foreach (QString fmuDirectory, mFMUDirectoriesList) {
if (QDir().exists(fmuDirectory)) {
Utilities::removeDirectoryRecursivly(fmuDirectory);
}
}
mFMUDirectoriesList.clear();
}
// Delete the MOL directories
foreach (QString molDirectory, mMOLDirectoriesList) {
if (QDir().exists(molDirectory)) {
Utilities::removeDirectoryRecursivly(molDirectory);
}
}
mMOLDirectoriesList.clear();
delete pSettings;
// delete the OptionsDialog object
OptionsDialog::destroy();
// delete the MessagesWidget object
MessagesWidget::destroy();
// delete the GDBAdapter object
GDBAdapter::destroy();
// delete the GitCommands object
GitCommands::destroy();
// delete the searchwidget object to call the destructor, to cancel the search operation running on seperate thread
delete mpSearchWidget;
}
/*!
* \brief MainWindow::openDroppedFile
* Opens the dropped file.
* \param pMimeData
*/
void MainWindow::openDroppedFile(const QMimeData *pMimeData)
{
int progressValue = 0;
mpProgressBar->setRange(0, pMimeData->urls().size());
showProgressBar();
//retrieves the filenames of all the dragged files in list and opens the valid files.
foreach (QUrl fileUrl, pMimeData->urls()) {
QFileInfo fileInfo(fileUrl.toLocalFile());
// show file loading message
mpStatusBar->showMessage(QString(Helper::loading).append(": ").append(fileInfo.absoluteFilePath()));
mpProgressBar->setValue(++progressValue);
// check the file extension
QRegExp resultFilesRegExp("\\b(mat|plt|csv)\\b");
if (resultFilesRegExp.indexIn(fileInfo.suffix()) != -1) {
openResultFiles(QStringList(fileInfo.absoluteFilePath()));
} else {
mpLibraryWidget->openFile(fileInfo.absoluteFilePath(), Helper::utf8, false);
}
}
mpStatusBar->clearMessage();
hideProgressBar();
}
/*!
* \brief MainWindow::openResultFiles
* Opens the result file(s).
* \param fileNames
*/
void MainWindow::openResultFiles(QStringList fileNames)
{
foreach (QString fileName, fileNames) {
QFileInfo fileInfo(fileName);
QStringList list = mpOMCProxy->readSimulationResultVars(fileInfo.absoluteFilePath());
if (list.size() > 0) {
switchToPlottingPerspectiveSlot();
mpVariablesWidget->insertVariablesItemsToTree(fileInfo.fileName(), fileInfo.absoluteDir().absolutePath(), list, SimulationOptions());
}
}
}
void MainWindow::simulate(LibraryTreeItem *pLibraryTreeItem)
{
if (pLibraryTreeItem->getLibraryType() == LibraryTreeItem::Modelica) {
if (!mpSimulationDialog) {
mpSimulationDialog = new SimulationDialog(this);
}
/* if Modelica text is changed manually by user then validate it before saving. */
if (pLibraryTreeItem->getModelWidget()) {
if (!pLibraryTreeItem->getModelWidget()->validateText(&pLibraryTreeItem)) {
return;
}
}
mpSimulationDialog->directSimulate(pLibraryTreeItem, false, false, false);
} else if (pLibraryTreeItem->getLibraryType() == LibraryTreeItem::OMS) {
// get the top level LibraryTreeItem
LibraryTreeItem *pTopLevelLibraryTreeItem = mpLibraryWidget->getLibraryTreeModel()->getTopLevelLibraryTreeItem(pLibraryTreeItem);
if (pTopLevelLibraryTreeItem) {
if (!mpOMSSimulationDialog) {
mpOMSSimulationDialog = new OMSSimulationDialog(this);
}
mpOMSSimulationDialog->simulate(pTopLevelLibraryTreeItem);
}
}
}
void MainWindow::simulateWithTransformationalDebugger(LibraryTreeItem *pLibraryTreeItem)
{
if (!mpSimulationDialog) {
mpSimulationDialog = new SimulationDialog(this);
}
/* if Modelica text is changed manually by user then validate it before saving. */
if (pLibraryTreeItem->getModelWidget()) {
if (!pLibraryTreeItem->getModelWidget()->validateText(&pLibraryTreeItem)) {
return;
}
}
mpSimulationDialog->directSimulate(pLibraryTreeItem, true, false, false);
}
void MainWindow::simulateWithAlgorithmicDebugger(LibraryTreeItem *pLibraryTreeItem)
{
if (!mpSimulationDialog) {
mpSimulationDialog = new SimulationDialog(this);
}
/* if Modelica text is changed manually by user then validate it before saving. */
if (pLibraryTreeItem->getModelWidget()) {
if (!pLibraryTreeItem->getModelWidget()->validateText(&pLibraryTreeItem)) {
return;
}
}
mpSimulationDialog->directSimulate(pLibraryTreeItem, false, true, false);
}
#if !defined(WITHOUT_OSG)
void MainWindow::simulateWithAnimation(LibraryTreeItem *pLibraryTreeItem)
{
if (!mpSimulationDialog) {
mpSimulationDialog = new SimulationDialog(this);
}
/* if Modelica text is changed manually by user then validate it before saving. */
if (pLibraryTreeItem->getModelWidget()) {
if (!pLibraryTreeItem->getModelWidget()->validateText(&pLibraryTreeItem)) {
return;
}
}
mpSimulationDialog->directSimulate(pLibraryTreeItem, false, false, true);
}
#endif
void MainWindow::simulationSetup(LibraryTreeItem *pLibraryTreeItem)
{
if (pLibraryTreeItem->getLibraryType() == LibraryTreeItem::Modelica) {
if (!mpSimulationDialog) {
mpSimulationDialog = new SimulationDialog(this);
}
/* if Modelica text is changed manually by user then validate it before saving. */
if (pLibraryTreeItem->getModelWidget()) {
if (!pLibraryTreeItem->getModelWidget()->validateText(&pLibraryTreeItem)) {
return;
}
}
mpSimulationDialog->show(pLibraryTreeItem, false, SimulationOptions());
} else if (pLibraryTreeItem->getLibraryType() == LibraryTreeItem::OMS) {
// get the top level LibraryTreeItem
LibraryTreeItem *pTopLevelLibraryTreeItem = mpLibraryWidget->getLibraryTreeModel()->getTopLevelLibraryTreeItem(pLibraryTreeItem);
if (pTopLevelLibraryTreeItem) {
if (!mpOMSSimulationDialog) {
mpOMSSimulationDialog = new OMSSimulationDialog(this);
}
mpOMSSimulationDialog->exec(pTopLevelLibraryTreeItem->getNameStructure(), pLibraryTreeItem);
}
}
}
/*!
* \brief MainWindow::instantiateOMSModel
* Instantiates the OMSimulator model.
* \param pLibraryTreeItem
* \param checked
*/
void MainWindow::instantiateOMSModel(LibraryTreeItem *pLibraryTreeItem, bool checked)
{
// get the top level LibraryTreeItem
LibraryTreeItem *pTopLevelLibraryTreeItem = mpLibraryWidget->getLibraryTreeModel()->getTopLevelLibraryTreeItem(pLibraryTreeItem);
if (pTopLevelLibraryTreeItem) {
if (!pLibraryTreeItem->getModelWidget()) {
mpLibraryWidget->getLibraryTreeModel()->showModelWidget(pLibraryTreeItem, false);
}
ModelWidget *pModelWidget = pLibraryTreeItem->getModelWidget();
if (checked) {
if (OMSProxy::instance()->instantiate(pTopLevelLibraryTreeItem->getNameStructure())) {
pModelWidget->getUndoStack()->setEnabled(false);
pModelWidget->createOMSimulatorUndoCommand("Instantiate Model", false);
pModelWidget->getUndoStack()->setEnabled(true);
mpModelWidgetContainer->currentModelWidgetChanged(mpModelWidgetContainer->getCurrentMdiSubWindow());
} else {
mpOMSInstantiateModelAction->setChecked(false);
}
} else {
if (OMSProxy::instance()->terminate(pTopLevelLibraryTreeItem->getNameStructure())) {
pModelWidget->getUndoStack()->setEnabled(false);
pModelWidget->createOMSimulatorUndoCommand("Terminate Model", false);
pModelWidget->getUndoStack()->setEnabled(true);
mpModelWidgetContainer->currentModelWidgetChanged(mpModelWidgetContainer->getCurrentMdiSubWindow());
} else {
mpOMSInstantiateModelAction->setChecked(true);
}
}
}
}
/*!
* \brief MainWindow::simulateOMSModel
* Simulates the OMSimulator model.
* \param pLibraryTreeItem
*/
void MainWindow::simulateOMSModel(LibraryTreeItem *pLibraryTreeItem)
{
// get the top level LibraryTreeItem
LibraryTreeItem *pTopLevelLibraryTreeItem = mpLibraryWidget->getLibraryTreeModel()->getTopLevelLibraryTreeItem(pLibraryTreeItem);
if (pTopLevelLibraryTreeItem) {
if (!mpOMSSimulationDialog) {
mpOMSSimulationDialog = new OMSSimulationDialog(this);
}
mpOMSSimulationDialog->simulate(pTopLevelLibraryTreeItem);
}
}
void MainWindow::instantiateModel(LibraryTreeItem *pLibraryTreeItem)
{
/* if Modelica text is changed manually by user then validate it before saving. */
if (pLibraryTreeItem->getModelWidget()) {
if (!pLibraryTreeItem->getModelWidget()->validateText(&pLibraryTreeItem)) {
return;
}
}
// set the status message.
mpStatusBar->showMessage(QString(Helper::instantiateModel).append(" ").append(pLibraryTreeItem->getNameStructure()));
// show the progress bar
mpProgressBar->setRange(0, 0);
showProgressBar();
// check reset messages number before instantiating
if (OptionsDialog::instance()->getMessagesPage()->getResetMessagesNumberBeforeSimulationCheckBox()->isChecked()) {
MessagesWidget::instance()->resetMessagesNumber();
}
// check clear messages browser before instantiating
if (OptionsDialog::instance()->getMessagesPage()->getClearMessagesBrowserBeforeSimulationCheckBox()->isChecked()) {
MessagesWidget::instance()->clearMessages();
}
QString instantiateModelResult = mpOMCProxy->instantiateModel(pLibraryTreeItem->getNameStructure());
if (!instantiateModelResult.isEmpty()) {
MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica,
tr("Instantiation of %1 completed successfully.").arg(pLibraryTreeItem->getNameStructure()),
Helper::scriptingKind, Helper::notificationLevel));
QString windowTitle = QString(Helper::instantiateModel).append(" - ").append(pLibraryTreeItem->getNameStructure());
InformationDialog *pInformationDialog = new InformationDialog(windowTitle, instantiateModelResult, true, this);
pInformationDialog->show();
}
// hide progress bar
hideProgressBar();
// clear the status bar message
mpStatusBar->clearMessage();
}
void MainWindow::checkModel(LibraryTreeItem *pLibraryTreeItem)
{
/* if Modelica text is changed manually by user then validate it before saving. */
if (pLibraryTreeItem->getModelWidget()) {
if (!pLibraryTreeItem->getModelWidget()->validateText(&pLibraryTreeItem)) {
return;
}
}
// set the status message.
mpStatusBar->showMessage(QString(Helper::checkModel).append(" ").append(pLibraryTreeItem->getNameStructure()));
// show the progress bar
mpProgressBar->setRange(0, 0);
showProgressBar();
// check reset messages number before checking
if (OptionsDialog::instance()->getMessagesPage()->getResetMessagesNumberBeforeSimulationCheckBox()->isChecked()) {
MessagesWidget::instance()->resetMessagesNumber();
}
// check clear messages browser before checking
if (OptionsDialog::instance()->getMessagesPage()->getClearMessagesBrowserBeforeSimulationCheckBox()->isChecked()) {
MessagesWidget::instance()->clearMessages();
}
QString checkModelResult = mpOMCProxy->checkModel(pLibraryTreeItem->getNameStructure());
if (!checkModelResult.isEmpty()) {
MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica,
tr("Check of %1 completed successfully.").arg(pLibraryTreeItem->getNameStructure()),
Helper::scriptingKind, Helper::notificationLevel));
QString windowTitle = QString(Helper::checkModel).append(" - ").append(pLibraryTreeItem->getNameStructure());
InformationDialog *pInformationDialog = new InformationDialog(windowTitle, checkModelResult, false, this);
pInformationDialog->show();
}
// hide progress bar
hideProgressBar();
// clear the status bar message
mpStatusBar->clearMessage();
}
void MainWindow::checkAllModels(LibraryTreeItem *pLibraryTreeItem)
{
/* if Modelica text is changed manually by user then validate it before saving. */
if (pLibraryTreeItem->getModelWidget()) {
if (!pLibraryTreeItem->getModelWidget()->validateText(&pLibraryTreeItem)) {
return;
}
}
// set the status message.
mpStatusBar->showMessage(QString(Helper::checkModel).append(" ").append(pLibraryTreeItem->getNameStructure()));
// show the progress bar
mpProgressBar->setRange(0, 0);
showProgressBar();
QString checkAllModelsResult = mpOMCProxy->checkAllModelsRecursive(pLibraryTreeItem->getNameStructure());
if (!checkAllModelsResult.isEmpty()) {
MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, checkAllModelsResult, Helper::scriptingKind,
Helper::notificationLevel));
}
// hide progress bar
hideProgressBar();
// clear the status bar message
mpStatusBar->clearMessage();
}
void MainWindow::exportModelFMU(LibraryTreeItem *pLibraryTreeItem)
{
/* if Modelica text is changed manually by user then validate it before saving. */
if (pLibraryTreeItem->getModelWidget()) {
if (!pLibraryTreeItem->getModelWidget()->validateText(&pLibraryTreeItem)) {
return;
}
}
// set the status message.
mpStatusBar->showMessage(tr("Exporting model as FMU"));
// show the progress bar
mpProgressBar->setRange(0, 0);
showProgressBar();
// create a folder with model name to dump the files in it.
QString modelDirectoryPath = QString("%1/%2").arg(OptionsDialog::instance()->getGeneralSettingsPage()->getWorkingDirectory(), pLibraryTreeItem->getNameStructure());
if (!QDir().exists(modelDirectoryPath)) {
QDir().mkpath(modelDirectoryPath);
}
// set the folder as working directory
MainWindow::instance()->getOMCProxy()->changeDirectory(modelDirectoryPath);
// buildModelFMU parameters
QString version = OptionsDialog::instance()->getFMIPage()->getFMIExportVersion();
QString type = OptionsDialog::instance()->getFMIPage()->getFMIExportType();
QString FMUName = OptionsDialog::instance()->getFMIPage()->getFMUNameTextBox()->text();
QString newFmuName = pLibraryTreeItem->getWhereToMoveFMU();
QSettings *pSettings = Utilities::getApplicationSettings();
QList<QString> platforms;
if (!pSettings->contains("FMIExport/Platforms")) {
QComboBox *pLinkingComboBox = OptionsDialog::instance()->getFMIPage()->getLinkingComboBox();
platforms.append(pLinkingComboBox->itemData(pLinkingComboBox->currentIndex()).toString());
} else {
platforms = pSettings->value("FMIExport/Platforms").toStringList();
}
int index = platforms.indexOf("none");
if (index > -1) {
platforms.removeAt(index);
}
if (platforms.empty()) {
MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica,
GUIMessages::getMessage(GUIMessages::FMU_EMPTY_PLATFORMS).arg(Helper::toolsOptionsPath),
Helper::scriptingKind, Helper::warningLevel));
}
mpOMCProxy->setCommandLineOptions(QString("--fmiFilter=%1").arg(OptionsDialog::instance()->getFMIPage()->getModelDescriptionFiltersComboBox()->currentText()));
mpOMCProxy->setCommandLineOptions(QString("--fmiSources=%1").arg(OptionsDialog::instance()->getFMIPage()->getIncludeSourceCodeCheckBox()->isChecked() ? "true" : "false"));
QString fmuFileName = mpOMCProxy->buildModelFMU(pLibraryTreeItem->getNameStructure(), version, type, FMUName, platforms);
if (!fmuFileName.isEmpty()) { // FMU was generated
if (!newFmuName.isEmpty()) { // FMU should be moved
QDir newNameAsDir(newFmuName);
QString whereToMove;
if (newNameAsDir.exists()) {
whereToMove = newNameAsDir.filePath(pLibraryTreeItem->getNameStructure() + ".fmu");
} else {
whereToMove = newFmuName;
}
QFile(whereToMove).remove();
if (QFile(fmuFileName).rename(whereToMove)) {
fmuFileName = whereToMove;
} else {
MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica,
GUIMessages::getMessage(GUIMessages::FMU_MOVE_FAILED).arg(whereToMove),
Helper::scriptingKind, Helper::errorLevel));
}
}
MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica,
GUIMessages::getMessage(GUIMessages::FMU_GENERATED).arg(fmuFileName),
Helper::scriptingKind, Helper::notificationLevel));