Skip to content

Commit

Permalink
Fetch interface data for TLM co-simulation.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Jun 5, 2015
1 parent 0fa0c95 commit 1c72bdb
Show file tree
Hide file tree
Showing 10 changed files with 262 additions and 23 deletions.
124 changes: 107 additions & 17 deletions OMEdit/OMEditGUI/MainWindow.cpp
Expand Up @@ -908,6 +908,46 @@ void MainWindow::exportModelFigaro(LibraryTreeNode *pLibraryTreeNode)
pExportFigaroDialog->exec();
}

/*!
* \brief MainWindow::fetchInterfaceData
* \param pLibraryTreeNode
* Fetches the interface data for TLM co-simulation.
*/
void MainWindow::fetchInterfaceData(LibraryTreeNode *pLibraryTreeNode)
{
if (mpOptionsDialog->getTLMPage()->getTLMManagerProcessTextBox()->text().isEmpty()) {
QString message;
#ifdef Q_OS_MAC
message = GUIMessages::getMessage(GUIMessages::TLMMANAGER_NOT_SET).arg(GUIMessages::getMessage(GUIMessages::TLMMANAGER_NOT_SET_MSG_MAC));
#else
message = GUIMessages::getMessage(GUIMessages::TLMMANAGER_NOT_SET).arg(GUIMessages::getMessage(GUIMessages::TLMMANAGER_NOT_SET_MSG));
#endif
QMessageBox::information(this, QString(Helper::applicationName).append(" - ").append(Helper::information), message, Helper::ok);
} else {
if (pLibraryTreeNode->isSaved()) {
fetchInterfaceDataHelper(pLibraryTreeNode);
} else {
QMessageBox *pMessageBox = new QMessageBox(this);
pMessageBox->setWindowTitle(QString(Helper::applicationName).append(" - ").append(Helper::question));
pMessageBox->setIcon(QMessageBox::Question);
pMessageBox->setText(GUIMessages::getMessage(GUIMessages::METAMODEL_UNSAVED).arg(pLibraryTreeNode->getNameStructure()));
pMessageBox->setStandardButtons(QMessageBox::Yes | QMessageBox::No);
pMessageBox->setDefaultButton(QMessageBox::Yes);
int answer = pMessageBox->exec();
switch (answer) {
case QMessageBox::Yes:
if (mpLibraryTreeWidget->saveLibraryTreeNode(pLibraryTreeNode)) {
fetchInterfaceDataHelper(pLibraryTreeNode);
}
break;
case QMessageBox::No:
default:
break;
}
}
}
}

/*!
* \brief MainWindow::TLMSimulate
* \param pLibraryTreeNode
Expand All @@ -921,7 +961,7 @@ void MainWindow::TLMSimulate(LibraryTreeNode *pLibraryTreeNode)
QMessageBox *pMessageBox = new QMessageBox(this);
pMessageBox->setWindowTitle(QString(Helper::applicationName).append(" - ").append(Helper::question));
pMessageBox->setIcon(QMessageBox::Question);
pMessageBox->setText(tr("Meta model <b>%1</b> has unsaved changes. Do you want to save?").arg(pLibraryTreeNode->getNameStructure()));
pMessageBox->setText(GUIMessages::getMessage(GUIMessages::METAMODEL_UNSAVED).arg(pLibraryTreeNode->getNameStructure()));
pMessageBox->setStandardButtons(QMessageBox::Yes | QMessageBox::No);
pMessageBox->setDefaultButton(QMessageBox::Yes);
int answer = pMessageBox->exec();
Expand Down Expand Up @@ -1248,9 +1288,9 @@ void MainWindow::showOpenTransformationFileDialog()

/*!
Creates a new TLM LibraryTreeNode & ModelWidget.\n
Slot activated when mpNewTLMFileAction triggered signal is raised.
Slot activated when mpNewMetaModelFileAction triggered signal is raised.
*/
void MainWindow::createNewTLMFile()
void MainWindow::createNewMetaModelFile()
{
QString metaModelName = mpLibraryTreeWidget->getUniqueLibraryTreeNodeName("MetaModel");
LibraryTreeNode *pLibraryTreeNode = mpLibraryTreeWidget->addLibraryTreeNode(LibraryTreeNode::TLM, metaModelName, false);
Expand All @@ -1263,9 +1303,9 @@ void MainWindow::createNewTLMFile()

/*!
Opens the TLM file(s).\n
Slot activated when mpOpenTLMFileAction triggered signal is raised.
Slot activated when mpOpenMetaModelFileAction triggered signal is raised.
*/
void MainWindow::openTLMFile()
void MainWindow::openMetaModelFile()
{
QStringList fileNames;
fileNames = StringHandler::getOpenFileNames(this, QString(Helper::applicationName).append(" - ").append(Helper::chooseFiles), NULL,
Expand Down Expand Up @@ -1926,9 +1966,27 @@ void MainWindow::exportToClipboard()
}

/*!
Slot activated when mpTLMSimulateAction triggered signal is raised.\n
Calls the function that starts the TLM simulation.
*/
* \brief MainWindow::fetchInterfaceData
* Slot activated when mpFetchInterfaceDataAction triggered signal is raised.
* Calls the function that fetches the interface data.
*/
void MainWindow::fetchInterfaceData()
{
ModelWidget *pModelWidget = mpModelWidgetContainer->getCurrentModelWidget();
if (pModelWidget)
{
LibraryTreeNode *pLibraryTreeNode = pModelWidget->getLibraryTreeNode();
if (pLibraryTreeNode) {
fetchInterfaceData(pLibraryTreeNode);
}
}
}

/*!
* \brief MainWindow::TLMSimulate
* Slot activated when mpTLMSimulateAction triggered signal is raised.
* Calls the function that starts the TLM simulation.
*/
void MainWindow::TLMSimulate()
{
ModelWidget *pModelWidget = mpModelWidgetContainer->getCurrentModelWidget();
Expand Down Expand Up @@ -2225,14 +2283,14 @@ void MainWindow::createActions()
mpOpenTransformationFileAction = new QAction(tr("Open Transformations File"), this);
mpOpenTransformationFileAction->setStatusTip(tr("Opens the class transformations file"));
connect(mpOpenTransformationFileAction, SIGNAL(triggered()), SLOT(showOpenTransformationFileDialog()));
// create new TLM file action
mpNewTLMFileAction = new QAction(QIcon(":/Resources/icons/new.svg"), tr("New TLM File"), this);
mpNewTLMFileAction->setStatusTip(tr("Create New TLM File"));
connect(mpNewTLMFileAction, SIGNAL(triggered()), SLOT(createNewTLMFile()));
// create new MetaModel action
mpNewMetaModelFileAction = new QAction(QIcon(":/Resources/icons/new.svg"), tr("New MetaModel"), this);
mpNewMetaModelFileAction->setStatusTip(tr("Create New MetaModel File"));
connect(mpNewMetaModelFileAction, SIGNAL(triggered()), SLOT(createNewMetaModelFile()));
// open TLM file action
mpOpenTLMFileAction = new QAction(QIcon(":/Resources/icons/open.svg"), tr("Open TLM File"), this);
mpOpenTLMFileAction->setStatusTip(tr("Opens the TLM file(s)"));
connect(mpOpenTLMFileAction, SIGNAL(triggered()), SLOT(openTLMFile()));
mpOpenMetaModelFileAction = new QAction(QIcon(":/Resources/icons/open.svg"), tr("Open MetaModel"), this);
mpOpenMetaModelFileAction->setStatusTip(tr("Opens the MetaModel file(s)"));
connect(mpOpenMetaModelFileAction, SIGNAL(triggered()), SLOT(openMetaModelFile()));
// load External Model action
mpLoadExternModelAction = new QAction(tr("Load External Model(s)"), this);
mpLoadExternModelAction->setStatusTip(tr("Loads the External Model(s) for the TLM meta-modeling"));
Expand Down Expand Up @@ -2527,6 +2585,10 @@ void MainWindow::createActions()
mpExportToClipboardAction->setStatusTip(Helper::exportAsImageTip);
mpExportToClipboardAction->setEnabled(false);
connect(mpExportToClipboardAction, SIGNAL(triggered()), SLOT(exportToClipboard()));
// fetch interface data
mpFetchInterfaceDataAction = new QAction(QIcon(":/Resources/icons/interface-data.svg"), Helper::fetchInterfaceData, this);
mpFetchInterfaceDataAction->setStatusTip(Helper::fetchInterfaceDataTip);
connect(mpFetchInterfaceDataAction, SIGNAL(triggered()), SLOT(fetchInterfaceData()));
// TLM simulate actions
mpTLMCoSimulationAction = new QAction(QIcon(":/Resources/icons/tlm-simulate.svg"), Helper::tlmCoSimulationSetup, this);
mpTLMCoSimulationAction->setStatusTip(Helper::tlmCoSimulationSetupTip);
Expand All @@ -2551,8 +2613,8 @@ void MainWindow::createMenus()
pFileMenu->addAction(mpOpenResultFileAction);
pFileMenu->addAction(mpOpenTransformationFileAction);
pFileMenu->addSeparator();
pFileMenu->addAction(mpNewTLMFileAction);
pFileMenu->addAction(mpOpenTLMFileAction);
pFileMenu->addAction(mpNewMetaModelFileAction);
pFileMenu->addAction(mpOpenMetaModelFileAction);
pFileMenu->addAction(mpLoadExternModelAction);
pFileMenu->addSeparator();
pFileMenu->addAction(mpSaveAction);
Expand Down Expand Up @@ -2829,6 +2891,33 @@ void MainWindow::tileSubWindows(QMdiArea *pMdiArea, bool horizontally)
}
}

/*!
* \brief MainWindow::fetchInterfaceDataHelper
* \param pLibraryTreeNode
* Helper function for fetching the interface data.
*/
void MainWindow::fetchInterfaceDataHelper(LibraryTreeNode *pLibraryTreeNode)
{
QProcess *pManagerProcess = new QProcess;
QFileInfo fileInfo(pLibraryTreeNode->getFileName());
pManagerProcess->setWorkingDirectory(fileInfo.absoluteDir().absolutePath());
QStringList args;
args << "-r" << fileInfo.absoluteFilePath();
QProcessEnvironment environment;
#ifdef WIN32
environment = StringHandler::simulationProcessEnvironment();
#else
environment = QProcessEnvironment::systemEnvironment();
#endif
environment.insert("PATH", mpOptionsDialog->getTLMPage()->getTLMPluginPathTextBox()->text() + ";" + environment.value("PATH"));
environment.insert("TLMPluginPath", mpOptionsDialog->getTLMPage()->getTLMPluginPathTextBox()->text());
pManagerProcess->setProcessEnvironment(environment);
pManagerProcess->start(mpOptionsDialog->getTLMPage()->getTLMManagerProcessTextBox()->text(), args);
pManagerProcess->waitForFinished();

/*! @todo Read the interfaceData.xml file here */
}

//! Creates the toolbars
void MainWindow::createToolbars()
{
Expand Down Expand Up @@ -2920,6 +3009,7 @@ void MainWindow::createToolbars()
mpTLMSimulationToolbar->setObjectName("TLM Simulation Toolbar");
mpTLMSimulationToolbar->setAllowedAreas(Qt::TopToolBarArea);
// add actions to TLM Simulation Toolbar
mpTLMSimulationToolbar->addAction(mpFetchInterfaceDataAction);
mpTLMSimulationToolbar->addAction(mpTLMCoSimulationAction);
}

Expand Down
13 changes: 9 additions & 4 deletions OMEdit/OMEditGUI/MainWindow.h
Expand Up @@ -139,6 +139,7 @@ class MainWindow : public QMainWindow
QAction* getImportFromOMNotebookAction();
QAction* getImportNgspiceNetlistAction();
QAction* getConnectModeAction();
QAction* getFetchInterfaceDataAction() {return mpFetchInterfaceDataAction;}
QAction* getTLMSimulationAction() {return mpTLMCoSimulationAction;}
void addRecentFile(const QString &fileName, const QString &encoding);
void updateRecentFileActions();
Expand All @@ -157,6 +158,7 @@ class MainWindow : public QMainWindow
void exportModelFMU(LibraryTreeNode *pLibraryTreeNode);
void exportModelXML(LibraryTreeNode *pLibraryTreeNode);
void exportModelFigaro(LibraryTreeNode *pLibraryTreeNode);
void fetchInterfaceData(LibraryTreeNode *pLibraryTreeNode);
void TLMSimulate(LibraryTreeNode *pLibraryTreeNode);
void exportModelToOMNotebook(LibraryTreeNode *pLibraryTreeNode);
void createOMNotebookTitleCell(LibraryTreeNode *pLibraryTreeNode, QDomDocument xmlDocument, QDomElement domElement);
Expand Down Expand Up @@ -212,8 +214,8 @@ class MainWindow : public QMainWindow
QAction *mpOpenResultFileAction;
QAction *mpOpenTransformationFileAction;
// TLM File Actions
QAction *mpNewTLMFileAction;
QAction *mpOpenTLMFileAction;
QAction *mpNewMetaModelFileAction;
QAction *mpOpenMetaModelFileAction;
QAction *mpLoadExternModelAction;
QAction *mpSaveAction;
QAction *mpSaveAsAction;
Expand Down Expand Up @@ -289,6 +291,7 @@ class MainWindow : public QMainWindow
QAction *mpExportAsImageAction;
QAction *mpExportToClipboardAction;
// TLM Simulation Action
QAction *mpFetchInterfaceDataAction;
QAction *mpTLMCoSimulationAction;
// Toolbars
QMenu *mpRecentFilesMenu;
Expand All @@ -311,8 +314,8 @@ public slots:
void loadModelicaLibrary();
void showOpenResultFileDialog();
void showOpenTransformationFileDialog();
void createNewTLMFile();
void openTLMFile();
void createNewMetaModelFile();
void openMetaModelFile();
void loadExternalModels();
void loadSystemLibrary();
void readOutputFile(qint64 bytes);
Expand Down Expand Up @@ -347,6 +350,7 @@ public slots:
void importNgspiceNetlist();
void exportModelAsImage(bool copyToClipboard = false);
void exportToClipboard();
void fetchInterfaceData();
void TLMSimulate();
void openConfigurationOptions();
void openUsersGuide();
Expand Down Expand Up @@ -383,6 +387,7 @@ private slots:
void switchToPlottingPerspective();
void closeAllWindowsButThis(QMdiArea *pMdiArea);
void tileSubWindows(QMdiArea *pMdiArea, bool horizontally);
void fetchInterfaceDataHelper(LibraryTreeNode *pLibraryTreeNode);
protected:
virtual void dragEnterEvent(QDragEnterEvent *event);
virtual void dragMoveEvent(QDragMoveEvent *event);
Expand Down
22 changes: 22 additions & 0 deletions OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp
Expand Up @@ -585,6 +585,10 @@ void LibraryTreeWidget::createActions()
mpExportFigaroAction = new QAction(QIcon(":/Resources/icons/console.svg"), Helper::exportFigaro, this);
mpExportFigaroAction->setStatusTip(Helper::exportFigaroTip);
connect(mpExportFigaroAction, SIGNAL(triggered()), SLOT(exportModelFigaro()));
// fetch interface data
mpFetchInterfaceDataAction = new QAction(QIcon(":/Resources/icons/interface-data.svg"), Helper::fetchInterfaceData, this);
mpFetchInterfaceDataAction->setStatusTip(Helper::fetchInterfaceDataTip);
connect(mpFetchInterfaceDataAction, SIGNAL(triggered()), SLOT(fetchInterfaceData()));
// TLM co-simulation action
mpTLMCoSimulationAction = new QAction(QIcon(":/Resources/icons/tlm-simulate.svg"), Helper::tlmCoSimulationSetup, this);
mpTLMCoSimulationAction->setStatusTip(Helper::tlmCoSimulationSetupTip);
Expand Down Expand Up @@ -1602,6 +1606,7 @@ void LibraryTreeWidget::showContextMenu(QPoint point)
menu.addAction(mpUnloadTextFileAction);
break;
case LibraryTreeNode::TLM:
menu.addAction(mpFetchInterfaceDataAction);
menu.addAction(mpTLMCoSimulationAction);
menu.addSeparator();
menu.addAction(mpUnloadTLMFileAction);
Expand Down Expand Up @@ -1797,6 +1802,23 @@ void LibraryTreeWidget::exportModelFigaro()
mpMainWindow->exportModelFigaro(pLibraryTreeNode);
}

