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.sourceforge.net/
13
// Copyright (C) 2001-2012 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 "
GUISettingsHandler.h
"
45
46
#ifdef CHECK_MEMORY_LEAKS
47
#include <
foreign/nvwa/debug_new.h
>
48
#endif // CHECK_MEMORY_LEAKS
49
50
51
// ===========================================================================
52
// method definitions
53
// ===========================================================================
54
GUISettingsHandler::GUISettingsHandler
(
const
std::string& content,
bool
isFile)
55
:
SUMOSAXHandler
(content), myDelay(-1), myZoom(-1), myXPos(-1), myYPos(-1), myCurrentColorer(
SUMO_TAG_NOTHING
), myCurrentScheme(0) {
56
if
(isFile) {
57
XMLSubSys::runParser
(*
this
, content);
58
}
else
{
59
setFileName
(
"registrySettings"
);
60
SUMOSAXReader
* reader =
XMLSubSys::getSAXReader
(*
this
);
61
reader->
parseString
(content);
62
delete
reader;
63
}
64
}
65
66
67
GUISettingsHandler::~GUISettingsHandler
() {
68
}
69
70
71
void
72
GUISettingsHandler::myStartElement
(
int
element,
73
const
SUMOSAXAttributes
& attrs) {
74
bool
ok =
true
;
75
switch
(element) {
76
case
SUMO_TAG_DELAY
:
77
myDelay
= attrs.
getOptSUMORealReporting
(
SUMO_ATTR_VALUE
, 0, ok,
myDelay
);
78
break
;
79
case
SUMO_TAG_VIEWPORT
:
80
myZoom
= attrs.
getOptSUMORealReporting
(
SUMO_ATTR_ZOOM
, 0, ok,
myZoom
);
81
myXPos
= attrs.
getOptSUMORealReporting
(
SUMO_ATTR_X
, 0, ok,
myXPos
);
82
myYPos
= attrs.
getOptSUMORealReporting
(
SUMO_ATTR_Y
, 0, ok,
myYPos
);
83
break
;
84
case
SUMO_TAG_SNAPSHOT
: {
85
bool
ok =
true
;
86
std::string file = attrs.
getStringReporting
(
SUMO_ATTR_FILE
, 0, ok);
87
if
(file !=
""
&& !
FileHelpers::isAbsolute
(file)) {
88
file =
FileHelpers::getConfigurationRelative
(
getFileName
(), file);
89
}
90
mySnapshots
[attrs.
getOptSUMOTimeReporting
(
SUMO_ATTR_TIME
, file.c_str(), ok, 0)] = file;
91
}
92
break
;
93
case
SUMO_TAG_VIEWSETTINGS_SCHEME
: {
94
bool
ok =
true
;
95
mySettings
.
name
= attrs.
getOptStringReporting
(
SUMO_ATTR_NAME
, 0, ok,
mySettings
.
name
);
96
if
(
gSchemeStorage
.
contains
(
mySettings
.
name
)) {
97
mySettings
=
gSchemeStorage
.
get
(
mySettings
.
name
);
98
}
99
}
100
break
;
101
case
SUMO_TAG_VIEWSETTINGS_OPENGL
:
102
mySettings
.
antialiase
=
TplConvert::_2bool
(attrs.
getStringSecure
(
"antialiase"
,
toString
(
mySettings
.
antialiase
)).c_str());
103
mySettings
.
dither
=
TplConvert::_2bool
(attrs.
getStringSecure
(
"dither"
,
toString
(
mySettings
.
dither
)).c_str());
104
break
;
105
case
SUMO_TAG_VIEWSETTINGS_BACKGROUND
: {
106
bool
ok =
true
;
107
mySettings
.
backgroundColor
=
RGBColor::parseColorReporting
(attrs.
getStringSecure
(
"backgroundColor"
,
toString
(
mySettings
.
backgroundColor
)),
"background"
, 0,
true
, ok);
108
mySettings
.
showGrid
=
TplConvert::_2bool
(attrs.
getStringSecure
(
"showGrid"
,
toString
(
mySettings
.
showGrid
)).c_str());
109
mySettings
.
gridXSize
=
TplConvert::_2SUMOReal
(attrs.
getStringSecure
(
"gridXSize"
,
toString
(
mySettings
.
gridXSize
)).c_str());
110
mySettings
.
gridYSize
=
TplConvert::_2SUMOReal
(attrs.
getStringSecure
(
"gridYSize"
,
toString
(
mySettings
.
gridYSize
)).c_str());
111
}
112
break
;
113
case
SUMO_TAG_VIEWSETTINGS_EDGES
: {
114
int
laneEdgeMode =
TplConvert::_2int
(attrs.
getStringSecure
(
"laneEdgeMode"
,
"0"
).c_str());
115
mySettings
.
laneShowBorders
=
TplConvert::_2bool
(attrs.
getStringSecure
(
"laneShowBorders"
,
toString
(
mySettings
.
laneShowBorders
)).c_str());
116
mySettings
.
showLinkDecals
=
TplConvert::_2bool
(attrs.
getStringSecure
(
"showLinkDecals"
,
toString
(
mySettings
.
showLinkDecals
)).c_str());
117
mySettings
.
showRails
=
TplConvert::_2bool
(attrs.
getStringSecure
(
"showRails"
,
toString
(
mySettings
.
showRails
)).c_str());
118
mySettings
.
edgeName
=
parseTextSettings
(
"edgeName"
, attrs,
mySettings
.
edgeName
);
119
mySettings
.
internalEdgeName
=
parseTextSettings
(
"internalEdgeName"
, attrs,
mySettings
.
internalEdgeName
);
120
mySettings
.
streetName
=
parseTextSettings
(
"streetName"
, attrs,
mySettings
.
streetName
);
121
mySettings
.
hideConnectors
=
TplConvert::_2bool
(attrs.
getStringSecure
(
"hideConnectors"
,
toString
(
mySettings
.
hideConnectors
)).c_str());
122
myCurrentColorer
= element;
123
#ifdef HAVE_INTERNAL
124
mySettings
.edgeColorer.setActive(laneEdgeMode);
125
#endif
126
mySettings
.
laneColorer
.
setActive
(laneEdgeMode);
127
}
128
break
;
129
case
SUMO_TAG_COLORSCHEME
:
130
myCurrentScheme
= 0;
131
if
(
myCurrentColorer
==
SUMO_TAG_VIEWSETTINGS_EDGES
) {
132
myCurrentScheme
=
mySettings
.
laneColorer
.
getSchemeByName
(attrs.
getStringSecure
(
SUMO_ATTR_NAME
,
""
));
133
#ifdef HAVE_INTERNAL
134
if
(
myCurrentScheme
== 0) {
135
myCurrentScheme
=
mySettings
.edgeColorer.getSchemeByName(attrs.
getStringSecure
(
SUMO_ATTR_NAME
,
""
));
136
}
137
#endif
138
}
139
if
(
myCurrentColorer
==
SUMO_TAG_VIEWSETTINGS_VEHICLES
) {
140
myCurrentScheme
=
mySettings
.
vehicleColorer
.
getSchemeByName
(attrs.
getStringSecure
(
SUMO_ATTR_NAME
,
""
));
141
}
142
if
(
myCurrentScheme
&& !
myCurrentScheme
->
isFixed
()) {
143
bool
ok =
true
;
144
myCurrentScheme
->
setInterpolated
(attrs.
getOptBoolReporting
(
SUMO_ATTR_INTERPOLATED
, 0, ok,
false
));
145
myCurrentScheme
->
clear
();
146
}
147
break
;
148
case
SUMO_TAG_ENTRY
:
149
if
(
myCurrentScheme
) {
150
bool
ok =
true
;
151
RGBColor
color = attrs.
getColorReporting
(0, ok);
152
if
(
myCurrentScheme
->
isFixed
()) {
153
myCurrentScheme
->
setColor
(attrs.
getStringSecure
(
SUMO_ATTR_NAME
,
""
), color);
154
}
else
{
155
myCurrentScheme
->
addColor
(color,
156
attrs.
getSUMORealReporting
(
SUMO_ATTR_THRESHOLD
, 0, ok));
157
}
158
}
159
break
;
160
case
SUMO_TAG_VIEWSETTINGS_VEHICLES
:
161
mySettings
.
vehicleColorer
.
setActive
(
TplConvert::_2int
(attrs.
getStringSecure
(
"vehicleMode"
,
"0"
).c_str()));
162
mySettings
.
vehicleQuality
=
TplConvert::_2int
(attrs.
getStringSecure
(
"vehicleQuality"
,
toString
(
mySettings
.
vehicleQuality
)).c_str());
163
mySettings
.
minVehicleSize
=
TplConvert::_2SUMOReal
(attrs.
getStringSecure
(
"minVehicleSize"
,
toString
(
mySettings
.
minVehicleSize
)).c_str());
164
mySettings
.
vehicleExaggeration
=
TplConvert::_2SUMOReal
(attrs.
getStringSecure
(
"vehicleExaggeration"
,
toString
(
mySettings
.
vehicleExaggeration
)).c_str());
165
mySettings
.
showBlinker
=
TplConvert::_2bool
(attrs.
getStringSecure
(
"showBlinker"
,
toString
(
mySettings
.
showBlinker
)).c_str());
166
mySettings
.
vehicleName
=
parseTextSettings
(
"vehicleName"
, attrs,
mySettings
.
vehicleName
);
167
myCurrentColorer
= element;
168
break
;
169
case
SUMO_TAG_VIEWSETTINGS_JUNCTIONS
:
170
mySettings
.
junctionMode
=
TplConvert::_2int
(attrs.
getStringSecure
(
"junctionMode"
,
toString
(
mySettings
.
junctionMode
)).c_str());
171
mySettings
.
drawLinkTLIndex
=
TplConvert::_2bool
(attrs.
getStringSecure
(
"drawLinkTLIndex"
,
toString
(
mySettings
.
drawLinkTLIndex
)).c_str());
172
mySettings
.
drawLinkJunctionIndex
=
TplConvert::_2bool
(attrs.
getStringSecure
(
"drawLinkJunctionIndex"
,
toString
(
mySettings
.
drawLinkJunctionIndex
)).c_str());
173
mySettings
.
junctionName
=
parseTextSettings
(
"junctionName"
, attrs,
mySettings
.
junctionName
);
174
mySettings
.
internalJunctionName
=
parseTextSettings
(
"internalJunctionName"
, attrs,
mySettings
.
internalJunctionName
);
175
mySettings
.
showLane2Lane
=
TplConvert::_2bool
(attrs.
getStringSecure
(
"showLane2Lane"
,
toString
(
mySettings
.
showLane2Lane
)).c_str());
176
break
;
177
case
SUMO_TAG_VIEWSETTINGS_ADDITIONALS
:
178
mySettings
.
addMode
=
TplConvert::_2int
(attrs.
getStringSecure
(
"addMode"
,
toString
(
mySettings
.
addMode
)).c_str());
179
mySettings
.
minAddSize
=
TplConvert::_2SUMOReal
(attrs.
getStringSecure
(
"minAddSize"
,
toString
(
mySettings
.
minAddSize
)).c_str());
180
mySettings
.
addExaggeration
=
TplConvert::_2SUMOReal
(attrs.
getStringSecure
(
"addExaggeration"
,
toString
(
mySettings
.
addExaggeration
)).c_str());
181
mySettings
.
addName
=
parseTextSettings
(
"addName"
, attrs,
mySettings
.
addName
);
182
break
;
183
case
SUMO_TAG_VIEWSETTINGS_POIS
:
184
mySettings
.
poiExaggeration
=
TplConvert::_2SUMOReal
(attrs.
getStringSecure
(
"poiExaggeration"
,
toString
(
mySettings
.
poiExaggeration
)).c_str());
185
mySettings
.
minPOISize
=
TplConvert::_2SUMOReal
(attrs.
getStringSecure
(
"minPOISize"
,
toString
(
mySettings
.
minPOISize
)).c_str());
186
mySettings
.
poiName
=
parseTextSettings
(
"poiName"
, attrs,
mySettings
.
poiName
);
187
break
;
188
case
SUMO_TAG_VIEWSETTINGS_LEGEND
:
189
mySettings
.
showSizeLegend
=
TplConvert::_2bool
(attrs.
getStringSecure
(
"showSizeLegend"
,
toString
(
mySettings
.
showSizeLegend
)).c_str());
190
break
;
191
case
SUMO_TAG_VIEWSETTINGS_DECAL
: {
192
GUISUMOAbstractView::Decal
d;
193
d.
filename
= attrs.
getStringSecure
(
"filename"
, d.
filename
);
194
if
(d.
filename
!=
""
&& !
FileHelpers::isAbsolute
(d.
filename
)) {
195
d.
filename
=
FileHelpers::getConfigurationRelative
(
getFileName
(), d.
filename
);
196
}
197
d.
centerX
=
TplConvert::_2SUMOReal
(attrs.
getStringSecure
(
"centerX"
,
toString
(d.
centerX
)).c_str());
198
d.
centerY
=
TplConvert::_2SUMOReal
(attrs.
getStringSecure
(
"centerY"
,
toString
(d.
centerY
)).c_str());
199
d.
width
=
TplConvert::_2SUMOReal
(attrs.
getStringSecure
(
"width"
,
toString
(d.
width
)).c_str());
200
d.
height
=
TplConvert::_2SUMOReal
(attrs.
getStringSecure
(
"height"
,
toString
(d.
height
)).c_str());
201
d.
rot
=
TplConvert::_2SUMOReal
(attrs.
getStringSecure
(
"rotation"
,
toString
(d.
rot
)).c_str());
202
d.
layer
=
TplConvert::_2SUMOReal
(attrs.
getStringSecure
(
"layer"
,
toString
(d.
layer
)).c_str());
203
d.
initialised
=
false
;
204
myDecals
.push_back(d);
205
}
206
break
;
207
default
:
208
break
;
209
}
210
}
211
212
213
GUIVisualizationTextSettings
214
GUISettingsHandler::parseTextSettings
(
215
const
std::string& prefix,
const
SUMOSAXAttributes
& attrs,
216
GUIVisualizationTextSettings
defaults) {
217
bool
ok =
true
;
218
return
GUIVisualizationTextSettings
(
219
TplConvert::_2bool
(attrs.
getStringSecure
(prefix +
"_show"
,
toString
(defaults.
show
)).c_str()),
220
TplConvert::_2SUMOReal
(attrs.
getStringSecure
(prefix +
"_size"
,
toString
(defaults.
size
)).c_str()),
221
RGBColor::parseColorReporting
(attrs.
getStringSecure
(prefix +
"_color"
,
toString
(defaults.
color
)),
"edges"
, 0,
true
, ok));
222
}
223
224
225
std::string
226
GUISettingsHandler::addSettings
(
GUISUMOAbstractView
* view)
const
{
227
if
(
mySettings
.
name
!=
""
) {
228
gSchemeStorage
.
add
(
mySettings
);
229
if
(view) {
230
FXint index = view->
getColoringSchemesCombo
().appendItem(
mySettings
.
name
.c_str());
231
view->
getColoringSchemesCombo
().setCurrentItem(index);
232
view->
setColorScheme
(
mySettings
.
name
);
233
}
234
}
235
return
mySettings
.
name
;
236
}
237
238
239
void
240
GUISettingsHandler::setViewport
(
GUISUMOAbstractView
* view)
const
{
241
if
(
myZoom
> 0) {
242
view->
setViewport
(
myZoom
,
myXPos
,
myYPos
);
243
}
244
}
245
246
247
void
248
GUISettingsHandler::setViewport
(
SUMOReal
& zoom,
SUMOReal
& xoff,
SUMOReal
& yoff)
const
{
249
zoom =
myZoom
;
250
xoff =
myXPos
;
251
yoff =
myYPos
;
252
}
253
254
255
void
256
GUISettingsHandler::setSnapshots
(
GUISUMOAbstractView
* view)
const
{
257
if
(!
mySnapshots
.empty()) {
258
view->
setSnapshots
(
mySnapshots
);
259
}
260
}
261
262
263
bool
264
GUISettingsHandler::hasDecals
()
const
{
265
return
!
myDecals
.empty();
266
}
267
268
269
const
std::vector<GUISUMOAbstractView::Decal>&
270
GUISettingsHandler::getDecals
()
const
{
271
return
myDecals
;
272
}
273
274
275
SUMOReal
276
GUISettingsHandler::getDelay
()
const
{
277
return
myDelay
;
278
}
279
280
281
/****************************************************************************/
282
build
buildd
sumo-0.16.0~dfsg
src
utils
gui
settings
GUISettingsHandler.cpp
Generated on Tue Apr 16 2013 01:32:16 for SUMO - Simulation of Urban MObility by
1.8.3.1