DebugLayerControlWidget.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package
19  * @author
20  * @date
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
25 
26 #include <RobotAPI/libraries/widgets/ui_DebugLayerControlWidget.h>
27 
28 #define UPDATE_INTERVAL 1.0 // update every second
29 
31  QWidget(parent), ui(new Ui::DebugLayerControlWidget)
32 {
33  entityDrawer = NULL;
34  ui->setupUi(this);
35 
36  //init timer
37  SoSensorManager* sensor_mgr = SoDB::getSensorManager();
38  timerSensor = new SoTimerSensor(onTimer, this);
39  timerSensor->setInterval(SbTime(UPDATE_INTERVAL));
40  sensor_mgr->insertTimerSensor(timerSensor);
41 
42  //connect signal mapper
43  QObject::connect(&layerSignalMapperVisible,
44  SIGNAL(mapped(QString)),
45  this,
46  SLOT(layerToggleVisibility(QString)));
47  QObject::connect(
48  &layerSignalMapperRemove, SIGNAL(mapped(QString)), this, SLOT(layerRemove(QString)));
49 }
50 
52 {
53  //destroy timer
54  if (timerSensor)
55  {
56  SoSensorManager* sensor_mgr = SoDB::getSensorManager();
57  sensor_mgr->removeTimerSensor(timerSensor);
58  }
59  delete ui;
60 }
61 
62 void
64 {
65  this->entityDrawer = entityDrawer;
66 }
67 
68 void
70 {
71  //ui.layerTable->clear();
72  if (entityDrawer)
73  {
74  armarx::LayerInformationSequence layers = entityDrawer->layerInformation();
75  ui->layerTable->setRowCount(layers.size());
76 
77  for (std::size_t i = 0; i < layers.size(); ++i)
78  {
79  const auto& layer = layers.at(i);
80  QString name = QString::fromStdString(layer.layerName);
81 
82  //store visibility
83  layerVisibility[layer.layerName] = layer.visible;
84 
85  //add name and number of elements
86  ui->layerTable->setItem(i, 0, new QTableWidgetItem{name});
87  ui->layerTable->setItem(
88  i, 1, new QTableWidgetItem{QString::number(layer.elementCount)});
89 
90  //add visibility checkbox
91  std::unique_ptr<QCheckBox> box{new QCheckBox};
92  box->setChecked(layer.visible);
93  layerSignalMapperVisible.setMapping(box.get(), name);
94  QObject::connect(
95  box.get(), SIGNAL(stateChanged(int)), &layerSignalMapperVisible, SLOT(map()));
96  ui->layerTable->setCellWidget(i, 2, box.release());
97 
98  //add remove button
99  std::unique_ptr<QPushButton> removeB{new QPushButton("remove")};
100  layerSignalMapperRemove.setMapping(removeB.get(), name);
101  QObject::connect(
102  removeB.get(), SIGNAL(clicked()), &layerSignalMapperRemove, SLOT(map()));
103  ui->layerTable->setCellWidget(i, 3, removeB.release());
104  }
105  }
106  else
107  {
108  ARMARX_INFO << "No Debug Drawer" << std::endl;
109  }
110 }
111 
112 void
114 {
115  //ARMARX_INFO << "should toggle: " << layerName.toStdString() << std::endl;
116  auto name = layerName.toStdString();
117  if (layerVisibility.find(name) != layerVisibility.end())
118  {
119  if (entityDrawer)
120  {
121  entityDrawer->enableLayerVisu(name, !layerVisibility.at(name));
122  }
123  }
124  else
125  {
126  ARMARX_INFO << "name not present" << std::endl;
127  }
128 }
129 
130 void
132 {
133  auto name = layerName.toStdString();
134  ARMARX_INFO << "remove layer: " << name << std::endl;
135 
136  if (entityDrawer->hasLayer(name))
137  {
138  entityDrawer->removeLayer(name);
139  }
140  else
141  {
142  ARMARX_INFO << "name not present" << std::endl;
143  }
144 }
145 
146 void
147 DebugLayerControlWidget::onTimer(void* data, SoSensor* sensor)
148 {
150  if (controller)
151  {
152  controller->updateLayers();
153  }
154 }
DebugLayerControlWidget::setEntityDrawer
void setEntityDrawer(armarx::DebugDrawerComponentPtr entityDrawer)
Definition: DebugLayerControlWidget.cpp:63
DebugLayerControlWidget::layerSignalMapperVisible
QSignalMapper layerSignalMapperVisible
Maps events to toggle a layer's visibility from checkboxes contained in the table to layerToggleVisib...
Definition: DebugLayerControlWidget.h:74
DebugLayerControlWidget.h
DebugLayerControlWidget::entityDrawer
armarx::DebugDrawerComponentPtr entityDrawer
Definition: DebugLayerControlWidget.h:69
UPDATE_INTERVAL
#define UPDATE_INTERVAL
Definition: DebugLayerControlWidget.cpp:28
DebugLayerControlWidget::updateLayers
void updateLayers()
Definition: DebugLayerControlWidget.cpp:69
DebugLayerControlWidget::timerSensor
SoTimerSensor * timerSensor
Definition: DebugLayerControlWidget.h:70
DebugLayerControlWidget::~DebugLayerControlWidget
~DebugLayerControlWidget() override
Definition: DebugLayerControlWidget.cpp:51
DebugLayerControlWidget::onTimer
static void onTimer(void *data, SoSensor *sensor)
Definition: DebugLayerControlWidget.cpp:147
IceInternal::Handle< DebugDrawerComponent >
controller
Definition: AddOperation.h:39
Ui
ArmarX Headers.
Definition: ArmarXMainWindow.h:54
DebugLayerControlWidget::layerVisibility
std::unordered_map< std::string, bool > layerVisibility
Stores whether a layer is currently visible.
Definition: DebugLayerControlWidget.h:82
DebugLayerControlWidget
Definition: DebugLayerControlWidget.h:54
DebugLayerControlWidget::DebugLayerControlWidget
DebugLayerControlWidget(QWidget *parent=0)
Definition: DebugLayerControlWidget.cpp:30
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
DebugLayerControlWidget::layerSignalMapperRemove
QSignalMapper layerSignalMapperRemove
Maps events to remove a layer.
Definition: DebugLayerControlWidget.h:78
DebugLayerControlWidget::layerToggleVisibility
void layerToggleVisibility(QString layerName)
Definition: DebugLayerControlWidget.cpp:113
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
DebugLayerControlWidget::layerRemove
void layerRemove(QString layerName)
Definition: DebugLayerControlWidget.cpp:131