Skip to content

Commit

Permalink
fix #4999
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed Jan 4, 2019
1 parent 4bd8684 commit 24ee733
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
3 changes: 3 additions & 0 deletions src/netbuild/NBEdge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 6 additions & 5 deletions src/netbuild/NBNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3203,21 +3203,22 @@ NBNode::sortEdges(bool useNodeShape) {
}
}

std::vector<Position>
std::vector<std::pair<Position, std::string> >
NBNode::getEndPoints() const {
// using a set would be nicer but we want to have some slack in position identification
std::vector<Position> result;
std::vector<std::pair<Position, std::string> >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;
Expand Down
2 changes: 1 addition & 1 deletion src/netbuild/NBNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Position> getEndPoints() const;
std::vector<std::pair<Position, std::string> > getEndPoints() const;

private:
/// @brief sets the priorites in case of a priority junction
Expand Down
31 changes: 19 additions & 12 deletions src/netedit/GNENet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1650,7 +1650,7 @@ GNENet::replaceJunctionByGeometry(GNEJunction* junction, GNEUndoList* undoList)

void
GNENet::splitJunction(GNEJunction* junction, GNEUndoList* undoList) {
std::vector<Position> endpoints = junction->getNBNode()->getEndPoints();
std::vector<std::pair<Position, std::string> > endpoints = junction->getNBNode()->getEndPoints();
if (endpoints.size() < 2) {
return;
}
Expand All @@ -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<GNEEdge*> incoming = junction->getGNEIncomingEdges();
const std::vector<GNEEdge*> 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()) {
Expand Down

0 comments on commit 24ee733

Please sign in to comment.