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:
38 WidgetPtr widget_;
39 };
40
41 template <typename WidgetT, typename Derived>
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 {
63 using WidgetMixin<WidgetT, Derived>::WidgetMixin;
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 {
75 using WidgetMixin<WidgetT, Derived>::WidgetMixin;
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>
94 {
95 Derived&
96 min(Type min)
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&>
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&
128 max(Type max)
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&>
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&
175 min(Type min)
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&
189 max(Type max)
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>
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
#define lo(x)
#define hi(x)
#define VAROUT(x)
WidgetBuilder & hidden(bool hidden=true)
Definition Basic.h:18
WidgetBuilder & disabled(bool disabled=true)
Definition Basic.h:25
WidgetMixin(std::string const &name)
Definition Basic.h:45
T max(T t1, T t2)
Definition gdiam.h:51
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
Vector3f toIceF(Eigen::Vector3f v)
Definition Storage.cpp:80
ValueVariant makeValue(bool value)
Definition Storage.cpp:144
double v(double t, double v0, double a0, double j)
Definition CtrlUtil.h:39
std::string GetTypeString(const std::type_info &tinf, bool withoutNamespaceSpecifier=false)
std::vector< T > min(const std::vector< T > &v1, const std::vector< T > &v2)
Derived & label(std::string const &label)
Definition Basic.h:216
std::enable_if_t< simox::meta::are_arithmetic_v< Type, T >, Derived & > max(std::array< T, 1 > v)
Definition Basic.h:152
std::enable_if_t< simox::meta::are_arithmetic_v< Type, T >, Derived & > max(T v)
Definition Basic.h:143
std::enable_if_t< simox::meta::are_arithmetic_v< Type, T >, Derived & > min(T v)
Definition Basic.h:111
Derived & max(std::array< Type, 1 > v)
Definition Basic.h:136
Derived & minmax(T0 lo, T1 hi)
Definition Basic.h:161
Derived & min(std::array< Type, 1 > v)
Definition Basic.h:104
std::enable_if_t< simox::meta::are_arithmetic_v< Type, T >, Derived & > min(std::array< T, 1 > v)
Definition Basic.h:120
static ValueVariant defaultValue()
Definition Basic.h:66
Derived & toolTip(std::string const &toolTip)
Definition Basic.h:228
Derived & value(ValueT const &value)
Definition Basic.h:84
static ValueVariant defaultValue()
Definition Basic.h:78