26 #include <SimoxUtility/algorithm/string/string_tools.h>
40 QTimer* timer =
new QTimer(
this);
41 connect(timer, SIGNAL(timeout()),
this, SLOT(updateComboClearLayer()));
59 rootVisu =
new SoSeparator;
64 connect(widget.btnClearAll, SIGNAL(clicked()),
this, SLOT(on_btnClearAll_clicked()), Qt::UniqueConnection);
65 connect(widget.btnClearLayer, SIGNAL(clicked()),
this, SLOT(on_btnClearLayer_clicked()), Qt::UniqueConnection);
72 std::string debugDrawerComponentName =
"GUIDebugDrawer_" +
getName();
73 ARMARX_INFO <<
"Creating component " << debugDrawerComponentName;
74 debugDrawer = Component::create<DebugDrawerComponent>(
getIceProperties(), debugDrawerComponentName);
87 m->addObject(debugDrawer,
false);
90 std::unique_lock lock(*
mutex3D);
91 rootVisu->addChild(debugDrawer->getVisualization());
100 rootVisu->removeAllChildren();
112 void armarx::DebugDrawerViewerWidgetController::on_btnClearAll_clicked()
116 ARMARX_INFO <<
"Clearing all visualization layers";
117 debugDrawer->clearAll();
121 void DebugDrawerViewerWidgetController::on_btnClearLayer_clicked()
125 int index = widget.comboClearLayer->currentIndex();
126 std::string layerName = widget.comboClearLayer->itemData(
index).toString().toStdString();
128 if (!layerName.empty())
130 ARMARX_INFO <<
"Clearing layer: '" << layerName <<
"'";
131 debugDrawer->clearLayer(layerName);
137 void DebugDrawerViewerWidgetController::updateComboClearLayer()
139 QComboBox* combo = widget.comboClearLayer;
141 auto setItalic = [combo](
bool italic)
143 QFont font = combo->font();
144 font.setItalic(italic);
145 combo->setFont(font);
148 auto disableButton = [combo,
this, &setItalic](
const std::string & hint)
150 QString itemText(hint.c_str());
151 QString itemData(
"");
154 if (combo->count() != 1)
157 combo->insertItem(0, itemText, itemData);
161 combo->setItemText(0, itemText);
162 combo->setItemData(0, itemData);
165 this->widget.btnClearLayer->setEnabled(
false);
170 disableButton(
"not connected");
175 LayerInformationSequence layers = debugDrawer->layerInformation();
179 disableButton(
"no layers");
185 this->widget.btnClearLayer->setEnabled(
true);
189 std::sort(layers.begin(), layers.end(), [](
const LayerInformation & lhs,
const LayerInformation & rhs)
192 for (std::size_t i = 0; i < lhs.layerName.size() && i < lhs.layerName.size(); ++i)
194 auto lhsLow = std::tolower(lhs.layerName[i]);
195 auto rhsLow = std::tolower(rhs.layerName[i]);
200 else if (lhsLow > rhsLow)
206 return lhs.layerName.size() < rhs.layerName.size();
210 const int numLayers =
static_cast<int>(layers.size());
212 for (
int i = 0; i < numLayers; ++i)
214 const LayerInformation& layer = layers[
static_cast<std::size_t
>(i)];
216 QString layerName(layer.layerName.c_str());
218 if (i < combo->count())
220 QString itemData = combo->itemData(i).toString();
223 while (itemData.size() != 0 && itemData < layerName)
227 combo->removeItem(i);
228 itemData = i < combo->count() ? combo->itemData(i).toString() :
"";
232 if (itemData == layerName)
234 combo->setItemText(i, makeLayerItemText(layer));
240 combo->insertItem(i, makeLayerItemText(layer), layerName);
245 combo->insertItem(i, makeLayerItemText(layer), layerName);
253 while (combo->count() > numLayers)
255 combo->removeItem(combo->count() - 1);
261 QString DebugDrawerViewerWidgetController::makeLayerItemText(
const LayerInformation& layer)
263 std::vector<std::string> annotations;
264 if (layer.elementCount == 0)
266 annotations.push_back(
"empty");
274 annotations.push_back(
"hidden");
277 if (annotations.empty())
279 return { layer.layerName.c_str() };
283 std::stringstream itemText;
284 itemText << layer.layerName
285 <<
" (" << simox::alg::join(annotations,
", ") <<
")";
286 return { itemText.str().c_str() };