Skip to content

Commit

Permalink
Now objects are sorted by layer in GUIPostDrawing. Refs #13894
Browse files Browse the repository at this point in the history
  • Loading branch information
palvarezlopez committed Dec 19, 2023
1 parent 4ea8f7d commit 44adc3b
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 108 deletions.
114 changes: 70 additions & 44 deletions src/netedit/GNEViewNet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1980,10 +1980,12 @@ GNEViewNet::setLastCreatedRoute(GNEDemandElement* lastCreatedRoute) {
GNEJunction*
GNEViewNet::getJunctionAtPopupPosition() {
// get first object that can be found in their container
for (const auto& glObject : gPostDrawing.getElementsUnderCursor()) {
auto junction = myNet->getAttributeCarriers()->retrieveJunction(glObject.first, false);
if (junction) {
return junction;
for (const auto& glObjectLayer : gPostDrawing.getElementsUnderCursor()) {
for (const auto &glObject : glObjectLayer.second) {
auto junction = myNet->getAttributeCarriers()->retrieveJunction(glObject.first, false);
if (junction) {
return junction;
}
}
}
return nullptr;
Expand All @@ -1993,10 +1995,12 @@ GNEViewNet::getJunctionAtPopupPosition() {
GNEConnection*
GNEViewNet::getConnectionAtPopupPosition() {
// get first object that can be found in their container
for (const auto& glObject : gPostDrawing.getElementsUnderCursor()) {
auto connection = myNet->getAttributeCarriers()->retrieveConnection(glObject.first, false);
if (connection) {
return connection;
for (const auto& glObjectLayer : gPostDrawing.getElementsUnderCursor()) {
for (const auto &glObject : glObjectLayer.second) {
auto connection = myNet->getAttributeCarriers()->retrieveConnection(glObject.first, false);
if (connection) {
return connection;
}
}
}
return nullptr;
Expand All @@ -2006,10 +2010,12 @@ GNEViewNet::getConnectionAtPopupPosition() {
GNECrossing*
GNEViewNet::getCrossingAtPopupPosition() {
// get first object that can be found in their container
for (const auto& glObject : gPostDrawing.getElementsUnderCursor()) {
auto crossing = myNet->getAttributeCarriers()->retrieveCrossing(glObject.first, false);
if (crossing) {
return crossing;
for (const auto& glObjectLayer : gPostDrawing.getElementsUnderCursor()) {
for (const auto &glObject : glObjectLayer.second) {
auto crossing = myNet->getAttributeCarriers()->retrieveCrossing(glObject.first, false);
if (crossing) {
return crossing;
}
}
}
return nullptr;
Expand All @@ -2019,10 +2025,12 @@ GNEViewNet::getCrossingAtPopupPosition() {
GNEWalkingArea*
GNEViewNet::getWalkingAreaAtPopupPosition() {
// get first object that can be found in their container
for (const auto& glObject : gPostDrawing.getElementsUnderCursor()) {
auto walkingArea = myNet->getAttributeCarriers()->retrieveWalkingArea(glObject.first, false);
if (walkingArea) {
return walkingArea;
for (const auto& glObjectLayer : gPostDrawing.getElementsUnderCursor()) {
for (const auto &glObject : glObjectLayer.second) {
auto walkingArea = myNet->getAttributeCarriers()->retrieveWalkingArea(glObject.first, false);
if (walkingArea) {
return walkingArea;
}
}
}
return nullptr;
Expand All @@ -2032,10 +2040,12 @@ GNEViewNet::getWalkingAreaAtPopupPosition() {
GNEEdge*
GNEViewNet::getEdgeAtPopupPosition() {
// get first object that can be found in their container
for (const auto& glObject : gPostDrawing.getElementsUnderCursor()) {
auto edge = myNet->getAttributeCarriers()->retrieveEdge(glObject.first, false);
if (edge) {
return edge;
for (const auto& glObjectLayer : gPostDrawing.getElementsUnderCursor()) {
for (const auto &glObject : glObjectLayer.second) {
auto edge = myNet->getAttributeCarriers()->retrieveEdge(glObject.first, false);
if (edge) {
return edge;
}
}
}
return nullptr;
Expand All @@ -2045,10 +2055,12 @@ GNEViewNet::getEdgeAtPopupPosition() {
GNELane*
GNEViewNet::getLaneAtPopupPosition() {
// get first object that can be found in their container
for (const auto& glObject : gPostDrawing.getElementsUnderCursor()) {
auto lane = myNet->getAttributeCarriers()->retrieveLane(glObject.first, false);
if (lane) {
return lane;
for (const auto& glObjectLayer : gPostDrawing.getElementsUnderCursor()) {
for (const auto &glObject : glObjectLayer.second) {
auto lane = myNet->getAttributeCarriers()->retrieveLane(glObject.first, false);
if (lane) {
return lane;
}
}
}
return nullptr;
Expand All @@ -2058,10 +2070,12 @@ GNEViewNet::getLaneAtPopupPosition() {
GNEAdditional*
GNEViewNet::getAdditionalAtPopupPosition() {
// get first object that can be found in their container
for (const auto& glObject : gPostDrawing.getElementsUnderCursor()) {
auto additionalElement = myNet->getAttributeCarriers()->retrieveAdditional(glObject.first, false);
if (additionalElement) {
return additionalElement;
for (const auto& glObjectLayer : gPostDrawing.getElementsUnderCursor()) {
for (const auto &glObject : glObjectLayer.second) {
auto additionalElement = myNet->getAttributeCarriers()->retrieveAdditional(glObject.first, false);
if (additionalElement) {
return additionalElement;
}
}
}
return nullptr;
Expand All @@ -2071,10 +2085,12 @@ GNEViewNet::getAdditionalAtPopupPosition() {
GNEDemandElement*
GNEViewNet::getDemandElementAtPopupPosition() {
// get first object that can be found in their container
for (const auto& glObject : gPostDrawing.getElementsUnderCursor()) {
auto demandElement = myNet->getAttributeCarriers()->retrieveDemandElement(glObject.first, false);
if (demandElement) {
return demandElement;
for (const auto& glObjectLayer : gPostDrawing.getElementsUnderCursor()) {
for (const auto &glObject : glObjectLayer.second) {
auto demandElement = myNet->getAttributeCarriers()->retrieveDemandElement(glObject.first, false);
if (demandElement) {
return demandElement;
}
}
}
return nullptr;
Expand All @@ -2084,10 +2100,12 @@ GNEViewNet::getDemandElementAtPopupPosition() {
GNEPoly*
GNEViewNet::getPolygonAtPopupPosition() {
// get first object that can be parsed to poly element
for (const auto& glObject : gPostDrawing.getElementsUnderCursor()) {
auto polygon = dynamic_cast<GNEPoly*>(myNet->getAttributeCarriers()->retrieveAdditional(glObject.first, false));
if (polygon) {
return polygon;
for (const auto& glObjectLayer : gPostDrawing.getElementsUnderCursor()) {
for (const auto &glObject : glObjectLayer.second) {
auto polygon = dynamic_cast<GNEPoly*>(myNet->getAttributeCarriers()->retrieveAdditional(glObject.first, false));
if (polygon) {
return polygon;
}
}
}
return nullptr;
Expand All @@ -2097,10 +2115,12 @@ GNEViewNet::getPolygonAtPopupPosition() {
GNEPOI*
GNEViewNet::getPOIAtPopupPosition() {
// get first object that can be parsed to POI element
for (const auto& glObject : gPostDrawing.getElementsUnderCursor()) {
auto POI = dynamic_cast<GNEPOI*>(myNet->getAttributeCarriers()->retrieveAdditional(glObject.first, false));
if (POI) {
return POI;
for (const auto& glObjectLayer : gPostDrawing.getElementsUnderCursor()) {
for (const auto &glObject : glObjectLayer.second) {
auto POI = dynamic_cast<GNEPOI*>(myNet->getAttributeCarriers()->retrieveAdditional(glObject.first, false));
if (POI) {
return POI;
}
}
}
return nullptr;
Expand All @@ -2110,10 +2130,12 @@ GNEViewNet::getPOIAtPopupPosition() {
GNETAZ*
GNEViewNet::getTAZAtPopupPosition() {
// get first object that can be parsed to TAZ element
for (const auto& glObject : gPostDrawing.getElementsUnderCursor()) {
auto TAZ = dynamic_cast<GNETAZ*>(myNet->getAttributeCarriers()->retrieveAdditional(glObject.first, false));
if (TAZ) {
return TAZ;
for (const auto& glObjectLayer : gPostDrawing.getElementsUnderCursor()) {
for (const auto &glObject : glObjectLayer.second) {
auto TAZ = dynamic_cast<GNETAZ*>(myNet->getAttributeCarriers()->retrieveAdditional(glObject.first, false));
if (TAZ) {
return TAZ;
}
}
}
return nullptr;
Expand Down Expand Up @@ -3272,6 +3294,10 @@ GNEViewNet::updateObjectsUnderCursor(const Position &pos) {
myVisualizationSettings->drawForObjectUnderCursor = false;
// pop matrix
GLHelper::popMatrix();
// check if update front element
if (myFrontAttributeCarrier) {
gPostDrawing.updateFrontElement(myFrontAttributeCarrier->getGUIGlObject());
}
// after draw elements, update objects under cursor
myObjectsUnderCursor.updateObjectUnderCursor();
}
Expand Down
20 changes: 11 additions & 9 deletions src/netedit/GNEViewNetHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1010,16 +1010,18 @@ GNEViewNetHelper::ObjectsUnderCursor::updateGenericDataElements(ObjectsContainer


void
GNEViewNetHelper::ObjectsUnderCursor::processGUIGlObjects(const GUIPostDrawing::GLObjectsContainer& objectsContainer) {
GNEViewNetHelper::ObjectsUnderCursor::processGUIGlObjects(const GUIPostDrawing::GLObjectsSortedContainer& objectsContainer) {
// iterate over filtered edge objects
for (const auto& glObject : objectsContainer) {
// update all elements by categories
updateNetworkElements(myObjects, glObject.first);
updateAdditionalElements(myObjects, glObject.first);
updateShapeElements(myObjects, glObject.first);
updateTAZElements(myObjects, glObject.first);
updateDemandElements(myObjects, glObject.first);
updateGenericDataElements(myObjects, glObject.first);
for (const auto& glObjectLayer : objectsContainer) {
for (const auto &glObject : glObjectLayer.second) {
// update all elements by categories
updateNetworkElements(myObjects, glObject.first);
updateAdditionalElements(myObjects, glObject.first);
updateShapeElements(myObjects, glObject.first);
updateTAZElements(myObjects, glObject.first);
updateDemandElements(myObjects, glObject.first);
updateGenericDataElements(myObjects, glObject.first);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/netedit/GNEViewNetHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ struct GNEViewNetHelper {
void updateGenericDataElements(ObjectsContainer& container, const GUIGlObject* glObject);

/// @brief process GL objects
void processGUIGlObjects(const GUIPostDrawing::GLObjectsContainer& objectsContainer);
void processGUIGlObjects(const GUIPostDrawing::GLObjectsSortedContainer& objectsContainer);

/// @brief default constructor
ObjectsUnderCursor();
Expand Down
95 changes: 73 additions & 22 deletions src/utils/gui/settings/GUIPostDrawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <config.h>
#include <algorithm>

#include <utils/shapes/Shape.h>

#include "GUIPostDrawing.h"


Expand All @@ -45,9 +47,11 @@ GUIPostDrawing::clearElements() {
bool
GUIPostDrawing::isElementUnderCursor(const GUIGlObject* GLObject) const {
// avoid to insert duplicated elements
for (auto &element : myElementsUnderCursor) {
if (element.first == GLObject) {
return true;
for (auto &elementLayer : myElementsUnderCursor) {
for (auto &element : elementLayer.second) {
if (element.first == GLObject) {
return true;
}
}
}
return false;
Expand All @@ -57,9 +61,11 @@ GUIPostDrawing::isElementUnderCursor(const GUIGlObject* GLObject) const {
bool
GUIPostDrawing::isGeometryPointUnderCursor(const GUIGlObject* GLObject, const int index) const {
// avoid to insert duplicated elements
for (auto &element : myElementsUnderCursor) {
if (element.first == GLObject) {
return std::find(element.second.begin(), element.second.end(), index) != element.second.end();
for (auto &elementLayer : myElementsUnderCursor) {
for (auto &element : elementLayer.second) {
if (element.first == GLObject) {
return std::find(element.second.begin(), element.second.end(), index) != element.second.end();
}
}
}
return false;
Expand Down Expand Up @@ -96,7 +102,7 @@ GUIPostDrawing::positionWithinShape(const GUIGlObject* GLObject, const Position
}


const GUIPostDrawing::GLObjectsContainer&
const GUIPostDrawing::GLObjectsSortedContainer&
GUIPostDrawing::getElementsUnderCursor() const {
return myElementsUnderCursor;
}
Expand All @@ -105,22 +111,57 @@ GUIPostDrawing::getElementsUnderCursor() const {
const GUIPostDrawing::GeometryPointsContainer&
GUIPostDrawing::getGeometryPoints(const GUIGlObject* GLObject) const {
// avoid to insert duplicated elements
for (auto &element : myElementsUnderCursor) {
if (element.first == GLObject) {
return element.second;
for (auto &elementLayer : myElementsUnderCursor) {
for (auto &element : elementLayer.second) {
if (element.first == GLObject) {
return element.second;
}
}
}
return myEmptyGeometryPoints;
}


void
GUIPostDrawing::updateFrontElement(const GUIGlObject* GLObject) {
GLObjectContainer frontElement(nullptr, {});
// extract element
for (auto &elementLayer : myElementsUnderCursor) {
auto it = elementLayer.second.begin();
while (it != elementLayer.second.end()) {
if (it->first == GLObject) {
// copy element to front element
frontElement.first = it->first;
frontElement.second = it->second;
// remove element from myElementsUnderCursor
it = elementLayer.second.erase(it);
} else {
it++;
}
}
}
// add element again wit a new layer
if (frontElement.first) {
myElementsUnderCursor[(double)GLO_FRONTELEMENT].push_back(frontElement);
}
}


bool
GUIPostDrawing::addElementUnderCursor(const GUIGlObject* GLObject) {
// avoid to insert duplicated elements
if (isElementUnderCursor(GLObject)) {
return false;
} else {
myElementsUnderCursor.push_back(std::make_pair(GLObject, GUIPostDrawing::GeometryPointsContainer()));
// check if this is an element with an associated layer
const auto layer = dynamic_cast<const Shape*>(GLObject);
if (layer) {
auto &layerContainer = myElementsUnderCursor[layer->getShapeLayer() * -1];
layerContainer.insert(layerContainer.begin(), std::make_pair(GLObject, myEmptyGeometryPoints));
} else {
auto &layerContainer = myElementsUnderCursor[GLObject->getType() * -1];
layerContainer.insert(layerContainer.begin(), std::make_pair(GLObject, myEmptyGeometryPoints));
}
return true;
}
}
Expand All @@ -129,22 +170,32 @@ GUIPostDrawing::addElementUnderCursor(const GUIGlObject* GLObject) {
bool
GUIPostDrawing::addGeometryPointUnderCursor(const GUIGlObject* GLObject, const int newIndex) {
// avoid to insert duplicated elements
for (auto &element : myElementsUnderCursor) {
if (element.first == GLObject) {
// avoid double points
for (auto &index : element.second) {
if (index == newIndex) {
return false;
for (auto &elementLayer : myElementsUnderCursor) {
for (auto &element : elementLayer.second) {
if (element.first == GLObject) {
// avoid double points
for (auto &index : element.second) {
if (index == newIndex) {
return false;
}
}
// add new index
element.second.push_back(newIndex);
return true;
}
// add new index
element.second.push_back(newIndex);
return true;
}
}
// no element found then add it
myElementsUnderCursor.push_back(std::make_pair(GLObject, GUIPostDrawing::GeometryPointsContainer()));
myElementsUnderCursor.back().second.push_back(newIndex);
const auto layer = dynamic_cast<const Shape*>(GLObject);
if (layer) {
auto &layerContainer = myElementsUnderCursor[layer->getShapeLayer() * -1];
auto it = layerContainer.insert(layerContainer.begin(), std::make_pair(GLObject, myEmptyGeometryPoints));
it->second.push_back(newIndex);
} else {
auto &layerContainer = myElementsUnderCursor[GLObject->getType() * -1];
auto it = layerContainer.insert(layerContainer.begin(), std::make_pair(GLObject, myEmptyGeometryPoints));
it->second.push_back(newIndex);
}
return true;
}

Expand Down

0 comments on commit 44adc3b

Please sign in to comment.