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 <QVBoxLayout>
37 #include <QHBoxLayout>
38 #include <QMessageBox>
39 #include <QFormLayout>
40 #include <QString>
41 #include <QGroupBox>
42 #include "controller_edit_widget.h"
43 
45 {
46 // ******************************************************************************************
47 // ControllerEditWidget constructor, create controller edit screen GUI
48 // ******************************************************************************************
49 ControllerEditWidget::ControllerEditWidget(QWidget* parent, moveit_setup_assistant::MoveItConfigDataPtr config_data)
50  : QWidget(parent), config_data_(config_data)
51 {
52  // Basic widget container
53  QVBoxLayout* layout = new QVBoxLayout();
54 
55  QGroupBox* controller_options_group = new QGroupBox("Controller Options");
56 
57  // Label ------------------------------------------------
58  title_ = new QLabel(this); // specify the title from the parent widget
59  QFont group_title_font(QFont().defaultFamily(), 12, QFont::Bold);
60  title_->setFont(group_title_font);
61  layout->addWidget(title_);
62 
63  QFormLayout* form_layout = new QFormLayout();
64  form_layout->setContentsMargins(0, 15, 0, 15);
65 
66  // Controller Name
67  controller_name_field_ = new QLineEdit(this);
68  controller_name_field_->setMaximumWidth(400);
69  form_layout->addRow("Controller Name:", controller_name_field_);
70 
71  // Controller Type
72  controller_type_field_ = new QComboBox(this);
73  controller_type_field_->setEditable(false);
74  controller_type_field_->setMaximumWidth(400);
75  form_layout->addRow("Controller Type:", controller_type_field_);
76 
77  controller_options_group->setLayout(form_layout);
78 
79  layout->addWidget(controller_options_group);
80 
81  layout->setAlignment(Qt::AlignTop);
82 
83  // New Controller Options ---------------------------------------------------------
84  new_buttons_widget_ = new QWidget();
85  QVBoxLayout* new_buttons_layout = new QVBoxLayout();
86 
87  QLabel* save_and_add = new QLabel("Next, Add Components To Controller:", this);
88  QFont save_and_add_font(QFont().defaultFamily(), 12, QFont::Bold);
89  save_and_add->setFont(save_and_add_font);
90  new_buttons_layout->addWidget(save_and_add);
91 
92  QLabel* add_subtitle = new QLabel("Recommended: ", this);
93  QFont add_subtitle_font(QFont().defaultFamily(), 10, QFont::Bold);
94  add_subtitle->setFont(add_subtitle_font);
95  new_buttons_layout->addWidget(add_subtitle);
96 
97  // Save and add groups
98  QPushButton* btn_save_groups_joints = new QPushButton("Add Planning Group Joints", this);
99  btn_save_groups_joints->setMaximumWidth(200);
100  connect(btn_save_groups_joints, SIGNAL(clicked()), this, SIGNAL(saveJointsGroups()));
101  new_buttons_layout->addWidget(btn_save_groups_joints);
102 
103  QLabel* add_subtitle2 = new QLabel("Advanced Options:", this);
104  add_subtitle2->setFont(add_subtitle_font);
105  new_buttons_layout->addWidget(add_subtitle2);
106 
107  // Save and add joints
108  QPushButton* btn_save_joints = new QPushButton("Add Individual Joints", this);
109  btn_save_joints->setMaximumWidth(200);
110  connect(btn_save_joints, SIGNAL(clicked()), this, SIGNAL(saveJoints()));
111  new_buttons_layout->addWidget(btn_save_joints);
112 
113  // Create widget and add to main layout
114  new_buttons_widget_->setLayout(new_buttons_layout);
115  layout->addWidget(new_buttons_widget_);
116 
117  // Verticle Spacer -----------------------------------------------------
118  QWidget* vspacer = new QWidget(this);
119  vspacer->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
120  layout->addWidget(vspacer);
121 
122  // Bottom Controls ---------------------------------------------------------
123  QHBoxLayout* controls_layout = new QHBoxLayout();
124 
125  // Delete
126  btn_delete_ = new QPushButton("&Delete Controller", this);
127  btn_delete_->setMaximumWidth(200);
128  connect(btn_delete_, SIGNAL(clicked()), this, SIGNAL(deleteController()));
129  controls_layout->addWidget(btn_delete_);
130  controls_layout->setAlignment(btn_delete_, Qt::AlignRight);
131 
132  // Horizontal Spacer
133  QWidget* spacer = new QWidget(this);
134  spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
135  controls_layout->addWidget(spacer);
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::ROSControlConfig* searched_controller =
165  config_data_->findROSControllerByName(controller_name);
166  if (searched_controller != NULL)
167  {
168  const std::string controller_type = searched_controller->type_;
169  int type_index = controller_type_field_->findText(controller_type.c_str());
170 
171  // Set the controller type combo box
172  if (type_index == -1)
173  {
174  QMessageBox::warning(this, "Missing Controller Type", QString("Setting controller type to the default value"));
175  return;
176  }
177  else
178  {
179  controller_type_field_->setCurrentIndex(type_index);
180  }
181  }
182  else
183  {
184  controller_type_field_->setCurrentIndex(0);
185  }
186 }
187 
188 // ******************************************************************************************
189 // Populate the combo dropdown box with controllers types
190 // ******************************************************************************************
192 {
193  // Only load this combo box once
194  if (has_loaded_)
195  return;
196  has_loaded_ = true;
197 
198  const std::array<std::string, 8> default_types = {
199  "effort_controllers/JointTrajectoryController", "effort_controllers/JointPositionController",
200  "effort_controllers/JointVelocityController", "effort_controllers/JointEffortController",
201  "position_controllers/JointPositionController", "position_controllers/JointTrajectoryController",
202  "velocity_controllers/JointTrajectoryController", "velocity_controllers/JointVelocityController"
203  };
204 
205  // Remove all old items
206  controller_type_field_->clear();
207 
208  // Add FollowJointTrajectory option, the default
209  controller_type_field_->addItem("FollowJointTrajectory");
210 
211  // Loop through all controller default_types and add to combo box
212  for (const std::string& type : default_types)
213  controller_type_field_->addItem(type.c_str());
214 }
215 
217 {
218  btn_delete_->hide();
219 }
220 
222 {
223  btn_save_->hide();
224 }
225 
227 {
228  new_buttons_widget_->hide();
229 }
230 
232 {
233  btn_delete_->show();
234 }
235 
237 {
238  btn_save_->show();
239 }
240 
242 {
243  new_buttons_widget_->show();
244 }
245 
246 void ControllerEditWidget::setTitle(const QString& title)
247 {
248  title_->setText(title);
249 }
250 
252 {
253  return controller_name_field_->text().trimmed().toStdString();
254 }
255 
257 {
258  return controller_type_field_->currentText().toStdString();
259 }
260 
261 } // namespace
#define NULL
moveit_setup_assistant::MoveItConfigDataPtr config_data_
Contains all the configuration data for the setup assistant.
std::string getControllerName()
Get controller name.
void hideSave()
Hide save controller button.
void hideDelete()
Hide delete controller button.
void showSave()
Show save controller button.
void setSelected(const std::string &controller_name)
Set the previous data.
void cancelEditing()
Event sent when user presses cancel button.
void save()
Button event for just saving, when in edit mode.
void saveJointsGroups()
Button event for new groups, progressing to adding subgroups.
void showNewButtonsWidget()
Show new buttons widget.
void saveJoints()
Button event for new groups, progressing to adding joints.
void setTitle(const QString &title)
Set widget title.
void hideNewButtonsWidget()
Hide new buttons widget.
void deleteController()
Event sent when delete is being requested for controller.
std::string getControllerType()
Get controller type.
void showDelete()
Show delete controller button.
ControllerEditWidget(QWidget *parent, moveit_setup_assistant::MoveItConfigDataPtr config_data)
Constructor.
void loadControllersTypesComboBox()
Populate the combo dropdown box with controllers types.


moveit_setup_assistant
Author(s): Dave Coleman
autogenerated on Sun Oct 18 2020 13:19:28