Skip to content

Commit

Permalink
- Send commands to omc as utf-8.
Browse files Browse the repository at this point in the history
- All files generated by OMEdit are now utf-8.
- check for errors after setting/changing the working directory of omc.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@23122 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Nov 1, 2014
1 parent 1871879 commit c05e51d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 14 deletions.
25 changes: 14 additions & 11 deletions OMEdit/OMEditGUI/MainWindow.cpp
Expand Up @@ -53,14 +53,23 @@ MainWindow::MainWindow(QSplashScreen *pSplashScreen, QWidget *parent)
QFont monospaceFont("Monospace");
monospaceFont.setStyleHint(QFont::TypeWriter);
Helper::monospacedFontInfo = QFontInfo(monospaceFont);
/*! @note register the RecentFile and FindText struct in the Qt's meta system
* Don't remove/move the following line.
* Because RecentFile, FindText and DebuggerConfiguration struct should be registered before reading the recentFilesList, FindText and
/*! @note Register the RecentFile, FindText and DebuggerConfiguration struct in the Qt's meta system
* Don't remove/move the following lines.
* Because RecentFile, FindText and DebuggerConfiguration structs should be registered before reading the recentFilesList, FindText and
DebuggerConfiguration section respectively from the settings file.
*/
qRegisterMetaTypeStreamOperators<RecentFile>("RecentFile");
qRegisterMetaTypeStreamOperators<FindText>("FindText");
qRegisterMetaTypeStreamOperators<DebuggerConfiguration>("DebuggerConfiguration");
/*! @note The above three lines registers the structs as QMetaObjects. Do not remove/move them. */
setObjectName("MainWindow");
setWindowTitle(Helper::applicationName + " - " + Helper::applicationIntroText);
setWindowIcon(QIcon(":/Resources/icons/modeling.png"));
setMinimumSize(400, 300);
resize(800, 600);
setContentsMargins(1, 1, 1, 1);
// Create an object of MessagesWidget.
mpMessagesWidget = new MessagesWidget(this);
// Create the OMCProxy object.
pSplashScreen->showMessage(tr("Connecting to OpenModelica Compiler"), Qt::AlignRight, Qt::white);
mpOMCProxy = new OMCProxy(this);
Expand All @@ -70,14 +79,6 @@ MainWindow::MainWindow(QSplashScreen *pSplashScreen, QWidget *parent)
mpOptionsDialog = new OptionsDialog(this);
//Set the name and size of the main window
pSplashScreen->showMessage(tr("Loading Widgets"), Qt::AlignRight, Qt::white);
setObjectName("MainWindow");
setWindowTitle(Helper::applicationName + " - " + Helper::applicationIntroText);
setWindowIcon(QIcon(":/Resources/icons/modeling.png"));
setMinimumSize(400, 300);
resize(800, 600);
setContentsMargins(1, 1, 1, 1);
// Create an object of MessagesWidget.
mpMessagesWidget = new MessagesWidget(this);
// Create MessagesDockWidget dock
mpMessagesDockWidget = new QDockWidget(tr("Messages Browser"), this);
mpMessagesDockWidget->setObjectName("Messages");
Expand Down Expand Up @@ -968,6 +969,8 @@ void MainWindow::exportModelToOMNotebook(LibraryTreeNode *pLibraryTreeNode)
QFile omnotebookFile(omnotebookFileName);
omnotebookFile.open(QIODevice::WriteOnly);
QTextStream textStream(&omnotebookFile);
textStream.setCodec(Helper::utf8.toStdString().data());
textStream.setGenerateByteOrderMark(false);
textStream << xmlDocument.toString();
omnotebookFile.close();
mpProgressBar->setValue(value++);
Expand Down
8 changes: 6 additions & 2 deletions OMEdit/OMEditGUI/Modeling/LibraryTreeWidget.cpp
Expand Up @@ -1125,8 +1125,10 @@ bool LibraryTreeWidget::saveTextLibraryTreeNode(LibraryTreeNode *pLibraryTreeNod
}

