void NLHandler::addDistrict(const SUMOSAXAttributes& attrs) { bool ok = true; myCurrentIsBroken = false; // get the id, report an error if not given or empty... myCurrentDistrictID = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok); if (!ok) { myCurrentIsBroken = true; return; } try { MSEdge* sink = myEdgeControlBuilder.buildEdge(myCurrentDistrictID + "-sink", MSEdge::EDGEFUNCTION_DISTRICT); if (!MSEdge::dictionary(myCurrentDistrictID + "-sink", sink)) { delete sink; throw InvalidArgument("Another edge with the id '" + myCurrentDistrictID + "-sink' exists."); } sink->initialize(new std::vector<MSLane*>()); MSEdge* source = myEdgeControlBuilder.buildEdge(myCurrentDistrictID + "-source", MSEdge::EDGEFUNCTION_DISTRICT); if (!MSEdge::dictionary(myCurrentDistrictID + "-source", source)) { delete source; throw InvalidArgument("Another edge with the id '" + myCurrentDistrictID + "-source' exists."); } source->initialize(new std::vector<MSLane*>()); if (attrs.hasAttribute(SUMO_ATTR_EDGES)) { std::vector<std::string> desc = attrs.getStringVector(SUMO_ATTR_EDGES); for (std::vector<std::string>::const_iterator i = desc.begin(); i != desc.end(); ++i) { MSEdge* edge = MSEdge::dictionary(*i); // check whether the edge exists if (edge == 0) { throw InvalidArgument("The edge '" + *i + "' within district '" + myCurrentDistrictID + "' is not known."); } source->addFollower(edge); edge->addFollower(sink); } } if (attrs.hasAttribute(SUMO_ATTR_SHAPE)) { PositionVector shape = attrs.get<PositionVector>(SUMO_ATTR_SHAPE, myCurrentDistrictID.c_str(), ok); if (shape.size() != 0) { if (!myNet.getShapeContainer().addPolygon(myCurrentDistrictID, "taz", RGBColor::parseColor("1.0,.33,.33"), 0, 0, "", shape, false)) { WRITE_WARNING("Skipping visualization of taz '" + myCurrentDistrictID + "', polygon already exists."); } } } } catch (InvalidArgument& e) { WRITE_ERROR(e.what()); myCurrentIsBroken = true; } }
void NLHandler::addDistrict(const SUMOSAXAttributes& attrs) { bool ok = true; myCurrentIsBroken = false; // get the id, report an error if not given or empty... myCurrentDistrictID = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok); if (!ok) { myCurrentIsBroken = true; return; } try { MSEdge* sink = myEdgeControlBuilder.buildEdge(myCurrentDistrictID + "-sink", MSEdge::EDGEFUNCTION_DISTRICT); if (!MSEdge::dictionary(myCurrentDistrictID + "-sink", sink)) { delete sink; throw InvalidArgument("Another edge with the id '" + myCurrentDistrictID + "-sink' exists."); } sink->initialize(new std::vector<MSLane*>()); MSEdge* source = myEdgeControlBuilder.buildEdge(myCurrentDistrictID + "-source", MSEdge::EDGEFUNCTION_DISTRICT); if (!MSEdge::dictionary(myCurrentDistrictID + "-source", source)) { delete source; throw InvalidArgument("Another edge with the id '" + myCurrentDistrictID + "-source' exists."); } source->initialize(new std::vector<MSLane*>()); if (attrs.hasAttribute(SUMO_ATTR_EDGES)) { std::vector<std::string> desc = attrs.getStringVector(SUMO_ATTR_EDGES); for (std::vector<std::string>::const_iterator i = desc.begin(); i != desc.end(); ++i) { MSEdge* edge = MSEdge::dictionary(*i); // check whether the edge exists if (edge == 0) { throw InvalidArgument("The edge '" + *i + "' within district '" + myCurrentDistrictID + "' is not known."); } source->addFollower(edge); edge->addFollower(sink); } } } catch (InvalidArgument& e) { WRITE_ERROR(e.what()); myCurrentIsBroken = true; } }