GUICompleteSchemeStorage.cpp
Go to the documentation of this file.00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00045
00046 GUICompleteSchemeStorage gSchemeStorage;
00047
00048
00049
00050
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
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
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 GUISettingsHandler handler(content, false);
00178 handler.addSettings();
00179 }
00180 }
00181 }
00182 myDefaultSettingName = mySortedSchemeNames[0];
00183 myX = myY = myZoom = 0;
00184 }
00185
00186
00187 void
00188 GUICompleteSchemeStorage::writeSettings(FXApp *app) throw() {
00189 const std::vector<std::string> &names = getNames();
00190 app->reg().writeIntEntry("VisualizationSettings", "settingNo", (FXint) names.size()-myNumInitialSettings);
00191 size_t gidx = 0;
00192 for (std::vector<std::string>::const_iterator i=names.begin()+myNumInitialSettings; i!=names.end(); ++i, ++gidx) {
00193 const GUIVisualizationSettings &item = mySettings.find(*i)->second;
00194 std::string sname = "visset#" + toString(gidx);
00195
00196 app->reg().writeStringEntry("VisualizationSettings", sname.c_str(), item.name.c_str());
00197 OutputDevice_String dev;
00198 item.save(dev);
00199 std::string content = dev.getString();
00200 app->reg().writeIntEntry(sname.c_str(), "xmlSize", content.size());
00201 const unsigned maxSize = 1500;
00202 for (unsigned int i = 0; i < content.size(); i+=maxSize) {
00203 const std::string b = content.substr(i, maxSize);
00204 app->reg().writeStringEntry(sname.c_str(), ("xml" + toString(i/maxSize)).c_str(), b.c_str());
00205 }
00206 }
00207 }
00208
00209
00210 void
00211 GUICompleteSchemeStorage::saveViewport(const SUMOReal x, const SUMOReal y, const SUMOReal zoom) throw() {
00212 myX = x;
00213 myY = y;
00214 myZoom = zoom;
00215 }
00216
00217
00218 void
00219 GUICompleteSchemeStorage::setViewport(GUISUMOAbstractView* view) throw() {
00220 if (myZoom > 0) {
00221 view->setViewport(myZoom, myX, myY);
00222 }
00223 }
00224
00225
00226
00227