Skip to content

Commit

Permalink
- some minor changes for FMI.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@10046 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Oct 7, 2011
1 parent 07315ca commit e29ac3f
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 125 deletions.
8 changes: 4 additions & 4 deletions OMEdit/OMEditGUI/Component.cpp
Expand Up @@ -1151,8 +1151,8 @@ void Component::getClassComponents(QString className, int type, Component *pPare
{
QString result = mpOMCProxy->getIconAnnotation(componentProperties->getClassName());
Component *component;
component = new Component(result, componentsAnnotationsList.at(i), componentProperties,
StringHandler::ICON, true, pParent);
component = new Component(result, componentsAnnotationsList.at(i), componentProperties, StringHandler::ICON, true,
pParent);
mpComponentsList.append(component);
getClassComponents(componentProperties->getClassName(), StringHandler::ICON, component);
}
Expand All @@ -1171,8 +1171,8 @@ void Component::getClassComponents(QString className, int type, Component *pPare
{
QString result = mpOMCProxy->getDiagramAnnotation(componentProperties->getClassName());
Component *component;
component = new Component(result, componentsAnnotationsList.at(i), componentProperties,
StringHandler::DIAGRAM, true, pParent);
component = new Component(result, componentsAnnotationsList.at(i), componentProperties, StringHandler::DIAGRAM, true,
pParent);
mpComponentsList.append(component);
getClassComponents(componentProperties->getClassName(), StringHandler::DIAGRAM, component);
}
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/Helper.cpp
Expand Up @@ -43,6 +43,7 @@ QString Helper::omcServerName = "OMEdit";
QString Helper::omFileTypes = "Modelica Files (*.mo)";
QString Helper::omnotebookFileTypes = "OMNotebook Files (*.onb *.onbz *.nb)";
QString Helper::imageFileTypes = "Image Files (*.png *.svg *.bmp *.jpg)";
QString Helper::fmuFileTypes = "FMU Files (*.fmu)";
QString Helper::readOnly = QString("Read-Only");
QString Helper::writeAble = QString("Writeable");
QString Helper::iconView = QString("Icon View");
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/Helper.h
Expand Up @@ -50,6 +50,7 @@ class Helper
static QString omFileTypes;
static QString omnotebookFileTypes;
static QString imageFileTypes;
static QString fmuFileTypes;
static QString readOnly;
static QString writeAble;
static QString iconView;
Expand Down
146 changes: 55 additions & 91 deletions OMEdit/OMEditGUI/InteractiveSimulationTabWidget.cpp
Expand Up @@ -189,14 +189,6 @@ OMIProxy::OMIProxy(InteractiveSimulationTab *pParent)
mpControlClientTextEdit->setReadOnly(true);
mpControlClientTextEdit->setLineWrapMode(QTextEdit::WidgetWidth);
mpControlClientTextEdit->setAutoFormatting(QTextEdit::AutoNone);
// set the layout of OMI Logger dialog
QHBoxLayout *horizontallayout = new QHBoxLayout;
horizontallayout->setContentsMargins(0, 0, 0, 0);
mpExpressionTextBox = new OMICustomExpressionBox(this);
mpSendButton = new QPushButton("Send");
connect(mpSendButton, SIGNAL(pressed()), SLOT(sendCustomExpression()));
horizontallayout->addWidget(mpExpressionTextBox);
horizontallayout->addWidget(mpSendButton);
QVBoxLayout *verticalallayout = new QVBoxLayout;
verticalallayout->addWidget(mpOMIRuntiumeOutputLabel);
verticalallayout->addWidget(mpOMIRuntiumeOutputTextEdit);
Expand All @@ -206,7 +198,6 @@ OMIProxy::OMIProxy(InteractiveSimulationTab *pParent)
verticalallayout->addWidget(mpTransferServerTextEdit);
verticalallayout->addWidget(mpControlClientLabel);
verticalallayout->addWidget(mpControlClientTextEdit);
verticalallayout->addLayout(horizontallayout);
mpOMILogger->setLayout(verticalallayout);
// set isConnected to false
setConnected(false);
Expand Down Expand Up @@ -294,24 +285,20 @@ void OMIProxy::startInteractiveSimulation(QString file)
mpSimulationProcess->setWorkingDirectory(fileInfo.absolutePath());
connect(mpSimulationProcess, SIGNAL(readyReadStandardOutput()), SLOT(readProcessStandardOutput()));
connect(mpSimulationProcess, SIGNAL(readyReadStandardError()), SLOT(readProcessStandardError()));
// mpSimulationProcess->setStandardOutputFile(QString(filePath).append("_output.txt"));
// mpSimulationProcess->setStandardErrorFile(QString(filePath).append("_error.txt"));
mpSimulationProcess->start(file, parameters);
mpSimulationProcess->waitForStarted();
// start the client control server
mpControlServer = new OMIServer(this);
mpControlServer = new OMIServer(OMIServer::CONTROLSERVER, this);
mpControlServer->listen(QHostAddress(Helper::omi_network_address), Helper::omi_control_server_port);
connect(mpControlServer, SIGNAL(recievedMessage(QString)), SLOT(readControlServerMessage(QString)));
// start the transfer control server
mpTransferServer = new OMIServer(this);
mpTransferServer = new OMIServer(OMIServer::TRANSFERSERVER, this);
mpTransferServer->listen(QHostAddress(Helper::omi_network_address), Helper::omi_transfer_server_port);
// create the control client socket and make signals slots connections
mpControlClientSocket = new QTcpSocket(this);
connect(mpControlClientSocket, SIGNAL(connected()), SLOT(controlClientConnected()));
connect(mpControlClientSocket, SIGNAL(disconnected()), SLOT(controlClientDisConnected()));
// connect(mpControlClientSocket, SIGNAL(disconnected()), mpControlClientSocket, SLOT(deleteLater()));
connect(mpControlClientSocket, SIGNAL(error(QAbstractSocket::SocketError)),
SLOT(getSocketError(QAbstractSocket::SocketError)));
connect(mpControlClientSocket, SIGNAL(error(QAbstractSocket::SocketError)), SLOT(getSocketError(QAbstractSocket::SocketError)));
connect(mpTransferServer, SIGNAL(recievedMessage(QString)), SLOT(readTransferServerMessage(QString)));
// connect to omi control server
mpControlClientSocket->connectToHost(QHostAddress(Helper::omi_network_address), Helper::omi_control_client_port);
Expand Down Expand Up @@ -349,39 +336,20 @@ QString OMIProxy::getResult()

void OMIProxy::logOMIMessages(QString message)
{
mCommandsList.append(message);
// move the cursor down before adding to the logger.
QTextCursor textCursor = mpControlClientTextEdit->textCursor();
textCursor.movePosition(QTextCursor::End);
mpControlClientTextEdit->setTextCursor(textCursor);
// log message
mpControlClientTextEdit->setCurrentFont(QFont("Times New Roman", 10, QFont::Bold, false));
mpControlClientTextEdit->append(QString(">>---- Message Send : ").append(QTime::currentTime().toString())
.append(" ----"));

mpControlClientTextEdit->insertPlainText(QString(">>---- Message Send : ").append(QTime::currentTime().toString()).append(" ----"));
mpControlClientTextEdit->setCurrentFont(QFont("Times New Roman", 10, QFont::Normal, false));
mpControlClientTextEdit->insertPlainText(QString("\n>> ").append(message).append("\n"));
// scroll the text to end
QTextCursor textCursor = mpControlClientTextEdit->textCursor();
// move the cursor
textCursor.movePosition(QTextCursor::End);
mpControlClientTextEdit->setTextCursor(textCursor);
}

void OMIProxy::getPreviousCommand()
{
if (mCommandsList.isEmpty())
return;
mpExpressionTextBox->setText(mCommandsList.at(mCommandsList.count() - 1));
QString tempCommand = mCommandsList.at(mCommandsList.count() - 1);
mCommandsList.insert(0, tempCommand);
mCommandsList.removeLast();
}

void OMIProxy::getNextCommand()
{
if (mCommandsList.isEmpty())
return;
mpExpressionTextBox->setText(mCommandsList.at(0));
QString tempCommand = mCommandsList.at(0);
mCommandsList.append(tempCommand);
mCommandsList.removeFirst();
}

//! Opens the OMI Logger dialog.
void OMIProxy::openOMILogger()
{
Expand All @@ -403,31 +371,42 @@ void OMIProxy::controlClientDisConnected()

void OMIProxy::readControlServerMessage(QString message)
{
// move the cursor down before adding to the logger.
QTextCursor textCursor = mpControlServerTextEdit->textCursor();
textCursor.movePosition(QTextCursor::End);
mpControlServerTextEdit->setTextCursor(textCursor);
// log message
mpControlServerTextEdit->setCurrentFont(QFont("Times New Roman", 10, QFont::Bold, false));
mpControlServerTextEdit->append(QString(">>---- Message Received : ").append(QTime::currentTime().toString())
.append(" ----"));

mpControlServerTextEdit->insertPlainText(QString(">>---- Message Received : ").append(QTime::currentTime().toString()).append(" ----"));
mpControlServerTextEdit->setCurrentFont(QFont("Times New Roman", 10, QFont::Normal, false));
mpControlServerTextEdit->insertPlainText(QString("\n>> ").append(message).append("\n"));
// scroll the text to end
QTextCursor textCursor = mpControlServerTextEdit->textCursor();
// move the cursor
textCursor.movePosition(QTextCursor::End);
mpControlServerTextEdit->setTextCursor(textCursor);
}

void OMIProxy::readTransferServerMessage(QString message)
{
// send the message to interactive simulation widget
emit sendResult(message);
/* QTimer and QSignalMapper are the best :) */
QSignalMapper *pSingnalMapper = new QSignalMapper;
QTimer *pTimer = new QTimer;
pTimer->setSingleShot(true);
pTimer->setInterval(1000); // 1 sec
connect(pTimer, SIGNAL(timeout()), pSingnalMapper, SLOT(map()));
pSingnalMapper->setMapping(pTimer, message);
connect(pSingnalMapper, SIGNAL(mapped(QString)), mpInteractiveSimulationTab, SLOT(recievedResult(QString)));
pTimer->start();
// move the cursor down before adding to the logger.
QTextCursor textCursor = mpTransferServerTextEdit->textCursor();
textCursor.movePosition(QTextCursor::End);
mpTransferServerTextEdit->setTextCursor(textCursor);
// log the message
mpTransferServerTextEdit->setCurrentFont(QFont("Times New Roman", 10, QFont::Bold, false));
mpTransferServerTextEdit->append(QString(">>---- Message Received : ").append(QTime::currentTime().toString())
.append(" ----"));

mpTransferServerTextEdit->insertPlainText(QString(">>---- Message Received : ").append(QTime::currentTime().toString()).append(" ----"));
mpTransferServerTextEdit->setCurrentFont(QFont("Times New Roman", 10, QFont::Normal, false));
mpTransferServerTextEdit->insertPlainText(QString("\n>> ").append(message).append("\n"));
// scroll the text to end
QTextCursor textCursor = mpTransferServerTextEdit->textCursor();
// move the cursor
textCursor.movePosition(QTextCursor::End);
mpTransferServerTextEdit->setTextCursor(textCursor);
}
Expand Down Expand Up @@ -472,39 +451,9 @@ void OMIProxy::getSocketError(QAbstractSocket::SocketError socketError)
setErrorOccurred(true);
}

void OMIProxy::sendCustomExpression()
{
if (mpExpressionTextBox->text().isEmpty())
return;

sendMessage(mpExpressionTextBox->text());
mpExpressionTextBox->setText(QString());
}

//! @class OMICustomExpressionBox
OMICustomExpressionBox::OMICustomExpressionBox(OMIProxy *pParent)
{
mpParentOMIProxy = pParent;
}

void OMICustomExpressionBox::keyPressEvent(QKeyEvent *event)
{
switch (event->key())
{
case Qt::Key_Up:
mpParentOMIProxy->getPreviousCommand();
break;
case Qt::Key_Down:
mpParentOMIProxy->getNextCommand();
break;
default:
QLineEdit::keyPressEvent(event);
}
}

//! @class OMIServer
OMIServer::OMIServer(OMIProxy *pParent)
: QTcpServer(pParent)
OMIServer::OMIServer(int serverType, OMIProxy *pParent)
: mServerType(serverType), QTcpServer(pParent)
{
mpOMIProxy = pParent;
}
Expand All @@ -514,9 +463,27 @@ OMIServer::~OMIServer()

}

int OMIServer::getServerType()
{
return mServerType;
}

void OMIServer::readMessages()
{
emit recievedMessage(QString(mTcpSocket.read(1024)));
if (getServerType() == OMIServer::CONTROLSERVER)
{
emit recievedMessage(QString(mTcpSocket.read(mTcpSocket.bytesAvailable())));
}
else if (getServerType() == OMIServer::TRANSFERSERVER)
{
QString message(mTcpSocket.read(mTcpSocket.bytesAvailable()));
QStringList messages = message.split("end", QString::SkipEmptyParts);

foreach (QString msg, messages)
{
emit recievedMessage(msg.append("end"));
}
}
}

void OMIServer::incomingConnection(int socketDescriptor)
Expand All @@ -527,7 +494,6 @@ void OMIServer::incomingConnection(int socketDescriptor)
return;
}
connect(&mTcpSocket, SIGNAL(readyRead()), SLOT(readMessages()));
// connect(&mTcpSocket, SIGNAL(disconnected()), &mTcpSocket, SLOT(deleteLater()));
}

