MakeGuiConfigStruct.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "MakeGuiElement.h"
4 
5 namespace armarx::meta::cfg
6 {
7  template<class T, class = void>
8  struct gui_definition_create : std::false_type {};
9 }
10 
12 {
13  template<class VarName, class CL, class MT, MT CL::* ptr>
14  std::vector<RemoteGui::WidgetPtr>
16  const boost::hana::pair<VarName, boost::hana::struct_detail::member_ptr<MT CL::*, ptr>>&,
17  const std::string& prefix,
18  const CL& val
19  )
20  {
22  const auto varname = hana::to<char const*>(VarName{});
23  const auto& var = val.*ptr;
24  using def_create = gui_definition_create<MT>;
26  if constexpr(def_create::value)
27  {
28  return {def_create::create(var, prefix, varname)};
29  }
30  else if constexpr(elem_create::value)
31  {
32  return elem_create::create(var, prefix, varname);
33  }
34  else
35  {
36  static_assert(!std::is_same_v<MT, MT>, "this member type is not handeled!");
37  return {};
38  }
39  }
40 }
41 
42 namespace armarx::meta::cfg
43 {
44  template<class T>
46  T,
47  std::enable_if_t<meta::cfg::gui_definition_enabled_v<T>>
48  > : std::true_type
49  {
50  template<class OverrideLayoutT = undefined_t>
51  static auto create(const T& val, const std::string& prefix, const std::string& name)
52  {
53  using layout_t = first_not_undefined_t <
54  OverrideLayoutT,
56  RemoteGui::GroupBox // default value
57  >;
58 
60  namespace hana = boost::hana;
61  static constexpr auto accessors = hana::accessors<T>();
62 
63  auto [widget, addChildren] = [&]
64  {
65  static constexpr bool grpbox = std::is_same_v<layout_t, RemoteGui::GroupBox>;
66  static constexpr bool sgrid = std::is_same_v<layout_t, RemoteGui::SimpleGridLayout>;
67  static constexpr bool vbox = std::is_same_v<layout_t, RemoteGui::VBoxLayout>;
68  static constexpr bool hbox = std::is_same_v<layout_t, RemoteGui::HBoxLayout>;
69 
70  if constexpr(grpbox || sgrid)
71  {
72  RemoteGui::SimpleGridLayoutPtr l = new RemoteGui::SimpleGridLayout;
73  l->columns = 2;
74  auto add = [l](const auto & cs)
75  {
76  if (cs.size() == 1)
77  {
78  l->children.emplace_back(new RemoteGui::Widget);
79  l->children.emplace_back(cs.front());
80  }
81  else
82  {
83  l->children.insert(l->children.end(), cs.begin(), cs.end());
84  }
85  };
86  if constexpr(grpbox)
87  {
88  return std::make_pair(RemoteGui::makeGroupBox(ConcatID(prefix, name)).label(name).addChild(l), add);
89  }
90  else
91  {
92  return std::make_pair(l, add);
93  }
94  }
95  else if constexpr(vbox || hbox)
96  {
97  RemoteGui::WidgetPtr l = new layout_t;
98  auto add = [l](const auto & cs)
99  {
100  l->children.insert(l->children.end(), cs.begin(), cs.end());
101  };
102  return std::make_pair(l, add);
103  }
104  else
105  {
106  static_assert(!std::is_same_v<T, T>, "the given type for config_layout can't be used");
107  }
108  }();
109 
110  hana::for_each(accessors, [&, addChildren=std::ref(addChildren)](auto & e)
111  {
113  using elem_det = decltype(armarx::meta::cfg::to_element_detail(e));
114  if constexpr(!elem_det::no_remote_gui)
115  {
116  addChildren(detail::DoCreateElement(e, ConcatID(prefix, name), val));
117  }
118  else
119  {
120  // do nothing
121  }
122  });
123 
124  return widget;
125  }
126  static auto create(const T& val, const std::string& prefix, const std::string& name)
127  {
128  return create<>(val, prefix, name);
129  }
130  };
131 }
armarx::meta::cfg::gui_definition_create< T, std::enable_if_t< meta::cfg::gui_definition_enabled_v< T > > >::create
static auto create(const T &val, const std::string &prefix, const std::string &name)
Definition: MakeGuiConfigStruct.h:126
armarx::meta::cfg::first_not_undefined_t
::simox::meta::first_not_undefined_t< Ts... > first_not_undefined_t
Definition: common.h:20
armarx::meta::cfg::gui_definition_create_element
Definition: MakeGuiElement.h:79
ARMARX_TRACE_LITE
#define ARMARX_TRACE_LITE
Definition: trace.h:85
armarx::meta::cfg::detail::DoCreateElement
std::vector< RemoteGui::WidgetPtr > DoCreateElement(const boost::hana::pair< VarName, boost::hana::struct_detail::member_ptr< MT CL::*, ptr >> &, const std::string &prefix, const CL &val)
Definition: MakeGuiConfigStruct.h:15
armarx::meta::cfg
Definition: PluginCfgStruct.h:31
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:69
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
MakeGuiElement.h
armarx::meta::cfg::detail
Definition: MakeGuiConfigStruct.h:11
armarx::meta::cfg::gui_definition_create< T, std::enable_if_t< meta::cfg::gui_definition_enabled_v< T > > >::create
static auto create(const T &val, const std::string &prefix, const std::string &name)
Definition: MakeGuiConfigStruct.h:51
armarx::RemoteGui::makeGroupBox
detail::GroupBoxBuilder makeGroupBox(std::string const &name="")
Definition: LayoutWidgets.h:250
armarx::meta::cfg::ConcatID
std::string ConcatID(const std::string &prefix, const std::string &suffix)
Definition: ConcatID.h:7
armarx::WidgetDescription::WidgetPtr
::IceInternal::Handle<::armarx::WidgetDescription::Widget > WidgetPtr
Definition: NJointControllerBase.h:66
std
Definition: Application.h:66
armarx::meta::cfg::to_element_detail
element_details< CL, MT, ptr > to_element_detail(const boost::hana::pair< VarName, boost::hana::struct_detail::member_ptr< MT CL::*, ptr >> &)
T
float T
Definition: UnscentedKalmanFilterTest.cpp:35
armarx::meta::cfg::gui_definition_create
Definition: MakeGuiConfigStruct.h:8
armarx::meta::cfg::config_layout
undefined_t config_layout
Definition: config_struct_details.h:21