Basic.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include <ArmarXGui/interface/RemoteGuiInterface.h>
5 
7 
8 #include <SimoxUtility/math/compare/value_in_limits_of.h>
9 
11 {
13  {
14  public:
15  virtual ~WidgetBuilder() = default;
16 
17  WidgetBuilder& hidden(bool hidden = true)
18  {
19  widget_->defaultState.hidden = hidden;
20  return *this;
21  }
22 
24  {
25  widget_->defaultState.disabled = disabled;
26  return *this;
27  }
28 
29  virtual operator WidgetPtr() const
30  {
31  return widget_;
32  }
33 
34  protected:
36  };
37 
38  template <typename WidgetT, typename Derived>
39  class WidgetMixin : public WidgetBuilder
40  {
41  public:
42  WidgetMixin(std::string const& name)
43  {
44  widget_ = new WidgetT;
45  widget_->name = name;
46  widget_->defaultValue = Derived::defaultValue();
47  }
48 
49  public:
50  WidgetT& widget()
51  {
52  return *dynamic_cast<WidgetT*>(widget_.get());
53  }
54  };
55 
56  template <typename WidgetT, typename Derived>
57  struct NoValueMixin : WidgetMixin<WidgetT, Derived>
58  {
60 
61  static ValueVariant defaultValue()
62  {
63  return ValueVariant();
64  }
65  };
66 
67  template <typename WidgetT, typename ValueT, typename Derived>
68  struct ValueMixin : WidgetMixin<WidgetT, Derived>
69  {
71 
72  static ValueVariant defaultValue()
73  {
74  return makeValue(ValueT());
75  }
76 
77  Derived& value(ValueT const& value)
78  {
79  Derived& this_ = *static_cast<Derived*>(this);
80  this_.widget().defaultValue = makeValue(value);
81  return this_;
82  }
83  };
84 
85  template <typename Derived, typename Type>
86  struct MinMaxMixin
87  {
88  Derived& min(Type min)
89  {
90  Derived& this_ = *static_cast<Derived*>(this);
91  this_.widget().min = min;
92  return this_;
93  }
94  Derived& min(std::array<Type, 1> v)
95  {
96  return min(v.at(0));
97  }
98  template<class T>
99  std::enable_if_t <simox::meta::are_arithmetic_v<Type, T>, Derived&>
100  min(T v)
101  {
102  ARMARX_CHECK(simox::math::value_in_limits_of_type<Type>(v))
103  << VAROUT(v) << " : " << GetTypeString<T>();
104  return min(static_cast<Type>(v));
105  }
106  template<class T>
107  std::enable_if_t <simox::meta::are_arithmetic_v<Type, T>, Derived&>
108  min(std::array<T, 1> v)
109  {
110  ARMARX_CHECK(simox::math::value_in_limits_of_type<Type>(v.at(0)))
111  << VAROUT(v.at(0)) << " : " << GetTypeString<T>();
112  return min(static_cast<Type>(v.at(0)));
113  }
114 
115 
116  Derived& max(Type max)
117  {
118  Derived& this_ = *static_cast<Derived*>(this);
119  this_.widget().max = max;
120  return this_;
121  }
122  Derived& max(std::array<Type, 1> v)
123  {
124  return max(v.at(0));
125  }
126  template<class T>
127  std::enable_if_t <simox::meta::are_arithmetic_v<Type, T>, Derived&>
128  max(T v)
129  {
130  ARMARX_CHECK(simox::math::value_in_limits_of_type<Type>(v))
131  << VAROUT(v) << " : " << GetTypeString<T>();
132  return max(static_cast<Type>(v));
133  }
134  template<class T>
135  std::enable_if_t <simox::meta::are_arithmetic_v<Type, T>, Derived&>
136  max(std::array<T, 1> v)
137  {
138  ARMARX_CHECK(simox::math::value_in_limits_of_type<Type>(v.at(0)))
139  << VAROUT(v.at(0)) << " : " << GetTypeString<T>();
140  return max(static_cast<Type>(v.at(0)));
141  }
142 
143  template<class T0, class T1>
144  Derived& minmax(T0 lo, T1 hi)
145  {
146  Derived& this_ = *static_cast<Derived*>(this);
147  this_.min(lo);
148  return this_.max(hi);
149  }
150  };
151 
152  template <typename Derived>
153  struct MinMaxMixin<Derived, Eigen::Vector3f>
154  {
155  using Type = Eigen::Vector3f;
156 
157  Derived& min(Type min)
158  {
159  Derived& this_ = *static_cast<Derived*>(this);
160  this_.widget().min = toIceF(min);
161  return this_;
162  }
163  Derived& min(std::array<Type, 1> v)
164  {
165  return min(v.at(0));
166  }
167 
168  Derived& max(Type max)
169  {
170  Derived& this_ = *static_cast<Derived*>(this);
171  this_.widget().max = toIceF(max);
172  return this_;
173  }
174  Derived& max(std::array<Type, 1> v)
175  {
176  return max(v.at(0));
177  }
178 
179  template<class T0, class T1>
180  Derived& minmax(T0 lo, T1 hi)
181  {
182  Derived& this_ = *static_cast<Derived*>(this);
183  this_.min(lo);
184  return this_.max(hi);
185  }
186  };
187 
188  template <typename Derived>
189  struct LabelMixin
190  {
191  Derived& label(std::string const& label)
192  {
193  Derived& this_ = *static_cast<Derived*>(this);
194  this_.widget().label = label;
195  return this_;
196  }
197  };
198 
199  template <typename Derived>
201  {
202  Derived& toolTip(std::string const& toolTip)
203  {
204  Derived& this_ = *static_cast<Derived*>(this);
205  this_.widget().toolTip = toolTip;
206  return this_;
207  }
208  };
209 }
armarx::RemoteGui::detail::WidgetBuilder::~WidgetBuilder
virtual ~WidgetBuilder()=default
armarx::RemoteGui::detail::MinMaxMixin::min
Derived & min(Type min)
Definition: Basic.h:88
Eigen
Definition: Elements.h:36
armarx::RemoteGui::detail::WidgetBuilder::hidden
WidgetBuilder & hidden(bool hidden=true)
Definition: Basic.h:17
armarx::RemoteGui::toIceF
Vector3f toIceF(Eigen::Vector3f v)
Definition: Storage.cpp:73
armarx::RemoteGui::detail
Definition: Basic.h:10
armarx::RemoteGui::detail::MinMaxMixin
Definition: Basic.h:86
armarx::RemoteGui::detail::WidgetMixin
Definition: Basic.h:39
armarx::RemoteGui::detail::WidgetBuilder
Definition: Basic.h:12
armarx::RemoteGui::detail::WidgetBuilder::widget_
WidgetPtr widget_
Definition: Basic.h:35
Storage.h
armarx::RemoteGui::detail::LabelMixin
Definition: Basic.h:189
lo
#define lo(x)
Definition: AbstractInterface.h:43
ARMARX_CHECK
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
Definition: ExpressionException.h:82
armarx::RemoteGui::detail::MinMaxMixin::max
std::enable_if_t< simox::meta::are_arithmetic_v< Type, T >, Derived & > max(T v)
Definition: Basic.h:128
armarx::RemoteGui::detail::WidgetBuilder::disabled
WidgetBuilder & disabled(bool disabled=true)
Definition: Basic.h:23
armarx::RemoteGui::detail::WidgetMixin::widget
WidgetT & widget()
Definition: Basic.h:50
armarx::RemoteGui::detail::MinMaxMixin::max
Derived & max(Type max)
Definition: Basic.h:116
armarx::RemoteGui::detail::NoValueMixin
Definition: Basic.h:57
armarx::RemoteGui::detail::MinMaxMixin< Derived, Eigen::Vector3f >::Type
Eigen::Vector3f Type
Definition: Basic.h:155
armarx::RemoteGui::detail::MinMaxMixin< Derived, Eigen::Vector3f >::minmax
Derived & minmax(T0 lo, T1 hi)
Definition: Basic.h:180
armarx::RemoteGui::detail::ValueMixin::value
Derived & value(ValueT const &value)
Definition: Basic.h:77
armarx::RemoteGui::detail::LabelMixin::label
Derived & label(std::string const &label)
Definition: Basic.h:191
armarx::RemoteGui::detail::ToolTipMixin::toolTip
Derived & toolTip(std::string const &toolTip)
Definition: Basic.h:202
armarx::aron::similarity::FloatSimilarity::Type
Type
The Type enum.
Definition: FloatSimilarity.h:8
armarx::RemoteGui::detail::ValueMixin::defaultValue
static ValueVariant defaultValue()
Definition: Basic.h:72
armarx::RemoteGui::detail::ToolTipMixin
Definition: Basic.h:200
armarx::RemoteGui::makeValue
ValueVariant makeValue(bool value)
Definition: Storage.cpp:133
armarx::RemoteGui::detail::MinMaxMixin::min
std::enable_if_t< simox::meta::are_arithmetic_v< Type, T >, Derived & > min(std::array< T, 1 > v)
Definition: Basic.h:108
armarx::WidgetDescription::WidgetPtr
::IceInternal::Handle<::armarx::WidgetDescription::Widget > WidgetPtr
Definition: NJointControllerBase.h:66
ExpressionException.h
armarx::RemoteGui::detail::MinMaxMixin::minmax
Derived & minmax(T0 lo, T1 hi)
Definition: Basic.h:144
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
armarx::RemoteGui::detail::NoValueMixin::defaultValue
static ValueVariant defaultValue()
Definition: Basic.h:61
VAROUT
#define VAROUT(x)
Definition: StringHelpers.h:182
hi
#define hi(x)
Definition: AbstractInterface.h:42
armarx::RemoteGui::detail::WidgetMixin::WidgetMixin
WidgetMixin(std::string const &name)
Definition: Basic.h:42
armarx::RemoteGui::detail::MinMaxMixin::min
std::enable_if_t< simox::meta::are_arithmetic_v< Type, T >, Derived & > min(T v)
Definition: Basic.h:100
armarx::RemoteGui::detail::MinMaxMixin::max
Derived & max(std::array< Type, 1 > v)
Definition: Basic.h:122
T
float T
Definition: UnscentedKalmanFilterTest.cpp:35
armarx::RemoteGui::detail::MinMaxMixin::max
std::enable_if_t< simox::meta::are_arithmetic_v< Type, T >, Derived & > max(std::array< T, 1 > v)
Definition: Basic.h:136
armarx::RemoteGui::detail::MinMaxMixin::min
Derived & min(std::array< Type, 1 > v)
Definition: Basic.h:94
armarx::RemoteGui::detail::ValueMixin
Definition: Basic.h:68