GUISelectionLoader Class Reference

#include <GUISelectionLoader.h>


Detailed Description

Helper for loading selections.

Definition at line 41 of file GUISelectionLoader.h.


Static Public Member Functions

static bool loadSelection (const std::string &file, std::string &msg) throw ()
 Loads a selection from a given file.

Protected Member Functions

 GUISelectionLoader () throw ()
 invalidated constructor
 ~GUISelectionLoader () throw ()
 invalidated destructor

Constructor & Destructor Documentation

GUISelectionLoader::GUISelectionLoader (  )  throw () [inline, protected]

invalidated constructor

Definition at line 53 of file GUISelectionLoader.h.

00053 {}

GUISelectionLoader::~GUISelectionLoader (  )  throw () [inline, protected]

invalidated destructor

Definition at line 56 of file GUISelectionLoader.h.

00056 {}


Member Function Documentation

bool GUISelectionLoader::loadSelection ( const std::string &  file,
std::string &  msg 
) throw () [static]

Loads a selection from a given file.

Parameters:
[in] file The file to load the selection from
[out] msg The error message
Returns:
Whether the selection could be loaded (fills the error message if not)

Definition at line 45 of file GUISelectionLoader.cpp.

References MSEdge::dictionary(), MSLane::dictionary(), MSLane::getEdge(), GLO_DETECTOR, GLO_EDGE, GLO_EMITTER, GLO_JUNCTION, GLO_LANE, GLO_TLLOGIC, GLO_TRIGGER, GLO_VEHICLE, gSelected, and GUISelectedStorage::select().

Referenced by GUIApplicationWindow::loadSelection().

00045                                                                                {
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 }


The documentation for this class was generated from the following files:

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