Skip to content

Commit

Permalink
Updated GNEInternalLanes. Refs #13894
Browse files Browse the repository at this point in the history
  • Loading branch information
palvarezlopez committed Dec 19, 2023
1 parent 5ea3e68 commit cfeb434
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 46 deletions.
44 changes: 41 additions & 3 deletions src/netedit/GNENetHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <netedit/elements/network/GNEEdgeTemplate.h>
#include <netedit/elements/network/GNEEdgeType.h>
#include <netedit/elements/network/GNEWalkingArea.h>
#include <netedit/elements/network/GNEInternalLane.h>
#include <netedit/frames/common/GNEInspectorFrame.h>
#include <netedit/frames/demand/GNEContainerFrame.h>
#include <netedit/frames/demand/GNEContainerPlanFrame.h>
Expand Down Expand Up @@ -963,6 +964,23 @@ GNENetHelper::AttributeCarriers::getNumberOfSelectedConnections() const {
}


GNEInternalLane*
GNENetHelper::AttributeCarriers::retrieveInternalLane(const GUIGlObject* glObject, bool hardFail) const {
// iterate over internalLanes
for (const auto& internalLane : myInternalLanes) {
if (internalLane.second == glObject) {
return internalLane.second;
}
}
if (hardFail) {
// If POI wasn't found, throw exception
throw UnknownElement("Attempted to retrieve non-existant internalLane " + glObject->getMicrosimID());
} else {
return nullptr;
}
}


