Skip to content

Commit

Permalink
ticket:4078 Check if the program to debug exists.
Browse files Browse the repository at this point in the history
Show the log-stream-output.
Moved the text cursor movement code to Utilities::insertText.
  • Loading branch information
adeas31 committed Nov 8, 2016
1 parent 2cc5196 commit 45442e0
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 192 deletions.
70 changes: 28 additions & 42 deletions OMEdit/OMEditGUI/Debugger/GDB/GDBAdapter.cpp
Expand Up @@ -92,15 +92,7 @@ GDBLoggerWidget::GDBLoggerWidget(MainWindow *pMainWindow)
*/
void GDBLoggerWidget::logDebuggerCommand(QString command)
{
// move the cursor down before adding to the logger.
QTextCursor textCursor = mpCommandsTextBox->textCursor();
textCursor.movePosition(QTextCursor::End);
mpCommandsTextBox->setTextCursor(textCursor);
// log command
mpCommandsTextBox->insertPlainText(command + "\n\n");
// move the cursor
textCursor.movePosition(QTextCursor::End);
mpCommandsTextBox->setTextCursor(textCursor);
Utilities::insertText(mpCommandsTextBox, command + "\n\n");
}

/*!
Expand Down Expand Up @@ -131,19 +123,10 @@ void GDBLoggerWidget::logDebuggerErrorResponse(QString response)
*/
void GDBLoggerWidget::logDebuggerResponse(QString response, QColor color)
{
// move the cursor down before adding to the logger.
QTextCursor textCursor = mpResponseTextBox->textCursor();
textCursor.movePosition(QTextCursor::End);
mpResponseTextBox->setTextCursor(textCursor);
// log response
QTextCharFormat charFormat = mpResponseTextBox->currentCharFormat();
charFormat.setForeground(color);
mpResponseTextBox->setCurrentCharFormat(charFormat);
QString newLine = response.endsWith("\n") ? "\n" : "\n\n";
mpResponseTextBox->insertPlainText(response + newLine);
// move the cursor
textCursor.movePosition(QTextCursor::End);
mpResponseTextBox->setTextCursor(textCursor);
QTextCharFormat format;
format.setForeground(color);
Utilities::insertText(mpResponseTextBox, response + newLine, format);
}

/*!
Expand Down Expand Up @@ -230,19 +213,16 @@ void TargetOutputWidget::logDebuggerErrorOutput(QString output)
*/
void TargetOutputWidget::logDebuggerOutput(QString output, QColor color)
{
// move the cursor down before adding to the logger.
QTextCursor tc = textCursor();
tc.movePosition(QTextCursor::End);
setTextCursor(tc);
// log response
QTextCharFormat charFormat = currentCharFormat();
charFormat.setForeground(color);
setCurrentCharFormat(charFormat);
mpMainWindow->getTargetOutputDockWidget()->show();
QList<QDockWidget*> tabifiedDockWidgetsList = mpMainWindow->tabifiedDockWidgets(mpMainWindow->getTargetOutputDockWidget());
if (tabifiedDockWidgetsList.size() > 0) {
mpMainWindow->tabifyDockWidget(tabifiedDockWidgetsList.at(0), mpMainWindow->getTargetOutputDockWidget());
}
// log the output
QString newLine = output.endsWith("\n") ? "" : "\n";
insertPlainText(output + newLine);
// move the cursor
tc.movePosition(QTextCursor::End);
setTextCursor(tc);
QTextCharFormat format;
format.setForeground(color);
Utilities::insertText(this, output + newLine, format);
}

