Skip to content

Commit

Permalink
Import FMU modelDescription xml
Browse files Browse the repository at this point in the history
  • Loading branch information
alash325 committed Nov 16, 2016
1 parent c5bf117 commit b3e955c
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 2 deletions.
85 changes: 85 additions & 0 deletions OMEdit/OMEditGUI/FMI/ImportFMUModelDescriptionDialog.cpp
@@ -0,0 +1,85 @@
#include "ImportFMUModelDescriptionDialog.h"


/*!
\class ImportFMUModelDescriptionDialog
\brief Creates an interface for importing FMU model description.
*/

/*!
\param pParent - pointer to MainWindow
*/
ImportFMUModelDescriptionDialog::ImportFMUModelDescriptionDialog(MainWindow *pParent)
: QDialog(pParent)
{
setWindowTitle(QString(Helper::applicationName).append(" - ").append(tr("Import FMU Model Description")));
setAttribute(Qt::WA_DeleteOnClose);
setMinimumWidth(550);
// set parent widget
mpMainWindow = pParent;
// create FMU File selection controls
mpFmuModelDescriptionLabel = new Label(tr("FMU Model Description:"));
mpFmuModelDescriptionTextBox = new QLineEdit;
mpBrowseFileButton = new QPushButton(Helper::browse);
mpBrowseFileButton->setAutoDefault(false);
connect(mpBrowseFileButton, SIGNAL(clicked()), SLOT(setSelectedFile()));
// create Output Directory selection controls
mpOutputDirectoryLabel = new Label(tr("Output Directory:"));
mpOutputDirectoryTextBox = new QLineEdit;
mpBrowseDirectoryButton = new QPushButton(Helper::browse);
mpBrowseDirectoryButton->setAutoDefault(false);
connect(mpBrowseDirectoryButton, SIGNAL(clicked()), SLOT(setSelectedDirectory()));
// create OK button
mpImportButton = new QPushButton(Helper::ok);
mpImportButton->setAutoDefault(true);
connect(mpImportButton, SIGNAL(clicked()), SLOT(importFMUModelDescription()));
// set grid layout
QGridLayout *pMainLayout = new QGridLayout;
pMainLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
pMainLayout->addWidget(mpFmuModelDescriptionLabel, 0, 0);
pMainLayout->addWidget(mpFmuModelDescriptionTextBox, 0, 1);
pMainLayout->addWidget(mpBrowseFileButton, 0, 2);
pMainLayout->addWidget(mpOutputDirectoryLabel, 1, 0);
pMainLayout->addWidget(mpOutputDirectoryTextBox, 1, 1);
pMainLayout->addWidget(mpBrowseDirectoryButton, 1, 2);
pMainLayout->addWidget(mpImportButton, 2, 0, 1, 3, Qt::AlignRight);
setLayout(pMainLayout);
}

/*!
Slot activated when mpBrowseFileButton clicked signal is raised.\n
Allows the user to select the FMU model description.
*/
void ImportFMUModelDescriptionDialog::setSelectedFile()
{
mpFmuModelDescriptionTextBox->setText(StringHandler::getOpenFileName(this, QString(Helper::applicationName).append(" - ").append(Helper::chooseFile),
NULL, Helper::xmlFileTypes, NULL));
}

/*!
Slot activated when mpBrowseDirectoryButton clicked signal is raised.\n
Allows the user to select the output directory for FMU models with input and output.
*/
void ImportFMUModelDescriptionDialog::setSelectedDirectory()
{
mpOutputDirectoryTextBox->setText(StringHandler::getExistingDirectory(this, QString(Helper::applicationName).append(" - ").append(Helper::chooseDirectory), NULL));
}