GNEAdditional*
GNENetHelper::AttributeCarriers::retrieveAdditional(SumoXMLTag type, const std::string& id, bool hardFail) const {
for (const auto& additional : myAdditionals.at(type)) {
Expand Down Expand Up @@ -2385,9 +2403,29 @@ GNENetHelper::AttributeCarriers::deleteConnection(GNEConnection* connection) {
} else {
myConnections.erase(finder);
}
// remove it from inspected elements and GNEElementTree
myNet->getViewNet()->removeFromAttributeCarrierInspected(connection);
myNet->getViewNet()->getViewParent()->getInspectorFrame()->getHierarchicalElementTree()->removeCurrentEditedAttributeCarrier(connection);
}


void
GNENetHelper::AttributeCarriers::insertInternalLane(GNEInternalLane* internalLane) {
if (myInternalLanes.count(internalLane->getGUIGlObject()) > 0) {
throw ProcessError(internalLane->getTagStr() + " with ID='" + internalLane->getID() + "' already exist");
} else {
myInternalLanes[internalLane->getGUIGlObject()] = internalLane;
}
myNet->addGLObjectIntoGrid(internalLane);
}


void
GNENetHelper::AttributeCarriers::deleteInternalLane(GNEInternalLane* internalLane) {
const auto finder = myInternalLanes.find(internalLane->getGUIGlObject());
if (finder == myInternalLanes.end()) {
throw ProcessError(internalLane->getTagStr() + " with ID='" + internalLane->getID() + "' wasn't previously inserted");
} else {
myInternalLanes.erase(finder);
}
myNet->removeGLObjectFromGrid(internalLane);
}


Expand Down
33 changes: 30 additions & 3 deletions src/netedit/GNENetHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ struct GNENetHelper {
friend class GNEChange_DataInterval;
friend class GNEChange_GenericData;
friend class GNEChange_MeanData;
friend class GNETLSEditorFrame;

public:
/// @brief constructor
Expand Down Expand Up @@ -338,6 +339,18 @@ struct GNENetHelper {

/// @}

/// @name function for internalLanes
/// @{

/**@brief get InternalLane by GUIGlObject
* @param[in] glObject The GUIGlObject associated with the element
* @param[in] hardFail Whether attempts to retrieve a nonexisting InternalLane should result in an exception
* @throws UnknownElement
*/
GNEInternalLane* retrieveInternalLane(const GUIGlObject* glObject, bool hardFail = true) const;

/// @}

/// @name function for additionals
/// @{
/**@brief Returns the named additional
Expand Down Expand Up @@ -657,7 +670,7 @@ struct GNENetHelper {

/// @}

/// @name walking areas protected functions
/// @name connection protected functions
/// @{

/// @brief insert connection in container
Expand All @@ -668,6 +681,17 @@ struct GNENetHelper {

/// @}

/// @name internalLane protected functions
/// @{

/// @brief insert internalLane in container
void insertInternalLane(GNEInternalLane* internalLane);

/// @brief delete internalLane from container
void deleteInternalLane(GNEInternalLane* internalLane);

/// @}

/// @name additionals protected functions
/// @{

Expand Down Expand Up @@ -759,12 +783,15 @@ struct GNENetHelper {
/// @brief map with the ID and pointer to edges of net
std::map<std::string, std::pair<const GUIGlObject*, GNEEdge*> > myEdges;

/// @brief set with lanes
/// @brief map with lanes
std::map<const GUIGlObject*, GNELane*> myLanes;

/// @brief set with connetions
/// @brief map with connetions
std::map<const GUIGlObject*, GNEConnection*> myConnections;

/// @brief map with internal lanes
std::map<const GUIGlObject*, GNEInternalLane*> myInternalLanes;

/// @brief map with the tag and pointer to additional elements of net
std::map<SumoXMLTag, std::map<const GUIGlObject*, GNEAdditional*> > myAdditionals;

Expand Down
4 changes: 1 addition & 3 deletions src/netedit/GNEViewNetHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -837,10 +837,9 @@ GNEViewNetHelper::ObjectsUnderCursor::updateNetworkElements(ObjectsContainer& co
}
break;
}
/*
case GLO_TLLOGIC: {
// get internal lane
auto internalLane = dynamic_cast<GNEInternalLane*>(glObject);
auto internalLane = myViewNet->getNet()->getAttributeCarriers()->retrieveInternalLane(glObject);
// check front element
if (glObject == frontGLObject) {
// insert at front
Expand All @@ -851,7 +850,6 @@ GNEViewNetHelper::ObjectsUnderCursor::updateNetworkElements(ObjectsContainer& co
}
break;
}
*/
default:
break;
}
Expand Down
52 changes: 25 additions & 27 deletions src/netedit/elements/network/GNEInternalLane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ GNEInternalLane::checkDrawRelatedContour() const {

bool
GNEInternalLane::checkDrawOverContour() const {
return false;
return myNet->getViewNet()->checkDrawOverContour(this);
}


Expand Down Expand Up @@ -176,33 +176,31 @@ GNEInternalLane::drawGL(const GUIVisualizationSettings& s) const {
if (!myNet->getViewNet()->selectingDetectorsTLSMode()) {
// get link state color
const auto linkStateColor = colorForLinksState(myState);
// avoid draw invisible elements
if (linkStateColor.alpha() != 0) {
// push name
GLHelper::pushName(getGlID());
// push layer matrix
GLHelper::pushMatrix();
// translate to front
myEditor->getViewNet()->drawTranslateFrontAttributeCarrier(myJunctionParent, GLO_TLLOGIC);
// move front again
glTranslated(0, 0, 0.5);
// set color
GLHelper::setColor(linkStateColor);
// draw lane checking whether it is not too small
if (s.scale < 1.) {
GLHelper::drawLine(myInternalLaneGeometry.getShape());
} else {
GUIGeometry::drawGeometry(s, myNet->getViewNet()->getPositionInformation(), myInternalLaneGeometry, 0.2);
}
// pop layer matrix
GLHelper::popMatrix();
// pop name
GLHelper::popName();
// draw edge name
if (s.internalEdgeName.show(this)) {
GLHelper::drawTextSettings(s.internalEdgeName, getMicrosimID(), myInternalLaneGeometry.getShape().getLineCenter(), s.scale, s.angle);
}
// push name
GLHelper::pushName(getGlID());
// push layer matrix
GLHelper::pushMatrix();
// translate to front
myEditor->getViewNet()->drawTranslateFrontAttributeCarrier(myJunctionParent, GLO_TLLOGIC);
// move front again
glTranslated(0, 0, 0.5);
// set color
GLHelper::setColor(linkStateColor);
// draw geometry
GUIGeometry::drawGeometry(s, myNet->getViewNet()->getPositionInformation(), myInternalLaneGeometry,
s.connectionSettings.connectionWidth);
// pop layer matrix
GLHelper::popMatrix();
// pop name
GLHelper::popName();
// draw edge name
if (s.internalEdgeName.show(this)) {
GLHelper::drawTextSettings(s.internalEdgeName, getMicrosimID(), myInternalLaneGeometry.getShape().getLineCenter(),
s.scale, s.angle);
}
// draw dotted geometry
myContour.drawDottedContourExtruded(s, myInternalLaneGeometry.getShape(), s.connectionSettings.connectionWidth,
1, true, true, s.dottedContourSettings.segmentWidthSmall);
}
}

Expand Down
20 changes: 10 additions & 10 deletions src/netedit/frames/network/GNETLSEditorFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,8 @@ GNETLSEditorFrame::buildInternalLanes(const NBTrafficLightDefinition* tlDef) {
// clean up previous internal lanes
for (const auto& internalLanes : myInternalLanes) {
for (const auto& internalLane : internalLanes.second) {
// remove internal lane from grid
myViewNet->getNet()->getGrid().removeAdditionalGLObject(internalLane);
// remove internal lane from ACs
myViewNet->getNet()->getAttributeCarriers()->deleteInternalLane(internalLane);
// delete internal lane
delete internalLane;
}
Expand Down Expand Up @@ -370,8 +370,8 @@ GNETLSEditorFrame::buildInternalLanes(const NBTrafficLightDefinition* tlDef) {
shape.push_back(laneShapeTo.positionAtOffset(MIN2(1.0, laneShapeFrom.length())));
}
GNEInternalLane* internalLane = new GNEInternalLane(this, myTLSJunction->getCurrentJunction(), innerID + '_' + toString(tlIndex), shape, tlIndex);
// due GNEInternalLane aren't attribute carriers, we need to use the net grid
myViewNet->getNet()->getGrid().addAdditionalGLObject(internalLane);
// add into atribute carriers
myViewNet->getNet()->getAttributeCarriers()->insertInternalLane(internalLane);
myInternalLanes[tlIndex].push_back(internalLane);
}
// iterate over crossings
Expand All @@ -382,20 +382,20 @@ GNETLSEditorFrame::buildInternalLanes(const NBTrafficLightDefinition* tlDef) {
PositionVector forward = crossing->shape;
forward.move2side(crossing->width / 4);
GNEInternalLane* internalLane = new GNEInternalLane(this, myTLSJunction->getCurrentJunction(), crossing->id, forward, crossing->tlLinkIndex);
// due GNEInternalLane aren't attribute carriers, we need to use the net grid
myViewNet->getNet()->getGrid().addAdditionalGLObject(internalLane);
// add into atribute carriers
myViewNet->getNet()->getAttributeCarriers()->insertInternalLane(internalLane);
myInternalLanes[crossing->tlLinkIndex].push_back(internalLane);
PositionVector backward = crossing->shape.reverse();
backward.move2side(crossing->width / 4);
GNEInternalLane* internalLaneReverse = new GNEInternalLane(this, myTLSJunction->getCurrentJunction(), crossing->id + "_r", backward, crossing->tlLinkIndex2);
// due GNEInternalLane aren't attribute carriers, we need to use the net grid
myViewNet->getNet()->getGrid().addAdditionalGLObject(internalLaneReverse);
// add into atribute carriers
myViewNet->getNet()->getAttributeCarriers()->insertInternalLane(internalLane);
myInternalLanes[crossing->tlLinkIndex2].push_back(internalLaneReverse);
} else {
// draw only one lane for both directions
GNEInternalLane* internalLane = new GNEInternalLane(this, myTLSJunction->getCurrentJunction(), crossing->id, crossing->shape, crossing->tlLinkIndex);
// due GNEInternalLane aren't attribute carriers, we need to use the net grid
myViewNet->getNet()->getGrid().addAdditionalGLObject(internalLane);
// add into atribute carriers
myViewNet->getNet()->getAttributeCarriers()->insertInternalLane(internalLane);
myInternalLanes[crossing->tlLinkIndex].push_back(internalLane);
}
}
Expand Down

0 comments on commit cfeb434

Please sign in to comment.