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 GUISettingsHandler.cpp
15 : /// @author Michael Behrisch
16 : /// @author Daniel Krajzewicz
17 : /// @author Jakob Erdmann
18 : /// @author Laura Bieker
19 : /// @author Mirko Barthauer
20 : /// @date Fri, 24. Apr 2009
21 : ///
22 : // The dialog to change the view (gui) settings.
23 : /****************************************************************************/
24 : #include <config.h>
25 :
26 : #include <vector>
27 : #include <utils/common/StringUtils.h>
28 : #include <utils/common/ToString.h>
29 : #include <utils/common/RGBColor.h>
30 : #include <utils/common/MsgHandler.h>
31 : #include <utils/common/FileHelpers.h>
32 : #include <utils/gui/settings/GUIVisualizationSettings.h>
33 : #include <utils/gui/settings/GUICompleteSchemeStorage.h>
34 : #include <utils/gui/windows/GUIPerspectiveChanger.h>
35 : #include <utils/foxtools/MFXImageHelper.h>
36 : #include <utils/xml/SUMOSAXReader.h>
37 : #include <utils/xml/XMLSubSys.h>
38 : #include "GUISettingsHandler.h"
39 :
40 :
41 : // ===========================================================================
42 : // method definitions
43 : // ===========================================================================
44 35 : GUISettingsHandler::GUISettingsHandler(const std::string& content, bool isFile, bool netedit) :
45 : SUMOSAXHandler(content),
46 70 : mySettings("TEMPORARY_NAME", netedit),
47 35 : myDelay(-1), myLookFrom(-1, -1, -1), myLookAt(-1, -1, -1), myZCoordSet(true),
48 35 : myRotation(0),
49 35 : myZoom(-1),
50 35 : myCurrentColorer(SUMO_TAG_NOTHING),
51 35 : myCurrentScheme(nullptr),
52 70 : myJamSoundTime(-1) {
53 35 : if (isFile) {
54 35 : XMLSubSys::runParser(*this, content);
55 : } else {
56 0 : setFileName("registrySettings");
57 0 : SUMOSAXReader* reader = XMLSubSys::getSAXReader(*this);
58 0 : reader->parseString(content);
59 0 : delete reader;
60 : }
61 35 : }
62 :
63 :
64 35 : GUISettingsHandler::~GUISettingsHandler() {
65 70 : }
66 :
67 :
68 : void
69 17306 : GUISettingsHandler::myStartElement(int element, const SUMOSAXAttributes& attrs) {
70 17306 : bool ok = true;
71 17306 : switch (element) {
72 0 : case SUMO_TAG_BREAKPOINT:
73 0 : if (attrs.hasAttribute(SUMO_ATTR_TIME)) {
74 0 : myBreakpoints.push_back(attrs.getSUMOTimeReporting(SUMO_ATTR_TIME, nullptr, ok));
75 : } else {
76 0 : myBreakpoints.push_back(attrs.getSUMOTimeReporting(SUMO_ATTR_VALUE, nullptr, ok));
77 0 : WRITE_WARNING(TL("The 'value' attribute is deprecated for breakpoints. Please use 'time'."));
78 : }
79 : break;
80 : case SUMO_TAG_VIEWSETTINGS:
81 32 : myViewType = attrs.getOpt<std::string>(SUMO_ATTR_TYPE, nullptr, ok, "default");
82 32 : myViewType = StringUtils::to_lower_case(myViewType);
83 32 : break;
84 2 : case SUMO_TAG_VIEWSETTINGS_3D:
85 4 : mySettings.show3DTLSLinkMarkers = StringUtils::toBool(attrs.getStringSecure("show3DTLSLinkMarkers", toString(mySettings.show3DTLSLinkMarkers)));
86 4 : mySettings.show3DTLSDomes = StringUtils::toBool(attrs.getStringSecure("show3DTLSDomes", toString(mySettings.show3DTLSDomes)));
87 4 : mySettings.show3DHeadUpDisplay = StringUtils::toBool(attrs.getStringSecure("show3DHeadUpDisplay", toString(mySettings.show3DHeadUpDisplay)));
88 4 : mySettings.generate3DTLSModels = StringUtils::toBool(attrs.getStringSecure("generate3DTLSModels", toString(mySettings.generate3DTLSModels)));
89 2 : mySettings.ambient3DLight = parseColor(attrs, "ambient3DLight", mySettings.ambient3DLight);
90 2 : mySettings.diffuse3DLight = parseColor(attrs, "diffuse3DLight", mySettings.diffuse3DLight);
91 2 : break;
92 5 : case SUMO_TAG_DELAY:
93 5 : myDelay = attrs.getOpt<double>(SUMO_ATTR_VALUE, nullptr, ok, myDelay);
94 5 : break;
95 6 : case SUMO_TAG_VIEWPORT: {
96 6 : const double x = attrs.getOpt<double>(SUMO_ATTR_X, nullptr, ok, myLookFrom.x());
97 6 : const double y = attrs.getOpt<double>(SUMO_ATTR_Y, nullptr, ok, myLookFrom.y());
98 6 : const double z = attrs.getOpt<double>(SUMO_ATTR_Z, nullptr, ok, myLookFrom.z());
99 6 : attrs.get<double>(SUMO_ATTR_Z, nullptr, myZCoordSet, false);
100 : myLookFrom.set(x, y, z);
101 6 : myZoom = attrs.getOpt<double>(SUMO_ATTR_ZOOM, nullptr, ok, myZoom);
102 6 : const double cx = attrs.getOpt<double>(SUMO_ATTR_CENTER_X, nullptr, ok, myLookFrom.x());
103 6 : const double cy = attrs.getOpt<double>(SUMO_ATTR_CENTER_Y, nullptr, ok, myLookFrom.y());
104 6 : const double cz = attrs.getOpt<double>(SUMO_ATTR_CENTER_Z, nullptr, ok, 0.);
105 : myLookAt.set(cx, cy, cz);
106 6 : myRotation = attrs.getOpt<double>(SUMO_ATTR_ANGLE, nullptr, ok, myRotation);
107 6 : break;
108 : }
109 2 : case SUMO_TAG_SNAPSHOT: {
110 2 : std::string file = attrs.get<std::string>(SUMO_ATTR_FILE, nullptr, ok);
111 2 : if (file != "" && !FileHelpers::isAbsolute(file)) {
112 4 : file = FileHelpers::getConfigurationRelative(getFileName(), file);
113 : }
114 2 : mySnapshots[attrs.getOptSUMOTimeReporting(SUMO_ATTR_TIME, file.c_str(), ok, 0)].push_back(file);
115 : }
116 2 : break;
117 32 : case SUMO_TAG_VIEWSETTINGS_SCHEME: {
118 32 : mySettings.name = attrs.getOpt<std::string>(SUMO_ATTR_NAME, nullptr, ok, mySettings.name);
119 32 : if (gSchemeStorage.contains(mySettings.name)) {
120 0 : mySettings.copy(gSchemeStorage.get(mySettings.name));
121 : }
122 : }
123 : break;
124 32 : case SUMO_TAG_VIEWSETTINGS_OPENGL:
125 64 : mySettings.dither = StringUtils::toBool(attrs.getStringSecure("dither", toString(mySettings.dither)));
126 64 : mySettings.fps = StringUtils::toBool(attrs.getStringSecure("fps", toString(mySettings.fps)));
127 64 : mySettings.trueZ = StringUtils::toBool(attrs.getStringSecure("trueZ", toString(mySettings.trueZ)));
128 64 : mySettings.drawBoundaries = StringUtils::toBool(attrs.getStringSecure("drawBoundaries", toString(mySettings.drawBoundaries)));
129 64 : mySettings.forceDrawForRectangleSelection = StringUtils::toBool(attrs.getStringSecure("forceDrawRectangleSelection", toString(mySettings.forceDrawForRectangleSelection)));
130 64 : mySettings.disableDottedContours = StringUtils::toBool(attrs.getStringSecure("disableDottedContours", toString(mySettings.disableDottedContours)));
131 32 : mySettings.geometryIndices = parseTextSettings("geometryIndices", attrs, mySettings.geometryIndices);
132 32 : break;
133 : case SUMO_TAG_VIEWSETTINGS_BACKGROUND:
134 64 : mySettings.backgroundColor = RGBColor::parseColorReporting(attrs.getStringSecure("backgroundColor", toString(mySettings.backgroundColor)), "background", nullptr, true, ok);
135 64 : mySettings.showGrid = StringUtils::toBool(attrs.getStringSecure("showGrid", toString(mySettings.showGrid)));
136 64 : mySettings.gridXSize = StringUtils::toDouble(attrs.getStringSecure("gridXSize", toString(mySettings.gridXSize)));
137 64 : mySettings.gridYSize = StringUtils::toDouble(attrs.getStringSecure("gridYSize", toString(mySettings.gridYSize)));
138 32 : break;
139 32 : case SUMO_TAG_VIEWSETTINGS_EDGES: {
140 64 : int laneEdgeMode = StringUtils::toInt(attrs.getStringSecure("laneEdgeMode", "0"));
141 64 : int laneEdgeScaleMode = StringUtils::toInt(attrs.getStringSecure("scaleMode", "0"));
142 64 : mySettings.laneShowBorders = StringUtils::toBool(attrs.getStringSecure("laneShowBorders", toString(mySettings.laneShowBorders)));
143 64 : mySettings.showBikeMarkings = StringUtils::toBool(attrs.getStringSecure("showBikeMarkings", toString(mySettings.showBikeMarkings)));
144 64 : mySettings.showLinkDecals = StringUtils::toBool(attrs.getStringSecure("showLinkDecals", toString(mySettings.showLinkDecals)));
145 64 : mySettings.realisticLinkRules = StringUtils::toBool(attrs.getStringSecure("realisticLinkRules", toString(mySettings.realisticLinkRules)));
146 64 : mySettings.showLinkRules = StringUtils::toBool(attrs.getStringSecure("showLinkRules", toString(mySettings.showLinkRules)));
147 64 : mySettings.showRails = StringUtils::toBool(attrs.getStringSecure("showRails", toString(mySettings.showRails)));
148 64 : mySettings.secondaryShape = StringUtils::toBool(attrs.getStringSecure("secondaryShape", toString(mySettings.secondaryShape)));
149 32 : mySettings.edgeName = parseTextSettings("edgeName", attrs, mySettings.edgeName);
150 32 : mySettings.internalEdgeName = parseTextSettings("internalEdgeName", attrs, mySettings.internalEdgeName);
151 32 : mySettings.cwaEdgeName = parseTextSettings("cwaEdgeName", attrs, mySettings.cwaEdgeName);
152 32 : mySettings.streetName = parseTextSettings("streetName", attrs, mySettings.streetName);
153 32 : mySettings.edgeValue = parseTextSettings("edgeValue", attrs, mySettings.edgeValue);
154 32 : mySettings.edgeScaleValue = parseTextSettings("edgeScaleValue", attrs, mySettings.edgeScaleValue);
155 64 : mySettings.hideConnectors = StringUtils::toBool(attrs.getStringSecure("hideConnectors", toString(mySettings.hideConnectors)));
156 64 : mySettings.laneWidthExaggeration = StringUtils::toDouble(attrs.getStringSecure("widthExaggeration", toString(mySettings.laneWidthExaggeration)));
157 64 : mySettings.laneMinSize = StringUtils::toDouble(attrs.getStringSecure("minSize", toString(mySettings.laneMinSize)));
158 64 : mySettings.showLaneDirection = StringUtils::toBool(attrs.getStringSecure("showDirection", toString(mySettings.showLaneDirection)));
159 64 : mySettings.showSublanes = StringUtils::toBool(attrs.getStringSecure("showSublanes", toString(mySettings.showSublanes)));
160 64 : mySettings.spreadSuperposed = StringUtils::toBool(attrs.getStringSecure("spreadSuperposed", toString(mySettings.spreadSuperposed)));
161 64 : mySettings.disableHideByZoom = StringUtils::toBool(attrs.getStringSecure("disableHideByZoom", toString(mySettings.disableHideByZoom)));
162 32 : mySettings.edgeParam = attrs.getStringSecure("edgeParam", mySettings.edgeParam);
163 32 : mySettings.laneParam = attrs.getStringSecure("laneParam", mySettings.laneParam);
164 32 : mySettings.vehicleParam = attrs.getStringSecure("vehicleParam", mySettings.vehicleParam);
165 32 : mySettings.vehicleScaleParam = attrs.getStringSecure("vehicleScaleParam", mySettings.vehicleScaleParam);
166 32 : mySettings.vehicleTextParam = attrs.getStringSecure("vehicleTextParam", mySettings.vehicleTextParam);
167 32 : mySettings.edgeData = attrs.getStringSecure("edgeData", mySettings.edgeData);
168 32 : mySettings.edgeDataID = attrs.getStringSecure("edgeDataID", mySettings.edgeDataID);
169 64 : mySettings.edgeDataScaling = attrs.getStringSecure("edgeDataScaling", mySettings.edgeDataScaling);
170 64 : mySettings.edgeValueRainBow = parseRainbowSettings("edgeValue", attrs, mySettings.edgeValueRainBow);
171 32 : myCurrentColorer = element;
172 : mySettings.edgeColorer.setActive(laneEdgeMode);
173 : mySettings.edgeScaler.setActive(laneEdgeScaleMode);
174 : mySettings.laneColorer.setActive(laneEdgeMode);
175 : mySettings.laneScaler.setActive(laneEdgeScaleMode);
176 : }
177 : break;
178 3044 : case SUMO_TAG_COLORSCHEME: {
179 3044 : myCurrentScheme = nullptr;
180 3044 : myCurrentScaleScheme = nullptr;
181 3044 : const std::string name = attrs.getStringSecure(SUMO_ATTR_NAME, "");
182 3044 : if (myCurrentColorer == SUMO_TAG_VIEWSETTINGS_EDGES) {
183 2824 : if (StringUtils::startsWith(name, "meso:")) {
184 : // see edgeColorer.save() in GUIVisualizationSettings::save
185 800 : myCurrentScheme = mySettings.edgeColorer.getSchemeByName(name.substr(5));
186 : } else {
187 1012 : myCurrentScheme = mySettings.laneColorer.getSchemeByName(name);
188 : }
189 1412 : if (myCurrentScheme == nullptr) {
190 : // legacy: meso schemes without prefix
191 68 : myCurrentScheme = mySettings.edgeColorer.getSchemeByName(name);
192 : }
193 : }
194 3044 : if (myCurrentColorer == SUMO_TAG_VIEWSETTINGS_VEHICLES) {
195 898 : myCurrentScheme = mySettings.vehicleColorer.getSchemeByName(name);
196 : }
197 3044 : if (myCurrentColorer == SUMO_TAG_VIEWSETTINGS_PERSONS) {
198 260 : myCurrentScheme = mySettings.personColorer.getSchemeByName(name);
199 : }
200 3044 : if (myCurrentColorer == SUMO_TAG_VIEWSETTINGS_JUNCTIONS) {
201 102 : myCurrentScheme = mySettings.junctionColorer.getSchemeByName(name);
202 : }
203 3044 : if (myCurrentColorer == SUMO_TAG_VIEWSETTINGS_POIS) {
204 66 : myCurrentScheme = mySettings.poiColorer.getSchemeByName(name);
205 : }
206 3044 : if (myCurrentColorer == SUMO_TAG_VIEWSETTINGS_POLYS) {
207 68 : myCurrentScheme = mySettings.polyColorer.getSchemeByName(name);
208 : }
209 3044 : if (myCurrentScheme && !myCurrentScheme->isFixed()) {
210 1764 : myCurrentScheme->setInterpolated(attrs.getOpt<bool>(SUMO_ATTR_INTERPOLATED, nullptr, ok, false));
211 1764 : myCurrentScheme->clear();
212 : }
213 : }
214 3044 : break;
215 757 : case SUMO_TAG_SCALINGSCHEME: {
216 757 : myCurrentScheme = nullptr;
217 757 : myCurrentScaleScheme = nullptr;
218 757 : const std::string name = attrs.getStringSecure(SUMO_ATTR_NAME, "");
219 757 : if (myCurrentColorer == SUMO_TAG_VIEWSETTINGS_EDGES) {
220 1454 : if (StringUtils::startsWith(name, "meso:")) {
221 : // see edgeScaler.save() in GUIVisualizationSettings::save
222 0 : myCurrentScaleScheme = mySettings.edgeScaler.getSchemeByName(name.substr(5));
223 : } else {
224 727 : myCurrentScaleScheme = mySettings.laneScaler.getSchemeByName(name);
225 : }
226 727 : if (myCurrentScaleScheme == nullptr) {
227 : // legacy: meso schemes without prefix
228 134 : myCurrentScaleScheme = mySettings.edgeScaler.getSchemeByName(name);
229 : }
230 : }
231 757 : if (myCurrentColorer == SUMO_TAG_VIEWSETTINGS_VEHICLES) {
232 30 : myCurrentScaleScheme = mySettings.vehicleScaler.getSchemeByName(name);
233 : }
234 757 : if (myCurrentScaleScheme && !myCurrentScaleScheme->isFixed()) {
235 661 : myCurrentScaleScheme->setInterpolated(attrs.getOpt<bool>(SUMO_ATTR_INTERPOLATED, nullptr, ok, false));
236 661 : myCurrentScaleScheme->clear();
237 : }
238 : }
239 757 : break;
240 12915 : case SUMO_TAG_ENTRY:
241 12915 : if (myCurrentScheme != nullptr) {
242 10476 : RGBColor color = attrs.get<RGBColor>(SUMO_ATTR_COLOR, nullptr, ok);
243 10476 : if (myCurrentScheme->isFixed()) {
244 3940 : myCurrentScheme->setColor(attrs.getStringSecure(SUMO_ATTR_NAME, ""), color);
245 : } else {
246 8506 : myCurrentScheme->addColor(color,
247 : attrs.getOpt<double>(SUMO_ATTR_THRESHOLD, nullptr, ok, std::numeric_limits<double>::max()),
248 17012 : attrs.getStringSecure(SUMO_ATTR_NAME, ""));
249 : }
250 2439 : } else if (myCurrentScaleScheme != nullptr) {
251 1729 : double scale = attrs.get<double>(SUMO_ATTR_COLOR, nullptr, ok);
252 1729 : if (myCurrentScaleScheme->isFixed()) {
253 280 : myCurrentScaleScheme->setColor(attrs.getStringSecure(SUMO_ATTR_NAME, ""), scale);
254 : } else {
255 1589 : myCurrentScaleScheme->addColor(scale,
256 : attrs.getOpt<double>(SUMO_ATTR_THRESHOLD, nullptr, ok, std::numeric_limits<double>::max()),
257 3178 : attrs.getStringSecure(SUMO_ATTR_NAME, ""));
258 : }
259 : }
260 : break;
261 32 : case SUMO_TAG_VIEWSETTINGS_VEHICLES:
262 64 : mySettings.vehicleColorer.setActive(StringUtils::toInt(attrs.getStringSecure("vehicleMode", "0")));
263 64 : mySettings.vehicleScaler.setActive(StringUtils::toInt(attrs.getStringSecure("vehicleScaleMode", "0")));
264 64 : mySettings.vehicleQuality = StringUtils::toInt(attrs.getStringSecure("vehicleQuality", toString(mySettings.vehicleQuality)));
265 64 : mySettings.showBlinker = StringUtils::toBool(attrs.getStringSecure("showBlinker", toString(mySettings.showBlinker)));
266 64 : mySettings.drawMinGap = StringUtils::toBool(attrs.getStringSecure("drawMinGap", toString(mySettings.drawMinGap)));
267 64 : mySettings.drawBrakeGap = StringUtils::toBool(attrs.getStringSecure("drawBrakeGap", toString(mySettings.drawBrakeGap)));
268 64 : mySettings.showBTRange = StringUtils::toBool(attrs.getStringSecure("showBTRange", toString(mySettings.showBTRange)));
269 64 : mySettings.showRouteIndex = StringUtils::toBool(attrs.getStringSecure("showRouteIndex", toString(mySettings.showRouteIndex)));
270 64 : mySettings.scaleLength = StringUtils::toBool(attrs.getStringSecure("scaleLength", toString(mySettings.scaleLength)));
271 64 : mySettings.drawReversed = StringUtils::toBool(attrs.getStringSecure("drawReversed", toString(mySettings.drawReversed)));
272 64 : mySettings.showParkingInfo = StringUtils::toBool(attrs.getStringSecure("showParkingInfo", toString(mySettings.showParkingInfo)));
273 64 : mySettings.showChargingInfo = StringUtils::toBool(attrs.getStringSecure("showChargingInfo", toString(mySettings.showChargingInfo)));
274 32 : mySettings.vehicleSize = parseSizeSettings("vehicle", attrs, mySettings.vehicleSize);
275 32 : mySettings.vehicleName = parseTextSettings("vehicleName", attrs, mySettings.vehicleName);
276 32 : mySettings.vehicleValue = parseTextSettings("vehicleValue", attrs, mySettings.vehicleValue);
277 32 : mySettings.vehicleScaleValue = parseTextSettings("vehicleScaleValue", attrs, mySettings.vehicleScaleValue);
278 32 : mySettings.vehicleText = parseTextSettings("vehicleText", attrs, mySettings.vehicleText);
279 32 : myCurrentColorer = element;
280 32 : break;
281 24 : case SUMO_TAG_VIEWSETTINGS_PERSONS:
282 48 : mySettings.personColorer.setActive(StringUtils::toInt(attrs.getStringSecure("personMode", "0")));
283 48 : mySettings.personQuality = StringUtils::toInt(attrs.getStringSecure("personQuality", toString(mySettings.personQuality)));
284 24 : mySettings.personSize = parseSizeSettings("person", attrs, mySettings.personSize);
285 24 : mySettings.personName = parseTextSettings("personName", attrs, mySettings.personName);
286 24 : mySettings.personValue = parseTextSettings("personValue", attrs, mySettings.personValue);
287 48 : mySettings.showPedestrianNetwork = StringUtils::toBool(attrs.getStringSecure("showPedestrianNetwork", toString(mySettings.showPedestrianNetwork)));
288 48 : mySettings.pedestrianNetworkColor = RGBColor::parseColorReporting(attrs.getStringSecure("pedestrianNetworkColor", toString(mySettings.pedestrianNetworkColor)), "pedestrianNetworkColor", nullptr, true, ok);
289 24 : myCurrentColorer = element;
290 24 : break;
291 24 : case SUMO_TAG_VIEWSETTINGS_CONTAINERS:
292 48 : mySettings.containerColorer.setActive(StringUtils::toInt(attrs.getStringSecure("containerMode", "0")));
293 48 : mySettings.containerQuality = StringUtils::toInt(attrs.getStringSecure("containerQuality", toString(mySettings.containerQuality)));
294 24 : mySettings.containerSize = parseSizeSettings("container", attrs, mySettings.containerSize);
295 24 : mySettings.containerName = parseTextSettings("containerName", attrs, mySettings.containerName);
296 24 : myCurrentColorer = element;
297 24 : break;
298 32 : case SUMO_TAG_VIEWSETTINGS_JUNCTIONS:
299 64 : mySettings.junctionColorer.setActive(StringUtils::toInt(attrs.getStringSecure("junctionMode", "0")));
300 32 : mySettings.drawLinkTLIndex = parseTextSettings("drawLinkTLIndex", attrs, mySettings.drawLinkTLIndex);
301 32 : mySettings.drawLinkJunctionIndex = parseTextSettings("drawLinkJunctionIndex", attrs, mySettings.drawLinkJunctionIndex);
302 32 : mySettings.junctionID = parseTextSettings("junctionID", attrs, mySettings.junctionID);
303 32 : mySettings.junctionName = parseTextSettings("junctionName", attrs, mySettings.junctionName);
304 32 : mySettings.internalJunctionName = parseTextSettings("internalJunctionName", attrs, mySettings.internalJunctionName);
305 32 : mySettings.tlsPhaseIndex = parseTextSettings("tlsPhaseIndex", attrs, mySettings.tlsPhaseIndex);
306 32 : mySettings.tlsPhaseName = parseTextSettings("tlsPhaseName", attrs, mySettings.tlsPhaseName);
307 64 : mySettings.showLane2Lane = StringUtils::toBool(attrs.getStringSecure("showLane2Lane", toString(mySettings.showLane2Lane)));
308 64 : mySettings.drawJunctionShape = StringUtils::toBool(attrs.getStringSecure("drawShape", toString(mySettings.drawJunctionShape)));
309 64 : mySettings.drawCrossingsAndWalkingareas = StringUtils::toBool(attrs.getStringSecure(
310 32 : "drawCrossingsAndWalkingareas", toString(mySettings.drawCrossingsAndWalkingareas)));
311 32 : mySettings.junctionSize = parseSizeSettings("junction", attrs, mySettings.junctionSize);
312 64 : mySettings.junctionValueRainBow = parseRainbowSettings("junctionValue", attrs, mySettings.junctionValueRainBow);
313 32 : myCurrentColorer = element;
314 32 : break;
315 32 : case SUMO_TAG_VIEWSETTINGS_ADDITIONALS:
316 64 : mySettings.addMode = StringUtils::toInt(attrs.getStringSecure("addMode", toString(mySettings.addMode)));
317 32 : mySettings.addSize = parseSizeSettings("add", attrs, mySettings.addSize);
318 32 : mySettings.addName = parseTextSettings("addName", attrs, mySettings.addName);
319 32 : mySettings.addFullName = parseTextSettings("addFullName", attrs, mySettings.addFullName);
320 : // color settings (temporal, will be integrated in a schema
321 32 : mySettings.colorSettings.busStopColorSign = parseColor(attrs, "busStopColorSign", mySettings.colorSettings.busStopColorSign);
322 32 : mySettings.colorSettings.chargingStationColor = parseColor(attrs, "chargingStationColor", mySettings.colorSettings.chargingStationColor);
323 32 : mySettings.colorSettings.chargingStationColorCharge = parseColor(attrs, "chargingStationColorCharge", mySettings.colorSettings.chargingStationColorCharge);
324 32 : mySettings.colorSettings.chargingStationColorSign = parseColor(attrs, "chargingStationColorSign", mySettings.colorSettings.chargingStationColorSign);
325 32 : mySettings.colorSettings.containerStopColor = parseColor(attrs, "containerStopColor", mySettings.colorSettings.containerStopColor);
326 32 : mySettings.colorSettings.containerStopColorSign = parseColor(attrs, "containerStopColorSign", mySettings.colorSettings.containerStopColorSign);
327 32 : mySettings.colorSettings.parkingAreaColor = parseColor(attrs, "parkingAreaColor", mySettings.colorSettings.parkingAreaColor);
328 32 : mySettings.colorSettings.parkingAreaColorSign = parseColor(attrs, "parkingAreaColorSign", mySettings.colorSettings.parkingAreaColorSign);
329 32 : mySettings.colorSettings.parkingSpaceColor = parseColor(attrs, "parkingSpaceColor", mySettings.colorSettings.parkingSpaceColor);
330 32 : mySettings.colorSettings.parkingSpaceColorContour = parseColor(attrs, "parkingSpaceColorContour", mySettings.colorSettings.parkingSpaceColorContour);
331 32 : mySettings.colorSettings.personTripColor = parseColor(attrs, "personTripColor", mySettings.colorSettings.personTripColor);
332 32 : mySettings.colorSettings.rideColor = parseColor(attrs, "rideColor", mySettings.colorSettings.rideColor);
333 32 : mySettings.colorSettings.selectedAdditionalColor = parseColor(attrs, "selectedAdditionalColor", mySettings.colorSettings.selectedAdditionalColor);
334 32 : mySettings.colorSettings.selectedConnectionColor = parseColor(attrs, "selectedConnectionColor", mySettings.colorSettings.selectedConnectionColor);
335 32 : mySettings.colorSettings.selectedContainerColor = parseColor(attrs, "selectedContainerColor", mySettings.colorSettings.selectedContainerColor);
336 32 : mySettings.colorSettings.selectedContainerPlanColor = parseColor(attrs, "selectedContainerPlanColor", mySettings.colorSettings.selectedContainerPlanColor);
337 32 : mySettings.colorSettings.selectedCrossingColor = parseColor(attrs, "selectedCrossingColor", mySettings.colorSettings.selectedCrossingColor);
338 32 : mySettings.colorSettings.selectedEdgeColor = parseColor(attrs, "selectedEdgeColor", mySettings.colorSettings.selectedEdgeColor);
339 32 : mySettings.colorSettings.selectedEdgeDataColor = parseColor(attrs, "selectedEdgeDataColor", mySettings.colorSettings.selectedEdgeDataColor);
340 32 : mySettings.colorSettings.selectedLaneColor = parseColor(attrs, "selectedLaneColor", mySettings.colorSettings.selectedLaneColor);
341 32 : mySettings.colorSettings.selectedPersonColor = parseColor(attrs, "selectedPersonColor", mySettings.colorSettings.selectedPersonColor);
342 32 : mySettings.colorSettings.selectedPersonPlanColor = parseColor(attrs, "selectedPersonPlanColor", mySettings.colorSettings.selectedPersonPlanColor);
343 32 : mySettings.colorSettings.selectedProhibitionColor = parseColor(attrs, "selectedProhibitionColor", mySettings.colorSettings.selectedProhibitionColor);
344 32 : mySettings.colorSettings.selectedRouteColor = parseColor(attrs, "selectedRouteColor", mySettings.colorSettings.selectedRouteColor);
345 32 : mySettings.colorSettings.selectedVehicleColor = parseColor(attrs, "selectedVehicleColor", mySettings.colorSettings.selectedVehicleColor);
346 32 : mySettings.colorSettings.selectionColor = parseColor(attrs, "selectionColor", mySettings.colorSettings.selectionColor);
347 32 : mySettings.colorSettings.stopColor = parseColor(attrs, "stopColor", mySettings.colorSettings.stopColor);
348 32 : mySettings.colorSettings.waypointColor = parseColor(attrs, "waypointColor", mySettings.colorSettings.waypointColor);
349 32 : mySettings.colorSettings.stopContainerColor = parseColor(attrs, "stopContainerColor", mySettings.colorSettings.stopContainerColor);
350 32 : mySettings.colorSettings.stopPersonColor = parseColor(attrs, "stopPersonColor", mySettings.colorSettings.stopPersonColor);
351 32 : mySettings.colorSettings.trainStopColor = parseColor(attrs, "trainStopColor", mySettings.colorSettings.trainStopColor);
352 32 : mySettings.colorSettings.trainStopColorSign = parseColor(attrs, "trainStopColorSign", mySettings.colorSettings.trainStopColorSign);
353 32 : mySettings.colorSettings.transhipColor = parseColor(attrs, "transhipColor", mySettings.colorSettings.transhipColor);
354 32 : mySettings.colorSettings.transportColor = parseColor(attrs, "transportColor", mySettings.colorSettings.transportColor);
355 32 : mySettings.colorSettings.vehicleTripColor = parseColor(attrs, "vehicleTripColor", mySettings.colorSettings.vehicleTripColor);
356 32 : mySettings.colorSettings.walkColor = parseColor(attrs, "walkColor", mySettings.colorSettings.walkColor);
357 64 : mySettings.widthSettings.personTripWidth = StringUtils::toDouble(attrs.getStringSecure("personTripWidth", toString(mySettings.widthSettings.personTripWidth)));
358 64 : mySettings.widthSettings.rideWidth = StringUtils::toDouble(attrs.getStringSecure("rideWidth", toString(mySettings.widthSettings.rideWidth)));
359 64 : mySettings.widthSettings.transhipWidth = StringUtils::toDouble(attrs.getStringSecure("transhipWidth", toString(mySettings.widthSettings.transhipWidth)));
360 64 : mySettings.widthSettings.transportWidth = StringUtils::toDouble(attrs.getStringSecure("transportWidth", toString(mySettings.widthSettings.transportWidth)));
361 64 : mySettings.widthSettings.tripWidth = StringUtils::toDouble(attrs.getStringSecure("tripWidth", toString(mySettings.widthSettings.tripWidth)));
362 64 : mySettings.widthSettings.walkWidth = StringUtils::toDouble(attrs.getStringSecure("walkWidth", toString(mySettings.widthSettings.walkWidth)));
363 32 : mySettings.colorSettings.busStopColor = parseColor(attrs, "busStopColor", mySettings.colorSettings.busStopColor);
364 32 : break;
365 32 : case SUMO_TAG_VIEWSETTINGS_POIS:
366 32 : mySettings.poiTextParam = attrs.getStringSecure("poiTextParam", mySettings.poiTextParam);
367 32 : mySettings.poiSize = parseSizeSettings("poi", attrs, mySettings.poiSize);
368 64 : mySettings.poiDetail = StringUtils::toInt(attrs.getStringSecure("poiDetail", toString(mySettings.poiDetail)));
369 32 : mySettings.poiName = parseTextSettings("poiName", attrs, mySettings.poiName);
370 32 : mySettings.poiType = parseTextSettings("poiType", attrs, mySettings.poiType);
371 32 : mySettings.poiText = parseTextSettings("poiText", attrs, mySettings.poiText);
372 64 : mySettings.poiColorer.setActive(StringUtils::toInt(attrs.getStringSecure("personMode", "0")));
373 64 : mySettings.poiUseCustomLayer = StringUtils::toBool(attrs.getStringSecure("poiUseCustomLayer", toString(mySettings.poiUseCustomLayer)));
374 64 : mySettings.poiCustomLayer = StringUtils::toDouble(attrs.getStringSecure("poiCustomLayer", toString(mySettings.poiCustomLayer)));
375 32 : myCurrentColorer = element;
376 32 : break;
377 : case SUMO_TAG_VIEWSETTINGS_POLYS:
378 28 : mySettings.polySize = parseSizeSettings("poly", attrs, mySettings.polySize);
379 28 : mySettings.polyName = parseTextSettings("polyName", attrs, mySettings.polyName);
380 28 : mySettings.polyType = parseTextSettings("polyType", attrs, mySettings.polyType);
381 56 : mySettings.polyColorer.setActive(StringUtils::toInt(attrs.getStringSecure("personMode", "0")));
382 56 : mySettings.polyUseCustomLayer = StringUtils::toBool(attrs.getStringSecure("polyUseCustomLayer", toString(mySettings.polyUseCustomLayer)));
383 56 : mySettings.polyCustomLayer = StringUtils::toDouble(attrs.getStringSecure("polyCustomLayer", toString(mySettings.polyCustomLayer)));
384 28 : myCurrentColorer = element;
385 28 : break;
386 32 : case SUMO_TAG_VIEWSETTINGS_LEGEND:
387 64 : mySettings.showSizeLegend = StringUtils::toBool(attrs.getStringSecure("showSizeLegend", toString(mySettings.showSizeLegend)));
388 64 : mySettings.showColorLegend = StringUtils::toBool(attrs.getStringSecure("showColorLegend", toString(mySettings.showColorLegend)));
389 64 : mySettings.showVehicleColorLegend = StringUtils::toBool(attrs.getStringSecure("showVehicleColorLegend", toString(mySettings.showVehicleColorLegend)));
390 32 : break;
391 : case SUMO_TAG_VIEWSETTINGS_DECAL: {
392 : GUISUMOAbstractView::Decal d;
393 7 : if (attrs.hasAttribute(SUMO_ATTR_FILE)) {
394 12 : d.filename = StringUtils::substituteEnvironment(attrs.get<std::string>(SUMO_ATTR_FILE, nullptr, ok));
395 : } else {
396 1 : d.filename = attrs.getStringSecure("filename", d.filename);
397 2 : WRITE_WARNING(TL("The 'filename' attribute is deprecated for decals. Please use 'file'."));
398 : }
399 7 : if (d.filename != "" && !FileHelpers::isAbsolute(d.filename)) {
400 14 : d.filename = FileHelpers::getConfigurationRelative(getFileName(), d.filename);
401 : }
402 7 : d.centerX = attrs.getOpt<double>(SUMO_ATTR_CENTER_X, nullptr, ok, d.centerX);
403 7 : d.centerY = attrs.getOpt<double>(SUMO_ATTR_CENTER_Y, nullptr, ok, d.centerY);
404 7 : d.centerZ = attrs.getOpt<double>(SUMO_ATTR_CENTER_Z, nullptr, ok, d.centerZ);
405 7 : d.width = attrs.getOpt<double>(SUMO_ATTR_WIDTH, nullptr, ok, d.width);
406 7 : d.height = attrs.getOpt<double>(SUMO_ATTR_HEIGHT, nullptr, ok, d.height);
407 14 : d.altitude = StringUtils::toDouble(attrs.getStringSecure("altitude", "0"));
408 14 : d.rot = StringUtils::toDouble(attrs.getStringSecure("rotation", toString(d.rot)));
409 14 : d.tilt = StringUtils::toDouble(attrs.getStringSecure("tilt", toString(d.tilt)));
410 14 : d.roll = StringUtils::toDouble(attrs.getStringSecure("roll", toString(d.roll)));
411 7 : d.layer = attrs.getOpt<double>(SUMO_ATTR_LAYER, nullptr, ok, d.layer);
412 14 : d.screenRelative = StringUtils::toBool(attrs.getStringSecure("screenRelative", toString(d.screenRelative)));
413 7 : d.initialised = false;
414 7 : myDecals.push_back(d);
415 : }
416 7 : break;
417 : case SUMO_TAG_VIEWSETTINGS_LIGHT: {
418 : GUISUMOAbstractView::Decal d;
419 0 : d.filename = "light" + attrs.getOpt<std::string>(SUMO_ATTR_INDEX, nullptr, ok, "0");
420 0 : d.centerX = attrs.getOpt<double>(SUMO_ATTR_CENTER_X, nullptr, ok, d.centerX);
421 0 : d.centerY = attrs.getOpt<double>(SUMO_ATTR_CENTER_Y, nullptr, ok, d.centerY);
422 0 : d.centerZ = attrs.getOpt<double>(SUMO_ATTR_CENTER_Z, nullptr, ok, d.centerZ);
423 0 : d.width = attrs.getOpt<double>(SUMO_ATTR_WIDTH, nullptr, ok, d.width);
424 0 : d.height = attrs.getOpt<double>(SUMO_ATTR_HEIGHT, nullptr, ok, d.height);
425 0 : d.altitude = StringUtils::toDouble(attrs.getStringSecure("altitude", "0"));
426 0 : d.rot = StringUtils::toDouble(attrs.getStringSecure("rotation", toString(d.rot)));
427 0 : d.tilt = StringUtils::toDouble(attrs.getStringSecure("tilt", toString(d.tilt)));
428 0 : d.roll = StringUtils::toDouble(attrs.getStringSecure("roll", toString(d.roll)));
429 0 : d.layer = attrs.getOpt<double>(SUMO_ATTR_LAYER, nullptr, ok, d.layer);
430 0 : d.initialised = false;
431 0 : myDecals.push_back(d);
432 : }
433 0 : break;
434 0 : case SUMO_TAG_VIEWSETTINGS_EVENT: {
435 0 : const std::string id = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
436 0 : const std::string cmd = attrs.get<std::string>(SUMO_ATTR_COMMAND, nullptr, ok);
437 0 : const double prob = attrs.get<double>(SUMO_ATTR_PROB, id.c_str(), ok);
438 0 : myEventDistributions[id].add(cmd, prob);
439 : }
440 0 : break;
441 0 : case SUMO_TAG_VIEWSETTINGS_EVENT_JAM_TIME:
442 0 : myJamSoundTime = attrs.get<double>(SUMO_ATTR_VALUE, nullptr, ok);
443 0 : break;
444 : default:
445 : break;
446 : }
447 17306 : }
448 :
449 : void
450 17306 : GUISettingsHandler::myEndElement(int element) {
451 17306 : switch (element) {
452 32 : case SUMO_TAG_VIEWSETTINGS_SCHEME: {
453 32 : if (mySettings.name != "") {
454 32 : gSchemeStorage.add(mySettings);
455 32 : myLoadedSettingNames.push_back(mySettings.name);
456 : }
457 : }
458 : }
459 17306 : }
460 :
461 :
462 : RGBColor
463 1188 : GUISettingsHandler::parseColor(const SUMOSAXAttributes& attrs, const std::string attribute, const RGBColor& defaultValue) const {
464 1188 : bool ok = true;
465 2376 : return RGBColor::parseColorReporting(attrs.getStringSecure(attribute, toString(defaultValue)), attribute.c_str(), nullptr, true, ok);
466 : }
467 :
468 :
469 : GUIVisualizationTextSettings
470 864 : GUISettingsHandler::parseTextSettings(
471 : const std::string& prefix, const SUMOSAXAttributes& attrs,
472 : GUIVisualizationTextSettings defaults) {
473 864 : bool ok = true;
474 : return GUIVisualizationTextSettings(
475 1728 : StringUtils::toBool(attrs.getStringSecure(prefix + "_show", toString(defaults.showText))),
476 1728 : StringUtils::toDouble(attrs.getStringSecure(prefix + "_size", toString(defaults.size))),
477 1728 : RGBColor::parseColorReporting(attrs.getStringSecure(prefix + "_color", toString(defaults.color)), "textSettings", nullptr, true, ok),
478 1728 : RGBColor::parseColorReporting(attrs.getStringSecure(prefix + "_bgColor", toString(defaults.bgColor)), "textSettings", nullptr, true, ok),
479 1728 : StringUtils::toBool(attrs.getStringSecure(prefix + "_constantSize", toString(defaults.constSize))),
480 7776 : StringUtils::toBool(attrs.getStringSecure(prefix + "_onlySelected", toString(defaults.onlySelected))));
481 : }
482 :
483 :
484 : GUIVisualizationSizeSettings
485 204 : GUISettingsHandler::parseSizeSettings(
486 : const std::string& prefix, const SUMOSAXAttributes& attrs,
487 : GUIVisualizationSizeSettings defaults) {
488 : return GUIVisualizationSizeSettings(
489 408 : StringUtils::toDouble(attrs.getStringSecure(prefix + "_minSize", toString(defaults.minSize))),
490 408 : StringUtils::toDouble(attrs.getStringSecure(prefix + "_exaggeration", toString(defaults.exaggeration))),
491 408 : StringUtils::toBool(attrs.getStringSecure(prefix + "_constantSize", toString(defaults.constantSize))),
492 1020 : StringUtils::toBool(attrs.getStringSecure(prefix + "_constantSizeSelected", toString(defaults.constantSizeSelected))));
493 : }
494 :
495 : GUIVisualizationRainbowSettings
496 64 : GUISettingsHandler::parseRainbowSettings(
497 : const std::string& prefix, const SUMOSAXAttributes& attrs,
498 : GUIVisualizationRainbowSettings defaults) {
499 : return GUIVisualizationRainbowSettings(
500 128 : StringUtils::toBool(attrs.getStringSecure(prefix + "HideCheck", toString(defaults.hideMin))),
501 128 : StringUtils::toDouble(attrs.getStringSecure(prefix + "HideThreshold", toString(defaults.minThreshold))),
502 128 : StringUtils::toBool(attrs.getStringSecure(prefix + "HideCheck2", toString(defaults.hideMax))),
503 128 : StringUtils::toDouble(attrs.getStringSecure(prefix + "HideThreshold2", toString(defaults.maxThreshold))),
504 128 : StringUtils::toBool(attrs.getStringSecure(prefix + "SetNeutral", toString(defaults.hideMax))),
505 128 : StringUtils::toDouble(attrs.getStringSecure(prefix + "NeutralThreshold", toString(defaults.neutralThreshold))),
506 512 : StringUtils::toBool(attrs.getStringSecure(prefix + "FixRange", toString(defaults.fixRange))));
507 : }
508 :
509 : const std::vector<std::string>&
510 0 : GUISettingsHandler::addSettings(GUISUMOAbstractView* view) const {
511 0 : if (view) {
512 0 : for (std::string name : myLoadedSettingNames) {
513 0 : FXint index = view->getColoringSchemesCombo()->appendIconItem(name.c_str());
514 0 : view->getColoringSchemesCombo()->setCurrentItem(index);
515 0 : view->setColorScheme(name);
516 : }
517 : }
518 0 : return myLoadedSettingNames;
519 : }
520 :
521 :
522 : void
523 35 : GUISettingsHandler::applyViewport(GUISUMOAbstractView* view) const {
524 35 : if (myLookFrom.z() > 0 || myZoom > 0) {
525 : // z value stores zoom so we must convert first
526 6 : double z = (view->is3DView()) ? myLookFrom.z() : view->getChanger().zoom2ZPos(myZoom);
527 6 : if (view->is3DView() && !myZCoordSet) { // set view angle to ground to at least 45 degrees if no Z coordinate is given
528 0 : z = myLookFrom.distanceTo2D(myLookAt) * sin(PI * 0.25);
529 : }
530 : Position lookFrom(myLookFrom.x(), myLookFrom.y(), z);
531 6 : view->setViewportFromToRot(lookFrom, myLookAt, myRotation);
532 6 : if (view->is3DView() && !myZCoordSet) {
533 0 : view->recenterView();
534 : }
535 : }
536 35 : }
537 :
538 :
539 : void
540 35 : GUISettingsHandler::setSnapshots(GUISUMOAbstractView* view) const {
541 35 : if (!mySnapshots.empty()) {
542 2 : for (auto item : mySnapshots) {
543 3 : for (auto file : item.second) {
544 2 : view->addSnapshot(item.first, file);
545 : }
546 : }
547 : }
548 35 : }
549 :
550 :
551 : bool
552 0 : GUISettingsHandler::hasDecals() const {
553 0 : return !myDecals.empty();
554 : }
555 :
556 :
557 : const std::vector<GUISUMOAbstractView::Decal>&
558 35 : GUISettingsHandler::getDecals() const {
559 35 : return myDecals;
560 : }
561 :
562 :
563 : double
564 40 : GUISettingsHandler::getDelay() const {
565 40 : return myDelay;
566 : }
567 :
568 :
569 : std::vector<SUMOTime>
570 0 : GUISettingsHandler::loadBreakpoints(const std::string& file) {
571 : std::vector<SUMOTime> result;
572 0 : std::ifstream strm(file.c_str());
573 0 : if (!strm.good()) {
574 0 : WRITE_ERRORF(TL("Could not open '%'."), file);
575 0 : return result;
576 : }
577 0 : while (strm.good()) {
578 : std::string val;
579 0 : strm >> val;
580 0 : if (val.length() == 0) {
581 : continue;
582 : }
583 : try {
584 0 : SUMOTime value = string2time(val);
585 0 : result.push_back(value);
586 0 : } catch (NumberFormatException& e) {
587 0 : WRITE_ERRORF(TL("A breakpoint value must be a time description (%)."), toString(e.what()));
588 0 : } catch (EmptyData&) {
589 0 : } catch (ProcessError&) {
590 0 : WRITE_ERRORF(TL("Could not decode breakpoint '%'."), val);
591 0 : }
592 : }
593 : return result;
594 0 : }
595 :
596 :
597 : RandomDistributor<std::string>
598 70 : GUISettingsHandler::getEventDistribution(const std::string& id) {
599 70 : RandomDistributor<std::string> result = myEventDistributions[id];
600 70 : if (result.getOverallProb() > 0 && result.getOverallProb() < 1) {
601 : // unscaled probabilities are assumed, fill up with dummy event
602 0 : result.add("", 1. - result.getOverallProb());
603 : }
604 70 : return result;
605 : }
606 :
607 :
608 : /****************************************************************************/
|