From e0914bf45aa3b28d03f15c50046051ab9f2a459c Mon Sep 17 00:00:00 2001 From: Peter Albrecht <usnlf@student.kit.edu> Date: Wed, 12 Feb 2025 15:52:03 +0100 Subject: [PATCH] implement: history saving and loading --- .../skill_details/ProfileMenuWidget.cpp | 19 ++++++++++++++----- .../skill_details/ProfileMenuWidget.h | 7 +++++++ .../skill_details/SkillDetailsGroupBox.cpp | 6 ++++++ .../skill_details/SkillDetailsTreeWidget.cpp | 19 +++++++++++++++++++ .../skill_details/SkillDetailsTreeWidget.h | 6 +++++- 5 files changed, 51 insertions(+), 6 deletions(-) diff --git a/source/RobotAPI/libraries/skills_gui/skill_details/ProfileMenuWidget.cpp b/source/RobotAPI/libraries/skills_gui/skill_details/ProfileMenuWidget.cpp index 73a69456d..76a027d86 100644 --- a/source/RobotAPI/libraries/skills_gui/skill_details/ProfileMenuWidget.cpp +++ b/source/RobotAPI/libraries/skills_gui/skill_details/ProfileMenuWidget.cpp @@ -22,14 +22,16 @@ namespace armarx::skills::gui copyArgsToClipboard = new QPushButton(); copySkillIdToClipboard = new QPushButton(); resetArgsToProfile = new QPushButton(); - profileSelector = new QComboBox(); + //profileSelector = new QComboBox(); + historySelector = new QPushButton(); // layouting QVBoxLayout* mainLayout = new QVBoxLayout(); QHBoxLayout* topLayout = new QHBoxLayout(); mainLayout->addLayout(topLayout); - mainLayout->addWidget(profileSelector); + //mainLayout->addWidget(profileSelector); + mainLayout->addWidget(historySelector); topLayout->addWidget(setArgsFromClipboard); topLayout->addWidget(copyArgsToClipboard); @@ -46,9 +48,16 @@ namespace armarx::skills::gui copySkillIdToClipboard->setIcon(getIcon("edit-copy-4.svg")); resetArgsToProfile->setText(QString::fromStdString(RESET_ARGS_BUTTON_TEXT)); resetArgsToProfile->setIcon(getIcon("refresh-black.svg")); - profileSelector->addItem(QString::fromStdString(DEFAULT_PROFILE_TEXT)); - profileSelector->setDisabled(true); - profileSelector->setToolTip(QString::fromStdString(PROFILE_NOT_IMPLEMENTED)); + //profileSelector->addItem(QString::fromStdString(DEFAULT_PROFILE_TEXT)); + //profileSelector->setDisabled(true); + //profileSelector->setToolTip(QString::fromStdString(PROFILE_NOT_IMPLEMENTED)); + historySelector->setText(QString::fromStdString(HIST_BUTTON_TEXT)); + } + + void ProfileMenuWidget::updateHistorySelector(skills::SkillID shownSkill) + { + auto params = memory->getLatestParametersForSkill(shownSkill); + historySelector->setDisabled(not params.has_value()); } diff --git a/source/RobotAPI/libraries/skills_gui/skill_details/ProfileMenuWidget.h b/source/RobotAPI/libraries/skills_gui/skill_details/ProfileMenuWidget.h index ad6feab68..d1e7bfaec 100644 --- a/source/RobotAPI/libraries/skills_gui/skill_details/ProfileMenuWidget.h +++ b/source/RobotAPI/libraries/skills_gui/skill_details/ProfileMenuWidget.h @@ -4,6 +4,7 @@ #include <QComboBox> #include <QPushButton> #include <QWidget> +#include <qpushbutton.h> #include "../memory/MemoryCommunicatorBase.h" @@ -20,6 +21,7 @@ namespace armarx::skills::gui static const constexpr char* DEFAULT_PROFILE_TEXT = "<No Profile selected. Using root>"; static const constexpr char* PROFILE_NOT_IMPLEMENTED = "Profiles other than the root profile are currently not supported."; + static const constexpr char* HIST_BUTTON_TEXT = "Load Parameters from Last Execution"; // contents are public, as this class is just a convenience wrapper QPushButton* setArgsFromClipboard = nullptr; @@ -27,6 +29,7 @@ namespace armarx::skills::gui QPushButton* copySkillIdToClipboard = nullptr; QPushButton* resetArgsToProfile = nullptr; QComboBox* profileSelector = nullptr; + QPushButton* historySelector = nullptr; ProfileMenuWidget(std::shared_ptr<SkillManagerWrapper> _memory, QWidget* parent = nullptr) : QWidget(parent), MemoryCommunicatorBase(_memory) @@ -34,6 +37,10 @@ namespace armarx::skills::gui setupUi(); } + public slots: + + void updateHistorySelector(const skills::SkillID shownSkill); + private: void setupUi(); }; diff --git a/source/RobotAPI/libraries/skills_gui/skill_details/SkillDetailsGroupBox.cpp b/source/RobotAPI/libraries/skills_gui/skill_details/SkillDetailsGroupBox.cpp index 07fc42bdf..834185f79 100644 --- a/source/RobotAPI/libraries/skills_gui/skill_details/SkillDetailsGroupBox.cpp +++ b/source/RobotAPI/libraries/skills_gui/skill_details/SkillDetailsGroupBox.cpp @@ -1,4 +1,6 @@ #include "SkillDetailsGroupBox.h" +#include <qpushbutton.h> +#include "RobotAPI/libraries/skills_gui/skill_details/SkillDetailsTreeWidget.h" namespace armarx::skills::gui { @@ -159,6 +161,10 @@ namespace armarx::skills::gui &QPushButton::clicked, skillDetailsTreeWidget, &SkillDetailsTreeWidget::resetCurrentConfig); + connect(profileMenuWidget->historySelector, + &QPushButton::pressed, + skillDetailsTreeWidget, + &SkillDetailsTreeWidget::reloadLastParameters); } diff --git a/source/RobotAPI/libraries/skills_gui/skill_details/SkillDetailsTreeWidget.cpp b/source/RobotAPI/libraries/skills_gui/skill_details/SkillDetailsTreeWidget.cpp index c7ec8c4d9..ef4a98533 100644 --- a/source/RobotAPI/libraries/skills_gui/skill_details/SkillDetailsTreeWidget.cpp +++ b/source/RobotAPI/libraries/skills_gui/skill_details/SkillDetailsTreeWidget.cpp @@ -80,6 +80,8 @@ namespace armarx::skills::gui this->expandAll(); resizeContents(); + emit updated(skillId); + // update the ShownSkill shownSkill = {skillId, descr, aronTreeWidgetController->convertToAron()}; } @@ -210,6 +212,23 @@ namespace armarx::skills::gui this->setColumnWidth(1, dynamicColumnSize); } + + void SkillDetailsTreeWidget::reloadLastParameters() + { + if (not shownSkill.has_value()) + { + return; + } + + auto params = memory->getLatestParametersForSkill(shownSkill->skillId); + + if (not params.has_value()) + { + return; + } + + aronTreeWidgetController->setFromAron(params.value()); + } aron::data::DictPtr SkillDetailsTreeWidget::getConfigAsAron() diff --git a/source/RobotAPI/libraries/skills_gui/skill_details/SkillDetailsTreeWidget.h b/source/RobotAPI/libraries/skills_gui/skill_details/SkillDetailsTreeWidget.h index 2cf18976a..92308c098 100644 --- a/source/RobotAPI/libraries/skills_gui/skill_details/SkillDetailsTreeWidget.h +++ b/source/RobotAPI/libraries/skills_gui/skill_details/SkillDetailsTreeWidget.h @@ -26,6 +26,9 @@ namespace armarx::skills::gui void pasteCurrentConfig(); void resetWidget(); + signals: + void updated(const skills::SkillID shownSkill); + public slots: // this will reset the args to the profile defaults void resetCurrentConfig(); @@ -34,7 +37,8 @@ namespace armarx::skills::gui void disconnectGui(); void updateGui(SkillManagerWrapper::Snapshot update); void resizeContents(); - + void reloadLastParameters(); + private: struct ShownSkill { -- GitLab