28 #include <SimoxUtility/algorithm/string/string_tools.h>
39 QTimer* timer =
new QTimer(
this);
40 connect(timer, SIGNAL(timeout()),
this, SLOT(updateComboClearLayer()));
59 rootVisu =
new SoSeparator;
64 connect(widget.btnClearAll,
67 SLOT(on_btnClearAll_clicked()),
68 Qt::UniqueConnection);
69 connect(widget.btnClearLayer,
72 SLOT(on_btnClearLayer_clicked()),
73 Qt::UniqueConnection);
80 std::string debugDrawerComponentName =
"GUIDebugDrawer_" +
getName();
81 ARMARX_INFO <<
"Creating component " << debugDrawerComponentName;
83 Component::create<DebugDrawerComponent>(
getIceProperties(), debugDrawerComponentName);
96 m->addObject(debugDrawer,
false);
99 std::unique_lock lock(*
mutex3D);
100 rootVisu->addChild(debugDrawer->getVisualization());
110 rootVisu->removeAllChildren();
123 armarx::DebugDrawerViewerWidgetController::on_btnClearAll_clicked()
127 ARMARX_INFO <<
"Clearing all visualization layers";
128 debugDrawer->clearAll();
133 DebugDrawerViewerWidgetController::on_btnClearLayer_clicked()
137 int index = widget.comboClearLayer->currentIndex();
138 std::string layerName =
139 widget.comboClearLayer->itemData(
index).toString().toStdString();
141 if (!layerName.empty())
143 ARMARX_INFO <<
"Clearing layer: '" << layerName <<
"'";
144 debugDrawer->clearLayer(layerName);
150 DebugDrawerViewerWidgetController::updateComboClearLayer()
152 QComboBox* combo = widget.comboClearLayer;
154 auto setItalic = [combo](
bool italic)
156 QFont font = combo->font();
157 font.setItalic(italic);
158 combo->setFont(font);
161 auto disableButton = [combo,
this, &setItalic](
const std::string& hint)
163 QString itemText(hint.c_str());
164 QString itemData(
"");
167 if (combo->count() != 1)
170 combo->insertItem(0, itemText, itemData);
174 combo->setItemText(0, itemText);
175 combo->setItemData(0, itemData);
178 this->widget.btnClearLayer->setEnabled(
false);
183 disableButton(
"not connected");
188 LayerInformationSequence layers = debugDrawer->layerInformation();
192 disableButton(
"no layers");
198 this->widget.btnClearLayer->setEnabled(
true);
202 std::sort(layers.begin(),
204 [](
const LayerInformation& lhs,
const LayerInformation& rhs)
207 for (std::size_t i = 0; i < lhs.layerName.size() && i < lhs.layerName.size();
210 auto lhsLow = std::tolower(lhs.layerName[i]);
211 auto rhsLow = std::tolower(rhs.layerName[i]);
216 else if (lhsLow > rhsLow)
222 return lhs.layerName.size() < rhs.layerName.size();
226 const int numLayers =
static_cast<int>(layers.size());
228 for (
int i = 0; i < numLayers; ++i)
230 const LayerInformation& layer = layers[
static_cast<std::size_t
>(i)];
232 QString layerName(layer.layerName.c_str());
234 if (i < combo->count())
236 QString itemData = combo->itemData(i).toString();
239 while (itemData.size() != 0 && itemData < layerName)
243 combo->removeItem(i);
244 itemData = i < combo->count() ? combo->itemData(i).toString() :
"";
248 if (itemData == layerName)
250 combo->setItemText(i, makeLayerItemText(layer));
256 combo->insertItem(i, makeLayerItemText(layer), layerName);
261 combo->insertItem(i, makeLayerItemText(layer), layerName);
269 while (combo->count() > numLayers)
271 combo->removeItem(combo->count() - 1);
276 DebugDrawerViewerWidgetController::makeLayerItemText(
const LayerInformation& layer)
278 std::vector<std::string> annotations;
279 if (layer.elementCount == 0)
281 annotations.push_back(
"empty");
289 annotations.push_back(
"hidden");
292 if (annotations.empty())
294 return {layer.layerName.c_str()};
298 std::stringstream itemText;
299 itemText << layer.layerName <<
" (" << simox::alg::join(annotations,
", ") <<
")";
300 return {itemText.str().c_str()};