24#include <RobotAPI/gui-plugins/DebugDrawerViewer/ui_DebugDrawerViewerWidget.h>
30#include <SimoxUtility/algorithm/string/string_tools.h>
41 widget = std::make_unique<Ui::DebugDrawerViewerWidget>();
44 QTimer* timer =
new QTimer(
this);
45 connect(timer, SIGNAL(timeout()),
this, SLOT(updateComboClearLayer()));
64 rootVisu =
new SoSeparator;
69 connect(widget->btnClearAll,
72 SLOT(on_btnClearAll_clicked()),
73 Qt::UniqueConnection);
74 connect(widget->btnClearLayer,
77 SLOT(on_btnClearLayer_clicked()),
78 Qt::UniqueConnection);
85 std::string debugDrawerComponentName =
"GUIDebugDrawer_" +
getName();
86 ARMARX_INFO <<
"Creating component " << debugDrawerComponentName;
101 m->addObject(debugDrawer,
false);
104 std::unique_lock lock(*
mutex3D);
105 rootVisu->addChild(debugDrawer->getVisualization());
115 rootVisu->removeAllChildren();
128 armarx::DebugDrawerViewerWidgetController::on_btnClearAll_clicked()
132 ARMARX_INFO <<
"Clearing all visualization layers";
133 debugDrawer->clearAll();
138 DebugDrawerViewerWidgetController::on_btnClearLayer_clicked()
142 int index = widget->comboClearLayer->currentIndex();
143 std::string layerName =
144 widget->comboClearLayer->itemData(
index).toString().toStdString();
146 if (!layerName.empty())
148 ARMARX_INFO <<
"Clearing layer: '" << layerName <<
"'";
149 debugDrawer->clearLayer(layerName);
155 DebugDrawerViewerWidgetController::updateComboClearLayer()
157 QComboBox* combo = widget->comboClearLayer;
159 auto setItalic = [combo](
bool italic)
161 QFont font = combo->font();
162 font.setItalic(italic);
163 combo->setFont(font);
166 auto disableButton = [combo,
this, &setItalic](
const std::string& hint)
168 QString itemText(hint.c_str());
169 QString itemData(
"");
172 if (combo->count() != 1)
175 combo->insertItem(0, itemText, itemData);
179 combo->setItemText(0, itemText);
180 combo->setItemData(0, itemData);
183 this->widget->btnClearLayer->setEnabled(
false);
188 disableButton(
"not connected");
193 LayerInformationSequence layers = debugDrawer->layerInformation();
197 disableButton(
"no layers");
203 this->widget->btnClearLayer->setEnabled(
true);
207 std::sort(layers.begin(),
209 [](
const LayerInformation& lhs,
const LayerInformation& rhs)
212 for (std::size_t i = 0; i < lhs.layerName.size() && i < lhs.layerName.size();
215 auto lhsLow = std::tolower(lhs.layerName[i]);
216 auto rhsLow = std::tolower(rhs.layerName[i]);
221 else if (lhsLow > rhsLow)
227 return lhs.layerName.size() < rhs.layerName.size();
231 const int numLayers =
static_cast<int>(layers.size());
233 for (
int i = 0; i < numLayers; ++i)
235 const LayerInformation& layer = layers[
static_cast<std::size_t
>(i)];
237 QString layerName(layer.layerName.c_str());
239 if (i < combo->count())
241 QString itemData = combo->itemData(i).toString();
244 while (itemData.size() != 0 && itemData < layerName)
248 combo->removeItem(i);
249 itemData = i < combo->count() ? combo->itemData(i).toString() :
"";
253 if (itemData == layerName)
255 combo->setItemText(i, makeLayerItemText(layer));
261 combo->insertItem(i, makeLayerItemText(layer), layerName);
266 combo->insertItem(i, makeLayerItemText(layer), layerName);
274 while (combo->count() > numLayers)
276 combo->removeItem(combo->count() - 1);
281 DebugDrawerViewerWidgetController::makeLayerItemText(
const LayerInformation& layer)
283 std::vector<std::string> annotations;
284 if (layer.elementCount == 0)
286 annotations.push_back(
"empty");
290 annotations.push_back(std::to_string(layer.elementCount));
294 annotations.push_back(
"hidden");
297 if (annotations.empty())
299 return {layer.layerName.c_str()};
303 std::stringstream itemText;
304 itemText << layer.layerName <<
" (" << simox::alg::join(annotations,
", ") <<
")";
305 return {itemText.str().c_str()};
static TPtr create(Ice::PropertiesPtr properties=Ice::createProperties(), const std::string &configName="", const std::string &configDomain="ArmarX")
Factory method for a component.
std::string getName() const
Retrieve name of object.
ArmarXManagerPtr getArmarXManager() const
Returns the ArmarX manager used to add and remove components.
Ice::PropertiesPtr getIceProperties() const
Returns the set of Ice properties.
#define ARMARX_CHECK_EQUAL(lhs, rhs)
This macro evaluates whether lhs is equal (==) rhs and if it turns out to be false it will throw an E...
#define ARMARX_INFO
The normal logging level.
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< ArmarXManager > ArmarXManagerPtr