From 1c76f9104cf19d7e1b9b849ad4b22060b12e8203 Mon Sep 17 00:00:00 2001
From: Rainer Kartmann <rainer.kartmann@kit.edu>
Date: Tue, 31 Oct 2023 11:12:26 +0100
Subject: [PATCH] Add a named group box for lists if element type not in
 implementedListDescriptors

---
 .../RemoteGuiVisitors.cpp                     | 69 ++++++++++++-------
 1 file changed, 46 insertions(+), 23 deletions(-)

diff --git a/source/RobotAPI/libraries/aron_component_config/RemoteGuiVisitors.cpp b/source/RobotAPI/libraries/aron_component_config/RemoteGuiVisitors.cpp
index 89499311e..fc06569dc 100644
--- a/source/RobotAPI/libraries/aron_component_config/RemoteGuiVisitors.cpp
+++ b/source/RobotAPI/libraries/aron_component_config/RemoteGuiVisitors.cpp
@@ -167,39 +167,62 @@ namespace armarx::aron::component_config
     MakeConfigGuiVisitor::visitListOnEnter(DataInput& o, TypeInput& t)
     {
         in_list_ = true;
-        auto group = RemoteGui::makeSimpleGridLayout(pathToName(o) + "_grid").cols(20);
-        auto data = data::List::DynamicCastAndCheck(o);
         auto type = type::List::DynamicCast(t)->getAcceptedType()->getDescriptor();
-        if (std::find(implementedListDescriptors.begin(), implementedListDescriptors.end(), type) ==
+
+        if (std::find(implementedListDescriptors.begin(), implementedListDescriptors.end(), type) !=
             implementedListDescriptors.end())
         {
-            return;
+            auto group = RemoteGui::makeSimpleGridLayout(pathToName(o) + "_grid").cols(20);
+            auto data = data::List::DynamicCastAndCheck(o);
+
+            for (const auto& el : data->getElements())
+            {
+                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"),
+                               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.")));
         }
-        for (const auto& el : data->getElements())
+        else
         {
-            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"),
-                           2);
+            std::string name = pathToName(o);
+            group_hierarchy_.emplace_back(std::make_shared<RemoteGui::detail::GroupBoxBuilder>(
+                RemoteGui::makeGroupBox(name)));
         }
-        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& /*unused*/, TypeInput& /*unused*/)
+    MakeConfigGuiVisitor::visitListOnExit(DataInput& /*unused*/, TypeInput& t)
     {
         in_list_ = false;
+
+        auto type = type::List::DynamicCast(t)->getAcceptedType()->getDescriptor();
+
+        if (std::find(implementedListDescriptors.begin(), implementedListDescriptors.end(), type) !=
+            implementedListDescriptors.end())
+        {
+        }
+        else
+        {
+            auto builder = *group_hierarchy_.back();
+            group_hierarchy_.pop_back();
+            if (not group_hierarchy_.empty())
+            {
+                group_hierarchy_.back()->addChild(builder);
+            }
+        }
     }
 
     void
@@ -232,7 +255,7 @@ namespace armarx::aron::component_config
         group.addChild(RemoteGui::makeLabel(name + "_label").value(q->getPath().getLastElement()));
         group.addHSpacer();
 
-        if (cols == 4 && rows == 4)
+        if (cols == 4 and rows == 4)
         {
             // Poses
             const auto& matrix = aron::data::converter::AronEigenConverter::ConvertToMatrix4f(data);
-- 
GitLab