elements.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015-2020 CNRS-UM LIRMM, CNRS-AIST JRL
3  */
4 
5 #pragma once
6 
8 
9 #include <mc_rtc/gui/api.h>
11 
15 namespace mc_rtc
16 {
17 
18 namespace gui
19 {
20 
22 enum class Elements
23 {
24  Label = 0,
25  ArrayLabel,
26  Button,
27  Checkbox,
32  ArrayInput,
33  ComboInput,
35  Point3D,
36  Trajectory,
37  Rotation,
38  Transform,
39  Schema,
40  Form,
41  Polygon,
42  Force,
43  Arrow,
44  XYTheta,
45  Table,
46  Robot,
47  Visual,
51  OneOf,
52  RobotMsg
53 };
54 
59 {
61  const std::string & name() const { return name_; }
62 
67  int id() const { return id_; }
68 
70  void id(int idIn) { id_ = idIn; }
71 
76  static constexpr size_t write_size() { return 3; }
77 
84 
86  bool handleRequest(const mc_rtc::Configuration &) { return false; }
87 
89  Element() {}
90 
91 protected:
92  Element(const std::string & name);
93 
94  std::string name_;
95 
96  int id_;
97 };
98 
103 template<typename GetT>
104 struct DataElement : public Element
105 {
106  static constexpr size_t write_size() { return Element::write_size() + 1; }
107 
108  void write(mc_rtc::MessagePackBuilder & builder) { builder.write(get_fn_()); }
109 
111  DataElement(const std::string & name, GetT get_fn) : Element(name), get_fn_(get_fn) {}
112 
115 
116 protected:
117  GetT get_fn_;
118 };
119 
125 template<typename ElementT, typename Callback>
126 struct CallbackElement : public ElementT
127 {
129  {
130  cb_(data);
131  return true;
132  }
133 
134  template<typename... Args>
135  CallbackElement(const std::string & name, Callback cb, Args &&... args)
136  : ElementT(name, std::forward<Args>(args)...), cb_(cb)
137  {
138  }
139 
142 
143 protected:
144  Callback cb_;
145 };
146 
151 template<typename ElementT>
152 struct CallbackElement<ElementT, std::nullptr_t> : public ElementT
153 {
154  template<typename... Args>
155  CallbackElement(const std::string & name, std::nullptr_t, Args &&... args)
156  : ElementT(name, std::forward<Args>(args)...)
157  {
158  }
159 
162 };
163 
165 template<typename GetT, typename SetT>
166 struct CommonInputImpl : public CallbackElement<DataElement<GetT>, SetT>
167 {
168  CommonInputImpl(const std::string & name, GetT get_fn, SetT set_fn)
169  : CallbackElement<DataElement<GetT>, SetT>(name, set_fn, get_fn)
170  {
171  }
172 
175 };
176 
182 template<typename ElementT, typename Callback>
183 struct VoidCallbackElement : public CallbackElement<ElementT, Callback>
184 {
186  {
187  this->cb_();
188  return true;
189  }
190 
191  template<typename... Args>
192  VoidCallbackElement(const std::string & name, Callback cb, Args &&... args)
193  : CallbackElement<ElementT, Callback>(name, cb, std::forward<Args>(args)...)
194  {
195  }
196 
199 };
200 
201 } // namespace gui
202 
203 } // namespace mc_rtc
#define MC_RTC_GUI_DLLAPI
Definition: api.h:50
Elements
Definition: elements.h:23
Definition: Contact.h:88
Definition: Contact.h:67
Simplify access to values hold within a JSON file.
Definition: Configuration.h:166
Definition: MessagePackBuilder.h:87
CallbackElement(const std::string &name, std::nullptr_t, Args &&... args)
Definition: elements.h:155
Definition: elements.h:127
CallbackElement(const std::string &name, Callback cb, Args &&... args)
Definition: elements.h:135
bool handleRequest(const mc_rtc::Configuration &data)
Definition: elements.h:128
Callback cb_
Definition: elements.h:144
CallbackElement()
Definition: elements.h:141
Definition: elements.h:167
CommonInputImpl(const std::string &name, GetT get_fn, SetT set_fn)
Definition: elements.h:168
CommonInputImpl()
Definition: elements.h:174
Definition: elements.h:105
DataElement()
Definition: elements.h:114
DataElement(const std::string &name, GetT get_fn)
Definition: elements.h:111
GetT get_fn_
Definition: elements.h:117
void write(mc_rtc::MessagePackBuilder &builder)
Definition: elements.h:108
static constexpr size_t write_size()
Definition: elements.h:106
Definition: elements.h:59
void id(int idIn)
Definition: elements.h:70
bool handleRequest(const mc_rtc::Configuration &)
Definition: elements.h:86
Element()
Definition: elements.h:89
int id_
Definition: elements.h:96
const std::string & name() const
Definition: elements.h:61
Element(const std::string &name)
std::string name_
Definition: elements.h:94
void write(mc_rtc::MessagePackBuilder &)
Definition: elements.h:83
int id() const
Definition: elements.h:67
static constexpr size_t write_size()
Definition: elements.h:76
Definition: elements.h:184
VoidCallbackElement()
Definition: elements.h:198
VoidCallbackElement(const std::string &name, Callback cb, Args &&... args)
Definition: elements.h:192
bool handleRequest(const mc_rtc::Configuration &)
Definition: elements.h:185