Eclipse SUMO - Simulation of Urban MObility
libtraci/POI.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 // Copyright (C) 2017-2024 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 /****************************************************************************/
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() {
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 
58 POI::getColor(const std::string& poiID) {
59  return Dom::getCol(libsumo::VAR_COLOR, poiID);
60 }
61 
62 
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) {
90 }
91 
92 
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;
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);
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);
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);
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) {
186  content.writeUnsignedByte(alphaMax);
187  StoHelp::writeTypedDouble(content, duration);
189  content.writeUnsignedByte(type);
190  }
191  Dom::set(libsumo::VAR_HIGHLIGHT, poiID, &content);
192 }
193 
194 
196 
197 
198 }
199 
200 
201 /****************************************************************************/
#define LIBTRACI_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOMAIN)
Definition: Domain.h:38
#define LIBTRACI_PARAMETER_IMPLEMENTATION(CLASS, DOMAIN)
Definition: Domain.h:77
C++ TraCI client API implementation.
Definition: POI.h:34
static void writeTypedDouble(tcpip::Storage &content, double value)
static void writeCompound(tcpip::Storage &content, int size)
static void writeTypedInt(tcpip::Storage &content, int value)
static void writeTypedString(tcpip::Storage &content, const std::string &value)
static void setDouble(int var, const std::string &id, double value)
Definition: Domain.h:231
static libsumo::TraCIPosition getPos(int var, const std::string &id, tcpip::Storage *add=nullptr, const bool isGeo=false)
Definition: Domain.h:153
static void setCol(int var, const std::string &id, const libsumo::TraCIColor value)
Definition: Domain.h:252
static std::vector< std::string > getStringVector(int var, const std::string &id, tcpip::Storage *add=nullptr)
Definition: Domain.h:177
static libsumo::TraCIColor getCol(int var, const std::string &id, tcpip::Storage *add=nullptr)
Definition: Domain.h:187
static std::string getString(int var, const std::string &id, tcpip::Storage *add=nullptr)
Definition: Domain.h:172
static int getInt(int var, const std::string &id, tcpip::Storage *add=nullptr)
Definition: Domain.h:125
static void set(int var, const std::string &id, tcpip::Storage *add)
Definition: Domain.h:219
static libsumo::TraCIPosition getPos3D(int var, const std::string &id, tcpip::Storage *add=nullptr, const bool isGeo=false)
Definition: Domain.h:162
static double getDouble(int var, const std::string &id, tcpip::Storage *add=nullptr)
Definition: Domain.h:130
static void setInt(int var, const std::string &id, int value)
Definition: Domain.h:224
static void setString(int var, const std::string &id, const std::string &value)
Definition: Domain.h:238
virtual void writeDouble(double)
Definition: storage.cpp:354
virtual void writeUnsignedByte(int)
Definition: storage.cpp:165
TRACI_CONST int TYPE_COLOR
TRACI_CONST int VAR_IMAGEFILE
TRACI_CONST int TRACI_ID_LIST
TRACI_CONST int VAR_TYPE
TRACI_CONST int VAR_ANGLE
TRACI_CONST int VAR_HIGHLIGHT
TRACI_CONST int TYPE_UBYTE
TRACI_CONST int VAR_COLOR
TRACI_CONST int VAR_POSITION
TRACI_CONST int VAR_WIDTH
TRACI_CONST int POSITION_2D
TRACI_CONST int ID_COUNT
TRACI_CONST int REMOVE
TRACI_CONST int VAR_HEIGHT
TRACI_CONST int VAR_POSITION3D
TRACI_CONST int ADD
Domain< libsumo::CMD_GET_BUSSTOP_VARIABLE, libsumo::CMD_SET_BUSSTOP_VARIABLE > Dom
A 2D or 3D-position, for 2D positions z == INVALID_DOUBLE_VALUE.
Definition: TraCIDefs.h:178