WebCFace 2.9.0
Web-based Communication Framework & Dashboard-like UI
Loading...
Searching...
No Matches
robot_model.h
Go to the documentation of this file.
1#pragma once
2#ifdef WEBCFACE_MESON
3#include "webcface-config.h"
4#else
5#include "webcface/common/webcface-config.h"
6#endif
7#include "robot_link.h"
8#include "field.h"
9#include "components.h"
10
12namespace internal {
13template <typename Component>
14class DataSetBuffer;
15} // namespace internal
16
26class WEBCFACE_DLL RobotModel : protected Field {
27 std::shared_ptr<internal::DataSetBuffer<RobotLink>> sb;
28
29 public:
30 RobotModel();
31 RobotModel(const Field &base);
32 RobotModel(const Field &base, const SharedString &field)
33 : RobotModel(Field{base, field}) {}
34
35 friend class Canvas3D;
38
39 using Field::lastName;
40 using Field::member;
41 using Field::name;
42 using Field::nameW;
47 RobotModel child(std::string_view field) const {
48 return this->Field::child(field);
49 }
54 RobotModel child(std::wstring_view field) const {
55 return this->Field::child(field);
56 }
61 [[deprecated]]
62 RobotModel child(int index) const {
63 return this->Field::child(std::to_string(index));
64 }
69 RobotModel operator[](std::string_view field) const { return child(field); }
74 RobotModel operator[](std::wstring_view field) const {
75 return child(field);
76 }
81 RobotModel operator[](const char *field) const { return child(field); }
85 RobotModel operator[](const wchar_t *field) const { return child(field); }
91 [[deprecated]]
92 RobotModel operator[](int index) const {
93 return child(std::to_string(index));
94 }
99 RobotModel parent() const { return this->Field::parent(); }
100
107 const RobotModel &
108 onChange(std::function<void WEBCFACE_CALL_FP(RobotModel)> callback) const;
115 template <typename F, typename std::enable_if_t<std::is_invocable_v<F>,
116 std::nullptr_t> = nullptr>
117 const RobotModel &onChange(F callback) const {
118 return onChange(
119 [callback = std::move(callback)](const auto &) { callback(); });
120 }
128 template <typename T>
129 [[deprecated]] void appendListener(T &&callback) const {
130 onChange(std::forward<T>(callback));
131 }
132
137 const RobotModel &init() const;
142 const RobotModel &operator<<(RobotLink rl) const;
147 template <typename T>
148 const RobotModel &add(T &&rl) const {
149 *this << std::forward<T>(rl);
150 return *this;
151 }
156 const RobotModel &sync() const;
157
162 const RobotModel &set(const std::vector<RobotLink> &v) const;
167 const RobotModel &operator=(const std::vector<RobotLink> &v) const {
168 this->set(v);
169 return *this;
170 }
176 const RobotModel &request() const;
181 std::optional<std::vector<RobotLink>> tryGet() const;
186 std::vector<RobotLink> get() const {
187 return tryGet().value_or(std::vector<RobotLink>{});
188 }
189 operator std::vector<RobotLink>() const { return get(); }
198 bool exists() const;
203 [[deprecated]] std::chrono::system_clock::time_point time() const;
204
209 const RobotModel &free() const;
210
215 TemporalCanvas3DComponent toComponent3D() const;
221 return toComponent3D().origin(origin);
222 }
228 return toComponent3D().color(color);
229 }
234 template <typename... Args>
235 TemporalCanvas3DComponent angles(Args &&...args) const {
236 return toComponent3D().angles(std::forward<Args>(args)...);
237 }
238
243 template <typename T,
244 typename std::enable_if_t<std::is_same_v<T, RobotModel>,
245 std::nullptr_t> = nullptr>
246 bool operator==(const T &other) const {
247 return static_cast<Field>(*this) == static_cast<Field>(other);
248 }
249 template <typename T,
250 typename std::enable_if_t<std::is_same_v<T, RobotModel>,
251 std::nullptr_t> = nullptr>
252 bool operator!=(const T &other) const {
253 return static_cast<Field>(*this) != static_cast<Field>(other);
254 }
255};
256
Canvas3Dの送受信データを表すクラス
Definition canvas3d.h:28
RobotModelの送受信データを表すクラス
Definition robot_model.h:26
RobotModel operator[](std::string_view field) const
Definition robot_model.h:69
bool operator==(const T &other) const
RobotModelの参照先を比較
Definition robot_model.h:246
RobotModel operator[](const char *field) const
Definition robot_model.h:81
RobotModel child(int index) const
Definition robot_model.h:62
RobotModel child(std::wstring_view field) const
「(thisの名前).(追加の名前)」を新しい名前とするField (wstring)
Definition robot_model.h:54
RobotModel operator[](std::wstring_view field) const
Definition robot_model.h:74
RobotModel operator[](int index) const
Definition robot_model.h:92
TemporalCanvas3DComponent origin(const Transform &origin) const
Canvas3DComponentに変換 + 要素の移動
Definition robot_model.h:220
const RobotModel & onChange(F callback) const
値が変化したときに呼び出されるコールバックを設定
Definition robot_model.h:117
bool operator!=(const T &other) const
Definition robot_model.h:252
RobotModel operator[](const wchar_t *field) const
Definition robot_model.h:85
const RobotModel & operator=(const std::vector< RobotLink > &v) const
モデルをセットする
Definition robot_model.h:167
void appendListener(T &&callback) const
Definition robot_model.h:129
TemporalCanvas3DComponent angles(Args &&...args) const
Canvas3DComponentに変換 + RobotModelの関節を設定
Definition robot_model.h:235
RobotModel(const Field &base, const SharedString &field)
Definition robot_model.h:32
RobotModel parent() const
nameの最後のピリオドの前までを新しい名前とするField
Definition robot_model.h:99
RobotModel child(std::string_view field) const
「(thisの名前).(追加の名前)」を新しい名前とするField
Definition robot_model.h:47
TemporalCanvas3DComponent color(ViewColor color) const
Canvas3DComponentに変換 + 色の指定
Definition robot_model.h:227
const RobotModel & add(T &&rl) const
モデルにlinkを追加
Definition robot_model.h:148
std::vector< RobotLink > get() const
モデルを返す
Definition robot_model.h:186
u8stringとstringとwstringをshared_ptrで持ち共有する
Definition encoding.h:67
Canvas3Dを構築するときに使う一時的なCanvas3DComponent.
Definition component_canvas3d.h:119
TemporalCanvas3DComponent & color(ViewColor color) &
Definition component_canvas3d.cc:96
TemporalCanvas3DComponent & origin(const Transform &origin) &
要素の移動
Definition component_canvas3d.cc:87
TemporalCanvas3DComponent & angles(const std::unordered_map< std::string, double > &angles) &
RobotModelの関節をまとめて設定
Definition component_canvas3d.cc:137
3次元の平行移動と回転
Definition transform.h:652
View,Canvasなどで送信用にaddされたデータを管理する
Definition data_buffer.h:17
std::ostream & operator<<(std::ostream &os, const Arg &arg)
Definition func_info.cc:100
ViewColor
Definition component_view.h:40
const auto & get(const AxisAngle &aa)
Definition transform.h:231
ClientDataの参照とメンバ名とデータ名を持つクラス
Definition field.h:71
Field parent() const
nameの最後のピリオドの前までを新しい名前とするField
Definition field.cc:33
Field child(const SharedString &field) const
Definition field.cc:42
#define WEBCFACE_DLL
Definition webcface-config.h:69
#define WEBCFACE_NS_END
Definition webcface-config.h:118
#define WEBCFACE_NS_BEGIN
Definition webcface-config.h:117
#define WEBCFACE_CALL_FP
Definition webcface-config.h:107