Visual.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015-2021 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 
13 
14 namespace mc_rtc::gui
15 {
16 
17 namespace details
18 {
19 
27 template<typename GetVisual, typename GetPos>
28 struct VisualImpl : public Element
29 {
30  static constexpr auto type = Elements::Visual;
31 
32  VisualImpl(const std::string & name, GetVisual get_visual_fn, GetPos get_pos_fn)
33  : Element(name), get_visual_fn_(get_visual_fn), get_pos_fn_(get_pos_fn)
34  {
36  "Visual element visual callback must return an rbd::parsers::Visual");
38  "Visual element position callback must return an sva::PTransformd or an Eigen::Vector3d");
39  }
40 
43 
44  constexpr static size_t write_size() { return Element::write_size() + 2; }
45 
47  {
48  Element::write(builder);
49  visual_.add("data", get_visual_fn_());
50  builder.write(visual_("data"));
51  builder.write(get_pos_fn_());
52  }
53 
54 private:
55  GetVisual get_visual_fn_;
56  GetPos get_pos_fn_;
57  mc_rtc::Configuration visual_;
58 };
59 
60 } // namespace details
61 
63 template<typename GetVisual, typename GetPos>
64 auto Visual(const std::string & name, GetVisual get_visual_fn, GetPos get_pos_fn)
65 {
66  return details::VisualImpl(name, get_visual_fn, get_pos_fn);
67 }
68 
69 } // 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::VisualImpl
Definition: Visual.h:28
mc_rtc::MessagePackBuilder
Definition: MessagePackBuilder.h:86
types.h
mc_rtc::gui::Element::write
void write(mc_rtc::MessagePackBuilder &)
Definition: elements.h:83
mc_rtc::gui::details::VisualImpl::VisualImpl
VisualImpl(const std::string &name, GetVisual get_visual_fn, GetPos get_pos_fn)
Definition: Visual.h:32
mc_rtc::gui::details::VisualImpl::write
void write(mc_rtc::MessagePackBuilder &builder)
Definition: Visual.h:46
elements.h
mc_rtc::Configuration::add
void add(const std::string &key, bool value)
Add a bool element to the Configuration.
mc_rtc::gui::Visual
auto Visual(const std::string &name, GetVisual get_visual_fn, GetPos get_pos_fn)
Definition: Visual.h:64
mc_rtc::MessagePackBuilder::write
void write()
mc_rtc::gui::details::VisualImpl::write_size
constexpr static size_t write_size()
Definition: Visual.h:44
MessagePackBuilder.h
mc_rtc::gui::Element::write_size
static constexpr size_t write_size()
Definition: elements.h:76
mc_rtc::gui::details::VisualImpl::VisualImpl
VisualImpl()
Definition: Visual.h:42
traits.h
mc_rtc::gui::details::VisualImpl::type
static constexpr auto type
Definition: Visual.h:30
mc_rtc::gui::details::CheckReturnType
Definition: traits.h:86
configuration_io.h
mc_rtc::gui::Elements::Visual
@ Visual
mc_rtc::gui
Definition: Observer.h:15
mc_rtc::gui::Element::name
const std::string & name() const
Definition: elements.h:61