Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- Catch the exception thrown in the OpenModelicaScriptingAPIQt.cpp
- Only done for translateModelFMU. We need to do it for all calls.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@25170 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Mar 19, 2015
1 parent dac91d5 commit 47cf694
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
29 changes: 22 additions & 7 deletions OMEdit/OMEditGUI/OMC/OMCProxy.cpp
Expand Up @@ -529,6 +529,16 @@ void OMCProxy::exitApplication()
exit(EXIT_FAILURE);
}

/*!
* \brief Writes the exception to MessagesWidget.
* \param exception
*/
void OMCProxy::showException(exception &exception)
{
MessageItem *pMessageItem = new MessageItem("", false, 0, 0, 0, 0, QString(exception.what()), Helper::scriptingKind, Helper::errorLevel, 0);
mpMainWindow->getMessagesWidget()->addGUIMessage(pMessageItem);
}

/*!
Returns the OMC error string.\n
\return the error string.
Expand Down Expand Up @@ -1919,14 +1929,19 @@ QStringList OMCProxy::getSimulationOptions(QString className, double defaultTole
*/
bool OMCProxy::translateModelFMU(QString className, double version, QString fileNamePrefix)
{
fileNamePrefix = fileNamePrefix.isEmpty() ? "<default>" : fileNamePrefix;
QString res = mpOMCInterface->translateModelFMU(className, QString::number(version), "me", fileNamePrefix);
if (res.compare("SimCode: The model " + className + " has been translated to FMU") == 0) {
return true;
} else {
printMessagesStringInternal();
return false;
bool result = false;
try {
fileNamePrefix = fileNamePrefix.isEmpty() ? "<default>" : fileNamePrefix;
QString res = mpOMCInterface->translateModelFMU(className, QString::number(version), "me", fileNamePrefix);
if (res.compare("SimCode: The model " + className + " has been translated to FMU") == 0) {
result = true;
} else {
printMessagesStringInternal();
}
} catch(std::exception &exception) {
showException(exception);
}
return result;
}

/*!
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/OMC/OMCProxy.h
Expand Up @@ -94,6 +94,7 @@ class OMCProxy : public QObject
QString getResult();
void exitApplication();
void removeObjectRefFile();
void showException(std::exception &exception);
QString getErrorString(bool warningsAsErrors = false);
bool printMessagesStringInternal();
int getMessagesStringInternal();
Expand Down

0 comments on commit 47cf694

Please sign in to comment.