Skip to content

Commit bb4e153

Browse files
committed
- added cplusplus macro to the read_matlab.h so that it can be linked against c++ files.
- Changed the simulate command to use mat as default. - Changed the plot API accordingly. git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8019 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 977f375 commit bb4e153

17 files changed

+237
-37
lines changed

OMEdit/OMEditGUI/Helper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ QString Helper::modelicaLibrarySearchText = QString("Search Modelica Standard Li
7474
QString Helper::noItemFound = QString("Sorry, no items found");
7575

7676
QString Helper::ModelicaSimulationMethods = "DASSL,DASSL2,Euler,Runge-Kutta";
77-
QString Helper::ModelicaSimulationOutputFormats = "mat,csv,plt,empty";
77+
QString Helper::ModelicaSimulationOutputFormats = "mat,plt,csv,empty";
7878

7979
QString GUIMessages::getMessage(int type)
8080
{

OMEdit/OMEditGUI/LibraryWidget.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ MSLSuggestCompletion::MSLSuggestCompletion(MSLSearchBox *pParent)
813813
// set up the timer to get the suggestions
814814
mpTimer = new QTimer(this);
815815
mpTimer->setSingleShot(true);
816-
mpTimer->setInterval(500);
816+
mpTimer->setInterval(100);
817817
connect(mpTimer, SIGNAL(timeout()), SLOT(getSuggestions()));
818818
connect(mpMSLSearchBox, SIGNAL(textEdited(QString)), mpTimer, SLOT(start()));
819819
}
@@ -849,8 +849,6 @@ bool MSLSuggestCompletion::eventFilter(QObject *pObject, QEvent *event)
849849
consumed = true;
850850
case Qt::Key_Up:
851851
case Qt::Key_Down:
852-
case Qt::Key_Home:
853-
case Qt::Key_End:
854852
case Qt::Key_PageUp:
855853
case Qt::Key_PageDown:
856854
break;
@@ -921,6 +919,7 @@ void MSLSuggestCompletion::getSuggestions()
921919
if ((mpMSLSearchBox->text().compare(Helper::modelicaLibrarySearchText) == 0) or (mpMSLSearchBox->text().isEmpty()))
922920
{
923921
preventSuggestions();
922+
mpPopup->hide();
924923
return;
925924
}
926925

@@ -1105,7 +1104,7 @@ void LibraryWidget::addModelFiles(QString fileName, QString parentFileName, QStr
11051104
}
11061105
}
11071106

1108-
void LibraryWidget::loadModel(QString path, QStringList modelsList)
1107+
void LibraryWidget::loadFile(QString path, QStringList modelsList)
11091108
{
11101109
// load the file in OMC
11111110
mpParentMainWindow->mpOMCProxy->loadFile(path);
@@ -1118,6 +1117,19 @@ void LibraryWidget::loadModel(QString path, QStringList modelsList)
11181117
mpLibraryTabs->setCurrentWidget(mpModelicaTree);
11191118
}
11201119

