Skip to content

Commit

Permalink
Added support for new fmi export flags --fmiFilter and --fmiSources
Browse files Browse the repository at this point in the history
Fixes ticket:3105 and ticket:5969
Added `--fmiFilter` options descriptions.
Change description of `--fmiFilter`.
Disable "Include Source Code" checkbox if filter is blackBox.
  • Loading branch information
adeas31 committed May 26, 2020
1 parent b7ab192 commit 2a7b500
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 6 deletions.
9 changes: 7 additions & 2 deletions OMCompiler/Compiler/Util/Flags.mo
Expand Up @@ -1355,8 +1355,13 @@ constant ConfigFlag FLAT_MODELICA = CONFIG_FLAG(141, "flatModelica",
Gettext.gettext("Outputs experimental flat Modelica."));
constant ConfigFlag FMI_FILTER = CONFIG_FLAG(142, "fmiFilter", NONE(), EXTERNAL(),
ENUM_FLAG(FMI_INTERNAL, {("none", FMI_NONE), ("internal", FMI_INTERNAL), ("protected", FMI_PROTECTED), ("blackBox", FMI_BLACKBOX)}),
SOME(STRING_OPTION({"none", "internal", "protected", "blackBox"})),
Gettext.gettext("Filters the FMI-ModelDescription Vars in the ModelDescription.xml"));
SOME(STRING_DESC_OPTION({
("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.")),
("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).")),
("protected", Gettext.gettext("All protected model variables will be filtered out in addition to --fmiFilter=internal.")),
("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."))
})),
Gettext.gettext("Specifies which model variables get exposed by the modelDescription.xml"));
constant ConfigFlag FMI_SOURCES = CONFIG_FLAG(143, "fmiSources", NONE(), EXTERNAL(),
BOOL_FLAG(true), NONE(),
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."));
Expand Down
5 changes: 3 additions & 2 deletions OMEdit/OMEditLIB/MainWindow.cpp
Expand Up @@ -926,8 +926,7 @@ void MainWindow::exportModelFMU(LibraryTreeItem *pLibraryTreeItem)
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());
QString modelDirectoryPath = QString("%1/%2").arg(OptionsDialog::instance()->getGeneralSettingsPage()->getWorkingDirectory(), pLibraryTreeItem->getNameStructure());
if (!QDir().exists(modelDirectoryPath)) {
QDir().mkpath(modelDirectoryPath);
}
Expand Down Expand Up @@ -955,6 +954,8 @@ void MainWindow::exportModelFMU(LibraryTreeItem *pLibraryTreeItem)
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
Expand Down
54 changes: 52 additions & 2 deletions OMEdit/OMEditLIB/Options/OptionsDialog.cpp
Expand Up @@ -896,6 +896,18 @@ void OptionsDialog::readFMISettings()
}
}
}
// read model description filter
if (mpSettings->contains("FMIExport/ModelDescriptionFilter")) {
int currentIndex = mpFMIPage->getModelDescriptionFiltersComboBox()->findText(mpSettings->value("FMIExport/ModelDescriptionFilter").toString());
if (currentIndex > -1) {
mpFMIPage->getModelDescriptionFiltersComboBox()->setCurrentIndex(currentIndex);
}
}
// read include source code
if (mpSettings->contains("FMIExport/IncludeSourceCode")) {
mpFMIPage->getIncludeSourceCodeCheckBox()->setChecked(mpSettings->value("FMIExport/IncludeSourceCode").toBool());
}
// read delete FMU directory
if (mpSettings->contains("FMIImport/DeleteFMUDirectoyAndModel")) {
mpFMIPage->getDeleteFMUDirectoryAndModelCheckBox()->setChecked(mpSettings->value("FMIImport/DeleteFMUDirectoyAndModel").toBool());
}
Expand Down Expand Up @@ -1453,6 +1465,8 @@ void OptionsDialog::saveFMISettings()
i++;
}
mpSettings->setValue("FMIExport/Platforms", platforms);
mpSettings->setValue("FMIExport/ModelDescriptionFilter", mpFMIPage->getModelDescriptionFiltersComboBox()->currentText());
mpSettings->setValue("FMIExport/IncludeSourceCode", mpFMIPage->getIncludeSourceCodeCheckBox()->isChecked());
mpSettings->setValue("FMIImport/DeleteFMUDirectoyAndModel", mpFMIPage->getDeleteFMUDirectoryAndModelCheckBox()->isChecked());
}

Expand Down Expand Up @@ -4833,6 +4847,22 @@ FMIPage::FMIPage(OptionsDialog *pOptionsDialog)
pPlatformsLayout->addWidget(pCheckBox);
}
mpPlatformsGroupBox->setLayout(pPlatformsLayout);
// Model description filters
OMCInterface::getConfigFlagValidOptions_res fmiFilters = MainWindow::instance()->getOMCProxy()->getConfigFlagValidOptions("fmiFilter");
mpModelDescriptionFiltersComboBox = new QComboBox;
mpModelDescriptionFiltersComboBox->addItems(fmiFilters.validOptions);
mpModelDescriptionFiltersComboBox->setToolTip(fmiFilters.mainDescription);
int i = 0;
foreach (QString description, fmiFilters.descriptions) {
mpModelDescriptionFiltersComboBox->setItemData(i, description, Qt::ToolTipRole);
i++;
}
mpModelDescriptionFiltersComboBox->setCurrentIndex(mpModelDescriptionFiltersComboBox->findText("internal"));
connect(mpModelDescriptionFiltersComboBox, SIGNAL(currentIndexChanged(QString)), SLOT(enableIncludeSourcesCheckBox(QString)));
// include source code checkbox
mpIncludeSourceCodeCheckBox = new QCheckBox(tr("Include Source Code (model description filter \"blackBox\" will override this, because black box FMUs do never contain their source code.)"));
mpIncludeSourceCodeCheckBox->setChecked(true);
enableIncludeSourcesCheckBox(mpModelDescriptionFiltersComboBox->currentText());
// set the export group box layout
QGridLayout *pExportLayout = new QGridLayout;
pExportLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
Expand All @@ -4844,6 +4874,9 @@ FMIPage::FMIPage(OptionsDialog *pOptionsDialog)
pExportLayout->addWidget(mpMoveFMUTextBox, 3, 1);
pExportLayout->addWidget(mpBrowseFMUDirectoryButton, 3, 2);
pExportLayout->addWidget(mpPlatformsGroupBox, 4, 0, 1, 3);
pExportLayout->addWidget(new Label(tr("Model Description Filters:")), 5, 0);
pExportLayout->addWidget(mpModelDescriptionFiltersComboBox, 5, 1);
pExportLayout->addWidget(mpIncludeSourceCodeCheckBox, 6, 0, 1, 3);
mpExportGroupBox->setLayout(pExportLayout);
// import groupbox
mpImportGroupBox = new QGroupBox(tr("Import"));
Expand Down Expand Up @@ -4926,10 +4959,27 @@ QString FMIPage::getFMIExportType()
}
}

/*!
* \brief FMIPage::selectFMUDirectory
* Selects the FMU directory.
*/
void FMIPage::selectFMUDirectory()
{
mpMoveFMUTextBox->setText(StringHandler::getExistingDirectory(this, QString("%1 - %2").arg(Helper::applicationName)
.arg(Helper::chooseDirectory), NULL));
mpMoveFMUTextBox->setText(StringHandler::getExistingDirectory(this, QString("%1 - %2").arg(Helper::applicationName).arg(Helper::chooseDirectory), NULL));
}

/*!
* \brief FMIPage::enableIncludeSourcesCheckBox
* Enables/Disables the includes sources checkbox.
* \param modelDescriptionFilter
*/
void FMIPage::enableIncludeSourcesCheckBox(QString modelDescriptionFilter)
{
if (modelDescriptionFilter.compare(QStringLiteral("blackBox")) == 0) {
mpIncludeSourceCodeCheckBox->setEnabled(false);
} else {
mpIncludeSourceCodeCheckBox->setEnabled(true);
}
}

/*!
Expand Down
5 changes: 5 additions & 0 deletions OMEdit/OMEditLIB/Options/OptionsDialog.h
Expand Up @@ -915,6 +915,8 @@ class FMIPage : public QWidget
QLineEdit* getMoveFMUTextBox() {return mpMoveFMUTextBox;}
QGroupBox* getPlatformsGroupBox() {return mpPlatformsGroupBox;}
QComboBox* getLinkingComboBox() {return mpLinkingComboBox;}
QComboBox *getModelDescriptionFiltersComboBox() const {return mpModelDescriptionFiltersComboBox;}
QCheckBox *getIncludeSourceCodeCheckBox() const {return mpIncludeSourceCodeCheckBox;}
QCheckBox* getDeleteFMUDirectoryAndModelCheckBox() {return mpDeleteFMUDirectoryAndModelCheckBox;}

static const QString FMU_FULL_CLASS_NAME_DOTS_PLACEHOLDER;
Expand All @@ -937,10 +939,13 @@ class FMIPage : public QWidget
QPushButton *mpBrowseFMUDirectoryButton;
QGroupBox *mpPlatformsGroupBox;
QComboBox *mpLinkingComboBox;
QComboBox *mpModelDescriptionFiltersComboBox;
QCheckBox *mpIncludeSourceCodeCheckBox;
QGroupBox *mpImportGroupBox;
QCheckBox *mpDeleteFMUDirectoryAndModelCheckBox;
public slots:
void selectFMUDirectory();
void enableIncludeSourcesCheckBox(QString modelDescriptionFilter);
};

class TLMPage : public QWidget
Expand Down

0 comments on commit 2a7b500

Please sign in to comment.