|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // A handler for loading polygon type maps 00008 /****************************************************************************/ 00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00010 // Copyright (C) 2001-2011 DLR (http://www.dlr.de/) and contributors 00011 /****************************************************************************/ 00012 // 00013 // This program is free software; you can redistribute it and/or modify 00014 // it under the terms of the GNU General Public License as published by 00015 // the Free Software Foundation; either version 2 of the License, or 00016 // (at your option) any later version. 00017 // 00018 /****************************************************************************/ 00019 00020 00021 // =========================================================================== 00022 // included modules 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/options/OptionsCont.h> 00032 #include <utils/common/MsgHandler.h> 00033 #include <utils/common/StringTokenizer.h> 00034 #include <utils/common/UtilExceptions.h> 00035 #include <utils/xml/SUMOSAXHandler.h> 00036 #include <utils/xml/SUMOXMLDefinitions.h> 00037 #include <utils/common/RGBColor.h> 00038 #include "PCTypeMap.h" 00039 #include "PCTypeDefHandler.h" 00040 00041 #ifdef CHECK_MEMORY_LEAKS 00042 #include <foreign/nvwa/debug_new.h> 00043 #endif // CHECK_MEMORY_LEAKS 00044 00045 00046 // =========================================================================== 00047 // method definitions 00048 // =========================================================================== 00049 PCTypeDefHandler::PCTypeDefHandler(OptionsCont& oc, PCTypeMap& con) throw() 00050 : SUMOSAXHandler("Detector-Defintion"), 00051 myOptions(oc), myContainer(con) {} 00052 00053 00054 PCTypeDefHandler::~PCTypeDefHandler() throw() {} 00055 00056 00057 void 00058 PCTypeDefHandler::myStartElement(int element, 00059 const SUMOSAXAttributes& attrs) throw(ProcessError) { 00060 if (element==SUMO_TAG_POLYTYPE||element==SUMO_TAG_POLYTYPE__DEPRECATED) { 00061 bool ok = true; 00062 // get the id, report an error if not given or empty... 00063 std::string id = attrs.getStringReporting(SUMO_ATTR_ID, 0, ok); 00064 if (!ok) { 00065 return; 00066 } 00067 int layer = attrs.getOptIntReporting(SUMO_ATTR_LAYER, id.c_str(), ok, myOptions.getInt("layer")); 00068 bool discard = attrs.getOptBoolReporting(SUMO_ATTR_DISCARD, id.c_str(), ok, false); 00069 bool allowFill = attrs.getOptBoolReporting(SUMO_ATTR_FILL, id.c_str(), ok, true); 00070 std::string type = attrs.getOptStringReporting(SUMO_ATTR_NAME, id.c_str(), ok, myOptions.getString("type")); 00071 std::string prefix = attrs.getOptStringReporting(SUMO_ATTR_PREFIX, id.c_str(), ok, myOptions.getString("prefix")); 00072 std::string color = attrs.getOptStringReporting(SUMO_ATTR_COLOR, id.c_str(), ok, myOptions.getString("color")); 00073 // !!! what about error handling? 00074 if (!myContainer.add(id, type, color, prefix, layer, discard, allowFill)) { 00075 WRITE_ERROR("Could not add polygon type '" + id + "' (probably the id is already used)."); 00076 } 00077 } 00078 } 00079 00080 00081 /****************************************************************************/ 00082