27 #include "../ListDictHelper.h"
28 #include "../widgets/EditMatrixWidget.h"
29 #include "../widgets/IntEnumWidget.h"
30 #include "../widgets/QuaternionWidget.h"
39 const char* locale =
"C";
40 ss.imbue(std::locale(locale));
42 ss << std::fixed << std::setprecision(precision) << number;
50 AronTreeWidgetSetterVisitor::checkTreeWidgetItemForSimilarName(
const std::string& name)
const
58 auto descr = castedThis->aronType->getDescriptor();
64 std::string n = el->text(0).toStdString();
67 ARMARX_WARNING_S <<
"Could not set a tree widget value for the element with key '"
68 << name <<
"' because it is different from the expected name '" << n
76 AronTreeWidgetSetterVisitor::adjustNumberOfChildren(AronTreeWidgetItem* parent,
79 if (((
size_t)parent->childCount()) < numChildren)
83 size_t childrenToAdd = numChildren - parent->childCount();
84 for (
size_t j = 0; j < childrenToAdd; ++j)
86 AronTreeWidgetCreatorVisitor childCreator(parent);
91 else if ((
size_t)parent->childCount() > numChildren)
93 size_t numChilds = (size_t)parent->childCount() - numChildren;
95 for (
size_t j = 0; j < numChilds; ++j)
97 parent->removeChild(parent->child(parent->childCount() - 1));
106 if (i->getPath().size() == 0 ||
107 checkTreeWidgetItemForSimilarName(i->getPath().getLastElement()))
112 adjustNumberOfChildren(aronTreeWidget, i->childrenSize());
116 for (
const auto& [key,
value] : i->getElements())
118 el->child(x)->setText(0, {key.c_str()});
126 el->setCheckState(1, Qt::CheckState::Checked);
134 if (checkTreeWidgetItemForSimilarName(i->getPath().getLastElement()))
138 adjustNumberOfChildren(aronTreeWidget, i->childrenSize());
141 for (
const auto&
value : i->getElements())
145 auto* currChild = el->child(x);
147 currChild->setText(0, listNum.c_str());
153 aronTreeWidget->setText(1, numElemsText);
155 auto currFont = aronTreeWidget->font(1);
156 currFont.setItalic(
true);
157 aronTreeWidget->setFont(1, currFont);
161 el->setCheckState(1, Qt::CheckState::Checked);
168 const std::shared_ptr<armarx::aron::type::Matrix>& matrixType,
171 auto elemType = matrixType->getElementType();
172 auto* rawData = arr->getData();
174 auto toString = [elemType, rawData](
size_t elementNr) -> std::string
178 case aron::type::matrix::ElementType::FLOAT32:
180 static_assert(
sizeof(
float) == 4);
181 float* interpreted =
reinterpret_cast<float*
>(rawData);
182 float laundered = std::launder(interpreted)[elementNr];
183 return usString<float>(laundered);
185 case aron::type::matrix::ElementType::FLOAT64:
187 static_assert(
sizeof(
double) == 8);
188 double* interpreted =
reinterpret_cast<double*
>(rawData);
189 float laundered = std::launder(interpreted)[elementNr];
190 return usString<double>(laundered);
192 case aron::type::matrix::ElementType::UINT8:
194 auto* interpreted =
reinterpret_cast<uint8_t*
>(rawData);
195 auto laudered = std::launder(interpreted)[elementNr];
196 return usString<uint8_t>(laudered);
198 case aron::type::matrix::ElementType::UINT16:
200 auto* interpreted =
reinterpret_cast<uint16_t*
>(rawData);
201 auto laudered = std::launder(interpreted)[elementNr];
202 return usString<uint16_t>(laudered);
204 case aron::type::matrix::ElementType::UINT32:
206 auto* interpreted =
reinterpret_cast<uint32_t*
>(rawData);
207 auto laudered = std::launder(interpreted)[elementNr];
208 return usString<uint32_t>(laudered);
210 case aron::type::matrix::ElementType::INT8:
212 auto* interpreted =
reinterpret_cast<int8_t*
>(rawData);
213 auto laudered = std::launder(interpreted)[elementNr];
214 return usString<int8_t>(laudered);
216 case aron::type::matrix::ElementType::INT16:
218 int16_t* interpreted =
reinterpret_cast<int16_t*
>(rawData);
219 int16_t laudered = std::launder(interpreted)[elementNr];
220 return usString<int16_t>(laudered);
222 case aron::type::matrix::ElementType::INT32:
224 int32_t* interpreted =
reinterpret_cast<int32_t*
>(rawData);
225 int32_t laudered = std::launder(interpreted)[elementNr];
226 return usString<int32_t>(laudered);
228 case aron::type::matrix::ElementType::INT64:
230 int64_t* interpreted =
reinterpret_cast<int64_t*
>(rawData);
231 int64_t laudered = std::launder(interpreted)[elementNr];
232 return usString<int64_t>(laudered);
239 for (
size_t row = 0; (int)row < matrixType->getRows(); ++row)
241 for (
size_t col = 0; (int)col < matrixType->getCols(); ++col)
243 matrixWidget->
setText(row, col,
toString(col * matrixType->getRows() + row));
250 std::shared_ptr<armarx::aron::type::Quaternion>& quatType,
253 auto elemType = quatType->getElementType();
254 auto rawData = arr->getData();
255 auto shape = arr->getShape();
257 auto toString = [elemType, rawData](
size_t elementNr) -> std::string
261 case aron::type::quaternion::ElementType::FLOAT32:
263 static_assert(
sizeof(
float) == 4);
264 float* interpreted =
reinterpret_cast<float*
>(rawData);
265 float laundered = std::launder(interpreted)[elementNr];
266 return usString<float>(laundered);
268 case aron::type::quaternion::ElementType::FLOAT64:
270 static_assert(
sizeof(
double) == 8);
271 double* interpreted =
reinterpret_cast<double*
>(rawData);
273 float laundered = std::launder(interpreted)[elementNr];
274 return usString<double>(laundered);
279 for (
size_t i = 0; i < 4; ++i)
295 auto* rootWidget = el->treeWidget();
300 if (matrixCast && matrixWidget)
304 else if (quaternionCast && quaternionWidget)
311 <<
"we do not support raw NDArrays. Ask Fabian Peller for more information.";
316 el->setCheckState(1, Qt::CheckState::Checked);
323 if (checkTreeWidgetItemForSimilarName(i->getPath().getLastElement()))
327 auto newText = QString::fromStdString(usString<int>(i->getValue()));
331 enumWidget->setText(newText);
336 el->setText(1, newText);
341 el->setCheckState(1, Qt::CheckState::Checked);
349 if (checkTreeWidgetItemForSimilarName(i->getPath().getLastElement()))
352 el->setText(1, QString::fromStdString(usString<long>(i->getValue())));
356 el->setCheckState(1, Qt::CheckState::Checked);
364 if (checkTreeWidgetItemForSimilarName(i->getPath().getLastElement()))
367 el->setText(1, QString::fromStdString(usString<float>(i->getValue())));
371 el->setCheckState(1, Qt::CheckState::Checked);
379 if (checkTreeWidgetItemForSimilarName(i->getPath().getLastElement()))
382 el->setText(1, QString::fromStdString(usString<double>(i->getValue())));
386 el->setCheckState(1, Qt::CheckState::Checked);
394 if (checkTreeWidgetItemForSimilarName(i->getPath().getLastElement()))
397 el->setText(1, QString::fromStdString(usString<bool>(i->getValue())));
401 el->setCheckState(1, Qt::CheckState::Checked);
409 if (checkTreeWidgetItemForSimilarName(i->getPath().getLastElement()))
412 el->setText(1, QString::fromStdString(i->getValue()));
416 el->setCheckState(1, Qt::CheckState::Checked);
424 ARMARX_WARNING_S <<
"Received an unknown type when trying to set a skill argument type "
425 "from an aron data object.";