From f8bbcd9cc3e38ca3a80f11c7673e0cb868e31975 Mon Sep 17 00:00:00 2001
From: Rainer Kartmann <rainer.kartmann@kit.edu>
Date: Thu, 16 Nov 2023 10:31:00 +0100
Subject: [PATCH] Load names from JSON if available

---
 .../util/LocationLoader/LocationLoader.cpp     | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/source/RobotAPI/libraries/PriorKnowledge/util/LocationLoader/LocationLoader.cpp b/source/RobotAPI/libraries/PriorKnowledge/util/LocationLoader/LocationLoader.cpp
index cfeb43db5..ebde885d2 100644
--- a/source/RobotAPI/libraries/PriorKnowledge/util/LocationLoader/LocationLoader.cpp
+++ b/source/RobotAPI/libraries/PriorKnowledge/util/LocationLoader/LocationLoader.cpp
@@ -6,6 +6,8 @@
 #include <ArmarXCore/core/exceptions/local/ExpressionException.h>
 #include <ArmarXCore/core/logging/Logging.h>
 
+#include <RobotAPI/libraries/core/json_conversions.h>
+
 namespace armarx::priorknowledge::util
 {
     FramedLocationPtr
@@ -53,8 +55,18 @@ namespace armarx::priorknowledge::util
             pose,
             framedPose.at("pose").get<std::vector<std::vector<float>>>()); // load the 4x4 matrix
 
-        FramedLocationPtr loc(new FramedLocation(
-            LocationId(source, locationName), LocationType::FRAMED_LOCATION, frame, agent, pose));
+        std::optional<Names> names;
+        if (auto it = j.find("names"); it != j.end())
+        {
+            it->get_to(names.emplace());
+        }
+
+        FramedLocationPtr loc(new FramedLocation(LocationId(source, locationName),
+                                                 LocationType::FRAMED_LOCATION,
+                                                 frame,
+                                                 agent,
+                                                 pose,
+                                                 names));
         return loc;
     }
 
@@ -133,7 +145,7 @@ namespace armarx::priorknowledge::util
         }
 
         for (const auto& [locationName, j] :
-             js["locations"].get<std::map<std::string, nlohmann::json>>())
+             js.at("locations").get<std::map<std::string, nlohmann::json>>())
         {
             if (j.find("framedPose") != j.end())
             {
-- 
GitLab