1120+
void LibraryWidget::loadModel(QString modelText, QStringList modelsList)
1121+
{
1122+
// load the file in OMC
1123+
mpParentMainWindow->mpOMCProxy->saveModifiedModel(modelText);
1124+
1125+
foreach (QString model, modelsList)
1126+
{
1127+
addModelFiles(model, tr(""), tr(""));
1128+
}
1129+
// make the modelica files tab visible in library widget dock window
1130+
mpLibraryTabs->setCurrentWidget(mpModelicaTree);
1131+
}
1132+
11211133
void LibraryWidget::addComponentObject(LibraryComponent *libraryComponent)
11221134
{
11231135
mComponentsList.append(libraryComponent);

OMEdit/OMEditGUI/LibraryWidget.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ class LibraryWidget : public QWidget
213213
~LibraryWidget();
214214
void addModelicaNode(QString name, int type, QString parentName=QString(), QString parentStructure=QString());
215215
void addModelFiles(QString fileName, QString parentFileName=QString(), QString parentStructure=QString());
216-
void loadModel(QString path, QStringList modelsList);
216+
void loadFile(QString path, QStringList modelsList);
217+
void loadModel(QString modelText, QStringList modelsList);
217218
void addComponentObject(LibraryComponent *libraryComponent);
218219
Component* getComponentObject(QString className);
219220
LibraryComponent* getLibraryComponentObject(QString className);

OMEdit/OMEditGUI/OMCProxy.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,9 @@ bool OMCProxy::startServer()
151151
QFile objectRefFile;
152152
QString fileIdentifier;
153153
if (mDisplayErrors)
154-
fileIdentifier = qApp->sessionId().append(QTime::currentTime().toString().remove(":"));
154+
fileIdentifier = qApp->sessionId().append(QTime::currentTime().toString(tr("hh:mm:ss:zzz")).remove(":"));
155155
else
156-
fileIdentifier = QString("temp-").append(qApp->sessionId().append(QTime::currentTime().toString().remove(":")));
156+
fileIdentifier = QString("temp-").append(qApp->sessionId().append(QTime::currentTime().toString(tr("hh:mm:ss:zzz")).remove(":")));
157157

158158
#ifdef WIN32 // Win32
159159
objectRefFile.setFileName(QString(QDir::tempPath()).append(QDir::separator()).append("openmodelica.objid.").append(this->mName).append(fileIdentifier));
@@ -1138,9 +1138,19 @@ bool OMCProxy::simulate(QString modelName, QString simualtionParameters)
11381138
return false;
11391139
}
11401140

1141-
bool OMCProxy::plot(QString modelName, QString plotVariables)
1141+
//bool OMCProxy::plot(QString modelName, QString plotVariables)
1142+
//{
1143+
// sendCommand("plot(" + modelName + ",{" + plotVariables + "})");
1144+
// if (getResult().contains("true"))
1145+
// return true;
1146+
// else
1147+
// return false;
1148+
//}
1149+
1150+
// modified plot API call
1151+
bool OMCProxy::plot(QString plotVariables, QString fileName)
11421152
{
1143-
sendCommand("plot(" + modelName + ",{" + plotVariables + "})");
1153+
sendCommand("plot({" + plotVariables + "}, " + fileName + ")");
11441154
if (getResult().contains("true"))
11451155
return true;
11461156
else

OMEdit/OMEditGUI/OMCProxy.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ class OMCProxy : public QObject
146146
bool deleteConnection(QString from, QString to, QString className);
147147
bool instantiateModel(QString modelName);
148148
bool simulate(QString modelName, QString simualtionParameters);
149-
bool plot(QString modelName, QString plotVariables);
149+
//bool plot(QString modelName, QString plotVariables);
150+
// modified plot API call
151+
bool plot(QString plotVariables, QString fileName);
150152
bool plotParametric(QString modelName, QString plotVariables);
151153
bool visualize(QString modelName);
152154
QString checkModel(QString modelName);

OMEdit/OMEditGUI/OMEditGUI.pro

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ SOURCES += main.cpp\
3939
Transformation.cpp \
4040
DocumentationWidget.cpp \
4141
OptionsWidget.cpp \
42-
BitmapAnnotation.cpp
42+
BitmapAnnotation.cpp \
43+
../../c_runtime/read_matlab4.c
4344

4445
HEADERS += mainwindow.h \
4546
ProjectTabWidget.h \
@@ -70,7 +71,8 @@ HEADERS += mainwindow.h \
7071
Transformation.h \
7172
DocumentationWidget.h \
7273
OptionsWidget.h \
73-
BitmapAnnotation.h
74+
BitmapAnnotation.h \
75+
../../c_runtime/read_matlab4.h
7476

7577
# -------For OMNIorb
7678
win32 {
@@ -81,7 +83,7 @@ DEFINES += __x86__ \
8183
LIBS += -L$$(OMDEV)/lib/omniORB-4.1.4-mingw/lib/x86_win32 \
8284
-lomniORB414_rt \
8385
-lomnithread34_rt
84-
INCLUDEPATH += $$(OMDEV)/lib/omniORB-4.1.4-mingw/include
86+
INCLUDEPATH += $$(OMDEV)/lib/omniORB-4.1.4-mingw/include ../../c_runtime/
8587
} else {
8688
include(OMEdit.config)
8789
}

OMEdit/OMEditGUI/PlotWidget.cpp

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
*/
3333

3434
#include "PlotWidget.h"
35+
#include "read_matlab4.h"
3536

3637
PlotWidget::PlotWidget(MainWindow *pParent)
3738
: QWidget(pParent)
@@ -64,10 +65,8 @@ PlotWidget::PlotWidget(MainWindow *pParent)
6465
connect(mpPlotTypesCombo, SIGNAL(currentIndexChanged(QString)), SLOT(visualize(QString)));
6566
}
6667

