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-sim.org/
13 // Copyright (C) 2001-2014 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 void
124  {
126  vs.name = "standard";
127  gSchemeStorage.add(vs);
128  }
129  {
131  vs.name = "faster standard";
132  vs.showLinkDecals = false;
133  vs.showRails = false;
134  gSchemeStorage.add(vs);
135  }
136  {
138  vs.name = "real world";
139  vs.vehicleQuality = 2;
140  vs.backgroundColor = RGBColor(51, 128, 51, 255);
141  vs.laneShowBorders = true;
142  vs.hideConnectors = true;
143  vs.minVehicleSize = 0;
144  vs.personQuality = 2;
145  gSchemeStorage.add(vs);
146  }
147  myNumInitialSettings = (unsigned int) mySortedSchemeNames.size();
148  // add saved settings
149  int noSaved = app->reg().readIntEntry("VisualizationSettings", "settingNo", 0);
150  for (int i = 0; i < noSaved; ++i) {
151  std::string name = "visset#" + toString(i);
152  std::string setting = app->reg().readStringEntry("VisualizationSettings", name.c_str(), "");
153  if (setting != "") {
155 
156  vs.name = setting;
157  app->reg().readStringEntry("VisualizationSettings", name.c_str(), "");
158 
159  // add saved xml setting
160  int xmlSize = app->reg().readIntEntry(name.c_str(), "xmlSize", 0);
161  std::string content = "";
162  int index = 0;
163  while (xmlSize > 0) {
164  std::string part = app->reg().readStringEntry(name.c_str(), ("xml" + toString(index)).c_str(), "");
165  if (part == "") {
166  break;
167  }
168  content += part;
169  xmlSize -= (int) part.size();
170  index++;
171  }
172  if (content != "" && xmlSize == 0) {
173  try {
174  GUISettingsHandler handler(content, false);
175  handler.addSettings();
176  } catch (ProcessError) { }
177  }
178  }
179  }
181  myLookFrom.set(0, 0, 0);
182 }
183 
184 
185 void
187  const std::vector<std::string>& names = getNames();
188  app->reg().writeIntEntry("VisualizationSettings", "settingNo", (FXint) names.size() - myNumInitialSettings);
189  size_t gidx = 0;
190  for (std::vector<std::string>::const_iterator i = names.begin() + myNumInitialSettings; i != names.end(); ++i, ++gidx) {
191  const GUIVisualizationSettings& item = mySettings.find(*i)->second;
192  std::string sname = "visset#" + toString(gidx);
193 
194  app->reg().writeStringEntry("VisualizationSettings", sname.c_str(), item.name.c_str());
196  item.save(dev);
197  std::string content = dev.getString();
198  app->reg().writeIntEntry(sname.c_str(), "xmlSize", (FXint)(content.size()));
199  const unsigned maxSize = 1500; // this is a fox limitation for registry entries
200  for (unsigned int i = 0; i < content.size(); i += maxSize) {
201  const std::string b = content.substr(i, maxSize);
202  app->reg().writeStringEntry(sname.c_str(), ("xml" + toString(i / maxSize)).c_str(), b.c_str());
203  }
204  }
205 }
206 
207 
208 void
210  myLookFrom.set(x, y, zoom);
211 }
212 
213 
214 void
216  if (myLookFrom.z() > 0) {
218  } else {
219  view->recenterView();
220  }
221 }
222 
223 
224 /****************************************************************************/
225