SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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.dlr.de/
13 // Copyright (C) 2001-2016 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 int
118  return myNumInitialSettings;
119 }
120 
121 
122 void
124  {
126  vs.name = "standard";
127  vs.laneShowBorders = true;
128  gSchemeStorage.add(vs);
129  }
130  {
132  vs.name = "faster standard";
133  vs.laneShowBorders = false;
134  vs.showLinkDecals = false;
135  vs.showRails = false;
136  gSchemeStorage.add(vs);
137  }
138  {
140  vs.name = "real world";
141  vs.vehicleQuality = 2;
142  vs.backgroundColor = RGBColor(51, 128, 51, 255);
143  vs.laneShowBorders = true;
144  vs.hideConnectors = true;
145  vs.vehicleSize.minSize = 0;
146  vs.personQuality = 2;
147  vs.containerQuality = 2;
148  gSchemeStorage.add(vs);
149  }
151  // add saved settings
152  int noSaved = app->reg().readIntEntry("VisualizationSettings", "settingNo", 0);
153  for (int i = 0; i < noSaved; ++i) {
154  std::string name = "visset#" + toString(i);
155  std::string setting = app->reg().readStringEntry("VisualizationSettings", name.c_str(), "");
156  if (setting != "") {
158 
159  vs.name = setting;
160  app->reg().readStringEntry("VisualizationSettings", name.c_str(), "");
161 
162  // add saved xml setting
163  int xmlSize = app->reg().readIntEntry(name.c_str(), "xmlSize", 0);
164  std::string content = "";
165  int index = 0;
166  while (xmlSize > 0) {
167  std::string part = app->reg().readStringEntry(name.c_str(), ("xml" + toString(index)).c_str(), "");
168  if (part == "") {
169  break;
170  }
171  content += part;
172  xmlSize -= (int) part.size();
173  index++;
174  }
175  if (content != "" && xmlSize == 0) {
176  try {
177  GUISettingsHandler handler(content, false);
178  handler.addSettings();
179  } catch (ProcessError) { }
180  }
181  }
182  }
184  myLookFrom.set(0, 0, 0);
185 }
186 
187 
188 void
190  const std::vector<std::string>& names = getNames();
191  app->reg().writeIntEntry("VisualizationSettings", "settingNo", (FXint) names.size() - myNumInitialSettings);
192  int gidx = 0;
193  for (std::vector<std::string>::const_iterator i = names.begin() + myNumInitialSettings; i != names.end(); ++i, ++gidx) {
194  const GUIVisualizationSettings& item = mySettings.find(*i)->second;
195  std::string sname = "visset#" + toString(gidx);
196 
197  app->reg().writeStringEntry("VisualizationSettings", sname.c_str(), item.name.c_str());
199  item.save(dev);
200  std::string content = dev.getString();
201  app->reg().writeIntEntry(sname.c_str(), "xmlSize", (FXint)(content.size()));
202  const unsigned maxSize = 1500; // this is a fox limitation for registry entries
203  for (int i = 0; i < (int)content.size(); i += maxSize) {
204  const std::string b = content.substr(i, maxSize);
205  app->reg().writeStringEntry(sname.c_str(), ("xml" + toString(i / maxSize)).c_str(), b.c_str());
206  }
207  }
208 }
209 
210 
211 void
213  myLookFrom.set(x, y, z);
214 }
215 
216 
217 void
219  if (myLookFrom.z() > 0) {
220  // look straight down
222  } else {
223  view->recenterView();
224  }
225 }
226 
227 
228 /****************************************************************************/
229 
int getNumInitialSettings() const
Returns the number of initial settings.
int myNumInitialSettings
The number of settings which were present at startup.
GUICompleteSchemeStorage gSchemeStorage
std::string getString() const
Returns the current content as a string.
std::string addSettings(GUISUMOAbstractView *view=0) const
Adds the parsed settings to the global list of settings.
void setDefault(const std::string &name)
Makes the scheme with the given name the default.
virtual void setViewportFromTo(const Position &lookFrom, const Position &lookAt)
applies the given viewport settings
Position myLookFrom
The default viewport.
virtual void recenterView()
recenters the view
Stores the information about how to visualize structures.
SUMOReal minSize
The minimum size to draw this object.
bool showRails
Information whether rails shall be drawn.
bool laneShowBorders
Information whether lane borders shall be drawn.
SUMOReal x() const
Returns the x-position.
Definition: Position.h:63
const std::vector< std::string > & getNames() const
Returns a list of stored settings names.
std::string name
The name of this setting.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
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.
SUMOReal z() const
Returns the z-position.
Definition: Position.h:73
GUIVisualizationSettings & get(const std::string &name)
Returns the named scheme.
std::map< std::string, GUIVisualizationSettings > mySettings
A map of settings referenced by their names.
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:55
int containerQuality
The quality of container drawing.
RGBColor backgroundColor
The background color to use.
GUIVisualizationSettings & getDefault()
Returns the default scheme.
void saveViewport(const SUMOReal x, const SUMOReal y, const SUMOReal z)
Makes the given viewport the default.
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.
SUMOReal y() const
Returns the y-position.
Definition: Position.h:68
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:214
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.