WebCFace 2.5.2
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 }
60 RobotModel child(int index) const { return this->Field::child(index); }
65 RobotModel operator[](std::string_view field) const { return child(field); }
70 RobotModel operator[](std::wstring_view field) const {
71 return child(field);
72 }
77 RobotModel operator[](const char *field) const { return child(field); }
81 RobotModel operator[](const wchar_t *field) const { return child(field); }
86 RobotModel operator[](int index) const { return child(index); }
91 RobotModel parent() const { return this->Field::parent(); }
92
99 const RobotModel &
100 onChange(std::function<void WEBCFACE_CALL_FP(RobotModel)> callback) const;
107 template <typename F, typename std::enable_if_t<std::is_invocable_v<F>,
108 std::nullptr_t> = nullptr>
109 const RobotModel &onChange(F callback) const {
110 return onChange(
111 [callback = std::move(callback)](const auto &) { callback(); });
112 }
120 template <typename T>
121 [[deprecated]] void appendListener(T &&callback) const {
122 onChange(std::forward<T>(callback));
123 }
124
129 const RobotModel &init() const;
134 const RobotModel &operator<<(RobotLink rl) const;
139 template <typename T>
140 const RobotModel &add(T &&rl) const {
141 *this << std::forward<T>(rl);
142 return *this;
143 }
148 const RobotModel &sync() const;
149
154 const RobotModel &set(const std::vector<RobotLink> &v) const;
159 const RobotModel &operator=(const std::vector<RobotLink> &v) const {
160 this->set(v);
161 return *this;
162 }
168 const RobotModel &request() const;
173 std::optional<std::vector<RobotLink>> tryGet() const;
178 std::vector<RobotLink> get() const {
179 return tryGet().value_or(std::vector<RobotLink>{});
180 }
181 operator std::vector<RobotLink>() const { return get(); }
190 bool exists() const;
195 [[deprecated]] std::chrono::system_clock::time_point time() const;
196
201 const RobotModel &free() const;
202
207 TemporalCanvas3DComponent toComponent3D() const;
213 return toComponent3D().origin(origin);
214 }
220 return toComponent3D().color(color);
221 }
226 template <typename... Args>
227 TemporalCanvas3DComponent angles(Args &&...args) const {
228 return toComponent3D().angles(std::forward<Args>(args)...);
229 }
230
235 template <typename T,
236 typename std::enable_if_t<std::is_same_v<T, RobotModel>,
237 std::nullptr_t> = nullptr>
238 bool operator==(const T &other) const {
239 return static_cast<Field>(*this) == static_cast<Field>(other);
240 }
241 template <typename T,
242 typename std::enable_if_t<std::is_same_v<T, RobotModel>,
243 std::nullptr_t> = nullptr>
244 bool operator!=(const T &other) const {
245 return static_cast<Field>(*this) != static_cast<Field>(other);
246 }
247};
248
Canvas3Dの送受信データを表すクラス
Definition canvas3d.h:28
RobotModelの送受信データを表すクラス
Definition robot_model.h:26
RobotModel operator[](std::string_view field) const
Definition robot_model.h:65
bool operator==(const T &other) const
RobotModelの参照先を比較
Definition robot_model.h:238
RobotModel operator[](const char *field) const
Definition robot_model.h:77
RobotModel child(int index) const
Definition robot_model.h:60
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:70
RobotModel operator[](int index) const
Definition robot_model.h:86
TemporalCanvas3DComponent origin(const Transform &origin) const
Canvas3DComponentに変換 + 要素の移動
Definition robot_model.h:212
const RobotModel & onChange(F callback) const
値が変化したときに呼び出されるコールバックを設定
Definition robot_model.h:109
bool operator!=(const T &other) const
Definition robot_model.h:244
RobotModel operator[](const wchar_t *field) const
Definition robot_model.h:81
const RobotModel & operator=(const std::vector< RobotLink > &v) const
モデルをセットする
Definition robot_model.h:159
void appendListener(T &&callback) const
Definition robot_model.h:121
TemporalCanvas3DComponent angles(Args &&...args) const
Canvas3DComponentに変換 + RobotModelの関節を設定
Definition robot_model.h:227
RobotModel(const Field &base, const SharedString &field)
Definition robot_model.h:32
RobotModel parent() const
nameの最後のピリオドの前までを新しい名前とするField
Definition robot_model.h:91
RobotModel child(std::string_view field) const
「(thisの名前).(追加の名前)」を新しい名前とするField
Definition robot_model.h:47
TemporalCanvas3DComponent color(ViewColor color) const
Canvas3DComponentに変換 + 色の指定
Definition robot_model.h:219
const RobotModel & add(T &&rl) const
モデルにlinkを追加
Definition robot_model.h:140
std::vector< RobotLink > get() const
モデルを返す
Definition robot_model.h:178
u8stringとstringとwstringをshared_ptrで持ち共有する
Definition encoding.h:69
Canvas3Dを構築するときに使う一時的なCanvas3DComponent.
Definition component_canvas3d.h:116
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:134
3次元の平行移動と回転
Definition transform.h:615
View,Canvasなどで送信用にaddされたデータを管理する
Definition data_buffer.h:17
std::ostream & operator<<(std::ostream &os, const Arg &arg)
Definition func_info.cc:96
ViewColor
Definition component_view.h:40
ClientDataの参照とメンバ名とデータ名を持つクラス
Definition field.h:70
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:60
#define WEBCFACE_NS_END
Definition webcface-config.h:104
#define WEBCFACE_NS_BEGIN
Definition webcface-config.h:103
#define WEBCFACE_CALL_FP
Definition webcface-config.h:98