67-
void PlotWidget::readPlotVariables(QString fileName)
68+
QList<QString> PlotWidget::readPltFile(QString filePath)
6869
{
69-
// need to replace \\ to / so that QFile can close the file properly, otherwise we can't open it second time
70-
QString filePath = QString(Helper::tmpPath.replace("\\", "/")).append("/").append(fileName);
7170
QFile simulationResultFile(filePath);
7271
simulationResultFile.open(QIODevice::ReadOnly);
7372

@@ -86,6 +85,45 @@ void PlotWidget::readPlotVariables(QString fileName)
8685
}
8786
}
8887
simulationResultFile.close();
88+
return plotVariablesList;
89+
}
90+
91+
QList<QString> PlotWidget::readMatFile(QString filePath)
92+
{
93+
QList<QString> plotVariablesList;
94+
ModelicaMatReader reader;
95+
// read the mat file structure
96+
omc_new_matlab4_reader(filePath.toLatin1(), &reader);
97+
98+
// read the mat file structure
99+
for (int i = 0 ; i < reader.nall ; i++)
100+
{
101+
QString plotVariable = QString(reader.allInfo[i].name);
102+
if (!plotVariable.contains("dummy"))
103+
plotVariablesList.append(plotVariable);
104+
}
105+
// free the mat reader
106+
omc_free_matlab4_reader(&reader);
107+
return plotVariablesList;
108+
}
109+
110+
void PlotWidget::readPlotVariables(QString fileName)
111+
{
112+
// need to replace \\ to / so that QFile can close the file properly, otherwise we can't open it second time
113+
QString filePath = QString(Helper::tmpPath.replace("\\", "/")).append("/").append(fileName);
114+
115+
QStringList fileNameList = filePath.split('.');
116+
QString fileExtension = fileNameList.last();
117+
QList<QString> plotVariablesList;
118+
119+
if (fileExtension.compare("plt") == 0)
120+
{
121+
plotVariablesList = readPltFile(filePath);
122+
}
123+
else if (fileExtension.compare("mat") == 0)
124+
{
125+
plotVariablesList = readMatFile(filePath);
126+
}
89127
addPlotVariablestoTree(fileName, plotVariablesList);
90128
}
91129

@@ -152,14 +190,17 @@ void PlotWidget::plotVariables(QTreeWidgetItem *item, int column)
152190
QString modelName = parentItem->toolTip(column).remove((parentItem->toolTip(column).length() - 8),
153191
(parentItem->toolTip(column).length() - 1));
154192
QString plotType = mpPlotTypesCombo->currentText();
193+
MessageWidget *pMessageWidget = mpParentMainWindow->mpMessageWidget;
155194

156195
if (plotType == "Plot")
157196
{
158197
plotExpression = "plot(" + modelName + ", {" + plotVariablesString + "})";
159198
setCursor(Qt::WaitCursor);
160-
if (!mpParentMainWindow->mpOMCProxy->plot(modelName, plotVariablesString))
199+
//if (!mpParentMainWindow->mpOMCProxy->plot(modelName, plotVariablesString))
200+
if (!mpParentMainWindow->mpOMCProxy->plot(plotVariablesString, parentItem->toolTip(column)))
161201
{
162-
mpParentMainWindow->mpMessageWidget->printGUIErrorMessage(mpParentMainWindow->mpOMCProxy->getResult());
202+
pMessageWidget->printGUIErrorMessage(QString(mpParentMainWindow->mpOMCProxy->getResult())
203+
.append(mpParentMainWindow->mpOMCProxy->getErrorString()));
163204
}
164205
unsetCursor();
165206
}
@@ -169,7 +210,8 @@ void PlotWidget::plotVariables(QTreeWidgetItem *item, int column)
169210
setCursor(Qt::WaitCursor);
170211
if (!mpParentMainWindow->mpOMCProxy->plotParametric(modelName, plotVariablesString))
171212
{
172-
mpParentMainWindow->mpMessageWidget->printGUIErrorMessage(mpParentMainWindow->mpOMCProxy->getResult());
213+
pMessageWidget->printGUIErrorMessage(QString(mpParentMainWindow->mpOMCProxy->getResult())
214+
.append(mpParentMainWindow->mpOMCProxy->getErrorString()));
173215
}
174216
unsetCursor();
175217
}
@@ -179,7 +221,8 @@ void PlotWidget::plotVariables(QTreeWidgetItem *item, int column)
179221
setCursor(Qt::WaitCursor);
180222
if (!mpParentMainWindow->mpOMCProxy->visualize(modelName))
181223
{
182-
mpParentMainWindow->mpMessageWidget->printGUIErrorMessage(mpParentMainWindow->mpOMCProxy->getResult());
224+
pMessageWidget->printGUIErrorMessage(QString(mpParentMainWindow->mpOMCProxy->getResult())
225+
.append(mpParentMainWindow->mpOMCProxy->getErrorString()));
183226
}
184227
unsetCursor();
185228
}

