stdr_info_connector.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002    STDR Simulator - Simple Two DImensional Robot Simulator
00003    Copyright (C) 2013 STDR Simulator
00004    This program is free software; you can redistribute it and/or modify
00005    it under the terms of the GNU General Public License as published by
00006    the Free Software Foundation; either version 3 of the License, or
00007    (at your option) any later version.
00008    This program is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011    GNU General Public License for more details.
00012    You should have received a copy of the GNU General Public License
00013    along with this program; if not, write to the Free Software Foundation,
00014    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
00015    
00016    Authors : 
00017    * Manos Tsardoulias, etsardou@gmail.com
00018    * Aris Thallas, aris.thallas@gmail.com
00019    * Chris Zalidis, zalidis@gmail.com 
00020 ******************************************************************************/
00021 
00022 #include "stdr_gui/stdr_info_connector.h"
00023 
00024 namespace stdr_gui
00025 {
00032   CInfoConnector::CInfoConnector(int argc, char **argv):
00033     QObject(),
00034     loader(argc,argv),
00035     argc_(argc),
00036     argv_(argv)
00037   {
00038     QObject::connect(
00039       loader.stdrInformationTree,
00040         SIGNAL(itemClicked(QTreeWidgetItem*, int)),
00041       this,
00042         SLOT(treeItemClicked(QTreeWidgetItem*, int)));
00043         
00044     QObject::connect(
00045       this,
00046         SIGNAL(adaptSignal()),
00047       this,
00048         SLOT(adaptSlot()));
00049         
00050     QObject::connect(
00051       loader.stdrInformationTree, 
00052         SIGNAL(itemCollapsed(QTreeWidgetItem *)),
00053       this, 
00054         SLOT(adaptColumns(QTreeWidgetItem *)));
00055         
00056     QObject::connect(
00057       loader.stdrInformationTree, 
00058         SIGNAL(itemExpanded(QTreeWidgetItem *)),
00059       this, 
00060         SLOT(adaptColumns(QTreeWidgetItem *)));
00061   }
00062 
00069   void CInfoConnector::adaptColumns(QTreeWidgetItem *item, int column)
00070   {
00071     loader.stdrInformationTree->resizeColumnToContents(0);
00072     loader.stdrInformationTree->resizeColumnToContents(1);
00073     loader.stdrInformationTree->resizeColumnToContents(2);
00074     loader.stdrInformationTree->resizeColumnToContents(3);
00075   }
00076   
00082   void CInfoConnector::adaptColumns(QTreeWidgetItem *item)
00083   {
00084     loader.stdrInformationTree->resizeColumnToContents(0);
00085     loader.stdrInformationTree->resizeColumnToContents(1);
00086     loader.stdrInformationTree->resizeColumnToContents(2);
00087     loader.stdrInformationTree->resizeColumnToContents(3);
00088   }
00089   
00094   void CInfoConnector::adaptSlot(void)
00095   {
00096     loader.stdrInformationTree->resizeColumnToContents(0);
00097     loader.stdrInformationTree->resizeColumnToContents(1);
00098     loader.stdrInformationTree->resizeColumnToContents(2);
00099     loader.stdrInformationTree->resizeColumnToContents(3);
00100   }
00101 
00109   void CInfoConnector::updateMapInfo(float width,float height,float ocgd)
00110   {
00111     loader.updateMapInfo(width,height,ocgd);
00112     Q_EMIT adaptSignal();
00113   }
00114   
00120   void CInfoConnector::updateTree(
00121     const stdr_msgs::RobotIndexedVectorMsg& msg)
00122   {
00123     
00124     loader.deleteTree();
00125     loader.updateRobots(msg);
00126     
00127     Q_EMIT adaptSignal();
00128   }
00129   
00136   void CInfoConnector::treeItemClicked ( QTreeWidgetItem * item, int column )
00137   {
00138     adaptColumns(item, column);
00139     if(item == &loader.robotsInfo || item == &loader.generalInfo)
00140     {
00141       return;
00142     }
00143     else if(item->parent()->text(0) == QString("Lasers") && column == 3)
00144     {
00145       Q_EMIT laserVisualizerClicked(
00146         item->parent()->parent()->text(0), item->text(0));
00147     }
00148     else if(item->parent()->text(0) == QString("Lasers") && column == 2)
00149     {
00150       Q_EMIT laserVisibilityClicked(
00151         item->parent()->parent()->text(0), item->text(0));
00152     }
00153     else if(item->parent()->text(0) == QString("Sonars") && column == 3)
00154     {
00155       Q_EMIT sonarVisualizerClicked(
00156         item->parent()->parent()->text(0),item->text(0));
00157     }
00158     else if(item->parent()->text(0) == QString("Sonars") && column == 2)
00159     {
00160       Q_EMIT sonarVisibilityClicked(
00161         item->parent()->parent()->text(0),item->text(0));
00162     }
00163     else if(item->parent()->text(0) == QString("RFID readers") && column == 2)
00164     {
00165       Q_EMIT rfidReaderVisibilityClicked(
00166         item->parent()->parent()->text(0), item->text(0));
00167     }
00168     else if(item->parent()->text(0) == QString("CO2 sensors") && column == 2)
00169     {
00170       Q_EMIT co2SensorVisibilityClicked(
00171         item->parent()->parent()->text(0), item->text(0));
00172     }
00173     else if(item->parent()->text(0) == QString("Thermal sensors") && column == 2)
00174     {
00175       Q_EMIT thermalSensorVisibilityClicked(
00176         item->parent()->parent()->text(0), item->text(0));
00177     }
00178     else if(item->parent()->text(0) == QString("Sound sensors") && column == 2)
00179     {
00180       Q_EMIT soundSensorVisibilityClicked(
00181         item->parent()->parent()->text(0), item->text(0));
00182     }
00183     else if(item->parent() == &loader.robotsInfo && column == 3)
00184     {
00185       Q_EMIT robotVisualizerClicked(
00186         item->text(0));
00187     }
00188     else if(item->parent() == &loader.robotsInfo && column == 2)
00189     {
00190       Q_EMIT robotVisibilityClicked(
00191         item->text(0));
00192     }
00193   }
00194   
00199   QWidget* CInfoConnector::getLoader(void)
00200   {
00201     return static_cast<QWidget *>(&loader);
00202   }
00203   
00211   void CInfoConnector::setLaserVisibility(
00212     QString robotName,QString laserName,char vs)
00213   {
00214     for(int i = 0 ; i < loader.robotsInfo.childCount() ; i++)
00215     {
00216       QString text = loader.robotsInfo.child(i)->text(0);
00217       if(text == robotName)
00218       {
00219         QTreeWidgetItem *it = loader.robotsInfo.child(i);
00220         for(int j = 0 ; j < it->childCount() ; j++)
00221         {
00222           if(it->child(j)->text(0) == QString("Lasers"))
00223           {
00224             for(int k = 0 ; k < it->child(j)->childCount() ; k++)
00225             {
00226               if(it->child(j)->child(k)->text(0) == laserName)
00227               {
00228                 QTreeWidgetItem *inIt = it->child(j)->child(k);
00229                 switch(vs)
00230                 {
00231                   case 0:
00232                   {
00233                     inIt->setIcon(2,loader.visible_icon_on_);
00234                     break;
00235                   }
00236                   case 1:
00237                   {
00238                     inIt->setIcon(2,loader.visible_icon_trans_);
00239                     break;
00240                   }
00241                   case 2:
00242                   {
00243                     inIt->setIcon(2,loader.visible_icon_off_);
00244                     break;
00245                   }
00246                 }
00247                 return;
00248               }
00249             }
00250           }
00251         }
00252       }
00253     }
00254   }
00255   
00263   void CInfoConnector::setSonarVisibility(
00264     QString robotName,QString sonarName,char vs)
00265   {
00266     for(int i = 0 ; i < loader.robotsInfo.childCount() ; i++)
00267     {
00268       QString text = loader.robotsInfo.child(i)->text(0);
00269       if(text == robotName)
00270       {
00271         QTreeWidgetItem *it = loader.robotsInfo.child(i);
00272         for(int j = 0 ; j < it->childCount() ; j++)
00273         {
00274           if(it->child(j)->text(0) == QString("Sonars"))
00275           {
00276             for(int k = 0 ; k < it->child(j)->childCount() ; k++)
00277             {
00278               if(it->child(j)->child(k)->text(0) == sonarName)
00279               {
00280                 QTreeWidgetItem *inIt = it->child(j)->child(k);
00281                 switch(vs)
00282                 {
00283                   case 0:
00284                   {
00285                     inIt->setIcon(2,loader.visible_icon_on_);
00286                     break;
00287                   }
00288                   case 1:
00289                   {
00290                     inIt->setIcon(2,loader.visible_icon_trans_);
00291                     break;
00292                   }
00293                   case 2:
00294                   {
00295                     inIt->setIcon(2,loader.visible_icon_off_);
00296                     break;
00297                   }
00298                 }
00299                 return;
00300               }
00301             }
00302           }
00303         }
00304       }
00305     }
00306   }  
00307   
00315   void CInfoConnector::setRfidReaderVisibility(
00316     QString robotName,QString rfidReaderName,char vs)
00317   {
00318     for(int i = 0 ; i < loader.robotsInfo.childCount() ; i++)
00319     {
00320       QString text = loader.robotsInfo.child(i)->text(0);
00321       if(text == robotName)
00322       {
00323         QTreeWidgetItem *it = loader.robotsInfo.child(i);
00324         for(int j = 0 ; j < it->childCount() ; j++)
00325         {
00326           if(it->child(j)->text(0) == QString("RFID readers"))
00327           {
00328             for(int k = 0 ; k < it->child(j)->childCount() ; k++)
00329             {
00330               if(it->child(j)->child(k)->text(0) == rfidReaderName)
00331               {
00332                 QTreeWidgetItem *inIt = it->child(j)->child(k);
00333                 switch(vs)
00334                 {
00335                   case 0:
00336                   {
00337                     inIt->setIcon(2,loader.visible_icon_on_);
00338                     break;
00339                   }
00340                   case 1:
00341                   {
00342                     inIt->setIcon(2,loader.visible_icon_trans_);
00343                     break;
00344                   }
00345                   case 2:
00346                   {
00347                     inIt->setIcon(2,loader.visible_icon_off_);
00348                     break;
00349                   }
00350                 }
00351                 return;
00352               }
00353             }
00354           }
00355         }
00356       }
00357     }
00358   }  
00366   void CInfoConnector::setCO2SensorVisibility(
00367     QString robotName,QString sensorName,char vs)
00368   {
00369     for(int i = 0 ; i < loader.robotsInfo.childCount() ; i++)
00370     {
00371       QString text = loader.robotsInfo.child(i)->text(0);
00372       if(text == robotName)
00373       {
00374         QTreeWidgetItem *it = loader.robotsInfo.child(i);
00375         for(int j = 0 ; j < it->childCount() ; j++)
00376         {
00377           if(it->child(j)->text(0) == QString("CO2 sensors"))
00378           {
00379             for(int k = 0 ; k < it->child(j)->childCount() ; k++)
00380             {
00381               if(it->child(j)->child(k)->text(0) == sensorName)
00382               {
00383                 QTreeWidgetItem *inIt = it->child(j)->child(k);
00384                 switch(vs)
00385                 {
00386                   case 0:
00387                   {
00388                     inIt->setIcon(2,loader.visible_icon_on_);
00389                     break;
00390                   }
00391                   case 1:
00392                   {
00393                     inIt->setIcon(2,loader.visible_icon_trans_);
00394                     break;
00395                   }
00396                   case 2:
00397                   {
00398                     inIt->setIcon(2,loader.visible_icon_off_);
00399                     break;
00400                   }
00401                 }
00402                 return;
00403               }
00404             }
00405           }
00406         }
00407       }
00408     }
00409   }  
00417   void CInfoConnector::setThermalSensorVisibility(
00418     QString robotName,QString sensorName,char vs)
00419   {
00420     for(int i = 0 ; i < loader.robotsInfo.childCount() ; i++)
00421     {
00422       QString text = loader.robotsInfo.child(i)->text(0);
00423       if(text == robotName)
00424       {
00425         QTreeWidgetItem *it = loader.robotsInfo.child(i);
00426         for(int j = 0 ; j < it->childCount() ; j++)
00427         {
00428           if(it->child(j)->text(0) == QString("Thermal sensors"))
00429           {
00430             for(int k = 0 ; k < it->child(j)->childCount() ; k++)
00431             {
00432               if(it->child(j)->child(k)->text(0) == sensorName)
00433               {
00434                 QTreeWidgetItem *inIt = it->child(j)->child(k);
00435                 switch(vs)
00436                 {
00437                   case 0:
00438                   {
00439                     inIt->setIcon(2,loader.visible_icon_on_);
00440                     break;
00441                   }
00442                   case 1:
00443                   {
00444                     inIt->setIcon(2,loader.visible_icon_trans_);
00445                     break;
00446                   }
00447                   case 2:
00448                   {
00449                     inIt->setIcon(2,loader.visible_icon_off_);
00450                     break;
00451                   }
00452                 }
00453                 return;
00454               }
00455             }
00456           }
00457         }
00458       }
00459     }
00460   }  
00468   void CInfoConnector::setSoundSensorVisibility(
00469     QString robotName,QString sensorName,char vs)
00470   {
00471     for(int i = 0 ; i < loader.robotsInfo.childCount() ; i++)
00472     {
00473       QString text = loader.robotsInfo.child(i)->text(0);
00474       if(text == robotName)
00475       {
00476         QTreeWidgetItem *it = loader.robotsInfo.child(i);
00477         for(int j = 0 ; j < it->childCount() ; j++)
00478         {
00479           if(it->child(j)->text(0) == QString("Sound sensors"))
00480           {
00481             for(int k = 0 ; k < it->child(j)->childCount() ; k++)
00482             {
00483               if(it->child(j)->child(k)->text(0) == sensorName)
00484               {
00485                 QTreeWidgetItem *inIt = it->child(j)->child(k);
00486                 switch(vs)
00487                 {
00488                   case 0:
00489                   {
00490                     inIt->setIcon(2,loader.visible_icon_on_);
00491                     break;
00492                   }
00493                   case 1:
00494                   {
00495                     inIt->setIcon(2,loader.visible_icon_trans_);
00496                     break;
00497                   }
00498                   case 2:
00499                   {
00500                     inIt->setIcon(2,loader.visible_icon_off_);
00501                     break;
00502                   }
00503                 }
00504                 return;
00505               }
00506             }
00507           }
00508         }
00509       }
00510     }
00511   }  
00512   
00519   void CInfoConnector::setRobotVisibility(QString robotName,char vs)
00520   {
00521     for(int i = 0 ; i < loader.robotsInfo.childCount() ; i++)
00522     {
00523       QString text = loader.robotsInfo.child(i)->text(0);
00524       if(text == robotName)
00525       {
00526         switch(vs)
00527         {
00528           case 0:
00529           {
00530             loader.robotsInfo.child(i)->setIcon(2,loader.visible_icon_on_);
00531             break;
00532           }
00533           case 1:
00534           {
00535             loader.robotsInfo.child(i)->setIcon(2,loader.visible_icon_trans_);
00536             break;
00537           }
00538           case 2:
00539           {
00540             loader.robotsInfo.child(i)->setIcon(2,loader.visible_icon_off_);
00541             break;
00542           }
00543         }
00544         QTreeWidgetItem *it = loader.robotsInfo.child(i);
00545         for(int j = 0 ; j < it->childCount() ; j++)
00546         {
00547           if(it->child(j)->text(0) == QString("Sonars"))
00548           {
00549             for(int k = 0 ; k < it->child(j)->childCount() ; k++)
00550             {
00551               QTreeWidgetItem *inIt = it->child(j)->child(k);
00552               switch(vs)
00553               {
00554                 case 0:
00555                 {
00556                   inIt->setIcon(2,loader.visible_icon_on_);
00557                   break;
00558                 }
00559                 case 1:
00560                 {
00561                   inIt->setIcon(2,loader.visible_icon_trans_);
00562                   break;
00563                 }
00564                 case 2:
00565                 {
00566                   inIt->setIcon(2,loader.visible_icon_off_);
00567                   break;
00568                 }
00569               }
00570             }
00571           }
00572           if(it->child(j)->text(0) == QString("Lasers"))
00573           {
00574             for(int k = 0 ; k < it->child(j)->childCount() ; k++)
00575             {
00576               QTreeWidgetItem *inIt = it->child(j)->child(k);
00577               switch(vs)
00578               {
00579                 case 0:
00580                 {
00581                   inIt->setIcon(2,loader.visible_icon_on_);
00582                   break;
00583                 }
00584                 case 1:
00585                 {
00586                   inIt->setIcon(2,loader.visible_icon_trans_);
00587                   break;
00588                 }
00589                 case 2:
00590                 {
00591                   inIt->setIcon(2,loader.visible_icon_off_);
00592                   break;
00593                 }
00594               }
00595             }
00596           }
00597         }
00598         return;
00599       }
00600     }
00601   }
00602 }


stdr_gui
Author(s): Manos Tsardoulias
autogenerated on Thu Jun 6 2019 18:57:38