ADTF Display Toolbox
Loading...
Searching...
No Matches
sensormanipulator.h
Go to the documentation of this file.
1
7
8/*
9 * This file depends on Qt which is licensed under LGPLv3.
10 * See ADTF_DIR/3rdparty/qt5 and doc/license for detailed information.
11 */
12
14
15#pragma once
16
18
19#include <QWidget>
20#include <QFrame>
21#include <QLabel>
22#include <QLayout>
23#include <QLineEdit>
24#include <QSlider>
25#include <QString>
26#include <QCloseEvent>
27
28#include <cmath>
29#ifndef M_PI
30namespace
31{
32const double M_PI = std::acos(-1.0);
33const double M_PI_2 = M_PI / 2.0;
34} // namespace
35#endif
36
37#ifndef DEG2RAD
38 #define DEG2RAD(angle) ((angle) * M_PI / 180.0)
39#endif
40#ifndef RAD2DEG
41 #define RAD2DEG(angle) ((angle) * 180.0 / M_PI)
42#endif
43
44namespace adtf
45{
46
47namespace disptb
48{
49
50namespace mixinlib
51{
52
53namespace endor
54{
55
62class cSensorManipulator : public QWidget
63{
64 // Removed Q_OBJECT for switch to interface library
65public:
66 class Delegate
67 {
68 public:
69 virtual void ValuesChangedInManipulator(cSensorManipulator* pManip) = 0;
70 };
71
72 explicit cSensorManipulator(QWidget* parent = nullptr, Qt::WindowFlags flags = Qt::Widget): QWidget(parent)
73 {
74 setWindowFlags(flags);
75
76 int row = 0;
77 auto pLayout = new QGridLayout;
78 auto pLabel = new QLabel("Roll [degrees]", this);
79
80 pLayout->addWidget(pLabel, row, 0);
81
82 m_pRollSlider = new QSlider(Qt::Horizontal, this);
83 m_pRollSlider->setMinimum(-1799);
84 m_pRollSlider->setMaximum(1800);
85 m_pRollSlider->setPageStep(10);
86 m_pRollSlider->setValue(0);
87 pLayout->addWidget(m_pRollSlider, row, 1);
88 QObject::connect(m_pRollSlider, SIGNAL(valueChanged(int)), this, SLOT(rollChanged(int)));
89
90 m_pRollLine = new QLineEdit;
91 m_pRollLine->setText("0.0");
92 pLayout->addWidget(m_pRollLine, row, 2);
93 QObject::connect(m_pRollLine, SIGNAL(editingFinished()), this, SLOT(rollEditFinished()));
94
95 row++;
96
97 // pitch
98
99 pLabel = new QLabel("Pitch [degrees]", this);
100 pLayout->addWidget(pLabel, row, 0);
101
102 m_pPitchSlider = new QSlider(Qt::Horizontal, this);
103 m_pPitchSlider->setMinimum(-1799);
104 m_pPitchSlider->setMaximum(1800);
105 m_pPitchSlider->setPageStep(10);
106 m_pPitchSlider->setValue(0);
107 pLayout->addWidget(m_pPitchSlider, row, 1);
108 QObject::connect(m_pPitchSlider, SIGNAL(valueChanged(int)), this, SLOT(pitchChanged(int)));
109
110 m_pPitchLine = new QLineEdit;
111 m_pPitchLine->setText("0.0");
112 pLayout->addWidget(m_pPitchLine, row, 2);
113 QObject::connect(m_pPitchLine, SIGNAL(editingFinished()), this, SLOT(pitchEditFinished()));
114
115 row++;
116
117 // yaw
118
119 pLabel = new QLabel("Yaw [degrees]", this);
120 pLayout->addWidget(pLabel, row, 0);
121
122 m_pYawSlider = new QSlider(Qt::Horizontal, this);
123 m_pYawSlider->setMinimum(-1799);
124 m_pYawSlider->setMaximum(1800);
125 m_pYawSlider->setPageStep(10);
126 m_pYawSlider->setValue(0);
127 pLayout->addWidget(m_pYawSlider, row, 1);
128 QObject::connect(m_pYawSlider, SIGNAL(valueChanged(int)), this, SLOT(yawChanged(int)));
129
130 m_pYawLine = new QLineEdit;
131 m_pYawLine->setText("0.0");
132 pLayout->addWidget(m_pYawLine, row, 2);
133 QObject::connect(m_pYawLine, SIGNAL(editingFinished()), this, SLOT(yawEditFinished()));
134
135 row++;
136
137 // x
138
139 pLabel = new QLabel("X [m]", this);
140 pLayout->addWidget(pLabel, row, 0);
141
142 m_pXSlider = new QSlider(Qt::Horizontal, this);
143 m_pXSlider->setMinimum(-10000);
144 m_pXSlider->setMaximum(10000);
145 m_pXSlider->setPageStep(100);
146 m_pXSlider->setValue(0);
147 pLayout->addWidget(m_pXSlider, row, 1);
148 QObject::connect(m_pXSlider, SIGNAL(valueChanged(int)), this, SLOT(xChanged(int)));
149
150 m_pXLine = new QLineEdit;
151 m_pXLine->setText("0.00");
152 pLayout->addWidget(m_pXLine, row, 2);
153 QObject::connect(m_pXLine, SIGNAL(editingFinished()), this, SLOT(xEditFinished()));
154
155 row++;
156
157 // y
158
159 pLabel = new QLabel("Y [m]", this);
160 pLayout->addWidget(pLabel, row, 0);
161
162 m_pYSlider = new QSlider(Qt::Horizontal, this);
163 m_pYSlider->setMinimum(-10000);
164 m_pYSlider->setMaximum(10000);
165 m_pYSlider->setPageStep(100);
166 m_pYSlider->setValue(0);
167 pLayout->addWidget(m_pYSlider, row, 1);
168 QObject::connect(m_pYSlider, SIGNAL(valueChanged(int)), this, SLOT(yChanged(int)));
169
170 m_pYLine = new QLineEdit;
171 m_pYLine->setText("0.00");
172 pLayout->addWidget(m_pYLine, row, 2);
173 QObject::connect(m_pYLine, SIGNAL(editingFinished()), this, SLOT(yEditFinished()));
174
175 row++;
176
177 // z
178
179 pLabel = new QLabel("Z [m]", this);
180 pLayout->addWidget(pLabel, row, 0);
181
182 m_pZSlider = new QSlider(Qt::Horizontal, this);
183 m_pZSlider->setMinimum(-10000);
184 m_pZSlider->setMaximum(10000);
185 m_pZSlider->setPageStep(100);
186 m_pZSlider->setValue(0);
187 pLayout->addWidget(m_pZSlider, row, 1);
188 QObject::connect(m_pZSlider, SIGNAL(valueChanged(int)), this, SLOT(zChanged(int)));
189
190 m_pZLine = new QLineEdit;
191 m_pZLine->setText("0.00");
192 pLayout->addWidget(m_pZLine, row, 2);
193 QObject::connect(m_pZLine, SIGNAL(editingFinished()), this, SLOT(zEditFinished()));
194
195 pLayout->setColumnMinimumWidth(1, 200);
196 pLayout->setColumnStretch(1, 1);
197
198 setLayout(pLayout);
199 }
200
201 ~cSensorManipulator() override = default;
202
204 void setRollPitchYawRad(tFloat64 fRoll, tFloat64 fPitch, tFloat64 fYaw)
205 {
206 setRollPitchYawDeg(RAD2DEG(fRoll), RAD2DEG(fPitch), RAD2DEG(fYaw));
207 }
208
210 void setRollPitchYawDeg(tFloat64 fRoll, tFloat64 fPitch, tFloat64 fYaw)
211 {
212 m_pRollSlider->setValue(static_cast<int>(fRoll * 10.0f + 0.5f));
213 m_pRollLine->setText(QString("%1").arg(fRoll, 0, 'f', 1));
214 m_pPitchSlider->setValue(static_cast<int>(fPitch * 10.0f + 0.5f));
215 m_pPitchLine->setText(QString("%1").arg(fPitch, 0, 'f', 1));
216 m_pYawSlider->setValue(static_cast<int>(fYaw * 10.0f + 0.5f));
217 m_pYawLine->setText(QString("%1").arg(fYaw, 0, 'f', 1));
218 }
219
221 void getRollPitchYawRad(tFloat64& fRoll, tFloat64& fPitch, tFloat64& fYaw)
222 {
223 fRoll = DEG2RAD(m_pRollSlider->value() / 10.0f);
224 fPitch = DEG2RAD(m_pPitchSlider->value() / 10.0f);
225 fYaw = DEG2RAD(m_pYawSlider->value() / 10.0f);
226 }
227
229 void setXYZ(tFloat64 fX, tFloat64 fY, tFloat64 fZ)
230 {
231 m_pXSlider->setValue(static_cast<int>(fX * 100.0f + 0.5f));
232 m_pXLine->setText(QString("%1").arg(fX, 0, 'f', 2));
233 m_pYSlider->setValue(static_cast<int>(fY * 100.0f + 0.5f));
234 m_pYLine->setText(QString("%1").arg(fY, 0, 'f', 2));
235 m_pZSlider->setValue(static_cast<int>(fZ * 100.0f + 0.5f));
236 m_pZLine->setText(QString("%1").arg(fZ, 0, 'f', 2));
237 }
238
240 void getXYZ(tFloat64& fX, tFloat64& fY, tFloat64& fZ)
241 {
242 fX = (tFloat64) m_pXSlider->value() / 100.0f;
243 fY = (tFloat64) m_pYSlider->value() / 100.0f;
244 fZ = (tFloat64) m_pZSlider->value() / 100.0f;
245 }
246
247 void setDelegate(Delegate* deleg, void* userData = nullptr)
248 {
249 m_pDeleg = deleg;
250 m_pUserData = userData;
251 }
252
253 void* getUserData()
254 {
255 return m_pUserData;
256 }
257
258public slots:
259 void rollChanged(int value)
260 {
261 m_pRollLine->setText(QString("%1").arg(static_cast<float>(value / 10.0f), 0, 'f', 1));
262 if (m_pDeleg)
263 {
264 m_pDeleg->ValuesChangedInManipulator(this);
265 }
266 }
267
268 void rollEditFinished()
269 {
270 const QString& str = m_pRollLine->text();
271 bool ok;
272 int val = str.toInt(&ok);
273 if (ok)
274 m_pRollSlider->setValue(static_cast<int>(val * 10.0f + 0.5f));
275 if (m_pDeleg)
276 {
277 m_pDeleg->ValuesChangedInManipulator(this);
278 }
279 }
280
281 void pitchChanged(int value)
282 {
283 m_pPitchLine->setText(QString("%1").arg((tFloat64) value / 10.0f, 0, 'f', 1));
284 if (m_pDeleg)
285 {
286 m_pDeleg->ValuesChangedInManipulator(this);
287 }
288 };
289
290 void pitchEditFinished()
291 {
292 const QString& str = m_pPitchLine->text();
293 bool ok;
294 int val = str.toInt(&ok);
295
296 if (ok)
297 {
298 m_pPitchSlider->setValue(static_cast<int>(val * 10.0f + 0.5f));
299 }
300
301 if (m_pDeleg)
302 {
303 m_pDeleg->ValuesChangedInManipulator(this);
304 }
305 };
306
307 void yawChanged(int value)
308 {
309 m_pYawLine->setText(QString("%1").arg((tFloat64) value / 10.0f, 0, 'f', 1));
310 if (m_pDeleg)
311 {
312 m_pDeleg->ValuesChangedInManipulator(this);
313 }
314 };
315
316 void yawEditFinished()
317 {
318 const QString& str = m_pYawLine->text();
319 bool ok;
320 int val = str.toInt(&ok);
321
322 if (ok)
323 {
324 m_pYawSlider->setValue(static_cast<int>(val * 10.0f + 0.5f));
325 }
326
327 if (m_pDeleg)
328 {
329 m_pDeleg->ValuesChangedInManipulator(this);
330 }
331 };
332
333 void xChanged(int value)
334 {
335 m_pXLine->setText(QString("%1").arg((tFloat64) value / 100.0f, 0, 'f', 2));
336 if (m_pDeleg)
337 {
338 m_pDeleg->ValuesChangedInManipulator(this);
339 }
340 };
341
342 void xEditFinished()
343 {
344 const QString& str = m_pXLine->text();
345 bool ok;
346 tFloat64 val = str.toDouble(&ok);
347
348 if (ok)
349 {
350 m_pXSlider->setValue(static_cast<int>(val * 100.0f + 0.5f));
351 }
352
353 if (m_pDeleg)
354 {
355 m_pDeleg->ValuesChangedInManipulator(this);
356 }
357 };
358
359 void yChanged(int value)
360 {
361 m_pYLine->setText(QString("%1").arg((tFloat64) value / 100.0f, 0, 'f', 2));
362 if (m_pDeleg)
363 {
364 m_pDeleg->ValuesChangedInManipulator(this);
365 }
366 };
367
368 void yEditFinished()
369 {
370 const QString& str = m_pYLine->text();
371 bool ok;
372 tFloat64 val = str.toDouble(&ok);
373
374 if (ok)
375 {
376 m_pYSlider->setValue(static_cast<int>(val * 100.0f + 0.5f));
377 }
378
379 if (m_pDeleg)
380 {
381 m_pDeleg->ValuesChangedInManipulator(this);
382 }
383 };
384
385 void zChanged(int value)
386 {
387 m_pZLine->setText(QString("%1").arg((tFloat64) value / 100.0f, 0, 'f', 2));
388 if (m_pDeleg)
389 {
390 m_pDeleg->ValuesChangedInManipulator(this);
391 }
392 };
393
394 void zEditFinished()
395 {
396 const QString& str = m_pZLine->text();
397 bool ok;
398 tFloat64 val = str.toDouble(&ok);
399
400 if (ok)
401 {
402 m_pZSlider->setValue(static_cast<int>(val * 100.0f + 0.5f));
403 }
404
405 if (m_pDeleg)
406 {
407 m_pDeleg->ValuesChangedInManipulator(this);
408 }
409 };
410
411protected:
412 QFrame* m_p6DPoseFrame;
413
414 QSlider *m_pRollSlider, *m_pPitchSlider, *m_pYawSlider;
415 QSlider *m_pXSlider, *m_pYSlider, *m_pZSlider;
416 QLineEdit *m_pRollLine, *m_pPitchLine, *m_pYawLine;
417 QLineEdit *m_pXLine, *m_pYLine, *m_pZLine;
418
419 Delegate* m_pDeleg = nullptr;
420 void* m_pUserData = nullptr;
421
422 void closeEvent(QCloseEvent* event) override
423 {
424 // instead of closing the window, we listen to the event and catch it
425 // to only hide the window so we can show and hide it as often as we want to
426 hide();
427 event->ignore();
428 }
429};
430
431} // namespace endor
432
434using endor::cSensorManipulator;
435
436} // namespace mixinlib
437
438} // namespace disptb
439
440} // namespace adtf
Copyright © Audi Electronics Venture GmbH.
Namespace for functionality provided by the Mixin Library.
Definition baseobject.h:26
Namespace for functionality provided by the Display Toolbox.
Main namespace.