TreeTypedDataVisitor.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <sstream>
4 #include <stack>
5 
6 #include <QTreeWidget>
7 #include <QLabel>
8 
11 
14 
16 
17 #include <SimoxUtility/algorithm/string/string_tools.h>
18 
19 
21 {
22 
25  public TreeDataVisitorBase
26  {
27  public:
28 
30 
31 
33  {
36  const std::string key = data->getPath().getLastElement();
37  _visitEnter(key, sanitizeTypeName(type->getFullName()), data->childrenSize());
38  }
40  {
41  _visitExit();
42  }
43 
45  {
48  const std::string key = data->getPath().getLastElement();
49  _visitEnter(key, sanitizeTypeName(type->getFullName()), data->childrenSize());
50  }
52  {
53  _visitExit();
54  }
55 
57  {
60  const std::string key = data->getPath().getLastElement();
61  _visitEnter(key, sanitizeTypeName(type->getFullName()), data->childrenSize());
62  }
64  {
65  _visitExit();
66  }
67 
69  {
72  const std::string key = data->getPath().getLastElement();
73  _visitEnter(key, sanitizeTypeName(type->getFullName()), data->childrenSize());
74  }
76  {
77  _visitExit();
78  }
79  // What about Pair??
80 
81 
82  void visitBool(const aron::data::VariantPtr& data, const aron::type::VariantPtr& type) override
83  {
86  const std::string key = data->getPath().getLastElement();
87 
90  this->addValueRow(key, d, t);
91  }
93  {
96  const std::string key = data->getPath().getLastElement();
97 
100  this->addValueRow(key, d, t);
101  }
103  {
105  ARMARX_CHECK_NOT_NULL(type);
106  const std::string key = data->getPath().getLastElement();
107 
110  this->addValueRow(key, d, t);
111  }
112  void visitInt(const aron::data::VariantPtr& data, const aron::type::VariantPtr& type) override
113  {
115  ARMARX_CHECK_NOT_NULL(type);
116  const std::string key = data->getPath().getLastElement();
117 
119  auto t = *aron::type::Int::DynamicCastAndCheck(type);
120  this->addValueRow(key, d, t);
121  }
122  void visitLong(const aron::data::VariantPtr& data, const aron::type::VariantPtr& type) override
123  {
125  ARMARX_CHECK_NOT_NULL(type);
126  const std::string key = data->getPath().getLastElement();
127 
130  this->addValueRow(key, d, t);
131  }
133  {
135  ARMARX_CHECK_NOT_NULL(type);
136  const std::string key = data->getPath().getLastElement();
137 
140  this->addValueRow(key, d, t);
141  }
142  /*void visitDateTime(const aron::data::VariantPtr& data, const aron::type::VariantPtr& type) override
143  {
144  ARMARX_CHECK_NOT_NULL(data);
145  ARMARX_CHECK_NOT_NULL(type);
146  const std::string key = data->getPath().getLastElement();
147 
148  auto d = *aron::data::Long::DynamicCastAndCheck(data);
149  auto t = *aron::type::DateTime::DynamicCastAndCheck(type);
150  this->addValueRow(key, d, t);
151  }*/
152 
153 
155  {
157  ARMARX_CHECK_NOT_NULL(type);
158  const std::string key = data->getPath().getLastElement();
159 
162  this->addValueRow(key, d, t);
163  }
165  {
167  ARMARX_CHECK_NOT_NULL(type);
168  const std::string key = data->getPath().getLastElement();
169 
172  this->addValueRow(key, d, t);
173  }
175  {
177  ARMARX_CHECK_NOT_NULL(type);
178  const std::string key = data->getPath().getLastElement();
179 
182  this->addValueRow(key, d, t);
183  }
185  {
187  ARMARX_CHECK_NOT_NULL(type);
188  const std::string key = data->getPath().getLastElement();
189 
192  this->addValueRow(key, d, t);
193  }
194  // What aboud NDArray
195 
196 
197  protected:
198 
199  template <class DataNavigatorT, class TypeNavigatorT>
200  bool addValueRow(const std::string& key, const DataNavigatorT& data, const TypeNavigatorT& type)
201  {
202  if (items.size() > 0)
203  {
204  QTreeWidgetItem* item = makeItem(key, data, type);
205  items.top()->addChild(item);
206 
207  item->setData(columnKey, Qt::UserRole, serializePath(data.getPath()));
208  item->setData(columnType, Qt::UserRole, int(type.getDescriptor()));
209 
210  if (false) // remove?
211  {
212  QFont font;
213  font.setFamily("Consolas");
214  font.setStyleHint(QFont::Monospace);
215  font.setFixedPitch(true);
216  font.setPointSize(10);
217  item->setFont(columnValue, font);
218  }
219  }
220  return true;
221  }
222 
223  template <class DataNavigatorT, class TypeNavigatorT>
224  QTreeWidgetItem* makeItem(const std::string& key, const DataNavigatorT& data, const TypeNavigatorT& type) const
225  {
226  std::stringstream ss;
227  try
228  {
229  this->streamValueText(data, type, ss);
230  }
231  catch (const aron::error::AronException& e)
232  {
233  ss << "x ";
235  std::stringstream es;
236  es << e.what();
237  ss << simox::alg::replace_all(es.str(), "\n", " | ");
238  }
239  return new QTreeWidgetItem(this->makeValueRowStrings(key, ss.str(), sanitizeTypeName(type.getFullName())));
240  }
241 
242 
243  template <class DataNavigatorT, class TypeNavigatorT>
244  void streamValueText(const DataNavigatorT& data, const TypeNavigatorT& type, std::stringstream& ss) const
245  {
246  // Fallback to type-agnostic (but data-aware).
247  (void) type;
249  }
250 
252  //void streamValueText(const aron::data::Long& data, const aron::type::DateTime& type, std::stringstream& ss) const;
253  void streamValueText(const aron::data::NDArray& data, const aron::type::Matrix& type, std::stringstream& ss) const;
254 
255  void streamPoseText(const aron::data::NDArray& data, const aron::type::Matrix& type, std::stringstream& ss) const;
256  void streamPositionText(const aron::data::NDArray& data, const aron::type::Matrix& type, std::stringstream& ss) const;
257  void streamOrientationText(const aron::data::NDArray& data, const aron::type::Matrix& type, std::stringstream& ss) const;
258 
259 
260  std::string coeffSep = " ";
261  };
262 
263 }
264 
sanitize_typename.h
armarx::armem::gui::instance::TreeTypedDataVisitor::addValueRow
bool addValueRow(const std::string &key, const DataNavigatorT &data, const TypeNavigatorT &type)
Definition: TreeTypedDataVisitor.h:200
armarx::armem::gui::instance::TreeTypedDataVisitor::streamOrientationText
void streamOrientationText(const aron::data::NDArray &data, const aron::type::Matrix &type, std::stringstream &ss) const
Definition: TreeTypedDataVisitor.cpp:81
armarx::armem::gui::instance::TreeDataVisitorBase
Definition: TreeDataVisitorBase.h:15
armarx::armem::gui::instance::TreeTypedDataVisitor::visitDouble
void visitDouble(const aron::data::VariantPtr &data, const aron::type::VariantPtr &type) override
Definition: TreeTypedDataVisitor.h:92
armarx::aron::error::AronException
A base class for aron exceptions.
Definition: Exception.h:42
armarx::armem::gui::instance::TreeDataVisitorBase::items
std::stack< QTreeWidgetItem * > items
Definition: TreeDataVisitorBase.h:73
armarx::aron::type::VariantPtr
std::shared_ptr< Variant > VariantPtr
Definition: forward_declarations.h:11
armarx::armem::gui::instance::TreeTypedDataVisitor::visitListOnExit
void visitListOnExit(const aron::data::VariantPtr &, const aron::type::VariantPtr &) override
Definition: TreeTypedDataVisitor.h:63
armarx::armem::gui::instance::sanitizeTypeName
std::string sanitizeTypeName(const std::string &typeName)
Definition: sanitize_typename.cpp:29
armarx::armem::gui::instance::TreeTypedDataVisitor::visitFloat
void visitFloat(const aron::data::VariantPtr &data, const aron::type::VariantPtr &type) override
Definition: TreeTypedDataVisitor.h:102
armarx::aron::data::NDArray
Definition: NDArray.h:48
armarx::armem::gui::instance::TreeTypedDataVisitor::visitListOnEnter
void visitListOnEnter(const aron::data::VariantPtr &data, const aron::type::VariantPtr &type) override
Definition: TreeTypedDataVisitor.h:56
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::armem::gui::instance::TreeTypedDataVisitor::visitBool
void visitBool(const aron::data::VariantPtr &data, const aron::type::VariantPtr &type) override
Definition: TreeTypedDataVisitor.h:82
armarx::armem::gui::instance::TreeTypedDataVisitor::visitString
void visitString(const aron::data::VariantPtr &data, const aron::type::VariantPtr &type) override
Definition: TreeTypedDataVisitor.h:132
armarx::armem::gui::instance::TreeTypedDataVisitor::visitPointCloud
void visitPointCloud(const aron::data::VariantPtr &data, const aron::type::VariantPtr &type) override
Definition: TreeTypedDataVisitor.h:174
armarx::armem::gui::instance::TreeTypedDataVisitor::visitInt
void visitInt(const aron::data::VariantPtr &data, const aron::type::VariantPtr &type) override
Definition: TreeTypedDataVisitor.h:112
armarx::armem::gui::instance::TreeTypedDataVisitor::visitTupleOnExit
void visitTupleOnExit(const aron::data::VariantPtr &, const aron::type::VariantPtr &) override
Definition: TreeTypedDataVisitor.h:75
armarx::aron::data::detail::SpecializedVariantBase< data::dto::AronBool, Bool >::DynamicCastAndCheck
static PointerType DynamicCastAndCheck(const VariantPtr &n)
Definition: SpecializedVariant.h:135
armarx::armem::gui::instance::TreeTypedDataVisitor::visitImage
void visitImage(const aron::data::VariantPtr &data, const aron::type::VariantPtr &type) override
Definition: TreeTypedDataVisitor.h:184
armarx::armem::gui::instance::TreeDataVisitorBase::streamValueText
void streamValueText(Navigator &n, std::stringstream &ss) const
Definition: TreeDataVisitorBase.h:61
armarx::armem::gui::instance::TreeDataVisitorBase::TreeDataVisitorBase
TreeDataVisitorBase()
Definition: TreeDataVisitorBase.cpp:10
armarx::armem::gui::instance::TreeTypedDataVisitor::streamPoseText
void streamPoseText(const aron::data::NDArray &data, const aron::type::Matrix &type, std::stringstream &ss) const
Definition: TreeTypedDataVisitor.cpp:56
armarx::aron::data::VariantPtr
std::shared_ptr< Variant > VariantPtr
Definition: forward_declarations.h:11
armarx::armem::gui::instance::TreeTypedDataVisitor::makeItem
QTreeWidgetItem * makeItem(const std::string &key, const DataNavigatorT &data, const TypeNavigatorT &type) const
Definition: TreeTypedDataVisitor.h:224
armarx::armem::gui::instance::TreeDataVisitorBase::_visitExit
bool _visitExit()
Definition: TreeDataVisitorBase.cpp:49
armarx::armem::gui::instance::TreeTypedDataVisitor::visitObjectOnEnter
void visitObjectOnEnter(const aron::data::VariantPtr &data, const aron::type::VariantPtr &type) override
Definition: TreeTypedDataVisitor.h:44
armarx::armem::gui::instance
Definition: AronDataView.cpp:2
armarx::armem::gui::instance::TreeTypedDataVisitor::visitQuaternion
void visitQuaternion(const aron::data::VariantPtr &data, const aron::type::VariantPtr &type) override
Definition: TreeTypedDataVisitor.h:164
armarx::armem::gui::instance::TreeTypedDataVisitor::visitObjectOnExit
void visitObjectOnExit(const aron::data::VariantPtr &, const aron::type::VariantPtr &) override
Definition: TreeTypedDataVisitor.h:51
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::armem::gui::instance::TreeTypedDataVisitor::streamPositionText
void streamPositionText(const aron::data::NDArray &data, const aron::type::Matrix &type, std::stringstream &ss) const
Definition: TreeTypedDataVisitor.cpp:69
armarx::armem::gui::instance::TreeTypedDataVisitor::visitDictOnExit
void visitDictOnExit(const aron::data::VariantPtr &, const aron::type::VariantPtr &) override
Definition: TreeTypedDataVisitor.h:39
armarx::armem::gui::instance::TreeTypedDataVisitor
Definition: TreeTypedDataVisitor.h:23
armarx::armem::gui::instance::TreeDataVisitorBase::_visitEnter
bool _visitEnter(const std::string &key, const std::string &type, size_t numChildren)
Definition: TreeDataVisitorBase.cpp:29
All.h
armarx::armem::gui::instance::TreeDataVisitorBase::makeValueRowStrings
QStringList makeValueRowStrings(const std::string &key, const std::string &value, const std::string &typeName) const
Definition: TreeDataVisitorBase.h:43
armarx::armem::gui::instance::TreeTypedDataVisitor::visitDictOnEnter
void visitDictOnEnter(const aron::data::VariantPtr &data, const aron::type::VariantPtr &type) override
Definition: TreeTypedDataVisitor.h:32
armarx::armem::gui::instance::serializePath
QStringList serializePath(const aron::Path &path)
Definition: serialize_path.cpp:13
VariantVisitor.h
armarx::armem::gui::instance::TreeDataVisitorBase::columnValue
int columnValue
Definition: TreeDataVisitorBase.h:76
armarx::aron::type::detail::SpecializedVariantBase< type::dto::AronBool, Bool >::DynamicCastAndCheck
static std::shared_ptr< Bool > DynamicCastAndCheck(const VariantPtr &n)
Definition: SpecializedVariant.h:124
armarx::aron::data::RecursiveConstTypedVariantVisitor
Definition: VariantVisitor.h:192
armarx::armem::gui::instance::TreeTypedDataVisitor::visitMatrix
void visitMatrix(const aron::data::VariantPtr &data, const aron::type::VariantPtr &type) override
Definition: TreeTypedDataVisitor.h:154
armarx::armem::gui::instance::TreeTypedDataVisitor::visitLong
void visitLong(const aron::data::VariantPtr &data, const aron::type::VariantPtr &type) override
Definition: TreeTypedDataVisitor.h:122
armarx::armem::gui::instance::TreeTypedDataVisitor::streamValueText
void streamValueText(const DataNavigatorT &data, const TypeNavigatorT &type, std::stringstream &ss) const
Definition: TreeTypedDataVisitor.h:244
TreeDataVisitorBase.h
armarx::armem::gui::instance::TreeDataVisitorBase::columnKey
int columnKey
Definition: TreeDataVisitorBase.h:75
armarx::armem::gui::instance::TreeTypedDataVisitor::coeffSep
std::string coeffSep
Definition: TreeTypedDataVisitor.h:260
armarx::armem::gui::instance::TreeDataVisitorBase::columnType
int columnType
Definition: TreeDataVisitorBase.h:77
armarx::armem::gui::instance::TreeTypedDataVisitor::visitTupleOnEnter
void visitTupleOnEnter(const aron::data::VariantPtr &data, const aron::type::VariantPtr &type) override
Definition: TreeTypedDataVisitor.h:68
serialize_path.h
armarx::aron::type::Matrix
The Matrix class.
Definition: Matrix.h:39