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
ShapeContainer.cpp
Go to the documentation of this file.
1
/****************************************************************************/
9
// Storage for geometrical objects, sorted by the layers they are in
10
/****************************************************************************/
11
// SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
12
// Copyright (C) 2001-2012 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 <fstream>
34
#include <stdlib.h>
35
#include <iostream>
36
#include <utility>
37
#include <string>
38
#include <cmath>
39
#include <
utils/common/NamedObjectCont.h
>
40
#include <
utils/shapes/PointOfInterest.h
>
41
#include <
utils/shapes/Polygon.h
>
42
#include <
utils/shapes/ShapeContainer.h
>
43
#include <
utils/common/MsgHandler.h
>
44
#include <
utils/common/UtilExceptions.h
>
45
#include <
utils/common/ToString.h
>
46
#include <
utils/common/StdDefs.h
>
47
48
#ifdef CHECK_MEMORY_LEAKS
49
#include <
foreign/nvwa/debug_new.h
>
50
#endif // CHECK_MEMORY_LEAKS
51
52
53
// ===========================================================================
54
// method definitions
55
// ===========================================================================
56
ShapeContainer::ShapeContainer
()
57
: myMinLayer(100), myMaxLayer(-100) {}
58
59
60
ShapeContainer::~ShapeContainer
() {}
61
62
63
bool
64
ShapeContainer::addPoI
(
const
std::string& name,
int
layer,
const
std::string& type,
const
RGBColor
& c,
65
const
Position
& pos) {
66
PointOfInterest
* p =
new
PointOfInterest
(name, type, pos, c);
67
if
(!
add
(layer, p)) {
68
delete
p;
69
return
false
;
70
}
71
return
true
;
72
}
73
74
75
bool
76
ShapeContainer::addPolygon
(
const
std::string& name,
int
layer,
const
std::string& type,
const
RGBColor
& c,
77
bool
filled,
const
PositionVector
& shape) {
78
Polygon
* p =
new
Polygon
(name, type, c, shape, filled);
79
if
(!
add
(layer, p)) {
80
delete
p;
81
return
false
;
82
}
83
return
true
;
84
}
85
86
87
88
bool
89
ShapeContainer::removePolygon
(
int
layer,
const
std::string&
id
) {
90
if
(
myPolygonLayers
.find(layer) ==
myPolygonLayers
.end()) {
91
return
false
;
92
}
93
return
myPolygonLayers
.find(layer)->second.remove(
id
);
94
}
95
96
97
bool
98
ShapeContainer::removePoI
(
int
layer,
const
std::string&
id
) {
99
if
(
myPOILayers
.find(layer) ==
myPOILayers
.end()) {
100
return
false
;
101
}
102
return
myPOILayers
.find(layer)->second.remove(
id
);
103
}
104
105
106
107
void
108
ShapeContainer::movePoI
(
int
layer,
const
std::string&
id
,
const
Position
& pos) {
109
if
(
myPOILayers
.find(layer) !=
myPOILayers
.end()) {
110
PointOfInterest
* p =
myPOILayers
.find(layer)->second.get(
id
);
111
if
(p != 0) {
112
static_cast<
Position
*
>
(p)->
set
(pos);
113
}
114
}
115
}
116
117
118
void
119
ShapeContainer::reshapePolygon
(
int
layer,
const
std::string&
id
,
const
PositionVector
& shape) {
120
if
(
myPolygonLayers
.find(layer) !=
myPolygonLayers
.end()) {
121
Polygon
* p =
myPolygonLayers
.find(layer)->second.get(
id
);
122
if
(p != 0) {
123
p->
setShape
(shape);
124
}
125
}
126
}
127
128
129
130
const
NamedObjectCont<Polygon*>
&
131
ShapeContainer::getPolygonCont
(
int
layer)
const
{
132
if
(
myPolygonLayers
.find(layer) ==
myPolygonLayers
.end()) {
133
myPolygonLayers
[layer] =
NamedObjectCont<Polygon*>
();
134
myMinLayer
=
MIN2
(layer, myMinLayer);
135
myMaxLayer
=
MAX2
(layer,
myMaxLayer
);
136
}
137
return
myPolygonLayers
[layer];
138
}
139
140
141
const
NamedObjectCont<PointOfInterest*>
&
142
ShapeContainer::getPOICont
(
int
layer)
const
{
143
if
(
myPOILayers
.find(layer) ==
myPOILayers
.end()) {
144
myPOILayers
[layer] =
NamedObjectCont<PointOfInterest*>
();
145
myMinLayer
=
MIN2
(layer, myMinLayer);
146
myMaxLayer
=
MAX2
(layer,
myMaxLayer
);
147
}
148
return
myPOILayers
[layer];
149
}
150
151
152
153
bool
154
ShapeContainer::add
(
int
layer,
Polygon
* p) {
155
if
(
myPolygonLayers
.find(layer) ==
myPolygonLayers
.end()) {
156
myPolygonLayers
[layer] =
NamedObjectCont<Polygon*>
();
157
myMinLayer
=
MIN2
(layer, myMinLayer);
158
myMaxLayer
=
MAX2
(layer,
myMaxLayer
);
159
}
160
return
myPolygonLayers
[layer].add(p->
getID
(), p);
161
}
162
163
164
bool
165
ShapeContainer::add
(
int
layer,
PointOfInterest
* p) {
166
if
(
myPOILayers
.find(layer) ==
myPOILayers
.end()) {
167
myPOILayers
[layer] =
NamedObjectCont<PointOfInterest*>
();
168
myMinLayer
=
MIN2
(layer, myMinLayer);
169
myMaxLayer
=
MAX2
(layer,
myMaxLayer
);
170
}
171
return
myPOILayers
[layer].add(p->
getID
(), p);
172
}
173
174
175
176
/****************************************************************************/
177
tmp
buildd
sumo-0.15.0~dfsg
src
utils
shapes
ShapeContainer.cpp
Generated on Sun May 27 2012 14:52:11 for SUMO - Simulation of Urban MObility by
1.8.1