12#include <qmessagebox.h>
13#include <qpushbutton.h>
14#include <qtreewidget.h>
32 std::optional<SkillID>
35 if (shownSkill.has_value())
37 return shownSkill.value().skillId;
56 if (shownSkill.has_value())
58 auto remDesc = shownSkill.value().descr;
74 QTreeWidgetItem* aronTreeWidgetItem =
new QTreeWidgetItem(
this);
75 aronTreeWidgetItem->setText(0, QString::fromStdString(
"Parameters"));
77 aronTreeWidgetController = std::make_shared<AronTreeWidgetController>(
78 this, aronTreeWidgetItem, aron_args, default_args_of_profile);
87 shownSkill = {skillId, descr, aronTreeWidgetController->convertToAron()};
93 this->aronTreeWidgetController =
nullptr;
99 if (not shownSkill.has_value())
110 auto skillsMap = update.skills;
111 if (skillsMap.count(sid.
providerId.value()) == 0 ||
112 skillsMap.at(sid.
providerId.value()).count(sid) == 0)
118 auto descr = update.skills.at(sid.
providerId.value()).at(sid);
123 if (descr.skillId != shownSkill->descr.skillId ||
124 descr.timeout != shownSkill->descr.timeout ||
125 descr.description != shownSkill->descr.description)
127 ARMARX_WARNING <<
"The skill description of the currently shown skill has changed. "
128 "Resetting the widget...";
134 SkillDetailsTreeWidget::setupUi()
136 this->setColumnCount(3);
138 this->setContextMenuPolicy(Qt::CustomContextMenu);
139 this->setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::EditKeyPressed);
141 QTreeWidgetItem* qtreewidgetitem2 = this->headerItem();
142 qtreewidgetitem2->setText(3,
"defaultValue (hidden in GUI)");
143 qtreewidgetitem2->setText(2,
"Type");
144 qtreewidgetitem2->setText(1,
"Value");
145 qtreewidgetitem2->setText(0,
"Key");
147 setColumnHidden(3,
true);
151 SkillDetailsTreeWidget::askUserToConfirmWidgetReset()
154 "The skill details widget will be reset. All changes will be lost, unless saved.";
156 msgBox.setText(QString::fromStdString(msg));
157 QCheckBox* ignoreCheckbox =
new QCheckBox(
"Do not ask again in this session.");
158 msgBox.setCheckBox(ignoreCheckbox);
159 QPushButton* copyParamsButton =
160 msgBox.addButton(tr(
"Copy Parameters && Close"), QMessageBox::ActionRole);
163 QPushButton* closeWithoutSavingButton =
164 msgBox.addButton(tr(
"Close"), QMessageBox::ActionRole);
166 msgBox.setDefaultButton(closeWithoutSavingButton);
167 QObject::connect(ignoreCheckbox,
168 &QCheckBox::stateChanged,
171 if (
static_cast<Qt::CheckState
>(state) == Qt::CheckState::Checked)
173 this->showWidgetResetConfirmation_ =
false;
177 connect(copyParamsButton,
178 &QPushButton::pressed,
187 SkillDetailsTreeWidget::checkIfParametersAreModified()
189 if (not shownSkill.has_value())
194 auto defaults = shownSkill->originalParameters;
196 if (this->aronTreeWidgetController.get() ==
nullptr)
201 auto params = this->aronTreeWidgetController->convertToAron();
203 if (defaults.get() ==
nullptr and params.get() ==
nullptr)
208 bool modified = not(*defaults == *params);
225 const int widthRemainder = this->width() - typeWidth;
228 const int dynamicColumnSize = widthRemainder / 2;
232 this->setColumnWidth(0, dynamicColumnSize);
234 this->setColumnWidth(1, dynamicColumnSize);
240 if (not shownSkill.has_value())
245 auto params =
memory->getLatestParametersForSkill(shownSkill->skillId);
247 if (not params.has_value())
252 ARMARX_INFO <<
"Reloaded parameters from the last execution";
253 aronTreeWidgetController->setFromAron(params.value());
259 auto executions =
memory->getExecutions();
260 if (executions.empty() || not shownSkill.has_value())
268 std::optional<armarx::skills::SkillStatusUpdate> found = std::nullopt;
269 for (
auto& execution : executions)
271 if (execution.first.skillId == shownSkill->skillId)
273 if (not found.has_value())
275 found = execution.second;
279 if (found->executionId.executionStartedTime <
280 execution.first.executionStartedTime)
283 found = execution.second;
289 if (not found.has_value())
292 ARMARX_INFO <<
"No execution for the skill " << shownSkill->skillId.toString()
293 <<
" has been found in the memory. The parametrization cannot be reloaded.";
296 auto params = found->parameters;
298 ARMARX_INFO <<
"Reloading parameters of skill " << found->executionId.skillId;
299 this->aronTreeWidgetController->setFromAron(params);
306 if (aronTreeWidgetController)
308 return aronTreeWidgetController->convertToAron();
323 QClipboard* clipboard = QApplication::clipboard();
324 clipboard->setText(QString::fromStdString(json.dump(2)));
330 if (not shownSkill.has_value())
339 placeholderDict->addElement(
"skill_args");
340 data = placeholderDict;
348 if (not skillID.has_value())
356 j[
"shortcuts"].push_back(
357 {{
"skill_id", skillID->toString()}, {
"skill_args", skillArgsJson}});
359 QClipboard* clipboard = QApplication::clipboard();
360 clipboard->setText(QString::fromStdString(j.dump(2)));
366 QClipboard* clipboard = QApplication::clipboard();
367 std::string s = clipboard->text().toStdString();
368 nlohmann::json json = nlohmann::json::parse(s);
372 if (!aronTreeWidgetController)
377 aronTreeWidgetController->setFromAron(
data);
387 if (!shownSkill.has_value())
407 if (checkIfParametersAreModified())
409 if (shownSkill.has_value())
412 <<
"A skill parametrization has been lost in the GUI. It can now be reloaded.";
413 memory->addParametersToHistory(shownSkill->skillId,
414 aronTreeWidgetController->convertToAron());
415 emit
updated(shownSkill->skillId);
419 this->shownSkill = std::nullopt;
420 aronTreeWidgetController =
nullptr;
static data::DictPtr ConvertFromNlohmannJSONObject(const nlohmann::json &, const armarx::aron::Path &p={})
static nlohmann::json ConvertToNlohmannJSON(const data::VariantPtr &)
bool isProviderSpecified() const
std::optional< ProviderID > providerId
bool isFullySpecified() const
MemoryCommunicatorBase(std::shared_ptr< SkillManagerWrapper > _memory)
std::shared_ptr< SkillManagerWrapper > memory
#define ARMARX_CHECK(expression)
Shortcut for ARMARX_CHECK_EXPRESSION.
#define ARMARX_INFO
The normal logging level.
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
std::shared_ptr< Dict > DictPtr
This file is part of ArmarX.
aron::data::DictPtr rootProfileDefaults
aron::type::ObjectPtr parametersType