bool NBEdgeCont::splitAt(NBDistrictCont& dc, NBEdge* edge, SUMOReal pos, NBNode* node, const std::string& firstEdgeName, const std::string& secondEdgeName, unsigned int noLanesFirstEdge, unsigned int noLanesSecondEdge) { // build the new edges' geometries std::pair<PositionVector, PositionVector> geoms = edge->getGeometry().splitAt(pos); if (geoms.first[-1] != node->getPosition()) { geoms.first.pop_back(); geoms.first.push_back(node->getPosition()); } if (geoms.second[0] != node->getPosition()) { geoms.second.pop_front(); geoms.second.push_front(node->getPosition()); } // build and insert the edges NBEdge* one = new NBEdge(firstEdgeName, edge->myFrom, node, edge->myType, edge->mySpeed, noLanesFirstEdge, edge->getPriority(), edge->myLaneWidth, 0, geoms.first, edge->getStreetName(), edge->myLaneSpreadFunction, true); for (unsigned int i = 0; i < noLanesFirstEdge && i < edge->getNumLanes(); i++) { one->setSpeed(i, edge->getLaneSpeed(i)); } NBEdge* two = new NBEdge(secondEdgeName, node, edge->myTo, edge->myType, edge->mySpeed, noLanesSecondEdge, edge->getPriority(), edge->myLaneWidth, edge->myOffset, geoms.second, edge->getStreetName(), edge->myLaneSpreadFunction, true); for (unsigned int i = 0; i < noLanesSecondEdge && i < edge->getNumLanes(); i++) { two->setSpeed(i, edge->getLaneSpeed(i)); } two->copyConnectionsFrom(edge); // replace information about this edge within the nodes edge->myFrom->replaceOutgoing(edge, one, 0); edge->myTo->replaceIncoming(edge, two, 0); // the edge is now occuring twice in both nodes... // clean up edge->myFrom->removeDoubleEdges(); edge->myTo->removeDoubleEdges(); // add connections from the first to the second edge // check special case: // one in, one out, the outgoing has one lane more if (noLanesFirstEdge == noLanesSecondEdge - 1) { for (unsigned int i = 0; i < one->getNumLanes(); i++) { if (!one->addLane2LaneConnection(i, two, i + 1, NBEdge::L2L_COMPUTED)) { // !!! Bresenham, here!!! throw ProcessError("Could not set connection!"); } } one->addLane2LaneConnection(0, two, 0, NBEdge::L2L_COMPUTED); } else { for (unsigned int i = 0; i < one->getNumLanes() && i < two->getNumLanes(); i++) { if (!one->addLane2LaneConnection(i, two, i, NBEdge::L2L_COMPUTED)) {// !!! Bresenham, here!!! throw ProcessError("Could not set connection!"); } } } if (myRemoveEdgesAfterJoining) { if (find(myEdges2Keep.begin(), myEdges2Keep.end(), edge->getID()) != myEdges2Keep.end()) { myEdges2Keep.insert(one->getID()); myEdges2Keep.insert(two->getID()); } if (find(myEdges2Remove.begin(), myEdges2Remove.end(), edge->getID()) != myEdges2Remove.end()) { myEdges2Remove.insert(one->getID()); myEdges2Remove.insert(two->getID()); } } // erase the splitted edge erase(dc, edge); insert(one, true); insert(two, true); myEdgesSplit++; return true; }