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
NILoader.cpp
Go to the documentation of this file.
1
/****************************************************************************/
10
// Perfoms network import
11
/****************************************************************************/
12
// SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
13
// Copyright (C) 2001-2014 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 <string>
35
#include <
utils/common/UtilExceptions.h
>
36
#include <
utils/common/MsgHandler.h
>
37
#include <
utils/options/OptionsCont.h
>
38
#include <
utils/options/Option.h
>
39
#include <
utils/common/FileHelpers.h
>
40
#include <
utils/common/StringUtils.h
>
41
#include <
utils/common/ToString.h
>
42
#include <
netbuild/NBTypeCont.h
>
43
#include <
netbuild/NBNodeCont.h
>
44
#include <
netbuild/NBEdgeCont.h
>
45
#include <
netbuild/NBNetBuilder.h
>
46
#include <
utils/xml/SUMOSAXHandler.h
>
47
#include <
utils/xml/SUMOSAXReader.h
>
48
#include <
netimport/NIXMLEdgesHandler.h
>
49
#include <
netimport/NIXMLNodesHandler.h
>
50
#include <
netimport/NIXMLTrafficLightsHandler.h
>
51
#include <
netimport/NIXMLTypesHandler.h
>
52
#include <
netimport/NIXMLConnectionsHandler.h
>
53
#include <
netimport/NIImporter_DlrNavteq.h
>
54
#include <
netimport/NIImporter_VISUM.h
>
55
#include <
netimport/vissim/NIImporter_Vissim.h
>
56
#include <
netimport/NIImporter_ArcView.h
>
57
#include <
netimport/NIImporter_SUMO.h
>
58
#include <
netimport/NIImporter_RobocupRescue.h
>
59
#include <
netimport/NIImporter_OpenStreetMap.h
>
60
#include <
netimport/NIImporter_OpenDrive.h
>
61
#include <
netimport/NIImporter_MATSim.h
>
62
#include <
netimport/NIImporter_ITSUMO.h
>
63
#include <
utils/xml/XMLSubSys.h
>
64
#include "
NILoader.h
"
65
#include <
utils/common/TplConvert.h
>
66
#include <
utils/geom/GeoConvHelper.h
>
67
68
#ifdef HAVE_INTERNAL
69
#include <internal/HeightMapper.h>
70
#endif
71
72
#ifdef CHECK_MEMORY_LEAKS
73
#include <
foreign/nvwa/debug_new.h
>
74
#endif // CHECK_MEMORY_LEAKS
75
76
77
// ===========================================================================
78
// method definitions
79
// ===========================================================================
80
NILoader::NILoader
(
NBNetBuilder
& nb)
81
: myNetBuilder(nb) {}
82
83
84
NILoader::~NILoader
() {}
85
86
87
void
88
NILoader::load
(
OptionsCont
& oc) {
89
// load types first
90
NIXMLTypesHandler
* handler =
91
new
NIXMLTypesHandler
(
myNetBuilder
.
getTypeCont
());
92
loadXMLType
(handler, oc.
getStringVector
(
"type-files"
),
"types"
);
93
// try to load height data so it is ready for use by other importers
94
#ifdef HAVE_INTERNAL
95
HeightMapper::loadIfSet(oc);
96
#endif
97
// try to load using different methods
98
NIImporter_SUMO::loadNetwork
(oc,
myNetBuilder
);
99
NIImporter_RobocupRescue::loadNetwork
(oc,
myNetBuilder
);
100
NIImporter_OpenStreetMap::loadNetwork
(oc,
myNetBuilder
);
101
NIImporter_VISUM::loadNetwork
(oc,
myNetBuilder
);
102
NIImporter_ArcView::loadNetwork
(oc,
myNetBuilder
);
103
NIImporter_Vissim::loadNetwork
(oc,
myNetBuilder
);
104
NIImporter_DlrNavteq::loadNetwork
(oc,
myNetBuilder
);
105
NIImporter_OpenDrive::loadNetwork
(oc,
myNetBuilder
);
106
NIImporter_MATSim::loadNetwork
(oc,
myNetBuilder
);
107
NIImporter_ITSUMO::loadNetwork
(oc,
myNetBuilder
);
108
if
(oc.
getBool
(
"tls.discard-loaded"
) || oc.
getBool
(
"tls.discard-simple"
)) {
109
myNetBuilder
.
getNodeCont
().
discardTrafficLights
(
myNetBuilder
.
getTLLogicCont
(), oc.
getBool
(
"tls.discard-simple"
),
110
oc.
getBool
(
"tls.guess-signals"
));
111
size_t
removed =
myNetBuilder
.
getTLLogicCont
().
getNumExtracted
();
112
if
(removed > 0) {
113
WRITE_MESSAGE
(
" Removed "
+
toString
(removed) +
" traffic lights before loading plain-XML"
);
114
}
115
}
116
loadXML
(oc);
117
// check the loaded structures
118
if
(
myNetBuilder
.
getNodeCont
().
size
() == 0) {
119
throw
ProcessError
(
"No nodes loaded."
);
120
}
121
if
(
myNetBuilder
.
getEdgeCont
().
size
() == 0) {
122
throw
ProcessError
(
"No edges loaded."
);
123
}
124
// report loaded structures
125
WRITE_MESSAGE
(
" Import done:"
);
126
if
(
myNetBuilder
.
getDistrictCont
().
size
() > 0) {
127
WRITE_MESSAGE
(
" "
+
toString
(
myNetBuilder
.
getDistrictCont
().
size
()) +
" districts loaded."
);
128
}
129
WRITE_MESSAGE
(
" "
+
toString
(
myNetBuilder
.
getNodeCont
().
size
()) +
" nodes loaded."
);
130
if
(
myNetBuilder
.
getTypeCont
().
size
() > 0) {
131
WRITE_MESSAGE
(
" "
+
toString
(
myNetBuilder
.
getTypeCont
().
size
()) +
" types loaded."
);
132
}
133
WRITE_MESSAGE
(
" "
+
toString
(
myNetBuilder
.
getEdgeCont
().
size
()) +
" edges loaded."
);
134
if
(
myNetBuilder
.
getEdgeCont
().
getNoEdgeSplits
() > 0) {
135
WRITE_MESSAGE
(
"The split of edges was performed "
+
toString
(
myNetBuilder
.
getEdgeCont
().
getNoEdgeSplits
()) +
" times."
);
136
}
137
if
(
GeoConvHelper::getProcessing
().usingGeoProjection()) {
138
WRITE_MESSAGE
(
"Proj projection parameters used: '"
+
GeoConvHelper::getProcessing
().getProjString() +
"'."
);
139
}
140
}
141
142
143
/* -------------------------------------------------------------------------
144
* file loading methods
145
* ----------------------------------------------------------------------- */
146
void
147
NILoader::loadXML
(
OptionsCont
& oc) {
148
// load nodes
149
loadXMLType
(
new
NIXMLNodesHandler
(
myNetBuilder
.
getNodeCont
(),
150
myNetBuilder
.
getTLLogicCont
(), oc),
151
oc.
getStringVector
(
"node-files"
),
"nodes"
);
152
// load the edges
153
loadXMLType
(
new
NIXMLEdgesHandler
(
myNetBuilder
.
getNodeCont
(),
154
myNetBuilder
.
getEdgeCont
(),
155
myNetBuilder
.
getTypeCont
(),
156
myNetBuilder
.
getDistrictCont
(),
157
myNetBuilder
.
getTLLogicCont
(),
158
oc),
159
oc.
getStringVector
(
"edge-files"
),
"edges"
);
160
if
(!
deprecatedVehicleClassesSeen
.empty()) {
161
WRITE_WARNING
(
"Deprecated vehicle class(es) '"
+
toString
(
deprecatedVehicleClassesSeen
) +
"' in input edge files."
);
162
}
163
// load the connections
164
loadXMLType
(
new
NIXMLConnectionsHandler
(
myNetBuilder
.
getEdgeCont
(),
myNetBuilder
.
getTLLogicCont
()),
165
oc.
getStringVector
(
"connection-files"
),
"connections"
);
166
// load traffic lights (needs to come last, references loaded edges and connections)
167
loadXMLType
(
new
NIXMLTrafficLightsHandler
(
168
myNetBuilder
.
getTLLogicCont
(),
myNetBuilder
.
getEdgeCont
()),
169
oc.
getStringVector
(
"tllogic-files"
),
"traffic lights"
);
170
}
171
172
173
void
174
NILoader::loadXMLType
(
SUMOSAXHandler
* handler,
const
std::vector<std::string>& files,
175
const
std::string& type) {
176
// build parser
177
std::string exceptMsg =
""
;
178
// start the parsing
179
try
{
180
for
(std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
181
if
(!
FileHelpers::isReadable
(*file)) {
182
WRITE_ERROR
(
"Could not open "
+ type +
"-file '"
+ *file +
"'."
);
183
exceptMsg =
"Process Error"
;
184
continue
;
185
}
186
PROGRESS_BEGIN_MESSAGE
(
"Parsing "
+ type +
" from '"
+ *file +
"'"
);
187
XMLSubSys::runParser
(*handler, *file);
188
PROGRESS_DONE_MESSAGE
();
189
}
190
}
catch
(
const
XERCES_CPP_NAMESPACE::XMLException& toCatch) {
191
exceptMsg =
TplConvert::_2str
(toCatch.getMessage())
192
+
"\n The "
+ type +
" could not be loaded from '"
+ handler->
getFileName
() +
"'."
;
193
}
catch
(
const
ProcessError
& toCatch) {
194
exceptMsg = std::string(toCatch.what()) +
"\n The "
+ type +
" could not be loaded from '"
+ handler->
getFileName
() +
"'."
;
195
}
catch
(...) {
196
exceptMsg =
"The "
+ type +
" could not be loaded from '"
+ handler->
getFileName
() +
"'."
;
197
}
198
delete
handler;
199
if
(exceptMsg !=
""
) {
200
throw
ProcessError
(exceptMsg);
201
}
202
}
203
204
/****************************************************************************/
tmp
buildd
sumo-0.21.0+dfsg
src
netimport
NILoader.cpp
Generated on Thu Nov 20 2014 19:49:57 for SUMO - Simulation of Urban MObility by
1.8.1.2