Skip to content

Commit 405ec94

Browse files
committed
Fix for #3576. Allow exporting different types of FMUs.
1 parent 53f5b7b commit 405ec94

File tree

6 files changed

+95
-24
lines changed

6 files changed

+95
-24
lines changed

OMEdit/OMEditGUI/MainWindow.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,8 +837,9 @@ void MainWindow::exportModelFMU(LibraryTreeItem *pLibraryTreeItem)
837837
mpProgressBar->setRange(0, 0);
838838
showProgressBar();
839839
double version = mpOptionsDialog->getFMIPage()->getFMIExportVersion();
840+
QString type = mpOptionsDialog->getFMIPage()->getFMIExportType();
840841
QString FMUName = mpOptionsDialog->getFMIPage()->getFMUNameTextBox()->text();
841-
if (mpOMCProxy->translateModelFMU(pLibraryTreeItem->getNameStructure(), version, FMUName)) {
842+
if (mpOMCProxy->translateModelFMU(pLibraryTreeItem->getNameStructure(), version, type, FMUName)) {
842843
mpMessagesWidget->addGUIMessage(MessageItem(MessageItem::Modelica, "", false, 0, 0, 0, 0, GUIMessages::getMessage(GUIMessages::FMU_GENERATED)
843844
.arg(FMUName.isEmpty() ? pLibraryTreeItem->getNameStructure() : FMUName)
844845
.arg(mpOMCProxy->changeDirectory()), Helper::scriptingKind,

OMEdit/OMEditGUI/OMC/OMCProxy.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,15 +2008,19 @@ QStringList OMCProxy::getSimulationOptions(QString className, double defaultTole
20082008
}
20092009

20102010
/*!
2011-
Creates the FMU of the model.
2012-
\param className - the name of the class.
2013-
\return the created FMU location
2014-
*/
2015-
bool OMCProxy::translateModelFMU(QString className, double version, QString fileNamePrefix)
2011+
* \brief OMCProxy::translateModelFMU
2012+
* Creates the FMU of the model.
2013+
* \param className - the name of the class.
2014+
* \param version - the fmu version
2015+
* \param type - the fmu type
2016+
* \param fileNamePrefix
2017+
* \return
2018+
*/
2019+
bool OMCProxy::translateModelFMU(QString className, double version, QString type, QString fileNamePrefix)
20162020
{
20172021
bool result = false;
20182022
fileNamePrefix = fileNamePrefix.isEmpty() ? "<default>" : fileNamePrefix;
2019-
QString res = mpOMCInterface->translateModelFMU(className, QString::number(version), "me", fileNamePrefix);
2023+
QString res = mpOMCInterface->translateModelFMU(className, QString::number(version), type, fileNamePrefix);
20202024
if (res.compare("SimCode: The model " + className + " has been translated to FMU") == 0) {
20212025
result = true;
20222026
mpMainWindow->getLibraryWidget()->getLibraryTreeModel()->loadDependentLibraries(getClassNames());

OMEdit/OMEditGUI/OMC/OMCProxy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class OMCProxy : public QObject
195195
QString checkAllModelsRecursive(QString className);
196196
bool isExperiment(QString className);
197197
QStringList getSimulationOptions(QString className, double defaultTolerance = 1e-4);
198-
bool translateModelFMU(QString className, double version, QString fileNamePrefix);
198+
bool translateModelFMU(QString className, double version, QString type, QString fileNamePrefix);
199199
bool translateModelXML(QString className);
200200
QString importFMU(QString fmuName, QString outputDirectory, int logLevel, bool debugLogging, bool generateInputConnectors, bool generateOutputConnectors);
201201
QString getMatchingAlgorithm();

OMEdit/OMEditGUI/Options/OptionsDialog.cpp

Lines changed: 75 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,9 @@ void OptionsDialog::readFMISettings()
516516
if (mpSettings->contains("FMIExport/Version")) {
517517
mpFMIPage->setFMIExportVersion(mpSettings->value("FMIExport/Version").toDouble());
518518
}
519+
if (mpSettings->contains("FMIExport/Type")) {
520+
mpFMIPage->setFMIExportType(mpSettings->value("FMIExport/Type").toString());
521+
}
519522
if (mpSettings->contains("FMI/FMUName")) {
520523
mpFMIPage->getFMUNameTextBox()->setText(mpSettings->value("FMI/FMUName").toString());
521524
}
@@ -855,6 +858,7 @@ void OptionsDialog::saveDebuggerSettings()
855858
void OptionsDialog::saveFMISettings()
856859
{
857860
mpSettings->setValue("FMIExport/Version", mpFMIPage->getFMIExportVersion());
861+
mpSettings->setValue("FMIExport/Type", mpFMIPage->getFMIExportType());
858862
mpSettings->setValue("FMI/FMUName", mpFMIPage->getFMUNameTextBox()->text());
859863
}
860864

@@ -1453,7 +1457,7 @@ LibrariesPage::LibrariesPage(OptionsDialog *pOptionsDialog)
14531457
mpSystemLibrariesTree->setColumnCount(2);
14541458
mpSystemLibrariesTree->setTextElideMode(Qt::ElideMiddle);
14551459
QStringList systemLabels;
1456-
systemLabels << tr("Name") << tr("Version");
1460+
systemLabels << tr("Name") << Helper::version;
14571461
mpSystemLibrariesTree->setHeaderLabels(systemLabels);
14581462
connect(mpSystemLibrariesTree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), SLOT(openEditSystemLibrary()));
14591463
// system libraries buttons
@@ -1631,7 +1635,7 @@ AddSystemLibraryDialog::AddSystemLibraryDialog(LibrariesPage *pLibrariesPage)
16311635
mpNameComboBox->addItem(key,key);
16321636
}
16331637

1634-
mpValueLabel = new Label(Helper::version);
1638+
mpValueLabel = new Label(Helper::version + ":");
16351639
mpVersionTextBox = new QLineEdit("default");
16361640
mpOkButton = new QPushButton(Helper::ok);
16371641
connect(mpOkButton, SIGNAL(clicked()), SLOT(addSystemLibrary()));
@@ -3361,38 +3365,53 @@ void DebuggerPage::browseGDBPath()
33613365
}
33623366

33633367
/*!
3364-
\class DebuggerPage
3365-
\brief Creates an interface for debugger settings.
3366-
*/
3368+
* \class DebuggerPage
3369+
* \brief Creates an interface for debugger settings.
3370+
*/
33673371
/*!
3368-
\param pParent - pointer to OptionsDialog
3369-
*/
3372+
* \brief FMIPage::FMIPage
3373+
* \param pParent - pointer to OptionsDialog
3374+
*/
33703375
FMIPage::FMIPage(OptionsDialog *pOptionsDialog)
33713376
: QWidget(pOptionsDialog)
33723377
{
33733378
mpOptionsDialog = pOptionsDialog;
33743379
mpExportGroupBox = new QGroupBox(tr("Export"));
33753380
// FMI export version
3376-
mpVersionLabel = new Label(Helper::version);
3381+
mpVersionGroupBox = new QGroupBox(Helper::version);
33773382
mpVersion1RadioButton = new QRadioButton("1.0");
33783383
mpVersion2RadioButton = new QRadioButton("2.0");
33793384
mpVersion2RadioButton->setChecked(true);
3380-
// set the version group box layout
3381-
QHBoxLayout *pVersionLayout = new QHBoxLayout;
3385+
// set the version groupbox layout
3386+
QVBoxLayout *pVersionLayout = new QVBoxLayout;
33823387
pVersionLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
33833388
pVersionLayout->addWidget(mpVersion1RadioButton);
33843389
pVersionLayout->addWidget(mpVersion2RadioButton);
3390+
mpVersionGroupBox->setLayout(pVersionLayout);
3391+
// FMI export type
3392+
mpTypeGroupBox = new QGroupBox(Helper::type);
3393+
mpModelExchangeRadioButton = new QRadioButton(tr("Model Exchange"));
3394+
mpCoSimulationRadioButton = new QRadioButton(tr("Co-Simulation"));
3395+
mpModelExchangeCoSimulationRadioButton = new QRadioButton(tr("Model Exchange and Co-Simulation"));
3396+
mpModelExchangeCoSimulationRadioButton->setChecked(true);
3397+
// set the type groupbox layout
3398+
QVBoxLayout *pTypeLayout = new QVBoxLayout;
3399+
pTypeLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
3400+
pTypeLayout->addWidget(mpModelExchangeRadioButton);
3401+
pTypeLayout->addWidget(mpCoSimulationRadioButton);
3402+
pTypeLayout->addWidget(mpModelExchangeCoSimulationRadioButton);
3403+
mpTypeGroupBox->setLayout(pTypeLayout);
33853404
// FMU name prefix
33863405
mpFMUNameLabel = new Label(tr("FMU Name:"));
33873406
mpFMUNameTextBox = new QLineEdit;
33883407
mpFMUNameTextBox->setPlaceholderText("<default>");
33893408
// set the export group box layout
33903409
QGridLayout *pExportLayout = new QGridLayout;
33913410
pExportLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
3392-
pExportLayout->addWidget(mpVersionLabel, 0, 0);
3393-
pExportLayout->addLayout(pVersionLayout, 0, 1);
3394-
pExportLayout->addWidget(mpFMUNameLabel, 1, 0);
3395-
pExportLayout->addWidget(mpFMUNameTextBox, 1, 1);
3411+
pExportLayout->addWidget(mpVersionGroupBox, 0, 0, 1, 2);
3412+
pExportLayout->addWidget(mpTypeGroupBox, 1, 0, 1, 2);
3413+
pExportLayout->addWidget(mpFMUNameLabel, 2, 0);
3414+
pExportLayout->addWidget(mpFMUNameTextBox, 2, 1);
33963415
mpExportGroupBox->setLayout(pExportLayout);
33973416
// set the layout
33983417
QVBoxLayout *pMainLayout = new QVBoxLayout;
@@ -3402,6 +3421,11 @@ FMIPage::FMIPage(OptionsDialog *pOptionsDialog)
34023421
setLayout(pMainLayout);
34033422
}
34043423

3424+
/*!
3425+
* \brief FMIPage::setFMIExportVersion
3426+
* Sets the FMI export version
3427+
* \param version
3428+
*/
34053429
void FMIPage::setFMIExportVersion(double version)
34063430
{
34073431
if (version == 1.0) {
@@ -3411,6 +3435,11 @@ void FMIPage::setFMIExportVersion(double version)
34113435
}
34123436
}
34133437

3438+
/*!
3439+
* \brief FMIPage::getFMIExportVersion
3440+
* Gets the FMI export version
3441+
* \return
3442+
*/
34143443
double FMIPage::getFMIExportVersion()
34153444
{
34163445
if (mpVersion1RadioButton->isChecked()) {
@@ -3420,6 +3449,38 @@ double FMIPage::getFMIExportVersion()
34203449
}
34213450
}
34223451

3452+
/*!
3453+
* \brief FMIPage::setFMIExportType
3454+
* Sets the FMI export type
3455+
* \param type
3456+
*/
3457+
void FMIPage::setFMIExportType(QString type)
3458+
{
3459+
if (type.compare("me") == 0) {
3460+
mpModelExchangeRadioButton->setChecked(true);
3461+
} else if (type.compare("cs") == 0) {
3462+
mpCoSimulationRadioButton->setChecked(true);
3463+
} else {
3464+
mpModelExchangeCoSimulationRadioButton->setChecked(true);
3465+
}
3466+
}
3467+
3468+
/*!
3469+
* \brief FMIPage::getFMIExportType
3470+
* Gets the FMI export type
3471+
* \return
3472+
*/
3473+
QString FMIPage::getFMIExportType()
3474+
{
3475+
if (mpModelExchangeRadioButton->isChecked()) {
3476+
return "me";
3477+
} else if (mpCoSimulationRadioButton->isChecked()) {
3478+
return "cs";
3479+
} else {
3480+
return "me_cs";
3481+
}
3482+
}
3483+
34233484
/*!
34243485
* \class TLMPage
34253486
* Creates an interface for TLM settings.

OMEdit/OMEditGUI/Options/OptionsDialog.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,14 +695,19 @@ class FMIPage : public QWidget
695695
FMIPage(OptionsDialog *pOptionsDialog);
696696
void setFMIExportVersion(double version);
697697
double getFMIExportVersion();
698+
void setFMIExportType(QString type);
699+
QString getFMIExportType();
698700
QLineEdit* getFMUNameTextBox() {return mpFMUNameTextBox;}
699701
private:
700702
OptionsDialog *mpOptionsDialog;
701703
QGroupBox *mpExportGroupBox;
702-
Label *mpVersionLabel;
703704
QGroupBox *mpVersionGroupBox;
704705
QRadioButton *mpVersion1RadioButton;
705706
QRadioButton *mpVersion2RadioButton;
707+
QGroupBox *mpTypeGroupBox;
708+
QRadioButton *mpModelExchangeRadioButton;
709+
QRadioButton *mpCoSimulationRadioButton;
710+
QRadioButton *mpModelExchangeCoSimulationRadioButton;
706711
Label *mpFMUNameLabel;
707712
QLineEdit *mpFMUNameTextBox;
708713
};

OMEdit/OMEditGUI/Util/Helper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ void Helper::initHelperVariables()
475475
Helper::parsingFailedJson = tr("Parsing of JSON file failed");
476476
Helper::expandAll = tr("Expand All");
477477
Helper::collapseAll = tr("Collapse All");
478-
Helper::version = tr("Version:");
478+
Helper::version = tr("Version");
479479
Helper::unlimited = tr("unlimited");
480480
Helper::simulationOutput = tr("Simulation Output");
481481
Helper::cancelSimulation = tr("Cancel Simulation");

0 commit comments

Comments
 (0)