Skip to content

Commit 1e4ee6b

Browse files
committed
- FMI Import widget files
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@10129 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent f25af76 commit 1e4ee6b

File tree

2 files changed

+240
-0
lines changed

2 files changed

+240
-0
lines changed

OMEdit/OMEditGUI/FMIWidget.cpp

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
/*
2+
* This file is part of OpenModelica.
3+
*
4+
* Copyright (c) 1998-CurrentYear, Linkoping University,
5+
* Department of Computer and Information Science,
6+
* SE-58183 Linkoping, Sweden.
7+
*
8+
* All rights reserved.
9+
*
10+
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3
11+
* AND THIS OSMC PUBLIC LICENSE (OSMC-PL).
12+
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S
13+
* ACCEPTANCE OF THE OSMC PUBLIC LICENSE.
14+
*
15+
* The OpenModelica software and the Open Source Modelica
16+
* Consortium (OSMC) Public License (OSMC-PL) are obtained
17+
* from Linkoping University, either from the above address,
18+
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
19+
* http://www.openmodelica.org, and in the OpenModelica distribution.
20+
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
21+
*
22+
* This program is distributed WITHOUT ANY WARRANTY; without
23+
* even the implied warranty of MERCHANTABILITY or FITNESS
24+
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
25+
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS
26+
* OF OSMC-PL.
27+
*
28+
* See the full OSMC Public License conditions for more details.
29+
*
30+
* Main Author 2011: Adeel Asghar
31+
*
32+
*/
33+
34+
#include "FMIWidget.h"
35+
36+
//! @class ImportFMIWidget
37+
//! @brief Creates an interface for importing FMU package.
38+
39+
//! Constructor
40+
ImportFMIWidget::ImportFMIWidget(MainWindow *pParent)
41+
: QDialog(pParent, Qt::WindowTitleHint)
42+
{
43+
setWindowTitle(QString(Helper::applicationName).append(" - Import FMI"));
44+
setAttribute(Qt::WA_DeleteOnClose);
45+
setMinimumWidth(550);
46+
// set parent widget
47+
mpParentMainWindow = pParent;
48+
// set import heading
49+
mpImportFMIHeading = new QLabel(Helper::importFMI);
50+
mpImportFMIHeading->setFont(QFont("", Helper::headingFontSize));
51+
// set seperator line
52+
mpHorizontalLine = new QFrame();
53+
mpHorizontalLine->setFrameShape(QFrame::HLine);
54+
mpHorizontalLine->setFrameShadow(QFrame::Sunken);
55+
// create FMU File selection controls
56+
mpFmuFileLabel = new QLabel(Helper::fmuFileName);
57+
mpFmuFileTextBox = new QLineEdit;
58+
mpBrowseFileButton = new QPushButton(Helper::browse);
59+
connect(mpBrowseFileButton, SIGNAL(clicked()), SLOT(setSelectedFile()));
60+
// create Output Directory selection controls
61+
mpOutputDirectoryLabel = new QLabel(Helper::outputDirectory);
62+
mpOutputDirectoryTextBox = new QLineEdit;
63+
mpBrowseDirectoryButton = new QPushButton(Helper::browse);
64+
connect(mpBrowseDirectoryButton, SIGNAL(clicked()), SLOT(setSelectedDirectory()));
65+
// import FMI note
66+
mpOutputDirectoryNoteLabel = new QLabel(Helper::outputDirectoryNote);
67+
// create OK button
68+
mpImportButton = new QPushButton(Helper::import);
69+
connect(mpImportButton, SIGNAL(clicked()), SLOT(importFMU()));
70+
// set grid layout
71+
QGridLayout *mainLayout = new QGridLayout;
72+
mainLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft);
73+
mainLayout->addWidget(mpImportFMIHeading, 0, 0, 1, 3);
74+
mainLayout->addWidget(mpHorizontalLine, 1, 0, 1, 3);
75+
mainLayout->addWidget(mpFmuFileLabel, 2, 0);
76+
mainLayout->addWidget(mpFmuFileTextBox, 2, 1);
77+
mainLayout->addWidget(mpBrowseFileButton, 2, 2);
78+
mainLayout->addWidget(mpOutputDirectoryLabel, 3, 0);
79+
mainLayout->addWidget(mpOutputDirectoryTextBox, 3, 1);
80+
mainLayout->addWidget(mpBrowseDirectoryButton, 3, 2);
81+
mainLayout->addWidget(mpOutputDirectoryNoteLabel, 4, 0, 1, 3, Qt::AlignLeft);
82+
mainLayout->addWidget(mpImportButton, 5, 0, 1, 3, Qt::AlignRight);
83+
84+
setLayout(mainLayout);
85+
}
86+
87+
//! Slot activated when mpBrowseFileButton clicked signal is raised.
88+
//! Allows the user to select the FMU file.
89+
void ImportFMIWidget::setSelectedFile()
90+
{
91+
mpFmuFileTextBox->setText(StringHandler::getOpenFileName(this, tr("Choose File"), NULL, Helper::fmuFileTypes, NULL));
92+
}
93+
94+
//! Slot activated when mpBrowseDirectoryButton clicked signal is raised.
95+
//! Allows the user to select the output directory for FMU files.
96+
void ImportFMIWidget::setSelectedDirectory()
97+
{
98+
mpOutputDirectoryTextBox->setText(StringHandler::getExistingDirectory(this, tr("Choose Directory"), NULL));
99+
}
100+
101+
//! Slot activated when mpImportButton clicked signal is raised.
102+
//! Sends the importFMU command to OMC.
103+
//! Reads the generated model by fmigenerator and loads it.
104+
void ImportFMIWidget::importFMU()
105+
{
106+
if (mpFmuFileTextBox->text().isEmpty())
107+
{
108+
QMessageBox::critical(this, Helper::applicationName + " - Error", GUIMessages::getMessage(GUIMessages::ENTER_NAME).
109+
arg("FMU File"), tr("OK"));
110+
return;
111+
}
112+
113+
if (mpParentMainWindow->mpOMCProxy->importFMU(mpFmuFileTextBox->text(), mpOutputDirectoryTextBox->text()))
114+
{
115+
QFile fmuImportLogfile;
116+
if (mpOutputDirectoryTextBox->text().isEmpty())
117+
{
118+
fmuImportLogfile.setFileName(QString(mpOutputDirectoryTextBox->text()).append(QDir::separator()).append("fmuImport.log"));
119+
}
120+
else
121+
{
122+
fmuImportLogfile.setFileName(mpParentMainWindow->mpOMCProxy->changeDirectory().append(QDir::separator()).append("fmuImport.log"));
123+
}
124+
125+
if (!fmuImportLogfile.open(QIODevice::ReadOnly))
126+
{
127+
QMessageBox::critical(this, Helper::applicationName + " - Error", GUIMessages::getMessage(GUIMessages::ERROR_OCCURRED)
128+
.arg("Could not open file ").append(fmuImportLogfile.fileName()), tr("OK"));
129+
return;
130+
}
131+
QTextStream inStream(&fmuImportLogfile);
132+
QString importedFileName;
133+
while (!inStream.atEnd())
134+
{
135+
QString line = inStream.readLine();
136+
// Check for the path
137+
if (line.contains("FMU decompression path:"))
138+
{
139+
importedFileName.append(line.mid(line.indexOf("FMU decompression path:")+24));
140+
}
141+
// Check for the model name
142+
if (line.contains("Modelica model name:"))
143+
{
144+
importedFileName.append(QDir::separator()).append(line.mid(line.indexOf("Modelica model name:")+21));
145+
}
146+
}
147+
mpParentMainWindow->mpProjectTabs->openFile(importedFileName);
148+
accept();
149+
}
150+
else
151+
{
152+
QFile fmuImportErrorLogfile;
153+
if (mpOutputDirectoryTextBox->text().isEmpty())
154+
{
155+
fmuImportErrorLogfile.setFileName(QString(mpOutputDirectoryTextBox->text()).append(QDir::separator()).append("fmuImportError.log"));
156+
}
157+
else
158+
{
159+
fmuImportErrorLogfile.setFileName(mpParentMainWindow->mpOMCProxy->changeDirectory().append(QDir::separator()).append("fmuImportError.log"));
160+
}
161+
162+
if (fmuImportErrorLogfile.open(QIODevice::ReadOnly))
163+
{
164+
QTextStream inStream(&fmuImportErrorLogfile);
165+
QMessageBox::critical(this, Helper::applicationName + " - Error", GUIMessages::getMessage(GUIMessages::ERROR_OCCURRED)
166+
.arg(inStream.readAll()).append("\nwhile importing " + mpFmuFileTextBox->text()), tr("OK"));
167+
}
168+
else
169+
{
170+
QMessageBox::critical(this, Helper::applicationName + " - Error", GUIMessages::getMessage(GUIMessages::ERROR_OCCURRED)
171+
.arg("unknown error ").append("\nwhile importing " + mpFmuFileTextBox->text()), tr("OK"));
172+
}
173+
}
174+
}

