controller_edit_widget.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2018, Mohamad Ayman.
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  * * The name of Mohamad Ayman may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *********************************************************************/
33 
34 /* Author: Mohamad Ayman */
35 
36 #include <QComboBox>
37 #include <QFormLayout>
38 #include <QGroupBox>
39 #include <QHBoxLayout>
40 #include <QLabel>
41 #include <QLineEdit>
42 #include <QMessageBox>
43 #include <QPushButton>
44 #include <QString>
45 #include <QVBoxLayout>
46 #include "controller_edit_widget.h"
47 
48 namespace moveit_setup_assistant
49 {
50 // ******************************************************************************************
51 // ControllerEditWidget constructor, create controller edit screen GUI
52 // ******************************************************************************************
53 ControllerEditWidget::ControllerEditWidget(QWidget* parent, const MoveItConfigDataPtr& config_data)
54  : QWidget(parent), config_data_(config_data)
55 {
56  // Basic widget container
57  QVBoxLayout* layout = new QVBoxLayout();
58 
59  QGroupBox* controller_options_group = new QGroupBox("Controller Options");
60 
61  // Label ------------------------------------------------
62  title_ = new QLabel(this); // specify the title from the parent widget
63  QFont group_title_font(QFont().defaultFamily(), 12, QFont::Bold);
64  title_->setFont(group_title_font);
65  layout->addWidget(title_);
66 
67  QFormLayout* form_layout = new QFormLayout();
68  form_layout->setContentsMargins(0, 15, 0, 15);
69 
70  // Controller Name
71  controller_name_field_ = new QLineEdit(this);
72  controller_name_field_->setMaximumWidth(400);
73  form_layout->addRow("Controller Name:", controller_name_field_);
74 
75  // Controller Type
76  controller_type_field_ = new QComboBox(this);
77  controller_type_field_->setEditable(false);
78  controller_type_field_->setMaximumWidth(400);
79  form_layout->addRow("Controller Type:", controller_type_field_);
80 
81  controller_options_group->setLayout(form_layout);
82 
83  layout->addWidget(controller_options_group);
84 
85  layout->setAlignment(Qt::AlignTop);
86 
87  // New Controller Options ---------------------------------------------------------
88  new_buttons_widget_ = new QWidget();
89  QVBoxLayout* new_buttons_layout = new QVBoxLayout();
90 
91  QLabel* save_and_add = new QLabel("Next, Add Components To Controller:", this);
92  QFont save_and_add_font(QFont().defaultFamily(), 12, QFont::Bold);
93  save_and_add->setFont(save_and_add_font);
94  new_buttons_layout->addWidget(save_and_add);
95 
96  QLabel* add_subtitle = new QLabel("Recommended: ", this);
97  QFont add_subtitle_font(QFont().defaultFamily(), 10, QFont::Bold);
98  add_subtitle->setFont(add_subtitle_font);
99  new_buttons_layout->addWidget(add_subtitle);
100 
101  // Save and add groups
102  QPushButton* btn_save_groups_joints = new QPushButton("Add Planning Group Joints", this);
103  btn_save_groups_joints->setMaximumWidth(200);
104  connect(btn_save_groups_joints, SIGNAL(clicked()), this, SIGNAL(saveJointsGroups()));
105  new_buttons_layout->addWidget(btn_save_groups_joints);
106 
107  QLabel* add_subtitle2 = new QLabel("Advanced Options:", this);
108  add_subtitle2->setFont(add_subtitle_font);
109  new_buttons_layout->addWidget(add_subtitle2);
110 
111  // Save and add joints
112  QPushButton* btn_save_joints = new QPushButton("Add Individual Joints", this);
113  btn_save_joints->setMaximumWidth(200);
114  connect(btn_save_joints, SIGNAL(clicked()), this, SIGNAL(saveJoints()));
115  new_buttons_layout->addWidget(btn_save_joints);
116 
117  // Create widget and add to main layout
118  new_buttons_widget_->setLayout(new_buttons_layout);
119  layout->addWidget(new_buttons_widget_);
120 
121  // Vertical Spacer
122  layout->addItem(new QSpacerItem(20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding));
123 
124  // Bottom Controls ---------------------------------------------------------
125  QHBoxLayout* controls_layout = new QHBoxLayout();
126 
127  // Delete
128  btn_delete_ = new QPushButton("&Delete Controller", this);
129  btn_delete_->setMaximumWidth(200);
130  connect(btn_delete_, SIGNAL(clicked()), this, SIGNAL(deleteController()));
131  controls_layout->addWidget(btn_delete_);
132  controls_layout->setAlignment(btn_delete_, Qt::AlignRight);
133 
134  // Horizontal Spacer
135  controls_layout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum));
136 
137  // Save
138  btn_save_ = new QPushButton("&Save", this);
139  btn_save_->setMaximumWidth(200);
140  connect(btn_save_, SIGNAL(clicked()), this, SIGNAL(save()));
141  controls_layout->addWidget(btn_save_);
142  controls_layout->setAlignment(btn_save_, Qt::AlignRight);
143 
144  // Cancel
145  QPushButton* btn_cancel = new QPushButton("&Cancel", this);
146  btn_cancel->setMaximumWidth(200);
147  connect(btn_cancel, SIGNAL(clicked()), this, SIGNAL(cancelEditing()));
148  controls_layout->addWidget(btn_cancel);
149  controls_layout->setAlignment(btn_cancel, Qt::AlignRight);
150 
151  // Add layout
152  layout->addLayout(controls_layout);
153 
154  // Finish Layout --------------------------------------------------
155  this->setLayout(layout);
156 }
157 
158 // ******************************************************************************************
159 // Set the fields with previous values
160 // ******************************************************************************************
161 void ControllerEditWidget::setSelected(const std::string& controller_name)
162 {
163  controller_name_field_->setText(QString(controller_name.c_str()));
164  moveit_setup_assistant::ControllerConfig* searched_controller = config_data_->findControllerByName(controller_name);
165  if (searched_controller != nullptr)
166  {
167  const std::string controller_type = searched_controller->type_;
168  int type_index = controller_type_field_->findText(controller_type.c_str());
169 
170  // Set the controller type combo box
171  if (type_index == -1)
172  {
173  QMessageBox::warning(this, "Missing Controller Type", QString("Setting controller type to the default value"));
174  return;
175  }
176  else
177  {
178  controller_type_field_->setCurrentIndex(type_index);
179  }
180  }
181  else
182  {
183  controller_type_field_->setCurrentIndex(0);
184  }
185 }
186 
187 // ******************************************************************************************
188 // Populate the combo dropdown box with controllers types
189 // ******************************************************************************************
191 {
192  // Only load this combo box once
193  if (has_loaded_)
194  return;
195  has_loaded_ = true;
196 
197  const std::vector<std::string> default_types = { "effort_controllers/JointTrajectoryController",
198  "velocity_controllers/JointTrajectoryController",
199  "position_controllers/JointTrajectoryController",
200  "FollowJointTrajectory", "GripperCommand" };
201 
202  // Remove all old items
203  controller_type_field_->clear();
204 
205  // Loop through all controller default_types and add to combo box
206  for (const std::string& type : default_types)
207  controller_type_field_->addItem(type.c_str());
208 }
209 
211 {
212  btn_delete_->hide();
213 }
214 
216 {
217  btn_save_->hide();
218 }
219 
221 {
222  new_buttons_widget_->hide();
223 }
224 
226 {
227  btn_delete_->show();
228 }
229 
231 {
232  btn_save_->show();
233 }
234 
236 {
237  new_buttons_widget_->show();
238 }
239 
240 void ControllerEditWidget::setTitle(const QString& title)
241 {
242  title_->setText(title);
243 }
244 
246 {
247  return controller_name_field_->text().trimmed().toStdString();
248 }
249 
251 {
252  return controller_type_field_->currentText().toStdString();
253 }
254 
255 } // namespace moveit_setup_assistant
moveit_setup_assistant::ControllerEditWidget::title_
QLabel * title_
Definition: controller_edit_widget.h:127
moveit_setup_assistant::ControllerEditWidget::hideSave
void hideSave()
Hide save controller button.
Definition: controller_edit_widget.cpp:246
moveit_setup_assistant::ControllerEditWidget::btn_save_
QPushButton * btn_save_
Definition: controller_edit_widget.h:131
moveit_setup_assistant::ControllerEditWidget::hideDelete
void hideDelete()
Hide delete controller button.
Definition: controller_edit_widget.cpp:241
moveit_setup_assistant::ControllerEditWidget::ControllerEditWidget
ControllerEditWidget(QWidget *parent, const MoveItConfigDataPtr &config_data)
Constructor.
Definition: controller_edit_widget.cpp:84
moveit_setup_assistant::ControllerEditWidget::getControllerType
std::string getControllerType()
Get controller type.
Definition: controller_edit_widget.cpp:281
moveit_setup_assistant::ConfigurationFilesWidget::btn_save_
QPushButton * btn_save_
Definition: configuration_files_widget.h:92
moveit_setup_assistant::ControllerEditWidget::showNewButtonsWidget
void showNewButtonsWidget()
Show new buttons widget.
Definition: controller_edit_widget.cpp:266
moveit_setup_assistant::ControllerConfig::type_
std::string type_
Definition: moveit_config_data.h:118
moveit_setup_assistant::ControllerEditWidget::btn_delete_
QPushButton * btn_delete_
Definition: controller_edit_widget.h:130
moveit_setup_assistant::ControllerEditWidget::setTitle
void setTitle(const QString &title)
Set widget title.
Definition: controller_edit_widget.cpp:271
moveit_setup_assistant::ControllerEditWidget::showSave
void showSave()
Show save controller button.
Definition: controller_edit_widget.cpp:261
moveit_setup_assistant::ControllerEditWidget::setSelected
void setSelected(const std::string &controller_name)
Set the previous data.
Definition: controller_edit_widget.cpp:192
moveit_setup_assistant::ControllerEditWidget::controller_type_field_
QComboBox * controller_type_field_
Definition: controller_edit_widget.h:129
moveit_setup_assistant::ControllerEditWidget::hideNewButtonsWidget
void hideNewButtonsWidget()
Hide new buttons widget.
Definition: controller_edit_widget.cpp:251
moveit_setup_assistant::ControllerEditWidget::controller_name_field_
QLineEdit * controller_name_field_
Definition: controller_edit_widget.h:128
moveit_setup_assistant::ControllerEditWidget::new_buttons_widget_
QWidget * new_buttons_widget_
Definition: controller_edit_widget.h:132
moveit_setup_assistant
Definition: compute_default_collisions.h:46
controller_edit_widget.h
moveit_setup_assistant::ControllerEditWidget::loadControllersTypesComboBox
void loadControllersTypesComboBox()
Populate the combo dropdown box with controllers types.
Definition: controller_edit_widget.cpp:221
moveit_setup_assistant::ControllerEditWidget::getControllerName
std::string getControllerName()
Get controller name.
Definition: controller_edit_widget.cpp:276
moveit_setup_assistant::ControllerEditWidget::showDelete
void showDelete()
Show delete controller button.
Definition: controller_edit_widget.cpp:256
moveit_setup_assistant::ControllerConfig
Definition: moveit_config_data.h:115
moveit_setup_assistant::ControllerEditWidget::config_data_
moveit_setup_assistant::MoveItConfigDataPtr config_data_
Contains all the configuration data for the setup assistant.
Definition: controller_edit_widget.h:141
moveit_setup_assistant::ControllerEditWidget::has_loaded_
bool has_loaded_
Definition: controller_edit_widget.h:139


moveit_setup_assistant
Author(s): Dave Coleman
autogenerated on Sat May 3 2025 02:28:04