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-2013 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  gSchemeStorage.add(vs);
145  }
146  myNumInitialSettings = (unsigned int) mySortedSchemeNames.size();
147  // add saved settings
148  int noSaved = app->reg().readIntEntry("VisualizationSettings", "settingNo", 0);
149  for (int i = 0; i < noSaved; ++i) {
150  std::string name = "visset#" + toString(i);
151  std::string setting = app->reg().readStringEntry("VisualizationSettings", name.c_str(), "");
152  if (setting != "") {
154 
155  vs.name = setting;
156  app->reg().readStringEntry("VisualizationSettings", name.c_str(), "");
157 
158  // add saved xml setting
159  int xmlSize = app->reg().readIntEntry(name.c_str(), "xmlSize", 0);
160  std::string content = "";
161  int index = 0;
162  while (xmlSize > 0) {
163  std::string part = app->reg().readStringEntry(name.c_str(), ("xml" + toString(index)).c_str(), "");
164  if (part == "") {
165  break;
166  }
167  content += part;
168  xmlSize -= (int) part.size();
169  index++;
170  }
171  if (content != "" && xmlSize == 0) {
172  try {
173  GUISettingsHandler handler(content, false);
174  handler.addSettings();
175  } catch (ProcessError) { }
176  }
177  }
178  }
180  myLookFrom.set(0, 0, 0);
181 }
182 
183 
184 void
186  const std::vector<std::string>& names = getNames();
187  app->reg().writeIntEntry("VisualizationSettings", "settingNo", (FXint) names.size() - myNumInitialSettings);
188  size_t gidx = 0;
189  for (std::vector<std::string>::const_iterator i = names.begin() + myNumInitialSettings; i != names.end(); ++i, ++gidx) {
190  const GUIVisualizationSettings& item = mySettings.find(*i)->second;
191  std::string sname = "visset#" + toString(gidx);
192 
193  app->reg().writeStringEntry("VisualizationSettings", sname.c_str(), item.name.c_str());
195  item.save(dev);
196  std::string content = dev.getString();
197  app->reg().writeIntEntry(sname.c_str(), "xmlSize", (FXint)(content.size()));
198  const unsigned maxSize = 1500; // this is a fox limitation for registry entries
199  for (unsigned int i = 0; i < content.size(); i += maxSize) {
200  const std::string b = content.substr(i, maxSize);
201  app->reg().writeStringEntry(sname.c_str(), ("xml" + toString(i / maxSize)).c_str(), b.c_str());
202  }
203  }
204 }
205 
206 
207 void
209  myLookFrom.set(x, y, zoom);
210 }
211 
212 
213 void
215  if (myLookFrom.z() > 0) {
217  } else {
218  view->recenterView();
219  }
220 }
221 
222 
223 /****************************************************************************/
224 
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.
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:51
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
float minVehicleSize
The minimum size of vehicles to let them be drawn.
#define SUMOReal
Definition: config.h:221
An XML-handler for visualisation schemes.
void save(OutputDevice &dev) const
Writes the settings into an output device.
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.