00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifdef _MSC_VER
00025 #include <windows_config.h>
00026 #else
00027 #include <config.h>
00028 #endif
00029
00030 #include <string>
00031 #include <utils/common/UtilExceptions.h>
00032 #include <utils/common/StringTokenizer.h>
00033 #include <utils/common/MsgHandler.h>
00034 #include "RORouteDef.h"
00035 #include "RONet.h"
00036 #include "RORouteDef_OrigDest.h"
00037 #include "RORDLoader_TripDefs.h"
00038 #include "ROVehicle.h"
00039 #include "RORouteDef_Complete.h"
00040 #include "ROAbstractRouteDefLoader.h"
00041 #include <utils/xml/SUMOVehicleParserHelper.h>
00042
00043 #ifdef CHECK_MEMORY_LEAKS
00044 #include <foreign/nvwa/debug_new.h>
00045 #endif // CHECK_MEMORY_LEAKS
00046
00047
00048
00049
00050
00051 RORDLoader_TripDefs::RORDLoader_TripDefs(RONet &net,
00052 SUMOTime begin, SUMOTime end,
00053 bool emptyDestinationsAllowed, bool withTaz,
00054 const std::string &fileName) throw(ProcessError)
00055 : ROTypedXMLRoutesLoader(net, begin, end, fileName),
00056 myEmptyDestinationsAllowed(emptyDestinationsAllowed),
00057 myWithTaz(withTaz),
00058 myDepartureTime(-1), myCurrentVehicleType(0),
00059 myParameter(0) {}
00060
00061
00062 RORDLoader_TripDefs::~RORDLoader_TripDefs() throw() {}
00063
00064
00065 void
00066 RORDLoader_TripDefs::myStartElement(SumoXMLTag element,
00067 const SUMOSAXAttributes &attrs) throw(ProcessError) {
00068
00069 if (element==SUMO_TAG_TRIPDEF) {
00070 bool ok = true;
00071
00072
00073 std::string id = getVehicleID(attrs);
00074 myDepartureTime = attrs.getSUMOTimeReporting(SUMO_ATTR_DEPART, "tripdef", id.c_str(), ok);
00075 if (myWithTaz) {
00076 myBeginEdge = getEdge(attrs, "origin", SUMO_ATTR_FROM_TAZ, id, false);
00077 myEndEdge = getEdge(attrs, "destination", SUMO_ATTR_TO_TAZ, id, myEmptyDestinationsAllowed);
00078 } else {
00079 myBeginEdge = getEdge(attrs, "origin", SUMO_ATTR_FROM, id, false);
00080 myEndEdge = getEdge(attrs, "destination", SUMO_ATTR_TO, id, myEmptyDestinationsAllowed);
00081 }
00082 myParameter = SUMOVehicleParserHelper::parseVehicleAttributes(attrs, true);
00083 myParameter->id = id;
00084
00085 if (!ok) {
00086 return;
00087 }
00088 if (myDepartureTime<0) {
00089 MsgHandler::getErrorInstance()->inform("The departure time must be positive.");
00090 return;
00091 }
00092 }
00093
00094 if (element==SUMO_TAG_VTYPE) {
00095 myCurrentVehicleType = SUMOVehicleParserHelper::beginVTypeParsing(attrs);
00096 } else if (myCurrentVehicleType!=0) {
00097 SUMOVehicleParserHelper::parseVTypeEmbedded(*myCurrentVehicleType, element, attrs);
00098 }
00099 }
00100
00101
00102 std::string
00103 RORDLoader_TripDefs::getVehicleID(const SUMOSAXAttributes &attrs) {
00104
00105 std::string id;
00106 attrs.setIDFromAttributes("tripdef", id, false);
00107
00108 if (id=="") {
00109 id = myIdSupplier.getNext();
00110 }
00111 return id;
00112 }
00113
00114
00115 ROEdge *
00116 RORDLoader_TripDefs::getEdge(const SUMOSAXAttributes &attrs,
00117 const std::string &purpose,
00118 SumoXMLAttr which, const std::string &vid,
00119 bool emptyAllowed) {
00120 bool ok = true;
00121 std::string id = attrs.getStringReporting(which, 0, 0, ok, !emptyAllowed);
00122 if (which == SUMO_ATTR_FROM_TAZ) {
00123 id += "-source";
00124 }
00125 ROEdge *e = myNet.getEdge(id);
00126 if (e==0 && !emptyAllowed) {
00127 MsgHandler::getErrorInstance()->inform("The edge '" + id + "' is not known.\n Vehicle id='" + vid + "'.");
00128 }
00129 return e;
00130 }
00131
00132
00133 SUMOTime
00134 RORDLoader_TripDefs::getPeriod(const SUMOSAXAttributes &attrs,
00135 const std::string &id) {
00136 if (!attrs.hasAttribute(SUMO_ATTR_PERIOD)) {
00137 return -1;
00138 }
00139
00140 bool ok = true;
00141 return attrs.getSUMOTimeReporting(SUMO_ATTR_PERIOD, "tripdef", id.c_str(), ok);
00142 }
00143
00144
00145 int
00146 RORDLoader_TripDefs::getRepetitionNumber(const SUMOSAXAttributes &attrs,
00147 const std::string &id) {
00148 if (!attrs.hasAttribute(SUMO_ATTR_REPNUMBER)) {
00149 return -1;
00150 }
00151
00152 bool ok = true;
00153 return attrs.getIntReporting(SUMO_ATTR_REPNUMBER, "tripdef", id.c_str(), ok);
00154 }
00155
00156
00157 std::string
00158 RORDLoader_TripDefs::getLane(const SUMOSAXAttributes &attrs) {
00159 bool ok = true;
00160 return attrs.getOptStringReporting(SUMO_ATTR_LANE, 0, 0, ok, "");
00161 }
00162
00163
00164 void
00165 RORDLoader_TripDefs::myEndElement(SumoXMLTag element) throw(ProcessError) {
00166 if (element==SUMO_TAG_TRIPDEF &&
00167 !MsgHandler::getErrorInstance()->wasInformed()) {
00168
00169 if (myDepartureTime<myBegin||myDepartureTime>=myEnd) {
00170 return;
00171 }
00172 RGBColor *col = myParameter->wasSet(VEHPARS_COLOR_SET) ? new RGBColor(myParameter->color) : 0;
00173 RORouteDef *route = new RORouteDef_OrigDest(myParameter->id, col, myBeginEdge, myEndEdge);
00174 SUMOVTypeParameter *type = myNet.getVehicleTypeSecure(myParameter->vtypeid);
00175
00176 if (MsgHandler::getErrorInstance()->wasInformed()) {
00177 return;
00178 }
00179 myNet.addRouteDef(route);
00180 myNextRouteRead = true;
00181
00182 ROVehicle *veh = new ROVehicle(*myParameter, route, type);
00183 myNet.addVehicle(myParameter->id, veh);
00184 delete myParameter;
00185 myParameter = 0;
00186 }
00187 if (element==SUMO_TAG_VTYPE) {
00188 SUMOVehicleParserHelper::closeVTypeParsing(*myCurrentVehicleType);
00189 myNet.addVehicleType(myCurrentVehicleType);
00190 myCurrentVehicleType = 0;
00191 }
00192 }
00193
00194
00195 void
00196 RORDLoader_TripDefs::beginNextRoute() throw() {
00197 myNextRouteRead = false;
00198 }
00199
00200
00201
00202