Eclipse 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-2022 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials are made available under the
5 // terms of the Eclipse Public License 2.0 which is available at
6 // https://www.eclipse.org/legal/epl-2.0/
7 // This Source Code may also be made available under the following Secondary
8 // Licenses when the conditions for such availability set forth in the Eclipse
9 // Public License 2.0 are satisfied: GNU General Public License, version 2
10 // or later which is available at
11 // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12 // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13 /****************************************************************************/
21 // Storage for available visualization settings
22 /****************************************************************************/
23 #include <config.h>
24 
26 #include <utils/common/ToString.h>
28 #include <utils/common/RGBColor.h>
32 
33 
34 // ===========================================================================
35 // static variable definitions
36 // ===========================================================================
38 
39 
40 // ===========================================================================
41 // method definitions
42 // ===========================================================================
44 
45 
47 
48 
49 
50 void
52  std::string name = scheme.name;
53  if (std::find(mySortedSchemeNames.begin(), mySortedSchemeNames.end(), name) == mySortedSchemeNames.end()) {
54  mySortedSchemeNames.push_back(name);
55  }
56  mySettings[name] = scheme;
57 }
58 
59 
61 GUICompleteSchemeStorage::get(const std::string& name) {
62  return mySettings.find(name)->second;
63 }
64 
65 
68  return mySettings.find(myDefaultSettingName)->second;
69 }
70 
71 
72 bool
73 GUICompleteSchemeStorage::contains(const std::string& name) const {
74  return mySettings.find(name) != mySettings.end();
75 }
76 
77 
78 void
79 GUICompleteSchemeStorage::remove(const std::string& name) {
80  if (!contains(name)) {
81  return;
82  }
83  mySortedSchemeNames.erase(find(mySortedSchemeNames.begin(), mySortedSchemeNames.end(), name));
84  mySettings.erase(mySettings.find(name));
85 }
86 
87 
88 void
89 GUICompleteSchemeStorage::setDefault(const std::string& name) {
90  if (!contains(name)) {
91  return;
92  }
93  myDefaultSettingName = name;
94 }
95 
96 
97 const std::vector<std::string>&
99  return mySortedSchemeNames;
100 }
101 
102 
103 int
105  return myNumInitialSettings;
106 }
107 
108 
109 void
110 GUICompleteSchemeStorage::init(FXApp* app, bool netedit) {
111  {
112  GUIVisualizationSettings vs(netedit);
113  vs.name = "standard";
114  vs.laneShowBorders = true;
115  gSchemeStorage.add(vs);
116  }
117  {
118  GUIVisualizationSettings vs(netedit);
119  vs.name = "faster standard";
120  vs.laneShowBorders = false;
121  vs.showLinkDecals = false;
122  vs.showRails = false;
123  vs.showRails = false;
124  vs.showSublanes = 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  vs.showSublanes = false;
138  gSchemeStorage.add(vs);
139  }
140  {
141  GUIVisualizationSettings vs(netedit);
142  vs.name = "rail";
143  vs.vehicleQuality = 2;
144  vs.showLaneDirection = true;
145  vs.spreadSuperposed = true;
146  vs.junctionSize.constantSize = true;
148  gSchemeStorage.add(vs);
149  }
150 
151  if (!netedit) {
152  GUIVisualizationSettings vs(netedit);
153  vs.name = "selection";
162  gSchemeStorage.add(vs);
163  }
165  // add saved settings
166  int noSaved = app->reg().readIntEntry("VisualizationSettings", "settingNo", 0);
167  for (int i = 0; i < noSaved; ++i) {
168  std::string name = "visset#" + toString(i);
169  std::string setting = app->reg().readStringEntry("VisualizationSettings", name.c_str(), "");
170  if (setting != "") {
171  GUIVisualizationSettings vs(netedit);
172 
173  vs.name = setting;
174  app->reg().readStringEntry("VisualizationSettings", name.c_str(), "");
175 
176  // add saved xml setting
177  int xmlSize = app->reg().readIntEntry(name.c_str(), "xmlSize", 0);
178  std::string content = "";
179  int index = 0;
180  while (xmlSize > 0) {
181  std::string part = app->reg().readStringEntry(name.c_str(), ("xml" + toString(index)).c_str(), "");
182  if (part == "") {
183  break;
184  }
185  content += part;
186  xmlSize -= (int) part.size();
187  index++;
188  }
189  if (content != "" && xmlSize == 0) {
190  try {
191  GUISettingsHandler handler(content, false, netedit);
192  handler.addSettings();
193  } catch (ProcessError&) { }
194  }
195  }
196  }
198  myLookFrom.set(0, 0, 0);
199 }
200 
201 
202 void
204  const std::vector<std::string>& names = getNames();
205  app->reg().writeIntEntry("VisualizationSettings", "settingNo", (FXint) names.size() - myNumInitialSettings);
206  int gidx = 0;
207  for (std::vector<std::string>::const_iterator it = names.begin() + myNumInitialSettings; it != names.end(); ++it, ++gidx) {
208  const GUIVisualizationSettings& item = mySettings.find(*it)->second;
209  std::string sname = "visset#" + toString(gidx);
210 
211  app->reg().writeStringEntry("VisualizationSettings", sname.c_str(), item.name.c_str());
213  item.save(dev);
214  std::string content = dev.getString();
215  app->reg().writeIntEntry(sname.c_str(), "xmlSize", (FXint)(content.size()));
216  const unsigned maxSize = 1500; // this is a fox limitation for registry entries
217  for (int i = 0; i < (int)content.size(); i += maxSize) {
218  const std::string b = content.substr(i, maxSize);
219  app->reg().writeStringEntry(sname.c_str(), ("xml" + toString(i / maxSize)).c_str(), b.c_str());
220  }
221  }
222 }
223 
224 
225 void
226 GUICompleteSchemeStorage::saveViewport(const double x, const double y, const double z, const double rot) {
227  myLookFrom.set(x, y, z);
228  myRotation = rot;
229 }
230 
231 
232 void
234  if (myLookFrom.z() > 0) {
235  // look straight down
237  } else {
238  view->recenterView();
239  }
240 }
241 
242 
243 /****************************************************************************/
GUICompleteSchemeStorage gSchemeStorage
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
Storage for available visualization settings.
bool contains(const std::string &name) const
Returns the information whether a setting with the given name is stored.
GUIVisualizationSettings & get(const std::string &name)
Returns the named scheme.
std::map< std::string, GUIVisualizationSettings > mySettings
A map of settings referenced by their names.
GUIVisualizationSettings & getDefault()
Returns the default scheme.
const std::vector< std::string > & getNames() const
Returns a list of stored settings names.
void add(const GUIVisualizationSettings &scheme)
Adds a visualization scheme.
int getNumInitialSettings() const
Returns the number of initial settings.
void saveViewport(const double x, const double y, const double z, const double rot)
Makes the given viewport the default.
std::vector< std::string > mySortedSchemeNames
List of known setting names.
std::string myDefaultSettingName
Name of the default setting.
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.
void setDefault(const std::string &name)
Makes the scheme with the given name the default.
void remove(const std::string &name)
Removes the setting with the given name.
Position myLookFrom
The default viewport.
void writeSettings(FXApp *app)
Writes the current scheme into the registry.
void setViewport(GUISUMOAbstractView *view)
Sets the default viewport.
void setSchemeByName(std::string name)
virtual void recenterView()
recenters the view
virtual void setViewportFromToRot(const Position &lookFrom, const Position &lookAt, double rotation)
applies the given viewport settings
An XML-handler for visualisation schemes.
const std::vector< std::string > & addSettings(GUISUMOAbstractView *view=0) const
Adds the parsed settings to the global list of settings.
Stores the information about how to visualize structures.
RGBColor backgroundColor
The background color to use.
GUIVisualizationSizeSettings vehicleSize
GUIVisualizationSizeSettings junctionSize
GUIColorer vehicleColorer
The vehicle colorer.
static const std::string SCHEME_NAME_SELECTION
std::string name
The name of this setting.
GUIColorer edgeColorer
The mesoscopic edge colorer.
int containerQuality
The quality of container drawing.
int personQuality
The quality of person drawing.
GUIColorer poiColorer
The POI colorer.
GUIColorer polyColorer
The polygon colorer.
int vehicleQuality
The quality of vehicle drawing.
bool showRails
Information whether rails shall be drawn.
bool showSublanes
Whether to show sublane boundaries.
static const std::string SCHEME_NAME_TYPE
bool hideConnectors
flag to show or hidde connectors
GUIColorer personColorer
The person colorer.
void save(OutputDevice &dev) const
Writes the settings into an output device.
bool showLaneDirection
Whether to show direction indicators for lanes.
bool showLinkDecals
Information whether link textures (arrows) shall be drawn.
GUIColorer laneColorer
The lane colorer.
bool laneShowBorders
Information whether lane borders shall be drawn.
GUIColorer containerColorer
The container colorer.
bool spreadSuperposed
Whether to improve visualisation of superposed (rail) edges.
GUIColorer junctionColorer
The junction colorer.
An output device that encapsulates an ofstream.
std::string getString() const
Returns the current content as a string.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
void set(double x, double y)
set positions x and y
Definition: Position.h:85
double x() const
Returns the x-position.
Definition: Position.h:55
double z() const
Returns the z-position.
Definition: Position.h:65
double y() const
Returns the y-position.
Definition: Position.h:60
bool constantSize
whether the object shall be drawn with constant size regardless of zoom
double minSize
The minimum size to draw this object.