OMEdit/OMEditGUI/FMIWidget.h

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* This file is part of OpenModelica.
3+
*
4+
* Copyright (c) 1998-CurrentYear, Linkoping University,
5+
* Department of Computer and Information Science,
6+
* SE-58183 Linkoping, Sweden.
7+
*
8+
* All rights reserved.
9+
*
10+
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3
11+
* AND THIS OSMC PUBLIC LICENSE (OSMC-PL).
12+
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S
13+
* ACCEPTANCE OF THE OSMC PUBLIC LICENSE.
14+
*
15+
* The OpenModelica software and the Open Source Modelica
16+
* Consortium (OSMC) Public License (OSMC-PL) are obtained
17+
* from Linkoping University, either from the above address,
18+
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
19+
* http://www.openmodelica.org, and in the OpenModelica distribution.
20+
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
21+
*
22+
* This program is distributed WITHOUT ANY WARRANTY; without
23+
* even the implied warranty of MERCHANTABILITY or FITNESS
24+
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
25+
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS
26+
* OF OSMC-PL.
27+
*
28+
* See the full OSMC Public License conditions for more details.
29+
*
30+
* Main Author 2011: Adeel Asghar
31+
*
32+
*/
33+
34+
#ifndef FMIWIDGET_H
35+
#define FMIWIDGET_H
36+
37+
#include "mainwindow.h"
38+
39+
class MainWindow;
40+
41+
class ImportFMIWidget : public QDialog
42+
{
43+
Q_OBJECT
44+
public:
45+
ImportFMIWidget(MainWindow *pParent = 0);
46+
47+
MainWindow *mpParentMainWindow;
48+
private:
49+
QLabel *mpImportFMIHeading;
50+
QFrame *mpHorizontalLine;
51+
QLabel *mpFmuFileLabel;
52+
QLineEdit *mpFmuFileTextBox;
53+
QPushButton *mpBrowseFileButton;
54+
QLabel *mpOutputDirectoryLabel;
55+
QLineEdit *mpOutputDirectoryTextBox;
56+
QPushButton *mpBrowseDirectoryButton;
57+
QLabel *mpOutputDirectoryNoteLabel;
58+
QPushButton *mpImportButton;
59+
private slots:
60+
void setSelectedFile();
61+
void setSelectedDirectory();
62+
void importFMU();
63+
};
64+
65+
66+
#endif // FMIWIDGET_H

0 commit comments

Comments
 (0)