Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/traci-server/TraCIServerAPI_POI.cpp
193716 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2017-2026 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 TraCIServerAPI_POI.cpp
15
/// @author Daniel Krajzewicz
16
/// @author Laura Bieker
17
/// @author Michael Behrisch
18
/// @author Jakob Erdmann
19
/// @author Robert Hilbrich
20
/// @date 07.05.2009
21
///
22
// APIs for getting/setting POI values via TraCI
23
/****************************************************************************/
24
#include <config.h>
25
26
#include <microsim/MSNet.h>
27
#include <utils/shapes/PointOfInterest.h>
28
#include <utils/shapes/ShapeContainer.h>
29
#include <libsumo/POI.h>
30
#include <libsumo/StorageHelper.h>
31
#include <libsumo/TraCIConstants.h>
32
#include "TraCIServerAPI_POI.h"
33
34
35
// ===========================================================================
36
// method definitions
37
// ===========================================================================
38
bool
39
TraCIServerAPI_POI::processSet(TraCIServer& server, tcpip::Storage& inputStorage,
40
tcpip::Storage& outputStorage) {
41
std::string warning = ""; // additional description for response
42
// variable & id
43
int variable = inputStorage.readUnsignedByte();
44
std::string id = inputStorage.readString();
45
// check variable
46
if (variable != libsumo::VAR_TYPE &&
47
variable != libsumo::VAR_COLOR &&
48
variable != libsumo::VAR_POSITION &&
49
variable != libsumo::VAR_WIDTH &&
50
variable != libsumo::VAR_HEIGHT &&
51
variable != libsumo::VAR_ANGLE &&
52
variable != libsumo::VAR_IMAGEFILE &&
53
variable != libsumo::VAR_HIGHLIGHT &&
54
variable != libsumo::ADD &&
55
variable != libsumo::REMOVE &&
56
variable != libsumo::VAR_PARAMETER) {
57
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "Change PoI State: unsupported variable " + toHex(variable, 2) + " specified", outputStorage);
58
}
59
// process
60
try {
61
switch (variable) {
62
case libsumo::VAR_TYPE: {
63
libsumo::POI::setType(id, StoHelp::readTypedString(inputStorage, "The type must be given as a string."));
64
}
65
break;
66
case libsumo::VAR_COLOR: {
67
libsumo::POI::setColor(id, StoHelp::readTypedColor(inputStorage, "The color must be given using the according type."));
68
}
69
break;
70
case libsumo::VAR_POSITION: {
71
const libsumo::TraCIPosition pos = StoHelp::readTypedPosition2D(inputStorage, "The position must be given using an according type.");
72
libsumo::POI::setPosition(id, pos.x, pos.y);
73
}
74
break;
75
case libsumo::VAR_WIDTH: {
76
libsumo::POI::setWidth(id, StoHelp::readTypedDouble(inputStorage, "The width must be given as a double."));
77
}
78
break;
79
case libsumo::VAR_HEIGHT: {
80
libsumo::POI::setHeight(id, StoHelp::readTypedDouble(inputStorage, "The height must be given as a double."));
81
}
82
break;
83
case libsumo::VAR_ANGLE: {
84
libsumo::POI::setAngle(id, StoHelp::readTypedDouble(inputStorage, "The angle must be given as a double."));
85
}
86
break;
87
case libsumo::VAR_IMAGEFILE: {
88
libsumo::POI::setImageFile(id, StoHelp::readTypedString(inputStorage, "The image file must be given as a string."));
89
}
90
break;
91
case libsumo::VAR_HIGHLIGHT: {
92
const int parameterCount = StoHelp::readCompound(inputStorage, -1, "A compound object is needed for highlighting an object.");
93
if (parameterCount > 5) {
94
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "Highlighting an object needs zero to five parameters.", outputStorage);
95
}
96
libsumo::TraCIColor col = libsumo::TraCIColor(255, 0, 0);
97
if (parameterCount > 0) {
98
col = StoHelp::readTypedColor(inputStorage, "The first parameter for highlighting must be the highlight color.");
99
}
100
double size = -1;
101
if (parameterCount > 1) {
102
size = StoHelp::readTypedDouble(inputStorage, "The second parameter for highlighting must be the highlight size.");
103
}
104
int alphaMax = -1;
105
if (parameterCount > 2) {
106
alphaMax = StoHelp::readTypedUnsignedByte(inputStorage, "The third parameter for highlighting must be maximal alpha.");
107
}
108
double duration = -1;
109
if (parameterCount > 3) {
110
duration = StoHelp::readTypedDouble(inputStorage, "The fourth parameter for highlighting must be the highlight duration.");
111
}
112
int type = 0;
113
if (parameterCount > 4) {
114
type = StoHelp::readTypedUnsignedByte(inputStorage, "The fifth parameter for highlighting must be the highlight type id as ubyte.");
115
}
116
libsumo::POI::highlight(id, col, size, alphaMax, duration, type);
117
}
118
break;
119
case libsumo::ADD: {
120
const int parameterCount = StoHelp::readCompound(inputStorage, -1, "A compound object is needed for adding a new PoI.");
121
const std::string type = StoHelp::readTypedString(inputStorage, "The first PoI parameter must be the type encoded as a string.");
122
libsumo::TraCIColor col = StoHelp::readTypedColor(inputStorage, "The second PoI parameter must be the color.");
123
const int layer = StoHelp::readTypedInt(inputStorage, "The third PoI parameter must be the layer encoded as int.");
124
const libsumo::TraCIPosition pos = StoHelp::readTypedPosition2D(inputStorage, "The fourth PoI parameter must be the position.");
125
if (parameterCount == 4) {
126
if (!libsumo::POI::add(id, pos.x, pos.y, col, type, layer)) {
127
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "Could not add PoI.", outputStorage);
128
}
129
} else if (parameterCount >= 8) {
130
const std::string imgFile = StoHelp::readTypedString(inputStorage, "The fifth PoI parameter must be the imgFile encoded as a string.");
131
const double width = StoHelp::readTypedDouble(inputStorage, "The sixth PoI parameter must be the width encoded as a double.");
132
const double height = StoHelp::readTypedDouble(inputStorage, "The seventh PoI parameter must be the height encoded as a double.");
133
const double angle = StoHelp::readTypedDouble(inputStorage, "The eighth PoI parameter must be the angle encoded as a double.");
134
std::string icon;
135
if (parameterCount == 9) {
136
icon = StoHelp::readTypedString(inputStorage, "The ninth PoI parameter must be the icon encoded as a string.");
137
}
138
if (!libsumo::POI::add(id, pos.x, pos.y, col, type, layer, imgFile, width, height, angle, icon)) {
139
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "Could not add PoI.", outputStorage);
140
}
141
} else {
142
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE,
143
"Adding a PoI requires either only type, color, layer and position parameters or these and icon, imageFile, width, height and angle parameters.",
144
outputStorage);
145
}
146
}
147
break;
148
case libsumo::REMOVE: {
149
const int layer = StoHelp::readTypedInt(inputStorage, "The layer must be given using an int.");
150
if (!libsumo::POI::remove(id, layer)) {
151
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, "Could not remove PoI '" + id + "'", outputStorage);
152
}
153
}
154
break;
155
case libsumo::VAR_PARAMETER: {
156
StoHelp::readCompound(inputStorage, 2, "A compound object of size 2 is needed for setting a parameter.");
157
const std::string name = StoHelp::readTypedString(inputStorage, "The name of the parameter must be given as a string.");
158
const std::string value = StoHelp::readTypedString(inputStorage, "The value of the parameter must be given as a string.");
159
libsumo::POI::setParameter(id, name, value);
160
}
161
break;
162
default:
163
break;
164
}
165
} catch (libsumo::TraCIException& e) {
166
return server.writeErrorStatusCmd(libsumo::CMD_SET_POI_VARIABLE, e.what(), outputStorage);
167
}
168
server.writeStatusCmd(libsumo::CMD_SET_POI_VARIABLE, libsumo::RTYPE_OK, warning, outputStorage);
169
return true;
170
}
171
172
173
/****************************************************************************/
174
175