Skip to content

Commit 2a7b500

Browse files
committed
Added support for new fmi export flags --fmiFilter and --fmiSources
Fixes ticket:3105 and ticket:5969 Added `--fmiFilter` options descriptions. Change description of `--fmiFilter`. Disable "Include Source Code" checkbox if filter is blackBox.
1 parent b7ab192 commit 2a7b500

File tree

4 files changed

+67
-6
lines changed

4 files changed

+67
-6
lines changed

OMCompiler/Compiler/Util/Flags.mo

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,8 +1355,13 @@ constant ConfigFlag FLAT_MODELICA = CONFIG_FLAG(141, "flatModelica",
13551355
Gettext.gettext("Outputs experimental flat Modelica."));
13561356
constant ConfigFlag FMI_FILTER = CONFIG_FLAG(142, "fmiFilter", NONE(), EXTERNAL(),
13571357
ENUM_FLAG(FMI_INTERNAL, {("none", FMI_NONE), ("internal", FMI_INTERNAL), ("protected", FMI_PROTECTED), ("blackBox", FMI_BLACKBOX)}),
1358-
SOME(STRING_OPTION({"none", "internal", "protected", "blackBox"})),
1359-
Gettext.gettext("Filters the FMI-ModelDescription Vars in the ModelDescription.xml"));
1358+
SOME(STRING_DESC_OPTION({
1359+
("none", Gettext.gettext("All variables will be exposed, even variables that are introduced by the symbolic transformations. Hence, this is intended to be used for debugging.")),
1360+
("internal", Gettext.gettext("All internal variables introduced by the symbolic transformations are filtered out. Only the variables from the actual Modelica model are exposed (with minor exceptions, e.g. for state sets).")),
1361+
("protected", Gettext.gettext("All protected model variables will be filtered out in addition to --fmiFilter=internal.")),
1362+
("blackBox", Gettext.gettext("This option is used to hide everything except for inputs and outputs. Additional variables that need to be present in the modelDescription file for structrial reasons will have concealed names."))
1363+
})),
1364+
Gettext.gettext("Specifies which model variables get exposed by the modelDescription.xml"));
13601365
constant ConfigFlag FMI_SOURCES = CONFIG_FLAG(143, "fmiSources", NONE(), EXTERNAL(),
13611366
BOOL_FLAG(true), NONE(),
13621367
Gettext.gettext("Defines if FMUs will be exported with sources or not. --fmiFilter=blackBox might override this, because black box FMUs do never contain their source code."));