//! @class InteractiveSimulation
Expand All @@ -538,7 +504,6 @@ InteractiveSimulationTab::InteractiveSimulationTab(QString filePath, Interactive
// create the OMIProxy instance
mpOMIProxy = new OMIProxy(this);
connect(mpOMIProxy, SIGNAL(interactiveSimulationStarted(QString)), SLOT(readParametersandVariables(QString)));
connect(mpOMIProxy, SIGNAL(sendResult(QString)), SLOT(recievedResult(QString)));
// create the plot window
mpPlotWindow = new PlotWindow();
mpPlotWindow->setTitle(tr(""));
Expand Down Expand Up @@ -788,7 +753,6 @@ void InteractiveSimulationTab::initializeInteractivePlotting()
{
pPlotCurve->detach();
mpPlotWindow->getPlot()->removeCurve(pPlotCurve);
mpPlotWindow->getPlot()->replot();
}
}

Expand Down Expand Up @@ -818,7 +782,6 @@ void InteractiveSimulationTab::initializeInteractivePlotting()
pPlotCurve->setTitle(variable->text());
pPlotCurve->attach(mpPlotWindow->getPlot());
mpPlotWindow->getPlot()->addPlotCurve(pPlotCurve);
mpPlotWindow->getPlot()->replot();
}
}
}
Expand Down Expand Up @@ -873,6 +836,8 @@ void InteractiveSimulationTab::recievedResult(QString message)
int count = 0;
QStringList list = message.split("#", QString::SkipEmptyParts);
// remove first and last from list, since first is "result" and last is "end" and we don't need them
if (list.size() < 4)
return;
list.removeFirst();
list.removeLast();