/*!
Expand Down Expand Up @@ -295,6 +275,11 @@ GDBAdapter::GDBAdapter(MainWindow *pMainWindow)
*/
void GDBAdapter::launch(QString program, QString workingDirectory, QStringList arguments, QString GDBPath, SimulationOptions simulationOptions)
{
// check if the inferior exists
if (!QFile::exists(program)) {
mpMainWindow->getTargetOutputWidget()->logDebuggerErrorOutput(tr("The executable to debug does not exist: %1").arg(program));
return;
}
mpGDBProcess = new QProcess;
setGDBKilled(false);
#ifdef WIN32
Expand Down Expand Up @@ -322,13 +307,12 @@ void GDBAdapter::launch(QString program, QString workingDirectory, QStringList a
connect(mpGDBProcess, SIGNAL(started()), SLOT(handleGDBProcessStartedForSimulation()));
connect(mpGDBProcess, SIGNAL(finished(int)), SLOT(handleGDBProcessFinishedForSimulation(int)));
}
/*
launch gdb with the default arguments
-q quiet mode. Don't print welcome messages
-nw don't use window interface
-i select interface
mi machine interface
*/
/* launch gdb with the default arguments
* -q quiet mode. Don't print welcome messages
* -nw don't use window interface
* -i select interface
* mi machine interface
*/
mGDBProgram = GDBPath;
mGDBArguments.clear();
mInferiorArguments.clear();
Expand Down Expand Up @@ -1138,14 +1122,16 @@ void GDBAdapter::handleGDBMIConsoleStream(GDBMIStreamRecord *pGDBMIStreamRecord)

/*!
* \brief GDBAdapter::handleGDBMILogStream
* Handles the GDBMIStreamRecord.
* Handles the GDBMIStreamRecord.\n
* log-stream-output is output text coming from gdb's internals, for instance messages that should be displayed as part of an error log.\n
* All the log output is prefixed by ‘&’.
* \param pGDBMIStreamRecord
*/
void GDBAdapter::handleGDBMILogStream(GDBMIStreamRecord *pGDBMIStreamRecord)
{
QString LogData = StringHandler::unparse(pGDBMIStreamRecord->value.c_str());
mPendingLogStreamOutput += LogData;
/*! @todo What should we do with log stream???? */
mpMainWindow->getTargetOutputWidget()->logDebuggerErrorOutput(LogData);
}

/*!
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/MainWindow.h
Expand Up @@ -118,6 +118,7 @@ class MainWindow : public QMainWindow
BreakpointsWidget* getBreakpointsWidget() {return mpBreakpointsWidget;}
LocalsWidget* getLocalsWidget() {return mpLocalsWidget;}
TargetOutputWidget* getTargetOutputWidget() {return mpTargetOutputWidget;}
QDockWidget* getTargetOutputDockWidget() {return mpTargetOutputDockWidget;}
GDBLoggerWidget* getGDBLoggerWidget() {return mpGDBLoggerWidget;}
DocumentationWidget* getDocumentationWidget() {return mpDocumentationWidget;}
QDockWidget* getDocumentationDockWidget() {return mpDocumentationDockWidget;}
Expand Down
40 changes: 4 additions & 36 deletions OMEdit/OMEditGUI/OMC/OMCProxy.cpp
Expand Up @@ -317,28 +317,11 @@ QString OMCProxy::getResult()
*/
void OMCProxy::logCommand(QString command, QTime *commandTime)
{
// move the cursor down before adding to the logger.
const bool atBottom = mpOMCLoggerTextBox->verticalScrollBar()->value() == mpOMCLoggerTextBox->verticalScrollBar()->maximum();
if (!mOMCLoggerTextCursor.atEnd()) {
mOMCLoggerTextCursor.movePosition(QTextCursor::End);
}
// add the expression to commands list
mCommandsList.append(command);
// log expression
// insert the command to the logger window.
QFont font(Helper::monospacedFontInfo.family(), Helper::monospacedFontInfo.pointSize() - 2, QFont::Bold, false);
QTextCharFormat format;
format.setFont(font);
mOMCLoggerTextCursor.beginEditBlock();
mOMCLoggerTextCursor.insertText(command + "\n", format);
mOMCLoggerTextCursor.endEditBlock();
// move the cursor
if (atBottom) {
mpOMCLoggerTextBox->verticalScrollBar()->setValue(mpOMCLoggerTextBox->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.
mpOMCLoggerTextBox->verticalScrollBar()->setValue(mpOMCLoggerTextBox->verticalScrollBar()->maximum());
}
Utilities::insertText(mpOMCLoggerTextBox, command + "\n", format);
// set the current command index.
mCurrentCommandIndex = mCommandsList.count();
mpExpressionTextBox->setText("");
Expand All @@ -365,26 +348,11 @@ void OMCProxy::logCommand(QString command, QTime *commandTime)
*/
void OMCProxy::logResponse(QString response, QTime *responseTime)
{
// move the cursor down before adding to the logger.
const bool atBottom = mpOMCLoggerTextBox->verticalScrollBar()->value() == mpOMCLoggerTextBox->verticalScrollBar()->maximum();
if (!mOMCLoggerTextCursor.atEnd()) {
mOMCLoggerTextCursor.movePosition(QTextCursor::End);
}
// log expression
// insert the response to the logger window.
QFont font(Helper::monospacedFontInfo.family(), Helper::monospacedFontInfo.pointSize() - 2, QFont::Normal, false);
QTextCharFormat format;
format.setFont(font);
mOMCLoggerTextCursor.beginEditBlock();
mOMCLoggerTextCursor.insertText(response + "\n\n", format);
mOMCLoggerTextCursor.endEditBlock();
// move the cursor
if (atBottom) {
mpOMCLoggerTextBox->verticalScrollBar()->setValue(mpOMCLoggerTextBox->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.
mpOMCLoggerTextBox->verticalScrollBar()->setValue(mpOMCLoggerTextBox->verticalScrollBar()->maximum());
}
Utilities::insertText(mpOMCLoggerTextBox, response + "\n\n", format);
// write the log to communication log file
if (mCommunicationLogFileTextStream.device()) {
mCommunicationLogFileTextStream << QString("%1 %2\n").arg(response).arg(responseTime->currentTime().toString("hh:mm:ss:zzz"));
Expand Down
20 changes: 11 additions & 9 deletions OMEdit/OMEditGUI/Simulation/SimulationDialog.cpp
Expand Up @@ -1317,16 +1317,18 @@ void SimulationDialog::simulationProcessFinished(SimulationOptions simulationOpt
if (mpMainWindow->getOptionsDialog()->getSimulationPage()->getSwitchToPlottingPerspectiveCheckBox()->isChecked()) {
#if !defined(WITHOUT_OSG)
// if simulated with animation then open the animation directly.
if (mpLaunchAnimationCheckBox->isChecked() && simulationOptions.getResultFileName().endsWith(".mat")) {
mpMainWindow->getPlotWindowContainer()->addAnimationWindow(mpMainWindow->getPlotWindowContainer()->subWindowList().isEmpty());
AnimationWindow *pAnimationWindow = mpMainWindow->getPlotWindowContainer()->getCurrentAnimationWindow();
if (pAnimationWindow) {
pAnimationWindow->openAnimationFile(simulationOptions.getResultFileName());
if (mpLaunchAnimationCheckBox->isChecked()) {
if (simulationOptions.getResultFileName().endsWith(".mat")) {
mpMainWindow->getPlotWindowContainer()->addAnimationWindow(mpMainWindow->getPlotWindowContainer()->subWindowList().isEmpty());
AnimationWindow *pAnimationWindow = mpMainWindow->getPlotWindowContainer()->getCurrentAnimationWindow();
if (pAnimationWindow) {
pAnimationWindow->openAnimationFile(simulationOptions.getResultFileName());
}
} else {
QString msg = tr("Animation is only supported with mat result files.");
mpMainWindow->getMessagesWidget()->addGUIMessage(MessageItem(MessageItem::Modelica, "", false, 0, 0, 0, 0, msg,
Helper::scriptingKind, Helper::notificationLevel));
}
} else {
QString msg = tr("Animation is only supported with mat result files.");
mpMainWindow->getMessagesWidget()->addGUIMessage(MessageItem(MessageItem::Modelica, "", false, 0, 0, 0, 0, msg,
Helper::scriptingKind, Helper::notificationLevel));
}
#endif
mpMainWindow->getPerspectiveTabBar()->setCurrentIndex(2);
Expand Down
16 changes: 3 additions & 13 deletions OMEdit/OMEditGUI/Simulation/SimulationOutputWidget.cpp
Expand Up @@ -390,19 +390,9 @@ void SimulationOutputWidget::compilationProcessStarted()
void SimulationOutputWidget::writeCompilationOutput(QString output, QColor color)
{
mpGeneratedFilesTabWidget->setTabEnabled(1, true);
/* move the cursor down before adding to the logger. */
QTextCursor textCursor = mpCompilationOutputTextBox->textCursor();
textCursor.movePosition(QTextCursor::End);
mpCompilationOutputTextBox->setTextCursor(textCursor);
/* set the text color red */
QTextCharFormat charFormat = mpCompilationOutputTextBox->currentCharFormat();
charFormat.setForeground(color);
mpCompilationOutputTextBox->setCurrentCharFormat(charFormat);
/* append the output */
mpCompilationOutputTextBox->insertPlainText(output);
/* move the cursor */
textCursor.movePosition(QTextCursor::End);
mpCompilationOutputTextBox->setTextCursor(textCursor);
QTextCharFormat format;
format.setForeground(color);
Utilities::insertText(mpCompilationOutputTextBox, output, format);
/* make the compilation tab the current one */
mpGeneratedFilesTabWidget->setCurrentIndex(1);
}
Expand Down
19 changes: 1 addition & 18 deletions OMEdit/OMEditGUI/TLM/FetchInterfaceDataDialog.cpp
Expand Up @@ -135,26 +135,9 @@ void FetchInterfaceDataDialog::managerProcessStarted()
*/
void FetchInterfaceDataDialog::writeManagerOutput(QString output, StringHandler::SimulationMessageType type)
{
// move the cursor down before adding to the logger.
QTextCursor textCursor = mpOutputTextBox->textCursor();
const bool atBottom = mpOutputTextBox->verticalScrollBar()->value() == mpOutputTextBox->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) {
mpOutputTextBox->verticalScrollBar()->setValue(mpOutputTextBox->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.
mpOutputTextBox->verticalScrollBar()->setValue(mpOutputTextBox->verticalScrollBar()->maximum());
}
Utilities::insertText(mpOutputTextBox, output, format);
}

/*!
Expand Down

0 comments on commit 45442e0

Please sign in to comment.