DefaultWidgetDescriptions.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package ArmarXGui::ArmarXObjects::DefaultWidgetDescriptions
17 * @author Raphael Grimm ( raphael dot grimm at kit dot edu )
18 * @date 2017
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
24
26
28{
29 //base widgets
30 HBoxLayoutPtr
31 makeHBoxLayout(std::vector<WidgetPtr> elements)
32 {
33 HBoxLayoutPtr w = new HBoxLayout;
34 w->children = std::move(elements);
35 return w;
36 }
37
38 VBoxLayoutPtr
39 makeVBoxLayout(std::vector<WidgetPtr> elements)
40 {
41 VBoxLayoutPtr w = new VBoxLayout;
42 w->children = std::move(elements);
43 return w;
44 }
45
46 FormLayoutElementPtr
48 {
49 ARMARX_CHECK_NOT_NULL(labelWidget);
51 FormLayoutElementPtr e = new FormLayoutElement;
52 e->labelWidget = std::move(labelWidget);
53 e->child = std::move(child);
54 e->childIsSpanning = false;
55 return e;
56 }
57
58 FormLayoutElementPtr
59 makeFormLayoutElement(std::string name, WidgetPtr child, bool spanning)
60 {
62 FormLayoutElementPtr e = new FormLayoutElement;
63 e->label = std::move(name);
64 e->child = std::move(child);
65 e->childIsSpanning = spanning;
66 return e;
67 }
68
69 FormLayoutElementPtr
70 makeFormLayoutElement(WidgetPtr child, bool spanning)
71 {
73 FormLayoutElementPtr e = new FormLayoutElement;
74 if (ConfigWidgetPtr::dynamicCast(child))
75 {
76 e->label = ConfigWidgetPtr::dynamicCast(child)->name;
77 }
78 e->child = std::move(child);
79 e->childIsSpanning = spanning;
80 return e;
81 }
82
83 FormLayoutElementPtr
85 {
86 return makeFormLayoutElement(std::move(child), true);
87 }
88
89 FormLayoutPtr
90 makeFormLayout(std::vector<std::pair<std::string, WidgetPtr>> elements)
91 {
92 FormLayoutPtr l = new FormLayout;
93 l->children.reserve(elements.size());
94 for (auto& elem : elements)
95 {
96 l->children.emplace_back(
97 makeFormLayoutElement(std::move(elem.first), std::move(elem.second)));
98 }
99 return l;
100 }
101
102 FormLayoutPtr
103 makeFormLayout(std::vector<WidgetPtr> elements)
104 {
105 FormLayoutPtr l = new FormLayout;
106 l->children.reserve(elements.size());
107 for (auto& elem : elements)
108 {
109 l->children.emplace_back(makeFormLayoutElement(std::move(elem)));
110 }
111 return l;
112 }
113
114 GroupBoxPtr
115 makeGroupBox(std::string label, WidgetPtr child, bool framed)
116 {
117 GroupBoxPtr w = new GroupBox;
118 w->child = std::move(child);
119 w->label = std::move(label);
120 w->framed = framed;
121 return w;
122 }
123
126 {
127 child->framed = true;
128 return child;
129 }
130
131 HSpacerPtr
133 {
134 return new HSpacer;
135 }
136
137 VSpacerPtr
139 {
140 return new VSpacer;
141 }
142
143 HLinePtr
145 {
146 return new HLine;
147 }
148
149 VLinePtr
151 {
152 return new VLine;
153 }
154
155 LabelPtr
156 makeLabel(std::string text)
157 {
158 return new Label{false, std::move(text)};
159 }
160
161 CheckBoxPtr
162 makeCheckBox(std::string name, bool defaultValue, std::string label)
163 {
164 CheckBoxPtr w = new CheckBox;
165 w->name = std::move(name);
166 w->label = std::move(label);
167 w->defaultValue = defaultValue;
168 return w;
169 }
170
171 CheckBoxPtr
172 makeCheckBox(std::string name, bool defaultValue)
173 {
174 CheckBoxPtr w = new CheckBox;
175 w->name = std::move(name);
176 w->label = w->name;
177 w->defaultValue = defaultValue;
178 return w;
179 }
180
181 IntSpinBoxPtr
182 makeIntSpinBox(std::string name, int min, int max, int defaultValue)
183 {
184 IntSpinBoxPtr w = new IntSpinBox;
185 w->name = std::move(name);
186 w->min = min;
187 w->max = max;
188 w->defaultValue = defaultValue;
189 return w;
190 }
191
192 FloatSpinBoxPtr
193 makeFloatSpinBox(std::string name,
194 float min,
195 float max,
196 float defaultValue,
197 int steps,
198 int decimals)
199 {
200 FloatSpinBoxPtr w = new FloatSpinBox;
201 w->name = std::move(name);
202 w->min = min;
203 w->max = max;
204 w->defaultValue = defaultValue;
205 w->steps = steps;
206 w->decimals = decimals;
207 return w;
208 }
209
210 DoubleSpinBoxPtr
211 makeDoubleSpinBox(std::string name,
212 double min,
213 double max,
214 double defaultValue,
215 int steps,
216 int decimals)
217 {
218 DoubleSpinBoxPtr w = new DoubleSpinBox;
219 w->name = std::move(name);
220 w->min = min;
221 w->max = max;
222 w->defaultValue = defaultValue;
223 w->steps = steps;
224 w->decimals = decimals;
225 return w;
226 }
227
228 IntSliderPtr
229 makeIntSlider(std::string name, int min, int max, int defaultValue)
230 {
231 IntSliderPtr w = new IntSlider;
232 w->name = std::move(name);
233 w->min = min;
234 w->max = max;
235 w->defaultValue = defaultValue;
236 return w;
237 }
238
239 FloatSliderPtr
240 makeFloatSlider(std::string name, float min, float max, float defaultValue)
241 {
242 FloatSliderPtr w = new FloatSlider;
243 w->name = std::move(name);
244 w->min = min;
245 w->max = max;
246 w->defaultValue = defaultValue;
247 return w;
248 }
249
250 DoubleSliderPtr
251 makeDoubleSlider(std::string name, double min, double max, double defaultValue)
252 {
253 DoubleSliderPtr w = new DoubleSlider;
254 w->name = std::move(name);
255 w->min = min;
256 w->max = max;
257 w->defaultValue = defaultValue;
258 return w;
259 }
260
261 StringComboBoxPtr
262 makeStringComboBox(std::string name, std::vector<std::string> options, long defaultIndex)
263 {
264 StringComboBoxPtr w = new StringComboBox;
265 w->name = std::move(name);
266 w->options = std::move(options);
267 w->defaultIndex = defaultIndex;
268 return w;
269 }
270
271 LineEditPtr
272 makeLineEdit(std::string name, std::string defaultValue)
273 {
274 LineEditPtr w = new LineEdit;
275 w->name = std::move(name);
276 w->defaultValue = std::move(defaultValue);
277 return w;
278 }
279
280 FloatLineEditPtr
281 makeFloatLineEdit(std::string name, float defaultValue)
282 {
283 FloatLineEditPtr w = new FloatLineEdit;
284 w->name = std::move(name);
285 w->defaultValue = defaultValue;
286 return w;
287 }
288
289 DoubleLineEditPtr
290 makeDoubleLineEdit(std::string name, double defaultValue)
291 {
292 DoubleLineEditPtr w = new DoubleLineEdit;
293 w->name = std::move(name);
294 w->defaultValue = defaultValue;
295 return w;
296 }
297
298 //more complex widgets
299 HBoxLayoutPtr
300 makeXYZRollPitchYawWidget(const std::string& namePrefix,
301 float initX,
302 float initY,
303 float initZ,
304 float initRoll,
305 float initPitch,
306 float initYaw,
307 FloatRange rangeX,
308 FloatRange rangeY,
309 FloatRange rangeZ,
310 FloatRange rangeRoll,
311 FloatRange rangePitch,
312 FloatRange rangeYaw)
313 {
314 return makeHBoxLayout(
315 {makeLabel("x / y / z"),
316 makeFloatSpinBox(namePrefix + "X", rangeX.min, rangeX.max, initX),
317 makeFloatSpinBox(namePrefix + "Y", rangeY.min, rangeY.max, initY),
318 makeFloatSpinBox(namePrefix + "Z", rangeZ.min, rangeZ.max, initZ),
319 makeLabel(" rx / ry / rz"),
320 makeFloatSpinBox(namePrefix + "Roll", rangeRoll.min, rangeRoll.max, initRoll, 2000),
322 namePrefix + "Pitch", rangePitch.min, rangePitch.max, initPitch, 2000),
323 makeFloatSpinBox(namePrefix + "Yaw", rangeYaw.min, rangeYaw.max, initYaw, 2000)});
324 }
325} // namespace armarx::WidgetDescription
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
StringComboBoxPtr makeStringComboBox(std::string name, std::vector< std::string > options, long defaultIndex)
IntSpinBoxPtr makeIntSpinBox(std::string name, int min, int max, int defaultValue)
LineEditPtr makeLineEdit(std::string name, std::string defaultValue)
DoubleSliderPtr makeDoubleSlider(std::string name, double min, double max, double defaultValue)
DoubleLineEditPtr makeDoubleLineEdit(std::string name, double defaultValue)
FloatSpinBoxPtr makeFloatSpinBox(std::string name, float min, float max, float defaultValue, int steps, int decimals)
WidgetPtr makeFrame(WidgetPtr child)
HBoxLayoutPtr makeHBoxLayout(std::vector< WidgetPtr > elements)
DoubleSpinBoxPtr makeDoubleSpinBox(std::string name, double min, double max, double defaultValue, int steps, int decimals)
FloatSliderPtr makeFloatSlider(std::string name, float min, float max, float defaultValue)
CheckBoxPtr makeCheckBox(std::string name, bool defaultValue, std::string label)
GroupBoxPtr makeGroupBox(std::string label, WidgetPtr child, bool framed)
LabelPtr makeLabel(std::string text)
FormLayoutPtr makeFormLayout(std::vector< std::pair< std::string, WidgetPtr > > elements)
FloatLineEditPtr makeFloatLineEdit(std::string name, float defaultValue)
VBoxLayoutPtr makeVBoxLayout(std::vector< WidgetPtr > elements)
::IceInternal::Handle<::armarx::WidgetDescription::Widget > WidgetPtr
FormLayoutElementPtr makeSpanningFormLayoutElement(WidgetPtr child)
IntSliderPtr makeIntSlider(std::string name, int min, int max, int defaultValue)
FormLayoutElementPtr makeFormLayoutElement(WidgetPtr labelWidget, WidgetPtr child)
HBoxLayoutPtr makeXYZRollPitchYawWidget(const std::string &namePrefix, float initX, float initY, float initZ, float initRoll, float initPitch, float initYaw, FloatRange rangeX, FloatRange rangeY, FloatRange rangeZ, FloatRange rangeRoll, FloatRange rangePitch, FloatRange rangeYaw)
Values will have the names namePrefix{X,Y,Z,Roll,Pitch,Yaw}.
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
std::vector< T > min(const std::vector< T > &v1, const std::vector< T > &v2)