Expand All @@ -886,7 +851,6 @@ void InteractiveSimulationTab::recievedResult(QString message)
pPlotCurve->addXAxisValue(time);
pPlotCurve->addYAxisValue(element);
pPlotCurve->setRawData(pPlotCurve->getXAxisVector(), pPlotCurve->getYAxisVector(), pPlotCurve->getSize());
mpPlotWindow->getPlot()->replot();
count++;
}
}
Expand Down
23 changes: 4 additions & 19 deletions OMEdit/OMEditGUI/InteractiveSimulationTabWidget.h
Expand Up @@ -89,7 +89,6 @@ public slots:
};

class OMIServer;
class OMICustomExpressionBox;

class OMIProxy : public QObject
{
Expand All @@ -100,13 +99,11 @@ class OMIProxy : public QObject
OMIServer *mpTransferServer;
QTcpSocket *mpControlClientSocket;
QProcess *mpSimulationProcess;

int mMessageCounter;
bool mIsConnected;
bool mErrorOccurred;
QString mResult;
QDialog *mpOMILogger;
OMICustomExpressionBox *mpExpressionTextBox;
QPushButton *mpSendButton;
QLabel *mpOMIRuntiumeOutputLabel;
QTextEdit *mpOMIRuntiumeOutputTextEdit;
Expand All @@ -116,7 +113,6 @@ class OMIProxy : public QObject
QTextEdit *mpTransferServerTextEdit;
QLabel *mpControlClientLabel;
QTextEdit *mpControlClientTextEdit;
QList<QString> mCommandsList;
public:
OMIProxy(InteractiveSimulationTab *pParent);
~OMIProxy();
Expand All @@ -132,12 +128,9 @@ class OMIProxy : public QObject
void setResult(QString result);
QString getResult();
void logOMIMessages(QString message);
void getPreviousCommand();
void getNextCommand();
signals:
void interactiveSimulationStarted(QString filePath);
void interactiveSimulationFinished();
void sendResult(QString);
public slots:
void openOMILogger();
void controlClientConnected();
Expand All @@ -147,17 +140,6 @@ public slots:
void readProcessStandardOutput();
void readProcessStandardError();
void getSocketError(QAbstractSocket::SocketError socketError);
void sendCustomExpression();
};

