QuaternionWidget.h
Go to the documentation of this file.
1#pragma once
2
3#include <cmath>
4#include <vector>
5
6#include <QLineEdit>
7#include <QObject>
8#include <QVBoxLayout>
9
10#include <SimoxUtility/algorithm/string/string_conversion.h>
11#include <SimoxUtility/error/SimoxError.h>
12
13#include <RobotAPI/interface/aron/Aron.h>
14
15#include "CustomWidget.h"
16
17namespace armarx
18{
19 // Custom Widget which represents a Quaternion - This class does not normalize the inputs
20 // It can parse its data to NDArray and also handles user edit signals itself. (And also the highlighting if errors occur)
22 {
23 Q_OBJECT
24 public:
25 QuaternionWidget(aron::type::quaternion::ElementType type, QTreeWidgetItem* currentItem);
26
27 static QuaternionWidget* DynamicCast(QWidget*);
28 static QuaternionWidget* DynamicCastAndCheck(QWidget*);
29
31 {
32 X = 0,
36 };
37 void setText(QuaternionComponents col, const std::string& str);
38 std::string getText(QuaternionComponents col);
39 bool hasParseErrors();
40 std::vector<unsigned char> parseAllToNDArray();
41
42 private:
43 std::vector<QLineEdit*> xyzw_components;
44 aron::type::quaternion::ElementType element_type;
45 bool parseErrors = false;
46
47 void highlightUnparsableEntries();
48 template <typename T>
49 std::pair<bool, T> parseQuatVals(QuaternionComponents comp);
50
51 private slots:
52 void quaternionElementChanged();
53 };
54
55 template <typename T>
56 std::pair<bool, T>
57 QuaternionWidget::parseQuatVals(QuaternionWidget::QuaternionComponents comp)
58 {
59 // size_t data_size = element_type == aron::type::quaternion::ElementType::FLOAT32 ? 4 : 8;
60 try
61 {
62 T val = simox::alg::to_<T>(xyzw_components.at((size_t)comp)->text().toStdString());
63 return {true, val};
64 }
65 catch (const simox::error::SimoxError& err)
66 {
67 return {false, NAN};
68 }
69 }
70
71
72} // namespace armarx
std::string str(const T &t)
CustomWidget(QTreeWidgetItem *overlayingItem)
static QuaternionWidget * DynamicCast(QWidget *)
QuaternionWidget(aron::type::quaternion::ElementType type, QTreeWidgetItem *currentItem)
std::string getText(QuaternionComponents col)
void setText(QuaternionComponents col, const std::string &str)
std::vector< unsigned char > parseAllToNDArray()
static QuaternionWidget * DynamicCastAndCheck(QWidget *)
This file offers overloads of toIce() and fromIce() functions for STL container types.