CurveAxisConfigWidget.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002  * Copyright (C) 2015 by Ralf Kaestner                                        *
00003  * ralf.kaestner@gmail.com                                                    *
00004  *                                                                            *
00005  * This program is free software; you can redistribute it and/or modify       *
00006  * it under the terms of the Lesser GNU General Public License as published by*
00007  * the Free Software Foundation; either version 3 of the License, or          *
00008  * (at your option) any later version.                                        *
00009  *                                                                            *
00010  * This program is distributed in the hope that it will be useful,            *
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the               *
00013  * Lesser GNU General Public License for more details.                        *
00014  *                                                                            *
00015  * You should have received a copy of the Lesser GNU General Public License   *
00016  * along with this program. If not, see <http://www.gnu.org/licenses/>.       *
00017  ******************************************************************************/
00018 
00019 #include <ros/package.h>
00020 
00021 #include <ui_CurveAxisConfigWidget.h>
00022 
00023 #include "rqt_multiplot/CurveAxisConfigWidget.h"
00024 
00025 namespace rqt_multiplot {
00026 
00027 /*****************************************************************************/
00028 /* Constructors and Destructor                                               */
00029 /*****************************************************************************/
00030 
00031 CurveAxisConfigWidget::CurveAxisConfigWidget(QWidget* parent) :
00032   QWidget(parent),
00033   ui_(new Ui::CurveAxisConfigWidget()),
00034   config_(0) {
00035   ui_->setupUi(this);
00036 
00037   QPixmap pixmapOkay = QPixmap(QString::fromStdString(ros::package::getPath(
00038     "rqt_multiplot").append("/resource/22x22/okay.png")));
00039   QPixmap pixmapError = QPixmap(QString::fromStdString(ros::package::getPath(
00040     "rqt_multiplot").append("/resource/22x22/error.png")));
00041   QPixmap pixmapBusy = QPixmap(QString::fromStdString(ros::package::getPath(
00042     "rqt_multiplot").append("/resource/22x22/busy.png")));
00043   
00044   ui_->statusWidgetTopic->setIcon(StatusWidget::Okay, pixmapOkay);
00045   ui_->statusWidgetTopic->setIcon(StatusWidget::Error, pixmapError);
00046   ui_->statusWidgetTopic->setFrames(StatusWidget::Busy, pixmapBusy, 8);
00047   
00048   ui_->statusWidgetType->setIcon(StatusWidget::Okay, pixmapOkay);
00049   ui_->statusWidgetType->setIcon(StatusWidget::Error, pixmapError);
00050   ui_->statusWidgetType->setFrames(StatusWidget::Busy, pixmapBusy, 8);
00051 
00052   ui_->statusWidgetField->setIcon(StatusWidget::Okay, pixmapOkay);
00053   ui_->statusWidgetField->setIcon(StatusWidget::Error, pixmapError);
00054   ui_->statusWidgetField->setFrames(StatusWidget::Busy, pixmapBusy, 8);
00055   
00056   ui_->statusWidgetScale->setIcon(StatusWidget::Okay, pixmapOkay);
00057   ui_->statusWidgetScale->setIcon(StatusWidget::Error, pixmapError);
00058   ui_->statusWidgetScale->setFrames(StatusWidget::Busy, pixmapBusy, 8);
00059   
00060   connect(ui_->comboBoxTopic, SIGNAL(updateStarted()), this,
00061     SLOT(comboBoxTopicUpdateStarted()));
00062   connect(ui_->comboBoxTopic, SIGNAL(updateFinished()), this,
00063     SLOT(comboBoxTopicUpdateFinished()));  
00064   connect(ui_->comboBoxTopic, SIGNAL(currentTopicChanged(const QString&)),
00065     this, SLOT(comboBoxTopicCurrentTopicChanged(const QString&)));
00066   
00067   connect(ui_->comboBoxType, SIGNAL(updateStarted()), this,
00068     SLOT(comboBoxTypeUpdateStarted()));
00069   connect(ui_->comboBoxType, SIGNAL(updateFinished()), this,
00070     SLOT(comboBoxTypeUpdateFinished()));  
00071   connect(ui_->comboBoxType, SIGNAL(currentTypeChanged(const QString&)),
00072     this, SLOT(comboBoxTypeCurrentTypeChanged(const QString&)));
00073   
00074   connect(ui_->widgetField, SIGNAL(loadingStarted()), this,
00075     SLOT(widgetFieldLoadingStarted()));
00076   connect(ui_->widgetField, SIGNAL(loadingFinished()), this,
00077     SLOT(widgetFieldLoadingFinished()));
00078   connect(ui_->widgetField, SIGNAL(loadingFailed(const QString&)),
00079     this, SLOT(widgetFieldLoadingFailed(const QString&)));
00080   connect(ui_->widgetField, SIGNAL(connecting(const QString&)), this,
00081     SLOT(widgetFieldConnecting(const QString&)));
00082   connect(ui_->widgetField, SIGNAL(connected(const QString&)), this,
00083     SLOT(widgetFieldConnected(const QString&)));
00084   connect(ui_->widgetField, SIGNAL(connectionTimeout(const QString&,
00085     double)), this, SLOT(widgetFieldConnectionTimeout(const QString&,
00086     double)));
00087   connect(ui_->widgetField, SIGNAL(currentFieldChanged(const QString&)),
00088     this, SLOT(widgetFieldCurrentFieldChanged(const QString&)));
00089   
00090   connect(ui_->checkBoxFieldReceiptTime, SIGNAL(stateChanged(int)), this,
00091     SLOT(checkBoxFieldReceiptTimeStateChanged(int)));
00092   
00093   if (ui_->comboBoxTopic->isUpdating())
00094     comboBoxTopicUpdateStarted();
00095   else
00096     comboBoxTopicUpdateFinished();
00097   
00098   if (ui_->comboBoxType->isUpdating())
00099     comboBoxTypeUpdateStarted();
00100   else
00101     comboBoxTypeUpdateFinished();
00102 }
00103 
00104 CurveAxisConfigWidget::~CurveAxisConfigWidget() {
00105   delete ui_;
00106 }
00107 
00108 /*****************************************************************************/
00109 /* Accessors                                                                 */
00110 /*****************************************************************************/
00111 
00112 void CurveAxisConfigWidget::setConfig(CurveAxisConfig* config) {
00113   if (config_ != config) {
00114     if (config_) {
00115       disconnect(config_, SIGNAL(topicChanged(const QString&)), this,
00116         SLOT(configTopicChanged(const QString&)));
00117       disconnect(config_, SIGNAL(typeChanged(const QString&)), this,
00118         SLOT(configTypeChanged(const QString&)));
00119       disconnect(config_, SIGNAL(fieldTypeChanged(int)), this,
00120         SLOT(configFieldTypeChanged(int)));
00121       disconnect(config_, SIGNAL(fieldChanged(const QString&)), this,
00122         SLOT(configFieldChanged(const QString&)));
00123       disconnect(config_->getScaleConfig(), SIGNAL(changed()), this,
00124         SLOT(configScaleConfigChanged()));
00125     }
00126     
00127     config_ = config;
00128     
00129     if (config) {
00130       ui_->widgetScale->setConfig(config->getScaleConfig());
00131             
00132       connect(config, SIGNAL(topicChanged(const QString&)), this,
00133         SLOT(configTopicChanged(const QString&)));
00134       connect(config, SIGNAL(typeChanged(const QString&)), this,
00135         SLOT(configTypeChanged(const QString&)));
00136       connect(config, SIGNAL(fieldTypeChanged(int)), this,
00137         SLOT(configFieldTypeChanged(int)));
00138       connect(config, SIGNAL(fieldChanged(const QString&)), this,
00139         SLOT(configFieldChanged(const QString&)));
00140       connect(config->getScaleConfig(), SIGNAL(changed()), this,
00141         SLOT(configScaleConfigChanged()));
00142       
00143       configTopicChanged(config->getTopic());
00144       configTypeChanged(config->getType());
00145       configFieldTypeChanged(config->getFieldType());
00146       configFieldChanged(config->getField());
00147       configScaleConfigChanged();
00148     }
00149     else {
00150       ui_->widgetScale->setConfig(0);
00151     }
00152   }
00153 }
00154 
00155 CurveAxisConfig* CurveAxisConfigWidget::getConfig() const {
00156   return config_;
00157 }
00158 
00159 /*****************************************************************************/
00160 /* Methods                                                                   */
00161 /*****************************************************************************/
00162 
00163 void CurveAxisConfigWidget::updateTopics() {
00164   ui_->comboBoxTopic->updateTopics();
00165 }
00166 
00167 void CurveAxisConfigWidget::updateTypes() {
00168   ui_->comboBoxType->updateTypes();
00169 }
00170 
00171 void CurveAxisConfigWidget::updateFields() {
00172   if (config_)
00173     ui_->widgetField->loadFields(config_->getType());
00174 }
00175 
00176 bool CurveAxisConfigWidget::validateTopic() {
00177   if (!config_ || ui_->comboBoxTopic->isUpdating())
00178     return false;
00179   
00180   if (config_->getTopic().isEmpty()) {
00181     ui_->statusWidgetTopic->setCurrentRole(StatusWidget::Error,
00182       "No topic selected");
00183     
00184     return false;
00185   }
00186   
00187   if (ui_->comboBoxTopic->isCurrentTopicRegistered()) {
00188     ui_->statusWidgetTopic->setCurrentRole(StatusWidget::Okay,
00189       "Topic okay");
00190     
00191     return true;
00192   }
00193   else {
00194     ui_->statusWidgetTopic->setCurrentRole(StatusWidget::Error,
00195       "Topic ["+config_->getTopic()+"] not advertised");
00196     
00197     return false;
00198   }
00199 }
00200 
00201 bool CurveAxisConfigWidget::validateType() {
00202   if (!config_ || ui_->comboBoxType->isUpdating())
00203     return false;
00204 
00205   if (config_->getType().isEmpty()) {
00206     ui_->statusWidgetType->setCurrentRole(StatusWidget::Error,
00207       "No message type selected");
00208     
00209     return false;
00210   }
00211   
00212   if (!ui_->comboBoxTopic->isCurrentTopicRegistered()) {
00213     if (ui_->comboBoxType->isCurrentTypeRegistered()) {
00214       ui_->statusWidgetType->setCurrentRole(StatusWidget::Okay,
00215         "Message type okay");
00216       
00217       return true;
00218     }
00219     else {
00220       ui_->statusWidgetType->setCurrentRole(StatusWidget::Error,
00221         "Message type ["+config_->getType()+"] not found in package path");
00222       
00223       return false;
00224     }
00225   }
00226   else {
00227     if (ui_->comboBoxTopic->getCurrentTopicType() == config_->getType()) {
00228       ui_->statusWidgetType->setCurrentRole(StatusWidget::Okay,
00229         "Message type okay");
00230       
00231       return true;
00232     }
00233     else {
00234       ui_->statusWidgetType->setCurrentRole(StatusWidget::Error,
00235         "Message type ["+config_->getType()+
00236         "] mismatches advertised message type ["
00237         +ui_->comboBoxTopic->getCurrentTopicType()+"] for topic ["+
00238         config_->getTopic()+"]");
00239       
00240       return false;
00241     }
00242   }  
00243 }
00244 
00245 bool CurveAxisConfigWidget::validateField() {
00246   if (!config_ || ui_->widgetField->isLoading())
00247     return false;
00248   
00249   if (config_->getFieldType() == CurveAxisConfig::MessageReceiptTime) {
00250     ui_->statusWidgetField->setCurrentRole(StatusWidget::Okay,
00251       "Message field okay");
00252     
00253     return true;
00254   }
00255   
00256   if (config_->getField().isEmpty()) {
00257     ui_->statusWidgetField->setCurrentRole(StatusWidget::Error,
00258       "No message field selected");
00259     
00260     return false;
00261   }
00262   
00263   variant_topic_tools::DataType fieldType = ui_->widgetField->
00264     getCurrentFieldDataType();  
00265   
00266   if (fieldType.isValid()) {
00267     if (fieldType.isBuiltin() && variant_topic_tools::
00268         BuiltinDataType(fieldType).isNumeric()) {
00269       ui_->statusWidgetField->setCurrentRole(StatusWidget::Okay,
00270         "Message field okay");
00271     
00272       return true;
00273     }
00274     else {
00275       ui_->statusWidgetField->setCurrentRole(StatusWidget::Error,
00276         "Message field ["+config_->getField()+"] is not numeric");
00277       
00278       return false;
00279     }
00280   }
00281   else {
00282     ui_->statusWidgetField->setCurrentRole(StatusWidget::Error,
00283       "No such message field ["+config_->getField()+"]");
00284     
00285     return false;
00286   }
00287 }
00288 
00289 bool CurveAxisConfigWidget::validateScale() {
00290   if (!config_)
00291     return false;
00292   
00293   if (!config_->getScaleConfig()->isValid()) {
00294     ui_->statusWidgetScale->setCurrentRole(StatusWidget::Error,
00295       "Axis scale invalid");
00296     
00297     return false;
00298   }
00299   else {
00300     ui_->statusWidgetScale->setCurrentRole(StatusWidget::Okay,
00301       "Axis scale okay");
00302     
00303     return true;
00304   }
00305 }
00306 
00307 /*****************************************************************************/
00308 /* Slots                                                                     */
00309 /*****************************************************************************/
00310 
00311 void CurveAxisConfigWidget::configTopicChanged(const QString& topic) {
00312   ui_->comboBoxTopic->setCurrentTopic(topic);
00313   
00314   validateTopic();
00315 }
00316 
00317 void CurveAxisConfigWidget::configTypeChanged(const QString& type) {
00318   ui_->comboBoxType->setCurrentType(type);
00319   
00320   validateType();
00321 }
00322 
00323 void CurveAxisConfigWidget::configFieldTypeChanged(int fieldType) {
00324   ui_->checkBoxFieldReceiptTime->setCheckState(
00325     (fieldType == CurveAxisConfig::MessageReceiptTime) ?
00326     Qt::Checked : Qt::Unchecked);
00327   
00328   validateType();
00329 }
00330 
00331 void CurveAxisConfigWidget::configFieldChanged(const QString& field) {
00332   ui_->widgetField->setCurrentField(field);
00333   
00334   validateField();
00335 }
00336 
00337 void CurveAxisConfigWidget::configScaleConfigChanged() {
00338   validateScale();
00339 }
00340 
00341 void CurveAxisConfigWidget::comboBoxTopicUpdateStarted() {
00342   ui_->statusWidgetTopic->pushCurrentRole();
00343   ui_->statusWidgetTopic->setCurrentRole(StatusWidget::Busy,
00344     "Updating topics...");
00345 }
00346 
00347 void CurveAxisConfigWidget::comboBoxTopicUpdateFinished() {
00348   ui_->statusWidgetTopic->popCurrentRole();
00349   
00350   validateTopic();
00351 }
00352 
00353 void CurveAxisConfigWidget::comboBoxTopicCurrentTopicChanged(const QString&
00354     topic) {
00355   if (config_) {
00356     config_->setTopic(topic);
00357     
00358     if (ui_->comboBoxTopic->isCurrentTopicRegistered())
00359       config_->setType(ui_->comboBoxTopic->getCurrentTopicType());
00360   }
00361   
00362   validateTopic();
00363 }
00364 
00365 void CurveAxisConfigWidget::comboBoxTypeUpdateStarted() {
00366   ui_->statusWidgetType->pushCurrentRole();
00367   ui_->statusWidgetType->setCurrentRole(StatusWidget::Busy,
00368     "Updating message types...");
00369 }
00370 
00371 void CurveAxisConfigWidget::comboBoxTypeUpdateFinished() {
00372   ui_->statusWidgetType->popCurrentRole();
00373   
00374   validateType();
00375 }
00376 
00377 void CurveAxisConfigWidget::comboBoxTypeCurrentTypeChanged(const QString&
00378     type) {
00379   if (config_)
00380     config_->setType(type);
00381   
00382   validateType();
00383   updateFields();
00384 }
00385 
00386 void CurveAxisConfigWidget::widgetFieldLoadingStarted() {
00387   ui_->widgetField->setEnabled(false);
00388   
00389   ui_->statusWidgetField->pushCurrentRole();
00390   ui_->statusWidgetField->setCurrentRole(StatusWidget::Busy,
00391     "Loading message definition...");
00392 }
00393 
00394 void CurveAxisConfigWidget::widgetFieldLoadingFinished() {
00395   ui_->widgetField->setEnabled(ui_->checkBoxFieldReceiptTime->
00396     checkState() != Qt::Checked);
00397   ui_->statusWidgetField->popCurrentRole();
00398   
00399   validateField();
00400 }
00401 
00402 void CurveAxisConfigWidget::widgetFieldLoadingFailed(const QString&
00403     error) {
00404   ui_->statusWidgetField->popCurrentRole();
00405   
00406   if (config_ && (ui_->comboBoxTopic->getCurrentTopicType() == config_->
00407       getType()))
00408     ui_->widgetField->connectTopic(config_->getTopic());
00409   else
00410     validateField();
00411 }
00412 
00413 void CurveAxisConfigWidget::widgetFieldConnecting(const QString& topic) {
00414   ui_->widgetField->setEnabled(false);
00415   
00416   ui_->statusWidgetField->pushCurrentRole();
00417   ui_->statusWidgetField->setCurrentRole(StatusWidget::Busy,
00418     "Waiting for connnection on topic ["+topic+"]...");
00419 }
00420 
00421 void CurveAxisConfigWidget::widgetFieldConnected(const QString& topic) {
00422   ui_->widgetField->setEnabled(ui_->checkBoxFieldReceiptTime->
00423     checkState() != Qt::Checked);
00424   ui_->statusWidgetField->popCurrentRole();  
00425   
00426   validateField();
00427 }
00428 
00429 void CurveAxisConfigWidget::widgetFieldConnectionTimeout(const QString&
00430     topic, double timeout) {
00431   ui_->statusWidgetField->popCurrentRole();
00432   
00433   validateField();
00434 }
00435 
00436 void CurveAxisConfigWidget::widgetFieldCurrentFieldChanged(const QString&
00437     field) {
00438   if (config_)
00439     config_->setField(field);
00440   
00441   validateField();
00442 }
00443 
00444 void CurveAxisConfigWidget::checkBoxFieldReceiptTimeStateChanged(int state) {
00445   ui_->widgetField->setEnabled(state != Qt::Checked);
00446   
00447   if (config_)
00448     config_->setFieldType((state == Qt::Checked) ?
00449       CurveAxisConfig::MessageReceiptTime : CurveAxisConfig::MessageData);
00450     
00451   validateField();
00452 }
00453 
00454 }


rqt_multiplot
Author(s): Ralf Kaestner
autogenerated on Thu Jun 6 2019 21:49:10