QFile file(fileName);
if (file.open(QIODevice::WriteOnly)) {
if (file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
QTextStream textStream(&file);
textStream.setCodec(Helper::utf8.toStdString().data());
textStream.setGenerateByteOrderMark(false);
textStream << pLibraryTreeNode->getModelWidget()->getTextEditor()->toPlainText();
file.close();
/* mark the file as saved and update the labels. */
Expand Down Expand Up @@ -1162,8 +1164,10 @@ bool LibraryTreeWidget::saveXMLLibraryTreeNode(LibraryTreeNode *pLibraryTreeNode
}

QFile file(fileName);
if (file.open(QIODevice::WriteOnly)) {
if (file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
QTextStream textStream(&file);
textStream.setCodec(Helper::utf8.toStdString().data());
textStream.setGenerateByteOrderMark(false);
textStream << pLibraryTreeNode->getModelWidget()->getTLMEditor()->toPlainText();
file.close();
/* mark the file as saved and update the labels. */
Expand Down
7 changes: 6 additions & 1 deletion OMEdit/OMEditGUI/OMC/OMCProxy.cpp
Expand Up @@ -310,11 +310,15 @@ bool OMCProxy::startServer()
mCommunicationLogFile.setFileName(QString("%1omeditcommunication.log").arg(tmpPath));
if (mCommunicationLogFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
mCommunicationLogFileTextStream.setDevice(&mCommunicationLogFile);
mCommunicationLogFileTextStream.setCodec(Helper::utf8.toStdString().data());
mCommunicationLogFileTextStream.setGenerateByteOrderMark(false);
}
/* create a file to write OMEdit commands */
mCommandsMosFile.setFileName(QString("%1omeditcommands.mos").arg(tmpPath));
if (mCommandsMosFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
mCommandsLogFileTextStream.setDevice(&mCommandsMosFile);
mCommandsLogFileTextStream.setCodec(Helper::utf8.toStdString().data());
mCommandsLogFileTextStream.setGenerateByteOrderMark(false);
}
try
{
Expand Down Expand Up @@ -513,7 +517,7 @@ void OMCProxy::sendCommand(const QString expression, bool cacheCommand, QString
*/
void OMCProxy::sendCommand()
{
mResult = QString::fromLocal8Bit(mOMC->sendExpression(getExpression().toLocal8Bit()));
mResult = QString::fromUtf8(mOMC->sendExpression(getExpression().toUtf8()));
emit commandFinished();
}

Expand Down Expand Up @@ -1507,6 +1511,7 @@ QString OMCProxy::changeDirectory(QString directory)
directory = directory.replace("\\", "/");
sendCommand("cd(\"" + directory + "\")");
}
printMessagesStringInternal();
return StringHandler::unparse(getResult());
}

Expand Down
2 changes: 2 additions & 0 deletions OMEdit/OMEditGUI/Plotting/VariablesWidget.cpp
Expand Up @@ -1277,6 +1277,8 @@ void VariablesWidget::reSimulate()
initFile.close();
initFile.open(QIODevice::WriteOnly | QIODevice::Truncate);
QTextStream textStream(&initFile);
textStream.setCodec(Helper::utf8.toStdString().data());
textStream.setGenerateByteOrderMark(false);
textStream << initXmlDocument.toString();
initFile.close();
} else {
Expand Down
4 changes: 4 additions & 0 deletions OMEdit/OMEditGUI/main.cpp
Expand Up @@ -75,6 +75,8 @@
static inline void printStackTrace(QFile *pFile, int signalNumber, const char* signalName, unsigned int max_frames = 50)
{
QTextStream out(pFile);
out.setCodec(Helper::utf8.toStdString().data());
out.setGenerateByteOrderMark(false);
if (signalName)
out << QString("Caught signal %1 (%2)\n").arg(QString::number(signalNumber)).arg(signalName);
else
Expand Down Expand Up @@ -168,6 +170,8 @@ LONG WINAPI exceptionFilter(LPEXCEPTION_POINTERS info)
if (stackTraceFile.open(QIODevice::WriteOnly | QIODevice::Text))
{
QTextStream out(&stackTraceFile);
out.setCodec(Helper::utf8.toStdString().data());
out.setGenerateByteOrderMark(false);
out << g_output;
out.flush();
stackTraceFile.close();
Expand Down

0 comments on commit c05e51d

Please sign in to comment.