Line data Source code
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 : /****************************************************************************/
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 8099 : GUICompleteSchemeStorage::GUICompleteSchemeStorage() { }
44 :
45 :
46 8099 : GUICompleteSchemeStorage::~GUICompleteSchemeStorage() {
47 45871 : for (auto item : mySettings) {
48 37772 : delete item.second;
49 : }
50 8099 : }
51 :
52 :
53 :
54 : void
55 37772 : GUICompleteSchemeStorage::add(const GUIVisualizationSettings& scheme) {
56 : std::string name = scheme.name;
57 37772 : if (std::find(mySortedSchemeNames.begin(), mySortedSchemeNames.end(), name) == mySortedSchemeNames.end()) {
58 37772 : mySortedSchemeNames.push_back(name);
59 : }
60 37772 : GUIVisualizationSettings* s = new GUIVisualizationSettings(name);
61 37772 : s->copy(scheme);
62 37772 : mySettings[name] = s;
63 37772 : }
64 :
65 :
66 : GUIVisualizationSettings&
67 32 : GUICompleteSchemeStorage::get(const std::string& name) {
68 32 : return *mySettings.find(name)->second;
69 : }
70 :
71 :
72 : GUIVisualizationSettings&
73 7103 : GUICompleteSchemeStorage::getDefault() {
74 7103 : return *mySettings.find(myDefaultSettingName)->second;
75 : }
76 :
77 :
78 : bool
79 7151 : GUICompleteSchemeStorage::contains(const std::string& name) const {
80 7151 : return mySettings.find(name) != mySettings.end();
81 : }
82 :
83 :
84 : void
85 0 : GUICompleteSchemeStorage::remove(const std::string name) {
86 0 : if (!contains(name)) {
87 : return;
88 : }
89 0 : mySortedSchemeNames.erase(find(mySortedSchemeNames.begin(), mySortedSchemeNames.end(), name));
90 0 : delete mySettings.find(name)->second;
91 : mySettings.erase(name);
92 : }
93 :
94 :
95 : void
96 7084 : GUICompleteSchemeStorage::setDefault(const std::string& name) {
97 7084 : if (!contains(name)) {
98 : return;
99 : }
100 7084 : myDefaultSettingName = name;
101 : }
102 :
103 :
104 : const std::vector<std::string>&
105 7103 : GUICompleteSchemeStorage::getNames() const {
106 7103 : return mySortedSchemeNames;
107 : }
108 :
109 :
110 : int
111 0 : GUICompleteSchemeStorage::getNumInitialSettings() const {
112 0 : return myNumInitialSettings;
113 : }
114 :
115 :
116 : void
117 7548 : GUICompleteSchemeStorage::init(FXApp* app, bool netedit) {
118 : {
119 7548 : GUIVisualizationSettings vs("standard", netedit);
120 7548 : vs.laneShowBorders = true;
121 7548 : gSchemeStorage.add(vs);
122 7548 : }
123 : {
124 7548 : GUIVisualizationSettings vs("faster standard", netedit);
125 7548 : vs.laneShowBorders = false;
126 7548 : vs.showLinkDecals = false;
127 7548 : vs.showRails = false;
128 : vs.showRails = false;
129 7548 : vs.showSublanes = false;
130 7548 : gSchemeStorage.add(vs);
131 7548 : }
132 : {
133 7548 : GUIVisualizationSettings vs("real world", netedit);
134 7548 : vs.vehicleQuality = 2;
135 7548 : vs.backgroundColor = RGBColor(51, 128, 51, 255);
136 7548 : vs.laneShowBorders = true;
137 7548 : vs.hideConnectors = true;
138 7548 : vs.vehicleSize.minSize = 0;
139 7548 : vs.personQuality = 2;
140 7548 : vs.containerQuality = 2;
141 7548 : vs.showSublanes = false;
142 7548 : gSchemeStorage.add(vs);
143 7548 : }
144 : {
145 7548 : GUIVisualizationSettings vs("rail", netedit);
146 7548 : vs.vehicleQuality = 2;
147 7548 : vs.showLaneDirection = true;
148 7548 : vs.spreadSuperposed = true;
149 7548 : vs.junctionSize.constantSize = true;
150 7548 : vs.junctionColorer.setSchemeByName(GUIVisualizationSettings::SCHEME_NAME_TYPE);
151 7548 : gSchemeStorage.add(vs);
152 7548 : }
153 :
154 7548 : if (!netedit) {
155 15096 : GUIVisualizationSettings vs("selection", netedit);
156 15096 : vs.vehicleColorer.setSchemeByName(GUIVisualizationSettings::SCHEME_NAME_SELECTION);
157 15096 : vs.edgeColorer.setSchemeByName(GUIVisualizationSettings::SCHEME_NAME_SELECTION);
158 15096 : vs.laneColorer.setSchemeByName(GUIVisualizationSettings::SCHEME_NAME_SELECTION);
159 15096 : vs.junctionColorer.setSchemeByName(GUIVisualizationSettings::SCHEME_NAME_SELECTION);
160 15096 : vs.personColorer.setSchemeByName(GUIVisualizationSettings::SCHEME_NAME_SELECTION);
161 15096 : vs.containerColorer.setSchemeByName(GUIVisualizationSettings::SCHEME_NAME_SELECTION);
162 15096 : vs.poiColorer.setSchemeByName(GUIVisualizationSettings::SCHEME_NAME_SELECTION);
163 7548 : vs.polyColorer.setSchemeByName(GUIVisualizationSettings::SCHEME_NAME_SELECTION);
164 7548 : gSchemeStorage.add(vs);
165 7548 : }
166 7548 : myNumInitialSettings = (int) mySortedSchemeNames.size();
167 : // add saved settings
168 7548 : int noSaved = app->reg().readIntEntry("VisualizationSettings", "settingNo", 0);
169 7548 : for (int i = 0; i < noSaved; ++i) {
170 0 : std::string name = "visset#" + toString(i);
171 0 : std::string setting = app->reg().readStringEntry("VisualizationSettings", name.c_str(), "");
172 0 : if (setting != "") {
173 0 : GUIVisualizationSettings vs(setting, netedit);
174 0 : app->reg().readStringEntry("VisualizationSettings", name.c_str(), "");
175 :
176 : // add saved xml setting
177 0 : int xmlSize = app->reg().readIntEntry(name.c_str(), "xmlSize", 0);
178 0 : std::string content = "";
179 0 : int index = 0;
180 0 : while (xmlSize > 0) {
181 0 : std::string part = app->reg().readStringEntry(name.c_str(), ("xml" + toString(index)).c_str(), "");
182 0 : if (part == "") {
183 : break;
184 : }
185 : content += part;
186 0 : xmlSize -= (int) part.size();
187 0 : index++;
188 : }
189 0 : if (content != "" && xmlSize == 0) {
190 : try {
191 0 : GUISettingsHandler handler(content, false, netedit);
192 0 : handler.addSettings();
193 0 : } catch (ProcessError&) { }
194 : }
195 0 : }
196 : }
197 7548 : myDefaultSettingName = mySortedSchemeNames[0];
198 : myLookFrom.set(0, 0, 0);
199 7548 : }
200 :
201 :
202 : void
203 0 : GUICompleteSchemeStorage::writeSettings(FXApp* app) {
204 0 : const std::vector<std::string>& names = getNames();
205 0 : app->reg().writeIntEntry("VisualizationSettings", "settingNo", (FXint) names.size() - myNumInitialSettings);
206 0 : int gidx = 0;
207 0 : for (std::vector<std::string>::const_iterator it = names.begin() + myNumInitialSettings; it != names.end(); ++it, ++gidx) {
208 0 : const GUIVisualizationSettings* item = mySettings.find(*it)->second;
209 0 : std::string sname = "visset#" + toString(gidx);
210 :
211 0 : app->reg().writeStringEntry("VisualizationSettings", sname.c_str(), item->name.c_str());
212 0 : OutputDevice_String dev;
213 0 : item->save(dev);
214 0 : std::string content = dev.getString();
215 0 : app->reg().writeIntEntry(sname.c_str(), "xmlSize", (FXint)(content.size()));
216 : const unsigned maxSize = 1500; // this is a fox limitation for registry entries
217 0 : for (int i = 0; i < (int)content.size(); i += maxSize) {
218 0 : const std::string b = content.substr(i, maxSize);
219 0 : app->reg().writeStringEntry(sname.c_str(), ("xml" + toString(i / maxSize)).c_str(), b.c_str());
220 : }
221 0 : }
222 0 : }
223 :
224 :
225 : void
226 14632 : GUICompleteSchemeStorage::saveViewport(const double x, const double y, const double z, const double rot) {
227 : myLookFrom.set(x, y, z);
228 14632 : myRotation = rot;
229 14632 : }
230 :
231 : void
232 7084 : GUICompleteSchemeStorage::saveDecals(const std::vector<GUISUMOAbstractView::Decal>& decals) {
233 7084 : myDecals = decals;
234 7091 : for (auto& d : myDecals) {
235 7 : d.initialised = false;
236 : }
237 7084 : }
238 :
239 : void
240 7103 : GUICompleteSchemeStorage::setViewport(GUISUMOAbstractView* view) {
241 7103 : if (myLookFrom.z() > 0) {
242 : // look straight down
243 0 : view->setViewportFromToRot(myLookFrom, Position(myLookFrom.x(), myLookFrom.y(), 0), myRotation);
244 : } else {
245 7103 : view->recenterView();
246 : }
247 7103 : }
248 :
249 :
250 : /****************************************************************************/
|