SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00009 // Storage for "selected" objects 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 #ifndef GUISelectedStorage_h 00023 #define GUISelectedStorage_h 00024 00025 00026 // =========================================================================== 00027 // included modules 00028 // =========================================================================== 00029 #ifdef _MSC_VER 00030 #include <windows_config.h> 00031 #else 00032 #include <config.h> 00033 #endif 00034 00035 #include <set> 00036 #include <string> 00037 #include <map> 00038 #include <fstream> 00039 #include <fx.h> 00040 #include <utils/common/UtilExceptions.h> 00041 #include <utils/gui/globjects/GUIGlObject.h> 00042 00043 00044 // =========================================================================== 00045 // class declarations 00046 // =========================================================================== 00047 class OutputDevice; 00048 00049 00050 // =========================================================================== 00051 // class definitions 00052 // =========================================================================== 00077 class GUISelectedStorage { 00078 00079 public: 00080 class UpdateTarget { 00081 public: 00082 virtual ~UpdateTarget() {}; 00083 virtual void selectionUpdated() = 0; 00084 }; 00085 00086 public: 00088 GUISelectedStorage(); 00089 00090 00092 ~GUISelectedStorage(); 00093 00094 00111 bool isSelected(GUIGlObjectType type, GUIGlID id); 00112 00113 00129 void select(GUIGlID id, bool update = true); 00130 00131 00147 void deselect(GUIGlID id); 00148 00149 00164 void toggleSelection(GUIGlID id); 00165 00166 00172 const std::set<GUIGlID> &getSelected() const; 00173 00174 00181 const std::set<GUIGlID> &getSelected(GUIGlObjectType type); 00182 00183 00190 void clear(); 00191 00192 00199 std::string load(const std::string& filename, GUIGlObjectType type = GLO_MAX); 00200 00201 00210 std::set<GUIGlID> loadIDs(const std::string& filename, std::string& msgOut, GUIGlObjectType type = GLO_MAX); 00211 00212 00218 void save(GUIGlObjectType type, const std::string& filename); 00219 00224 void save(const std::string& filename) const; 00225 00226 00230 void add2Update(UpdateTarget* updateTarget); 00231 00232 00235 void remove2Update(); 00236 00237 00242 class SingleTypeSelections { 00243 public: 00245 SingleTypeSelections(); 00246 00248 ~SingleTypeSelections(); 00249 00250 00255 bool isSelected(GUIGlID id); 00256 00257 00261 void select(GUIGlID id); 00262 00263 00267 void deselect(GUIGlID id); 00268 00269 00271 void clear(); 00272 00273 00277 void save(const std::string& filename); 00278 00279 00283 const std::set<GUIGlID> &getSelected() const; 00284 00285 private: 00287 std::set<GUIGlID> mySelected; 00288 00289 }; 00290 friend class SingleTypeSelections; 00291 00292 00293 private: 00294 std::map<GUIGlObjectType, SingleTypeSelections> mySelections; 00295 00297 std::set<GUIGlID> myAllSelected; 00298 00300 UpdateTarget* myUpdateTarget; 00301 00302 /* @brief load items into the given set, optionally restricting to type 00303 */ 00304 std::string load(GUIGlObjectType type, const std::string& filename, bool restrictType, std::set<GUIGlID>& into); 00305 00306 00308 static void save(const std::string& filename, const std::set<GUIGlID>& ids); 00309 00310 }; 00311 00312 00313 #endif 00314 00315 /****************************************************************************/ 00316