Skip to content

Commit

Permalink
Fixed printing the output of manager and monitor.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Sep 28, 2016
1 parent a4b17ce commit ebbfe52
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 30 deletions.
62 changes: 38 additions & 24 deletions OMEdit/OMEditGUI/TLM/TLMCoSimulationOutputWidget.cpp
Expand Up @@ -211,19 +211,26 @@ void TLMCoSimulationOutputWidget::managerProcessStarted()
*/
void TLMCoSimulationOutputWidget::writeManagerOutput(QString output, StringHandler::SimulationMessageType type)
{
/* move the cursor down before adding to the logger. */
// move the cursor down before adding to the logger.
QTextCursor textCursor = mpManagerOutputTextBox->textCursor();
textCursor.movePosition(QTextCursor::End);
mpManagerOutputTextBox->setTextCursor(textCursor);
/* set the text color */
QTextCharFormat charFormat = mpManagerOutputTextBox->currentCharFormat();
charFormat.setForeground(StringHandler::getSimulationMessageTypeColor(type));
mpManagerOutputTextBox->setCurrentCharFormat(charFormat);
/* append the output */
mpManagerOutputTextBox->insertPlainText(output + "\n");
/* move the cursor */
textCursor.movePosition(QTextCursor::End);
mpManagerOutputTextBox->setTextCursor(textCursor);
const bool atBottom = mpManagerOutputTextBox->verticalScrollBar()->value() == mpManagerOutputTextBox->verticalScrollBar()->maximum();
if (!textCursor.atEnd()) {
textCursor.movePosition(QTextCursor::End);
}
// set the text color
QTextCharFormat format;
format.setForeground(StringHandler::getSimulationMessageTypeColor(type));
textCursor.beginEditBlock();
textCursor.insertText(output, format);
textCursor.endEditBlock();
// move the cursor
if (atBottom) {
mpManagerOutputTextBox->verticalScrollBar()->setValue(mpManagerOutputTextBox->verticalScrollBar()->maximum());
// QPlainTextEdit destroys the first calls value in case of multiline
// text, so make sure that the scroll bar actually gets the value set.
// Is a noop if the first call succeeded.
mpManagerOutputTextBox->verticalScrollBar()->setValue(mpManagerOutputTextBox->verticalScrollBar()->maximum());
}
}

/*!
Expand Down Expand Up @@ -254,19 +261,26 @@ void TLMCoSimulationOutputWidget::monitorProcessStarted()
*/
void TLMCoSimulationOutputWidget::writeMonitorOutput(QString output, StringHandler::SimulationMessageType type)
{
/* move the cursor down before adding to the logger. */
// move the cursor down before adding to the logger.
QTextCursor textCursor = mpMonitorOutputTextBox->textCursor();
textCursor.movePosition(QTextCursor::End);
mpMonitorOutputTextBox->setTextCursor(textCursor);
/* set the text color */
QTextCharFormat charFormat = mpMonitorOutputTextBox->currentCharFormat();
charFormat.setForeground(StringHandler::getSimulationMessageTypeColor(type));
mpMonitorOutputTextBox->setCurrentCharFormat(charFormat);
/* append the output */
mpMonitorOutputTextBox->insertPlainText(output + "\n");
/* move the cursor */
textCursor.movePosition(QTextCursor::End);
mpMonitorOutputTextBox->setTextCursor(textCursor);
const bool atBottom = mpMonitorOutputTextBox->verticalScrollBar()->value() == mpMonitorOutputTextBox->verticalScrollBar()->maximum();
if (!textCursor.atEnd()) {
textCursor.movePosition(QTextCursor::End);
}
// set the text color
QTextCharFormat format;
format.setForeground(StringHandler::getSimulationMessageTypeColor(type));
textCursor.beginEditBlock();
textCursor.insertText(output, format);
textCursor.endEditBlock();
// move the cursor
if (atBottom) {
mpMonitorOutputTextBox->verticalScrollBar()->setValue(mpManagerOutputTextBox->verticalScrollBar()->maximum());
// QPlainTextEdit destroys the first calls value in case of multiline
// text, so make sure that the scroll bar actually gets the value set.
// Is a noop if the first call succeeded.
mpMonitorOutputTextBox->verticalScrollBar()->setValue(mpManagerOutputTextBox->verticalScrollBar()->maximum());
}
}

/*!
Expand Down
12 changes: 6 additions & 6 deletions OMEdit/OMEditGUI/TLM/TLMCoSimulationThread.cpp
Expand Up @@ -105,7 +105,7 @@ void TLMCoSimulationThread::runManager()
// start the executable
mpManagerProcess->start(fileName, args);
mManagerProcessId = Utilities::getProcessId(mpManagerProcess);
emit sendManagerOutput(QString("%1 %2").arg(fileName).arg(args.join(" ")), StringHandler::OMEditInfo);
emit sendManagerOutput(QString("%1 %2\n").arg(fileName).arg(args.join(" ")), StringHandler::OMEditInfo);
}

void TLMCoSimulationThread::runMonitor()
Expand Down Expand Up @@ -134,7 +134,7 @@ void TLMCoSimulationThread::runMonitor()
environment.insert("TLMPluginPath", tlmCoSimulationOptions.getTLMPluginPath());
mpMonitorProcess->setProcessEnvironment(environment);
mpMonitorProcess->start(fileName, args);
emit sendMonitorOutput(QString("%1 %2").arg(fileName).arg(args.join(" ")), StringHandler::OMEditInfo);
emit sendMonitorOutput(QString("%1 %2\n").arg(fileName).arg(args.join(" ")), StringHandler::OMEditInfo);
}

/*!
Expand Down Expand Up @@ -174,9 +174,9 @@ void TLMCoSimulationThread::readManagerStandardError()
void TLMCoSimulationThread::managerProcessFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
setIsManagerProcessRunning(false);
QString exitCodeStr = tr("TLMManager process failed. Exited with code %1.").arg(QString::number(exitCode));
QString exitCodeStr = tr("TLMManager process failed. Exited with code %1.\n").arg(QString::number(exitCode));
if (exitStatus == QProcess::NormalExit && exitCode == 0) {
emit sendManagerOutput(tr("TLMManager process finished successfully."), StringHandler::OMEditInfo);
emit sendManagerOutput(tr("TLMManager process finished successfully.\n"), StringHandler::OMEditInfo);
} else if (mpManagerProcess->error() == QProcess::UnknownError) {
emit sendManagerOutput(exitCodeStr, StringHandler::Error);
} else {
Expand Down Expand Up @@ -243,9 +243,9 @@ void TLMCoSimulationThread::monitorProcessFinished(int exitCode, QProcess::ExitS
if (mpProgressFileTimer) {
mpProgressFileTimer->stop();
}
QString exitCodeStr = tr("TLMMonitor process failed. Exited with code %1.").arg(QString::number(exitCode));
QString exitCodeStr = tr("TLMMonitor process failed. Exited with code %1.\n").arg(QString::number(exitCode));
if (exitStatus == QProcess::NormalExit && exitCode == 0) {
emit sendMonitorOutput(tr("TLMMonitor process finished successfully."), StringHandler::OMEditInfo);
emit sendMonitorOutput(tr("TLMMonitor process finished successfully.\n"), StringHandler::OMEditInfo);
} else if (mpMonitorProcess->error() == QProcess::UnknownError) {
emit sendMonitorOutput(exitCodeStr, StringHandler::Error);
} else {
Expand Down

0 comments on commit ebbfe52

Please sign in to comment.