SUMOVehicleParameter.cpp
Go to the documentation of this file.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 "SUMOVehicleParameter.h"
00031 #include <utils/common/ToString.h>
00032 #include <utils/common/TplConvert.h>
00033 #include <utils/common/MsgHandler.h>
00034 #include <utils/iodevices/OutputDevice.h>
00035 #include <utils/options/OptionsCont.h>
00036
00037 #ifdef CHECK_MEMORY_LEAKS
00038 #include <foreign/nvwa/debug_new.h>
00039 #endif // CHECK_MEMORY_LEAKS
00040
00041
00042
00043
00044
00045 SUMOVehicleParameter::SUMOVehicleParameter() throw()
00046 : vtypeid(DEFAULT_VTYPE_ID), depart(-1), departProcedure(DEPART_GIVEN),
00047 departLaneProcedure(DEPART_LANE_DEFAULT), departLane(0),
00048 departPosProcedure(DEPART_POS_DEFAULT), departSpeedProcedure(DEPART_SPEED_DEFAULT),
00049 arrivalLaneProcedure(ARRIVAL_LANE_DEFAULT),
00050 arrivalPosProcedure(ARRIVAL_POS_DEFAULT), arrivalSpeedProcedure(ARRIVAL_SPEED_DEFAULT),
00051 arrivalPos(0), arrivalSpeed(-1),
00052 repetitionNumber(-1), repetitionsDone(-1), repetitionOffset(-1),
00053 line(""), fromTaz(""), toTaz(""), setParameter(0), color(RGBColor::DEFAULT_COLOR) {
00054 }
00055
00056
00057 bool
00058 SUMOVehicleParameter::defaultOptionOverrides(const OptionsCont &oc, const std::string &optionName) const throw() {
00059 return oc.isSet(optionName) && oc.getBool("defaults-override");
00060 }
00061
00062
00063 void
00064 SUMOVehicleParameter::writeAs(const std::string &xmlElem, OutputDevice &dev,
00065 const OptionsCont &oc) const throw(IOError) {
00066 dev.openTag(xmlElem) << " id=\"" << id << "\"";
00067 if (wasSet(VEHPARS_VTYPE_SET)) {
00068 dev << " type=\"" << vtypeid << "\"";
00069 }
00070 dev << " depart=\"" << time2string(depart) << "\"";
00071
00072
00073
00074 if (wasSet(VEHPARS_DEPARTLANE_SET) && !defaultOptionOverrides(oc, "departlane")) {
00075 std::string val;
00076 switch (departLaneProcedure) {
00077 case DEPART_LANE_GIVEN:
00078 val = toString(departLane);
00079 break;
00080 case DEPART_LANE_RANDOM:
00081 val = "random";
00082 break;
00083 case DEPART_LANE_FREE:
00084 val = "free";
00085 break;
00086 case DEPART_LANE_DEPARTLANE:
00087 val = "departlane";
00088 break;
00089 case DEPART_LANE_DEFAULT:
00090 default:
00091 break;
00092 }
00093 dev << " departlane=\"" << val << "\"";
00094 } else if (oc.isSet("departlane")) {
00095 dev << " departlane=\"" << oc.getString("departlane") << "\"";
00096 }
00097
00098 if (wasSet(VEHPARS_DEPARTPOS_SET) && !defaultOptionOverrides(oc, "departpos")) {
00099 std::string val;
00100 switch (departPosProcedure) {
00101 case DEPART_POS_GIVEN:
00102 val = toString(departPos);
00103 break;
00104 case DEPART_POS_RANDOM:
00105 val = "random";
00106 break;
00107 case DEPART_POS_RANDOM_FREE:
00108 val = "random_free";
00109 break;
00110 case DEPART_POS_FREE:
00111 val = "free";
00112 break;
00113 case DEPART_POS_DEFAULT:
00114 default:
00115 break;
00116 }
00117 dev << " departpos=\"" << val << "\"";
00118 } else if (oc.isSet("departpos")) {
00119 dev << " departpos=\"" << oc.getString("departpos") << "\"";
00120 }
00121
00122 if (wasSet(VEHPARS_DEPARTSPEED_SET) && !defaultOptionOverrides(oc, "departspeed")) {
00123 std::string val;
00124 switch (departSpeedProcedure) {
00125 case DEPART_SPEED_GIVEN:
00126 val = toString(departSpeed);
00127 break;
00128 case DEPART_SPEED_RANDOM:
00129 val = "random";
00130 break;
00131 case DEPART_SPEED_MAX:
00132 val = "max";
00133 break;
00134 case DEPART_SPEED_DEFAULT:
00135 default:
00136 break;
00137 }
00138 dev << " departspeed=\"" << val << "\"";
00139 } else if (oc.isSet("departspeed")) {
00140 dev << " departspeed=\"" << oc.getString("departspeed") << "\"";
00141 }
00142
00143
00144 if (wasSet(VEHPARS_ARRIVALLANE_SET) && !defaultOptionOverrides(oc, "arrivallane")) {
00145 std::string val;
00146 switch (arrivalLaneProcedure) {
00147 case ARRIVAL_LANE_GIVEN:
00148 val = toString(arrivalLane);
00149 break;
00150 case ARRIVAL_LANE_CURRENT:
00151 val = "current";
00152 break;
00153 case ARRIVAL_LANE_DEFAULT:
00154 default:
00155 break;
00156 }
00157 dev << " arrivallane=\"" << val << "\"";
00158 } else if (oc.isSet("arrivallane")) {
00159 dev << " arrivallane=\"" << oc.getString("arrivallane") << "\"";
00160 }
00161
00162 if (wasSet(VEHPARS_ARRIVALPOS_SET) && !defaultOptionOverrides(oc, "arrivalpos")) {
00163 std::string val;
00164 switch (arrivalPosProcedure) {
00165 case ARRIVAL_POS_GIVEN:
00166 val = toString(arrivalPos);
00167 break;
00168 case ARRIVAL_POS_RANDOM:
00169 val = "random";
00170 break;
00171 case ARRIVAL_POS_MAX:
00172 val = "max";
00173 break;
00174 case ARRIVAL_POS_DEFAULT:
00175 default:
00176 break;
00177 }
00178 dev << " arrivalpos=\"" << val << "\"";
00179 } else if (oc.isSet("arrivalpos")) {
00180 dev << " arrivalpos=\"" << oc.getString("arrivalpos") << "\"";
00181 }
00182
00183 if (wasSet(VEHPARS_ARRIVALSPEED_SET) && !defaultOptionOverrides(oc, "arrivalspeed")) {
00184 std::string val;
00185 switch (arrivalSpeedProcedure) {
00186 case ARRIVAL_SPEED_GIVEN:
00187 val = toString(arrivalSpeed);
00188 break;
00189 case ARRIVAL_SPEED_CURRENT:
00190 val = "current";
00191 break;
00192 case ARRIVAL_SPEED_DEFAULT:
00193 default:
00194 break;
00195 }
00196 dev << " arrivalspeed=\"" << val << "\"";
00197 } else if (oc.isSet("arrivalspeed")) {
00198 dev << " arrivalspeed=\"" << oc.getString("arrivalspeed") << "\"";
00199 }
00200
00201
00202 if (wasSet(VEHPARS_COLOR_SET)) {
00203 dev << " color=\"" << color << "\"";
00204 }
00205
00206 if (wasSet(VEHPARS_PERIODNUM_SET)) {
00207 dev << " repno=\"" << repetitionNumber << "\"";
00208 }
00209 if (wasSet(VEHPARS_PERIODFREQ_SET)) {
00210 dev << " period=\"" << repetitionOffset << "\"";
00211 }
00212 if (wasSet(VEHPARS_LINE_SET)) {
00213 dev << " line=\"" << line << "\"";
00214 }
00215 if (wasSet(VEHPARS_TAZ_SET)) {
00216 dev << " fromtaz=\"" << fromTaz << "\" totaz=\"" << toTaz << "\"";
00217 }
00218 dev << ">\n";
00219 }
00220
00221
00222 bool
00223 SUMOVehicleParameter::departlaneValidate(const std::string &val) throw() {
00224 if (val=="departlane"||val=="random"||val=="free") {
00225 return true;
00226 }
00227 try {
00228 TplConvert<char>::_2int(val.c_str());
00229 return true;
00230 } catch (NumberFormatException &) {
00231 } catch (EmptyData &) {
00232 }
00233 MsgHandler::getErrorInstance()->inform("Invalid departlane definition;\n must be one of (\"departlane\", \"random\", \"free\", or an int>0)");
00234 return false;
00235 }
00236
00237
00238 bool
00239 SUMOVehicleParameter::departposValidate(const std::string &val) throw() {
00240 if (val=="random"||val=="random_free"||val=="free") {
00241 return true;
00242 }
00243 try {
00244 TplConvert<char>::_2SUMOReal(val.c_str());
00245 return true;
00246 } catch (NumberFormatException &) {
00247 } catch (EmptyData &) {
00248 }
00249 MsgHandler::getErrorInstance()->inform("Invalid departpos definition;\n must be one of (\"random\", \"random_free\", \"free\", or a float)");
00250 return false;
00251 }
00252
00253
00254 bool
00255 SUMOVehicleParameter::departspeedValidate(const std::string &val) throw() {
00256 if (val=="random"||val=="max") {
00257 return true;
00258 }
00259 try {
00260 TplConvert<char>::_2SUMOReal(val.c_str());
00261 return true;
00262 } catch (NumberFormatException &) {
00263 } catch (EmptyData &) {
00264 }
00265 MsgHandler::getErrorInstance()->inform("Invalid departspeed definition;\n must be one of (\"random\", \"max\", or a float>0)");
00266 return false;
00267 }
00268
00269
00270 bool
00271 SUMOVehicleParameter::arrivallaneValidate(const std::string &val) throw() {
00272 if (val=="current") {
00273 return true;
00274 }
00275 try {
00276 TplConvert<char>::_2int(val.c_str());
00277 return true;
00278 } catch (NumberFormatException &) {
00279 } catch (EmptyData &) {
00280 }
00281 MsgHandler::getErrorInstance()->inform("Invalid arrivallane definition;\n must be one of (\"current\", or int>0)");
00282 return false;
00283 }
00284
00285
00286 bool
00287 SUMOVehicleParameter::arrivalposValidate(const std::string &val) throw() {
00288 if (val=="random"||val=="max") {
00289 return true;
00290 }
00291 try {
00292 TplConvert<char>::_2SUMOReal(val.c_str());
00293 return true;
00294 } catch (NumberFormatException &) {
00295 } catch (EmptyData &) {
00296 }
00297 MsgHandler::getErrorInstance()->inform("Invalid arrivalpos definition;\n must be one of (\"random\", \"max\", or a float)");
00298 return false;
00299 }
00300
00301
00302 bool
00303 SUMOVehicleParameter::arrivalspeedValidate(const std::string &val) throw() {
00304 if (val=="current") {
00305 return true;
00306 }
00307 try {
00308 TplConvert<char>::_2SUMOReal(val.c_str());
00309 return true;
00310 } catch (NumberFormatException &) {
00311 } catch (EmptyData &) {
00312 }
00313 MsgHandler::getErrorInstance()->inform("Invalid arrivalspeed definition;\n must be one of (\"current\", or a float>0)");
00314 return false;
00315 }
00316
00317
00318
00319