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 #include <RobotAPI/libraries/widgets/ui_DebugLayerControlWidget.h>
26 
27 #define UPDATE_INTERVAL 1.0 // update every second
28 
30  QWidget(parent),
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, SIGNAL(mapped(QString)), this, SLOT(layerToggleVisibility(QString)));
44  QObject::connect(&layerSignalMapperRemove, SIGNAL(mapped(QString)), this, SLOT(layerRemove(QString)));
45 }
46 
48 {
49  //destroy timer
50  if (timerSensor)
51  {
52  SoSensorManager* sensor_mgr = SoDB::getSensorManager();
53  sensor_mgr->removeTimerSensor(timerSensor);
54  }
55  delete ui;
56 }
57 
59 {
60  this->entityDrawer = entityDrawer;
61 }
62 
64 {
65  //ui.layerTable->clear();
66  if (entityDrawer)
67  {
68  armarx::LayerInformationSequence layers = entityDrawer->layerInformation();
69  ui->layerTable->setRowCount(layers.size());
70 
71  for (std::size_t i = 0; i < layers.size(); ++i)
72  {
73  const auto& layer = layers.at(i);
74  QString name = QString::fromStdString(layer.layerName);
75 
76  //store visibility
77  layerVisibility[layer.layerName] = layer.visible;
78 
79  //add name and number of elements
80  ui->layerTable->setItem(i, 0, new QTableWidgetItem{name});
81  ui->layerTable->setItem(i, 1, new QTableWidgetItem{QString::number(layer.elementCount)});
82 
83  //add visibility checkbox
84  std::unique_ptr<QCheckBox> box{new QCheckBox};
85  box->setChecked(layer.visible);
86  layerSignalMapperVisible.setMapping(box.get(), name);
87  QObject::connect(box.get(), SIGNAL(stateChanged(int)), &layerSignalMapperVisible, SLOT(map()));
88  ui->layerTable->setCellWidget(i, 2, box.release());
89 
90  //add remove button
91  std::unique_ptr<QPushButton> removeB{new QPushButton("remove")};
92  layerSignalMapperRemove.setMapping(removeB.get(), name);
93  QObject::connect(removeB.get(), SIGNAL(clicked()), &layerSignalMapperRemove, SLOT(map()));
94  ui->layerTable->setCellWidget(i, 3, removeB.release());
95  }
96  }
97  else
98  {
99  VR_INFO << "No Debug Drawer" << std::endl;
100  }
101 }
102 
104 {
105  //VR_INFO << "should toggle: " << layerName.toStdString() << std::endl;
106  auto name = layerName.toStdString();
107  if (layerVisibility.find(name) != layerVisibility.end())
108  {
109  if (entityDrawer)
110  {
111  entityDrawer->enableLayerVisu(name, !layerVisibility.at(name));
112  }
113  }
114  else
115  {
116  VR_INFO << "name not present" << std::endl;
117  }
118 }
119 
121 {
122  auto name = layerName.toStdString();
123  VR_INFO << "remove layer: " << name << std::endl;
124 
125  if (entityDrawer->hasLayer(name))
126  {
127  entityDrawer->removeLayer(name);
128  }
129  else
130  {
131  VR_INFO << "name not present" << std::endl;
132  }
133 }
134 
135 void DebugLayerControlWidget::onTimer(void* data, SoSensor* sensor)
136 {
138  if (controller)
139  {
140  controller->updateLayers();
141  }
142 }
DebugLayerControlWidget::setEntityDrawer
void setEntityDrawer(armarx::DebugDrawerComponentPtr entityDrawer)
Definition: DebugLayerControlWidget.cpp:58
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:27
DebugLayerControlWidget::updateLayers
void updateLayers()
Definition: DebugLayerControlWidget.cpp:63
DebugLayerControlWidget::timerSensor
SoTimerSensor * timerSensor
Definition: DebugLayerControlWidget.h:70
DebugLayerControlWidget::~DebugLayerControlWidget
~DebugLayerControlWidget() override
Definition: DebugLayerControlWidget.cpp:47
DebugLayerControlWidget::onTimer
static void onTimer(void *data, SoSensor *sensor)
Definition: DebugLayerControlWidget.cpp:135
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:29
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:103
DebugLayerControlWidget::layerRemove
void layerRemove(QString layerName)
Definition: DebugLayerControlWidget.cpp:120