class OMICustomExpressionBox : public QLineEdit
{
public:
OMICustomExpressionBox(OMIProxy *pParent);

OMIProxy *mpParentOMIProxy;
protected:
virtual void keyPressEvent(QKeyEvent *event);
};

class OMIServer : public QTcpServer
Expand All @@ -166,9 +148,12 @@ class OMIServer : public QTcpServer
private:
QTcpSocket mTcpSocket;
OMIProxy *mpOMIProxy;
int mServerType;
public:
OMIServer(OMIProxy *pParent);
OMIServer(int serverType, OMIProxy *pParent);
~OMIServer();
enum serverType {CONTROLSERVER, TRANSFERSERVER};
int getServerType();
signals:
void recievedMessage(QString message);
public slots:
Expand Down
6 changes: 6 additions & 0 deletions OMEdit/OMEditGUI/OMCProxy.cpp
Expand Up @@ -1396,6 +1396,12 @@ bool OMCProxy::translateModelFMU(QString modelName)
return false;
}

bool OMCProxy::importFMU(QString fmuName)
{
sendCommand("importFMU(\"" + fmuName + "\")");
return StringHandler::unparseBool(getResult());
}

CustomExpressionBox::CustomExpressionBox(OMCProxy *pParent)
{
mpParentOMCProxy = pParent;
Expand Down

0 comments on commit e29ac3f

Please sign in to comment.