Eclipse SUMO - Simulation of Urban MObility
libtraci/Polygon.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 /****************************************************************************/
18 // C++ TraCI client API implementation
19 /****************************************************************************/
20 #include <config.h>
21 
22 #define LIBTRACI 1
23 #include "Domain.h"
24 #include <libsumo/Polygon.h>
25 #include <libsumo/StorageHelper.h>
26 
27 
28 namespace libtraci {
29 
30 typedef Domain<libsumo::CMD_GET_POLYGON_VARIABLE, libsumo::CMD_SET_POLYGON_VARIABLE> Dom;
31 
32 // ===========================================================================
33 // static member definitions
34 // ===========================================================================
35 std::vector<std::string>
36 Polygon::getIDList() {
38 }
39 
40 
41 int
42 Polygon::getIDCount() {
43  return Dom::getInt(libsumo::ID_COUNT, "");
44 }
45 
46 
47 std::string
48 Polygon::getType(const std::string& polygonID) {
49  return Dom::getString(libsumo::VAR_TYPE, polygonID);
50 }
51 
52 
54 Polygon::getShape(const std::string& polygonID) {
55  return Dom::getPolygon(libsumo::VAR_SHAPE, polygonID);
56 }
57 
58 
59 bool
60 Polygon::getFilled(const std::string& polygonID) {
61  return Dom::getInt(libsumo::VAR_FILL, polygonID) != 0;
62 }
63 
64 
65 double
66 Polygon::getLineWidth(const std::string& polygonID) {
67  return Dom::getDouble(libsumo::VAR_WIDTH, polygonID);
68 }
69 
70 
72 Polygon::getColor(const std::string& polygonID) {
73  return Dom::getCol(libsumo::VAR_COLOR, polygonID);
74 }
75 
76 
78 
79 
80 void
81 Polygon::setType(const std::string& polygonID, const std::string& polygonType) {
82  Dom::setString(libsumo::VAR_TYPE, polygonID, polygonType);
83 }
84 
85 
86 void
87 Polygon::setShape(const std::string& polygonID, const libsumo::TraCIPositionVector& shape) {
88  tcpip::Storage content;
89  StoHelp::writePolygon(content, shape);
90  return Dom::set(libsumo::VAR_SHAPE, polygonID, &content);
91 }
92 
93 
94 void
95 Polygon::setColor(const std::string& polygonID, const libsumo::TraCIColor& c) {
96  Dom::setCol(libsumo::VAR_COLOR, polygonID, c);
97 }
98 
99 
100 void
101 Polygon::add(const std::string& polygonID, const libsumo::TraCIPositionVector& shape, const libsumo::TraCIColor& color, bool fill, const std::string& polygonType, int layer, double lineWidth) {
102  tcpip::Storage content;
103  StoHelp::writeCompound(content, 6);
104  StoHelp::writeTypedString(content, polygonType);
106  content.writeUnsignedByte(color.r);
107  content.writeUnsignedByte(color.g);
108  content.writeUnsignedByte(color.b);
109  content.writeUnsignedByte(color.a);
111  content.writeUnsignedByte(fill);
112  StoHelp::writeTypedInt(content, layer);
113  StoHelp::writePolygon(content, shape);
114  StoHelp::writeTypedDouble(content, lineWidth);
115  Dom::set(libsumo::ADD, polygonID, &content);
116 }
117 
118 
119 void
120 Polygon::addDynamics(const std::string& polygonID, const std::string& trackedObjectID, const std::vector<double>& timeSpan, const std::vector<double>& alphaSpan, bool looped, bool rotate) {
121  tcpip::Storage content;
122  StoHelp::writeCompound(content, 5);
123  StoHelp::writeTypedString(content, trackedObjectID);
125  content.writeInt((int)timeSpan.size());
126  for (const double d : timeSpan) {
127  content.writeDouble(d);
128  }
130  content.writeInt((int)alphaSpan.size());
131  for (const double d : alphaSpan) {
132  content.writeDouble(d);
133  }
135  content.writeUnsignedByte(looped);
137  content.writeUnsignedByte(rotate);
138  Dom::set(libsumo::VAR_ADD_DYNAMICS, polygonID, &content);
139 }
140 
141 
142 void
143 Polygon::remove(const std::string& polygonID, int layer) {
144  Dom::setInt(libsumo::REMOVE, polygonID, layer);
145 }
146 
147 
148 void
149 Polygon::setFilled(std::string polygonID, bool filled) {
150  Dom::setInt(libsumo::VAR_FILL, polygonID, filled);
151 }
152 
153 
154 void
155 Polygon::setLineWidth(std::string polygonID, double lineWidth) {
156  Dom::setDouble(libsumo::VAR_WIDTH, polygonID, lineWidth);
157 }
158 
159 
161 
162 
163 }
164 
165 
166 /****************************************************************************/
#define LIBTRACI_SUBSCRIPTION_IMPLEMENTATION(CLASS, DOMAIN)
Definition: Domain.h:38
#define LIBTRACI_PARAMETER_IMPLEMENTATION(CLASS, DOMAIN)
Definition: Domain.h:77
A 2D- or 3D-polygon.
Definition: SUMOPolygon.h:34
static void writeTypedDouble(tcpip::Storage &content, double value)
static void writePolygon(tcpip::Storage &content, const libsumo::TraCIPositionVector &shape)
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 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 libsumo::TraCIPositionVector getPolygon(int var, const std::string &id, tcpip::Storage *add=nullptr)
Definition: Domain.h:135
static void set(int var, const std::string &id, tcpip::Storage *add)
Definition: Domain.h:219
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 writeInt(int)
Definition: storage.cpp:321
virtual void writeDouble(double)
Definition: storage.cpp:354
virtual void writeUnsignedByte(int)
Definition: storage.cpp:165
TRACI_CONST int TYPE_COLOR
TRACI_CONST int TRACI_ID_LIST
TRACI_CONST int VAR_TYPE
TRACI_CONST int TYPE_UBYTE
TRACI_CONST int VAR_COLOR
TRACI_CONST int VAR_WIDTH
TRACI_CONST int VAR_SHAPE
TRACI_CONST int ID_COUNT
TRACI_CONST int REMOVE
TRACI_CONST int VAR_ADD_DYNAMICS
TRACI_CONST int TYPE_DOUBLELIST
TRACI_CONST int VAR_FILL
TRACI_CONST int ADD
Domain< libsumo::CMD_GET_BUSSTOP_VARIABLE, libsumo::CMD_SET_BUSSTOP_VARIABLE > Dom
A list of positions.
Definition: TraCIDefs.h:234