SUMO - Simulation of Urban MObility
SUMOVTypeParameter.cpp
Go to the documentation of this file.
00001 /****************************************************************************/
00009 // Structure representing possible vehicle parameter
00010 /****************************************************************************/
00011 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00012 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00013 /****************************************************************************/
00014 //
00015 //   This file is part of SUMO.
00016 //   SUMO is free software: you can redistribute it and/or modify
00017 //   it under the terms of the GNU General Public License as published by
00018 //   the Free Software Foundation, either version 3 of the License, or
00019 //   (at your option) any later version.
00020 //
00021 /****************************************************************************/
00022 
00023 
00024 // ===========================================================================
00025 // included modules
00026 // ===========================================================================
00027 #ifdef _MSC_VER
00028 #include <windows_config.h>
00029 #else
00030 #include <config.h>
00031 #endif
00032 
00033 #include <algorithm>
00034 #include <utils/common/SUMOVTypeParameter.h>
00035 #include <utils/common/ToString.h>
00036 #include <utils/common/TplConvert.h>
00037 #include <utils/common/MsgHandler.h>
00038 #include <utils/iodevices/OutputDevice.h>
00039 #include <utils/options/OptionsCont.h>
00040 #include <utils/xml/SUMOXMLDefinitions.h>
00041 
00042 #ifdef CHECK_MEMORY_LEAKS
00043 #include <foreign/nvwa/debug_new.h>
00044 #endif // CHECK_MEMORY_LEAKS
00045 
00046 
00047 // ===========================================================================
00048 // member method definitions
00049 // ===========================================================================
00050 SUMOVTypeParameter::SUMOVTypeParameter()
00051     : id(DEFAULT_VTYPE_ID), length(DEFAULT_VEH_LENGTH),
00052       minGap(DEFAULT_VEH_MINGAP), maxSpeed(DEFAULT_VEH_MAXSPEED),
00053       defaultProbability(DEFAULT_VEH_PROB),
00054       speedFactor(DEFAULT_VEH_SPEEDFACTOR), speedDev(DEFAULT_VEH_SPEEDDEV),
00055       emissionClass(SVE_UNKNOWN), color(RGBColor::DEFAULT_COLOR),
00056       vehicleClass(SVC_UNKNOWN), width(DEFAULT_VEH_WIDTH),
00057       height(DEFAULT_VEH_HEIGHT), shape(DEFAULT_VEH_SHAPE),
00058       cfModel(DEFAULT_VEH_FOLLOW_MODEL), lcModel(DEFAULT_VEH_LANE_CHANGE_MODEL),
00059       setParameter(0), saved(false), onlyReferenced(false) {
00060 }
00061 
00062 
00063 void
00064 SUMOVTypeParameter::write(OutputDevice& dev) const {
00065     if (onlyReferenced) {
00066         return;
00067     }
00068     dev.openTag(SUMO_TAG_VTYPE);
00069     dev.writeAttr(SUMO_ATTR_ID, id);
00070     if (wasSet(VTYPEPARS_LENGTH_SET)) {
00071         dev.writeAttr(SUMO_ATTR_LENGTH, length);
00072     }
00073     if (wasSet(VTYPEPARS_MINGAP_SET)) {
00074         dev.writeAttr(SUMO_ATTR_MINGAP, minGap);
00075     }
00076     if (wasSet(VTYPEPARS_MAXSPEED_SET)) {
00077         dev.writeAttr(SUMO_ATTR_MAXSPEED, maxSpeed);
00078     }
00079     if (wasSet(VTYPEPARS_PROBABILITY_SET)) {
00080         dev.writeAttr(SUMO_ATTR_PROB, defaultProbability);
00081     }
00082     if (wasSet(VTYPEPARS_SPEEDFACTOR_SET)) {
00083         dev.writeAttr(SUMO_ATTR_SPEEDFACTOR, speedFactor);
00084     }
00085     if (wasSet(VTYPEPARS_SPEEDDEVIATION_SET)) {
00086         dev.writeAttr(SUMO_ATTR_SPEEDDEV, speedDev);
00087     }
00088     if (wasSet(VTYPEPARS_VEHICLECLASS_SET)) {
00089         dev.writeAttr(SUMO_ATTR_VCLASS, toString(vehicleClass));
00090     }
00091     if (wasSet(VTYPEPARS_EMISSIONCLASS_SET)) {
00092         dev.writeAttr(SUMO_ATTR_EMISSIONCLASS, getVehicleEmissionTypeName(emissionClass));
00093     }
00094     if (wasSet(VTYPEPARS_SHAPE_SET)) {
00095         dev.writeAttr(SUMO_ATTR_GUISHAPE, getVehicleShapeName(shape));
00096     }
00097     if (wasSet(VTYPEPARS_WIDTH_SET)) {
00098         dev.writeAttr(SUMO_ATTR_WIDTH, width);
00099     }
00100     if (wasSet(VTYPEPARS_HEIGHT_SET)) {
00101         dev.writeAttr(SUMO_ATTR_HEIGHT, height);
00102     }
00103     if (wasSet(VTYPEPARS_COLOR_SET)) {
00104         dev.writeAttr(SUMO_ATTR_COLOR, color);
00105     }
00106     if (wasSet(VTYPEPARS_OSGFILE_SET)) {
00107         dev.writeAttr(SUMO_ATTR_OSGFILE, osgFile);
00108     }
00109 
00110     if (cfParameter.size() != 0) {
00111         dev << ">\n";
00112         dev.openTag(cfModel);
00113         std::vector<SumoXMLAttr> attrs;
00114         for (CFParams::const_iterator i = cfParameter.begin(); i != cfParameter.end(); ++i) {
00115             attrs.push_back(i->first);
00116         }
00117         std::sort(attrs.begin(), attrs.end());
00118         for (std::vector<SumoXMLAttr>::const_iterator i = attrs.begin(); i != attrs.end(); ++i) {
00119             dev.writeAttr(*i, cfParameter.find(*i)->second);
00120         }
00121         dev.closeTag(true);
00122         dev.closeTag();
00123     } else {
00124         dev.closeTag(true);
00125     }
00126 }
00127 
00128 
00129 SUMOReal
00130 SUMOVTypeParameter::get(const SumoXMLAttr attr, const SUMOReal defaultValue) const {
00131     if (cfParameter.count(attr)) {
00132         return cfParameter.find(attr)->second;
00133     } else {
00134         return defaultValue;
00135     }
00136 }
00137 
00138 
00139 /****************************************************************************/
00140 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines