SUMO - Simulation of Urban MObility
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.dlr.de/
13 // Copyright (C) 2001-2015 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.vehicleSize.minSize = 0;
144  vs.personQuality = 2;
145  vs.containerQuality = 2;
146  gSchemeStorage.add(vs);
147  }
148  myNumInitialSettings = (unsigned int) mySortedSchemeNames.size();
149  // add saved settings
150  int noSaved = app->reg().readIntEntry("VisualizationSettings", "settingNo", 0);
151  for (int i = 0; i < noSaved; ++i) {
152  std::string name = "visset#" + toString(i);
153  std::string setting = app->reg().readStringEntry("VisualizationSettings", name.c_str(), "");
154  if (setting != "") {
156 
157  vs.name = setting;
158  app->reg().readStringEntry("VisualizationSettings", name.c_str(), "");
159 
160  // add saved xml setting
161  int xmlSize = app->reg().readIntEntry(name.c_str(), "xmlSize", 0);
162  std::string content = "";
163  int index = 0;
164  while (xmlSize > 0) {
165  std::string part = app->reg().readStringEntry(name.c_str(), ("xml" + toString(index)).c_str(), "");
166  if (part == "") {
167  break;
168  }
169  content += part;
170  xmlSize -= (int) part.size();
171  index++;
172  }
173  if (content != "" && xmlSize == 0) {
174  try {
175  GUISettingsHandler handler(content, false);
176  handler.addSettings();
177  } catch (ProcessError) { }
178  }
179  }
180  }
182  myLookFrom.set(0, 0, 0);
183 }
184 
185 
186 void
188  const std::vector<std::string>& names = getNames();
189  app->reg().writeIntEntry("VisualizationSettings", "settingNo", (FXint) names.size() - myNumInitialSettings);
190  size_t gidx = 0;
191  for (std::vector<std::string>::const_iterator i = names.begin() + myNumInitialSettings; i != names.end(); ++i, ++gidx) {
192  const GUIVisualizationSettings& item = mySettings.find(*i)->second;
193  std::string sname = "visset#" + toString(gidx);
194 
195  app->reg().writeStringEntry("VisualizationSettings", sname.c_str(), item.name.c_str());
197  item.save(dev);
198  std::string content = dev.getString();
199  app->reg().writeIntEntry(sname.c_str(), "xmlSize", (FXint)(content.size()));
200  const unsigned maxSize = 1500; // this is a fox limitation for registry entries
201  for (unsigned int i = 0; i < content.size(); i += maxSize) {
202  const std::string b = content.substr(i, maxSize);
203  app->reg().writeStringEntry(sname.c_str(), ("xml" + toString(i / maxSize)).c_str(), b.c_str());
204  }
205  }
206 }
207 
208 
209 void
211  myLookFrom.set(x, y, zoom);
212 }
213 
214 
215 void
217  if (myLookFrom.z() > 0) {
219  } else {
220  view->recenterView();
221  }
222 }
223 
224 
225 /****************************************************************************/
226 
GUICompleteSchemeStorage gSchemeStorage
std::string addSettings(GUISUMOAbstractView *view=0) const
Adds the parsed settings to the global list of settings.
virtual void setViewport(const Position &lookFrom, const Position &lookAt)
applies the given viewport settings
void setDefault(const std::string &name)
Makes the scheme with the given name the default.
Position myLookFrom
The default viewport.
virtual void recenterView()
recenters the view
unsigned int myNumInitialSettings
The number of settings which were present at startup.
Stores the information about how to visualize structures.
bool showRails
Information whether rails shall be drawn.
bool laneShowBorders
Information whether lane borders shall be drawn.
const std::vector< std::string > & getNames() const
Returns a list of stored settings names.
std::string name
The name of this setting.
bool contains(const std::string &name) const
Returns the information whether a setting with the given name is stored.
void remove(const std::string &name)
Removes the setting with the given name.
unsigned int getNumInitialSettings() const
Returns the number of initial settings.
SUMOReal z() const
Returns the z-position.
Definition: Position.h:73
GUIVisualizationSettings & get(const std::string &name)
Returns the named scheme.
std::string getString()
Returns the current content as a string.
std::map< std::string, GUIVisualizationSettings > mySettings
A map of settings referenced by their names.
float minSize
The minimum size to draw this object.
void saveViewport(const SUMOReal x, const SUMOReal y, const SUMOReal zoom)
Makes the given viewport the default.
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:53
int containerQuality
The quality of container drawing.
RGBColor backgroundColor
The background color to use.
GUIVisualizationSettings & getDefault()
Returns the default scheme.
Storage for available visualization settings.
bool showLinkDecals
Information whether link textures (arrows) shall be drawn.
void setViewport(GUISUMOAbstractView *view)
Sets the default viewport.
std::vector< std::string > mySortedSchemeNames
List of known setting names.
void writeSettings(FXApp *app)
Writes the current scheme into the registry.
void set(SUMOReal x, SUMOReal y)
Definition: Position.h:78
int personQuality
The quality of person drawing.
#define SUMOReal
Definition: config.h:218
An XML-handler for visualisation schemes.
void save(OutputDevice &dev) const
Writes the settings into an output device.
GUIVisualizationSizeSettings vehicleSize
void init(FXApp *app)
Initialises the storage with some default settings.
int vehicleQuality
The quality of vehicle drawing.
An output device that encapsulates an ofstream.
void add(const GUIVisualizationSettings &scheme)
Adds a visualization scheme.
std::string myDefaultSettingName
Name of the default setting.