SUMO - Simulation of Urban MObility
GUICompleteSchemeStorage.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
20 // Storage for available visualization settings
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
34 #include <utils/common/ToString.h>
36 #include <utils/common/RGBColor.h>
40 
41 
42 // ===========================================================================
43 // static variable definitions
44 // ===========================================================================
46 
47 
48 // ===========================================================================
49 // method definitions
50 // ===========================================================================
52 
53 
55 
56 
57 
58 void
60  std::string name = scheme.name;
61  if (std::find(mySortedSchemeNames.begin(), mySortedSchemeNames.end(), name) == mySortedSchemeNames.end()) {
62  mySortedSchemeNames.push_back(name);
63  }
64  mySettings[name] = scheme;
65 }
66 
67 
69 GUICompleteSchemeStorage::get(const std::string& name) {
70  return mySettings.find(name)->second;
71 }
72 
73 
76  return mySettings.find(myDefaultSettingName)->second;
77 }
78 
79 
80 bool
81 GUICompleteSchemeStorage::contains(const std::string& name) const {
82  return mySettings.find(name) != mySettings.end();
83 }
84 
85 
86 void
87 GUICompleteSchemeStorage::remove(const std::string& name) {
88  if (!contains(name)) {
89  return;
90  }
91  mySortedSchemeNames.erase(find(mySortedSchemeNames.begin(), mySortedSchemeNames.end(), name));
92  mySettings.erase(mySettings.find(name));
93 }
94 
95 
96 void
97 GUICompleteSchemeStorage::setDefault(const std::string& name) {
98  if (!contains(name)) {
99  return;
100  }
101  myDefaultSettingName = name;
102 }
103 
104 
105 const std::vector<std::string>&
107  return mySortedSchemeNames;
108 }
109 
110 
111 int
113  return myNumInitialSettings;
114 }
115 
116 
117 void
118 GUICompleteSchemeStorage::init(FXApp* app, bool netedit) {
119  {
120  GUIVisualizationSettings vs(netedit);
121  vs.name = "standard";
122  vs.laneShowBorders = true;
123  gSchemeStorage.add(vs);
124  }
125  {
126  GUIVisualizationSettings vs(netedit);
127  vs.name = "faster standard";
128  vs.laneShowBorders = false;
129  vs.showLinkDecals = false;
130  vs.showRails = false;
131  gSchemeStorage.add(vs);
132  }
133  {
134  GUIVisualizationSettings vs(netedit);
135  vs.name = "real world";
136  vs.vehicleQuality = 2;
137  vs.backgroundColor = RGBColor(51, 128, 51, 255);
138  vs.laneShowBorders = true;
139  vs.hideConnectors = true;
140  vs.vehicleSize.minSize = 0;
141  vs.personQuality = 2;
142  vs.containerQuality = 2;
143  gSchemeStorage.add(vs);
144  }
146  // add saved settings
147  int noSaved = app->reg().readIntEntry("VisualizationSettings", "settingNo", 0);
148  for (int i = 0; i < noSaved; ++i) {
149  std::string name = "visset#" + toString(i);
150  std::string setting = app->reg().readStringEntry("VisualizationSettings", name.c_str(), "");
151  if (setting != "") {
152  GUIVisualizationSettings vs(netedit);
153 
154  vs.name = setting;
155  app->reg().readStringEntry("VisualizationSettings", name.c_str(), "");
156 
157  // add saved xml setting
158  int xmlSize = app->reg().readIntEntry(name.c_str(), "xmlSize", 0);
159  std::string content = "";
160  int index = 0;
161  while (xmlSize > 0) {
162  std::string part = app->reg().readStringEntry(name.c_str(), ("xml" + toString(index)).c_str(), "");
163  if (part == "") {
164  break;
165  }
166  content += part;
167  xmlSize -= (int) part.size();
168  index++;
169  }
170  if (content != "" && xmlSize == 0) {
171  try {
172  GUISettingsHandler handler(content, false, netedit);
173  handler.addSettings();
174  } catch (ProcessError) { }
175  }
176  }
177  }
179  myLookFrom.set(0, 0, 0);
180 }
181 
182 
183 void
185  const std::vector<std::string>& names = getNames();
186  app->reg().writeIntEntry("VisualizationSettings", "settingNo", (FXint) names.size() - myNumInitialSettings);
187  int gidx = 0;
188  for (std::vector<std::string>::const_iterator i = names.begin() + myNumInitialSettings; i != names.end(); ++i, ++gidx) {
189  const GUIVisualizationSettings& item = mySettings.find(*i)->second;
190  std::string sname = "visset#" + toString(gidx);
191 
192  app->reg().writeStringEntry("VisualizationSettings", sname.c_str(), item.name.c_str());
194  item.save(dev);
195  std::string content = dev.getString();
196  app->reg().writeIntEntry(sname.c_str(), "xmlSize", (FXint)(content.size()));
197  const unsigned maxSize = 1500; // this is a fox limitation for registry entries
198  for (int i = 0; i < (int)content.size(); i += maxSize) {
199  const std::string b = content.substr(i, maxSize);
200  app->reg().writeStringEntry(sname.c_str(), ("xml" + toString(i / maxSize)).c_str(), b.c_str());
201  }
202  }
203 }
204 
205 
206 void
207 GUICompleteSchemeStorage::saveViewport(const double x, const double y, const double z) {
208  myLookFrom.set(x, y, z);
209 }
210 
211 
212 void
214  if (myLookFrom.z() > 0) {
215  // look straight down
217  } else {
218  view->recenterView();
219  }
220 }
221 
222 
223 /****************************************************************************/
224 
void init(FXApp *app, bool netedit=false)
Initialises the storage with some default settings.
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:72
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:67
bool showRails
Information whether rails shall be drawn.
double x() const
Returns the x-position.
Definition: Position.h:62
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:92
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:55
double minSize
The minimum size to draw this object.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
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
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.