From 24ee73390856cf7c08db0d56e3df17c11b09f933 Mon Sep 17 00:00:00 2001 From: namdre Date: Fri, 4 Jan 2019 14:33:40 +0100 Subject: [PATCH] fix #4999 --- src/netbuild/NBEdge.cpp | 3 +++ src/netbuild/NBNode.cpp | 11 ++++++----- src/netbuild/NBNode.h | 2 +- src/netedit/GNENet.cpp | 31 +++++++++++++++++++------------ 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/netbuild/NBEdge.cpp b/src/netbuild/NBEdge.cpp index 7ec5ef5d303..198772848d5 100644 --- a/src/netbuild/NBEdge.cpp +++ b/src/netbuild/NBEdge.cpp @@ -2989,6 +2989,9 @@ NBEdge::append(NBEdge* e) { // set the node myTo = e->myTo; myToBorder = e->myToBorder; + if (e->knowsParameter("origTo")) { + setParameter("origTo", e->getParameter("origTo")); + } if (e->getSignalOffset() != UNSPECIFIED_SIGNAL_OFFSET) { mySignalOffset = e->getSignalOffset(); } else { diff --git a/src/netbuild/NBNode.cpp b/src/netbuild/NBNode.cpp index 3cac111e2d1..cac1792df6b 100644 --- a/src/netbuild/NBNode.cpp +++ b/src/netbuild/NBNode.cpp @@ -3203,21 +3203,22 @@ NBNode::sortEdges(bool useNodeShape) { } } -std::vector +std::vector > NBNode::getEndPoints() const { // using a set would be nicer but we want to have some slack in position identification - std::vector result; + std::vector >result; for (NBEdge* e : myAllEdges) { Position pos = this == e->getFromNode() ? e->getGeometry().front() : e->getGeometry().back(); + const std::string origID = e->getParameter(this == e->getFromNode() ? "origFrom" : "origTo"); bool unique = true; - for (Position p2 : result) { - if (pos.almostSame(p2)) { + for (const auto& pair : result) { + if (pos.almostSame(pair.first) || (origID != "" && pair.second == origID)) { unique = false; break; } } if (unique) { - result.push_back(pos); + result.push_back(std::make_pair(pos, origID)); } } return result; diff --git a/src/netbuild/NBNode.h b/src/netbuild/NBNode.h index ad78f16e7b9..b134694a17a 100644 --- a/src/netbuild/NBNode.h +++ b/src/netbuild/NBNode.h @@ -748,7 +748,7 @@ class NBNode : public Named, public Parameterised { bool isConstantWidthTransition() const; /// @brief return list of unique endpoint coordinates of all edges at this node - std::vector getEndPoints() const; + std::vector > getEndPoints() const; private: /// @brief sets the priorites in case of a priority junction diff --git a/src/netedit/GNENet.cpp b/src/netedit/GNENet.cpp index 9c92a7d41fa..e4012e0a9c9 100644 --- a/src/netedit/GNENet.cpp +++ b/src/netedit/GNENet.cpp @@ -1650,7 +1650,7 @@ GNENet::replaceJunctionByGeometry(GNEJunction* junction, GNEUndoList* undoList) void GNENet::splitJunction(GNEJunction* junction, GNEUndoList* undoList) { - std::vector endpoints = junction->getNBNode()->getEndPoints(); + std::vector > endpoints = junction->getNBNode()->getEndPoints(); if (endpoints.size() < 2) { return; } @@ -1665,23 +1665,30 @@ GNENet::splitJunction(GNEJunction* junction, GNEUndoList* undoList) { } }; } - //std::cout << "split junction at endpoints: " << toString(endpoints) << "\n"; + //std::cout << "split junction at endpoints:\n"; + junction->setLogicValid(false, undoList); - for (Position pos : endpoints) { + for (const auto& pair : endpoints) { + const Position& pos = pair.first; + const std::string& origID = pair.second; GNEJunction* newJunction = createJunction(pos, undoList); - std::string newID = newJunction->getID(); - for (GNEEdge* e : junction->getGNEIncomingEdges()) { - if (e->getNBEdge()->getGeometry().back().almostSame(pos)) { - //std::cout << " " << e->getID() << " pos=" << pos << "\n"; + std::string newID = origID != "" ? origID : newJunction->getID(); + // make a copy because the original vectors are modified during iteration + const std::vector incoming = junction->getGNEIncomingEdges(); + const std::vector outgoing = junction->getGNEOutgoingEdges(); + //std::cout << " checkEndpoint " << pair.first << " " << pair.second << " newID=" << newID << "\n"; + for (GNEEdge* e : incoming) { + //std::cout << " incoming " << e->getID() << " pos=" << pos << " origTo=" << e->getNBEdge()->getParameter("origTo") << " newID=" << newID << "\n"; + if (e->getNBEdge()->getGeometry().back().almostSame(pos) || e->getNBEdge()->getParameter("origTo") == newID) { + //std::cout << " match\n"; undoList->p_add(new GNEChange_Attribute(e, SUMO_ATTR_TO, newJunction->getID())); - newID = e->getNBEdge()->getParameter("origTo", newID); } } - for (GNEEdge* e : junction->getGNEOutgoingEdges()) { - if (e->getNBEdge()->getGeometry().front().almostSame(pos)) { - //std::cout << " " << e->getID() << " pos=" << pos << "\n"; + for (GNEEdge* e : outgoing) { + //std::cout << " outgoing " << e->getID() << " pos=" << pos << " origFrom=" << e->getNBEdge()->getParameter("origFrom") << " newID=" << newID << "\n"; + if (e->getNBEdge()->getGeometry().front().almostSame(pos) || e->getNBEdge()->getParameter("origFrom") == newID) { + //std::cout << " match\n"; undoList->p_add(new GNEChange_Attribute(e, SUMO_ATTR_FROM, newJunction->getID())); - newID = e->getNBEdge()->getParameter("origFrom", newID); } } if (newID != newJunction->getID()) {