Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/libtraci/Polygon.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 Polygon.cpp
15
/// @author Gregor Laemmel
16
/// @date 15.03.2017
17
///
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() {
37
return Dom::getStringVector(libsumo::TRACI_ID_LIST, "");
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
53
libsumo::TraCIPositionVector
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
71
libsumo::TraCIColor
72
Polygon::getColor(const std::string& polygonID) {
73
return Dom::getCol(libsumo::VAR_COLOR, polygonID);
74
}
75
76
77
LIBTRACI_PARAMETER_IMPLEMENTATION(Polygon, POLYGON)
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);
105
content.writeUnsignedByte(libsumo::TYPE_COLOR);
106
content.writeUnsignedByte(color.r);
107
content.writeUnsignedByte(color.g);
108
content.writeUnsignedByte(color.b);
109
content.writeUnsignedByte(color.a);
110
content.writeUnsignedByte(libsumo::TYPE_UBYTE);
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);
124
content.writeUnsignedByte(libsumo::TYPE_DOUBLELIST);
125
content.writeInt((int)timeSpan.size());
126
for (const double d : timeSpan) {
127
content.writeDouble(d);
128
}
129
content.writeUnsignedByte(libsumo::TYPE_DOUBLELIST);
130
content.writeInt((int)alphaSpan.size());
131
for (const double d : alphaSpan) {
132
content.writeDouble(d);
133
}
134
content.writeUnsignedByte(libsumo::TYPE_UBYTE);
135
content.writeUnsignedByte(looped);
136
content.writeUnsignedByte(libsumo::TYPE_UBYTE);
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
160
LIBTRACI_SUBSCRIPTION_IMPLEMENTATION(Polygon, POLYGON)
161
162
163
}
164
165
166
/****************************************************************************/
167
168