00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <QColorDialog>
00020 #include <QFileDialog>
00021
00022 #include <ros/package.h>
00023
00024 #include <rqt_multiplot/PlotTableWidget.h>
00025 #include <rqt_multiplot/PlotWidget.h>
00026
00027 #include <ui_PlotTableConfigWidget.h>
00028
00029 #include "rqt_multiplot/PlotTableConfigWidget.h"
00030
00031 namespace rqt_multiplot {
00032
00033
00034
00035
00036
00037 PlotTableConfigWidget::PlotTableConfigWidget(QWidget* parent) :
00038 QWidget(parent),
00039 ui_(new Ui::PlotTableConfigWidget()),
00040 menuImportExport_(new QMenu(this)),
00041 config_(0),
00042 plotTable_(0) {
00043 ui_->setupUi(this);
00044
00045 ui_->labelBackgroundColor->setAutoFillBackground(true);
00046 ui_->labelForegroundColor->setAutoFillBackground(true);
00047
00048 ui_->widgetProgress->setEnabled(false);
00049
00050 ui_->pushButtonRun->setIcon(
00051 QIcon(QString::fromStdString(ros::package::getPath("rqt_multiplot").
00052 append("/resource/16x16/run.png"))));
00053 ui_->pushButtonPause->setIcon(
00054 QIcon(QString::fromStdString(ros::package::getPath("rqt_multiplot").
00055 append("/resource/16x16/pause.png"))));
00056 ui_->pushButtonClear->setIcon(
00057 QIcon(QString::fromStdString(ros::package::getPath("rqt_multiplot").
00058 append("/resource/16x16/clear.png"))));
00059 ui_->pushButtonImportExport->setIcon(
00060 QIcon(QString::fromStdString(ros::package::getPath("rqt_multiplot").
00061 append("/resource/16x16/eject.png"))));
00062
00063 ui_->pushButtonPause->setEnabled(false);
00064
00065 menuImportExport_->addAction("Import from bag file...", this,
00066 SLOT(menuImportBagFileTriggered()));
00067 menuImportExport_->addSeparator();
00068 menuImportExport_->addAction("Export to image file...", this,
00069 SLOT(menuExportImageFileTriggered()));
00070 menuImportExport_->addAction("Export to text file...", this,
00071 SLOT(menuExportTextFileTriggered()));
00072
00073 connect(ui_->spinBoxRows, SIGNAL(valueChanged(int)), this,
00074 SLOT(spinBoxRowsValueChanged(int)));
00075 connect(ui_->spinBoxColumns, SIGNAL(valueChanged(int)), this,
00076 SLOT(spinBoxColumnsValueChanged(int)));
00077
00078 connect(ui_->checkBoxLinkScale, SIGNAL(stateChanged(int)), this,
00079 SLOT(checkBoxLinkScaleStateChanged(int)));
00080 connect(ui_->checkBoxLinkCursor, SIGNAL(stateChanged(int)), this,
00081 SLOT(checkBoxLinkCursorStateChanged(int)));
00082 connect(ui_->checkBoxTrackPoints, SIGNAL(stateChanged(int)), this,
00083 SLOT(checkBoxTrackPointsStateChanged(int)));
00084
00085 connect(ui_->pushButtonRun, SIGNAL(clicked()), this,
00086 SLOT(pushButtonRunClicked()));
00087 connect(ui_->pushButtonPause, SIGNAL(clicked()), this,
00088 SLOT(pushButtonPauseClicked()));
00089 connect(ui_->pushButtonClear, SIGNAL(clicked()), this,
00090 SLOT(pushButtonClearClicked()));
00091 connect(ui_->pushButtonImportExport, SIGNAL(clicked()), this,
00092 SLOT(pushButtonImportExportClicked()));
00093
00094 ui_->labelBackgroundColor->installEventFilter(this);
00095 ui_->labelForegroundColor->installEventFilter(this);
00096 }
00097
00098 PlotTableConfigWidget::~PlotTableConfigWidget() {
00099 delete ui_;
00100 }
00101
00102
00103
00104
00105
00106 void PlotTableConfigWidget::setConfig(PlotTableConfig* config) {
00107 if (config != config_) {
00108 if (config_) {
00109 disconnect(config_, SIGNAL(backgroundColorChanged(const QColor&)),
00110 this, SLOT(configBackgroundColorChanged(const QColor&)));
00111 disconnect(config_, SIGNAL(foregroundColorChanged(const QColor&)),
00112 this, SLOT(configForegroundColorChanged(const QColor&)));
00113 disconnect(config_, SIGNAL(numPlotsChanged(size_t, size_t)),
00114 this, SLOT(configNumPlotsChanged(size_t, size_t)));
00115 disconnect(config_, SIGNAL(linkScaleChanged(bool)),
00116 this, SLOT(configLinkScaleChanged(bool)));
00117 disconnect(config_, SIGNAL(linkCursorChanged(bool)),
00118 this, SLOT(configLinkCursorChanged(bool)));
00119 disconnect(config_, SIGNAL(trackPointsChanged(bool)),
00120 this, SLOT(configTrackPointsChanged(bool)));
00121 }
00122
00123 config_ = config;
00124
00125 if (config) {
00126 connect(config, SIGNAL(backgroundColorChanged(const QColor&)),
00127 this, SLOT(configBackgroundColorChanged(const QColor&)));
00128 connect(config, SIGNAL(foregroundColorChanged(const QColor&)),
00129 this, SLOT(configForegroundColorChanged(const QColor&)));
00130 connect(config, SIGNAL(numPlotsChanged(size_t, size_t)),
00131 this, SLOT(configNumPlotsChanged(size_t, size_t)));
00132 connect(config, SIGNAL(linkScaleChanged(bool)),
00133 this, SLOT(configLinkScaleChanged(bool)));
00134 connect(config, SIGNAL(linkCursorChanged(bool)),
00135 this, SLOT(configLinkCursorChanged(bool)));
00136 connect(config, SIGNAL(trackPointsChanged(bool)),
00137 this, SLOT(configTrackPointsChanged(bool)));
00138
00139 configBackgroundColorChanged(config->getBackgroundColor());
00140 configForegroundColorChanged(config->getForegroundColor());
00141 configNumPlotsChanged(config->getNumRows(), config->getNumColumns());
00142 configLinkScaleChanged(config_->isScaleLinked());
00143 configLinkCursorChanged(config_->isCursorLinked());
00144 configTrackPointsChanged(config_->arePointsTracked());
00145 }
00146 }
00147 }
00148
00149 PlotTableConfig* PlotTableConfigWidget::getConfig() const {
00150 return config_;
00151 }
00152
00153 void PlotTableConfigWidget::setPlotTable(PlotTableWidget* plotTable) {
00154 if (plotTable != plotTable_) {
00155 if (plotTable_) {
00156 disconnect(plotTable_, SIGNAL(plotPausedChanged()),
00157 this, SLOT(plotTablePlotPausedChanged()));
00158 disconnect(plotTable_, SIGNAL(jobStarted(const QString&)),
00159 this, SLOT(plotTableJobStarted(const QString&)));
00160 disconnect(plotTable_, SIGNAL(jobProgressChanged(double)),
00161 this, SLOT(plotTableJobProgressChanged(double)));
00162 disconnect(plotTable_, SIGNAL(jobFinished(const QString&)),
00163 this, SLOT(plotTableJobFinished(const QString&)));
00164 disconnect(plotTable_, SIGNAL(jobFailed(const QString&)),
00165 this, SLOT(plotTableJobFailed(const QString&)));
00166 }
00167
00168 plotTable_ = plotTable;
00169
00170 if (plotTable) {
00171 connect(plotTable, SIGNAL(plotPausedChanged()),
00172 this, SLOT(plotTablePlotPausedChanged()));
00173 connect(plotTable, SIGNAL(jobStarted(const QString&)),
00174 this, SLOT(plotTableJobStarted(const QString&)));
00175 connect(plotTable, SIGNAL(jobProgressChanged(double)),
00176 this, SLOT(plotTableJobProgressChanged(double)));
00177 connect(plotTable, SIGNAL(jobFinished(const QString&)),
00178 this, SLOT(plotTableJobFinished(const QString&)));
00179 connect(plotTable, SIGNAL(jobFailed(const QString&)),
00180 this, SLOT(plotTableJobFailed(const QString&)));
00181
00182 plotTablePlotPausedChanged();
00183 }
00184 }
00185 }
00186
00187 PlotTableWidget* PlotTableConfigWidget::getPlotTableWidget() const {
00188 return plotTable_;
00189 }
00190
00191 void PlotTableConfigWidget::runPlots() {
00192 if (plotTable_) {
00193 plotTable_->runPlots();
00194 }
00195 }
00196
00197
00198
00199
00200
00201 bool PlotTableConfigWidget::eventFilter(QObject* object, QEvent* event) {
00202 if (config_) {
00203 if (((object == ui_->labelBackgroundColor) ||
00204 (object == ui_->labelForegroundColor)) &&
00205 (event->type() == QEvent::MouseButtonPress)) {
00206 QColorDialog dialog(this);
00207
00208 dialog.setCurrentColor((object == ui_->labelBackgroundColor) ?
00209 config_->getBackgroundColor() : config_->getForegroundColor());
00210
00211 if (dialog.exec() == QDialog::Accepted) {
00212 if (object == ui_->labelBackgroundColor)
00213 config_->setBackgroundColor(dialog.currentColor());
00214 else
00215 config_->setForegroundColor(dialog.currentColor());
00216 }
00217 }
00218 }
00219
00220 return false;
00221 }
00222
00223
00224
00225
00226
00227 void PlotTableConfigWidget::configBackgroundColorChanged(const QColor&
00228 color) {
00229 QPalette palette = ui_->labelBackgroundColor->palette();
00230 palette.setColor(QPalette::Window, color);
00231
00232 ui_->labelBackgroundColor->setPalette(palette);
00233 }
00234
00235 void PlotTableConfigWidget::configForegroundColorChanged(const QColor&
00236 color) {
00237 QPalette palette = ui_->labelForegroundColor->palette();
00238 palette.setColor(QPalette::Window, color);
00239
00240 ui_->labelForegroundColor->setPalette(palette);
00241 }
00242
00243 void PlotTableConfigWidget::configNumPlotsChanged(size_t numRows, size_t
00244 numColumns) {
00245 ui_->spinBoxRows->setValue(numRows);
00246 ui_->spinBoxColumns->setValue(numColumns);
00247 }
00248
00249 void PlotTableConfigWidget::configLinkScaleChanged(bool link) {
00250 ui_->checkBoxLinkScale->setCheckState(link ? Qt::Checked : Qt::Unchecked);
00251 }
00252
00253 void PlotTableConfigWidget::configLinkCursorChanged(bool link) {
00254 ui_->checkBoxLinkCursor->setCheckState(link ? Qt::Checked : Qt::Unchecked);
00255 }
00256
00257 void PlotTableConfigWidget::configTrackPointsChanged(bool track) {
00258 ui_->checkBoxTrackPoints->setCheckState(track ? Qt::Checked :
00259 Qt::Unchecked);
00260 }
00261
00262 void PlotTableConfigWidget::spinBoxRowsValueChanged(int value) {
00263 if (config_)
00264 config_->setNumRows(value);
00265 }
00266
00267 void PlotTableConfigWidget::spinBoxColumnsValueChanged(int value) {
00268 if (config_)
00269 config_->setNumColumns(value);
00270 }
00271
00272 void PlotTableConfigWidget::checkBoxLinkScaleStateChanged(int state) {
00273 if (config_)
00274 config_->setLinkScale(state == Qt::Checked);
00275 }
00276
00277 void PlotTableConfigWidget::checkBoxLinkCursorStateChanged(int state) {
00278 if (config_)
00279 config_->setLinkCursor(state == Qt::Checked);
00280 }
00281
00282 void PlotTableConfigWidget::checkBoxTrackPointsStateChanged(int state) {
00283 if (config_)
00284 config_->setTrackPoints(state == Qt::Checked);
00285 }
00286
00287 void PlotTableConfigWidget::pushButtonRunClicked() {
00288 if (plotTable_)
00289 plotTable_->runPlots();
00290 }
00291
00292 void PlotTableConfigWidget::pushButtonPauseClicked() {
00293 if (plotTable_)
00294 plotTable_->pausePlots();
00295 }
00296
00297 void PlotTableConfigWidget::pushButtonClearClicked() {
00298 if (plotTable_)
00299 plotTable_->clearPlots();
00300 }
00301
00302 void PlotTableConfigWidget::pushButtonImportExportClicked() {
00303 menuImportExport_->popup(QCursor::pos());
00304 }
00305
00306 void PlotTableConfigWidget::menuImportBagFileTriggered() {
00307 QFileDialog dialog(this, "Open Bag", QDir::homePath(),
00308 "ROS Bag (*.bag)");
00309
00310 dialog.setAcceptMode(QFileDialog::AcceptOpen);
00311 dialog.setFileMode(QFileDialog::ExistingFile);
00312
00313 if (dialog.exec() == QDialog::Accepted)
00314 plotTable_->loadFromBagFile(dialog.selectedFiles().first());
00315 }
00316
00317 void PlotTableConfigWidget::menuExportImageFileTriggered() {
00318 QFileDialog dialog(this, "Save Image File", QDir::homePath(),
00319 "Portable Network Graphics (*.png)");
00320
00321 dialog.setAcceptMode(QFileDialog::AcceptSave);
00322 dialog.setFileMode(QFileDialog::AnyFile);
00323 dialog.selectFile("rqt_multiplot.png");
00324
00325 if (dialog.exec() == QDialog::Accepted)
00326 plotTable_->saveToImageFile(dialog.selectedFiles().first());
00327 }
00328
00329 void PlotTableConfigWidget::menuExportTextFileTriggered() {
00330 QFileDialog dialog(this, "Save Text File", QDir::homePath(),
00331 "Text file (*.txt)");
00332
00333 dialog.setAcceptMode(QFileDialog::AcceptSave);
00334 dialog.setFileMode(QFileDialog::AnyFile);
00335 dialog.selectFile("rqt_multiplot.txt");
00336
00337 if (dialog.exec() == QDialog::Accepted)
00338 plotTable_->saveToTextFile(dialog.selectedFiles().first());
00339 }
00340
00341 void PlotTableConfigWidget::plotTablePlotPausedChanged() {
00342 if (plotTable_) {
00343 bool allPlotsPaused = true;
00344 bool anyPlotPaused = false;
00345
00346 for (size_t row = 0; row < plotTable_->getNumRows(); ++row) {
00347 for (size_t column = 0; column < plotTable_->getNumColumns();
00348 ++column) {
00349 allPlotsPaused &= plotTable_->getPlotWidget(row, column)->isPaused();
00350 anyPlotPaused |= plotTable_->getPlotWidget(row, column)->isPaused();
00351 }
00352 }
00353
00354 ui_->pushButtonRun->setEnabled(anyPlotPaused);
00355 ui_->pushButtonPause->setEnabled(!allPlotsPaused);
00356 }
00357 }
00358
00359 void PlotTableConfigWidget::plotTableJobStarted(const QString& toolTip) {
00360 ui_->widgetProgress->setEnabled(true);
00361
00362 ui_->widgetProgress->start(toolTip);
00363 }
00364
00365 void PlotTableConfigWidget::plotTableJobProgressChanged(double progress) {
00366 ui_->widgetProgress->setCurrentProgress(progress);
00367 }
00368
00369 void PlotTableConfigWidget::plotTableJobFinished(const QString& toolTip) {
00370 ui_->widgetProgress->finish(toolTip);
00371 }
00372
00373 void PlotTableConfigWidget::plotTableJobFailed(const QString& toolTip) {
00374 ui_->widgetProgress->fail(toolTip);
00375 }
00376
00377 }