diff --git a/source/RobotAPI/components/DebugDrawer/DebugDrawerComponent.cpp b/source/RobotAPI/components/DebugDrawer/DebugDrawerComponent.cpp index be83c748e037bd9603f08e9532ac16513ffb6b52..508180247963def8b29e4555b1cb8420a0920303 100644 --- a/source/RobotAPI/components/DebugDrawer/DebugDrawerComponent.cpp +++ b/source/RobotAPI/components/DebugDrawer/DebugDrawerComponent.cpp @@ -108,31 +108,41 @@ namespace armarx u->units = SoUnits::MILLIMETERS; selectionNode->addChild(u); selectionNode->addChild(layerMainNode); - - // Debug - enableSelections(""); } void DebugDrawerComponent::enableSelections(const std::string& layerName, const ::Ice::Current&) { ScopedRecursiveLockPtr l = getScopedVisuLock(); - - selectionNode->addSelectionCallback(selection_callback, this); - selectionNode->addDeselectionCallback(deselection_callback, this); + selectableLayers.insert(layerName); } void DebugDrawerComponent::disableSelections(const std::string& layerName, const ::Ice::Current&) { ScopedRecursiveLockPtr l = getScopedVisuLock(); - selectionNode->removeSelectionCallback(selection_callback, this); - selectionNode->removeDeselectionCallback(deselection_callback, this); + if (layerName == "") + { + selectableLayers.clear(); + } + else + { + selectableLayers.erase(layerName); + } } void DebugDrawerComponent::clearSelections(const std::string& layerName, const Ice::Current&) { ScopedRecursiveLockPtr l = getScopedVisuLock(); - selectionNode->deselectAll(); + ScopedRecursiveLockPtr l2(new ScopedRecursiveLock(selectionMutex)); + + if (layerName == "") + { + selectionNode->deselectAll(); + } + else + { + selectionNode->deselect(layers.at(layerName).mainNode); + } } void DebugDrawerComponent::selectionCallback() @@ -147,13 +157,26 @@ namespace armarx listenerPrx->reportSelectionChanged(getSelections()); } + void DebugDrawerComponent::installSelectionCallbacks() + { + ScopedRecursiveLockPtr l = getScopedVisuLock(); + selectionNode->addSelectionCallback(selection_callback, this); + selectionNode->addDeselectionCallback(deselection_callback, this); + } + + void DebugDrawerComponent::removeSelectionCallbacks() + { + ScopedRecursiveLockPtr l = getScopedVisuLock(); + selectionNode->removeSelectionCallback(selection_callback, this); + selectionNode->removeDeselectionCallback(deselection_callback, this); + } + void DebugDrawerComponent::reportSelectionChanged(const DebugDrawerSelectionList& selectedElements, const Ice::Current&) { ScopedRecursiveLockPtr l = getScopedVisuLock(); ScopedRecursiveLockPtr l2(new ScopedRecursiveLock(selectionMutex)); - disableSelections(""); - + removeSelectionCallbacks(); selectionNode->deselectAll(); for (auto& e : selectedElements) @@ -168,7 +191,7 @@ namespace armarx // Force visualization update selectionNode->touch(); - enableSelections(""); + installSelectionCallbacks(); } DebugDrawerSelectionList DebugDrawerComponent::getSelections(const ::Ice::Current&) @@ -185,7 +208,19 @@ namespace armarx if (name.length() > 0 && name.find(SELECTION_NAME_PREFIX) == 0) { name = name.substr(SELECTION_NAME_PREFIX.length()); - selectedElements.push_back(name); + + // Check if selected element is 'selectable' + for (auto& layer : selectableLayers) + { + if (layers[layer].addedBoxVisualizations.find(name) != layers[layer].addedBoxVisualizations.end() + || layers[layer].addedTextVisualizations.find(name) != layers[layer].addedTextVisualizations.end() + || layers[layer].addedSphereVisualizations.find(name) != layers[layer].addedSphereVisualizations.end() + || layers[layer].addedCylinderVisualizations.find(name) != layers[layer].addedCylinderVisualizations.end()) + { + selectedElements.push_back(name); + break; + } + } } } @@ -244,6 +279,8 @@ namespace armarx offeringTopic(getProperty<std::string>("DebugDrawerSelectionTopic").getValue()); usingTopic(getProperty<std::string>("DebugDrawerSelectionTopic").getValue()); + + installSelectionCallbacks(); } void DebugDrawerComponent::updateVisualizationCB(void* data, SoSensor* sensor) diff --git a/source/RobotAPI/components/DebugDrawer/DebugDrawerComponent.h b/source/RobotAPI/components/DebugDrawer/DebugDrawerComponent.h index b39c222ccf29841e9370ea6e15fc797727d9c99c..bae49caa056a5aead0cd79525e30b5483a6bb521 100644 --- a/source/RobotAPI/components/DebugDrawer/DebugDrawerComponent.h +++ b/source/RobotAPI/components/DebugDrawer/DebugDrawerComponent.h @@ -241,6 +241,8 @@ namespace armarx void selectionCallback(); void deselectionCallback(); + void installSelectionCallbacks(); + void removeSelectionCallbacks(); void reportSelectionChanged(const DebugDrawerSelectionList& selectedElements, const ::Ice::Current& = ::Ice::Current()); @@ -477,6 +479,7 @@ namespace armarx boost::shared_ptr<boost::recursive_mutex> topicMutex; static boost::recursive_mutex selectionMutex; + std::set<std::string> selectableLayers; ScopedRecursiveLockPtr getScopedAccumulatedDataLock();