mc_rtc  2.16.0
Point3D.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 
29 template<typename GetT, typename SetT = std::nullptr_t>
30 struct Point3DImpl : public CommonInputImpl<GetT, SetT>
31 {
32  static constexpr auto type = Elements::Point3D;
33 
34  Point3DImpl(const std::string & name, const PointConfig & config, GetT get_fn, SetT set_fn = nullptr)
35  : CommonInputImpl<GetT, SetT>(name, get_fn, set_fn), config_(config)
36  {
38  "Point3D element position callback must return an Eigen::Vector3d");
39  }
40 
43 
44  static constexpr size_t write_size()
46 
48  {
50  // True for read-only
51  builder.write(std::is_same_v<SetT, std::nullptr_t>);
52  config_.write(builder);
53  }
54 
55 private:
56  PointConfig config_;
57 };
58 
59 } // namespace details
60 
62 template<typename GetT, std::enable_if_t<std::is_invocable_v<GetT>, int> = 0>
63 auto Point3D(const std::string & name, GetT get_fn)
64 { return details::Point3DImpl(name, {}, get_fn); }
65 
67 template<typename GetT, typename SetT>
68 auto Point3D(const std::string & name, GetT get_fn, SetT set_fn)
69 { return details::Point3DImpl(name, {}, get_fn, set_fn); }
70 
72 template<typename GetT, std::enable_if_t<std::is_invocable_v<GetT>, int> = 0>
73 auto Point3D(const std::string & name, const PointConfig & config, GetT get_fn)
74 { return details::Point3DImpl(name, config, get_fn); }
75 
77 template<typename GetT, typename SetT>
78 auto Point3D(const std::string & name, const PointConfig & config, GetT get_fn, SetT set_fn)
79 { return details::Point3DImpl(name, config, get_fn, set_fn); }
80 
82 template<typename T>
83 auto Point3DRO(const std::string & name, T && value)
84 { return Point3D(name, details::read(std::forward<T>(value))); }
85 
87 template<typename T>
88 auto Point3DRO(const std::string & name, const PointConfig & config, T && value)
89 { return Point3D(name, config, details::read(std::forward<T>(value))); }
90 
92 template<typename T, std::enable_if_t<!std::is_invocable_v<T>, int> = 0>
93 auto Point3D(const std::string & name, T & value)
94 { return Point3D(name, details::read(value), details::write(value)); }
95 
97 template<typename T, std::enable_if_t<!std::is_invocable_v<T>, int> = 0>
98 auto Point3D(const std::string & name, const PointConfig & config, T & value)
99 { return Point3D(name, config, details::read(value), details::write(value)); }
100 
101 } // namespace mc_rtc::gui
std::optional< Eigen::VectorXd > value
auto read(const T &&value)
Definition: traits.h:184
auto write(T &value)
Definition: traits.h:226
Definition: Observer.h:16
auto Point3D(const std::string &name, GetT get_fn)
Definition: Point3D.h:63
auto Point3DRO(const std::string &name, T &&value)
Definition: Point3D.h:83
Definition: MessagePackBuilder.h:87
Definition: elements.h:167
void write(mc_rtc::MessagePackBuilder &builder)
Definition: elements.h:108
static constexpr size_t write_size()
Definition: elements.h:106
Definition: types.h:343
void write(mc_rtc::MessagePackBuilder &out) const
Definition: types.h:370
static constexpr size_t write_size()
Definition: types.h:368
Definition: Point3D.h:31
void write(mc_rtc::MessagePackBuilder &builder)
Definition: Point3D.h:47
static constexpr size_t write_size()
Definition: Point3D.h:44
static constexpr auto type
Definition: Point3D.h:32
Point3DImpl(const std::string &name, const PointConfig &config, GetT get_fn, SetT set_fn=nullptr)
Definition: Point3D.h:34
Point3DImpl()
Definition: Point3D.h:42