Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
GUICompleteSchemeStorage.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2024 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
32
33
34// ===========================================================================
35// static variable definitions
36// ===========================================================================
38
39
40// ===========================================================================
41// method definitions
42// ===========================================================================
44
45
47 for (auto item : mySettings) {
48 delete item.second;
49 }
50}
51
52
53
54void
56 std::string name = scheme.name;
57 if (std::find(mySortedSchemeNames.begin(), mySortedSchemeNames.end(), name) == mySortedSchemeNames.end()) {
58 mySortedSchemeNames.push_back(name);
59 }
61 s->copy(scheme);
62 mySettings[name] = s;
63}
64
65
67GUICompleteSchemeStorage::get(const std::string& name) {
68 return *mySettings.find(name)->second;
69}
70
71
76
77
78bool
79GUICompleteSchemeStorage::contains(const std::string& name) const {
80 return mySettings.find(name) != mySettings.end();
81}
82
83
84void
85GUICompleteSchemeStorage::remove(const std::string name) {
86 if (!contains(name)) {
87 return;
88 }
89 mySortedSchemeNames.erase(find(mySortedSchemeNames.begin(), mySortedSchemeNames.end(), name));
90 delete mySettings.find(name)->second;
91 mySettings.erase(name);
92}
93
94
95void
96GUICompleteSchemeStorage::setDefault(const std::string& name) {
97 if (!contains(name)) {
98 return;
99 }
101}
102
103
104const std::vector<std::string>&
108
109
110int
114
115
116void
117GUICompleteSchemeStorage::init(FXApp* app, bool netedit) {
118 {
119 GUIVisualizationSettings vs("standard", netedit);
120 vs.laneShowBorders = true;
122 }
123 {
124 GUIVisualizationSettings vs("faster standard", netedit);
125 vs.laneShowBorders = false;
126 vs.showLinkDecals = false;
127 vs.showRails = false;
128 vs.showRails = false;
129 vs.showSublanes = false;
131 }
132 {
133 GUIVisualizationSettings vs("real world", netedit);
134 vs.vehicleQuality = 2;
135 vs.backgroundColor = RGBColor(51, 128, 51, 255);
136 vs.laneShowBorders = true;
137 vs.hideConnectors = true;
138 vs.vehicleSize.minSize = 0;
139 vs.personQuality = 2;
140 vs.containerQuality = 2;
141 vs.showSublanes = false;
143 }
144 {
145 GUIVisualizationSettings vs("rail", netedit);
146 vs.vehicleQuality = 2;
147 vs.showLaneDirection = true;
148 vs.spreadSuperposed = true;
149 vs.junctionSize.constantSize = true;
152 }
153
154 if (!netedit) {
155 GUIVisualizationSettings vs("selection", netedit);
165 }
167 // add saved settings
168 int noSaved = app->reg().readIntEntry("VisualizationSettings", "settingNo", 0);
169 for (int i = 0; i < noSaved; ++i) {
170 std::string name = "visset#" + toString(i);
171 std::string setting = app->reg().readStringEntry("VisualizationSettings", name.c_str(), "");
172 if (setting != "") {
173 GUIVisualizationSettings vs(setting, netedit);
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
202void
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
225void
226GUICompleteSchemeStorage::saveViewport(const double x, const double y, const double z, const double rot) {
227 myLookFrom.set(x, y, z);
228 myRotation = rot;
229}
230
231void
232GUICompleteSchemeStorage::saveDecals(const std::vector<GUISUMOAbstractView::Decal>& decals) {
233 myDecals = decals;
234 for (auto& d : myDecals) {
235 d.initialised = false;
236 }
237}
238
239void
241 if (myLookFrom.z() > 0) {
242 // look straight down
244 } else {
245 view->recenterView();
246 }
247}
248
249
250/****************************************************************************/
GUICompleteSchemeStorage gSchemeStorage
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.
void remove(const std::string name)
Removes the setting with the given name.
std::map< std::string, GUIVisualizationSettings * > mySettings
A map of settings referenced by their names.
GUIVisualizationSettings & getDefault()
Returns the default scheme.
std::vector< GUISUMOAbstractView::Decal > myDecals
The default decals.
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 saveDecals(const std::vector< GUISUMOAbstractView::Decal > &decals)
Makes the given decals the default.
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 hide 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.
void copy(const GUIVisualizationSettings &s)
copy all content from another GUIVisualizationSettings (note: DON'T USE in DrawGL functions!...
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.