moveit2
The MoveIt Motion Planning Framework for ROS 2.
launches_widget.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2022, Metro Robots
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Metro Robots nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: David V. Lu!! */
38 
39 #include <QSplitter>
40 
41 namespace moveit_setup
42 {
43 namespace app
44 {
46 {
47  // Basic widget container
48  QVBoxLayout* layout = new QVBoxLayout();
49 
50  // Top Header Area ------------------------------------------------
51 
52  auto header = new HeaderWidget("Configure Desired Launch Files",
53  "Figure out which launch files you want to be generated.", this);
54  layout->addWidget(header);
55 
56  QSplitter* splitter = new QSplitter(Qt::Horizontal, this);
57  splitter->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
58 
59  list_widget_ = new QListWidget(this);
60  list_widget_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
61  list_widget_->setSelectionMode(QAbstractItemView::ExtendedSelection);
62  connect(list_widget_, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this,
63  SLOT(onNewSelectedItem(QListWidgetItem*, QListWidgetItem*)));
64 
65  splitter->addWidget(list_widget_);
66 
67  for (const LaunchBundle& lb : setup_step_.getAvailableLaunchBundles())
68  {
69  QListWidgetItem* item = new QListWidgetItem(QString(lb.getTitle().c_str()), list_widget_);
70  item->setData(Qt::UserRole, QVariant(lb.getID()));
71 
72  list_widget_->addItem(item);
73  }
74 
75  text_widget_ = new QLabel(this);
76  text_widget_->setFrameShape(QFrame::StyledPanel);
77  text_widget_->setFrameShadow(QFrame::Raised);
78  text_widget_->setLineWidth(1);
79  text_widget_->setMidLineWidth(0);
80  text_widget_->setWordWrap(true);
81  text_widget_->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
82  text_widget_->setMinimumWidth(100);
83  text_widget_->setAlignment(Qt::AlignTop);
84  splitter->addWidget(text_widget_);
85  layout->addWidget(splitter);
86 
87  // Finish Layout --------------------------------------------------
88  this->setLayout(layout);
89 }
90 
91 unsigned int getID(QListWidgetItem* item)
92 {
93  QVariant data = item->data(Qt::UserRole);
94  return data.toUInt();
95 }
96 
98 {
99  disconnect(list_widget_, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(changeCheckedState(QListWidgetItem*)));
100  for (int i = 0; i < list_widget_->count(); ++i)
101  {
102  QListWidgetItem* item = list_widget_->item(i);
103 
104  unsigned int id = getID(item);
105 
106  item->setCheckState(setup_step_.getState(id) ? Qt::Checked : Qt::Unchecked);
107  }
108  connect(list_widget_, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(changeCheckedState(QListWidgetItem*)));
109 }
110 
111 void LaunchesWidget::onNewSelectedItem(QListWidgetItem* current, QListWidgetItem* /*previous*/)
112 {
113  unsigned int id = getID(current);
114  text_widget_->setText(setup_step_.getDescription(id).c_str());
115 }
116 
117 void LaunchesWidget::changeCheckedState(QListWidgetItem* item)
118 {
119  unsigned int id = getID(item);
120  bool state = (item->checkState() == Qt::Checked);
121  setup_step_.setState(id, state);
122 }
123 
124 } // namespace app
125 } // namespace moveit_setup
126 
127 #include <pluginlib/class_list_macros.hpp> // NOLINT
PLUGINLIB_EXPORT_CLASS(cached_ik_kinematics_plugin::CachedIKKinematicsPlugin< kdl_kinematics_plugin::KDLKinematicsPlugin >, kinematics::KinematicsBase)
The GUI code for one SetupStep.
One launch file and any other bonus files that get bundled with it, i.e. the RViz launch file and its...
void focusGiven() override
Received when this widget is chosen from the navigation menu.
void setState(unsigned int id, bool state)
Sets whether the LaunchBundle with the given id is included (true) or not (false)
Definition: launches.cpp:95
bool getState(unsigned int id) const
Definition: launches.cpp:90
const std::vector< LaunchBundle > & getAvailableLaunchBundles() const
Get all available launch bundles.
Definition: launches.hpp:65
const std::string & getDescription(unsigned int id) const
Definition: launches.hpp:83
unsigned int getID(QListWidgetItem *item)