diff --git a/source/RobotAPI/components/ArViz/ArVizStorage.cpp b/source/RobotAPI/components/ArViz/ArVizStorage.cpp index 24d933cc3653b567235fd3eac80c80ac0720d6bb..c49bc46f12ab45bcd034c21b92d1eb94e8c0e0b9 100644 --- a/source/RobotAPI/components/ArViz/ArVizStorage.cpp +++ b/source/RobotAPI/components/ArViz/ArVizStorage.cpp @@ -240,7 +240,7 @@ namespace armarx if (input.interactionComponent.size() > 0) { auto interactionsEnd = interactionBuffer.end(); - auto foundInteractionsBegin = std::remove_if(interactionBuffer.begin(), interactionsEnd, + auto foundInteractionsBegin = std::partition(interactionBuffer.begin(), interactionsEnd, [&input](viz::data::InteractionFeedback const& interaction) { if (interaction.component == input.interactionComponent) @@ -249,11 +249,11 @@ namespace armarx { if (interaction.layer == layer) { - return true; + return false; } } } - return false; + return true; }); result.interactions.assign(foundInteractionsBegin, interactionsEnd); diff --git a/source/RobotAPI/components/ArViz/Coin/Visualizer.cpp b/source/RobotAPI/components/ArViz/Coin/Visualizer.cpp index 29e0cb3297797b6438cff98c04e6f8ca1cb230cd..764277bc58d4c0d21dd347197092e172c2aac4a7 100644 --- a/source/RobotAPI/components/ArViz/Coin/Visualizer.cpp +++ b/source/RobotAPI/components/ArViz/Coin/Visualizer.cpp @@ -37,13 +37,13 @@ namespace armarx::viz static void selectionCallback(void* data, SoPath* path) { CoinVisualizer* this_ = static_cast<CoinVisualizer*>(data); - this_->onSelection(path); + this_->onSelectEvent(path, data::InteractionFeedbackType::SELECT); } static void deselectionCallback(void* data, SoPath* path) { CoinVisualizer* this_ = static_cast<CoinVisualizer*>(data); - this_->onDeselection(path); + this_->onSelectEvent(path, data::InteractionFeedbackType::DESELECT); } static const char* toString(CoinVisualizerState state) @@ -62,12 +62,6 @@ namespace armarx::viz return "UNKNOWN"; } - // static void updateVisualizationCB(void* data, SoSensor* sensor) - // { - // auto* visu = static_cast<CoinVisualizer*>(data); - // visu->update(); - // } - struct TimedBlock { TimedBlock(const char* function) @@ -385,6 +379,8 @@ namespace armarx::viz storage = stateStorage; selection->deselectAll(); root->removeAllChildren(); + interactionFeedbackBuffer.clear(); + elementInteractions.clear(); layers.data.clear(); pulledUpdates.revision = 0; pulledUpdates.updates.clear(); @@ -578,56 +574,7 @@ namespace armarx::viz return static_cast<ElementInteractionData*>(userData); } - void CoinVisualizer::onSelection(SoPath* path) - { - if (state != CoinVisualizerState::RUNNING) - { - return; - } - - ElementInteractionData* id = findInteractionDataOnPath(path); - if (id == nullptr) - { - // In this case, we want to deselect all objects in the scene, - // because the selected object was not marked for selection interactions - selection->deselectAll(); - - // Removed logging, since this is not an error, but expected - // This happens, when the user selects an object that was not marked as selectable - // ARMARX_INFO << "Selected something. But no user data attached."; - return; - } - - CoinLayer* layer = layers.findLayer(id->layer); - if (layer == nullptr) - { - ARMARX_WARNING << "Selected an element whose layer does not exist: \n" - << "Layer: " << id->layer.first << "/" << id->layer.second - << ", element: " << id->element; - return; - } - CoinLayerElement* element = layer->findElement(id->element); - if (element == nullptr) - { - ARMARX_WARNING << "Selected an element which does not exist: \n" - << "Layer: " << id->layer.first << "/" << id->layer.second - << ", element: " << id->element; - return; - } - - ARMARX_INFO << "Selected element: \n" - << "Layer: " << id->layer.first << "/" << id->layer.second - << ", element: " << id->element; - - viz::data::InteractionFeedback& feedback = interactionFeedbackBuffer.emplace_back(); - feedback.type = viz::data::InteractionFeedbackType::SELECT; - feedback.component = id->layer.first; - feedback.layer = id->layer.second; - feedback.element = id->element; - feedback.revision = pulledUpdates.revision; - } - - void CoinVisualizer::onDeselection(SoPath* path) + void CoinVisualizer::onSelectEvent(SoPath* path, int eventType) { if (state != CoinVisualizerState::RUNNING) { @@ -637,14 +584,20 @@ namespace armarx::viz ElementInteractionData* id = findInteractionDataOnPath(path); if (id == nullptr) { - // An object was deselected that does not have any interactions enabled + if (eventType == data::InteractionFeedbackType::SELECT) + { + // An object was selected that does not have any interactions enabled + // We deselect all other elements in this case to avoid highlighting + // non-interactable elements + selection->deselectAll(); + } return; } CoinLayer* layer = layers.findLayer(id->layer); if (layer == nullptr) { - ARMARX_WARNING << "Deselected an element whose layer does not exist: \n" + ARMARX_WARNING << "Selected/Deselected an element whose layer does not exist: \n" << "Layer: " << id->layer.first << "/" << id->layer.second << ", element: " << id->element; return; @@ -652,19 +605,18 @@ namespace armarx::viz CoinLayerElement* element = layer->findElement(id->element); if (element == nullptr) { - ARMARX_WARNING << "Deselected an element which does not exist: \n" + ARMARX_WARNING << "Selected/Deselected an element which does not exist: \n" << "Layer: " << id->layer.first << "/" << id->layer.second << ", element: " << id->element; return; } - ARMARX_INFO << "Deselected element: \n" - << "Layer: " << id->layer.first << "/" << id->layer.second - << ", element: " << id->element; - + // ARMARX_INFO << "Selected/Deselected element: \n" + // << "Layer: " << id->layer.first << "/" << id->layer.second + // << ", element: " << id->element; viz::data::InteractionFeedback& feedback = interactionFeedbackBuffer.emplace_back(); - feedback.type = viz::data::InteractionFeedbackType::DESELECT; + feedback.type = eventType; feedback.component = id->layer.first; feedback.layer = id->layer.second; feedback.element = id->element; diff --git a/source/RobotAPI/components/ArViz/Coin/Visualizer.h b/source/RobotAPI/components/ArViz/Coin/Visualizer.h index cffa7eb0c6d3b612f1e009d149d8046b1fb4a39c..885387a19b706d204b36b60c69bed607f1331f1d 100644 --- a/source/RobotAPI/components/ArViz/Coin/Visualizer.h +++ b/source/RobotAPI/components/ArViz/Coin/Visualizer.h @@ -236,8 +236,7 @@ namespace armarx::viz void emitLayersChanged(std::vector<CoinLayerID> const& layerIDs); void emitLayerUpdated(CoinLayerID const& layerID, CoinLayer const& layer); - void onSelection(SoPath* path); - void onDeselection(SoPath* path); + void onSelectEvent(SoPath* path, int eventType); // These are selectable element IDs and need to be persistent in memory. // We store a raw pointer to these into the SoSeperator objects of Coin. // Later, we can retrieve the element ID from this pointer, if it has been selected.