SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GUICompleteSchemeStorage.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // Storage for available visualization settings
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
13 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
35 #include <utils/common/ToString.h>
37 #include <utils/common/RGBColor.h>
41 
42 #ifdef CHECK_MEMORY_LEAKS
43 #include <foreign/nvwa/debug_new.h>
44 #endif // CHECK_MEMORY_LEAKS
45 
46 
47 // ===========================================================================
48 // static variable definitions
49 // ===========================================================================
51 
52 
53 // ===========================================================================
54 // method definitions
55 // ===========================================================================
57 
58 
60 
61 
62 
63 void
65  std::string name = scheme.name;
66  if (std::find(mySortedSchemeNames.begin(), mySortedSchemeNames.end(), name) == mySortedSchemeNames.end()) {
67  mySortedSchemeNames.push_back(name);
68  }
69  mySettings[name] = scheme;
70 }
71 
72 
74 GUICompleteSchemeStorage::get(const std::string& name) {
75  return mySettings.find(name)->second;
76 }
77 
78 
81  return mySettings.find(myDefaultSettingName)->second;
82 }
83 
84 
85 bool
86 GUICompleteSchemeStorage::contains(const std::string& name) const {
87  return mySettings.find(name) != mySettings.end();
88 }
89 
90 
91 void
92 GUICompleteSchemeStorage::remove(const std::string& name) {
93  if (!contains(name)) {
94  return;
95  }
96  mySortedSchemeNames.erase(find(mySortedSchemeNames.begin(), mySortedSchemeNames.end(), name));
97  mySettings.erase(mySettings.find(name));
98 }
99 
100 
101 void
102 GUICompleteSchemeStorage::setDefault(const std::string& name) {
103  if (!contains(name)) {
104  return;
105  }
106  myDefaultSettingName = name;
107 }
108 
109 
110 const std::vector<std::string>&
112  return mySortedSchemeNames;
113 }
114 
115 
116 unsigned int
118  return myNumInitialSettings;
119 }
120 
121 
122 RGBColor
123 convert(const FXColor c) {
124  return RGBColor(
125  (SUMOReal) FXREDVAL(c) / (SUMOReal) 255.,
126  (SUMOReal) FXGREENVAL(c) / (SUMOReal) 255.,
127  (SUMOReal) FXBLUEVAL(c) / (SUMOReal) 255.);
128 }
129 
130 
131 void
133  {
135  vs.name = "standard";
136  gSchemeStorage.add(vs);
137  }
138  {
140  vs.name = "faster standard";
141  vs.showLinkDecals = false;
142  vs.showRails = false;
143  gSchemeStorage.add(vs);
144  }
145  {
147  vs.name = "real world";
148  vs.vehicleQuality = 2;
149  vs.backgroundColor = RGBColor((SUMOReal) .2, (SUMOReal) .5, (SUMOReal) .2);
150  vs.laneShowBorders = true;
151  vs.hideConnectors = true;
152  vs.minVehicleSize = 0;
153  gSchemeStorage.add(vs);
154  }
155  myNumInitialSettings = (unsigned int) mySortedSchemeNames.size();
156  // add saved settings
157  int noSaved = app->reg().readIntEntry("VisualizationSettings", "settingNo", 0);
158  for (int i = 0; i < noSaved; ++i) {
159  std::string name = "visset#" + toString(i);
160  std::string setting = app->reg().readStringEntry("VisualizationSettings", name.c_str(), "");
161  if (setting != "") {
163 
164  vs.name = setting;
165  app->reg().readStringEntry("VisualizationSettings", name.c_str(), "");
166 
167  // add saved xml setting
168  int xmlSize = app->reg().readIntEntry(name.c_str(), "xmlSize", 0);
169  std::string content = "";
170  int index = 0;
171  while (xmlSize > 0) {
172  std::string part = app->reg().readStringEntry(name.c_str(), ("xml" + toString(index)).c_str(), "");
173  if (part == "") {
174  break;
175  }
176  content += part;
177  xmlSize -= (int) part.size();
178  index++;
179  }
180  if (content != "" && xmlSize == 0) {
181  try {
182  GUISettingsHandler handler(content, false);
183  handler.addSettings();
184  } catch (ProcessError) { }
185  }
186  }
187  }
189  myX = myY = myZoom = 0;
190 }
191 
192 
193 void
195  const std::vector<std::string>& names = getNames();
196  app->reg().writeIntEntry("VisualizationSettings", "settingNo", (FXint) names.size() - myNumInitialSettings);
197  size_t gidx = 0;
198  for (std::vector<std::string>::const_iterator i = names.begin() + myNumInitialSettings; i != names.end(); ++i, ++gidx) {
199  const GUIVisualizationSettings& item = mySettings.find(*i)->second;
200  std::string sname = "visset#" + toString(gidx);
201 
202  app->reg().writeStringEntry("VisualizationSettings", sname.c_str(), item.name.c_str());
204  item.save(dev);
205  std::string content = dev.getString();
206  app->reg().writeIntEntry(sname.c_str(), "xmlSize", (FXint)(content.size()));
207  const unsigned maxSize = 1500; // this is a fox limitation for registry entries
208  for (unsigned int i = 0; i < content.size(); i += maxSize) {
209  const std::string b = content.substr(i, maxSize);
210  app->reg().writeStringEntry(sname.c_str(), ("xml" + toString(i / maxSize)).c_str(), b.c_str());
211  }
212  }
213 }
214 
215 
216 void
218  myX = x;
219  myY = y;
220  myZoom = zoom;
221 }
222 
223 
224 void
226  if (myZoom > 0) {
227  view->setViewport(myZoom, myX, myY);
228  } else {
229  view->recenterView();
230  }
231 }
232 
233 
234 /****************************************************************************/
235