void NIXMLConnectionsHandler::addCrossing(const SUMOSAXAttributes& attrs) { bool ok = true; NBNode* node = 0; EdgeVector edges; const std::string nodeID = attrs.get<std::string>(SUMO_ATTR_NODE, 0, ok); const double width = attrs.getOpt<double>(SUMO_ATTR_WIDTH, nodeID.c_str(), ok, NBEdge::UNSPECIFIED_WIDTH, true); const bool discard = attrs.getOpt<bool>(SUMO_ATTR_DISCARD, nodeID.c_str(), ok, false, true); int tlIndex = attrs.getOpt<int>(SUMO_ATTR_TLLINKINDEX, 0, ok, -1); int tlIndex2 = attrs.getOpt<int>(SUMO_ATTR_TLLINKINDEX2, 0, ok, -1); std::vector<std::string> edgeIDs; if (!attrs.hasAttribute(SUMO_ATTR_EDGES)) { if (discard) { node = myNodeCont.retrieve(nodeID); if (node == 0) { WRITE_ERROR("Node '" + nodeID + "' in crossing is not known."); return; } node->discardAllCrossings(true); return; } else { WRITE_ERROR("No edges specified for crossing at node '" + nodeID + "'."); return; } } SUMOSAXAttributes::parseStringVector(attrs.get<std::string>(SUMO_ATTR_EDGES, 0, ok), edgeIDs); if (!ok) { return; } for (std::vector<std::string>::const_iterator it = edgeIDs.begin(); it != edgeIDs.end(); ++it) { NBEdge* edge = myEdgeCont.retrieve(*it); if (edge == 0) { WRITE_ERROR("Edge '" + (*it) + "' for crossing at node '" + nodeID + "' is not known."); return; } if (node == 0) { if (edge->getToNode()->getID() == nodeID) { node = edge->getToNode(); } else if (edge->getFromNode()->getID() == nodeID) { node = edge->getFromNode(); } else { WRITE_ERROR("Edge '" + (*it) + "' does not touch node '" + nodeID + "'."); return; } } else { if (edge->getToNode() != node && edge->getFromNode() != node) { WRITE_ERROR("Edge '" + (*it) + "' does not touch node '" + nodeID + "'."); return; } } edges.push_back(edge); } bool priority = attrs.getOpt<bool>(SUMO_ATTR_PRIORITY, nodeID.c_str(), ok, node->isTLControlled(), true); if (node->isTLControlled() && !priority) { // traffic_light nodes should always have priority crossings WRITE_WARNING("Crossing at controlled node '" + nodeID + "' must be prioritized"); priority = true; } PositionVector customShape = attrs.getOpt<PositionVector>(SUMO_ATTR_SHAPE, 0, ok, PositionVector::EMPTY); if (!NBNetBuilder::transformCoordinates(customShape)) { WRITE_ERROR("Unable to project shape for crossing at node '" + node->getID() + "'."); } if (discard) { node->removeCrossing(edges); } else { if (node->checkCrossingDuplicated(edges)) { WRITE_ERROR("Crossing with edges '" + toString(edges) + "' already exists at node '" + node->getID() + "'."); return; } node->addCrossing(edges, width, priority, tlIndex, tlIndex2, customShape); } }