Skip to content

Commit

Permalink
Optimiced GUIViewObjectsHandler. Refs #15844
Browse files Browse the repository at this point in the history
  • Loading branch information
palvarezlopez committed Jan 17, 2025
1 parent af77d19 commit 8700bd1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/netedit/GNEViewNet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
21 changes: 16 additions & 5 deletions src/utils/gui/div/GUIViewObjectsHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<const GNEPathElement*>&
GUIViewObjectsHandler::getRedrawPathElements() const {
return myRedrawPathElements;
Expand Down
3 changes: 3 additions & 0 deletions src/utils/gui/div/GUIViewObjectsHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8700bd1

Please sign in to comment.