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