Arrow.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015-2019 CNRS-UM LIRMM, CNRS-AIST JRL
3  */
4 
5 #pragma once
6 
8 #include <mc_rtc/gui/elements.h>
9 #include <mc_rtc/gui/types.h>
10 
11 namespace mc_rtc::gui
12 {
13 
14 namespace details
15 {
16 
26 template<typename GetStart, typename GetEnd>
27 struct ArrowROImpl : public Element
28 {
29  static constexpr auto type = Elements::Arrow;
30 
31  ArrowROImpl(const std::string & name, const ArrowConfig & config, GetStart get_start_fn, GetEnd get_end_fn)
32  : Element(name), get_start_fn_(get_start_fn), get_end_fn_(get_end_fn), config_(config)
33  {
35  "Arrow element start callback must return an Eigen::Vector3d");
37  "Arrow element end callback must return an Eigen::Vector3d");
38  }
39 
42 
43  constexpr static size_t write_size() { return Element::write_size() + 3 + ArrowConfig::write_size(); }
44 
45  void write(mc_rtc::MessagePackBuilder & builder, bool ro = true)
46  {
47  Element::write(builder);
48  builder.write(get_start_fn_());
49  builder.write(get_end_fn_());
50  builder.write(ro);
51  config_.write(builder);
52  }
53 
54 private:
55  GetStart get_start_fn_;
56  GetEnd get_end_fn_;
57  ArrowConfig config_;
58 };
59 
60 template<typename GetStart, typename SetStart, typename GetEnd, typename SetEnd>
61 struct ArrowImpl : public ArrowROImpl<GetStart, GetEnd>
62 {
63  ArrowImpl(const std::string & name,
64  const ArrowConfig & config,
65  GetStart get_start_fn,
66  SetStart set_start_fn,
67  GetEnd get_end_fn,
68  SetEnd set_end_fn)
69  : ArrowROImpl<GetStart, GetEnd>(name, config, get_start_fn, get_end_fn), set_start_fn_(set_start_fn),
70  set_end_fn_(set_end_fn)
71  {
72  }
73 
75  ArrowImpl(){};
76 
78 
80  {
81  const Eigen::Vector6d & arrow = data;
82  set_start_fn_(arrow.head<3>());
83  set_end_fn_(arrow.tail<3>());
84  return true;
85  }
86 
87 private:
88  SetStart set_start_fn_;
89  SetEnd set_end_fn_;
90 };
91 
92 } // namespace details
93 
95 template<typename GetStart, typename GetEnd>
96 auto Arrow(const std::string & name, GetStart get_start_fn, GetEnd get_end_fn)
97 {
98  return details::ArrowROImpl(name, {}, get_start_fn, get_end_fn);
99 }
100 
102 template<typename GetStart, typename GetEnd>
103 auto Arrow(const std::string & name, const ArrowConfig & config, GetStart get_start_fn, GetEnd get_end_fn)
104 {
105  return details::ArrowROImpl(name, config, get_start_fn, get_end_fn);
106 }
107 
108 template<typename GetStart, typename SetStart, typename GetEnd, typename SetEnd>
109 auto Arrow(const std::string & name, GetStart get_start_fn, SetStart set_start_fn, GetEnd get_end_fn, SetEnd set_end_fn)
110 {
111  return details::ArrowImpl(name, ArrowConfig{}, get_start_fn, set_start_fn, get_end_fn, set_end_fn);
112 }
113 
114 template<typename GetStart, typename SetStart, typename GetEnd, typename SetEnd>
115 auto Arrow(const std::string & name,
116  const ArrowConfig & config,
117  GetStart get_start_fn,
118  SetStart set_start_fn,
119  GetEnd get_end_fn,
120  SetEnd set_end_fn)
121 {
122  return details::ArrowImpl(name, config, get_start_fn, set_start_fn, get_end_fn, set_end_fn);
123 }
124 
125 } // namespace mc_rtc::gui
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::details::ArrowROImpl::ArrowROImpl
ArrowROImpl()
Definition: Arrow.h:41
mc_rtc::MessagePackBuilder
Definition: MessagePackBuilder.h:86
mc_rtc::gui::details::ArrowROImpl::type
static constexpr auto type
Definition: Arrow.h:29
mc_rtc::gui::details::ArrowROImpl::ArrowROImpl
ArrowROImpl(const std::string &name, const ArrowConfig &config, GetStart get_start_fn, GetEnd get_end_fn)
Definition: Arrow.h:31
types.h
mc_rtc::gui::Element::write
void write(mc_rtc::MessagePackBuilder &)
Definition: elements.h:83
mc_rtc::gui::details::ArrowROImpl::write_size
constexpr static size_t write_size()
Definition: Arrow.h:43
mc_rtc::gui::ArrowConfig
Definition: types.h:205
mc_rtc::gui::ArrowConfig::write_size
static constexpr size_t write_size()
Definition: types.h:246
mc_rtc::gui::details::ArrowImpl::write
void write(mc_rtc::MessagePackBuilder &builder)
Definition: Arrow.h:77
elements.h
mc_rtc::gui::details::ArrowImpl
Definition: Arrow.h:61
mc_rtc::gui::details::ArrowImpl::ArrowImpl
ArrowImpl()
Definition: Arrow.h:75
mc_rtc::MessagePackBuilder::write
void write()
mc_rtc::gui::ArrowConfig::write
void write(mc_rtc::MessagePackBuilder &out) const
Definition: types.h:248
mc_rtc::gui::details::ArrowROImpl::write
void write(mc_rtc::MessagePackBuilder &builder, bool ro=true)
Definition: Arrow.h:45
mc_rtc::gui::Element::write_size
static constexpr size_t write_size()
Definition: elements.h:76
mc_rtc::gui::Elements::Arrow
@ Arrow
traits.h
mc_rtc::gui::Arrow
auto Arrow(const std::string &name, GetStart get_start_fn, GetEnd get_end_fn)
Definition: Arrow.h:96
mc_rtc::gui::details::CheckReturnType
Definition: traits.h:86
mc_rtc::gui::details::ArrowImpl::ArrowImpl
ArrowImpl(const std::string &name, const ArrowConfig &config, GetStart get_start_fn, SetStart set_start_fn, GetEnd get_end_fn, SetEnd set_end_fn)
Definition: Arrow.h:63
mc_rtc::gui::details::ArrowImpl::handleRequest
bool handleRequest(const mc_rtc::Configuration &data)
Definition: Arrow.h:79
mc_rtc::gui::details::ArrowROImpl
Definition: Arrow.h:27
mc_rtc::gui
Definition: Observer.h:15
mc_rtc::gui::Element::name
const std::string & name() const
Definition: elements.h:61