Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/libtraci/POI.cpp
169665 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2017-2025 German Aerospace Center (DLR) and others.
4
// This program and the accompanying materials are made available under the
5
// terms of the Eclipse Public License 2.0 which is available at
6
// https://www.eclipse.org/legal/epl-2.0/
7
// This Source Code may also be made available under the following Secondary
8
// Licenses when the conditions for such availability set forth in the Eclipse
9
// Public License 2.0 are satisfied: GNU General Public License, version 2
10
// or later which is available at
11
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
/****************************************************************************/
14
/// @file POI.cpp
15
/// @author Daniel Krajzewicz
16
/// @author Mario Krumnow
17
/// @author Jakob Erdmann
18
/// @author Michael Behrisch
19
/// @author Robert Hilbrich
20
/// @date 30.05.2012
21
///
22
// C++ TraCI client API implementation
23
/****************************************************************************/
24
#include <config.h>
25
26
#define LIBTRACI 1
27
#include "Domain.h"
28
#include <libsumo/POI.h>
29
#include <libsumo/StorageHelper.h>
30
31
32
namespace libtraci {
33
34
typedef Domain<libsumo::CMD_GET_POI_VARIABLE, libsumo::CMD_SET_POI_VARIABLE> Dom;
35
36
// ===========================================================================
37
// static member definitions
38
// ===========================================================================
39
std::vector<std::string>
40
POI::getIDList() {
41
return Dom::getStringVector(libsumo::TRACI_ID_LIST, "");
42
}
43
44
45
int
46
POI::getIDCount() {
47
return Dom::getInt(libsumo::ID_COUNT, "");
48
}
49
50
51
std::string
52
POI::getType(const std::string& poiID) {
53
return Dom::getString(libsumo::VAR_TYPE, poiID);
54
}
55
56
57
libsumo::TraCIColor
58
POI::getColor(const std::string& poiID) {
59
return Dom::getCol(libsumo::VAR_COLOR, poiID);
60
}
61
62
63
libsumo::TraCIPosition
64
POI::getPosition(const std::string& poiID, const bool includeZ) {
65
return includeZ ? Dom::getPos3D(libsumo::VAR_POSITION3D, poiID) : Dom::getPos(libsumo::VAR_POSITION, poiID);
66
}
67
68
69
double
70
POI::getWidth(const std::string& poiID) {
71
return Dom::getDouble(libsumo::VAR_WIDTH, poiID);
72
}
73
74
75
double
76
POI::getHeight(const std::string& poiID) {
77
return Dom::getDouble(libsumo::VAR_HEIGHT, poiID);
78
}
79
80
81
double
82
POI::getAngle(const std::string& poiID) {
83
return Dom::getDouble(libsumo::VAR_ANGLE, poiID);
84
}
85
86
87
std::string
88
POI::getImageFile(const std::string& poiID) {
89
return Dom::getString(libsumo::VAR_IMAGEFILE, poiID);
90
}
91
92
93
LIBTRACI_PARAMETER_IMPLEMENTATION(POI, POI)
94
95
96
void
97
POI::setType(const std::string& poiID, const std::string& poiType) {
98
Dom::setString(libsumo::VAR_TYPE, poiID, poiType);
99
}
100
101
102
void
103
POI::setPosition(const std::string& poiID, double x, double y) {
104
tcpip::Storage content;
105
content.writeUnsignedByte(libsumo::POSITION_2D);
106
content.writeDouble(x);
107
content.writeDouble(y);
108
Dom::set(libsumo::VAR_POSITION, poiID, &content);
109
}
110
111
112
void
113
POI::setColor(const std::string& poiID, const libsumo::TraCIColor& c) {
114
Dom::setCol(libsumo::VAR_COLOR, poiID, c);
115
}
116
117
118
void
119
POI::setWidth(const std::string& poiID, double width) {
120
Dom::setDouble(libsumo::VAR_WIDTH, poiID, width);
121
}
122
123
124
void
125
POI::setHeight(const std::string& poiID, double height) {
126
Dom::setDouble(libsumo::VAR_HEIGHT, poiID, height);
127
}
128
129
130
void
131
POI::setAngle(const std::string& poiID, double angle) {
132
Dom::setDouble(libsumo::VAR_ANGLE, poiID, angle);
133
}
134
135
136
void
137
POI::setImageFile(const std::string& poiID, const std::string& imageFile) {
138
Dom::setString(libsumo::VAR_IMAGEFILE, poiID, imageFile);
139
}
140
141
142
bool
143
POI::add(const std::string& poiID, double x, double y, const libsumo::TraCIColor& color, const std::string& poiType,
144
int layer, const std::string& imgFile, double width, double height, double angle, const std::string& icon) {
145
tcpip::Storage content;
146
StoHelp::writeCompound(content, 9);
147
StoHelp::writeTypedString(content, poiType);
148
content.writeUnsignedByte(libsumo::TYPE_COLOR);
149
content.writeUnsignedByte(color.r);
150
content.writeUnsignedByte(color.g);
151
content.writeUnsignedByte(color.b);
152
content.writeUnsignedByte(color.a);
153
StoHelp::writeTypedInt(content, layer);
154
content.writeUnsignedByte(libsumo::POSITION_2D);
155
content.writeDouble(x);
156
content.writeDouble(y);
157
StoHelp::writeTypedString(content, imgFile);
158
StoHelp::writeTypedDouble(content, width);
159
StoHelp::writeTypedDouble(content, height);
160
StoHelp::writeTypedDouble(content, angle);
161
StoHelp::writeTypedString(content, icon);
162
Dom::set(libsumo::ADD, poiID, &content);
163
return true;
164
}
165
166
167
bool
168
POI::remove(const std::string& poiID, int layer) {
169
Dom::setInt(libsumo::REMOVE, poiID, layer);
170
return true;
171
}
172
173
174
void
175
POI::highlight(const std::string& poiID, const libsumo::TraCIColor& col, double size, const int alphaMax, const double duration, const int type) {
176
tcpip::Storage content;
177
StoHelp::writeCompound(content, alphaMax > 0 ? 5 : 2);
178
content.writeUnsignedByte(libsumo::TYPE_COLOR);
179
content.writeUnsignedByte(col.r);
180
content.writeUnsignedByte(col.g);
181
content.writeUnsignedByte(col.b);
182
content.writeUnsignedByte(col.a);
183
StoHelp::writeTypedDouble(content, size);
184
if (alphaMax > 0) {
185
content.writeUnsignedByte(libsumo::TYPE_UBYTE);
186
content.writeUnsignedByte(alphaMax);
187
StoHelp::writeTypedDouble(content, duration);
188
content.writeUnsignedByte(libsumo::TYPE_UBYTE);
189
content.writeUnsignedByte(type);
190
}
191
Dom::set(libsumo::VAR_HIGHLIGHT, poiID, &content);
192
}
193
194
195
LIBTRACI_SUBSCRIPTION_IMPLEMENTATION(POI, POI)
196
197
198
}
199
200
201
/****************************************************************************/
202
203