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
GeomConvHelper.cpp
Go to the documentation of this file.
1
/****************************************************************************/
9
// Some helping functions for geometry parsing
10
/****************************************************************************/
11
// SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
12
// Copyright (C) 2001-2014 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 <sstream>
35
#include <
utils/geom/PositionVector.h
>
36
#include <
utils/common/MsgHandler.h
>
37
#include <
utils/common/StringTokenizer.h
>
38
#include <
utils/common/TplConvert.h
>
39
#include "
GeomConvHelper.h
"
40
41
#ifdef CHECK_MEMORY_LEAKS
42
#include <
foreign/nvwa/debug_new.h
>
43
#endif // CHECK_MEMORY_LEAKS
44
45
46
// ===========================================================================
47
// method definitions
48
// ===========================================================================
49
PositionVector
50
GeomConvHelper::parseShapeReporting
(
const
std::string& shpdef,
const
std::string& objecttype,
51
const
char
* objectid,
bool
& ok,
bool
allowEmpty,
bool
report) {
52
if
(shpdef ==
""
) {
53
if
(!allowEmpty) {
54
emitError
(report,
"Shape"
, objecttype, objectid,
"the shape is empty"
);
55
ok =
false
;
56
}
57
return
PositionVector
();
58
}
59
StringTokenizer
st(shpdef,
" "
);
60
PositionVector
shape;
61
while
(st.
hasNext
()) {
62
StringTokenizer
pos(st.
next
(),
","
);
63
if
(pos.size() != 2 && pos.size() != 3) {
64
emitError
(report,
"Shape"
, objecttype, objectid,
"the position is neither x,y nor x,y,z"
);
65
ok =
false
;
66
return
PositionVector
();
67
}
68
try
{
69
SUMOReal
x =
TplConvert::_2SUMOReal
(pos.next().c_str());
70
SUMOReal
y =
TplConvert::_2SUMOReal
(pos.next().c_str());
71
if
(pos.size() == 2) {
72
shape.
push_back
(
Position
(x, y));
73
}
else
{
74
SUMOReal
z =
TplConvert::_2SUMOReal
(pos.next().c_str());
75
shape.
push_back
(
Position
(x, y, z));
76
}
77
}
catch
(
NumberFormatException
&) {
78
emitError
(report,
"Shape"
, objecttype, objectid,
"not numeric position entry"
);
79
ok =
false
;
80
return
PositionVector
();
81
}
catch
(
EmptyData
&) {
82
emitError
(report,
"Shape"
, objecttype, objectid,
"empty position entry"
);
83
ok =
false
;
84
return
PositionVector
();
85
}
86
}
87
return
shape;
88
}
89
90
91
Boundary
92
GeomConvHelper::parseBoundaryReporting
(
const
std::string& def,
const
std::string& objecttype,
93
const
char
* objectid,
bool
& ok,
bool
report) {
94
StringTokenizer
st(def,
","
);
95
if
(st.
size
() != 4) {
96
emitError
(report,
"Bounding box"
, objecttype, objectid,
"mismatching entry number"
);
97
ok =
false
;
98
return
Boundary
();
99
}
100
try
{
101
SUMOReal
xmin =
TplConvert::_2SUMOReal
(st.
next
().c_str());
102
SUMOReal
ymin =
TplConvert::_2SUMOReal
(st.
next
().c_str());
103
SUMOReal
xmax =
TplConvert::_2SUMOReal
(st.
next
().c_str());
104
SUMOReal
ymax =
TplConvert::_2SUMOReal
(st.
next
().c_str());
105
return
Boundary
(xmin, ymin, xmax, ymax);
106
}
catch
(
NumberFormatException
&) {
107
emitError
(report,
"Shape"
, objecttype, objectid,
"not numeric entry"
);
108
}
catch
(
EmptyData
&) {
109
emitError
(report,
"Shape"
, objecttype, objectid,
"empty entry"
);
110
}
111
ok =
false
;
112
return
Boundary
();
113
}
114
115
116
void
117
GeomConvHelper::emitError
(
bool
report,
const
std::string& what,
const
std::string& objecttype,
118
const
char
* objectid,
const
std::string& desc) {
119
if
(!report) {
120
return
;
121
}
122
std::ostringstream oss;
123
oss << what <<
" of "
;
124
if
(objectid == 0) {
125
oss <<
"a(n) "
;
126
}
127
oss << objecttype;
128
if
(objectid != 0) {
129
oss <<
" '"
<< objectid <<
"'"
;
130
}
131
oss <<
" is broken: "
<< desc <<
"."
;
132
WRITE_ERROR
(oss.str());
133
}
134
135
136
137
/****************************************************************************/
138
tmp
buildd
sumo-0.21.0+dfsg
src
utils
geom
GeomConvHelper.cpp
Generated on Thu Nov 20 2014 19:49:53 for SUMO - Simulation of Urban MObility by
1.8.1.2