/*!
* \brief LibraryTreeWidget::fetchInterfaceData
* Slot activated when mpFetchInterfaceDataAction triggered signal is raised.
* Calls the function that fetches the interface data.
*/
void LibraryTreeWidget::fetchInterfaceData()
{
QList<QTreeWidgetItem*> selectedItemsList = selectedItems();
if (selectedItemsList.isEmpty()) {
return;
}
LibraryTreeNode *pLibraryTreeNode = dynamic_cast<LibraryTreeNode*>(selectedItemsList.at(0));
if (pLibraryTreeNode) {
mpMainWindow->fetchInterfaceData(pLibraryTreeNode);
}
}

void LibraryTreeWidget::TLMSimulate()
{
QList<QTreeWidgetItem*> selectedItemsList = selectedItems();
Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.h
Expand Up @@ -213,6 +213,7 @@ class LibraryTreeWidget : public QTreeWidget
QAction *mpExportFMUAction;
QAction *mpExportXMLAction;
QAction *mpExportFigaroAction;
QAction *mpFetchInterfaceDataAction;
QAction *mpTLMCoSimulationAction;
bool saveModelicaLibraryTreeNode(LibraryTreeNode *pLibraryTreeNode);
bool saveTextLibraryTreeNode(LibraryTreeNode *pLibraryTreeNode);
Expand Down Expand Up @@ -245,6 +246,7 @@ public slots:
void exportModelFMU();
void exportModelXML();
void exportModelFigaro();
void fetchInterfaceData();
void TLMSimulate();
void openFile(QString fileName, QString encoding = Helper::utf8, bool showProgress = true, bool checkFileExists = false);
void openModelicaFile(QString fileName, QString encoding = Helper::utf8, bool showProgress = true);
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -3441,6 +3441,7 @@ void ModelWidgetContainer::currentModelWidgetChanged(QMdiSubWindow *pSubWindow)
getMainWindow()->getExportAsImageAction()->setEnabled(enabled && modelica);
getMainWindow()->getExportToClipboardAction()->setEnabled(enabled && modelica);
getMainWindow()->getPrintModelAction()->setEnabled(enabled);
getMainWindow()->getFetchInterfaceDataAction()->setEnabled(enabled && TLM);
getMainWindow()->getTLMSimulationAction()->setEnabled(enabled && TLM);
/* disable the save actions if class is a system library class. */
if (pModelWidget) {
Expand Down

0 comments on commit 1c72bdb

Please sign in to comment.