From 56789608c936400c1a953aee6d1b0c4f90a5cc89 Mon Sep 17 00:00:00 2001
From: Peter Albrecht <albrecpe@gmail.com>
Date: Sat, 21 Oct 2023 16:16:54 +0200
Subject: [PATCH] Implemented tracking of selected SkillExecutionID in
 SelectedSkill

---
 .../SkillManagerMonitorWidgetController.cpp   | 30 +++++++++++++++----
 .../SkillManagerMonitorWidgetController.h     |  8 ++++-
 .../libraries/skills/core/SkillExecutionID.h  |  1 +
 3 files changed, 33 insertions(+), 6 deletions(-)

diff --git a/source/RobotAPI/gui-plugins/SkillManagerPlugin/SkillManagerMonitorWidgetController.cpp b/source/RobotAPI/gui-plugins/SkillManagerPlugin/SkillManagerMonitorWidgetController.cpp
index 49e3a18bf..bb7ac21c9 100644
--- a/source/RobotAPI/gui-plugins/SkillManagerPlugin/SkillManagerMonitorWidgetController.cpp
+++ b/source/RobotAPI/gui-plugins/SkillManagerPlugin/SkillManagerMonitorWidgetController.cpp
@@ -160,16 +160,17 @@ namespace armarx
                 &QPushButton::clicked,
                 this,
                 &SkillManagerMonitorWidgetController::executeSkill);
-        //        connect(widget.pushButtonStopSkill,
-        //                &QPushButton::clicked,
-        //                this,
-        //                &SkillManagerMonitorWidgetController::stopSkill);
 
         connect(widget.treeWidgetSkills,
                 &QTreeWidget::currentItemChanged,
                 this,
                 &SkillManagerMonitorWidgetController::skillSelectionChanged);
 
+        connect(widget.treeWidgetSkillExecutions,
+                &QTreeWidget::currentItemChanged,
+                this,
+                &SkillManagerMonitorWidgetController::skillExecutionSelectionChanged);
+
         connect(widget.pushButtonRefreshNow,
                 &QPushButton::clicked,
                 this,
@@ -487,7 +488,8 @@ namespace armarx
     void
     SkillManagerMonitorWidgetController::stopSkill()
     {
-        ARMARX_IMPORTANT << "Stop skill triggered";
+        std::string c = selectedSkill.skillExecutionId.skillId.skillName;
+        ARMARX_IMPORTANT << "Stop skill triggered: " << c;
         //        std::scoped_lock l(updateMutex);
         //        if (selectedSkill.skillId.fullySpecified())
         //        {
@@ -505,6 +507,24 @@ namespace armarx
         //        manager->abortSkill(selectedSkill.skillId);
     }
 
+    void
+    SkillManagerMonitorWidgetController::skillExecutionSelectionChanged(QTreeWidgetItem* current,
+                                                                        QTreeWidgetItem*)
+    {
+        std::scoped_lock l(updateMutex);
+        widget.groupBoxSkillExecutions->setEnabled(false);
+
+        if (!current)
+        {
+            // gui has died?
+            return;
+        }
+
+        auto c = static_cast<SkillExecutionInfoTreeWidgetItem*>(current);
+        selectedSkill.skillExecutionId = c->executionId;
+        widget.groupBoxSkillExecutions->setEnabled(true);
+    }
+
     void
     SkillManagerMonitorWidgetController::skillSelectionChanged(QTreeWidgetItem* current,
                                                                QTreeWidgetItem*)
diff --git a/source/RobotAPI/gui-plugins/SkillManagerPlugin/SkillManagerMonitorWidgetController.h b/source/RobotAPI/gui-plugins/SkillManagerPlugin/SkillManagerMonitorWidgetController.h
index c894f30c2..6d35a5279 100644
--- a/source/RobotAPI/gui-plugins/SkillManagerPlugin/SkillManagerMonitorWidgetController.h
+++ b/source/RobotAPI/gui-plugins/SkillManagerPlugin/SkillManagerMonitorWidgetController.h
@@ -116,6 +116,7 @@ namespace armarx
 
     private slots:
         void skillSelectionChanged(QTreeWidgetItem* current, QTreeWidgetItem* previous);
+        void skillExecutionSelectionChanged(QTreeWidgetItem* current, QTreeWidgetItem* previous);
 
         void stopSkill();
         void executeSkill();
@@ -155,9 +156,14 @@ namespace armarx
         struct SelectedSkill
         {
             skills::SkillID skillId;
+            skills::SkillExecutionID skillExecutionId;
 
             // make default constructable
-            SelectedSkill() : skillId({skills::SkillID::UNKNOWN}, skills::SkillID::UNKNOWN)
+            SelectedSkill() :
+                skillId({skills::SkillID::UNKNOWN}, skills::SkillID::UNKNOWN),
+                skillExecutionId({{skills::SkillID::UNKNOWN}, skills::SkillID::UNKNOWN},
+                                 skills::SkillExecutionID::UNKNOWN,
+                                 armarx::core::time::DateTime::Invalid())
             {
             }
         } selectedSkill;
diff --git a/source/RobotAPI/libraries/skills/core/SkillExecutionID.h b/source/RobotAPI/libraries/skills/core/SkillExecutionID.h
index 7ba3ea987..a39d82bd2 100644
--- a/source/RobotAPI/libraries/skills/core/SkillExecutionID.h
+++ b/source/RobotAPI/libraries/skills/core/SkillExecutionID.h
@@ -21,6 +21,7 @@ namespace armarx
             SkillID skillId;
             std::string executorName;
             armarx::core::time::DateTime executionStartedTime;
+            static const constexpr char* UNKNOWN = "UNKNOWN";
 
             SkillExecutionID() = delete;
             SkillExecutionID(const SkillID&,
-- 
GitLab