YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
robotWidgetTree.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4 * SPDX-License-Identifier: LGPL-2.1-or-later
5 */
6
7#include "robotWidgetTree.h"
8#include "yarpmotorgui.h"
9#include "yarp/os/LogStream.h"
10
12 : CustomGroupBox(parent)
13{
14 connect(this, SIGNAL(sig_titleDoubleClick()), this, SLOT(onRobotTitleDoubleClick()));
15}
16
17void RobotWidgetTree::setIcons(const QIcon &okIcon, const QIcon &warningIcon)
18{
19 m_okIcon = okIcon;
20 m_warningIcon = warningIcon;
21}
22
23void RobotWidgetTree::addPart(const std::string &partName, int partIndex, PartItemTree *partTreeWidget)
24{
25 CustomGroupBox* newPart = new CustomGroupBox;
26 newPart->setTitle(partName.c_str());
27 newPart->addWidget(partTreeWidget);
28
29 this->addWidget(newPart);
30 m_indexToPartMap[partIndex].partWidget = partTreeWidget;
31 m_indexToPartMap[partIndex].partWidgetParent = newPart;
32
33 connect(newPart, &CustomGroupBox::sig_titleDoubleClick, this, [this, partIndex]{onPartTitleDoubleClick(partIndex);});
34}
35
36void RobotWidgetTree::updateRobotPart(int index, const QVector<JointItem::JointState> &modes)
37{
38 PartPointers& partPointers = m_indexToPartMap[index];
39 PartItemTree* partWidget = partPointers.partWidget;
40 CustomGroupBox* partWidgetParent = partPointers.partWidgetParent;
41
42
43 bool foundFaultPart = false;
44 for (int i = 0; i < partWidget->numberOfJoints(); i++){
45 auto* jointNode = partWidget->getJoint(i);
46 jointNode->setJointMode(modes.at(i));
47
48 if (modes.at(i) == JointItem::HwFault){
49 foundFaultPart = true;
50 }
51 }
52
53 if (!foundFaultPart){
54 partWidgetParent->removeTitleBackground();
55 partWidgetParent->setTitleIcon(m_okIcon);
56 } else {
57 partWidgetParent->setTitleBackgroundColor(hwFaultColor);
58 partWidgetParent->setTitleIcon(m_warningIcon);
59 }
60}
61
62void RobotWidgetTree::resizeEvent(QResizeEvent *event)
63{
64 QSize maxSize;
65 for (auto& part : m_indexToPartMap)
66 {
67 maxSize = maxSize.expandedTo(part.second.partWidget->getMaxElementSize());
68 }
69
70 for (auto& part : m_indexToPartMap)
71 {
72 part.second.partWidget->setDesiredElementSize(maxSize);
73 }
74
75 QWidget::resizeEvent(event);
76
77}
78
79void RobotWidgetTree::onRobotTitleDoubleClick()
80{
81 toggle(!visible());
82}
83
84void RobotWidgetTree::onPartTitleDoubleClick(int index)
85{
86 emit sig_partDoubleClicked(index);
87}
int SIGNAL(int pid, int signum)
void setTitleIcon(const QIcon &icon)
void sig_titleDoubleClick()
void toggle(bool visible)
void setTitleBackgroundColor(const QColor &backgroundColor)
bool visible() const
void addWidget(QWidget *widget)
void setTitle(const QString &string)
void removeTitleBackground()
void setJointMode(const JointItem::JointState &mode)
JointItemTree * getJoint(int index)
int numberOfJoints() const
void resizeEvent(QResizeEvent *event) override
void updateRobotPart(int index, const QVector< JointItem::JointState > &modes)
void sig_partDoubleClicked(int index)
RobotWidgetTree(QWidget *parent=nullptr)
void addPart(const std::string &partName, int partIndex, PartItemTree *partTreeWidget)
void setIcons(const QIcon &okIcon, const QIcon &warningIcon)
const QColor hwFaultColor