Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/utils/gui/settings/GUICompleteSchemeStorage.cpp
169684 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2025 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
/****************************************************************************/
14
/// @file GUICompleteSchemeStorage.cpp
15
/// @author Daniel Krajzewicz
16
/// @author Jakob Erdmann
17
/// @author Michael Behrisch
18
/// @author Laura Bieker
19
/// @date 2006-01-09
20
///
21
// Storage for available visualization settings
22
/****************************************************************************/
23
#include <config.h>
24
25
#include "GUICompleteSchemeStorage.h"
26
#include <utils/common/ToString.h>
27
#include <utils/common/StringUtils.h>
28
#include <utils/common/RGBColor.h>
29
#include <utils/foxtools/MFXUtils.h>
30
#include <utils/gui/settings/GUISettingsHandler.h>
31
#include <utils/iodevices/OutputDevice_String.h>
32
33
34
// ===========================================================================
35
// static variable definitions
36
// ===========================================================================
37
GUICompleteSchemeStorage gSchemeStorage;
38
39
40
// ===========================================================================
41
// method definitions
42
// ===========================================================================
43
GUICompleteSchemeStorage::GUICompleteSchemeStorage() { }
44
45
46
GUICompleteSchemeStorage::~GUICompleteSchemeStorage() {
47
for (auto item : mySettings) {
48
delete item.second;
49
}
50
}
51
52
53
54
void
55
GUICompleteSchemeStorage::add(const GUIVisualizationSettings& scheme) {
56
std::string name = scheme.name;
57
if (std::find(mySortedSchemeNames.begin(), mySortedSchemeNames.end(), name) == mySortedSchemeNames.end()) {
58
mySortedSchemeNames.push_back(name);
59
}
60
GUIVisualizationSettings* s = new GUIVisualizationSettings(name);
61
s->copy(scheme);
62
mySettings[name] = s;
63
}
64
65
66
GUIVisualizationSettings&
67
GUICompleteSchemeStorage::get(const std::string& name) {
68
return *mySettings.find(name)->second;
69
}
70
71
72
GUIVisualizationSettings&
73
GUICompleteSchemeStorage::getDefault() {
74
return *mySettings.find(myDefaultSettingName)->second;
75
}
76
77
78
bool
79
GUICompleteSchemeStorage::contains(const std::string& name) const {
80
return mySettings.find(name) != mySettings.end();
81
}
82
83
84
void
85
GUICompleteSchemeStorage::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
95
void
96
GUICompleteSchemeStorage::setDefault(const std::string& name) {
97
if (!contains(name)) {
98
return;
99
}
100
myDefaultSettingName = name;
101
}
102
103
104
const std::vector<std::string>&
105
GUICompleteSchemeStorage::getNames() const {
106
return mySortedSchemeNames;
107
}
108
109
110
int
111
GUICompleteSchemeStorage::getNumInitialSettings() const {
112
return myNumInitialSettings;
113
}
114
115
116
void
117
GUICompleteSchemeStorage::init(FXApp* app, bool netedit) {
118
{
119
GUIVisualizationSettings vs("standard", netedit);
120
vs.laneShowBorders = true;
121
gSchemeStorage.add(vs);
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;
130
gSchemeStorage.add(vs);
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;
142
gSchemeStorage.add(vs);
143
}
144
{
145
GUIVisualizationSettings vs("rail", netedit);
146
vs.vehicleQuality = 2;
147
vs.showLaneDirection = true;
148
vs.spreadSuperposed = true;
149
vs.junctionSize.constantSize = true;
150
vs.junctionColorer.setSchemeByName(GUIVisualizationSettings::SCHEME_NAME_TYPE);
151
gSchemeStorage.add(vs);
152
}
153
154
if (!netedit) {
155
GUIVisualizationSettings vs("selection", netedit);
156
vs.vehicleColorer.setSchemeByName(GUIVisualizationSettings::SCHEME_NAME_SELECTION);
157
vs.edgeColorer.setSchemeByName(GUIVisualizationSettings::SCHEME_NAME_SELECTION);
158
vs.laneColorer.setSchemeByName(GUIVisualizationSettings::SCHEME_NAME_SELECTION);
159
vs.junctionColorer.setSchemeByName(GUIVisualizationSettings::SCHEME_NAME_SELECTION);
160
vs.personColorer.setSchemeByName(GUIVisualizationSettings::SCHEME_NAME_SELECTION);
161
vs.containerColorer.setSchemeByName(GUIVisualizationSettings::SCHEME_NAME_SELECTION);
162
vs.poiColorer.setSchemeByName(GUIVisualizationSettings::SCHEME_NAME_SELECTION);
163
vs.polyColorer.setSchemeByName(GUIVisualizationSettings::SCHEME_NAME_SELECTION);
164
gSchemeStorage.add(vs);
165
}
166
myNumInitialSettings = (int) mySortedSchemeNames.size();
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
}
197
myDefaultSettingName = mySortedSchemeNames[0];
198
myLookFrom.set(0, 0, 0);
199
}
200
201
202
void
203
GUICompleteSchemeStorage::writeSettings(FXApp* app) {
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());
212
OutputDevice_String dev;
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
void
232
GUICompleteSchemeStorage::saveDecals(const std::vector<GUISUMOAbstractView::Decal>& decals) {
233
myDecals = decals;
234
for (auto& d : myDecals) {
235
d.initialised = false;
236
}
237
}
238
239
void
240
GUICompleteSchemeStorage::setViewport(GUISUMOAbstractView* view) {
241
if (myLookFrom.z() > 0) {
242
// look straight down
243
view->setViewportFromToRot(myLookFrom, Position(myLookFrom.x(), myLookFrom.y(), 0), myRotation);
244
} else {
245
view->recenterView();
246
}
247
}
248
249
250
/****************************************************************************/
251
252