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)
79 isDirectError = ownFault;
82 aronItem->setValueErrorState(isDirectError,
false);
89 auto createdAronDict = std::make_shared<aron::data::Dict>(i->getPath());
96 if (el->checkState(1) == Qt::CheckState::Unchecked)
104 for (
const auto& [key,
value] : i->getMemberTypes())
111 if (
v.isConversionSuccessful())
113 createdAronDict->addElement(key,
v.createdAron);
122 auto createdAronDict = std::make_shared<aron::data::Dict>(i->getPath());
129 if (el->checkState(1) == Qt::CheckState::Unchecked)
136 for (
int x = 0; x < el->childCount(); ++x)
138 auto it = el->child(x);
141 auto key = it->text(0).toStdString();
143 handleErrors(
v, createdAronDict->hasElement(key));
144 if (
v.createdAron &&
v.isConversionSuccessful() && !createdAronDict->hasElement(key))
146 createdAronDict->addElement(key,
v.createdAron);
155 auto createdAronList = std::make_shared<aron::data::List>(i->getPath());
162 if (el->checkState(1) == Qt::CheckState::Unchecked)
169 auto childrenTypes = i->getChildren();
171 for (
int j = 0; j < el->childCount(); ++j)
175 handleErrors(convVisitor);
179 createdAronList->addElement(convVisitor.
createdAron);
188 auto createdAronPair = std::make_shared<aron::data::List>(i->getPath());
195 if (el->checkState(1) == Qt::CheckState::Unchecked)
202 for (
int j = 0; j < 2; ++j)
205 handleErrors(convVisitor);
208 createdAronPair->addElement(convVisitor.
createdAron);
217 auto createdAronList = std::make_shared<aron::data::List>(i->getPath());
224 if (el->checkState(1) == Qt::CheckState::Unchecked)
231 for (
int x = 0; x < el->childCount(); ++x)
233 auto* it = el->child(x);
240 createdAronList->addElement(
v.createdAron);
249 ARMARX_ERROR <<
"Currently do not support supplying raw NDArrays!";
256 auto createdMatrix = std::make_shared<aron::data::NDArray>(i->getPath());
258 switch (i->getElementType())
260 case armarx::aron::type::matrix::INT8:
261 case armarx::aron::type::matrix::UINT8:
264 case armarx::aron::type::matrix::INT16:
265 case armarx::aron::type::matrix::UINT16:
268 case armarx::aron::type::matrix::UINT32:
269 case armarx::aron::type::matrix::INT32:
270 case armarx::aron::type::matrix::FLOAT32:
273 case armarx::aron::type::matrix::FLOAT64:
274 case armarx::aron::type::matrix::INT64:
280 switch (i->getElementType())
282 case armarx::aron::type::matrix::UINT8:
283 createdMatrix->setType(
"unsigned char");
285 case armarx::aron::type::matrix::UINT16:
286 createdMatrix->setType(
"unsigned short");
288 case armarx::aron::type::matrix::UINT32:
289 createdMatrix->setType(
"unsigned int");
291 case armarx::aron::type::matrix::INT8:
292 createdMatrix->setType(
"char");
294 case armarx::aron::type::matrix::INT16:
295 createdMatrix->setType(
"short");
297 case armarx::aron::type::matrix::INT32:
298 createdMatrix->setType(
"int");
300 case armarx::aron::type::matrix::FLOAT32:
301 createdMatrix->setType(
"float");
303 case armarx::aron::type::matrix::FLOAT64:
304 createdMatrix->setType(
"double");
306 case armarx::aron::type::matrix::INT64:
307 createdMatrix->setType(
"long");
311 createdMatrix->setShape({i->getRows(), i->getCols(), dataSize});
312 int totalByteSize = i->getRows() * i->getCols() * dataSize;
319 if (el->checkState(1) == Qt::CheckState::Unchecked)
327 auto* rootWidget = el->treeWidget();
329 auto* widget = rootWidget->itemWidget(el, 1);
332 handleErrors(matrixWidget->hasParseErrors());
333 if (matrixWidget->hasParseErrors())
338 std::vector<unsigned char> elems;
339 elems.reserve(totalByteSize);
341 for (
size_t col = 0; col < (size_t)i->getCols(); ++col)
343 for (
size_t row = 0; row < (size_t)i->getRows(); ++row)
346 auto parsed = matrixWidget->parseElement(row, col);
348 elems.insert(elems.end(), parsed.begin(), parsed.end());
351 createdMatrix->setData(totalByteSize, elems.data());
358 auto createdQuat = std::make_shared<aron::data::NDArray>(i->getPath());
360 int dataSize = i->getElementType() == aron::type::quaternion::ElementType::FLOAT32 ? 4 : 8;
361 createdQuat->setShape({1, 4, dataSize});
362 createdQuat->setType(i->getFullName());
368 if (el->checkState(1) == Qt::CheckState::Unchecked)
375 auto* itemWidget = el->treeWidget()->itemWidget(el, 1);
379 handleErrors(quatWidget->hasParseErrors());
380 if (quatWidget->hasParseErrors())
386 auto serialized = quatWidget->parseAllToNDArray();
387 if ((
int)serialized.size() != dataSize * 4)
390 <<
"serialized quaternions did not return byte sequence of correct length!";
392 createdQuat->setData(serialized.size(), serialized.data());
418 if (el->checkState(1) == Qt::CheckState::Unchecked)
425 auto* genericWidget = el->treeWidget()->itemWidget(el, 1);
442 auto createdAronInt = std::make_shared<aron::data::Int>(i->getPath());
449 if (el->checkState(1) == Qt::CheckState::Unchecked)
456 std::string
str = el->text(1).toStdString();
459 createdAronInt->setValue(0);
464 int val = simox::alg::to_<int>(
str);
465 createdAronInt->setValue(val);
467 catch (
const simox::error::SimoxError& err)
470 ARMARX_VERBOSE <<
"Conversion from String to Int failed. Error:\"" << err.what()
481 auto createdAronLong = std::make_shared<aron::data::Long>(i->getPath());
488 if (el->checkState(1) == Qt::CheckState::Unchecked)
495 std::string
str = el->text(1).toStdString();
499 str = el->text(3).toStdString();
503 createdAronLong->setValue(simox::alg::to_<long>(
str));
505 catch (
const simox::error::SimoxError& err)
508 ARMARX_VERBOSE <<
"Conversion from String to Long failed. Error:\"" << err.what()
519 auto createdAronFloat = std::make_shared<aron::data::Float>(i->getPath());
526 if (el->checkState(1) == Qt::CheckState::Unchecked)
533 std::string
str = el->text(1).toStdString();
536 str = el->text(3).toStdString();
540 createdAronFloat->setValue(simox::alg::to_<float>(
str));
542 catch (
const simox::error::SimoxError& err)
545 ARMARX_VERBOSE <<
"Conversion from String to Float failed. Error:\"" << err.what()
556 auto createdAronDouble = std::make_shared<aron::data::Double>(i->getPath());
563 if (el->checkState(1) == Qt::CheckState::Unchecked)
570 std::string
str = el->text(1).toStdString();
573 str = el->text(3).toStdString();
577 createdAronDouble->setValue(simox::alg::to_<double>(
str));
579 catch (
const simox::error::SimoxError& err)
582 ARMARX_VERBOSE <<
"Conversion from String to Double failed. Error:\"" << err.what()
593 auto createdAronBool = std::make_shared<aron::data::Bool>(i->getPath());
600 if (el->checkState(1) == Qt::CheckState::Unchecked)
607 std::string
str = el->text(1).toStdString();
610 str = el->text(3).toStdString();
614 createdAronBool->setValue(simox::alg::to_<bool>(
str));
616 catch (
const simox::error::SimoxError& err)
619 ARMARX_VERBOSE <<
"Conversion from String to Bool failed. Error:\"" << err.what()
630 auto createdAronString = std::make_shared<aron::data::String>(i->getPath());
637 if (el->checkState(1) == Qt::CheckState::Unchecked)
644 std::string
str = el->text(1).toStdString();
645 createdAronString->setValue(
str);
651 ARMARX_WARNING_S <<
"Received an unknown type when trying to convert a skill argument type "
652 "to an aron data object.";