Skip to content

Commit

Permalink
fix #3192
Browse files Browse the repository at this point in the history
git-svn-id: file:///home/behr_mi/git/sumo_synched/trunk@24666 afbd958f-9f77-42d5-a016-97a22340ccf4
  • Loading branch information
namdre committed Jun 13, 2017
1 parent 0cdbc31 commit ab28938
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 44 deletions.
91 changes: 47 additions & 44 deletions sumo/src/netimport/NIXMLEdgesHandler.cpp
Expand Up @@ -356,7 +356,7 @@ void NIXMLEdgesHandler::addSplit(const SUMOSAXAttributes& attrs) {
WRITE_ERROR("Edge '" + myCurrentID + "' has already a split at position " + toString(e.pos) + ".");
return;
}
const std::string nameid = toString((int)e.pos);
e.nameID = myCurrentID + "." + toString((int)e.pos);
if (e.pos < 0) {
e.pos += myCurrentEdge->getGeometry().length();
}
Expand Down Expand Up @@ -386,8 +386,11 @@ void NIXMLEdgesHandler::addSplit(const SUMOSAXAttributes& attrs) {
if (!ok) {
return;
}
e.node = new NBNode(myCurrentID + "." + nameid,
myCurrentEdge->getGeometry().positionAtOffset(e.pos));
const std::string nodeID = attrs.getOpt(SUMO_ATTR_ID, 0, ok, e.nameID);
e.node = myNodeCont.retrieve(nodeID);
if (e.node == 0) {
e.node = new NBNode(nodeID, myCurrentEdge->getGeometry().positionAtOffset(e.pos));
}
NIXMLNodesHandler::processNodeType(attrs, e.node, e.node->getID(), e.node->getPosition(), false,
myNodeCont, myTLLogicCont);
mySplits.push_back(e);
Expand Down Expand Up @@ -551,50 +554,50 @@ NIXMLEdgesHandler::myEndElement(int element) {
const Split& exp = *i;
assert(exp.lanes.size() != 0);
if (exp.pos > 0 && e->getGeometry().length() + seen > exp.pos && exp.pos > seen) {
if (myNodeCont.insert(exp.node)) {
myNodeCont.markAsSplit(exp.node);
// split the edge
std::string idBefore = exp.idBefore == "" ? e->getID() : exp.idBefore;
std::string idAfter = exp.idAfter == "" ? exp.node->getID() : exp.idAfter;
if (firstID == "") {
firstID = idBefore;
}
myEdgeCont.splitAt(myDistrictCont, e, exp.pos - seen, exp.node,
idBefore, idAfter, e->getNumLanes(), (int) exp.lanes.size(), exp.speed);
seen = exp.pos;
std::vector<int> newLanes = exp.lanes;
NBEdge* pe = myEdgeCont.retrieve(idBefore);
NBEdge* ne = myEdgeCont.retrieve(idAfter);
// reconnect lanes
pe->invalidateConnections(true);
// new on right
int rightMostP = currLanes[0];
int rightMostN = newLanes[0];
for (int l = 0; l < (int) rightMostP - (int) rightMostN; ++l) {
pe->addLane2LaneConnection(0, ne, l, NBEdge::L2L_VALIDATED, true);
}
// new on left
int leftMostP = currLanes.back();
int leftMostN = newLanes.back();
for (int l = 0; l < (int) leftMostN - (int) leftMostP; ++l) {
pe->addLane2LaneConnection(pe->getNumLanes() - 1, ne, leftMostN - l - rightMostN, NBEdge::L2L_VALIDATED, true);
myNodeCont.insert(exp.node);
myNodeCont.markAsSplit(exp.node);
// split the edge
std::string idBefore = exp.idBefore == "" ? e->getID() : exp.idBefore;
std::string idAfter = exp.idAfter == "" ? exp.nameID : exp.idAfter;
if (firstID == "") {
firstID = idBefore;
}
const bool ok = myEdgeCont.splitAt(myDistrictCont, e, exp.pos - seen, exp.node,
idBefore, idAfter, e->getNumLanes(), (int) exp.lanes.size(), exp.speed);
if (!ok) {
WRITE_WARNING("Error on parsing a split (edge '" + myCurrentID + "').");
}
seen = exp.pos;
std::vector<int> newLanes = exp.lanes;
NBEdge* pe = myEdgeCont.retrieve(idBefore);
NBEdge* ne = myEdgeCont.retrieve(idAfter);
// reconnect lanes
pe->invalidateConnections(true);
// new on right
int rightMostP = currLanes[0];
int rightMostN = newLanes[0];
for (int l = 0; l < (int) rightMostP - (int) rightMostN; ++l) {
pe->addLane2LaneConnection(0, ne, l, NBEdge::L2L_VALIDATED, true);
}
// new on left
int leftMostP = currLanes.back();
int leftMostN = newLanes.back();
for (int l = 0; l < (int) leftMostN - (int) leftMostP; ++l) {
pe->addLane2LaneConnection(pe->getNumLanes() - 1, ne, leftMostN - l - rightMostN, NBEdge::L2L_VALIDATED, true);
}
// all other connected
for (int l = 0; l < noLanesMax; ++l) {
if (find(currLanes.begin(), currLanes.end(), l) == currLanes.end()) {
continue;
}
// all other connected
for (int l = 0; l < noLanesMax; ++l) {
if (find(currLanes.begin(), currLanes.end(), l) == currLanes.end()) {
continue;
}
if (find(newLanes.begin(), newLanes.end(), l) == newLanes.end()) {
continue;
}
pe->addLane2LaneConnection(l - rightMostP, ne, l - rightMostN, NBEdge::L2L_VALIDATED, true);
if (find(newLanes.begin(), newLanes.end(), l) == newLanes.end()) {
continue;
}
// move to next
e = ne;
currLanes = newLanes;
} else {
WRITE_WARNING("Error on parsing a split (edge '" + myCurrentID + "').");
pe->addLane2LaneConnection(l - rightMostP, ne, l - rightMostN, NBEdge::L2L_VALIDATED, true);
}
// move to next
e = ne;
currLanes = newLanes;
} else if (exp.pos == 0) {
const int laneCountDiff = e->getNumLanes() - (int)exp.lanes.size();
if (laneCountDiff < 0) {
Expand Down
2 changes: 2 additions & 0 deletions sumo/src/netimport/NIXMLEdgesHandler.h
Expand Up @@ -240,6 +240,8 @@ class NIXMLEdgesHandler : public SUMOSAXHandler {
std::string idBefore;
/// @brief The id for the edge after the split
std::string idAfter;
/// @brief the default node id
std::string nameID;
};

/// @brief The list of this edge's splits
Expand Down

0 comments on commit ab28938

Please sign in to comment.