OMEdit/OMEditLIB/MainWindow.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -926,8 +926,7 @@ void MainWindow::exportModelFMU(LibraryTreeItem *pLibraryTreeItem)
926926
mpProgressBar->setRange(0, 0);
927927
showProgressBar();
928928
// create a folder with model name to dump the files in it.
929-
QString modelDirectoryPath = QString("%1/%2").arg(OptionsDialog::instance()->getGeneralSettingsPage()->getWorkingDirectory(),
930-
pLibraryTreeItem->getNameStructure());
929+
QString modelDirectoryPath = QString("%1/%2").arg(OptionsDialog::instance()->getGeneralSettingsPage()->getWorkingDirectory(), pLibraryTreeItem->getNameStructure());
931930
if (!QDir().exists(modelDirectoryPath)) {
932931
QDir().mkpath(modelDirectoryPath);
933932
}
@@ -955,6 +954,8 @@ void MainWindow::exportModelFMU(LibraryTreeItem *pLibraryTreeItem)
955954
GUIMessages::getMessage(GUIMessages::FMU_EMPTY_PLATFORMS).arg(Helper::toolsOptionsPath),
956955
Helper::scriptingKind, Helper::warningLevel));
957956
}
957+
mpOMCProxy->setCommandLineOptions(QString("--fmiFilter=%1").arg(OptionsDialog::instance()->getFMIPage()->getModelDescriptionFiltersComboBox()->currentText()));
958+
mpOMCProxy->setCommandLineOptions(QString("--fmiSources=%1").arg(OptionsDialog::instance()->getFMIPage()->getIncludeSourceCodeCheckBox()->isChecked() ? "true" : "false"));
958959
QString fmuFileName = mpOMCProxy->buildModelFMU(pLibraryTreeItem->getNameStructure(), version, type, FMUName, platforms);
959960
if (!fmuFileName.isEmpty()) { // FMU was generated
960961
if (!newFmuName.isEmpty()) { // FMU should be moved

OMEdit/OMEditLIB/Options/OptionsDialog.cpp

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,18 @@ void OptionsDialog::readFMISettings()
896896
}
897897
}
898898
}
899+
// read model description filter
900+
if (mpSettings->contains("FMIExport/ModelDescriptionFilter")) {
901+
int currentIndex = mpFMIPage->getModelDescriptionFiltersComboBox()->findText(mpSettings->value("FMIExport/ModelDescriptionFilter").toString());
902+
if (currentIndex > -1) {
903+
mpFMIPage->getModelDescriptionFiltersComboBox()->setCurrentIndex(currentIndex);
904+
}
905+
}
906+
// read include source code
907+
if (mpSettings->contains("FMIExport/IncludeSourceCode")) {
908+
mpFMIPage->getIncludeSourceCodeCheckBox()->setChecked(mpSettings->value("FMIExport/IncludeSourceCode").toBool());
909+
}
910+
// read delete FMU directory
899911
if (mpSettings->contains("FMIImport/DeleteFMUDirectoyAndModel")) {
900912
mpFMIPage->getDeleteFMUDirectoryAndModelCheckBox()->setChecked(mpSettings->value("FMIImport/DeleteFMUDirectoyAndModel").toBool());
901913
}
@@ -1453,6 +1465,8 @@ void OptionsDialog::saveFMISettings()
14531465
i++;
14541466
}
14551467
mpSettings->setValue("FMIExport/Platforms", platforms);
1468+
mpSettings->setValue("FMIExport/ModelDescriptionFilter", mpFMIPage->getModelDescriptionFiltersComboBox()->currentText());
1469+
mpSettings->setValue("FMIExport/IncludeSourceCode", mpFMIPage->getIncludeSourceCodeCheckBox()->isChecked());
14561470
mpSettings->setValue("FMIImport/DeleteFMUDirectoyAndModel", mpFMIPage->getDeleteFMUDirectoryAndModelCheckBox()->isChecked());
14571471
}
14581472

@@ -4833,6 +4847,22 @@ FMIPage::FMIPage(OptionsDialog *pOptionsDialog)
48334847
pPlatformsLayout->addWidget(pCheckBox);
48344848
}
48354849
mpPlatformsGroupBox->setLayout(pPlatformsLayout);
4850+
// Model description filters
4851+
OMCInterface::getConfigFlagValidOptions_res fmiFilters = MainWindow::instance()->getOMCProxy()->getConfigFlagValidOptions("fmiFilter");
4852+
mpModelDescriptionFiltersComboBox = new QComboBox;
4853+
mpModelDescriptionFiltersComboBox->addItems(fmiFilters.validOptions);
4854+
mpModelDescriptionFiltersComboBox->setToolTip(fmiFilters.mainDescription);
4855+
int i = 0;
4856+
foreach (QString description, fmiFilters.descriptions) {
4857+
mpModelDescriptionFiltersComboBox->setItemData(i, description, Qt::ToolTipRole);
4858+
i++;
4859+
}
4860+
mpModelDescriptionFiltersComboBox->setCurrentIndex(mpModelDescriptionFiltersComboBox->findText("internal"));
4861+
connect(mpModelDescriptionFiltersComboBox, SIGNAL(currentIndexChanged(QString)), SLOT(enableIncludeSourcesCheckBox(QString)));
4862+
// include source code checkbox
4863+
mpIncludeSourceCodeCheckBox = new QCheckBox(tr("Include Source Code (model description filter \"blackBox\" will override this, because black box FMUs do never contain their source code.)"));
4864+
mpIncludeSourceCodeCheckBox->setChecked(true);
4865+
enableIncludeSourcesCheckBox(mpModelDescriptionFiltersComboBox->currentText());
48364866
// set the export group box layout
48374867
QGridLayout *pExportLayout = new QGridLayout;
48384868
pExportLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
@@ -4844,6 +4874,9 @@ FMIPage::FMIPage(OptionsDialog *pOptionsDialog)
48444874
pExportLayout->addWidget(mpMoveFMUTextBox, 3, 1);
48454875
pExportLayout->addWidget(mpBrowseFMUDirectoryButton, 3, 2);
48464876
pExportLayout->addWidget(mpPlatformsGroupBox, 4, 0, 1, 3);
4877+
pExportLayout->addWidget(new Label(tr("Model Description Filters:")), 5, 0);
4878+
pExportLayout->addWidget(mpModelDescriptionFiltersComboBox, 5, 1);
4879+
pExportLayout->addWidget(mpIncludeSourceCodeCheckBox, 6, 0, 1, 3);
48474880
mpExportGroupBox->setLayout(pExportLayout);
48484881
// import groupbox
48494882
mpImportGroupBox = new QGroupBox(tr("Import"));
@@ -4926,10 +4959,27 @@ QString FMIPage::getFMIExportType()
49264959
}
49274960
}
49284961

