moveit2
The MoveIt Motion Planning Framework for ROS 2.
default_collisions_widget.hpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2012, Willow Garage, Inc.
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 Willow Garage 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: Dave Coleman */
36 
37 #pragma once
38 
41 
42 #include <QThread>
43 #include <QAbstractItemModel>
44 #include <QAction>
45 #include <QButtonGroup>
46 #include <QCheckBox>
47 #include <QGroupBox>
48 #include <QHeaderView>
49 #include <QItemSelection>
50 #include <QItemSelectionModel>
51 #include <QLabel>
52 #include <QLineEdit>
53 #include <QProgressBar>
54 #include <QPushButton>
55 #include <QSlider>
56 #include <QSpinBox>
57 #include <QTableView>
58 #include <QVBoxLayout>
59 
60 namespace moveit_setup
61 {
62 namespace srdf_setup
63 {
64 class MonitorThread;
65 
70 {
71  Q_OBJECT
72 
73 public:
74  enum ViewMode
75  {
77  LINEAR_MODE = 1
78  };
79 
80  // ******************************************************************************************
81  // Public Functions
82  // ******************************************************************************************
83  void onInit() override;
84 
85  ~DefaultCollisionsWidget() override;
86 
87  SetupStep& getSetupStep() override
88  {
89  return setup_step_;
90  }
91 
92 private Q_SLOTS:
93 
94  // ******************************************************************************************
95  // Slot Event Functions
96  // ******************************************************************************************
97 
101  void startGeneratingCollisionTable();
105  void finishGeneratingCollisionTable();
106 
111  void changeDensityLabel(int value);
112 
116  void loadCollisionTable();
117 
121  void checkedFilterChanged();
122 
126  void collisionsChanged(const QModelIndex& index);
127 
131  void revertChanges();
132 
136  void previewSelectedMatrix(const QModelIndex& index);
137  void previewSelectedLinear(const QModelIndex& index);
138 
142  void focusGiven() override;
143 
147  bool focusLost() override;
148 
149  void showHeaderContextMenu(const QPoint& p);
150  void hideSections();
151  void hideOtherSections();
152  void showSections();
153 
154 private:
155  // ******************************************************************************************
156  // Qt Components
157  // ******************************************************************************************
158  QLabel* page_title_;
159  QTableView* collision_table_;
160  QAbstractItemModel* model_;
161  QItemSelectionModel* selection_model_;
162  QVBoxLayout* layout_;
163  QLabel* density_value_label_;
164  QSlider* density_slider_;
165  QPushButton* btn_generate_;
166  QGroupBox* controls_box_;
167  QProgressBar* progress_bar_;
168  QLabel* progress_label_;
169  QLineEdit* link_name_filter_;
170  QCheckBox* collision_checkbox_;
171  QLabel* fraction_label_;
172  QSpinBox* fraction_spinbox_;
173  QPushButton* btn_revert_;
174  QButtonGroup* view_mode_buttons_;
175 
176  QList<QAction*> header_actions_; // context actions for header sections
177  Qt::Orientations clicked_headers_; // remember which header section activated context actions
178  int clicked_section_; // remember which header section activated context actions
179 
180  // ******************************************************************************************
181  // Variables
182  // ******************************************************************************************
183  MonitorThread* worker_;
184 
185  DefaultCollisions setup_step_;
186 
187  // ******************************************************************************************
188  // Private Functions
189  // ******************************************************************************************
190 
195  void disableControls(bool disable);
196 
200  bool eventFilter(QObject* object, QEvent* event) override;
201 
205  void showSections(QHeaderView* header, const QList<int>& logicalIndexes);
209  void toggleSelection(QItemSelection selection);
210 };
211 
215 class MonitorThread : public QThread
216 {
217  Q_OBJECT
218 
219 public:
220  MonitorThread(DefaultCollisions& setup_step, QProgressBar* progress_bar = nullptr);
221  void run() override;
222  void cancel()
223  {
224  canceled_ = true;
225  }
226  bool canceled() const
227  {
228  return canceled_;
229  }
230 
231 Q_SIGNALS:
232  void progress(int /*_t1*/);
233 
234 private:
235  DefaultCollisions& setup_step_;
236  bool canceled_;
237 };
238 } // namespace srdf_setup
239 } // namespace moveit_setup
The GUI code for one SetupStep.
Contains all of the non-GUI code necessary for doing one "screen" worth of setup.
Definition: setup_step.hpp:47
User interface for editing the default collision matrix list in an SRDF.
SetupStep & getSetupStep() override
Return a reference to the SetupStep object.
QThread to monitor progress of the setup step.
MonitorThread(DefaultCollisions &setup_step, QProgressBar *progress_bar=nullptr)