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