forked from cyberbotics/webots
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathField.cpp
More file actions
259 lines (198 loc) · 7.01 KB
/
Field.cpp
File metadata and controls
259 lines (198 loc) · 7.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
// Copyright 1996-2023 Cyberbotics Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#define WB_ALLOW_MIXING_C_AND_CPP_API
#include <webots/supervisor.h>
#include <webots/Field.hpp>
#include <stdio.h>
#include <map>
using namespace std;
using namespace webots;
static map<WbFieldRef, Field *> fieldMap;
Field *Field::findField(WbFieldRef ref) {
if (!ref)
return NULL;
map<WbFieldRef, Field *>::iterator iter = fieldMap.find(ref);
if (iter != fieldMap.end())
return iter->second;
Field *field = new Field(ref);
fieldMap.insert(pair<WbFieldRef, Field *>(ref, field));
return field;
}
void Field::cleanup() {
map<WbFieldRef, Field *>::iterator iter;
for (iter = fieldMap.begin(); iter != fieldMap.end(); ++iter)
delete (*iter).second;
fieldMap.clear();
}
Field::Field(WbFieldRef ref) {
fieldRef = ref;
}
Field::Type Field::getType() const {
return Type(wb_supervisor_field_get_type(fieldRef));
}
void Field::enableSFTracking(int samplingPeriod) {
wb_supervisor_field_enable_sf_tracking(fieldRef, samplingPeriod);
}
void Field::disableSFTracking() {
wb_supervisor_field_disable_sf_tracking(fieldRef);
}
std::string Field::getTypeName() const {
return string(wb_supervisor_field_get_type_name(fieldRef));
}
std::string Field::getName() const {
return string(wb_supervisor_field_get_name(fieldRef));
}
int Field::getCount() const {
return wb_supervisor_field_get_count(fieldRef);
}
bool Field::getSFBool() const {
return wb_supervisor_field_get_sf_bool(fieldRef);
}
int Field::getSFInt32() const {
return wb_supervisor_field_get_sf_int32(fieldRef);
}
double Field::getSFFloat() const {
return wb_supervisor_field_get_sf_float(fieldRef);
}
const double *Field::getSFVec2f() const {
return wb_supervisor_field_get_sf_vec2f(fieldRef);
}
const double *Field::getSFVec3f() const {
return wb_supervisor_field_get_sf_vec3f(fieldRef);
}
const double *Field::getSFRotation() const {
return wb_supervisor_field_get_sf_rotation(fieldRef);
}
const double *Field::getSFColor() const {
return wb_supervisor_field_get_sf_color(fieldRef);
}
string Field::getSFString() const {
return string(wb_supervisor_field_get_sf_string(fieldRef));
}
Node *Field::getSFNode() const {
WbNodeRef nodeRef = wb_supervisor_field_get_sf_node(fieldRef);
return Node::findNode(nodeRef);
}
bool Field::getMFBool(int index) const {
return wb_supervisor_field_get_mf_bool(fieldRef, index);
}
int Field::getMFInt32(int index) const {
return wb_supervisor_field_get_mf_int32(fieldRef, index);
}
double Field::getMFFloat(int index) const {
return wb_supervisor_field_get_mf_float(fieldRef, index);
}
const double *Field::getMFVec2f(int index) const {
return wb_supervisor_field_get_mf_vec2f(fieldRef, index);
}
const double *Field::getMFVec3f(int index) const {
return wb_supervisor_field_get_mf_vec3f(fieldRef, index);
}
const double *Field::getMFRotation(int index) const {
return wb_supervisor_field_get_mf_rotation(fieldRef, index);
}
const double *Field::getMFColor(int index) const {
return wb_supervisor_field_get_mf_color(fieldRef, index);
}
string Field::getMFString(int index) const {
return string(wb_supervisor_field_get_mf_string(fieldRef, index));
}
Node *Field::getMFNode(int index) const {
WbNodeRef nodeRef = wb_supervisor_field_get_mf_node(fieldRef, index);
return Node::findNode(nodeRef);
}
void Field::setSFBool(bool value) {
wb_supervisor_field_set_sf_bool(fieldRef, value);
}
void Field::setSFInt32(int value) {
wb_supervisor_field_set_sf_int32(fieldRef, value);
}
void Field::setSFFloat(double value) {
wb_supervisor_field_set_sf_float(fieldRef, value);
}
void Field::setSFVec2f(const double values[2]) {
wb_supervisor_field_set_sf_vec2f(fieldRef, values);
}
void Field::setSFVec3f(const double values[3]) {
wb_supervisor_field_set_sf_vec3f(fieldRef, values);
}
void Field::setSFRotation(const double values[4]) {
wb_supervisor_field_set_sf_rotation(fieldRef, values);
}
void Field::setSFColor(const double values[4]) {
wb_supervisor_field_set_sf_color(fieldRef, values);
}
void Field::setSFString(const string &value) {
wb_supervisor_field_set_sf_string(fieldRef, value.c_str());
}
void Field::setMFBool(int index, bool value) {
wb_supervisor_field_set_mf_bool(fieldRef, index, value);
}
void Field::setMFInt32(int index, int value) {
wb_supervisor_field_set_mf_int32(fieldRef, index, value);
}
void Field::setMFFloat(int index, double value) {
wb_supervisor_field_set_mf_float(fieldRef, index, value);
}
void Field::setMFVec2f(int index, const double values[2]) {
wb_supervisor_field_set_mf_vec2f(fieldRef, index, values);
}
void Field::setMFVec3f(int index, const double values[3]) {
wb_supervisor_field_set_mf_vec3f(fieldRef, index, values);
}
void Field::setMFRotation(int index, const double values[4]) {
wb_supervisor_field_set_mf_rotation(fieldRef, index, values);
}
void Field::setMFColor(int index, const double values[3]) {
wb_supervisor_field_set_mf_color(fieldRef, index, values);
}
void Field::setMFString(int index, const string &value) {
wb_supervisor_field_set_mf_string(fieldRef, index, value.c_str());
}
void Field::insertMFBool(int index, bool value) {
wb_supervisor_field_insert_mf_bool(fieldRef, index, value);
}
void Field::insertMFInt32(int index, int value) {
wb_supervisor_field_insert_mf_int32(fieldRef, index, value);
}
void Field::insertMFFloat(int index, double value) {
wb_supervisor_field_insert_mf_float(fieldRef, index, value);
}
void Field::insertMFVec2f(int index, const double values[2]) {
wb_supervisor_field_insert_mf_vec2f(fieldRef, index, values);
}
void Field::insertMFVec3f(int index, const double values[3]) {
wb_supervisor_field_insert_mf_vec3f(fieldRef, index, values);
}
void Field::insertMFRotation(int index, const double values[4]) {
wb_supervisor_field_insert_mf_rotation(fieldRef, index, values);
}
void Field::insertMFColor(int index, const double values[3]) {
wb_supervisor_field_insert_mf_color(fieldRef, index, values);
}
void Field::insertMFString(int index, const std::string &value) {
wb_supervisor_field_insert_mf_string(fieldRef, index, value.c_str());
}
void Field::removeMF(int index) {
wb_supervisor_field_remove_mf(fieldRef, index);
}
void Field::removeSF() {
wb_supervisor_field_remove_sf(fieldRef);
}
void Field::importMFNodeFromString(int position, const std::string &nodeString) {
wb_supervisor_field_import_mf_node_from_string(fieldRef, position, nodeString.c_str());
}
void Field::importSFNodeFromString(const std::string &nodeString) {
wb_supervisor_field_import_sf_node_from_string(fieldRef, nodeString.c_str());
}