diff --git a/source/RobotAPI/components/AronComponentConfigExample/aron/ComponentConfig.xml b/source/RobotAPI/components/AronComponentConfigExample/aron/ComponentConfig.xml index 56dc87b417ab791fe31e9840fc273aa13f88dfe8..aabd27602d4f4ef4f0313dd00af36ccfa9c2a9dd 100644 --- a/source/RobotAPI/components/AronComponentConfigExample/aron/ComponentConfig.xml +++ b/source/RobotAPI/components/AronComponentConfigExample/aron/ComponentConfig.xml @@ -91,6 +91,15 @@ <ObjectChild key='subMember'> <armarx::component_config::aron::SubConfig /> </ObjectChild> + <ObjectChild key='position'> + <framedposition /> + </ObjectChild> + <ObjectChild key='pose'> + <framedpose /> + </ObjectChild> + <ObjectChild key='orientation'> + <framedorientation /> + </ObjectChild> </Object> </GenerateTypes> </AronTypeDefinition> diff --git a/source/RobotAPI/libraries/aron_component_config/CMakeLists.txt b/source/RobotAPI/libraries/aron_component_config/CMakeLists.txt index 2529d9e77da2d02cadad9be1da028aae078c23fe..5b6b176ca9b2e9d303251db890ab28939ac1544b 100644 --- a/source/RobotAPI/libraries/aron_component_config/CMakeLists.txt +++ b/source/RobotAPI/libraries/aron_component_config/CMakeLists.txt @@ -23,7 +23,7 @@ armarx_build_if(Simox_FOUND "Simox not available") set(LIBS ArmarXCoreInterfaces ArmarXCore ArmarXGuiComponentPlugins - RobotAPIInterfaces RobotAPICore RobotAPIComponentPlugins + RobotAPIInterfaces RobotAPICore RobotAPIComponentPlugins aroneigenconverter ) set(LIB_FILES diff --git a/source/RobotAPI/libraries/aron_component_config/RemoteGuiVisitors.cpp b/source/RobotAPI/libraries/aron_component_config/RemoteGuiVisitors.cpp index 42c8124493d8273594e5056b70bb8f5a37c6141f..348edcb9ef22177f449dcb1ace857aeee34ec548 100644 --- a/source/RobotAPI/libraries/aron_component_config/RemoteGuiVisitors.cpp +++ b/source/RobotAPI/libraries/aron_component_config/RemoteGuiVisitors.cpp @@ -22,39 +22,46 @@ #include "RemoteGuiVisitors.h" +#include <SimoxUtility/math/convert/quat_to_rpy.h> + +#include <ArmarXCore/util/CPPUtility/Iterator.h> + #include <ArmarXGui/libraries/RemoteGui/RemoteGui.h> + +#include <RobotAPI/libraries/aron/converter/eigen/EigenConverter.h> #include <RobotAPI/libraries/aron/core/data/variant/All.h> -#include <ArmarXCore/util/CPPUtility/Iterator.h> #include <RobotAPI/libraries/aron_component_config/VariantHelperFactory.h> + #include "Util.h" -#define INPUT_GUARD(i) \ -ARMARX_TRACE; \ -ARMARX_CHECK_NOT_NULL(i); \ -if (in_list_) return; +#define INPUT_GUARD(i) \ + ARMARX_TRACE; \ + ARMARX_CHECK_NOT_NULL(i); \ + if (in_list_) \ + return; namespace armarx::aron::component_config { void - MakeConfigGuiVisitor::visitObjectOnEnter(DataInput& dict, TypeInput&) + MakeConfigGuiVisitor::visitObjectOnEnter(DataInput& dict, TypeInput& /*unused*/) { INPUT_GUARD(dict); if (dict->getPath().hasElement()) { std::string name = pathToName(dict); - group_hierarchy_.emplace_back(std::make_shared<RemoteGui::detail::GroupBoxBuilder>(RemoteGui::makeGroupBox( - name))); - } else + group_hierarchy_.emplace_back(std::make_shared<RemoteGui::detail::GroupBoxBuilder>( + RemoteGui::makeGroupBox(name))); + } + else { group_hierarchy_.push_back(builder_); } - } void - MakeConfigGuiVisitor::visitObjectOnExit(DataInput& dict, TypeInput&) + MakeConfigGuiVisitor::visitObjectOnExit(DataInput& dict, TypeInput& /*j*/) { INPUT_GUARD(dict); auto builder = *group_hierarchy_.back(); @@ -66,7 +73,7 @@ namespace armarx::aron::component_config } void - MakeConfigGuiVisitor::visitInt(DataInput& i, TypeInput&) + MakeConfigGuiVisitor::visitInt(DataInput& i, TypeInput& /*unused*/) { INPUT_GUARD(i); auto value = data::Int::DynamicCastAndCheck(i); @@ -74,15 +81,16 @@ namespace armarx::aron::component_config auto group = RemoteGui::makeHBoxLayout(name + "_layout"); group.addChild(RemoteGui::makeLabel(name + "_label").value(i->getPath().getLastElement())); group.addHSpacer(); - group.addChild(RemoteGui::makeIntSpinBox(name).value(value->getValue()) - .min(-1000) - .max(1000).toolTip(name)); - group_hierarchy_.back() - ->addChild(group); + group.addChild(RemoteGui::makeIntSpinBox(name) + .value(value->getValue()) + .min(-1000) + .max(1000) + .toolTip(name)); + group_hierarchy_.back()->addChild(group); } void - MakeConfigGuiVisitor::visitFloat(DataInput& f, TypeInput&) + MakeConfigGuiVisitor::visitFloat(DataInput& f, TypeInput& /*unused*/) { INPUT_GUARD(f); auto value = data::Float::DynamicCastAndCheck(f); @@ -90,15 +98,16 @@ namespace armarx::aron::component_config auto group = RemoteGui::makeHBoxLayout(name + "_layout"); group.addChild(RemoteGui::makeLabel(name + "_label").value(f->getPath().getLastElement())); group.addHSpacer(); - group.addChild(RemoteGui::makeFloatSpinBox(name).value(value->getValue()) - .min(-1000) - .max(1000).toolTip(name)); - group_hierarchy_.back() - ->addChild(group); + group.addChild(RemoteGui::makeFloatSpinBox(name) + .value(value->getValue()) + .min(-1000) + .max(1000) + .toolTip(name)); + group_hierarchy_.back()->addChild(group); } void - MakeConfigGuiVisitor::visitDouble(DataInput& d, TypeInput&) + MakeConfigGuiVisitor::visitDouble(DataInput& d, TypeInput& /*unused*/) { INPUT_GUARD(d); auto value = data::Double::DynamicCastAndCheck(d); @@ -106,38 +115,44 @@ namespace armarx::aron::component_config auto group = RemoteGui::makeHBoxLayout(name + "_layout"); group.addChild(RemoteGui::makeLabel(name + "_label").value(d->getPath().getLastElement())); group.addHSpacer(); - group.addChild(RemoteGui::makeFloatSpinBox(name).value(value->getValue()) - .min(-1000) - .max(1000).toolTip(name)); - group_hierarchy_.back() - ->addChild(group); + group.addChild(RemoteGui::makeFloatSpinBox(name) + .value(value->getValue()) + .min(-1000) + .max(1000) + .toolTip(name)); + group_hierarchy_.back()->addChild(group); } void - MakeConfigGuiVisitor::visitBool(DataInput& b, TypeInput&) + MakeConfigGuiVisitor::visitBool(DataInput& b, TypeInput& /*unused*/) { INPUT_GUARD(b); auto value = data::Bool::DynamicCastAndCheck(b); - group_hierarchy_.back() - ->addChild(RemoteGui::makeCheckBox(pathToName(b)).value(value->getValue()) - .label(b->getPath().getLastElement())); + const auto& name = pathToName(b); + auto group = RemoteGui::makeHBoxLayout(name + "_layout"); + group.addChild(RemoteGui::makeLabel(name + "_label").value(b->getPath().getLastElement())); + group.addHSpacer(); + group.addChild( + RemoteGui::makeCheckBox(name).label("").value(value->getValue()).toolTip(name)); + group_hierarchy_.back()->addChild(group); } void - MakeConfigGuiVisitor::visitString(DataInput& string, TypeInput&) + MakeConfigGuiVisitor::visitString(DataInput& string, TypeInput& /*unused*/) { INPUT_GUARD(string); auto value = data::String::DynamicCastAndCheck(string); const auto& name = pathToName(string); auto group = RemoteGui::makeHBoxLayout(name + "_layout"); - group.addChild(RemoteGui::makeLabel(name + "_label").value(string->getPath().getLastElement())); + group.addChild( + RemoteGui::makeLabel(name + "_label").value(string->getPath().getLastElement())); group.addHSpacer(); group.addChild(RemoteGui::makeLineEdit(name).value(value->getValue()).toolTip(name)); group_hierarchy_.back()->addChild(group); } MakeConfigGuiVisitor::MakeConfigGuiVisitor(const std::string& name) : - builder_(std::make_unique<RemoteGui::detail::GroupBoxBuilder>(name)) + builder_(std::make_unique<RemoteGui::detail::GroupBoxBuilder>(name)) { } @@ -160,27 +175,29 @@ namespace armarx::aron::component_config { return; } - for (const auto& el: data->getElements()) + for (const auto& el : data->getElements()) { - group.addChild(RemoteGui::makeLineEdit(pathToName(el)).value(factories::VariantHelper::make(type)->to_string( - el)), 10); + group.addChild(RemoteGui::makeLineEdit(pathToName(el)) + .value(factories::VariantHelper::make(type)->to_string(el)), + 10); group.addHSpacer(8); - group.addChild(RemoteGui::makeButton(pathToName(el) + "_button").label("-").toolTip("Remove List Element"), + group.addChild(RemoteGui::makeButton(pathToName(el) + "_button") + .label("-") + .toolTip("Remove List Element"), 2); } - group_hierarchy_.back() - ->addChild(RemoteGui::makeGroupBox(pathToName(o) + "_grp").label(o->getPath().getLastElement()) - .collapsed(true) - .addChild(group) - .addChild(RemoteGui::makeButton( - pathToName(o) + - "_add").label("+") - .toolTip( - "Add new list entry."))); + group_hierarchy_.back()->addChild( + RemoteGui::makeGroupBox(pathToName(o) + "_grp") + .label(o->getPath().getLastElement()) + .collapsed(true) + .addChild(group) + .addChild(RemoteGui::makeButton(pathToName(o) + "_add") + .label("+") + .toolTip("Add new list entry."))); } void - MakeConfigGuiVisitor::visitListOnExit(DataInput&, TypeInput&) + MakeConfigGuiVisitor::visitListOnExit(DataInput& /*unused*/, TypeInput& /*unused*/) { in_list_ = false; } @@ -195,10 +212,55 @@ namespace armarx::aron::component_config auto group = RemoteGui::makeHBoxLayout(name + "_layout"); group.addChild(RemoteGui::makeLabel(name + "_label").value(o->getPath().getLastElement())); group.addHSpacer(); - group.addChild(RemoteGui::makeComboBox(name).options(type->getAcceptedValueNames()) - .value(type->getValueName(data->getValue())).toolTip(name)); - group_hierarchy_.back() - ->addChild(group); + group.addChild(RemoteGui::makeComboBox(name) + .options(type->getAcceptedValueNames()) + .value(type->getValueName(data->getValue())) + .toolTip(name)); + group_hierarchy_.back()->addChild(group); + } + void + MakeConfigGuiVisitor::visitMatrix(const std::shared_ptr<data::Variant>& q, + const std::shared_ptr<type::Variant>& t) + { + auto data = data::NDArray::DynamicCastAndCheck(q); + auto type = type::Matrix::DynamicCast(t); + const auto& cols = type->getCols(); + const auto& rows = type->getRows(); + const auto& name = pathToName(q); + auto group = RemoteGui::makeHBoxLayout(name + "_layout"); + group.addChild(RemoteGui::makeLabel(name + "_label").value(q->getPath().getLastElement())); + group.addHSpacer(); + + if (cols == 4 && rows == 4) + { + // Poses + const auto& matrix = aron::converter::AronEigenConverter::ConvertToMatrix4f(data); + group.addChild(RemoteGui::makePosRPYSpinBoxes(name).value(matrix).toolTip(name)); + } + else if ((cols == 3 and rows == 1) or (rows == 3 and cols == 1)) + { + // Positions + const auto& vector = aron::converter::AronEigenConverter::ConvertToVector3f(data); + group.addChild(RemoteGui::makeVector3fSpinBoxes(name).value(vector).toolTip(name)); + } + group_hierarchy_.back()->addChild(group); + } + + void + MakeConfigGuiVisitor::visitQuaternion(const std::shared_ptr<data::Variant>& q, + const std::shared_ptr<type::Variant>& t) + { + INPUT_GUARD(q); + auto data = data::NDArray::DynamicCastAndCheck(q); + auto type = type::Quaternion::DynamicCast(t); + const auto& quat = simox::math::quat_to_rpy( + aron::converter::AronEigenConverter::ConvertToQuaternionf(data)); + const auto& name = pathToName(q); + auto group = RemoteGui::makeHBoxLayout(name + "_layout"); + group.addChild(RemoteGui::makeLabel(name + "_label").value(q->getPath().getLastElement())); + group.addHSpacer(); + group.addChild(RemoteGui::makeVector3fSpinBoxes(name).value(quat).min(-M_PI).max(M_PI).toolTip(name)); + group_hierarchy_.back()->addChild(group); } void @@ -214,36 +276,40 @@ namespace armarx::aron::component_config { return; } - for (const auto& el: data->getElements()) + for (const auto& el : data->getElements()) { - group.addChild(RemoteGui::makeLineEdit(pathToName(el.second) + "_lbl").value(el.first), 5); + group.addChild(RemoteGui::makeLineEdit(pathToName(el.second) + "_lbl").value(el.first), + 5); group.addHSpacer(2); - group.addChild(RemoteGui::makeLineEdit(pathToName(el.second)).value(factories::VariantHelper::make(type)->to_string( - el.second)), 5); + group.addChild(RemoteGui::makeLineEdit(pathToName(el.second)) + .value(factories::VariantHelper::make(type)->to_string(el.second)), + 5); group.addHSpacer(6); - group.addChild(RemoteGui::makeButton(pathToName(el.second) + "_button").label("-") - .toolTip("Remove List Element"), 2); + group.addChild(RemoteGui::makeButton(pathToName(el.second) + "_button") + .label("-") + .toolTip("Remove List Element"), + 2); } - group_hierarchy_.back() - ->addChild(RemoteGui::makeGroupBox(pathToName(o) + "_grp").label(o->getPath().getLastElement()) - .collapsed(true) - .addChild(group) - .addChild(RemoteGui::makeButton( - pathToName(o) + - "_add").label("+") - .toolTip( - "Add new dict entry."))); + group_hierarchy_.back()->addChild( + RemoteGui::makeGroupBox(pathToName(o) + "_grp") + .label(o->getPath().getLastElement()) + .collapsed(true) + .addChild(group) + .addChild(RemoteGui::makeButton(pathToName(o) + "_add") + .label("+") + .toolTip("Add new dict entry."))); } void - MakeConfigGuiVisitor::visitDictOnExit(const std::shared_ptr<data::Variant>&, const std::shared_ptr<type::Variant>&) + MakeConfigGuiVisitor::visitDictOnExit(const std::shared_ptr<data::Variant>&, + const std::shared_ptr<type::Variant>&) { in_list_ = false; } GetValueFromMapVisitor::GetValueFromMapVisitor(armarx::RemoteGui::TabProxy* proxy) : - proxy_(std::experimental::make_observer(proxy)) + proxy_(std::experimental::make_observer(proxy)) { } @@ -260,7 +326,8 @@ namespace armarx::aron::component_config { value->setValue(gui_value.get()); i = value; - } else + } + else { proxy_->setValue(value->getValue(), name); } @@ -280,7 +347,8 @@ namespace armarx::aron::component_config { value->setValue(gui_value.get()); f = value; - } else + } + else { proxy_->setValue(value->getValue(), name); } @@ -301,7 +369,8 @@ namespace armarx::aron::component_config { value->setValue(gui_value.get()); d = value; - } else + } + else { proxy_->setValue(static_cast<float>(value->getValue()), name); } @@ -321,7 +390,8 @@ namespace armarx::aron::component_config { value->setValue(gui_value.get()); b = value; - } else + } + else { proxy_->setValue(value->getValue(), name); } @@ -341,7 +411,8 @@ namespace armarx::aron::component_config { value->setValue(gui_value.get()); string = value; - } else + } + else { proxy_->setValue(value->getValue(), name); } @@ -399,7 +470,8 @@ namespace armarx::aron::component_config { data->getValue() = type->getValue(str); o = data; - } else + } + else { proxy_->setValue(type->getValueName(data->getValue()), name); } @@ -418,7 +490,7 @@ namespace armarx::aron::component_config return; } const auto& elements = data->getElements(); - for (const auto& [idx, el]: armarx::MakeIndexedContainer(elements)) + for (const auto& [idx, el] : armarx::MakeIndexedContainer(elements)) { if (proxy_->getButtonClicked(pathToName(el) + "_button")) { @@ -430,9 +502,8 @@ namespace armarx::aron::component_config } if (proxy_->getButtonClicked(pathToName(o) + "_add")) { - data->addElement(factories::VariantHelper::make(type)->from_string("", - o->getPath() - .withIndex(data->childrenSize()))); + data->addElement(factories::VariantHelper::make(type)->from_string( + "", o->getPath().withIndex(data->childrenSize()))); tab_rebuild_required_ = true; } } @@ -450,7 +521,8 @@ namespace armarx::aron::component_config } void - GetValueFromMapVisitor::visitDictOnEnter(std::shared_ptr<data::Variant>& o, const std::shared_ptr<type::Variant>& t) + GetValueFromMapVisitor::visitDictOnEnter(std::shared_ptr<data::Variant>& o, + const std::shared_ptr<type::Variant>& t) { in_list_ = true; auto data = data::Dict::DynamicCastAndCheck(o); @@ -462,7 +534,7 @@ namespace armarx::aron::component_config } const auto& elements = data->getElements(); std::map<std::string, std::string> changed_labels; - for (const auto& [idx, el]: elements) + for (const auto& [idx, el] : elements) { const std::string name = pathToName(el); if (proxy_->getButtonClicked(name + "_button")) @@ -478,7 +550,8 @@ namespace armarx::aron::component_config if (proxy_->hasValueChanged(name)) { factories::VariantHelper::make(type)->set_value_from_string(el, gui_value); - } else + } + else { proxy_->setValue(config_value, name); } @@ -488,40 +561,41 @@ namespace armarx::aron::component_config if (proxy_->hasValueChanged(name + "_lbl")) { changed_labels.emplace(idx, gui_key); - } else + } + else { proxy_->setValue(idx, name + "_lbl"); } } } // replace changed keys in map - for (const auto& [old_label, new_label]: changed_labels) + for (const auto& [old_label, new_label] : changed_labels) { auto element = data->getElement(old_label); data->removeElement(old_label); auto variantHelper = factories::VariantHelper::make(type); data->addElement(new_label, - variantHelper->from_string(variantHelper->to_string(element), - o->getPath().withDetachedLastElement().withElement(new_label))); + variantHelper->from_string( + variantHelper->to_string(element), + o->getPath().withDetachedLastElement().withElement(new_label))); tab_rebuild_required_ = true; } if (proxy_->getButtonClicked(pathToName(o) + "_add")) { data->addElement("defaultKey", - factories::VariantHelper::make(type)->from_string("", - o->getPath() - .withElement("defaultKey"))); + factories::VariantHelper::make(type)->from_string( + "", o->getPath().withElement("defaultKey"))); tab_rebuild_required_ = true; } - } void - GetValueFromMapVisitor::visitDictOnExit(std::shared_ptr<data::Variant>&, const std::shared_ptr<type::Variant>&) + GetValueFromMapVisitor::visitDictOnExit(std::shared_ptr<data::Variant>&, + const std::shared_ptr<type::Variant>&) { in_list_ = false; } -} +} // namespace armarx::aron::component_config #undef INPUT_GUARD \ No newline at end of file diff --git a/source/RobotAPI/libraries/aron_component_config/RemoteGuiVisitors.h b/source/RobotAPI/libraries/aron_component_config/RemoteGuiVisitors.h index ef9f3596bcff18cbd53b0bea245d52d80ab9642e..65fd6c153a35b1cb70139a9db779f173b0a3b6f3 100644 --- a/source/RobotAPI/libraries/aron_component_config/RemoteGuiVisitors.h +++ b/source/RobotAPI/libraries/aron_component_config/RemoteGuiVisitors.h @@ -70,6 +70,10 @@ namespace armarx::aron::component_config void visitString(DataInput&, TypeInput&) override; + void visitQuaternion(DataInput& input, TypeInput& typeInput) override; + + void visitMatrix(DataInput& input, TypeInput& typeInput) override; + [[nodiscard]] RemoteGui::detail::GroupBoxBuilder getGroupBoxBuilder() const; private: