Skip to content

Commit

Permalink
Fix for #3576. Allow exporting different types of FMUs.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Dec 4, 2015
1 parent f87a8a8 commit 80fb4da
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 24 deletions.
3 changes: 2 additions & 1 deletion OMEdit/OMEditGUI/MainWindow.cpp
Expand Up @@ -837,8 +837,9 @@ void MainWindow::exportModelFMU(LibraryTreeItem *pLibraryTreeItem)
mpProgressBar->setRange(0, 0);
showProgressBar();
double version = mpOptionsDialog->getFMIPage()->getFMIExportVersion();
QString type = mpOptionsDialog->getFMIPage()->getFMIExportType();
QString FMUName = mpOptionsDialog->getFMIPage()->getFMUNameTextBox()->text();
if (mpOMCProxy->translateModelFMU(pLibraryTreeItem->getNameStructure(), version, FMUName)) {
if (mpOMCProxy->translateModelFMU(pLibraryTreeItem->getNameStructure(), version, type, FMUName)) {
mpMessagesWidget->addGUIMessage(MessageItem(MessageItem::Modelica, "", false, 0, 0, 0, 0, GUIMessages::getMessage(GUIMessages::FMU_GENERATED)
.arg(FMUName.isEmpty() ? pLibraryTreeItem->getNameStructure() : FMUName)
.arg(mpOMCProxy->changeDirectory()), Helper::scriptingKind,
Expand Down
16 changes: 10 additions & 6 deletions OMEdit/OMEditGUI/OMC/OMCProxy.cpp
Expand Up @@ -2008,15 +2008,19 @@ QStringList OMCProxy::getSimulationOptions(QString className, double defaultTole
}

/*!
Creates the FMU of the model.
\param className - the name of the class.
\return the created FMU location
*/
bool OMCProxy::translateModelFMU(QString className, double version, QString fileNamePrefix)
* \brief OMCProxy::translateModelFMU
* Creates the FMU of the model.
* \param className - the name of the class.
* \param version - the fmu version
* \param type - the fmu type
* \param fileNamePrefix
* \return
*/
bool OMCProxy::translateModelFMU(QString className, double version, QString type, QString fileNamePrefix)
{
bool result = false;
fileNamePrefix = fileNamePrefix.isEmpty() ? "<default>" : fileNamePrefix;
QString res = mpOMCInterface->translateModelFMU(className, QString::number(version), "me", fileNamePrefix);
QString res = mpOMCInterface->translateModelFMU(className, QString::number(version), type, fileNamePrefix);
if (res.compare("SimCode: The model " + className + " has been translated to FMU") == 0) {
result = true;
mpMainWindow->getLibraryWidget()->getLibraryTreeModel()->loadDependentLibraries(getClassNames());
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/OMC/OMCProxy.h
Expand Up @@ -195,7 +195,7 @@ class OMCProxy : public QObject
QString checkAllModelsRecursive(QString className);
bool isExperiment(QString className);
QStringList getSimulationOptions(QString className, double defaultTolerance = 1e-4);
bool translateModelFMU(QString className, double version, QString fileNamePrefix);
bool translateModelFMU(QString className, double version, QString type, QString fileNamePrefix);
bool translateModelXML(QString className);
QString importFMU(QString fmuName, QString outputDirectory, int logLevel, bool debugLogging, bool generateInputConnectors, bool generateOutputConnectors);
QString getMatchingAlgorithm();
Expand Down
89 changes: 75 additions & 14 deletions OMEdit/OMEditGUI/Options/OptionsDialog.cpp
Expand Up @@ -516,6 +516,9 @@ void OptionsDialog::readFMISettings()
if (mpSettings->contains("FMIExport/Version")) {
mpFMIPage->setFMIExportVersion(mpSettings->value("FMIExport/Version").toDouble());
}
if (mpSettings->contains("FMIExport/Type")) {
mpFMIPage->setFMIExportType(mpSettings->value("FMIExport/Type").toString());
}
if (mpSettings->contains("FMI/FMUName")) {
mpFMIPage->getFMUNameTextBox()->setText(mpSettings->value("FMI/FMUName").toString());
}
Expand Down Expand Up @@ -855,6 +858,7 @@ void OptionsDialog::saveDebuggerSettings()
void OptionsDialog::saveFMISettings()
{
mpSettings->setValue("FMIExport/Version", mpFMIPage->getFMIExportVersion());
mpSettings->setValue("FMIExport/Type", mpFMIPage->getFMIExportType());
mpSettings->setValue("FMI/FMUName", mpFMIPage->getFMUNameTextBox()->text());
}

Expand Down Expand Up @@ -1453,7 +1457,7 @@ LibrariesPage::LibrariesPage(OptionsDialog *pOptionsDialog)
mpSystemLibrariesTree->setColumnCount(2);
mpSystemLibrariesTree->setTextElideMode(Qt::ElideMiddle);
QStringList systemLabels;
systemLabels << tr("Name") << tr("Version");
systemLabels << tr("Name") << Helper::version;
mpSystemLibrariesTree->setHeaderLabels(systemLabels);
connect(mpSystemLibrariesTree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), SLOT(openEditSystemLibrary()));
// system libraries buttons
Expand Down Expand Up @@ -1631,7 +1635,7 @@ AddSystemLibraryDialog::AddSystemLibraryDialog(LibrariesPage *pLibrariesPage)
mpNameComboBox->addItem(key,key);
}

mpValueLabel = new Label(Helper::version);
mpValueLabel = new Label(Helper::version + ":");
mpVersionTextBox = new QLineEdit("default");
mpOkButton = new QPushButton(Helper::ok);
connect(mpOkButton, SIGNAL(clicked()), SLOT(addSystemLibrary()));
Expand Down Expand Up @@ -3361,38 +3365,53 @@ void DebuggerPage::browseGDBPath()
}

/*!
\class DebuggerPage
\brief Creates an interface for debugger settings.
*/
* \class DebuggerPage
* \brief Creates an interface for debugger settings.
*/
/*!
\param pParent - pointer to OptionsDialog
*/
* \brief FMIPage::FMIPage
* \param pParent - pointer to OptionsDialog
*/
FMIPage::FMIPage(OptionsDialog *pOptionsDialog)
: QWidget(pOptionsDialog)
{
mpOptionsDialog = pOptionsDialog;
mpExportGroupBox = new QGroupBox(tr("Export"));
// FMI export version
mpVersionLabel = new Label(Helper::version);
mpVersionGroupBox = new QGroupBox(Helper::version);
mpVersion1RadioButton = new QRadioButton("1.0");
mpVersion2RadioButton = new QRadioButton("2.0");
mpVersion2RadioButton->setChecked(true);
// set the version group box layout
QHBoxLayout *pVersionLayout = new QHBoxLayout;
// set the version groupbox layout
QVBoxLayout *pVersionLayout = new QVBoxLayout;
pVersionLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
pVersionLayout->addWidget(mpVersion1RadioButton);
pVersionLayout->addWidget(mpVersion2RadioButton);
mpVersionGroupBox->setLayout(pVersionLayout);
// FMI export type
mpTypeGroupBox = new QGroupBox(Helper::type);
mpModelExchangeRadioButton = new QRadioButton(tr("Model Exchange"));
mpCoSimulationRadioButton = new QRadioButton(tr("Co-Simulation"));
mpModelExchangeCoSimulationRadioButton = new QRadioButton(tr("Model Exchange and Co-Simulation"));
mpModelExchangeCoSimulationRadioButton->setChecked(true);
// set the type groupbox layout
QVBoxLayout *pTypeLayout = new QVBoxLayout;
pTypeLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
pTypeLayout->addWidget(mpModelExchangeRadioButton);
pTypeLayout->addWidget(mpCoSimulationRadioButton);
pTypeLayout->addWidget(mpModelExchangeCoSimulationRadioButton);
mpTypeGroupBox->setLayout(pTypeLayout);
// FMU name prefix
mpFMUNameLabel = new Label(tr("FMU Name:"));
mpFMUNameTextBox = new QLineEdit;
mpFMUNameTextBox->setPlaceholderText("<default>");
// set the export group box layout
QGridLayout *pExportLayout = new QGridLayout;
pExportLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
pExportLayout->addWidget(mpVersionLabel, 0, 0);
pExportLayout->addLayout(pVersionLayout, 0, 1);
pExportLayout->addWidget(mpFMUNameLabel, 1, 0);
pExportLayout->addWidget(mpFMUNameTextBox, 1, 1);
pExportLayout->addWidget(mpVersionGroupBox, 0, 0, 1, 2);
pExportLayout->addWidget(mpTypeGroupBox, 1, 0, 1, 2);
pExportLayout->addWidget(mpFMUNameLabel, 2, 0);
pExportLayout->addWidget(mpFMUNameTextBox, 2, 1);
mpExportGroupBox->setLayout(pExportLayout);
// set the layout
QVBoxLayout *pMainLayout = new QVBoxLayout;
Expand All @@ -3402,6 +3421,11 @@ FMIPage::FMIPage(OptionsDialog *pOptionsDialog)
setLayout(pMainLayout);
}

/*!
* \brief FMIPage::setFMIExportVersion
* Sets the FMI export version
* \param version
*/
void FMIPage::setFMIExportVersion(double version)
{
if (version == 1.0) {
Expand All @@ -3411,6 +3435,11 @@ void FMIPage::setFMIExportVersion(double version)
}
}

/*!
* \brief FMIPage::getFMIExportVersion
* Gets the FMI export version
* \return
*/
double FMIPage::getFMIExportVersion()
{
if (mpVersion1RadioButton->isChecked()) {
Expand All @@ -3420,6 +3449,38 @@ double FMIPage::getFMIExportVersion()
}
}

/*!
* \brief FMIPage::setFMIExportType
* Sets the FMI export type
* \param type
*/
void FMIPage::setFMIExportType(QString type)
{
if (type.compare("me") == 0) {
mpModelExchangeRadioButton->setChecked(true);
} else if (type.compare("cs") == 0) {
mpCoSimulationRadioButton->setChecked(true);
} else {
mpModelExchangeCoSimulationRadioButton->setChecked(true);
}
}

/*!
* \brief FMIPage::getFMIExportType
* Gets the FMI export type
* \return
*/
QString FMIPage::getFMIExportType()
{
if (mpModelExchangeRadioButton->isChecked()) {
return "me";
} else if (mpCoSimulationRadioButton->isChecked()) {
return "cs";
} else {
return "me_cs";
}
}

/*!
* \class TLMPage
* Creates an interface for TLM settings.
Expand Down
7 changes: 6 additions & 1 deletion OMEdit/OMEditGUI/Options/OptionsDialog.h
Expand Up @@ -695,14 +695,19 @@ class FMIPage : public QWidget
FMIPage(OptionsDialog *pOptionsDialog);
void setFMIExportVersion(double version);
double getFMIExportVersion();
void setFMIExportType(QString type);
QString getFMIExportType();
QLineEdit* getFMUNameTextBox() {return mpFMUNameTextBox;}
private:
OptionsDialog *mpOptionsDialog;
QGroupBox *mpExportGroupBox;
Label *mpVersionLabel;
QGroupBox *mpVersionGroupBox;
QRadioButton *mpVersion1RadioButton;
QRadioButton *mpVersion2RadioButton;
QGroupBox *mpTypeGroupBox;
QRadioButton *mpModelExchangeRadioButton;
QRadioButton *mpCoSimulationRadioButton;
QRadioButton *mpModelExchangeCoSimulationRadioButton;
Label *mpFMUNameLabel;
QLineEdit *mpFMUNameTextBox;
};
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Util/Helper.cpp
Expand Up @@ -475,7 +475,7 @@ void Helper::initHelperVariables()
Helper::parsingFailedJson = tr("Parsing of JSON file failed");
Helper::expandAll = tr("Expand All");
Helper::collapseAll = tr("Collapse All");
Helper::version = tr("Version:");
Helper::version = tr("Version");
Helper::unlimited = tr("unlimited");
Helper::simulationOutput = tr("Simulation Output");
Helper::cancelSimulation = tr("Cancel Simulation");
Expand Down

0 comments on commit 80fb4da

Please sign in to comment.