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