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 makeHBoxLayout(std::vector<WidgetPtr> elements)
31  {
32  HBoxLayoutPtr w = new HBoxLayout;
33  w->children = std::move(elements);
34  return w;
35  }
36 
37  VBoxLayoutPtr makeVBoxLayout(std::vector<WidgetPtr> elements)
38  {
39  VBoxLayoutPtr w = new VBoxLayout;
40  w->children = std::move(elements);
41  return w;
42  }
43 
44  FormLayoutElementPtr makeFormLayoutElement(WidgetPtr labelWidget, WidgetPtr child)
45  {
46  ARMARX_CHECK_NOT_NULL(labelWidget);
47  ARMARX_CHECK_NOT_NULL(child);
48  FormLayoutElementPtr e = new FormLayoutElement;
49  e->labelWidget = std::move(labelWidget);
50  e->child = std::move(child);
51  e->childIsSpanning = false;
52  return e;
53  }
54 
55  FormLayoutElementPtr makeFormLayoutElement(std::string name, WidgetPtr child, bool spanning)
56  {
57  ARMARX_CHECK_NOT_NULL(child);
58  FormLayoutElementPtr e = new FormLayoutElement;
59  e->label = std::move(name);
60  e->child = std::move(child);
61  e->childIsSpanning = spanning;
62  return e;
63  }
64 
65  FormLayoutElementPtr makeFormLayoutElement(WidgetPtr child, bool spanning)
66  {
67  ARMARX_CHECK_NOT_NULL(child);
68  FormLayoutElementPtr e = new FormLayoutElement;
69  if (ConfigWidgetPtr::dynamicCast(child))
70  {
71  e->label = ConfigWidgetPtr::dynamicCast(child)->name;
72  }
73  e->child = std::move(child);
74  e->childIsSpanning = spanning;
75  return e;
76  }
77 
78  FormLayoutElementPtr makeSpanningFormLayoutElement(WidgetPtr child)
79  {
80  return makeFormLayoutElement(std::move(child), true);
81  }
82 
83  FormLayoutPtr makeFormLayout(std::vector<std::pair<std::string, WidgetPtr> > elements)
84  {
85  FormLayoutPtr l = new FormLayout;
86  l->children.reserve(elements.size());
87  for (auto& elem : elements)
88  {
89  l->children.emplace_back(makeFormLayoutElement(std::move(elem.first), std::move(elem.second)));
90  }
91  return l;
92  }
93 
94  FormLayoutPtr makeFormLayout(std::vector<WidgetPtr> elements)
95  {
96  FormLayoutPtr l = new FormLayout;
97  l->children.reserve(elements.size());
98  for (auto& elem : elements)
99  {
100  l->children.emplace_back(makeFormLayoutElement(std::move(elem)));
101  }
102  return l;
103  }
104 
105  GroupBoxPtr makeGroupBox(std::string label, WidgetPtr child, bool framed)
106  {
107  GroupBoxPtr w = new GroupBox;
108  w->child = std::move(child);
109  w->label = std::move(label);
110  w->framed = framed;
111  return w;
112  }
113 
115  {
116  child->framed = true;
117  return child;
118  }
119 
120  HSpacerPtr makeHSpacer()
121  {
122  return new HSpacer;
123  }
124 
125  VSpacerPtr makeVSpacer()
126  {
127  return new VSpacer;
128  }
129 
130  HLinePtr makeHLine()
131  {
132  return new HLine;
133  }
134 
135  VLinePtr makeVLine()
136  {
137  return new VLine;
138  }
139 
140  LabelPtr makeLabel(std::string text)
141  {
142  return new Label {false, std::move(text)};
143  }
144 
145  CheckBoxPtr makeCheckBox(std::string name, bool defaultValue, std::string label)
146  {
147  CheckBoxPtr w = new CheckBox;
148  w->name = std::move(name);
149  w->label = std::move(label);
150  w->defaultValue = defaultValue;
151  return w;
152  }
153  CheckBoxPtr makeCheckBox(std::string name, bool defaultValue)
154  {
155  CheckBoxPtr w = new CheckBox;
156  w->name = std::move(name);
157  w->label = w->name;
158  w->defaultValue = defaultValue;
159  return w;
160  }
161 
162  IntSpinBoxPtr makeIntSpinBox(std::string name, int min, int max, int defaultValue)
163  {
164  IntSpinBoxPtr w = new IntSpinBox;
165  w->name = std::move(name);
166  w->min = min;
167  w->max = max;
168  w->defaultValue = defaultValue;
169  return w;
170  }
171 
172  FloatSpinBoxPtr makeFloatSpinBox(std::string name, float min, float max, float defaultValue, int steps, int decimals)
173  {
174  FloatSpinBoxPtr w = new FloatSpinBox;
175  w->name = std::move(name);
176  w->min = min;
177  w->max = max;
178  w->defaultValue = defaultValue;
179  w->steps = steps;
180  w->decimals = decimals;
181  return w;
182  }
183 
184  DoubleSpinBoxPtr makeDoubleSpinBox(std::string name, double min, double max, double defaultValue, int steps, int decimals)
185  {
186  DoubleSpinBoxPtr w = new DoubleSpinBox;
187  w->name = std::move(name);
188  w->min = min;
189  w->max = max;
190  w->defaultValue = defaultValue;
191  w->steps = steps;
192  w->decimals = decimals;
193  return w;
194  }
195 
196  IntSliderPtr makeIntSlider(std::string name, int min, int max, int defaultValue)
197  {
198  IntSliderPtr w = new IntSlider;
199  w->name = std::move(name);
200  w->min = min;
201  w->max = max;
202  w->defaultValue = defaultValue;
203  return w;
204  }
205 
206  FloatSliderPtr makeFloatSlider(std::string name, float min, float max, float defaultValue)
207  {
208  FloatSliderPtr w = new FloatSlider;
209  w->name = std::move(name);
210  w->min = min;
211  w->max = max;
212  w->defaultValue = defaultValue;
213  return w;
214  }
215 
216  DoubleSliderPtr makeDoubleSlider(std::string name, double min, double max, double defaultValue)
217  {
218  DoubleSliderPtr w = new DoubleSlider;
219  w->name = std::move(name);
220  w->min = min;
221  w->max = max;
222  w->defaultValue = defaultValue;
223  return w;
224  }
225 
226  StringComboBoxPtr makeStringComboBox(std::string name, std::vector<std::string> options, long defaultIndex)
227  {
228  StringComboBoxPtr w = new StringComboBox;
229  w->name = std::move(name);
230  w->options = std::move(options);
231  w->defaultIndex = defaultIndex;
232  return w;
233  }
234 
235  LineEditPtr makeLineEdit(std::string name, std::string defaultValue)
236  {
237  LineEditPtr w = new LineEdit;
238  w->name = std::move(name);
239  w->defaultValue = std::move(defaultValue);
240  return w;
241  }
242 
243  FloatLineEditPtr makeFloatLineEdit(std::string name, float defaultValue)
244  {
245  FloatLineEditPtr w = new FloatLineEdit;
246  w->name = std::move(name);
247  w->defaultValue = defaultValue;
248  return w;
249  }
250 
251  DoubleLineEditPtr makeDoubleLineEdit(std::string name, double defaultValue)
252  {
253  DoubleLineEditPtr w = new DoubleLineEdit;
254  w->name = std::move(name);
255  w->defaultValue = defaultValue;
256  return w;
257  }
258 
259  //more complex widgets
261  const std::string& namePrefix,
262  float initX,
263  float initY,
264  float initZ,
265  float initRoll,
266  float initPitch,
267  float initYaw,
268  FloatRange rangeX,
269  FloatRange rangeY,
270  FloatRange rangeZ,
271  FloatRange rangeRoll,
272  FloatRange rangePitch,
273  FloatRange rangeYaw)
274  {
275  return makeHBoxLayout(
276  {
277  makeLabel("x / y / z"),
278  makeFloatSpinBox(namePrefix + "X", rangeX.min, rangeX.max, initX),
279  makeFloatSpinBox(namePrefix + "Y", rangeY.min, rangeY.max, initY),
280  makeFloatSpinBox(namePrefix + "Z", rangeZ.min, rangeZ.max, initZ),
281  makeLabel(" rx / ry / rz"),
282  makeFloatSpinBox(namePrefix + "Roll", rangeRoll.min, rangeRoll.max, initRoll, 2000),
283  makeFloatSpinBox(namePrefix + "Pitch", rangePitch.min, rangePitch.max, initPitch, 2000),
284  makeFloatSpinBox(namePrefix + "Yaw", rangeYaw.min, rangeYaw.max, initYaw, 2000)
285  });
286  }
287 }
armarx::WidgetDescription::makeSpanningFormLayoutElement
FormLayoutElementPtr makeSpanningFormLayoutElement(WidgetPtr child)
Definition: DefaultWidgetDescriptions.cpp:78
armarx::WidgetDescription::makeVSpacer
VSpacerPtr makeVSpacer()
Definition: DefaultWidgetDescriptions.cpp:125
armarx::WidgetDescription::makeGroupBox
GroupBoxPtr makeGroupBox(std::string label, WidgetPtr child, bool framed)
Definition: DefaultWidgetDescriptions.cpp:105
armarx::RemoteGui::Client::VBoxLayout
Definition: Widgets.h:167
armarx::RemoteGui::Client::Label
Definition: Widgets.h:31
armarx::WidgetDescription::makeDoubleSlider
DoubleSliderPtr makeDoubleSlider(std::string name, double min, double max, double defaultValue)
Definition: DefaultWidgetDescriptions.cpp:216
ARMARX_CHECK_NOT_NULL
#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...
Definition: ExpressionException.h:206
armarx::RemoteGui::Client::HSpacer
Definition: Widgets.h:209
armarx::WidgetDescription::makeHBoxLayout
HBoxLayoutPtr makeHBoxLayout(std::vector< WidgetPtr > elements)
Definition: DefaultWidgetDescriptions.cpp:30
armarx::max
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
Definition: VectorHelpers.h:267
armarx::WidgetDescription::makeFloatSlider
FloatSliderPtr makeFloatSlider(std::string name, float min, float max, float defaultValue)
Definition: DefaultWidgetDescriptions.cpp:206
armarx::RemoteGui::Client::VSpacer
Definition: Widgets.h:204
armarx::WidgetDescription::makeHLine
HLinePtr makeHLine()
Definition: DefaultWidgetDescriptions.cpp:130
armarx::WidgetDescription::makeFloatSpinBox
FloatSpinBoxPtr makeFloatSpinBox(std::string name, float min, float max, float defaultValue, int steps, int decimals)
Definition: DefaultWidgetDescriptions.cpp:172
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::WidgetDescription::makeLabel
LabelPtr makeLabel(std::string text)
Definition: DefaultWidgetDescriptions.cpp:140
armarx::WidgetDescription::makeDoubleLineEdit
DoubleLineEditPtr makeDoubleLineEdit(std::string name, double defaultValue)
Definition: DefaultWidgetDescriptions.cpp:251
armarx::WidgetDescription::makeFrame
WidgetPtr makeFrame(WidgetPtr child)
Definition: DefaultWidgetDescriptions.cpp:114
armarx::WidgetDescription
Definition: DefaultWidgetDescriptions.cpp:27
armarx::RemoteGui::Client::FloatSlider
Definition: Widgets.h:107
armarx::WidgetDescription::makeIntSlider
IntSliderPtr makeIntSlider(std::string name, int min, int max, int defaultValue)
Definition: DefaultWidgetDescriptions.cpp:196
armarx::RemoteGui::Client::IntSlider
Definition: Widgets.h:81
armarx::WidgetDescription::makeFormLayoutElement
FormLayoutElementPtr makeFormLayoutElement(WidgetPtr labelWidget, WidgetPtr child)
Definition: DefaultWidgetDescriptions.cpp:44
armarx::WidgetDescription::makeVLine
VLinePtr makeVLine()
Definition: DefaultWidgetDescriptions.cpp:135
armarx::WidgetDescription::makeFloatLineEdit
FloatLineEditPtr makeFloatLineEdit(std::string name, float defaultValue)
Definition: DefaultWidgetDescriptions.cpp:243
armarx::RemoteGui::Client::GroupBox
Definition: Widgets.h:193
armarx::RemoteGui::Client::LineEdit
Definition: Widgets.h:40
armarx::WidgetDescription::makeFormLayout
FormLayoutPtr makeFormLayout(std::vector< std::pair< std::string, WidgetPtr > > elements)
Definition: DefaultWidgetDescriptions.cpp:83
armarx::WidgetDescription::makeXYZRollPitchYawWidget
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}.
Definition: DefaultWidgetDescriptions.cpp:260
DefaultWidgetDescriptions.h
armarx::WidgetDescription::makeIntSpinBox
IntSpinBoxPtr makeIntSpinBox(std::string name, int min, int max, int defaultValue)
Definition: DefaultWidgetDescriptions.cpp:162
armarx::WidgetDescription::makeDoubleSpinBox
DoubleSpinBoxPtr makeDoubleSpinBox(std::string name, double min, double max, double defaultValue, int steps, int decimals)
Definition: DefaultWidgetDescriptions.cpp:184
armarx::RemoteGui::Client::HBoxLayout
Definition: Widgets.h:160
ExpressionException.h
armarx::min
std::vector< T > min(const std::vector< T > &v1, const std::vector< T > &v2)
Definition: VectorHelpers.h:294
armarx::WidgetDescription::makeStringComboBox
StringComboBoxPtr makeStringComboBox(std::string name, std::vector< std::string > options, long defaultIndex)
Definition: DefaultWidgetDescriptions.cpp:226
armarx::WidgetDescription::makeCheckBox
CheckBoxPtr makeCheckBox(std::string name, bool defaultValue, std::string label)
Definition: DefaultWidgetDescriptions.cpp:145
armarx::WidgetDescription::makeHSpacer
HSpacerPtr makeHSpacer()
Definition: DefaultWidgetDescriptions.cpp:120
armarx::RemoteGui::Client::IntSpinBox
Definition: Widgets.h:69
armarx::RemoteGui::Client::CheckBox
Definition: Widgets.h:129
armarx::WidgetDescription::makeLineEdit
LineEditPtr makeLineEdit(std::string name, std::string defaultValue)
Definition: DefaultWidgetDescriptions.cpp:235
armarx::WidgetDescription::makeVBoxLayout
VBoxLayoutPtr makeVBoxLayout(std::vector< WidgetPtr > elements)
Definition: DefaultWidgetDescriptions.cpp:37
armarx::RemoteGui::Client::FloatSpinBox
Definition: Widgets.h:93