Skip to content

Commit

Permalink
Updated GNENetHelper. Refs #13894
Browse files Browse the repository at this point in the history
  • Loading branch information
palvarezlopez committed Dec 19, 2023
1 parent 72967fe commit 2ba1cd8
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 26 deletions.
36 changes: 36 additions & 0 deletions src/netedit/GNENetHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,24 @@ GNENetHelper::AttributeCarriers::retrieveAdditional(GNEAttributeCarrier* AC, boo
}


GNEAdditional*
GNENetHelper::AttributeCarriers::retrieveAdditionalGL(const GUIGlObject* glObject, bool hardFail) const {
// iterate over all additionals
for (const auto &additionalTag : myAdditionals){
for (const auto &additionalPair : additionalTag.second) {
if (additionalPair.first == glObject) {
return additionalPair.second;
}
}
}
if (hardFail) {
throw ProcessError("Attempted to retrieve non-existant additional (glObject)");
} else {
return nullptr;
}
}


GNEAdditional*
GNENetHelper::AttributeCarriers::retrieveRerouterInterval(const std::string& rerouterID, const SUMOTime begin, const SUMOTime end) const {
// first retrieve rerouter
Expand Down Expand Up @@ -1414,6 +1432,24 @@ GNENetHelper::AttributeCarriers::retrieveDemandElement(GNEAttributeCarrier* AC,
}


GNEDemandElement*
GNENetHelper::AttributeCarriers::retrieveDemandElementGL(const GUIGlObject* glObject, bool hardFail) const {
// iterate over all demand elements
for (const auto &demandElementTag : myDemandElements){
for (const auto &demandElementPair : demandElementTag.second) {
if (demandElementPair.first == glObject) {
return demandElementPair.second;
}
}
}
if (hardFail) {
throw ProcessError("Attempted to retrieve non-existant demandElement (glObject)");
} else {
return nullptr;
}
}


std::vector<GNEDemandElement*>
GNENetHelper::AttributeCarriers::getSelectedDemandElements() const {
std::vector<GNEDemandElement*> result;
Expand Down
12 changes: 12 additions & 0 deletions src/netedit/GNENetHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,12 @@ struct GNENetHelper {
*/
GNEAdditional* retrieveAdditional(GNEAttributeCarrier* AC, bool hardFail = true) const;

/**@brief Returns the named additional
* @param[in] id The GLObject related with the additional element
* @param[in] hardFail Whether attempts to retrieve a nonexisting additional should result in an exception
*/
GNEAdditional* retrieveAdditionalGL(const GUIGlObject* glObject, bool hardFail = true) const;

/**@brief Returns the rerouter interval defined by given begin and end
* @param[in] rerouter ID
* @param[in] begin SUMOTime begin
Expand Down Expand Up @@ -444,6 +450,12 @@ struct GNENetHelper {
*/
GNEDemandElement* retrieveDemandElement(GNEAttributeCarrier* AC, bool hardFail = true) const;

/**@brief Returns the named demand
* @param[in] id The GLObject related with the demand element
* @param[in] hardFail Whether attempts to retrieve a nonexisting demand should result in an exception
*/
GNEDemandElement* retrieveDemandElementGL(const GUIGlObject* glObject, bool hardFail = true) const;

/// @brief get selected demand elements
std::vector<GNEDemandElement*> getSelectedDemandElements() const;

Expand Down
36 changes: 12 additions & 24 deletions src/netedit/GNEViewNet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2215,17 +2215,11 @@ GNEViewNet::getLaneAtPopupPosition() {

GNEAdditional*
GNEViewNet::getAdditionalAtPopupPosition() {
if (makeCurrent()) {
// get all gl objects in position
auto glObjects = getGUIGlObjectsAtPosition(getPopupPosition(), 0.1);
// swap objects
std::reverse(glObjects.begin(), glObjects.end());
// get first object that can be parsed to additional element
for (const auto& glObject : glObjects) {
auto additionalElement = dynamic_cast<GNEAdditional*>(glObject);
if (additionalElement) {
return additionalElement;
}
// get first object that can be parsed to additional element
for (const auto& glObject : gPostDrawing.getElementsUnderCursor()) {
auto additionalElement = myNet->getAttributeCarriers()->retrieveAdditionalGL(glObject, false);
if (additionalElement) {
return additionalElement;
}
}
return nullptr;
Expand All @@ -2234,17 +2228,11 @@ GNEViewNet::getAdditionalAtPopupPosition() {

GNEDemandElement*
GNEViewNet::getDemandElementAtPopupPosition() {
if (makeCurrent()) {
// get all gl objects in position
auto glObjects = getGUIGlObjectsAtPosition(getPopupPosition(), 0.1);
// swap objects
std::reverse(glObjects.begin(), glObjects.end());
// get first object that can be parsed to demand element
for (const auto& glObject : glObjects) {
auto demandElement = dynamic_cast<GNEDemandElement*>(glObject);
if (demandElement) {
return demandElement;
}
// get first object that can be parsed to demand element
for (const auto& glObject : gPostDrawing.getElementsUnderCursor()) {
auto demandElement = myNet->getAttributeCarriers()->retrieveDemandElementGL(glObject, false);
if (demandElement) {
return demandElement;
}
}
return nullptr;
Expand Down Expand Up @@ -5614,7 +5602,7 @@ GNEViewNet::drawDeleteDottedContour() {
gPostDrawing.markedElementDeleteContour->drawGL(*myVisualizationSettings);
}
// iterate over all objects under cursor
for (const auto& objectUnderCursor : gPostDrawing.getElementUnderCursor()) {
for (const auto& objectUnderCursor : gPostDrawing.getElementsUnderCursor()) {
// compare objectUnderCursor and markedElementsDeleteContour types
if (objectUnderCursor->getType() == gPostDrawing.markedElementDeleteContour->getType()) {
// check if is a normalGLObject or a path element
Expand Down Expand Up @@ -5642,7 +5630,7 @@ GNEViewNet::drawSelectDottedContour() {
gPostDrawing.markedElementSelectContour->drawGL(*myVisualizationSettings);
}
// iterate over all objects under cursor
for (const auto& objectUnderCursor : gPostDrawing.getElementUnderCursor()) {
for (const auto& objectUnderCursor : gPostDrawing.getElementsUnderCursor()) {
// compare objectUnderCursor and markedElementsSelectContour types
if (objectUnderCursor->getType() == gPostDrawing.markedElementSelectContour->getType()) {
// check if is a normalGLObject or a path element
Expand Down
2 changes: 1 addition & 1 deletion src/utils/gui/settings/GUIPostDrawing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ GUIPostDrawing::isElementUnderCursor(const GUIGlObject* GLObject) const {


const std::vector<const GUIGlObject*>&
GUIPostDrawing::getElementUnderCursor() const {
GUIPostDrawing::getElementsUnderCursor() const {
return myElementsUnderCursor;
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/gui/settings/GUIPostDrawing.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class GUIPostDrawing {
bool isElementUnderCursor(const GUIGlObject* GLObject) const;

/// @brief get all elements under cursor
const std::vector<const GUIGlObject*>& getElementUnderCursor() const;
const std::vector<const GUIGlObject*>& getElementsUnderCursor() const;

/// @brief recompute boundaries
GUIGlObjectType recomputeBoundaries = GLO_NETWORK;
Expand Down

0 comments on commit 2ba1cd8

Please sign in to comment.