/*!
Slot activated when mpImportButton clicked signal is raised.\n
Sends the importFMUModelDescription command to OMC.
*/
void ImportFMUModelDescriptionDialog::importFMUModelDescription()
{
if (mpFmuModelDescriptionTextBox->text().isEmpty())
{
QMessageBox::critical(this, QString(Helper::applicationName).append(" - ").append(Helper::error),
GUIMessages::getMessage(GUIMessages::ENTER_NAME).arg(tr("FMU Model Description")), Helper::ok);
return;
}
QString fmuFileName = mpMainWindow->getOMCProxy()->importFMUModelDescription(mpFmuModelDescriptionTextBox->text(), mpOutputDirectoryTextBox->text(), 1, false, true, true);

if (!fmuFileName.isEmpty())
mpMainWindow->getLibraryWidget()->openFile(fmuFileName);
accept();
}
28 changes: 28 additions & 0 deletions OMEdit/OMEditGUI/FMI/ImportFMUModelDescriptionDialog.h
@@ -0,0 +1,28 @@
#ifndef IMPORTFMUMODELDESCRIPTIONDIALOG_H
#define IMPORTFMUMODELDESCRIPTIONDIALOG_H

#include "MainWindow.h"

class MainWindow;

class ImportFMUModelDescriptionDialog : public QDialog
{
Q_OBJECT
public:
ImportFMUModelDescriptionDialog(MainWindow *pParent = 0);
private:
MainWindow *mpMainWindow;
Label *mpFmuModelDescriptionLabel;
QLineEdit *mpFmuModelDescriptionTextBox;
QPushButton *mpBrowseFileButton;
Label *mpOutputDirectoryLabel;
QLineEdit *mpOutputDirectoryTextBox;
QPushButton *mpBrowseDirectoryButton;
QPushButton *mpImportButton;
private slots:
void setSelectedFile();
void setSelectedDirectory();
void importFMUModelDescription();
};

#endif // IMPORTFMUMODELDESCRIPTIONDIALOG_H
12 changes: 12 additions & 0 deletions OMEdit/OMEditGUI/MainWindow.cpp
Expand Up @@ -1722,6 +1722,13 @@ void MainWindow::importModelFMU()
pImportFMUDialog->exec();
}

//! Imports the model from FMU model description
void MainWindow::importFMUModelDescription()
{
ImportFMUModelDescriptionDialog *pImportFMUModelDescriptionDialog = new ImportFMUModelDescriptionDialog(this);
pImportFMUModelDescriptionDialog->exec();
}

//! Exports the current model to OMNotebook.
//! Creates a new onb file and add the model text and model image in it.
//! @see importModelfromOMNotebook();
Expand Down Expand Up @@ -2531,6 +2538,10 @@ void MainWindow::createActions()
mpImportFMUAction = new QAction(QIcon(":/Resources/icons/import-fmu.svg"), Helper::importFMU, this);
mpImportFMUAction->setStatusTip(Helper::importFMUTip);
connect(mpImportFMUAction, SIGNAL(triggered()), SLOT(importModelFMU()));
// import FMU model description action
mpImportFMUModelDescriptionAction = new QAction(tr("Import FMU Model Description"), this);
mpImportFMUModelDescriptionAction->setStatusTip(Helper::importFMUTip);
connect(mpImportFMUModelDescriptionAction, SIGNAL(triggered()), SLOT(importFMUModelDescription()));
// XML Menu
// export XML action
mpExportXMLAction = new QAction(QIcon(":/Resources/icons/export-xml.svg"), Helper::exportXML, this);
Expand Down Expand Up @@ -2868,6 +2879,7 @@ void MainWindow::createMenus()
// add actions to FMI menu
pFMIMenu->addAction(mpExportFMUAction);
pFMIMenu->addAction(mpImportFMUAction);
pFMIMenu->addAction(mpImportFMUModelDescriptionAction);
// add FMI menu to menu bar
menuBar()->addAction(pFMIMenu->menuAction());
// Export menu
Expand Down
3 changes: 3 additions & 0 deletions OMEdit/OMEditGUI/MainWindow.h
Expand Up @@ -77,6 +77,7 @@
#include "StackFramesWidget.h"
#include "LocalsWidget.h"
#include "ImportFMUDialog.h"
#include "ImportFMUModelDescriptionDialog.h"
#include "NotificationsDialog.h"

