SUMO - Simulation of Urban MObility
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
GUISettingsHandler.cpp
Go to the documentation of this file.
1
/****************************************************************************/
10
// The dialog to change the view (gui) settings.
11
/****************************************************************************/
12
// SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
13
// Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
14
/****************************************************************************/
15
//
16
// This file is part of SUMO.
17
// SUMO is free software: you can redistribute it and/or modify
18
// it under the terms of the GNU General Public License as published by
19
// the Free Software Foundation, either version 3 of the License, or
20
// (at your option) any later version.
21
//
22
/****************************************************************************/
23
24
25
// ===========================================================================
26
// included modules
27
// ===========================================================================
28
#ifdef _MSC_VER
29
#include <
windows_config.h
>
30
#else
31
#include <
config.h
>
32
#endif
33
34
#include <vector>
35
#include <
utils/common/TplConvert.h
>
36
#include <
utils/common/ToString.h
>
37
#include <
utils/common/RGBColor.h
>
38
#include <
utils/common/MsgHandler.h
>
39
#include <
utils/common/FileHelpers.h
>
40
#include <
utils/gui/settings/GUIVisualizationSettings.h
>
41
#include <
utils/gui/settings/GUICompleteSchemeStorage.h
>
42
#include <
utils/foxtools/MFXImageHelper.h
>
43
#include <
utils/xml/SUMOSAXReader.h
>
44
#include <
utils/xml/XMLSubSys.h
>
45
#include "
GUISettingsHandler.h
"
46
47
#ifdef CHECK_MEMORY_LEAKS
48
#include <
foreign/nvwa/debug_new.h
>
49
#endif // CHECK_MEMORY_LEAKS
50
51
52
// ===========================================================================
53
// method definitions
54
// ===========================================================================
55
GUISettingsHandler::GUISettingsHandler
(
const
std::string& content,
bool
isFile)
56
:
SUMOSAXHandler
(content), myDelay(-1), myLookFrom(-1, -1, -1), myLookAt(-1, -1, -1),
57
myCurrentColorer(
SUMO_TAG_NOTHING
), myCurrentScheme(0) {
58
if
(isFile) {
59
XMLSubSys::runParser
(*
this
, content);
60
}
else
{
61
setFileName
(
"registrySettings"
);
62
SUMOSAXReader
* reader =
XMLSubSys::getSAXReader
(*
this
);
63
reader->
parseString
(content);
64
delete
reader;
65
}
66
}
67
68
69
GUISettingsHandler::~GUISettingsHandler
() {
70
}
71
72
73
void
74
GUISettingsHandler::myStartElement
(
int
element,
75
const
SUMOSAXAttributes
& attrs) {
76
bool
ok =
true
;
77
switch
(element) {
78
case
SUMO_TAG_BREAKPOINTS_FILE
: {
79
std::string file = attrs.
get
<std::string>(
SUMO_ATTR_VALUE
, 0, ok);
80
myBreakpoints
=
loadBreakpoints
(file);
81
}
82
break
;
83
case
SUMO_TAG_VIEWSETTINGS
:
84
myViewType
= attrs.
getOpt
<std::string>(
SUMO_ATTR_TYPE
, 0, ok,
"default"
);
85
std::transform(
myViewType
.begin(),
myViewType
.end(),
myViewType
.begin(), tolower);
86
break
;
87
case
SUMO_TAG_DELAY
:
88
myDelay
= attrs.
getOpt
<
SUMOReal
>(
SUMO_ATTR_VALUE
, 0, ok,
myDelay
);
89
break
;
90
case
SUMO_TAG_VIEWPORT
: {
91
const
SUMOReal
x = attrs.
getOpt
<
SUMOReal
>(
SUMO_ATTR_X
, 0, ok,
myLookFrom
.
x
());
92
const
SUMOReal
y = attrs.
getOpt
<
SUMOReal
>(
SUMO_ATTR_Y
, 0, ok,
myLookFrom
.
y
());
93
const
SUMOReal
z = attrs.
getOpt
<
SUMOReal
>(
SUMO_ATTR_ZOOM
, 0, ok,
myLookFrom
.
z
());
94
myLookFrom
.
set
(x, y, z);
95
const
SUMOReal
cx = attrs.
getOpt
<
SUMOReal
>(
SUMO_ATTR_CENTER_X
, 0, ok,
myLookAt
.
x
());
96
const
SUMOReal
cy = attrs.
getOpt
<
SUMOReal
>(
SUMO_ATTR_CENTER_Y
, 0, ok,
myLookAt
.
y
());
97
const
SUMOReal
cz = attrs.
getOpt
<
SUMOReal
>(
SUMO_ATTR_CENTER_Z
, 0, ok,
myLookAt
.
z
());
98
myLookAt
.
set
(cx, cy, cz);
99
break
;
100
}
101
case
SUMO_TAG_SNAPSHOT
: {
102
bool
ok =
true
;
103
std::string file = attrs.
get
<std::string>(
SUMO_ATTR_FILE
, 0, ok);
104
if
(file !=
""
&& !
FileHelpers::isAbsolute
(file)) {
105
file =
FileHelpers::getConfigurationRelative
(
getFileName
(), file);
106
}
107
mySnapshots
[attrs.
getOptSUMOTimeReporting
(
SUMO_ATTR_TIME
, file.c_str(), ok, 0)] = file;
108
}
109
break
;
110
case
SUMO_TAG_VIEWSETTINGS_SCHEME
: {
111
bool
ok =
true
;
112
mySettings
.
name
= attrs.
getOpt
<std::string>(
SUMO_ATTR_NAME
, 0, ok,
mySettings
.
name
);
113
if
(
gSchemeStorage
.
contains
(
mySettings
.
name
)) {
114
mySettings
=
gSchemeStorage
.
get
(
mySettings
.
name
);
115
}
116
}
117
break
;
118
case
SUMO_TAG_VIEWSETTINGS_OPENGL
:
119
mySettings
.
antialiase
=
TplConvert::_2bool
(attrs.
getStringSecure
(
"antialiase"
,
toString
(
mySettings
.
antialiase
)).c_str());
120
mySettings
.
dither
=
TplConvert::_2bool
(attrs.
getStringSecure
(
"dither"
,
toString
(
mySettings
.
dither
)).c_str());
121
break
;
122
case
SUMO_TAG_VIEWSETTINGS_BACKGROUND
: {
123
bool
ok =
true
;
124
mySettings
.
backgroundColor
=
RGBColor::parseColorReporting
(attrs.
getStringSecure
(
"backgroundColor"
,
toString
(
mySettings
.
backgroundColor
)),
"background"
, 0,
true
, ok);
125
mySettings
.
showGrid
=
TplConvert::_2bool
(attrs.
getStringSecure
(
"showGrid"
,
toString
(
mySettings
.
showGrid
)).c_str());
126
mySettings
.
gridXSize
=
TplConvert::_2SUMOReal
(attrs.
getStringSecure
(
"gridXSize"
,
toString
(
mySettings
.
gridXSize
)).c_str());
127
mySettings
.
gridYSize
=
TplConvert::_2SUMOReal
(attrs.
getStringSecure
(
"gridYSize"
,
toString
(
mySettings
.
gridYSize
)).c_str());
128
}
129
break
;
130
case
SUMO_TAG_VIEWSETTINGS_EDGES
: {
131
int
laneEdgeMode =
TplConvert::_2int
(attrs.
getStringSecure
(
"laneEdgeMode"
,
"0"
).c_str());
132
mySettings
.
laneShowBorders
=
TplConvert::_2bool
(attrs.
getStringSecure
(
"laneShowBorders"
,
toString
(
mySettings
.
laneShowBorders
)).c_str());
133
mySettings
.
showLinkDecals
=
TplConvert::_2bool
(attrs.
getStringSecure
(
"showLinkDecals"
,
toString
(
mySettings
.
showLinkDecals
)).c_str());
134
mySettings
.
showRails
=
TplConvert::_2bool
(attrs.
getStringSecure
(
"showRails"
,
toString
(
mySettings
.
showRails
)).c_str());
135
mySettings
.
edgeName
=
parseTextSettings
(
"edgeName"
, attrs,
mySettings
.
edgeName
);
136
mySettings
.
internalEdgeName
=
parseTextSettings
(
"internalEdgeName"
, attrs,
mySettings
.
internalEdgeName
);
137
mySettings
.
streetName
=
parseTextSettings
(
"streetName"
, attrs,
mySettings
.
streetName
);
138
mySettings
.
hideConnectors
=
TplConvert::_2bool
(attrs.
getStringSecure
(
"hideConnectors"
,
toString
(
mySettings
.
hideConnectors
)).c_str());
139
myCurrentColorer
= element;
140
#ifdef HAVE_INTERNAL
141
mySettings
.edgeColorer.setActive(laneEdgeMode);
142
#endif
143
mySettings
.
laneColorer
.
setActive
(laneEdgeMode);
144
}
145
break
;
146
case
SUMO_TAG_COLORSCHEME
:
147
myCurrentScheme
= 0;
148
if
(
myCurrentColorer
==
SUMO_TAG_VIEWSETTINGS_EDGES
) {
149
myCurrentScheme
=
mySettings
.
laneColorer
.
getSchemeByName
(attrs.
getStringSecure
(
SUMO_ATTR_NAME
,
""
));
150
#ifdef HAVE_INTERNAL
151
if
(
myCurrentScheme
== 0) {
152
myCurrentScheme
=
mySettings
.edgeColorer.getSchemeByName(attrs.
getStringSecure
(
SUMO_ATTR_NAME
,
""
));
153
}
154
#endif
155
}
156
if
(
myCurrentColorer
==
SUMO_TAG_VIEWSETTINGS_VEHICLES
) {
157
myCurrentScheme
=
mySettings
.
vehicleColorer
.
getSchemeByName
(attrs.
getStringSecure
(
SUMO_ATTR_NAME
,
""
));
158
}
159
if
(
myCurrentColorer
==
SUMO_TAG_VIEWSETTINGS_JUNCTIONS
) {
160
myCurrentScheme
=
mySettings
.
junctionColorer
.
getSchemeByName
(attrs.
getStringSecure
(
SUMO_ATTR_NAME
,
""
));
161
}
162
if
(
myCurrentScheme
&& !
myCurrentScheme
->
isFixed
()) {
163
bool
ok =
true
;
164
myCurrentScheme
->
setInterpolated
(attrs.
getOpt
<
bool
>(
SUMO_ATTR_INTERPOLATED
, 0, ok,
false
));
165
myCurrentScheme
->
clear
();
166
}
167
break
;
168
case
SUMO_TAG_ENTRY
:
169
if
(
myCurrentScheme
) {
170
bool
ok =
true
;
171
RGBColor
color = attrs.
get
<
RGBColor
>(
SUMO_ATTR_COLOR
, 0, ok);
172
if
(
myCurrentScheme
->
isFixed
()) {
173
myCurrentScheme
->
setColor
(attrs.
getStringSecure
(
SUMO_ATTR_NAME
,
""
), color);
174
}
else
{
175
myCurrentScheme
->
addColor
(color,
176
attrs.
get
<
SUMOReal
>(
SUMO_ATTR_THRESHOLD
, 0, ok));
177
}
178
}
179
break
;
180
case
SUMO_TAG_VIEWSETTINGS_VEHICLES
:
181
mySettings
.
vehicleColorer
.
setActive
(
TplConvert::_2int
(attrs.
getStringSecure
(
"vehicleMode"
,
"0"
).c_str()));
182
mySettings
.
vehicleQuality
=
TplConvert::_2int
(attrs.
getStringSecure
(
"vehicleQuality"
,
toString
(
mySettings
.
vehicleQuality
)).c_str());
183
mySettings
.
minVehicleSize
=
TplConvert::_2SUMOReal
(attrs.
getStringSecure
(
"minVehicleSize"
,
toString
(
mySettings
.
minVehicleSize
)).c_str());
184
mySettings
.
vehicleExaggeration
=
TplConvert::_2SUMOReal
(attrs.
getStringSecure
(
"vehicleExaggeration"
,
toString
(
mySettings
.
vehicleExaggeration
)).c_str());
185
mySettings
.
showBlinker
=
TplConvert::_2bool
(attrs.
getStringSecure
(
"showBlinker"
,
toString
(
mySettings
.
showBlinker
)).c_str());
186
mySettings
.
vehicleName
=
parseTextSettings
(
"vehicleName"
, attrs,
mySettings
.
vehicleName
);
187
myCurrentColorer
= element;
188
break
;
189
case
SUMO_TAG_VIEWSETTINGS_PERSONS
:
190
mySettings
.
personColorer
.
setActive
(
TplConvert::_2int
(attrs.
getStringSecure
(
"personMode"
,
"0"
).c_str()));
191
mySettings
.
personQuality
=
TplConvert::_2int
(attrs.
getStringSecure
(
"personQuality"
,
toString
(
mySettings
.
personQuality
)).c_str());
192
mySettings
.
minPersonSize
=
TplConvert::_2SUMOReal
(attrs.
getStringSecure
(
"minPersonSize"
,
toString
(
mySettings
.
minPersonSize
)).c_str());
193
mySettings
.
personExaggeration
=
TplConvert::_2SUMOReal
(attrs.
getStringSecure
(
"personExaggeration"
,
toString
(
mySettings
.
personExaggeration
)).c_str());
194
mySettings
.
personName
=
parseTextSettings
(
"personName"
, attrs,
mySettings
.
personName
);
195
myCurrentColorer
= element;
196
break
;
197
case
SUMO_TAG_VIEWSETTINGS_JUNCTIONS
:
198
mySettings
.
junctionColorer
.
setActive
(
TplConvert::_2int
(attrs.
getStringSecure
(
"junctionMode"
,
"0"
).c_str()));
199
mySettings
.
drawLinkTLIndex
=
TplConvert::_2bool
(attrs.
getStringSecure
(
"drawLinkTLIndex"
,
toString
(
mySettings
.
drawLinkTLIndex
)).c_str());
200
mySettings
.
drawLinkJunctionIndex
=
TplConvert::_2bool
(attrs.
getStringSecure
(
"drawLinkJunctionIndex"
,
toString
(
mySettings
.
drawLinkJunctionIndex
)).c_str());
201
mySettings
.
junctionName
=
parseTextSettings
(
"junctionName"
, attrs,
mySettings
.
junctionName
);
202
mySettings
.
internalJunctionName
=
parseTextSettings
(
"internalJunctionName"
, attrs,
mySettings
.
internalJunctionName
);
203
mySettings
.
showLane2Lane
=
TplConvert::_2bool
(attrs.
getStringSecure
(
"showLane2Lane"
,
toString
(
mySettings
.
showLane2Lane
)).c_str());
204
myCurrentColorer
= element;
205
break
;
206
case
SUMO_TAG_VIEWSETTINGS_ADDITIONALS
:
207
mySettings
.
addMode
=
TplConvert::_2int
(attrs.
getStringSecure
(
"addMode"
,
toString
(
mySettings
.
addMode
)).c_str());
208
mySettings
.
minAddSize
=
TplConvert::_2SUMOReal
(attrs.
getStringSecure
(
"minAddSize"
,
toString
(
mySettings
.
minAddSize
)).c_str());
209
mySettings
.
addExaggeration
=
TplConvert::_2SUMOReal
(attrs.
getStringSecure
(
"addExaggeration"
,
toString
(
mySettings
.
addExaggeration
)).c_str());
210
mySettings
.
addName
=
parseTextSettings
(
"addName"
, attrs,
mySettings
.
addName
);
211
break
;
212
case
SUMO_TAG_VIEWSETTINGS_POIS
:
213
mySettings
.
poiExaggeration
=
TplConvert::_2SUMOReal
(attrs.
getStringSecure
(
"poiExaggeration"
,
toString
(
mySettings
.
poiExaggeration
)).c_str());
214
mySettings
.
minPOISize
=
TplConvert::_2SUMOReal
(attrs.
getStringSecure
(
"minPOISize"
,
toString
(
mySettings
.
minPOISize
)).c_str());
215
mySettings
.
poiName
=
parseTextSettings
(
"poiName"
, attrs,
mySettings
.
poiName
);
216
break
;
217
case
SUMO_TAG_VIEWSETTINGS_POLYS
:
218
mySettings
.
polyExaggeration
=
TplConvert::_2SUMOReal
(attrs.
getStringSecure
(
"polyExaggeration"
,
toString
(
mySettings
.
polyExaggeration
)).c_str());
219
mySettings
.
minPolySize
=
TplConvert::_2SUMOReal
(attrs.
getStringSecure
(
"minPolySize"
,
toString
(
mySettings
.
minPolySize
)).c_str());
220
mySettings
.
polyName
=
parseTextSettings
(
"polyName"
, attrs,
mySettings
.
polyName
);
221
break
;
222
case
SUMO_TAG_VIEWSETTINGS_LEGEND
:
223
mySettings
.
showSizeLegend
=
TplConvert::_2bool
(attrs.
getStringSecure
(
"showSizeLegend"
,
toString
(
mySettings
.
showSizeLegend
)).c_str());
224
break
;
225
case
SUMO_TAG_VIEWSETTINGS_DECAL
: {
226
GUISUMOAbstractView::Decal
d;
227
d.
filename
= attrs.
getStringSecure
(
"filename"
, d.
filename
);
228
if
(d.
filename
!=
""
&& !
FileHelpers::isAbsolute
(d.
filename
)) {
229
d.
filename
=
FileHelpers::getConfigurationRelative
(
getFileName
(), d.
filename
);
230
}
231
d.
centerX
= attrs.
getOpt
<
SUMOReal
>(
SUMO_ATTR_CENTER_X
, 0, ok, d.
centerX
);
232
d.
centerY
= attrs.
getOpt
<
SUMOReal
>(
SUMO_ATTR_CENTER_Y
, 0, ok, d.
centerY
);
233
d.
centerZ
= attrs.
getOpt
<
SUMOReal
>(
SUMO_ATTR_CENTER_Z
, 0, ok, d.
centerZ
);
234
d.
width
= attrs.
getOpt
<
SUMOReal
>(
SUMO_ATTR_WIDTH
, 0, ok, d.
width
);
235
d.
height
= attrs.
getOpt
<
SUMOReal
>(
SUMO_ATTR_HEIGHT
, 0, ok, d.
height
);
236
d.
altitude
=
TplConvert::_2SUMOReal
(attrs.
getStringSecure
(
"altitude"
,
toString
(d.
height
)).c_str());
237
d.
rot
=
TplConvert::_2SUMOReal
(attrs.
getStringSecure
(
"rotation"
,
toString
(d.
rot
)).c_str());
238
d.
tilt
=
TplConvert::_2SUMOReal
(attrs.
getStringSecure
(
"tilt"
,
toString
(d.
tilt
)).c_str());
239
d.
roll
=
TplConvert::_2SUMOReal
(attrs.
getStringSecure
(
"roll"
,
toString
(d.
roll
)).c_str());
240
d.
layer
= attrs.
getOpt
<
SUMOReal
>(
SUMO_ATTR_LAYER
, 0, ok, d.
layer
);
241
d.
initialised
=
false
;
242
myDecals
.push_back(d);
243
}
244
break
;
245
default
:
246
break
;
247
}
248
}
249
250
251
GUIVisualizationTextSettings
252
GUISettingsHandler::parseTextSettings
(
253
const
std::string& prefix,
const
SUMOSAXAttributes
& attrs,
254
GUIVisualizationTextSettings
defaults) {
255
bool
ok =
true
;
256
return
GUIVisualizationTextSettings
(
257
TplConvert::_2bool
(attrs.
getStringSecure
(prefix +
"_show"
,
toString
(defaults.
show
)).c_str()),
258
TplConvert::_2SUMOReal
(attrs.
getStringSecure
(prefix +
"_size"
,
toString
(defaults.
size
)).c_str()),
259
RGBColor::parseColorReporting
(attrs.
getStringSecure
(prefix +
"_color"
,
toString
(defaults.
color
)),
"edges"
, 0,
true
, ok));
260
}
261
262
263
std::string
264
GUISettingsHandler::addSettings
(
GUISUMOAbstractView
* view)
const
{
265
if
(
mySettings
.
name
!=
""
) {
266
gSchemeStorage
.
add
(
mySettings
);
267
if
(view) {
268
FXint index = view->
getColoringSchemesCombo
().appendItem(
mySettings
.
name
.c_str());
269
view->
getColoringSchemesCombo
().setCurrentItem(index);
270
view->
setColorScheme
(
mySettings
.
name
);
271
}
272
}
273
return
mySettings
.
name
;
274
}
275
276
277
void
278
GUISettingsHandler::setViewport
(
GUISUMOAbstractView
* view)
const
{
279
if
(
myLookFrom
.
z
() > 0) {
280
view->
setViewport
(
myLookFrom
,
myLookAt
);
281
}
282
}
283
284
285
void
286
GUISettingsHandler::setViewport
(
Position
& lookFrom,
Position
& lookAt)
const
{
287
lookFrom =
myLookFrom
;
288
lookAt =
myLookAt
;
289
}
290
291
292
void
293
GUISettingsHandler::setSnapshots
(
GUISUMOAbstractView
* view)
const
{
294
if
(!
mySnapshots
.empty()) {
295
view->
setSnapshots
(
mySnapshots
);
296
}
297
}
298
299
300
bool
301
GUISettingsHandler::hasDecals
()
const
{
302
return
!
myDecals
.empty();
303
}
304
305
306
const
std::vector<GUISUMOAbstractView::Decal>&
307
GUISettingsHandler::getDecals
()
const
{
308
return
myDecals
;
309
}
310
311
312
SUMOReal
313
GUISettingsHandler::getDelay
()
const
{
314
return
myDelay
;
315
}
316
317
318
std::vector<SUMOTime>
319
GUISettingsHandler::loadBreakpoints
(
const
std::string& file) {
320
std::vector<SUMOTime> result;
321
std::ifstream strm(file.c_str());
322
while
(strm.good()) {
323
std::string val;
324
strm >> val;
325
if
(val.length() == 0) {
326
continue
;
327
}
328
try
{
329
SUMOTime
value =
string2time
(val);
330
result.push_back(value);
331
}
catch
(
NumberFormatException
&) {
332
WRITE_ERROR
(
" A breakpoint-value must be an int, is:"
+ val);
333
}
catch
(
ProcessError
&) {
334
WRITE_ERROR
(
" Could not decode breakpoint '"
+ val +
"'"
);
335
}
catch
(
EmptyData
&) {}
336
}
337
return
result;
338
}
339
340
/****************************************************************************/
341
build
buildd
sumo-0.18~dfsg
src
utils
gui
settings
GUISettingsHandler.cpp
Generated on Wed Oct 23 2013 01:15:08 for SUMO - Simulation of Urban MObility by
1.8.4