SkillDetailsGroupBox.cpp
Go to the documentation of this file.
1 #include "SkillDetailsGroupBox.h"
2 
3 namespace armarx::skills::gui
4 {
5  void
7  {
8  if (_skillId.skillName == SkillID::UNKNOWN)
9  return;
10 
11  auto const& skills = memory->getSkills();
12 
13  std::optional<skills::ProviderID> provider_opt;
14  // check skillId
15  if (_skillId.isProviderSpecified())
16  {
17  provider_opt = _skillId.providerId;
18  }
19  else
20  {
21  // find first provider to provide the skill
22  provider_opt = SkillManagerWrapper::findFirstProvider(skills, _skillId);
23  }
24 
25  if (provider_opt == std::nullopt)
26  {
27  // skill was not found in snapshot. Abort...
28  return;
29  }
30 
31  // construct skill id (with guaranteed valid provider)
32  skills::SkillID skillId = {provider_opt, _skillId.skillName};
33 
34 
35  // Maybe the search doesn't include the shown skill?
36  if (skills.count(skillId.providerId.value()) == 0 ||
37  skills.at(skillId.providerId.value()).count(skillId) == 0)
38  {
39  // reset details widget
40  skillDetailsTreeWidget->resetWidget();
41  return;
42  }
43 
44 
45  // get skill description
46  skills::SkillDescription descr = skills.at(skillId.providerId.value()).at(skillId);
47 
48  // ------------ update widgets ------------
49 
50  setDisabled(true);
51 
52  // setup groupBox
53  this->setTitle(QString::fromStdString(skillId.toString()));
54  setDisabled(false);
55 
56  // setup table view
57  skillDetailsTreeWidget->updateContents(skillId, descr);
58 
59  // description widget
60  skillDescriptionWidget->setSkillDescription(descr);
61 
62 
63  // add new profiles for this skill
64  // TODO: Where stored?
65  }
66 
67  void
68  SkillDetailGroupBox::connectGui(std::string observerName)
69  {
70  skillDetailsTreeWidget->setEditTriggers(QAbstractItemView::EditTrigger::NoEditTriggers);
71  }
72 
73  void
74  SkillDetailGroupBox::handleExecutionRequest()
75  {
76  auto data = skillDetailsTreeWidget->getConfigAsAron();
77  auto skillId = skillDetailsTreeWidget->getShownId();
78  if (skillId.has_value())
79  {
80  memory->startExecutionWithParams(skillId.value(), data);
81  }
82  }
83 
84  void
85  SkillDetailGroupBox::resizeEvent(QResizeEvent* event)
86  {
87  QGroupBox::resizeEvent(event);
88  skillDetailsTreeWidget->resizeContents();
89  }
90 
91  void
92  SkillDetailGroupBox::setupUi()
93  {
94  this->setTitle(QString::fromStdString(GROUP_BOX_TITLE));
95 
96  this->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
97 
98  // construct all sub widgets
99  this->executeSkillButton = new QPushButton();
100  this->profileMenuWidget = new ProfileMenuWidget(this->memory, this);
101  this->skillDetailsTreeWidget = new SkillDetailsTreeWidget(this->memory, this);
102  this->skillDescriptionWidget = new SkillDescriptionWidget(this);
103  this->layout = new QVBoxLayout();
104  this->splitter = new QSplitter();
105  splitter->setOrientation(Qt::Orientation::Vertical);
106 
107  // Layouting
108  this->setLayout(layout);
109 
110  layout->addWidget(this->profileMenuWidget);
111  layout->addWidget(splitter);
112  splitter->addWidget(this->skillDescriptionWidget);
113  splitter->addWidget(this->skillDetailsTreeWidget);
114  layout->addWidget(this->executeSkillButton);
115 
116  // Text
117  this->executeSkillButton->setText(
118  QString::fromStdString(SkillDetailGroupBox::EXECUTE_SKILL_BUTTON_TEXT));
119  {
120  QPixmap pix(QString::fromStdString(":icons/run.svg"));
121  QIcon icon(pix);
122  this->executeSkillButton->setIcon(icon);
123  }
124 
125 
126  connectSignals();
127  }
128 
129  void
130  SkillDetailGroupBox::connectSignals()
131  {
132  connect(executeSkillButton,
133  &QPushButton::clicked,
134  this,
135  &SkillDetailGroupBox::handleExecutionRequest);
136  connect(this,
138  skillDetailsTreeWidget,
140 
141  // profile buttons
142  connect(profileMenuWidget->copyArgsToClipboard,
143  &QPushButton::clicked,
144  skillDetailsTreeWidget,
146  connect(profileMenuWidget->setArgsFromClipboard,
147  &QPushButton::clicked,
148  skillDetailsTreeWidget,
150  connect(profileMenuWidget->resetArgsToProfile,
151  &QPushButton::clicked,
152  skillDetailsTreeWidget,
154  }
155 
156 
157 } // namespace armarx::skills::gui
armarx::skills::SkillID::toString
std::string toString() const
Definition: SkillID.cpp:64
skills
This file is part of ArmarX.
armarx::skills::gui::SkillDetailsTreeWidget::resetCurrentConfig
void resetCurrentConfig()
Definition: SkillDetailsTreeWidget.cpp:188
armarx::skills::gui::MemoryCommunicatorBase::memory
std::shared_ptr< SkillManagerWrapper > memory
Definition: MemoryCommunicatorBase.h:23
armarx::skills::SkillID::skillName
std::string skillName
Definition: SkillID.h:60
armarx::skills::SkillDescription
Definition: SkillDescription.h:18
armarx::skills::gui::SkillDetailGroupBox::connectGui
void connectGui(std::string observerName)
Definition: SkillDetailsGroupBox.cpp:68
armarx::skills::gui::ProfileMenuWidget::setArgsFromClipboard
QPushButton * setArgsFromClipboard
Definition: ProfileMenuWidget.h:24
armarx::skills::SkillID::providerId
std::optional< ProviderID > providerId
Definition: SkillID.h:59
armarx::skills::gui::SkillDetailsTreeWidget::resizeContents
void resizeContents()
Problem: columns 0 and 1 have arbitrary size; so we want to limit their size, to make sure everything...
Definition: SkillDetailsTreeWidget.cpp:130
armarx::skills::gui::ProfileMenuWidget::copyArgsToClipboard
QPushButton * copyArgsToClipboard
Definition: ProfileMenuWidget.h:25
armarx::memory
Brief description of class memory.
Definition: memory.h:39
armarx::skills::SkillID::UNKNOWN
static const constexpr char * UNKNOWN
Definition: SkillID.h:21
armarx::skills::gui::SkillManagerWrapper::findFirstProvider
static const std::optional< skills::ProviderID > findFirstProvider(SkillMap const &map, SkillID const &skillId)
Definition: SkillManagerWrapper.cpp:239
armarx::skills::SkillID::isProviderSpecified
bool isProviderSpecified() const
Definition: SkillID.h:41
armarx::skills::gui::SkillDetailsTreeWidget::updateContents
void updateContents(skills::SkillID const &skillId, skills::SkillDescription const &descr)
Definition: SkillDetailsTreeWidget.cpp:34
armarx::skills::gui::SkillDetailsTreeWidget::getShownId
std::optional< skills::SkillID > getShownId()
Definition: SkillDetailsTreeWidget.cpp:21
armarx::skills::gui::SkillDetailGroupBox::disconnectGui
void disconnectGui()
armarx::skills::gui::SkillDetailGroupBox::GROUP_BOX_TITLE
static const constexpr char * GROUP_BOX_TITLE
Definition: SkillDetailsGroupBox.h:24
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::skills::gui::SkillDetailsTreeWidget::copyCurrentConfig
void copyCurrentConfig()
Definition: SkillDetailsTreeWidget.cpp:157
SkillDetailsGroupBox.h
armarx::skills::gui
Definition: PeriodicUpdateWidget.cpp:11
armarx::skills::gui::SkillDetailsTreeWidget::getConfigAsAron
aron::data::DictPtr getConfigAsAron()
Definition: SkillDetailsTreeWidget.cpp:146
armarx::skills::gui::SkillDetailsTreeWidget::disconnectGui
void disconnectGui()
Definition: SkillDetailsTreeWidget.cpp:77
armarx::skills::gui::ProfileMenuWidget::resetArgsToProfile
QPushButton * resetArgsToProfile
Definition: ProfileMenuWidget.h:26
armarx::skills::gui::SkillDetailsTreeWidget::resetWidget
void resetWidget()
Definition: SkillDetailsTreeWidget.cpp:212
armarx::skills::gui::SkillDescriptionWidget::setSkillDescription
void setSkillDescription(const skills::SkillDescription &desc)
Definition: SkillDescriptionWidget.cpp:62
armarx::skills::gui::SkillDetailGroupBox::updateSkillDetails
void updateSkillDetails(skills::SkillID &skillId)
Notify subwidgets of an updated skill selection.
Definition: SkillDetailsGroupBox.cpp:6
armarx::skills::SkillID
Definition: SkillID.h:17
armarx::skills::gui::SkillDetailsTreeWidget::pasteCurrentConfig
void pasteCurrentConfig()
Definition: SkillDetailsTreeWidget.cpp:171
armarx::skills::gui::SkillDetailGroupBox::EXECUTE_SKILL_BUTTON_TEXT
static const constexpr char * EXECUTE_SKILL_BUTTON_TEXT
Definition: SkillDetailsGroupBox.h:23