void RORouteHandler::addStop(const SUMOSAXAttributes& attrs) { if (myActivePlan) { myActivePlan->openTag(SUMO_TAG_STOP); (*myActivePlan) << attrs; myActivePlan->closeTag(); myActivePlanSize++; return; } std::string errorSuffix; if (myActiveRouteID != "") { errorSuffix = " in route '" + myActiveRouteID + "'."; } else { errorSuffix = " in vehicle '" + myVehicleParameter->id + "'."; } SUMOVehicleParameter::Stop stop; bool ok = parseStop(stop, attrs, errorSuffix, myErrorOutput); if (!ok) { return; } // try to parse the assigned bus stop if (stop.busstop != "") { const SUMOVehicleParameter::Stop* busstop = myNet.getBusStop(stop.busstop); if (busstop == 0) { myErrorOutput->inform("Unknown bus stop '" + stop.busstop + "'" + errorSuffix); } else { stop.lane = busstop->lane; stop.endPos = busstop->endPos; stop.startPos = busstop->startPos; } } else { // no, the lane and the position should be given stop.lane = attrs.getOpt<std::string>(SUMO_ATTR_LANE, 0, ok, ""); if (!ok || stop.lane == "") { myErrorOutput->inform("A stop must be placed on a bus stop or a lane" + errorSuffix); return; } ROEdge* edge = myNet.getEdge(stop.lane.substr(0, stop.lane.rfind('_'))); if (edge == 0) { myErrorOutput->inform("The lane '" + stop.lane + "' for a stop is not known" + errorSuffix); return; } stop.endPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_ENDPOS, 0, ok, edge->getLength()); stop.startPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_STARTPOS, 0, ok, stop.endPos - 2 * POSITION_EPS); const bool friendlyPos = attrs.getOpt<bool>(SUMO_ATTR_FRIENDLY_POS, 0, ok, false); if (!ok || !checkStopPos(stop.startPos, stop.endPos, edge->getLength(), POSITION_EPS, friendlyPos)) { myErrorOutput->inform("Invalid start or end position for stop" + errorSuffix); return; } } if (myVehicleParameter != 0) { myVehicleParameter->stops.push_back(stop); } else { myActiveRouteStops.push_back(stop); } }
void MSRouteHandler::addStop(const SUMOSAXAttributes& attrs) { bool ok = true; std::string errorSuffix; if (myActiveRouteID != "") { errorSuffix = " in route '" + myActiveRouteID + "'."; } else if (myActivePlan) { errorSuffix = " in person '" + myVehicleParameter->id + "'."; } else { errorSuffix = " in vehicle '" + myVehicleParameter->id + "'."; } SUMOVehicleParameter::Stop stop; // try to parse the assigned bus stop if (attrs.hasAttribute(SUMO_ATTR_BUS_STOP__DEPRECATED)) { stop.busstop = attrs.getStringReporting(SUMO_ATTR_BUS_STOP__DEPRECATED, 0, ok); if (!myHaveWarnedAboutDeprecatedBusStop) { myHaveWarnedAboutDeprecatedBusStop = true; WRITE_WARNING("'bus_stop' is deprecated, please use 'busStop' instead."); } } else { stop.busstop = attrs.getOptStringReporting(SUMO_ATTR_BUS_STOP, 0, ok, ""); } if (stop.busstop != "") { // ok, we have obviously a bus stop MSBusStop* bs = MSNet::getInstance()->getBusStop(stop.busstop); if (bs != 0) { const MSLane& l = bs->getLane(); stop.lane = l.getID(); stop.endPos = bs->getEndLanePosition(); stop.startPos = bs->getBeginLanePosition(); } else { WRITE_ERROR("The bus stop '" + stop.busstop + "' is not known" + errorSuffix); return; } } else { // no, the lane and the position should be given // get the lane stop.lane = attrs.getOptStringReporting(SUMO_ATTR_LANE, 0, ok, ""); if (ok && stop.lane != "") { if (MSLane::dictionary(stop.lane) == 0) { WRITE_ERROR("The lane '" + stop.lane + "' for a stop is not known" + errorSuffix); return; } } else { WRITE_ERROR("A stop must be placed on a bus stop or a lane" + errorSuffix); return; } if (myActivePlan && !myActivePlan->empty() && &myActivePlan->back()->getDestination() != &MSLane::dictionary(stop.lane)->getEdge()) { throw ProcessError("Disconnected plan for person '" + myVehicleParameter->id + "' (" + MSLane::dictionary(stop.lane)->getEdge().getID() + "!=" + myActivePlan->back()->getDestination().getID() + ")."); } stop.endPos = attrs.getOptSUMORealReporting(SUMO_ATTR_ENDPOS, 0, ok, MSLane::dictionary(stop.lane)->getLength()); if (attrs.hasAttribute(SUMO_ATTR_POSITION)) { WRITE_WARNING("Deprecated attribute 'pos' in description of stop" + errorSuffix); stop.endPos = attrs.getOptSUMORealReporting(SUMO_ATTR_POSITION, 0, ok, stop.endPos); } stop.startPos = attrs.getOptSUMORealReporting(SUMO_ATTR_STARTPOS, 0, ok, stop.endPos - 2 * POSITION_EPS); if (attrs.hasAttribute(SUMO_ATTR_FRIENDLY_POS__DEPRECATED) && !myHaveWarnedAboutDeprecatedFriendlyPos) { myHaveWarnedAboutDeprecatedFriendlyPos = true; WRITE_WARNING("'" + toString(SUMO_ATTR_FRIENDLY_POS__DEPRECATED) + "' is deprecated, use '" + toString(SUMO_ATTR_FRIENDLY_POS) + "' instead."); } bool friendlyPos = attrs.hasAttribute(SUMO_ATTR_FRIENDLY_POS__DEPRECATED) ? attrs.getOptBoolReporting(SUMO_ATTR_FRIENDLY_POS__DEPRECATED, 0, ok, false) : attrs.getOptBoolReporting(SUMO_ATTR_FRIENDLY_POS, 0, ok, false); if (!ok || !checkStopPos(stop.startPos, stop.endPos, MSLane::dictionary(stop.lane)->getLength(), POSITION_EPS, friendlyPos)) { WRITE_ERROR("Invalid start or end position for stop" + errorSuffix); return; } } // get the standing duration if (!attrs.hasAttribute(SUMO_ATTR_DURATION) && !attrs.hasAttribute(SUMO_ATTR_UNTIL)) { stop.triggered = attrs.getOptBoolReporting(SUMO_ATTR_TRIGGERED, 0, ok, true); stop.duration = -1; stop.until = -1; } else { stop.duration = attrs.getOptSUMOTimeReporting(SUMO_ATTR_DURATION, 0, ok, -1); stop.until = attrs.getOptSUMOTimeReporting(SUMO_ATTR_UNTIL, 0, ok, -1); if (!ok || (stop.duration < 0 && stop.until < 0)) { WRITE_ERROR("Invalid duration or end time is given for a stop" + errorSuffix); return; } stop.triggered = attrs.getOptBoolReporting(SUMO_ATTR_TRIGGERED, 0, ok, false); } stop.parking = attrs.getOptBoolReporting(SUMO_ATTR_PARKING, 0, ok, stop.triggered); if (!ok) { WRITE_ERROR("Invalid bool for 'triggered' or 'parking' for stop" + errorSuffix); return; } const std::string idx = attrs.getOptStringReporting(SUMO_ATTR_INDEX, 0, ok, "end"); if (idx == "end") { stop.index = STOP_INDEX_END; } else if (idx == "fit") { stop.index = STOP_INDEX_FIT; } else { stop.index = attrs.getIntReporting(SUMO_ATTR_INDEX, 0, ok); if (!ok || stop.index < 0) { WRITE_ERROR("Invalid 'index' for stop" + errorSuffix); return; } } if (myActiveRouteID != "") { myActiveRouteStops.push_back(stop); } else if (myActivePlan) { myActivePlan->push_back(new MSPerson::MSPersonStage_Waiting(MSLane::dictionary(stop.lane)->getEdge(), stop.duration, stop.until)); } else { myVehicleParameter->stops.push_back(stop); } }
void RORouteHandler::addStop(const SUMOSAXAttributes& attrs) { if (myActiveContainerPlan != 0) { myActiveContainerPlan->openTag(SUMO_TAG_STOP); (*myActiveContainerPlan) << attrs; myActiveContainerPlan->closeTag(); myActiveContainerPlanSize++; return; } std::string errorSuffix; if (myVehicleParameter != 0) { errorSuffix = " in vehicle '" + myVehicleParameter->id + "'."; } else { errorSuffix = " in route '" + myActiveRouteID + "'."; } SUMOVehicleParameter::Stop stop; bool ok = parseStop(stop, attrs, errorSuffix, myErrorOutput); if (!ok) { return; } // try to parse the assigned bus stop ROEdge* edge = 0; if (stop.busstop != "") { const SUMOVehicleParameter::Stop* busstop = myNet.getStoppingPlace(stop.busstop, SUMO_TAG_BUS_STOP); if (busstop == 0) { myErrorOutput->inform("Unknown bus stop '" + stop.busstop + "'" + errorSuffix); return; } stop.lane = busstop->lane; stop.endPos = busstop->endPos; stop.startPos = busstop->startPos; edge = myNet.getEdge(stop.lane.substr(0, stop.lane.rfind('_'))); } // try to parse the assigned container stop else if (stop.containerstop != "") { const SUMOVehicleParameter::Stop* containerstop = myNet.getStoppingPlace(stop.containerstop, SUMO_TAG_CONTAINER_STOP); if (containerstop == 0) { myErrorOutput->inform("Unknown container stop '" + stop.containerstop + "'" + errorSuffix); return; } stop.lane = containerstop->lane; stop.endPos = containerstop->endPos; stop.startPos = containerstop->startPos; edge = myNet.getEdge(stop.lane.substr(0, stop.lane.rfind('_'))); } // try to parse the assigned parking area else if (stop.parkingarea != "") { const SUMOVehicleParameter::Stop* parkingarea = myNet.getStoppingPlace(stop.parkingarea, SUMO_TAG_PARKING_AREA); if (parkingarea == 0) { myErrorOutput->inform("Unknown parking area '" + stop.parkingarea + "'" + errorSuffix); return; } stop.lane = parkingarea->lane; stop.endPos = parkingarea->endPos; stop.startPos = parkingarea->startPos; edge = myNet.getEdge(stop.lane.substr(0, stop.lane.rfind('_'))); } else { // no, the lane and the position should be given stop.lane = attrs.getOpt<std::string>(SUMO_ATTR_LANE, 0, ok, ""); if (!ok || stop.lane == "") { myErrorOutput->inform("A stop must be placed on a bus stop, a container stop, a parking area or a lane" + errorSuffix); return; } edge = myNet.getEdge(stop.lane.substr(0, stop.lane.rfind('_'))); if (edge == 0) { myErrorOutput->inform("The lane '" + stop.lane + "' for a stop is not known" + errorSuffix); return; } stop.endPos = attrs.getOpt<double>(SUMO_ATTR_ENDPOS, 0, ok, edge->getLength()); stop.startPos = attrs.getOpt<double>(SUMO_ATTR_STARTPOS, 0, ok, stop.endPos - 2 * POSITION_EPS); const bool friendlyPos = attrs.getOpt<bool>(SUMO_ATTR_FRIENDLY_POS, 0, ok, false); const double endPosOffset = edge->isInternal() ? edge->getNormalBefore()->getLength() : 0; if (!ok || !checkStopPos(stop.startPos, stop.endPos, edge->getLength() + endPosOffset, POSITION_EPS, friendlyPos)) { myErrorOutput->inform("Invalid start or end position for stop" + errorSuffix); return; } } if (myActivePerson != 0) { myActivePerson->addStop(stop, edge); } else if (myVehicleParameter != 0) { myVehicleParameter->stops.push_back(stop); } else { myActiveRouteStops.push_back(stop); } if (myInsertStopEdgesAt >= 0) { myActiveRoute.insert(myActiveRoute.begin() + myInsertStopEdgesAt, edge); myInsertStopEdgesAt++; } }
void RORouteHandler::addStop(const SUMOSAXAttributes& attrs) { if (myActivePlan) { myActivePlan->openTag(SUMO_TAG_STOP); (*myActivePlan) << attrs; myActivePlan->closeTag(); return; } bool ok = true; std::string errorSuffix; if (myActiveRouteID != "") { errorSuffix = " in route '" + myActiveRouteID + "'."; } else { errorSuffix = " in vehicle '" + myVehicleParameter->id + "'."; } SUMOVehicleParameter::Stop stop; SUMOVehicleParserHelper::parseStop(stop, attrs); // try to parse the assigned bus stop stop.busstop = attrs.getOpt<std::string>(SUMO_ATTR_BUS_STOP, 0, ok, ""); if (stop.busstop == "") { // no, the lane and the position should be given stop.lane = attrs.getOpt<std::string>(SUMO_ATTR_LANE, 0, ok, ""); if (!ok || stop.lane == "") { myErrorOutput->inform("A stop must be placed on a bus stop or a lane" + errorSuffix); return; } ROEdge* edge = myNet.getEdge(stop.lane.substr(0, stop.lane.rfind('_'))); if (edge == 0) { myErrorOutput->inform("The lane '" + stop.lane + "' for a stop is not known" + errorSuffix); return; } stop.endPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_ENDPOS, 0, ok, edge->getLength()); stop.startPos = attrs.getOpt<SUMOReal>(SUMO_ATTR_STARTPOS, 0, ok, stop.endPos - 2 * POSITION_EPS); const bool friendlyPos = attrs.getOpt<bool>(SUMO_ATTR_FRIENDLY_POS, 0, ok, false); if (!ok || !checkStopPos(stop.startPos, stop.endPos, edge->getLength(), POSITION_EPS, friendlyPos)) { myErrorOutput->inform("Invalid start or end position for stop" + errorSuffix); return; } } // get the standing duration if (!attrs.hasAttribute(SUMO_ATTR_DURATION) && !attrs.hasAttribute(SUMO_ATTR_UNTIL)) { stop.triggered = attrs.getOpt<bool>(SUMO_ATTR_TRIGGERED, 0, ok, true); stop.duration = -1; stop.until = -1; } else { stop.duration = attrs.getOptSUMOTimeReporting(SUMO_ATTR_DURATION, 0, ok, -1); stop.until = attrs.getOptSUMOTimeReporting(SUMO_ATTR_UNTIL, 0, ok, -1); if (!ok || (stop.duration < 0 && stop.until < 0)) { myErrorOutput->inform("Invalid duration or end time is given for a stop" + errorSuffix); return; } stop.triggered = attrs.getOpt<bool>(SUMO_ATTR_TRIGGERED, 0, ok, false); } stop.parking = attrs.getOpt<bool>(SUMO_ATTR_PARKING, 0, ok, stop.triggered); if (!ok) { myErrorOutput->inform("Invalid bool for 'triggered' or 'parking' for stop" + errorSuffix); return; } // expected persons std::string expectedStr = attrs.getOpt<std::string>(SUMO_ATTR_EXPECTED, 0, ok, ""); std::set<std::string> personIDs; SUMOSAXAttributes::parseStringSet(expectedStr, personIDs); stop.awaitedPersons = personIDs; const std::string idx = attrs.getOpt<std::string>(SUMO_ATTR_INDEX, 0, ok, "end"); if (idx == "end") { stop.index = STOP_INDEX_END; } else if (idx == "fit") { stop.index = STOP_INDEX_FIT; } else { stop.index = attrs.get<int>(SUMO_ATTR_INDEX, 0, ok); if (!ok || stop.index < 0) { myErrorOutput->inform("Invalid 'index' for stop" + errorSuffix); return; } } if (myVehicleParameter != 0) { myVehicleParameter->stops.push_back(stop); } else { myActiveRouteStops.push_back(stop); } }