GUISelectionLoader.cpp

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // Helper for loading selections
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright 2001-2010 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 <guisim/GUIEdge.h>
00031 #include <microsim/MSLane.h>
00032 #include <utils/gui/div/GUIGlobalSelection.h>
00033 #include "GUISelectionLoader.h"
00034 #include <fstream>
00035 
00036 #ifdef CHECK_MEMORY_LEAKS
00037 #include <foreign/nvwa/debug_new.h>
00038 #endif // CHECK_MEMORY_LEAKS
00039 
00040 
00041 // ===========================================================================
00042 // member method definitions
00043 // ===========================================================================
00044 bool
00045 GUISelectionLoader::loadSelection(const std::string &file, std::string &msg) throw() {
00046     // ok, load all
00047     std::map<std::string, int> typeMap;
00048     typeMap["edge"] = GLO_EDGE;
00049     typeMap["induct loop"] = GLO_DETECTOR;
00050     typeMap["junction"] = GLO_JUNCTION;
00051     typeMap["speedtrigger"] = GLO_TRIGGER;
00052     typeMap["lane"] = GLO_LANE;
00053     typeMap["tl-logic"] = GLO_TLLOGIC;
00054     typeMap["vehicle"] = GLO_VEHICLE;
00055     std::ifstream strm(file.c_str());
00056     if (!strm.good()) {
00057         msg = "Could not open '" + file + "'.";
00058         return false;
00059     }
00060     while (strm.good()) {
00061         std::string line;
00062         strm >> line;
00063         if (line.length()==0) {
00064             continue;
00065         }
00066         size_t idx = line.find(':');
00067         if (idx!=std::string::npos) {
00068             std::string type = line.substr(0, idx);
00069             std::string name = line.substr(idx+1);
00070             if (typeMap.find(type)==typeMap.end()) {
00071                 msg = "Unknown type '" + type + "' occured.";
00072                 continue;
00073             }
00074             int itype = typeMap[type];
00075             int oid = -1;
00076             switch (itype) {
00077             case GLO_VEHICLE: {}
00078             break;
00079             case GLO_TLLOGIC: {}
00080             break;
00081             case GLO_DETECTOR: {}
00082             break;
00083             case GLO_EMITTER: {}
00084             break;
00085             case GLO_LANE: {
00086                 MSLane *l = MSLane::dictionary(name);
00087                 if (l!=0) {
00088                     oid = static_cast<GUIEdge&>(l->getEdge()).getLaneGeometry(l).getGlID();
00089                 }
00090             }
00091             break;
00092             case GLO_EDGE: {
00093                 MSEdge *e = MSEdge::dictionary(name);
00094                 if (e!=0) {
00095                     oid = static_cast<const GUIEdge * const>(e)->getGlID();
00096                 }
00097             }
00098             break;
00099             case GLO_JUNCTION: {}
00100             break;
00101             case GLO_TRIGGER: {}
00102             break;
00103             }
00104             if (oid>=0) {
00105                 gSelected.select(itype, oid, false);
00106             } else {
00107                 msg = "Item '" + line + "' not found";
00108                 continue;
00109             }
00110         } else {
00111             msg = "Could not parse entry while loading selection.";
00112             continue;
00113         }
00114     }
00115     return true;
00116 }
00117 
00118 
00119 /****************************************************************************/
00120 

Generated on Wed May 5 00:06:30 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6