29 #include <SimoxUtility/algorithm/string.h>
36 #include <QTreeWidgetItem>
38 #include "../widgets/EditMatrixWidget.h"
39 #include "../widgets/IntEnumWidget.h"
40 #include "../widgets/QuaternionWidget.h"
47 return !isDirectError && !hasTransitiveError;
53 return hasTransitiveError;
67 isDirectError |= ownFault;
68 hasTransitiveError |= childV.isDirectError || childV.hasTransitiveError;
72 aronItem->setValueErrorState(isDirectError, hasTransitiveError);
76 AronTreeWidgetConverterVisitor::handleErrors(
bool ownFault)
80 isDirectError = ownFault;
83 aronItem->setValueErrorState(isDirectError,
false);
91 auto createdAronDict = std::make_shared<aron::data::Dict>(i->getPath());
98 if (el->checkState(2) == Qt::CheckState::Unchecked)
106 for (
const auto& [key,
value] : i->getMemberTypes())
113 if (
v.isConversionSuccessful())
115 createdAronDict->addElement(key,
v.createdAron);
125 auto createdAronDict = std::make_shared<aron::data::Dict>(i->getPath());
132 if (el->checkState(2) == Qt::CheckState::Unchecked)
139 for (
int x = 0; x < el->childCount(); ++x)
141 auto it = el->child(x);
144 auto key = it->text(0).toStdString();
146 handleErrors(
v, createdAronDict->hasElement(key));
147 if (
v.createdAron &&
v.isConversionSuccessful() && !createdAronDict->hasElement(key))
149 createdAronDict->addElement(key,
v.createdAron);
159 auto createdAronList = std::make_shared<aron::data::List>(i->getPath());
166 if (el->checkState(2) == Qt::CheckState::Unchecked)
173 auto childrenTypes = i->getChildren();
175 for (
int j = 0; j < el->childCount(); ++j)
179 handleErrors(convVisitor);
183 createdAronList->addElement(convVisitor.
createdAron);
193 auto createdAronPair = std::make_shared<aron::data::List>(i->getPath());
200 if (el->checkState(2) == Qt::CheckState::Unchecked)
207 for (
int j = 0; j < 2; ++j)
210 handleErrors(convVisitor);
213 createdAronPair->addElement(convVisitor.
createdAron);
223 auto createdAronList = std::make_shared<aron::data::List>(i->getPath());
230 if (el->checkState(2) == Qt::CheckState::Unchecked)
237 for (
int x = 0; x < el->childCount(); ++x)
239 auto* it = el->child(x);
246 createdAronList->addElement(
v.createdAron);
255 ARMARX_ERROR <<
"Currently do not support supplying raw NDArrays!";
263 auto createdMatrix = std::make_shared<aron::data::NDArray>(i->getPath());
265 switch (i->getElementType())
267 case armarx::aron::type::matrix::UINT8:
268 case armarx::aron::type::matrix::INT8:
271 case armarx::aron::type::matrix::UINT16:
272 case armarx::aron::type::matrix::INT16:
275 case armarx::aron::type::matrix::UINT32:
276 case armarx::aron::type::matrix::INT32:
277 case armarx::aron::type::matrix::FLOAT32:
280 case armarx::aron::type::matrix::FLOAT64:
281 case armarx::aron::type::matrix::INT64:
288 switch (i->getElementType())
290 case armarx::aron::type::matrix::UINT8:
291 createdMatrix->setType(
"unsigned char");
293 case armarx::aron::type::matrix::UINT16:
294 createdMatrix->setType(
"unsigned short");
296 case armarx::aron::type::matrix::UINT32:
297 createdMatrix->setType(
"unsigned int");
299 case armarx::aron::type::matrix::INT8:
300 createdMatrix->setType(
"char");
302 case armarx::aron::type::matrix::INT16:
303 createdMatrix->setType(
"short");
305 case armarx::aron::type::matrix::INT32:
306 createdMatrix->setType(
"int");
308 case armarx::aron::type::matrix::FLOAT32:
309 createdMatrix->setType(
"float");
311 case armarx::aron::type::matrix::FLOAT64:
312 createdMatrix->setType(
"double");
314 case armarx::aron::type::matrix::INT64:
315 createdMatrix->setType(
"long");
320 createdMatrix->setShape({i->getRows(), i->getCols(), dataSize});
321 int totalByteSize = i->getRows() * i->getCols() * dataSize;
328 if (el->checkState(2) == Qt::CheckState::Unchecked)
336 auto* rootWidget = el->treeWidget();
338 auto* widget = rootWidget->itemWidget(el, 1);
343 handleErrors(matrixWidget->hasParseErrors());
344 if (matrixWidget->hasParseErrors())
351 std::vector<unsigned char> elems;
352 elems.reserve(totalByteSize);
354 for (
size_t col = 0; col < (size_t)i->getCols(); ++col)
356 for (
size_t row = 0; row < (size_t)i->getRows(); ++row)
359 auto parsed = matrixWidget->parseElement(row, col);
361 elems.insert(elems.end(), parsed.begin(), parsed.end());
364 createdMatrix->setData(totalByteSize, elems.data());
372 auto createdQuat = std::make_shared<aron::data::NDArray>(i->getPath());
374 int dataSize = i->getElementType() == aron::type::quaternion::ElementType::FLOAT32 ? 4 : 8;
375 createdQuat->setShape({1, 4, dataSize});
376 createdQuat->setType(i->getFullName());
382 if (el->checkState(2) == Qt::CheckState::Unchecked)
389 auto* itemWidget = el->treeWidget()->itemWidget(el, 1);
393 handleErrors(quatWidget->hasParseErrors());
394 if (quatWidget->hasParseErrors())
400 auto serialized = quatWidget->parseAllToNDArray();
401 if ((
int)serialized.size() != dataSize * 4)
404 <<
"serialized quaternions did not return byte sequence of correct length!";
406 createdQuat->setData(serialized.size(), serialized.data());
433 if (el->checkState(2) == Qt::CheckState::Unchecked)
440 auto* genericWidget = el->treeWidget()->itemWidget(el, 1);
458 auto createdAronInt = std::make_shared<aron::data::Int>(i->getPath());
465 if (el->checkState(2) == Qt::CheckState::Unchecked)
472 std::string
str = el->text(1).toStdString();
475 createdAronInt->setValue(0);
480 int val = simox::alg::to_<int>(
str);
481 createdAronInt->setValue(val);
483 catch (
const simox::error::SimoxError& err)
486 ARMARX_VERBOSE <<
"Conversion from String to Int failed. Error:\"" << err.what()
498 auto createdAronLong = std::make_shared<aron::data::Long>(i->getPath());
505 if (el->checkState(2) == Qt::CheckState::Unchecked)
512 std::string
str = el->text(1).toStdString();
516 str = el->text(3).toStdString();
520 createdAronLong->setValue(simox::alg::to_<long>(
str));
522 catch (
const simox::error::SimoxError& err)
525 ARMARX_VERBOSE <<
"Conversion from String to Long failed. Error:\"" << err.what()
537 auto createdAronFloat = std::make_shared<aron::data::Float>(i->getPath());
544 if (el->checkState(2) == Qt::CheckState::Unchecked)
551 std::string
str = el->text(1).toStdString();
554 str = el->text(3).toStdString();
558 createdAronFloat->setValue(simox::alg::to_<float>(
str));
560 catch (
const simox::error::SimoxError& err)
563 ARMARX_VERBOSE <<
"Conversion from String to Float failed. Error:\"" << err.what()
575 auto createdAronDouble = std::make_shared<aron::data::Double>(i->getPath());
582 if (el->checkState(2) == Qt::CheckState::Unchecked)
589 std::string
str = el->text(1).toStdString();
592 str = el->text(3).toStdString();
596 createdAronDouble->setValue(simox::alg::to_<double>(
str));
598 catch (
const simox::error::SimoxError& err)
601 ARMARX_VERBOSE <<
"Conversion from String to Double failed. Error:\"" << err.what()
613 auto createdAronBool = std::make_shared<aron::data::Bool>(i->getPath());
620 if (el->checkState(2) == Qt::CheckState::Unchecked)
627 std::string
str = el->text(1).toStdString();
630 str = el->text(3).toStdString();
634 createdAronBool->setValue(simox::alg::to_<bool>(
str));
636 catch (
const simox::error::SimoxError& err)
639 ARMARX_VERBOSE <<
"Conversion from String to Bool failed. Error:\"" << err.what()
651 auto createdAronString = std::make_shared<aron::data::String>(i->getPath());
663 if (el->checkState(2) == Qt::CheckState::Unchecked)
670 std::string
str = el->text(1).toStdString();
671 createdAronString->setValue(
str);
677 ARMARX_WARNING_S <<
"Received an unknown type when trying to convert a skill argument type "
678 "to an aron data object.";