Skip to content

Commit

Permalink
Using qt to start OMC in both OMNotebook and OMShell. No console wind…
Browse files Browse the repository at this point in the history
…ow is now neccessary for OMC.

// Anders Fernström

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@2214 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
x05andfe committed Mar 14, 2006
1 parent 1128b33 commit d1b5a5d
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 39 deletions.
20 changes: 10 additions & 10 deletions OMShell/QWinMosh.vcproj
Expand Up @@ -249,6 +249,15 @@
Name="Generated Files"
Filter="moc;h;cpp"
UniqueIdentifier="{71ED8ED8-ACB9-4CE9-BBE1-E00B30144E11}">
<File
RelativePath=".\generatedfiles\release\moc_omc_communicator.cpp">
<FileConfiguration
Name="Debug|Win32"
ExcludedFromBuild="TRUE">
<Tool
Name="VCCLCompilerTool"/>
</FileConfiguration>
</File>
<File
RelativePath=".\generatedfiles\debug\moc_omc_communicator.cpp">
<FileConfiguration
Expand All @@ -266,7 +275,7 @@
</FileConfiguration>
</File>
<File
RelativePath=".\generatedfiles\release\moc_omc_communicator.cpp">
RelativePath=".\GeneratedFiles\release\moc_oms.cpp">
<FileConfiguration
Name="Debug|Win32"
ExcludedFromBuild="TRUE">
Expand All @@ -290,15 +299,6 @@
ObjectFile="$(IntDir)/$(InputName)1.obj"/>
</FileConfiguration>
</File>
<File
RelativePath=".\GeneratedFiles\release\moc_oms.cpp">
<FileConfiguration
Name="Debug|Win32"
ExcludedFromBuild="TRUE">
<Tool
Name="VCCLCompilerTool"/>
</FileConfiguration>
</File>
<File
RelativePath=".\GeneratedFiles\qrc_oms.cpp">
</File>
Expand Down
52 changes: 23 additions & 29 deletions OMShell/omcinteractiveenvironment.cpp
Expand Up @@ -44,14 +44,12 @@ licence: http://www.trolltech.com/products/qt/licensing.html
------------------------------------------------------------------------------------
*/
#ifdef WIN32
#include "windows.h"
#endif

#include <exception>
#include <stdexcept>

#include <QtCore/QDir>
#include <QtCore/QProcess>
#include <QtGui/QMessageBox>

#include "omcinteractiveenvironment.h"
Expand Down Expand Up @@ -130,7 +128,6 @@ namespace IAEX
{
bool flag = false;

#ifdef WIN32
try
{
// 2006-02-28 AF, use environment varable to find omc.exe
Expand All @@ -148,45 +145,42 @@ namespace IAEX
OMCPath = "";
else
{
string msg = "Unable to find omc.exe, searched in:\n" +
string msg = "Unable to find OMC, searched in:\n" +
OMCPath + "\\bin\\\n" +
OMCPath + "\n" +
dir.absolutePath().toStdString();

throw std::exception( msg.c_str() );
}

STARTUPINFO startinfo;
PROCESS_INFORMATION procinfo;
memset(&startinfo, 0, sizeof(startinfo));
memset(&procinfo, 0, sizeof(procinfo));
startinfo.cb = sizeof(STARTUPINFO);
startinfo.wShowWindow = SW_MINIMIZE;
startinfo.dwFlags = STARTF_USESHOWWINDOW;

//string parameter = "\"omc.exe\" +d=interactiveCorba";
string parameter = "\"" + OMCPath + "omc.exe\" +d=interactiveCorba";
char *pParameter = new char[parameter.size() + 1];
const char *cpParameter = parameter.c_str();
strcpy(pParameter, cpParameter);

flag = CreateProcess(NULL,pParameter,NULL,NULL,FALSE,CREATE_NEW_CONSOLE,NULL,NULL,&startinfo,&procinfo);

Sleep(1000);
// 2006-03-14 AF, set omc loaction and parameters
QString omc;
#ifdef WIN32
omc = QString( OMCPath.c_str() ) + "omc.exe";
#else
omc = QString( OMCPath.c_str() ) + "omc";
#endif

QStringList parameters;
parameters << "+d=interactiveCorba";

// 2006-03-14 AF, create qt process
QProcess *omcProcess = new QProcess();

// 2006-03-14 AF, start omc
omcProcess->start( omc, parameters );
if( QProcess::Running == omcProcess->state() )
flag = true;
else
flag = false;

if( !flag )
throw std::exception("Was unable to start OMC");

}
catch( exception &e )
{
QString msg = e.what();
QMessageBox::warning( 0, "Error", msg, "OK" );
}
#else
QString msg = e.what();
msg += "\nOMC not started!";
QMessageBox::warning( 0, "Error", msg, "OK" );
#endif

return flag;
}
Expand Down
23 changes: 23 additions & 0 deletions OMShell/oms.cpp
Expand Up @@ -62,6 +62,7 @@ licence: http://www.trolltech.com/products/qt/licensing.html

//QT Headers
#include <QtCore/QStringList>
#include <QtCore/QThread>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QFileDialog>
Expand All @@ -86,6 +87,18 @@ licence: http://www.trolltech.com/products/qt/licensing.html

using namespace std;

//A small trick to get access to protected function in QThread.
class SleeperThread : public QThread
{
public:
static void msleep(unsigned long msecs)
{
QThread::msleep(msecs);
}
};

// ******************************************************

MyTextEdit::MyTextEdit( QWidget* parent )
: QTextEdit( parent )
{
Expand Down Expand Up @@ -683,6 +696,10 @@ void OMS::exceptionInEval(exception &e)
delegate_->closeConnection();
if( delegate_->startDelegate() )
{
// 2006-03-14 AF, wait before trying to reconnect,
// give OMC time to start up
SleeperThread::msleep( 1000 );

//delegate_->closeConnection();
try
{
Expand Down Expand Up @@ -1020,7 +1037,13 @@ bool OMS::startServer()
exit();
}
else
{
// 2006-03-14 AF, wait before trying to reconnect,
// give OMC time to start up
SleeperThread::msleep( 1000 );

omcNowStarted = true;
}
}

if( omcNowStarted )
Expand Down

0 comments on commit d1b5a5d

Please sign in to comment.