2011-06-05 14:45:39 +00:00
|
|
|
/*
|
2016-07-17 21:57:10 -04:00
|
|
|
Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
|
2014-08-11 17:00:55 +00:00
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
|
* Neither the name of the Universite de Sherbrooke nor the
|
|
|
|
|
names of its contributors may be used to endorse or promote products
|
|
|
|
|
derived from this software without specific prior written permission.
|
|
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
|
|
|
|
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
*/
|
2011-06-05 14:45:39 +00:00
|
|
|
|
2015-08-25 10:32:27 -04:00
|
|
|
#include "rtabmap/gui/ConsoleWidget.h"
|
2012-03-03 01:46:30 +00:00
|
|
|
#include "ui_consoleWidget.h"
|
2013-04-30 20:16:01 +00:00
|
|
|
#include <rtabmap/utilite/ULogger.h>
|
|
|
|
|
#include <rtabmap/utilite/UEventsManager.h>
|
2015-03-16 19:51:22 +00:00
|
|
|
#include <QMessageBox>
|
2012-03-03 01:46:30 +00:00
|
|
|
#include <QtGui/QTextCursor>
|
|
|
|
|
#include <QtCore/QTimer>
|
|
|
|
|
|
2011-06-05 14:45:39 +00:00
|
|
|
namespace rtabmap {
|
|
|
|
|
|
|
|
|
|
ConsoleWidget::ConsoleWidget(QWidget * parent) :
|
|
|
|
|
QWidget(parent)
|
|
|
|
|
{
|
2012-03-03 01:46:30 +00:00
|
|
|
_ui = new Ui_consoleWidget();
|
|
|
|
|
_ui->setupUi(this);
|
2011-06-05 14:45:39 +00:00
|
|
|
UEventsManager::addHandler(this);
|
2015-10-24 17:03:44 -04:00
|
|
|
_ui->textEdit->document()->setMaximumBlockCount(_ui->spinBox_lines->value());
|
2012-03-03 01:46:30 +00:00
|
|
|
_textCursor = new QTextCursor(_ui->textEdit->document());
|
|
|
|
|
_ui->textEdit->setFontPointSize(10);
|
|
|
|
|
QPalette p(_ui->textEdit->palette());
|
|
|
|
|
p.setColor(QPalette::Base, Qt::black);
|
|
|
|
|
_ui->textEdit->setPalette(p);
|
|
|
|
|
_errorMessage = new QMessageBox(QMessageBox::Critical, tr("Fatal error occurred"), "", QMessageBox::Ok, this);
|
|
|
|
|
_errorMessageMutex.lock();
|
|
|
|
|
_time.start();
|
|
|
|
|
_timer.setSingleShot(true);
|
|
|
|
|
connect(_ui->pushButton_clear, SIGNAL(clicked()), _ui->textEdit, SLOT(clear()));
|
2015-10-24 17:03:44 -04:00
|
|
|
connect(_ui->spinBox_lines, SIGNAL(valueChanged(int)), this, SLOT(updateTextEditBufferSize()));
|
2011-06-05 14:45:39 +00:00
|
|
|
connect(this, SIGNAL(msgReceived(const QString &, int)), this, SLOT(appendMsg(const QString &, int)));
|
2012-03-03 01:46:30 +00:00
|
|
|
connect(&_timer, SIGNAL(timeout()), this, SLOT(flushConsole()));
|
2011-06-05 14:45:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ConsoleWidget::~ConsoleWidget()
|
|
|
|
|
{
|
2012-03-03 01:46:30 +00:00
|
|
|
delete _ui;
|
2011-06-05 14:45:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ConsoleWidget::handleEvent(UEvent * anEvent)
|
|
|
|
|
{
|
|
|
|
|
// WARNING, don't put a log message here! otherwise it could be recursively called.
|
|
|
|
|
if(anEvent->getClassName().compare("ULogEvent") == 0)
|
|
|
|
|
{
|
|
|
|
|
ULogEvent * logEvent = (ULogEvent*)anEvent;
|
2012-03-03 01:46:30 +00:00
|
|
|
_msgListMutex.lock();
|
|
|
|
|
_msgList.append(QPair<QString, int>(logEvent->getMsg().c_str(), logEvent->getCode()));
|
2015-10-24 17:03:44 -04:00
|
|
|
while(_ui->spinBox_lines->value()>0 && _msgList.size()>_ui->spinBox_lines->value())
|
2012-03-03 01:46:30 +00:00
|
|
|
{
|
|
|
|
|
_msgList.pop_front();
|
|
|
|
|
}
|
|
|
|
|
_msgListMutex.unlock();
|
|
|
|
|
|
2015-10-24 17:03:44 -04:00
|
|
|
if(_ui->spinBox_time->value()>0 && _time.restart() < _ui->spinBox_time->value())
|
2012-03-03 01:46:30 +00:00
|
|
|
{
|
|
|
|
|
if(logEvent->getCode() == ULogger::kFatal)
|
|
|
|
|
{
|
2012-06-24 17:19:34 +00:00
|
|
|
QMetaObject::invokeMethod(&_timer, "start", Q_ARG(int, 0));
|
2012-03-03 01:46:30 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-10-24 17:03:44 -04:00
|
|
|
QMetaObject::invokeMethod(&_timer, "start", Q_ARG(int, _ui->spinBox_time->value()));
|
2012-03-03 01:46:30 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-06-24 17:19:34 +00:00
|
|
|
QMetaObject::invokeMethod(&_timer, "start", Q_ARG(int, 0));
|
2012-03-03 01:46:30 +00:00
|
|
|
}
|
|
|
|
|
|
2011-06-05 14:45:39 +00:00
|
|
|
if(logEvent->getCode() == ULogger::kFatal)
|
|
|
|
|
{
|
2012-03-03 01:46:30 +00:00
|
|
|
//This thread will wait until the message box is closed...
|
|
|
|
|
// Assuming that error messages come from a different thread.
|
|
|
|
|
_errorMessageMutex.lock();
|
2011-06-05 14:45:39 +00:00
|
|
|
}
|
2012-03-03 01:46:30 +00:00
|
|
|
|
2011-06-05 14:45:39 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ConsoleWidget::appendMsg(const QString & msg, int level)
|
|
|
|
|
{
|
|
|
|
|
switch(level)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
2012-03-03 01:46:30 +00:00
|
|
|
_ui->textEdit->setTextColor(Qt::darkGreen);
|
2011-06-05 14:45:39 +00:00
|
|
|
break;
|
|
|
|
|
case 2:
|
2012-03-03 01:46:30 +00:00
|
|
|
_ui->textEdit->setTextColor(Qt::yellow);
|
2011-06-05 14:45:39 +00:00
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
case 4:
|
2012-03-03 01:46:30 +00:00
|
|
|
_ui->textEdit->setTextColor(Qt::red);
|
2011-06-05 14:45:39 +00:00
|
|
|
break;
|
|
|
|
|
default:
|
2012-03-03 01:46:30 +00:00
|
|
|
_ui->textEdit->setTextColor(Qt::white);
|
2011-06-05 14:45:39 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2012-03-03 01:46:30 +00:00
|
|
|
_ui->textEdit->append(msg);
|
|
|
|
|
|
|
|
|
|
if(level == ULogger::kFatal)
|
|
|
|
|
{
|
|
|
|
|
_textCursor->endEditBlock();
|
|
|
|
|
QTextCursor cursor = _ui->textEdit->textCursor();
|
|
|
|
|
cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
|
|
|
|
|
_ui->textEdit->setTextCursor(cursor);
|
|
|
|
|
//The application will exit, so warn the user.
|
|
|
|
|
_errorMessage->setText(tr("Description:\n\n%1\n\nThe application will now exit...").arg(msg));
|
|
|
|
|
_errorMessage->exec();
|
|
|
|
|
_errorMessageMutex.unlock();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ConsoleWidget::flushConsole()
|
|
|
|
|
{
|
|
|
|
|
_msgListMutex.lock();
|
|
|
|
|
_textCursor->beginEditBlock();
|
|
|
|
|
for(int i=0; i<_msgList.size(); ++i)
|
|
|
|
|
{
|
|
|
|
|
appendMsg(_msgList[i].first, _msgList[i].second);
|
|
|
|
|
}
|
|
|
|
|
_textCursor->endEditBlock();
|
|
|
|
|
_msgList.clear();
|
|
|
|
|
_msgListMutex.unlock();
|
|
|
|
|
QTextCursor cursor = _ui->textEdit->textCursor();
|
|
|
|
|
cursor.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
|
|
|
|
|
_ui->textEdit->setTextCursor(cursor);
|
2011-06-05 14:45:39 +00:00
|
|
|
}
|
|
|
|
|
|
2015-10-24 17:03:44 -04:00
|
|
|
void ConsoleWidget::updateTextEditBufferSize()
|
|
|
|
|
{
|
|
|
|
|
_ui->textEdit->document()->setMaximumBlockCount(_ui->spinBox_lines->value());
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-05 14:45:39 +00:00
|
|
|
}
|