diff --git a/source/RobotAPI/libraries/skills_gui/aron_tree_widget/AronTreeWidgetController.cpp b/source/RobotAPI/libraries/skills_gui/aron_tree_widget/AronTreeWidgetController.cpp index 79d606639c320ffeba73918967d9a832de446e68..8c24f906fef8edea5f33db3b4a890431f5bc7bb4 100644 --- a/source/RobotAPI/libraries/skills_gui/aron_tree_widget/AronTreeWidgetController.cpp +++ b/source/RobotAPI/libraries/skills_gui/aron_tree_widget/AronTreeWidgetController.cpp @@ -136,6 +136,7 @@ namespace armarx::skills::gui void AronTreeWidgetController::onTreeWidgetItemChanged(QTreeWidgetItem* item, int column) { + tree->blockSignals(true); auto* aronElem = AronTreeWidgetItem::DynamicCast(item); @@ -143,13 +144,14 @@ namespace armarx::skills::gui { aronElem->onUserChange(column); } + // start conversion for entire tree -- this also sets the highlighting if (parent->childCount() == 1) { auto* aronTreeRoot = AronTreeWidgetItem::DynamicCast(parent->child(0)); - aronTreeRoot->resetError(); if (aronTreeRoot) { + aronTreeRoot->resetError(); AronTreeWidgetConverterVisitor v(parent, 0); aron::type::visit(v, type); aronTreeRoot->setValueErrorState(v.hasDirectError(), v.onlyChildFailedConversion()); @@ -158,6 +160,7 @@ namespace armarx::skills::gui // else perhaps the GUI was stopped or died. tree->blockSignals(false); + } } // namespace armarx::skills::gui diff --git a/source/RobotAPI/libraries/skills_gui/aron_tree_widget/AronTreeWidgetItem.cpp b/source/RobotAPI/libraries/skills_gui/aron_tree_widget/AronTreeWidgetItem.cpp index d76cee191fda8cb927548a795b53291875ae14e6..5f24c40c959e8008457c096b4d872e8407041ab8 100644 --- a/source/RobotAPI/libraries/skills_gui/aron_tree_widget/AronTreeWidgetItem.cpp +++ b/source/RobotAPI/libraries/skills_gui/aron_tree_widget/AronTreeWidgetItem.cpp @@ -149,6 +149,7 @@ namespace armarx::skills::gui void AronTreeWidgetItem::onUserChange(int changedColumn) { + QTreeWidgetItem* qParent = QTreeWidgetItem::parent(); ARMARX_CHECK(qParent); AronTreeWidgetItem* aronParent = DynamicCast(qParent); @@ -172,6 +173,7 @@ namespace armarx::skills::gui preventIllegalKeyChange(); } } + } void diff --git a/source/RobotAPI/libraries/skills_gui/aron_tree_widget/visitors/AronTreeWidgetConverter.cpp b/source/RobotAPI/libraries/skills_gui/aron_tree_widget/visitors/AronTreeWidgetConverter.cpp index 23be73d02da766a0b361f53cb53486fd91d65684..164e4498f0adcc2ca99bfdacbfcb36cf441a8879 100644 --- a/source/RobotAPI/libraries/skills_gui/aron_tree_widget/visitors/AronTreeWidgetConverter.cpp +++ b/source/RobotAPI/libraries/skills_gui/aron_tree_widget/visitors/AronTreeWidgetConverter.cpp @@ -75,16 +75,19 @@ namespace armarx::skills::gui void AronTreeWidgetConverterVisitor::handleErrors(bool ownFault) { + ARMARX_TRACE; isDirectError = ownFault; auto* aronItem = AronTreeWidgetItem::DynamicCast(parentItem->child(index)); ARMARX_CHECK(aronItem); aronItem->setValueErrorState(isDirectError, false); + } void AronTreeWidgetConverterVisitor::visitAronVariant(const aron::type::ObjectPtr& i) { + ARMARX_TRACE; auto createdAronDict = std::make_shared<aron::data::Dict>(i->getPath()); createdAron = createdAronDict; @@ -113,11 +116,13 @@ namespace armarx::skills::gui createdAronDict->addElement(key, v.createdAron); } } + } void AronTreeWidgetConverterVisitor::visitAronVariant(const aron::type::DictPtr& i) { + ARMARX_TRACE; auto createdAronDict = std::make_shared<aron::data::Dict>(i->getPath()); createdAron = createdAronDict; @@ -146,11 +151,13 @@ namespace armarx::skills::gui createdAronDict->addElement(key, v.createdAron); } } + } void AronTreeWidgetConverterVisitor::visitAronVariant(const aron::type::ListPtr& i) { + ARMARX_TRACE; auto createdAronList = std::make_shared<aron::data::List>(i->getPath()); createdAron = createdAronList; @@ -179,11 +186,13 @@ namespace armarx::skills::gui createdAronList->addElement(convVisitor.createdAron); } } + } void AronTreeWidgetConverterVisitor::visitAronVariant(const aron::type::PairPtr& i) { + ARMARX_TRACE; auto createdAronPair = std::make_shared<aron::data::List>(i->getPath()); createdAron = createdAronPair; @@ -208,11 +217,13 @@ namespace armarx::skills::gui createdAronPair->addElement(convVisitor.createdAron); } } + } void AronTreeWidgetConverterVisitor::visitAronVariant(const aron::type::TuplePtr& i) { + ARMARX_TRACE; auto createdAronList = std::make_shared<aron::data::List>(i->getPath()); createdAron = createdAronList; @@ -240,6 +251,7 @@ namespace armarx::skills::gui createdAronList->addElement(v.createdAron); } } + } void @@ -252,6 +264,7 @@ namespace armarx::skills::gui void AronTreeWidgetConverterVisitor::visitAronVariant(const aron::type::MatrixPtr& i) { + ARMARX_TRACE; auto createdMatrix = std::make_shared<aron::data::NDArray>(i->getPath()); int dataSize = 0; @@ -276,6 +289,7 @@ namespace armarx::skills::gui break; }; + // UGLY HACK: FIX ME!!! switch (i->getElementType()) { @@ -308,6 +322,7 @@ namespace armarx::skills::gui break; }; + createdMatrix->setShape({i->getRows(), i->getCols(), dataSize}); int totalByteSize = i->getRows() * i->getCols() * dataSize; createdAron = createdMatrix; @@ -323,17 +338,21 @@ namespace armarx::skills::gui } } - + auto* rootWidget = el->treeWidget(); ARMARX_CHECK(rootWidget); auto* widget = rootWidget->itemWidget(el, 1); + ARMARX_CHECK(rootWidget); auto* matrixWidget = EditMatrixWidget::DynamicCastAndCheck(widget); + ARMARX_CHECK(matrixWidget); handleErrors(matrixWidget->hasParseErrors()); if (matrixWidget->hasParseErrors()) { return; } + + // write to aron data std::vector<unsigned char> elems; elems.reserve(totalByteSize); @@ -349,11 +368,13 @@ namespace armarx::skills::gui } } createdMatrix->setData(totalByteSize, elems.data()); + } void AronTreeWidgetConverterVisitor::visitAronVariant(const aron::type::QuaternionPtr& i) { + ARMARX_TRACE; auto createdQuat = std::make_shared<aron::data::NDArray>(i->getPath()); createdAron = createdQuat; @@ -390,6 +411,7 @@ namespace armarx::skills::gui << "serialized quaternions did not return byte sequence of correct length!"; } createdQuat->setData(serialized.size(), serialized.data()); + } void @@ -409,6 +431,7 @@ namespace armarx::skills::gui void AronTreeWidgetConverterVisitor::visitAronVariant(const aron::type::IntEnumPtr& i) { + ARMARX_TRACE; QTreeWidgetItem* el = parentItem->child(index); @@ -433,11 +456,13 @@ namespace armarx::skills::gui std::tie(success, createdAron) = intEnumWidget->parseToAron(); handleErrors(!success); + } void AronTreeWidgetConverterVisitor::visitAronVariant(const aron::type::IntPtr& i) { + ARMARX_TRACE; auto createdAronInt = std::make_shared<aron::data::Int>(i->getPath()); createdAron = createdAronInt; @@ -472,11 +497,13 @@ namespace armarx::skills::gui return; } handleErrors(false); + } void AronTreeWidgetConverterVisitor::visitAronVariant(const aron::type::LongPtr& i) { + ARMARX_TRACE; auto createdAronLong = std::make_shared<aron::data::Long>(i->getPath()); createdAron = createdAronLong; @@ -510,11 +537,13 @@ namespace armarx::skills::gui return; } handleErrors(false); + } void AronTreeWidgetConverterVisitor::visitAronVariant(const aron::type::FloatPtr& i) { + ARMARX_TRACE; auto createdAronFloat = std::make_shared<aron::data::Float>(i->getPath()); createdAron = createdAronFloat; @@ -547,11 +576,13 @@ namespace armarx::skills::gui return; } handleErrors(false); + } void AronTreeWidgetConverterVisitor::visitAronVariant(const aron::type::DoublePtr& i) { + ARMARX_TRACE; auto createdAronDouble = std::make_shared<aron::data::Double>(i->getPath()); createdAron = createdAronDouble; @@ -584,11 +615,13 @@ namespace armarx::skills::gui return; } handleErrors(false); + } void AronTreeWidgetConverterVisitor::visitAronVariant(const aron::type::BoolPtr& i) { + ARMARX_TRACE; auto createdAronBool = std::make_shared<aron::data::Bool>(i->getPath()); createdAron = createdAronBool; @@ -621,16 +654,23 @@ namespace armarx::skills::gui return; } handleErrors(false); + } void AronTreeWidgetConverterVisitor::visitAronVariant(const aron::type::StringPtr& i) { + ARMARX_TRACE; auto createdAronString = std::make_shared<aron::data::String>(i->getPath()); createdAron = createdAronString; QTreeWidgetItem* el = parentItem->child(index); + if (el == nullptr) + { + return; + } + if (i->getMaybe() != armarx::aron::type::Maybe::NONE) { // its a maybetype. We have to check the state @@ -643,6 +683,7 @@ namespace armarx::skills::gui std::string str = el->text(1).toStdString(); createdAronString->setValue(str); + } void diff --git a/source/RobotAPI/libraries/skills_gui/aron_tree_widget/visitors/AronTreeWidgetSetter.cpp b/source/RobotAPI/libraries/skills_gui/aron_tree_widget/visitors/AronTreeWidgetSetter.cpp index 77887a000c8c5b7dddf955ba8eadeb1ec39b43ec..a9f7e4db55e3e90abcd02bf29e4d4e8c3527b4f6 100644 --- a/source/RobotAPI/libraries/skills_gui/aron_tree_widget/visitors/AronTreeWidgetSetter.cpp +++ b/source/RobotAPI/libraries/skills_gui/aron_tree_widget/visitors/AronTreeWidgetSetter.cpp @@ -35,11 +35,12 @@ template <typename T> std::string usString(T number, size_t precision = 3) { + std::stringstream ss; const char* locale = "C"; ss.imbue(std::locale(locale)); - ss << std::fixed << std::setprecision(precision) << number; + return ss.str(); } @@ -102,6 +103,7 @@ namespace armarx::skills::gui void AronTreeWidgetSetterVisitor::visitAronVariant(const aron::data::DictPtr& i) { + // either it is the root or it has a name if (i->getPath().size() == 0 || checkTreeWidgetItemForSimilarName(i->getPath().getLastElement())) @@ -126,11 +128,13 @@ namespace armarx::skills::gui el->setCheckState(2, Qt::CheckState::Checked); } } + } void AronTreeWidgetSetterVisitor::visitAronVariant(const aron::data::ListPtr& i) { + if (checkTreeWidgetItemForSimilarName(i->getPath().getLastElement())) { AronTreeWidgetItem* el = AronTreeWidgetItem::DynamicCast(parentItem->child(index)); @@ -161,6 +165,7 @@ namespace armarx::skills::gui el->setCheckState(2, Qt::CheckState::Checked); } } + } void @@ -168,6 +173,7 @@ namespace armarx::skills::gui const std::shared_ptr<armarx::aron::type::Matrix>& matrixType, const aron::data::NDArrayPtr& arr) { + auto elemType = matrixType->getElementType(); auto* rawData = arr->getData(); // string can convert any item @@ -250,6 +256,7 @@ namespace armarx::skills::gui std::shared_ptr<armarx::aron::type::Quaternion>& quatType, const aron::data::NDArrayPtr& arr) { + auto elemType = quatType->getElementType(); auto rawData = arr->getData(); auto shape = arr->getShape(); @@ -280,11 +287,13 @@ namespace armarx::skills::gui { quatWidget->setText((QuaternionWidget::QuaternionComponents)i, toString(i)); } + } void AronTreeWidgetSetterVisitor::visitAronVariant(const aron::data::NDArrayPtr& arr) { + // Matrices are handled as NDArray. Raw ndarrays cannot be created currently auto* el = AronTreeWidgetItem::DynamicCast(parentItem->child(index)); ARMARX_CHECK(el); @@ -315,11 +324,13 @@ namespace armarx::skills::gui { el->setCheckState(2, Qt::CheckState::Checked); } + } void AronTreeWidgetSetterVisitor::visitAronVariant(const aron::data::IntPtr& i) { + if (checkTreeWidgetItemForSimilarName(i->getPath().getLastElement())) { AronTreeWidgetItem* el = AronTreeWidgetItem::DynamicCast(parentItem->child(index)); @@ -341,11 +352,13 @@ namespace armarx::skills::gui el->setCheckState(2, Qt::CheckState::Checked); } } + } void AronTreeWidgetSetterVisitor::visitAronVariant(const aron::data::LongPtr& i) { + if (checkTreeWidgetItemForSimilarName(i->getPath().getLastElement())) { AronTreeWidgetItem* el = AronTreeWidgetItem::DynamicCast(parentItem->child(index)); @@ -356,6 +369,7 @@ namespace armarx::skills::gui el->setCheckState(2, Qt::CheckState::Checked); } } + } void @@ -364,18 +378,21 @@ namespace armarx::skills::gui if (checkTreeWidgetItemForSimilarName(i->getPath().getLastElement())) { AronTreeWidgetItem* el = AronTreeWidgetItem::DynamicCast(parentItem->child(index)); - el->setText(1, QString::fromStdString(usString<float>(i->getValue()))); - + std::string repr = usString<float>(i->getValue()); + QString qstr = QString::fromStdString(repr); + el->setText(1, qstr); if (el->aronType && el->aronType->getMaybe() != armarx::aron::type::Maybe::NONE) { el->setCheckState(2, Qt::CheckState::Checked); } } + } void AronTreeWidgetSetterVisitor::visitAronVariant(const aron::data::DoublePtr& i) { + if (checkTreeWidgetItemForSimilarName(i->getPath().getLastElement())) { AronTreeWidgetItem* el = AronTreeWidgetItem::DynamicCast(parentItem->child(index)); @@ -386,11 +403,13 @@ namespace armarx::skills::gui el->setCheckState(2, Qt::CheckState::Checked); } } + } void AronTreeWidgetSetterVisitor::visitAronVariant(const aron::data::BoolPtr& i) { + if (checkTreeWidgetItemForSimilarName(i->getPath().getLastElement())) { AronTreeWidgetItem* el = AronTreeWidgetItem::DynamicCast(parentItem->child(index)); @@ -401,11 +420,13 @@ namespace armarx::skills::gui el->setCheckState(2, Qt::CheckState::Checked); } } + } void AronTreeWidgetSetterVisitor::visitAronVariant(const aron::data::StringPtr& i) { + if (checkTreeWidgetItemForSimilarName(i->getPath().getLastElement())) { AronTreeWidgetItem* el = AronTreeWidgetItem::DynamicCast(parentItem->child(index)); @@ -416,6 +437,7 @@ namespace armarx::skills::gui el->setCheckState(2, Qt::CheckState::Checked); } } + } void