4962+
/*!
4963+
* \brief FMIPage::selectFMUDirectory
4964+
* Selects the FMU directory.
4965+
*/
49294966
void FMIPage::selectFMUDirectory()
49304967
{
4931-
mpMoveFMUTextBox->setText(StringHandler::getExistingDirectory(this, QString("%1 - %2").arg(Helper::applicationName)
4932-
.arg(Helper::chooseDirectory), NULL));
4968+
mpMoveFMUTextBox->setText(StringHandler::getExistingDirectory(this, QString("%1 - %2").arg(Helper::applicationName).arg(Helper::chooseDirectory), NULL));
4969+
}
4970+
4971+
/*!
4972+
* \brief FMIPage::enableIncludeSourcesCheckBox
4973+
* Enables/Disables the includes sources checkbox.
4974+
* \param modelDescriptionFilter
4975+
*/
4976+
void FMIPage::enableIncludeSourcesCheckBox(QString modelDescriptionFilter)
4977+
{
4978+
if (modelDescriptionFilter.compare(QStringLiteral("blackBox")) == 0) {
4979+
mpIncludeSourceCodeCheckBox->setEnabled(false);
4980+
} else {
4981+
mpIncludeSourceCodeCheckBox->setEnabled(true);
4982+
}
49334983
}
49344984

49354985
/*!

OMEdit/OMEditLIB/Options/OptionsDialog.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,8 @@ class FMIPage : public QWidget
915915
QLineEdit* getMoveFMUTextBox() {return mpMoveFMUTextBox;}
916916
QGroupBox* getPlatformsGroupBox() {return mpPlatformsGroupBox;}
917917
QComboBox* getLinkingComboBox() {return mpLinkingComboBox;}
918+
QComboBox *getModelDescriptionFiltersComboBox() const {return mpModelDescriptionFiltersComboBox;}
919+
QCheckBox *getIncludeSourceCodeCheckBox() const {return mpIncludeSourceCodeCheckBox;}
918920
QCheckBox* getDeleteFMUDirectoryAndModelCheckBox() {return mpDeleteFMUDirectoryAndModelCheckBox;}
919921

920922
static const QString FMU_FULL_CLASS_NAME_DOTS_PLACEHOLDER;
@@ -937,10 +939,13 @@ class FMIPage : public QWidget
937939
QPushButton *mpBrowseFMUDirectoryButton;
938940
QGroupBox *mpPlatformsGroupBox;
939941
QComboBox *mpLinkingComboBox;
942+
QComboBox *mpModelDescriptionFiltersComboBox;
943+
QCheckBox *mpIncludeSourceCodeCheckBox;
940944
QGroupBox *mpImportGroupBox;
941945
QCheckBox *mpDeleteFMUDirectoryAndModelCheckBox;
942946
public slots:
943947
void selectFMUDirectory();
948+
void enableIncludeSourcesCheckBox(QString modelDescriptionFilter);
944949
};
945950

946951
class TLMPage : public QWidget

0 commit comments

Comments
 (0)