|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // Storage for available visualization settings 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 "GUICompleteSchemeStorage.h" 00031 #include <utils/common/ToString.h> 00032 #include <utils/common/StringUtils.h> 00033 #include <utils/common/RGBColor.h> 00034 #include <utils/foxtools/MFXUtils.h> 00035 #include <utils/gui/settings/GUISettingsHandler.h> 00036 #include <utils/iodevices/OutputDevice_String.h> 00037 00038 #ifdef CHECK_MEMORY_LEAKS 00039 #include <foreign/nvwa/debug_new.h> 00040 #endif // CHECK_MEMORY_LEAKS 00041 00042 00043 // =========================================================================== 00044 // static variable definitions 00045 // =========================================================================== 00046 GUICompleteSchemeStorage gSchemeStorage; 00047 00048 00049 // =========================================================================== 00050 // method definitions 00051 // =========================================================================== 00052 GUICompleteSchemeStorage::GUICompleteSchemeStorage() throw() { } 00053 00054 00055 GUICompleteSchemeStorage::~GUICompleteSchemeStorage() throw() { } 00056 00057 00058 00059 void 00060 GUICompleteSchemeStorage::add(const GUIVisualizationSettings& scheme) throw() { 00061 std::string name = scheme.name; 00062 if (std::find(mySortedSchemeNames.begin(), mySortedSchemeNames.end(), name)==mySortedSchemeNames.end()) { 00063 mySortedSchemeNames.push_back(name); 00064 } 00065 mySettings[name] = scheme; 00066 } 00067 00068 00069 GUIVisualizationSettings& 00070 GUICompleteSchemeStorage::get(const std::string& name) throw() { 00071 return mySettings.find(name)->second; 00072 } 00073 00074 00075 GUIVisualizationSettings& 00076 GUICompleteSchemeStorage::getDefault() throw() { 00077 return mySettings.find(myDefaultSettingName)->second; 00078 } 00079 00080 00081 bool 00082 GUICompleteSchemeStorage::contains(const std::string& name) const throw() { 00083 return mySettings.find(name)!=mySettings.end(); 00084 } 00085 00086 00087 void 00088 GUICompleteSchemeStorage::remove(const std::string& name) throw() { 00089 if (!contains(name)) { 00090 return; 00091 } 00092 mySortedSchemeNames.erase(find(mySortedSchemeNames.begin(), mySortedSchemeNames.end(), name)); 00093 mySettings.erase(mySettings.find(name)); 00094 } 00095 00096 00097 void 00098 GUICompleteSchemeStorage::setDefault(const std::string& name) throw() { 00099 if (!contains(name)) { 00100 return; 00101 } 00102 myDefaultSettingName = name; 00103 } 00104 00105 00106 const std::vector<std::string> & 00107 GUICompleteSchemeStorage::getNames() const throw() { 00108 return mySortedSchemeNames; 00109 } 00110 00111 00112 unsigned int 00113 GUICompleteSchemeStorage::getNumInitialSettings() const throw() { 00114 return myNumInitialSettings; 00115 } 00116 00117 00118 RGBColor 00119 convert(const FXColor c) throw() { 00120 return RGBColor( 00121 (SUMOReal) FXREDVAL(c) / (SUMOReal) 255., 00122 (SUMOReal) FXGREENVAL(c) / (SUMOReal) 255., 00123 (SUMOReal) FXBLUEVAL(c) / (SUMOReal) 255.); 00124 } 00125 00126 00127 void 00128 GUICompleteSchemeStorage::init(FXApp* app) throw() { 00129 { 00130 GUIVisualizationSettings vs; 00131 vs.name = "standard"; 00132 gSchemeStorage.add(vs); 00133 } 00134 { 00135 GUIVisualizationSettings vs; 00136 vs.name = "faster standard"; 00137 vs.showLinkDecals = false; 00138 vs.showRails = false; 00139 gSchemeStorage.add(vs); 00140 } 00141 { 00142 GUIVisualizationSettings vs; 00143 vs.name = "real world"; 00144 vs.vehicleQuality = 2; 00145 vs.backgroundColor = RGBColor((SUMOReal) .2, (SUMOReal) .5, (SUMOReal) .2); 00146 vs.laneShowBorders = true; 00147 vs.hideConnectors = true; 00148 vs.minVehicleSize = 0; 00149 gSchemeStorage.add(vs); 00150 } 00151 myNumInitialSettings = (unsigned int) mySortedSchemeNames.size(); 00152 // add saved settings 00153 int noSaved = app->reg().readIntEntry("VisualizationSettings", "settingNo", 0); 00154 for (int i=0; i<noSaved; ++i) { 00155 std::string name = "visset#" + toString(i); 00156 std::string setting = app->reg().readStringEntry("VisualizationSettings",name.c_str(), ""); 00157 if (setting!="") { 00158 GUIVisualizationSettings vs; 00159 00160 vs.name = setting; 00161 app->reg().readStringEntry("VisualizationSettings",name.c_str(), ""); 00162 00163 // add saved xml setting 00164 int xmlSize = app->reg().readIntEntry(name.c_str(), "xmlSize", 0); 00165 std::string content = ""; 00166 int index = 0; 00167 while (xmlSize > 0) { 00168 std::string part = app->reg().readStringEntry(name.c_str(), ("xml"+toString(index)).c_str(), ""); 00169 if (part == "") { 00170 break; 00171 } 00172 content += part; 00173 xmlSize -= (int) part.size(); 00174 index++; 00175 } 00176 if (content != "" && xmlSize == 0) { 00177 try { 00178 GUISettingsHandler handler(content, false); 00179 handler.addSettings(); 00180 } catch (ProcessError) { } 00181 } 00182 } 00183 } 00184 myDefaultSettingName = mySortedSchemeNames[0]; 00185 myX = myY = myZoom = 0; 00186 } 00187 00188 00189 void 00190 GUICompleteSchemeStorage::writeSettings(FXApp* app) throw() { 00191 const std::vector<std::string> &names = getNames(); 00192 app->reg().writeIntEntry("VisualizationSettings", "settingNo", (FXint) names.size()-myNumInitialSettings); 00193 size_t gidx = 0; 00194 for (std::vector<std::string>::const_iterator i=names.begin()+myNumInitialSettings; i!=names.end(); ++i, ++gidx) { 00195 const GUIVisualizationSettings& item = mySettings.find(*i)->second; 00196 std::string sname = "visset#" + toString(gidx); 00197 00198 app->reg().writeStringEntry("VisualizationSettings", sname.c_str(), item.name.c_str()); 00199 OutputDevice_String dev; 00200 item.save(dev); 00201 std::string content = dev.getString(); 00202 app->reg().writeIntEntry(sname.c_str(), "xmlSize", (FXint)(content.size())); 00203 const unsigned maxSize = 1500; // this is a fox limitation for registry entries 00204 for (unsigned int i = 0; i < content.size(); i+=maxSize) { 00205 const std::string b = content.substr(i, maxSize); 00206 app->reg().writeStringEntry(sname.c_str(), ("xml" + toString(i/maxSize)).c_str(), b.c_str()); 00207 } 00208 } 00209 } 00210 00211 00212 void 00213 GUICompleteSchemeStorage::saveViewport(const SUMOReal x, const SUMOReal y, const SUMOReal zoom) throw() { 00214 myX = x; 00215 myY = y; 00216 myZoom = zoom; 00217 } 00218 00219 00220 void 00221 GUICompleteSchemeStorage::setViewport(GUISUMOAbstractView* view) throw() { 00222 if (myZoom > 0) { 00223 view->setViewport(myZoom, myX, myY); 00224 } else { 00225 view->recenterView(); 00226 } 00227 } 00228 00229 00230 /****************************************************************************/ 00231