Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/libtraci/GUI.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 GUI.cpp
15
/// @author Michael Behrisch
16
/// @date 07.04.2021
17
///
18
// C++ TraCI client API implementation
19
/****************************************************************************/
20
#include <config.h>
21
22
#define LIBTRACI 1
23
#include "Domain.h"
24
#include <libsumo/GUI.h>
25
26
27
namespace libtraci {
28
29
typedef Domain<libsumo::CMD_GET_GUI_VARIABLE, libsumo::CMD_SET_GUI_VARIABLE> Dom;
30
31
// ===========================================================================
32
// static member definitions
33
// ===========================================================================
34
std::vector<std::string>
35
GUI::getIDList() {
36
return Dom::getStringVector(libsumo::TRACI_ID_LIST, "");
37
}
38
39
40
int
41
GUI::getIDCount() {
42
return Dom::getInt(libsumo::ID_COUNT, "");
43
}
44
45
46
double
47
GUI::getZoom(const std::string& viewID) {
48
return Dom::getDouble(libsumo::VAR_VIEW_ZOOM, viewID);
49
}
50
51
52
double
53
GUI::getAngle(const std::string& viewID) {
54
return Dom::getDouble(libsumo::VAR_ANGLE, viewID);
55
}
56
57
58
libsumo::TraCIPosition
59
GUI::getOffset(const std::string& viewID) {
60
return Dom::getPos(libsumo::VAR_VIEW_OFFSET, viewID);
61
}
62
63
64
std::string
65
GUI::getSchema(const std::string& viewID) {
66
return Dom::getString(libsumo::VAR_VIEW_SCHEMA, viewID);
67
}
68
69
70
libsumo::TraCIPositionVector
71
GUI::getBoundary(const std::string& viewID) {
72
return Dom::getPolygon(libsumo::VAR_VIEW_BOUNDARY, viewID);
73
}
74
75
76
LIBTRACI_PARAMETER_IMPLEMENTATION(GUI, GUI)
77
78
79
void
80
GUI::setZoom(const std::string& viewID, double zoom) {
81
Dom::setDouble(libsumo::VAR_VIEW_ZOOM, viewID, zoom);
82
}
83
84
85
void
86
GUI::setAngle(const std::string& viewID, double angle) {
87
Dom::setDouble(libsumo::VAR_ANGLE, viewID, angle);
88
}
89
90
91
void
92
GUI::setOffset(const std::string& viewID, double x, double y) {
93
tcpip::Storage content;
94
content.writeUnsignedByte(libsumo::POSITION_2D);
95
content.writeDouble(x);
96
content.writeDouble(y);
97
Dom::set(libsumo::VAR_VIEW_OFFSET, viewID, &content);
98
}
99
100
101
void
102
GUI::setSchema(const std::string& viewID, const std::string& schemeName) {
103
Dom::setString(libsumo::VAR_VIEW_SCHEMA, viewID, schemeName);
104
}
105
106
void
107
GUI::addView(const std::string& viewID, const std::string& schemeName, bool in3D) {
108
tcpip::Storage content;
109
StoHelp::writeCompound(content, 2);
110
StoHelp::writeTypedString(content, schemeName);
111
StoHelp::writeTypedInt(content, in3D ? 1 : 0);
112
Dom::set(libsumo::ADD, viewID, &content);
113
}
114
115
void
116
GUI::removeView(const std::string& viewID) {
117
Dom::set(libsumo::REMOVE, viewID, nullptr);
118
}
119
120
121
void
122
GUI::setBoundary(const std::string& viewID, double xmin, double ymin, double xmax, double ymax) {
123
tcpip::Storage content;
124
content.writeUnsignedByte(libsumo::TYPE_POLYGON);
125
content.writeUnsignedByte(2);
126
content.writeDouble(xmin);
127
content.writeDouble(ymin);
128
content.writeDouble(xmax);
129
content.writeDouble(ymax);
130
Dom::set(libsumo::VAR_VIEW_BOUNDARY, viewID, &content);
131
}
132
133
134
void
135
GUI::screenshot(const std::string& viewID, const std::string& filename, const int width, const int height) {
136
tcpip::Storage content;
137
StoHelp::writeCompound(content, 3);
138
StoHelp::writeTypedString(content, filename);
139
StoHelp::writeTypedInt(content, width);
140
StoHelp::writeTypedInt(content, height);
141
Dom::set(libsumo::VAR_SCREENSHOT, viewID, &content);
142
}
143
144
145
void
146
GUI::trackVehicle(const std::string& viewID, const std::string& vehID) {
147
Dom::setString(libsumo::VAR_TRACK_VEHICLE, viewID, vehID);
148
}
149
150
151
bool
152
GUI::hasView(const std::string& viewID) {
153
return Dom::getInt(libsumo::VAR_HAS_VIEW, viewID) != 0;
154
}
155
156
157
std::string
158
GUI::getTrackedVehicle(const std::string& viewID) {
159
return Dom::getString(libsumo::VAR_TRACK_VEHICLE, viewID);
160
}
161
162
163
void
164
GUI::track(const std::string& objID, const std::string& viewID) {
165
Dom::setString(libsumo::VAR_TRACK_VEHICLE, viewID, objID);
166
}
167
168
169
bool
170
GUI::isSelected(const std::string& objID, const std::string& objType) {
171
tcpip::Storage content;
172
StoHelp::writeTypedString(content, objType);
173
return Dom::getInt(libsumo::VAR_SELECT, objID, &content) != 0;
174
}
175
176
177
void
178
GUI::toggleSelection(const std::string& objID, const std::string& objType) {
179
Dom::setString(libsumo::VAR_SELECT, objID, objType);
180
}
181
182
183
LIBTRACI_SUBSCRIPTION_IMPLEMENTATION(GUI, GUI)
184
185
186
}
187
188
189
/****************************************************************************/
190
191