-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathClient.h
More file actions
214 lines (156 loc) · 7.21 KB
/
Copy pathClient.h
File metadata and controls
214 lines (156 loc) · 7.21 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
#pragma once
#include <mc_control/ControllerClient.h>
#include <mc_control/ControllerServer.h>
#include <mc_rbdyn/Robots.h>
#include "InteractiveMarker.h"
#include "LogSink.h"
#include "RobotModel.h"
#include "SceneState.h"
#include "widgets/Category.h"
/* Typedef for brievity */
using ElementId = mc_control::ElementId;
struct Client : public mc_control::ControllerClient
{
/** Same constructors as the base class */
using mc_control::ControllerClient::ControllerClient;
/** Bring-in stop to kill the connection */
using mc_control::ControllerClient::stop;
/** Register the log sink */
void register_log_sink();
/** Update the client data from the latest server message */
void update(SceneState & state);
/** Draw 2D elements */
void draw2D();
/** Draw 3D elements */
void draw3D(Camera camera);
/** Remove all elements */
void clear();
/** Clear the log console */
void clearConsole();
inline const mc_rtc::Configuration & data() const noexcept
{
return data_;
}
private:
LogSinkPtr sink_;
SuccessSinkPtr successSink_;
std::vector<char> buffer_ = std::vector<char>(65535);
std::chrono::system_clock::time_point t_last_ = std::chrono::system_clock::now();
/** No message for unsupported types */
void default_impl(const std::string &, const ElementId &) final {}
void started() override;
void category(const std::vector<std::string> &, const std::string &) override;
void label(const ElementId & id, const std::string & txt) override;
void array_label(const ElementId & id,
const std::vector<std::string> & labels,
const Eigen::VectorXd & data) override;
void button(const ElementId & id) override;
void checkbox(const ElementId & id, bool state) override;
void string_input(const ElementId & id, const std::string & data) override;
void integer_input(const ElementId & id, int data) override;
void number_input(const ElementId & id, double data) override;
void number_slider(const ElementId & id, double data, double min, double max) override;
void array_input(const ElementId & id,
const std::vector<std::string> & labels,
const Eigen::VectorXd & data) override;
void combo_input(const ElementId & id, const std::vector<std::string> & values, const std::string & data) override;
void data_combo_input(const ElementId & id, const std::vector<std::string> & ref, const std::string & data) override;
void point3d(const ElementId & id,
const ElementId & requestId,
bool ro,
const Eigen::Vector3d & pos,
const mc_rtc::gui::PointConfig & config) override;
void trajectory(const ElementId & id,
const std::vector<Eigen::Vector3d> & points,
const mc_rtc::gui::LineConfig & config) override;
void trajectory(const ElementId & id,
const std::vector<sva::PTransformd> & points,
const mc_rtc::gui::LineConfig & config) override;
void trajectory(const ElementId & id, const Eigen::Vector3d & point, const mc_rtc::gui::LineConfig & config) override;
void trajectory(const ElementId & id,
const sva::PTransformd & point,
const mc_rtc::gui::LineConfig & config) override;
void polygon(const ElementId & id,
const std::vector<std::vector<Eigen::Vector3d>> & points,
const mc_rtc::gui::Color & color) override;
void force(const ElementId & id,
const ElementId & requestId,
const sva::ForceVecd & force,
const sva::PTransformd & pos,
const mc_rtc::gui::ForceConfig & forceConfig,
bool /* ro */) override;
void arrow(const ElementId & id,
const ElementId & requestId,
const Eigen::Vector3d & start,
const Eigen::Vector3d & end,
const mc_rtc::gui::ArrowConfig & config,
bool ro) override;
void rotation(const ElementId & id, const ElementId & requestId, bool ro, const sva::PTransformd & pos) override;
void transform(const ElementId & id, const ElementId & requestId, bool ro, const sva::PTransformd & pos) override;
void xytheta(const ElementId & id,
const ElementId & requestId,
bool ro,
const Eigen::Vector3d & xytheta,
double altitude) override;
void table_start(const ElementId & id, const std::vector<std::string> & header) override;
void table_row(const ElementId & id, const std::vector<std::string> & data) override;
void table_end(const ElementId & id) override;
void robot(const ElementId & id,
const std::vector<std::string> & params,
const std::vector<std::vector<double>> & q,
const sva::PTransformd & posW) override;
void schema(const ElementId & id, const std::string & schema) override;
void form(const ElementId & id) override;
void form_checkbox(const ElementId & formId, const std::string & name, bool required, bool default_) override;
void form_integer_input(const ElementId & formId, const std::string & name, bool required, int default_) override;
void form_number_input(const ElementId & formId, const std::string & name, bool required, double default_) override;
void form_string_input(const ElementId & formId,
const std::string & name,
bool required,
const std::string & default_) override;
void form_array_input(const ElementId & formId,
const std::string & name,
bool required,
const Eigen::VectorXd & default_,
bool fixed_size) override;
void form_combo_input(const ElementId & formId,
const std::string & name,
bool required,
const std::vector<std::string> & values,
bool send_index) override;
void form_data_combo_input(const ElementId & formId,
const std::string & name,
bool required,
const std::vector<std::string> & ref,
bool send_index) override;
void stopped() override;
Category root_;
/** Returns a category (creates it if it does not exist */
Category & getCategory(const std::vector<std::string> & category);
/** Get a widget with the right type and id */
template<typename T, typename... Args>
T & widget(const ElementId & id, Args &&... args)
{
auto & category = getCategory(id.category);
auto it =
std::find_if(category.widgets.begin(), category.widgets.end(), [&](auto & w) { return w->id.name == id.name; });
if(it == category.widgets.end())
{
auto & w = category.widgets.emplace_back(std::make_unique<T>(*this, id, std::forward<Args>(args)...));
w->seen = true;
return *dynamic_cast<T *>(w.get());
}
else
{
auto w_ptr = dynamic_cast<T *>(it->get());
if(w_ptr)
{
w_ptr->seen = true;
return *w_ptr;
}
/** Different type, remove and add the widget again */
category.widgets.erase(it);
return widget<T>(id, std::forward<Args>(args)...);
}
}
};