diff --git a/source/RobotAPI/components/DebugDrawer/DebugDrawerComponent.cpp b/source/RobotAPI/components/DebugDrawer/DebugDrawerComponent.cpp index 450604aaeb5599b57daa3ec62f83fd1297f4ecd8..d783b0f9de50238b220fb3f5f9662da8bda9d306 100644 --- a/source/RobotAPI/components/DebugDrawer/DebugDrawerComponent.cpp +++ b/source/RobotAPI/components/DebugDrawer/DebugDrawerComponent.cpp @@ -58,6 +58,8 @@ using namespace VirtualRobot; +#define SELECTION_NAME_PREFIX "selection_" + namespace armarx { void selection_callback(void* userdata, SoPath* path) @@ -115,63 +117,72 @@ namespace armarx void DebugDrawerComponent::enableSelections(const std::string& layerName, const ::Ice::Current&) { + ScopedRecursiveLockPtr l = getScopedVisuLock(); + coinVisu->addSelectionCallback(selection_callback, this); coinVisu->addDeselectionCallback(deselection_callback, this); } void DebugDrawerComponent::disableSelections(const std::string& layerName, const ::Ice::Current&) { + ScopedRecursiveLockPtr l = getScopedVisuLock(); + coinVisu->removeSelectionCallback(selection_callback, this); coinVisu->removeDeselectionCallback(deselection_callback, this); - coinVisu->deselectAll(); } - void DebugDrawerComponent::selectionChangeReport() + void DebugDrawerComponent::clearSelections(const std::string& layerName, const Ice::Current&) { - listenerPrx->reportSelectionChanged(getSelectedListNames()); + ScopedRecursiveLockPtr l = getScopedVisuLock(); + + coinVisu->deselectAll(); } void DebugDrawerComponent::selectionCallback(SoPath* path) { - selectionChangeReport(); + listenerPrx->reportSelectionChanged(getSelections()); } void DebugDrawerComponent::deselectionCallback(SoPath* path) { - selectionChangeReport(); + listenerPrx->reportSelectionChanged(getSelections()); } - DebugDrawerSelectionList DebugDrawerComponent:: getSelectedListNames() + void DebugDrawerComponent::reportSelectionChanged(const DebugDrawerSelectionList& selectedElements, const Ice::Current&) { - DebugDrawerSelectionList selectedElements; - - const SoPathList* selectedList = coinVisu->getList(); + disableSelections(""); - for (int i = 0; i < selectedList->getLength(); i++) { - SoPath* path = selectedList->operator [](i); - const char* name = path->getTail()->getName().getString(); - selectedElements.push_back(name); + ScopedRecursiveLockPtr l = getScopedVisuLock(); + + for (auto & e : selectedElements) + { + coinVisu->select(coinVisu->getByName((SELECTION_NAME_PREFIX + e).c_str())); + } } - return selectedElements; + enableSelections(""); } - void DebugDrawerComponent::reportSelectionChanged(const DebugDrawerSelectionList& selectedElements, const Ice::Current&) + DebugDrawerSelectionList DebugDrawerComponent::getSelections(const ::Ice::Current&) { - disableSelections(""); + ScopedRecursiveLockPtr l = getScopedVisuLock(); + + DebugDrawerSelectionList selectedElements; - for (auto iterator = selectedElements.begin(); iterator != selectedElements.end(); ++iterator) + ARMARX_INFO << "Number of selected elements: " << coinVisu->getNumSelected(); + for (int i = 0; i < coinVisu->getNumSelected(); i++) { - coinVisu->select(coinVisu->getByName(iterator->c_str())); - } + SoPath* path = coinVisu->getPath(i); - enableSelections(""); - } + std::string name = path->getTail()->getName().getString(); + name = name.substr(strlen(SELECTION_NAME_PREFIX)); - DebugDrawerSelectionList DebugDrawerComponent:: getSelections(const ::Ice::Current&) - { - return getSelections(); + ARMARX_INFO << "Selection: " << name; + selectedElements.push_back(name); + } + + return selectedElements; } void DebugDrawerComponent::setVisuUpdateTime(float visuUpdatesPerSec) @@ -410,7 +421,7 @@ namespace armarx newS->addChild(material); SoCube* cube = new SoCube; - cube->setName(d.name.c_str()); + cube->setName((SELECTION_NAME_PREFIX + d.name).c_str()); cube->width = d.width; cube->height = d.height; cube->depth = d.depth; diff --git a/source/RobotAPI/components/DebugDrawer/DebugDrawerComponent.h b/source/RobotAPI/components/DebugDrawer/DebugDrawerComponent.h index f6ab78a1f678b574b5291a6bb62d793fe53a2161..590af93139ee0f56d7a93755ee6f23ed29b441fc 100644 --- a/source/RobotAPI/components/DebugDrawer/DebugDrawerComponent.h +++ b/source/RobotAPI/components/DebugDrawer/DebugDrawerComponent.h @@ -236,9 +236,8 @@ namespace armarx // Methods for selection management virtual void enableSelections(const std::string& layerName, const ::Ice::Current& = ::Ice::Current()); virtual void disableSelections(const std::string& layerName, const ::Ice::Current& = ::Ice::Current()); + virtual void clearSelections(const std::string& layerName, const ::Ice::Current& = ::Ice::Current()); virtual DebugDrawerSelectionList getSelections(const ::Ice::Current& = ::Ice::Current()); - virtual DebugDrawerSelectionList getSelectedListNames(); - virtual void selectionChangeReport(); void selectionCallback(SoPath* path); void deselectionCallback(SoPath* path); diff --git a/source/RobotAPI/interface/visualization/DebugDrawerInterface.ice b/source/RobotAPI/interface/visualization/DebugDrawerInterface.ice index 4272d868345fa80af102fac15846013901f2e774..8e7e85c35ed7f8ab51738c5bcc6fb6e7b4c13ceb 100644 --- a/source/RobotAPI/interface/visualization/DebugDrawerInterface.ice +++ b/source/RobotAPI/interface/visualization/DebugDrawerInterface.ice @@ -261,6 +261,11 @@ module armarx */ void disableSelections(string layerName); + /*! + * \brief Clear selections in visualizations + */ + void clearSelections(string layerName); + /*! * \brief Return currently selected elements */