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
PCNetProjectionLoader.cpp
Go to the documentation of this file.
1
/****************************************************************************/
9
// A reader for a SUMO network's projection description
10
/****************************************************************************/
11
// SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
12
// Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
13
/****************************************************************************/
14
//
15
// This file is part of SUMO.
16
// SUMO is free software: you can redistribute it and/or modify
17
// it under the terms of the GNU General Public License as published by
18
// the Free Software Foundation, either version 3 of the License, or
19
// (at your option) any later version.
20
//
21
/****************************************************************************/
22
23
24
// ===========================================================================
25
// included modules
26
// ===========================================================================
27
#ifdef _MSC_VER
28
#include <
windows_config.h
>
29
#else
30
#include <
config.h
>
31
#endif
32
33
#include <string>
34
#include <map>
35
#include <fstream>
36
#include <
utils/options/OptionsCont.h
>
37
#include <
utils/options/Option.h
>
38
#include <
utils/common/StdDefs.h
>
39
#include <
polyconvert/PCPolyContainer.h
>
40
#include <
utils/common/RGBColor.h
>
41
#include <
utils/geom/GeomHelper.h
>
42
#include <
utils/geom/Boundary.h
>
43
#include <
utils/geom/Position.h
>
44
#include <
utils/geom/GeoConvHelper.h
>
45
#include <
utils/xml/XMLSubSys.h
>
46
#include <
utils/xml/SUMOSAXReader.h
>
47
#include <
utils/geom/GeomConvHelper.h
>
48
#include <
utils/common/MsgHandler.h
>
49
#include <
utils/common/FileHelpers.h
>
50
#include <
utils/xml/SUMOXMLDefinitions.h
>
51
#include "
PCNetProjectionLoader.h
"
52
53
#ifdef CHECK_MEMORY_LEAKS
54
#include <
foreign/nvwa/debug_new.h
>
55
#endif // CHECK_MEMORY_LEAKS
56
57
58
// ===========================================================================
59
// method definitions
60
// ===========================================================================
61
// ---------------------------------------------------------------------------
62
// static interface
63
// ---------------------------------------------------------------------------
64
void
65
PCNetProjectionLoader::load
(
const
std::string& file,
int
shift) {
66
if
(!
FileHelpers::exists
(file)) {
67
throw
ProcessError
(
"Could not open net-file '"
+ file +
"'."
);
68
}
69
// build handler and parser
70
PCNetProjectionLoader
handler(shift);
71
handler.
setFileName
(file);
72
SUMOSAXReader
* parser =
XMLSubSys::getSAXReader
(handler);
73
PROGRESS_BEGIN_MESSAGE
(
"Parsing network projection from '"
+ file +
"'"
);
74
if
(!parser->
parseFirst
(file)) {
75
delete
parser;
76
throw
ProcessError
(
"Can not read XML-file '"
+ handler.
getFileName
() +
"'."
);
77
}
78
// parse
79
while
(parser->
parseNext
() && !handler.
hasReadAll
());
80
// clean up
81
PROGRESS_DONE_MESSAGE
();
82
if
(!handler.
hasReadAll
()) {
83
throw
ProcessError
(
"Could not find projection parameter in net."
);
84
}
85
delete
parser;
86
}
87
88
89
90
// ---------------------------------------------------------------------------
91
// handler methods
92
// ---------------------------------------------------------------------------
93
PCNetProjectionLoader::PCNetProjectionLoader
(
int
shift) :
94
SUMOSAXHandler
(
"sumo-network"
),
95
myFoundLocation(false),
96
myShift(shift)
97
{}
98
99
100
PCNetProjectionLoader::~PCNetProjectionLoader
() {}
101
102
103
void
104
PCNetProjectionLoader::myStartElement
(
int
element,
105
const
SUMOSAXAttributes
& attrs) {
106
if
(element !=
SUMO_TAG_LOCATION
) {
107
return
;
108
}
109
// @todo refactor parsing of location since its duplicated in NLHandler and PCNetProjectionLoader
110
myFoundLocation
=
true
;
111
PositionVector
s = attrs.
get
<
PositionVector
>(
SUMO_ATTR_NET_OFFSET
, 0,
myFoundLocation
);
112
Boundary
convBoundary = attrs.
get
<
Boundary
>(
SUMO_ATTR_CONV_BOUNDARY
, 0,
myFoundLocation
);
113
Boundary
origBoundary = attrs.
get
<
Boundary
>(
SUMO_ATTR_ORIG_BOUNDARY
, 0,
myFoundLocation
);
114
std::string proj = attrs.
get
<std::string>(
SUMO_ATTR_ORIG_PROJ
, 0,
myFoundLocation
);
115
if
(
myFoundLocation
) {
116
Position
networkOffset = s[0];
117
GeoConvHelper::init
(proj, networkOffset, origBoundary, convBoundary,
myShift
);
118
}
119
}
120
121
122
bool
123
PCNetProjectionLoader::hasReadAll
()
const
{
124
return
myFoundLocation
;
125
}
126
127
128
/****************************************************************************/
129
home
gladk
tmp
05
sumo-0.17.1~dfsg
src
polyconvert
PCNetProjectionLoader.cpp
Generated on Sun Jun 16 2013 07:08:17 for SUMO - Simulation of Urban MObility by
1.8.1.2