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
mc_rtc::gui::Element
Definition: elements.h:58
mc_rtc::Configuration
Simplify access to values hold within a JSON file.
Definition: Configuration.h:165
mc_rtc::gui::Elements::ArrayLabel
@ ArrayLabel
mc_rtc::gui::DataElement::write_size
static constexpr size_t write_size()
Definition: elements.h:106
mc_rtc::MessagePackBuilder
Definition: MessagePackBuilder.h:86
mc_rtc::gui::VoidCallbackElement::VoidCallbackElement
VoidCallbackElement()
Definition: elements.h:198
mc_rtc::gui::Element::handleRequest
bool handleRequest(const mc_rtc::Configuration &)
Definition: elements.h:86
mc_rtc::gui::Element::Element
Element()
Definition: elements.h:89
mc_rtc::gui::Elements::Trajectory
@ Trajectory
mc_rtc::gui::DataElement::DataElement
DataElement(const std::string &name, GetT get_fn)
Definition: elements.h:111
mc_rtc::gui::Elements::ArrayInput
@ ArrayInput
mc_rtc::gui::Elements::Transform
@ Transform
mc_rtc::gui::CallbackElement< ElementT, std::nullptr_t >::CallbackElement
CallbackElement(const std::string &name, std::nullptr_t, Args &&... args)
Definition: elements.h:155
mc_rtc::gui::Elements::Polygon
@ Polygon
mc_rtc::gui::Elements::NumberSlider
@ NumberSlider
mc_rtc::gui::DataElement::get_fn_
GetT get_fn_
Definition: elements.h:117
mc_rtc::gui::Elements::Point3D
@ Point3D
mc_rtc::gui::Element::id
int id() const
Definition: elements.h:67
mc_rtc::gui::VoidCallbackElement::VoidCallbackElement
VoidCallbackElement(const std::string &name, Callback cb, Args &&... args)
Definition: elements.h:192
mc_rtc::gui::Elements::NumberInput
@ NumberInput
mc_rtc::gui::Elements::XYTheta
@ XYTheta
mc_rtc::gui::CallbackElement
Definition: elements.h:126
mc_rtc::gui::Element::write
void write(mc_rtc::MessagePackBuilder &)
Definition: elements.h:83
mc_rtc::gui::Elements::PolyhedronTrianglesList
@ PolyhedronTrianglesList
mc_rtc::gui::Elements::OneOf
@ OneOf
mc_rtc::gui::CallbackElement::cb_
Callback cb_
Definition: elements.h:144
mc_rtc::gui::Element::name_
std::string name_
Definition: elements.h:94
mc_rtc::gui::DataElement::DataElement
DataElement()
Definition: elements.h:114
mc_rtc::gui::Elements::RobotMsg
@ RobotMsg
mc_rtc::gui::Elements::Button
@ Button
mc_rtc::gui::Element::id
void id(int idIn)
Definition: elements.h:70
mc_rtc::gui::Elements::IntegerInput
@ IntegerInput
mc_rtc::gui::CallbackElement::CallbackElement
CallbackElement()
Definition: elements.h:141
mc_rtc::gui::Elements::Robot
@ Robot
mc_rtc::gui::Elements::Label
@ Label
mc_rtc::gui::Elements::PolyhedronVerticesTriangles
@ PolyhedronVerticesTriangles
mc_rtc::gui::CallbackElement::handleRequest
bool handleRequest(const mc_rtc::Configuration &data)
Definition: elements.h:128
mc_rtc::gui::Elements
Elements
Definition: elements.h:22
api.h
mc_rtc::gui::Elements::Schema
@ Schema
mc_rtc::MessagePackBuilder::write
void write()
mc_rtc::gui::Elements::Force
@ Force
mc_rtc::gui::Element::id_
int id_
Definition: elements.h:96
mc_rtc::gui::Elements::StringInput
@ StringInput
mc_rtc::gui::DataElement
Definition: elements.h:104
MessagePackBuilder.h
mc_rtc::gui::VoidCallbackElement::handleRequest
bool handleRequest(const mc_rtc::Configuration &)
Definition: elements.h:185
mc_rtc::gui::Element::write_size
static constexpr size_t write_size()
Definition: elements.h:76
mc_rtc::gui::Elements::Table
@ Table
mc_rtc::gui::CallbackElement::CallbackElement
CallbackElement(const std::string &name, Callback cb, Args &&... args)
Definition: elements.h:135
mc_rtc::gui::Elements::ComboInput
@ ComboInput
std
Definition: Contact.h:66
mc_rtc::gui::Elements::Checkbox
@ Checkbox
mc_rtc::gui::Elements::Form
@ Form
mc_rtc::gui::Elements::Arrow
@ Arrow
mc_rtc::gui::VoidCallbackElement
Definition: elements.h:183
mc_rtc::gui::Elements::Rotation
@ Rotation
mc_rtc::gui::DataElement::write
void write(mc_rtc::MessagePackBuilder &builder)
Definition: elements.h:108
mc_rtc::gui::Elements::GenericArray
@ GenericArray
traits.h
mc_rtc::gui::Elements::DataComboInput
@ DataComboInput
mc_rtc::gui::CommonInputImpl::CommonInputImpl
CommonInputImpl()
Definition: elements.h:174
mc_rtc::gui::CallbackElement< ElementT, std::nullptr_t >::CallbackElement
CallbackElement()
Definition: elements.h:161
mc_rtc::gui::CommonInputImpl
Definition: elements.h:166
mc_rtc::gui::Elements::Visual
@ Visual
MC_RTC_GUI_DLLAPI
#define MC_RTC_GUI_DLLAPI
Definition: api.h:50
mc_rtc
Definition: Contact.h:87
mc_rtc::gui::CommonInputImpl::CommonInputImpl
CommonInputImpl(const std::string &name, GetT get_fn, SetT set_fn)
Definition: elements.h:168
mc_rtc::gui::Element::name
const std::string & name() const
Definition: elements.h:61