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