class OMCProxy;
Expand Down Expand Up @@ -307,6 +308,7 @@ class MainWindow : public QMainWindow
// FMI Menu
QAction *mpExportFMUAction;
QAction *mpImportFMUAction;
QAction *mpImportFMUModelDescriptionAction;
// Export Menu
QAction *mpExportXMLAction;
QAction *mpExportFigaroAction;
Expand Down Expand Up @@ -417,6 +419,7 @@ public slots:
void openSimulationDialog();
void exportModelFMU();
void importModelFMU();
void importFMUModelDescription();
void exportModelXML();
void exportModelFigaro();
void showOpenModelicaCommandPrompt();
Expand Down
21 changes: 21 additions & 0 deletions OMEdit/OMEditGUI/OMC/OMCProxy.cpp
Expand Up @@ -2107,6 +2107,27 @@ QString OMCProxy::importFMU(QString fmuName, QString outputDirectory, int logLev
return fmuFileName;
}

/*!
* \brief OMCProxy::importFMUModelDescription
* Imports the FMU model description xml
* \param fmuModelDescriptionName - the modelDescription xml location
* \param outputDirectory - the output location
* \param logLevel - the logging level
* \param debugLogging - enables the debug logging for the imported FMU.
* \param generateInputConnectors - generates the input variables as connectors
* \param generateOutputConnectors - generates the output variables as connectors.
* \return generated Modelica Code file path
*/
QString OMCProxy::importFMUModelDescription(QString fmuModelDescriptionName, QString outputDirectory, int logLevel, bool debugLogging, bool generateInputConnectors,
bool generateOutputConnectors)
{
outputDirectory = outputDirectory.isEmpty() ? "<default>" : outputDirectory;
QString fmuFileName = mpOMCInterface->importFMUModelDescription(fmuModelDescriptionName, outputDirectory, logLevel, true, debugLogging, generateInputConnectors,
generateOutputConnectors);
printMessagesStringInternal();
return fmuFileName;
}

/*!
Reads the matching algorithm used during the simulation.
\return the name of the matching algorithm
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/OMC/OMCProxy.h
Expand Up @@ -197,6 +197,7 @@ class OMCProxy : public QObject
bool buildModelFMU(QString className, double version, QString type, QString fileNamePrefix, QList<QString> platforms);
bool translateModelXML(QString className);
QString importFMU(QString fmuName, QString outputDirectory, int logLevel, bool debugLogging, bool generateInputConnectors, bool generateOutputConnectors);
QString importFMUModelDescription(QString fmuModelDescriptionName, QString outputDirectory, int logLevel, bool debugLogging, bool generateInputConnectors, bool generateOutputConnectors);
QString getMatchingAlgorithm();
OMCInterface::getAvailableMatchingAlgorithms_res getAvailableMatchingAlgorithms();
bool setMatchingAlgorithm(QString matchingAlgorithm);
Expand Down
6 changes: 4 additions & 2 deletions OMEdit/OMEditGUI/OMEditGUI.pro
Expand Up @@ -170,7 +170,8 @@ SOURCES += main.cpp \
Debugger/Attach/AttachToProcessDialog.cpp \
Debugger/Attach/ProcessListModel.cpp \
CrashReport/backtrace.c \
CrashReport/CrashReportDialog.cpp
CrashReport/CrashReportDialog.cpp \
FMI/ImportFMUModelDescriptionDialog.cpp

HEADERS += Util/Helper.h \
Util/Utilities.h \
Expand Down Expand Up @@ -235,7 +236,8 @@ HEADERS += Util/Helper.h \
Debugger/Attach/AttachToProcessDialog.h \
Debugger/Attach/ProcessListModel.h \
CrashReport/backtrace.h \
CrashReport/CrashReportDialog.h
CrashReport/CrashReportDialog.h \
FMI/ImportFMUModelDescriptionDialog.h

CONFIG(osg) {

Expand Down

0 comments on commit b3e955c

Please sign in to comment.