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-2017 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 
43 // ===========================================================================
44 // static variable definitions
45 // ===========================================================================
47 
48 
49 // ===========================================================================
50 // method definitions
51 // ===========================================================================
53 
54 
56 
57 
58 
59 void
61  std::string name = scheme.name;
62  if (std::find(mySortedSchemeNames.begin(), mySortedSchemeNames.end(), name) == mySortedSchemeNames.end()) {
63  mySortedSchemeNames.push_back(name);
64  }
65  mySettings[name] = scheme;
66 }
67 
68 
70 GUICompleteSchemeStorage::get(const std::string& name) {
71  return mySettings.find(name)->second;
72 }
73 
74 
77  return mySettings.find(myDefaultSettingName)->second;
78 }
79 
80 
81 bool
82 GUICompleteSchemeStorage::contains(const std::string& name) const {
83  return mySettings.find(name) != mySettings.end();
84 }
85 
86 
87 void
88 GUICompleteSchemeStorage::remove(const std::string& name) {
89  if (!contains(name)) {
90  return;
91  }
92  mySortedSchemeNames.erase(find(mySortedSchemeNames.begin(), mySortedSchemeNames.end(), name));
93  mySettings.erase(mySettings.find(name));
94 }
95 
96 
97 void
98 GUICompleteSchemeStorage::setDefault(const std::string& name) {
99  if (!contains(name)) {
100  return;
101  }
102  myDefaultSettingName = name;
103 }
104 
105 
106 const std::vector<std::string>&
108  return mySortedSchemeNames;
109 }
110 
111 
112 int
114  return myNumInitialSettings;
115 }
116 
117 
118 void
120  {
122  vs.name = "standard";
123  vs.laneShowBorders = true;
124  gSchemeStorage.add(vs);
125  }
126  {
128  vs.name = "faster standard";
129  vs.laneShowBorders = false;
130  vs.showLinkDecals = false;
131  vs.showRails = false;
132  gSchemeStorage.add(vs);
133  }
134  {
136  vs.name = "real world";
137  vs.vehicleQuality = 2;
138  vs.backgroundColor = RGBColor(51, 128, 51, 255);
139  vs.laneShowBorders = true;
140  vs.hideConnectors = true;
141  vs.vehicleSize.minSize = 0;
142  vs.personQuality = 2;
143  vs.containerQuality = 2;
144  gSchemeStorage.add(vs);
145  }
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  int 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 (int i = 0; i < (int)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
208 GUICompleteSchemeStorage::saveViewport(const double x, const double y, const double z) {
209  myLookFrom.set(x, y, z);
210 }
211 
212 
213 void
215  if (myLookFrom.z() > 0) {
216  // look straight down
218  } else {
219  view->recenterView();
220  }
221 }
222 
223 
224 /****************************************************************************/
225 
int myNumInitialSettings
The number of settings which were present at startup.
GUICompleteSchemeStorage gSchemeStorage
void setDefault(const std::string &name)
Makes the scheme with the given name the default.
double z() const
Returns the z-position.
Definition: Position.h:73
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
const std::vector< std::string > & getNames() const
Returns a list of stored settings names.
Stores the information about how to visualize structures.
std::string getString() const
Returns the current content as a string.
double y() const
Returns the y-position.
Definition: Position.h:68
bool showRails
Information whether rails shall be drawn.
double x() const
Returns the x-position.
Definition: Position.h:63
bool laneShowBorders
Information whether lane borders shall be drawn.
void saveViewport(const double x, const double y, const double z)
Makes the given viewport the default.
void set(double x, double y)
set positions x and y
Definition: Position.h:93
void save(OutputDevice &dev) const
Writes the settings into an output device.
std::string name
The name of this setting.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:56
double minSize
The minimum size to draw this object.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
void remove(const std::string &name)
Removes the setting with the given name.
GUIVisualizationSettings & get(const std::string &name)
Returns the named scheme.
std::map< std::string, GUIVisualizationSettings > mySettings
A map of settings referenced by their names.
int getNumInitialSettings() const
Returns the number of initial settings.
int containerQuality
The quality of container drawing.
RGBColor backgroundColor
The background color to use.
std::string addSettings(GUISUMOAbstractView *view=0) const
Adds the parsed settings to the global list of settings.
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.
bool contains(const std::string &name) const
Returns the information whether a setting with the given name is stored.
std::vector< std::string > mySortedSchemeNames
List of known setting names.
void writeSettings(FXApp *app)
Writes the current scheme into the registry.
int personQuality
The quality of person drawing.
An XML-handler for visualisation schemes.
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.