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 8154 : GUICompleteSchemeStorage::GUICompleteSchemeStorage() { }
44 :
45 :
46 8154 : GUICompleteSchemeStorage::~GUICompleteSchemeStorage() {
47 46176 : for (auto item : mySettings) {
48 38022 : delete item.second;
49 : }
50 8154 : }
51 :
52 :
53 :
54 : void
55 38022 : GUICompleteSchemeStorage::add(const GUIVisualizationSettings& scheme) {
56 : std::string name = scheme.name;
57 38022 : if (std::find(mySortedSchemeNames.begin(), mySortedSchemeNames.end(), name) == mySortedSchemeNames.end()) {
58 38022 : mySortedSchemeNames.push_back(name);
59 : }
60 38022 : GUIVisualizationSettings* s = new GUIVisualizationSettings(name);
61 38022 : s->copy(scheme);
62 38022 : mySettings[name] = s;
63 38022 : }
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 7152 : GUICompleteSchemeStorage::getDefault() {
74 7152 : return *mySettings.find(myDefaultSettingName)->second;
75 : }
76 :
77 :
78 : bool
79 7201 : GUICompleteSchemeStorage::contains(const std::string& name) const {
80 7201 : 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 7134 : GUICompleteSchemeStorage::setDefault(const std::string& name) {
97 7134 : if (!contains(name)) {
98 : return;
99 : }
100 7134 : myDefaultSettingName = name;
101 : }
102 :
103 :
104 : const std::vector<std::string>&
105 7152 : GUICompleteSchemeStorage::getNames() const {
106 7152 : return mySortedSchemeNames;
107 : }
108 :
109 :
110 : int
111 0 : GUICompleteSchemeStorage::getNumInitialSettings() const {
112 0 : return myNumInitialSettings;
113 : }
114 :
115 :
116 : void
117 7598 : GUICompleteSchemeStorage::init(FXApp* app, bool netedit) {
118 : {
119 7598 : GUIVisualizationSettings vs("standard", netedit);
120 7598 : vs.laneShowBorders = true;
121 7598 : gSchemeStorage.add(vs);
122 7598 : }
123 : {
124 7598 : GUIVisualizationSettings vs("faster standard", netedit);
125 7598 : vs.laneShowBorders = false;
126 7598 : vs.showLinkDecals = false;
127 7598 : vs.showRails = false;
128 : vs.showRails = false;
129 7598 : vs.showSublanes = false;
130 7598 : gSchemeStorage.add(vs);
131 7598 : }
132 : {
133 7598 : GUIVisualizationSettings vs("real world", netedit);
134 7598 : vs.vehicleQuality = 2;
135 7598 : vs.backgroundColor = RGBColor(51, 128, 51, 255);
136 7598 : vs.laneShowBorders = true;
137 7598 : vs.hideConnectors = true;
138 7598 : vs.vehicleSize.minSize = 0;
139 7598 : vs.personQuality = 2;
140 7598 : vs.containerQuality = 2;
141 7598 : vs.showSublanes = false;
142 7598 : gSchemeStorage.add(vs);
143 7598 : }
144 : {
145 7598 : GUIVisualizationSettings vs("rail", netedit);
146 7598 : vs.vehicleQuality = 2;
147 7598 : vs.showLaneDirection = true;
148 7598 : vs.spreadSuperposed = true;
149 7598 : vs.junctionSize.constantSize = true;
150 7598 : vs.junctionColorer.setSchemeByName(GUIVisualizationSettings::SCHEME_NAME_TYPE);
151 7598 : gSchemeStorage.add(vs);
152 7598 : }
153 :
154 7598 : if (!netedit) {
155 15196 : GUIVisualizationSettings vs("selection", netedit);
156 15196 : vs.vehicleColorer.setSchemeByName(GUIVisualizationSettings::SCHEME_NAME_SELECTION);
157 15196 : vs.edgeColorer.setSchemeByName(GUIVisualizationSettings::SCHEME_NAME_SELECTION);
158 15196 : vs.laneColorer.setSchemeByName(GUIVisualizationSettings::SCHEME_NAME_SELECTION);
159 15196 : vs.junctionColorer.setSchemeByName(GUIVisualizationSettings::SCHEME_NAME_SELECTION);
160 15196 : vs.personColorer.setSchemeByName(GUIVisualizationSettings::SCHEME_NAME_SELECTION);
161 15196 : vs.containerColorer.setSchemeByName(GUIVisualizationSettings::SCHEME_NAME_SELECTION);
162 15196 : vs.poiColorer.setSchemeByName(GUIVisualizationSettings::SCHEME_NAME_SELECTION);
163 7598 : vs.polyColorer.setSchemeByName(GUIVisualizationSettings::SCHEME_NAME_SELECTION);
164 7598 : gSchemeStorage.add(vs);
165 7598 : }
166 7598 : myNumInitialSettings = (int) mySortedSchemeNames.size();
167 : // add saved settings
168 7598 : int noSaved = app->reg().readIntEntry("VisualizationSettings", "settingNo", 0);
169 7598 : 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 7598 : myDefaultSettingName = mySortedSchemeNames[0];
198 : myLookFrom.set(0, 0, 0);
199 7598 : }
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 14732 : GUICompleteSchemeStorage::saveViewport(const double x, const double y, const double z, const double rot) {
227 : myLookFrom.set(x, y, z);
228 14732 : myRotation = rot;
229 14732 : }
230 :
231 : void
232 7134 : GUICompleteSchemeStorage::saveDecals(const std::vector<GUISUMOAbstractView::Decal>& decals) {
233 7134 : myDecals = decals;
234 7141 : for (auto& d : myDecals) {
235 7 : d.initialised = false;
236 : }
237 7134 : }
238 :
239 : void
240 7152 : GUICompleteSchemeStorage::setViewport(GUISUMOAbstractView* view) {
241 7152 : if (myLookFrom.z() > 0) {
242 : // look straight down
243 0 : view->setViewportFromToRot(myLookFrom, Position(myLookFrom.x(), myLookFrom.y(), 0), myRotation);
244 : } else {
245 7152 : view->recenterView();
246 : }
247 7152 : }
248 :
249 :
250 : /****************************************************************************/
|