OMEdit/OMEditGUI/PlotWidget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class PlotWidget : public QWidget
4343
Q_OBJECT
4444
public:
4545
PlotWidget(MainWindow *pParent = 0);
46+
QList<QString> readPltFile(QString filePath);
47+
QList<QString> readMatFile(QString filePath);
4648

4749
MainWindow *mpParentMainWindow;
4850

OMEdit/OMEditGUI/ProjectTabWidget.cpp

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void GraphicsView::drawBackground(QPainter *painter, const QRectF &rect)
117117
//! @todo Grid Lines changes when resize the window. Update it.
118118
if (mpParentProjectTab->mpParentProjectTabWidget->mShowLines)
119119
{
120-
painter->scale(1.0, -1.0);
120+
//painter->scale(1.0, -1.0);
121121
painter->setBrush(Qt::NoBrush);
122122
painter->setPen(Qt::gray);
123123

@@ -781,7 +781,7 @@ void GraphicsView::contextMenuEvent(QContextMenuEvent *event)
781781
QMenu menu(mpParentProjectTab->mpParentProjectTabWidget->mpParentMainWindow);
782782
mpCancelConnectionAction->setText("Context Menu");
783783
menu.addAction(mpParentProjectTab->mpParentProjectTabWidget->mpParentMainWindow->exportAsImage);
784-
menu.addAction(mpParentProjectTab->mpParentProjectTabWidget->mpParentMainWindow->exportToOMNotebookAction);
784+
//menu.addAction(mpParentProjectTab->mpParentProjectTabWidget->mpParentMainWindow->exportToOMNotebookAction);
785785
menu.exec(event->globalPos());
786786
return; // return from it because at a time we only want one context menu.
787787
}
@@ -1918,7 +1918,7 @@ ProjectTabWidget::ProjectTabWidget(MainWindow *parent)
19181918
mShowLines = false;
19191919
mToolBarEnabled = true;
19201920

1921-
connect(mpParentMainWindow->openAction, SIGNAL(triggered()), this,SLOT(openModel()));
1921+
connect(mpParentMainWindow->openAction, SIGNAL(triggered()), this,SLOT(openFile()));
19221922
connect(mpParentMainWindow->saveAction, SIGNAL(triggered()), this,SLOT(saveProjectTab()));
19231923
connect(mpParentMainWindow->saveAsAction, SIGNAL(triggered()), this,SLOT(saveProjectTabAs()));
19241924
connect(this,SIGNAL(tabCloseRequested(int)),SLOT(closeProjectTab(int)));
@@ -2381,7 +2381,7 @@ bool ProjectTabWidget::closeAllProjectTabs()
23812381

