From 8700bd16c4e39b5ab6abaef54680b4b30b62bcd1 Mon Sep 17 00:00:00 2001 From: Pablo Alvarez Lopez Date: Fri, 17 Jan 2025 13:39:48 +0100 Subject: [PATCH] Optimiced GUIViewObjectsHandler. Refs #15844 --- src/netedit/GNEViewNet.cpp | 4 ++++ src/utils/gui/div/GUIViewObjectsHandler.cpp | 21 ++++++++++++++++----- src/utils/gui/div/GUIViewObjectsHandler.h | 3 +++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/netedit/GNEViewNet.cpp b/src/netedit/GNEViewNet.cpp index 8ba68063f913..4627eb1cd508 100644 --- a/src/netedit/GNEViewNet.cpp +++ b/src/netedit/GNEViewNet.cpp @@ -496,6 +496,8 @@ GNEViewNet::updateObjectsInBoundary(const Boundary& boundary) { myVisualizationSettings->drawForRectangleSelection = true; // draw all GL elements within the small boundary drawGLElements(boundary); + // swap selected objects (needed after selecting) + gViewObjectsHandler.reverseSelectedObjects(); // restore draw for object under cursor myVisualizationSettings->drawForViewObjectsHandler = false; myVisualizationSettings->drawForRectangleSelection = false; @@ -526,6 +528,8 @@ GNEViewNet::updateObjectsInPosition(const Position& pos) { myVisualizationSettings->drawForViewObjectsHandler = true; // draw all GL elements within the small boundary drawGLElements(positionBoundary); + // swap selected objects (needed after selecting) + gViewObjectsHandler.reverseSelectedObjects(); // check if filter edges that have the mouse over their geometry points if (myEditModes.isCurrentSupermodeNetwork() && myEditModes.networkEditMode == NetworkEditMode::NETWORK_MOVE) { gViewObjectsHandler.isolateEdgeGeometryPoints(); diff --git a/src/utils/gui/div/GUIViewObjectsHandler.cpp b/src/utils/gui/div/GUIViewObjectsHandler.cpp index c01ccbfff179..11bbbd02aa8a 100644 --- a/src/utils/gui/div/GUIViewObjectsHandler.cpp +++ b/src/utils/gui/div/GUIViewObjectsHandler.cpp @@ -273,7 +273,10 @@ GUIViewObjectsHandler::selectObject(const GUIGlObject* GLObject, const double la return false; } else { auto& layerContainer = mySortedSelectedObjects[layer * -1]; - layerContainer.insert(layerContainer.begin(), ObjectContainer(GLObject)); + if (layerContainer.size() == 10) { + layerContainer.reserve(10000000); + } + layerContainer.push_back(ObjectContainer(GLObject)); mySelectedObjects[GLObject] = std::make_pair(fullBoundary, segment); myNumberOfSelectedObjects++; return true; @@ -302,8 +305,8 @@ GUIViewObjectsHandler::selectGeometryPoint(const GUIGlObject* GLObject, const in } // no element found then add it auto& layerContainer = mySortedSelectedObjects[layer * -1]; - auto it = layerContainer.insert(layerContainer.begin(), ObjectContainer(GLObject)); - it->geometryPoints.push_back(newIndex); + layerContainer.push_back(ObjectContainer(GLObject)); + layerContainer.back().geometryPoints.push_back(newIndex); mySelectedObjects[GLObject] = std::make_pair(false, nullptr); myNumberOfSelectedObjects++; return true; @@ -330,8 +333,8 @@ GUIViewObjectsHandler::selectPositionOverShape(const GUIGlObject* GLObject, cons } // no element found then add it auto& layerContainer = mySortedSelectedObjects[layer * -1]; - auto it = layerContainer.insert(layerContainer.begin(), ObjectContainer(GLObject)); - it->posOverShape = pos; + layerContainer.push_back(ObjectContainer(GLObject)); + layerContainer.back().posOverShape = pos; mySelectedObjects[GLObject] = std::make_pair(false, nullptr); myNumberOfSelectedObjects++; return true; @@ -406,6 +409,14 @@ GUIViewObjectsHandler::getNumberOfSelectedObjects() const { } +void +GUIViewObjectsHandler::reverseSelectedObjects() { + for (auto &layerContainer : mySortedSelectedObjects) { + std::reverse(layerContainer.second.begin(), layerContainer.second.end()); + } +} + + const std::set& GUIViewObjectsHandler::getRedrawPathElements() const { return myRedrawPathElements; diff --git a/src/utils/gui/div/GUIViewObjectsHandler.h b/src/utils/gui/div/GUIViewObjectsHandler.h index 92c8dccbb8dc..c8003dcad5b5 100644 --- a/src/utils/gui/div/GUIViewObjectsHandler.h +++ b/src/utils/gui/div/GUIViewObjectsHandler.h @@ -145,6 +145,9 @@ class GUIViewObjectsHandler { /// @brief get number of selected objects int getNumberOfSelectedObjects() const; + /// @brief reverse selected objects + void reverseSelectedObjects(); + /// @} /// @name functions related with redrawing path elements