23822382
//! Loads a model from a file and opens it in a new project tab.
23832383
//! @see saveModel(bool saveAs)
2384-
void ProjectTabWidget::openModel(QString fileName)
2384+
void ProjectTabWidget::openFile(QString fileName)
23852385
{
23862386
if (fileName.isEmpty())
23872387
{
@@ -2394,7 +2394,6 @@ void ProjectTabWidget::openModel(QString fileName)
23942394
fileName = name;
23952395
}
23962396

2397-
23982397
// create new OMC instance and load the file in it
23992398
OMCProxy *omc = new OMCProxy(mpParentMainWindow, false);
24002399
// if error in loading file
@@ -2423,7 +2422,57 @@ void ProjectTabWidget::openModel(QString fileName)
24232422
if (existModel)
24242423
{
24252424
QMessageBox *msgBox = new QMessageBox(mpParentMainWindow);
2426-
msgBox->setWindowTitle(QString(Helper::applicationName).append(" - Question"));
2425+
msgBox->setWindowTitle(QString(Helper::applicationName).append(" - Information"));
2426+
msgBox->setIcon(QMessageBox::Information);
2427+
msgBox->setText(QString(GUIMessages::getMessage(GUIMessages::UNABLE_TO_LOAD_FILE)));
2428+
msgBox->setInformativeText(QString(GUIMessages::getMessage(GUIMessages::REDEFING_EXISTING_MODELS))
2429+
.arg(existingmodelsList.join(",")).append("\n")
2430+
.append(GUIMessages::getMessage(GUIMessages::DELETE_AND_LOAD)));
2431+
msgBox->setStandardButtons(QMessageBox::Ok);
2432+
msgBox->exec();
2433+
}
2434+
// if no conflicting model found then just load the file simply
2435+
else
2436+
{
2437+
mpParentMainWindow->mpLibrary->loadFile(fileName, modelsList);
2438+
}
2439+
// quit the temporary OMC
2440+
omc->stopServer();
2441+
}
2442+
2443+
//! Loads a model and opens it in a new project tab.
2444+
//! @see saveModel(bool saveAs)
2445+
void ProjectTabWidget::openModel(QString modelText)
2446+
{
2447+
// create new OMC instance and load the file in it
2448+
OMCProxy *omc = new OMCProxy(mpParentMainWindow, false);
2449+
// if error in loading file
2450+
if (!omc->saveModifiedModel(modelText))
2451+
{
2452+
QString message = QString(GUIMessages::getMessage(GUIMessages::UNABLE_TO_LOAD_FILE))
2453+
.append(omc->getErrorString());
2454+
mpParentMainWindow->mpMessageWidget->printGUIErrorMessage(message);
2455+
return;
2456+
}
2457+
// get the class names now to check if they are already loaded or not
2458+
QStringList existingmodelsList;
2459+
QStringList modelsList = omc->getClassNames();
2460+
bool existModel = false;
2461+
// check if the model already exists in OMEdit OMC instance
2462+
foreach(QString model, modelsList)
2463+
{
2464+
if (mpParentMainWindow->mpOMCProxy->existClass(model))
2465+
{
2466+
existingmodelsList.append(model);
2467+
existModel = true;
2468+
}
2469+
}
2470+
2471+
// check if existModel is true
2472+
if (existModel)
2473+
{
2474+
QMessageBox *msgBox = new QMessageBox(mpParentMainWindow);
2475+
msgBox->setWindowTitle(QString(Helper::applicationName).append(" - Information"));
24272476
msgBox->setIcon(QMessageBox::Information);
24282477
msgBox->setText(QString(GUIMessages::getMessage(GUIMessages::UNABLE_TO_LOAD_FILE)));
24292478
msgBox->setInformativeText(QString(GUIMessages::getMessage(GUIMessages::REDEFING_EXISTING_MODELS))
@@ -2435,7 +2484,7 @@ void ProjectTabWidget::openModel(QString fileName)
24352484
// if no conflicting model found then just load the file simply
24362485
else
24372486
{
2438-
mpParentMainWindow->mpLibrary->loadModel(fileName, modelsList);
2487+
mpParentMainWindow->mpLibrary->loadModel(modelText, modelsList);
24392488
}
24402489
// quit the temporary OMC
24412490
omc->stopServer();

OMEdit/OMEditGUI/ProjectTabWidget.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@ public slots:
253253
bool saveModel(bool saveAs);
254254
bool closeProjectTab(int index);
255255
bool closeAllProjectTabs();
256-
void openModel(QString fileName = QString());
256+
void openFile(QString fileName = QString());
257+
void openModel(QString modelText);
257258
void resetZoom();
258259
void zoomIn();
259260
void zoomOut();

0 commit comments

Comments
 (0)