41 #include <QApplication>
42 #include <QFormLayout>
43 #include <QHBoxLayout>
44 #include <QMessageBox>
46 #include <QVBoxLayout>
55 QVBoxLayout* layout =
new QVBoxLayout();
60 "Create a virtual joint between the base robot link and an external frame of "
61 "reference. This allows to place the robot in the world or on a mobile platform.",
63 layout->addWidget(header);
77 this->setLayout(layout);
83 QWidget* VirtualJointsWidget::createContentsWidget()
86 QWidget* content_widget =
new QWidget(
this);
89 QVBoxLayout* layout =
new QVBoxLayout(
this);
96 data_table_->setSelectionBehavior(QAbstractItemView::SelectRows);
97 connect(
data_table_, SIGNAL(cellDoubleClicked(
int,
int)),
this, SLOT(editDoubleClicked(
int,
int)));
98 connect(
data_table_, SIGNAL(cellClicked(
int,
int)),
this, SLOT(previewClicked(
int,
int)));
102 QStringList header_list;
103 header_list.append(
"Virtual Joint Name");
104 header_list.append(
"Child Link");
105 header_list.append(
"Parent Frame");
106 header_list.append(
"Type");
107 data_table_->setHorizontalHeaderLabels(header_list);
111 QHBoxLayout* controls_layout =
new QHBoxLayout();
114 controls_layout->addItem(
new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum));
117 btn_edit_ =
new QPushButton(
"&Edit Selected",
this);
118 btn_edit_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
121 connect(
btn_edit_, SIGNAL(clicked()),
this, SLOT(editSelected()));
123 controls_layout->setAlignment(
btn_edit_, Qt::AlignRight);
126 btn_delete_ =
new QPushButton(
"&Delete Selected",
this);
127 connect(
btn_delete_, SIGNAL(clicked()),
this, SLOT(deleteSelected()));
129 controls_layout->setAlignment(
btn_delete_, Qt::AlignRight);
132 QPushButton* btn_add =
new QPushButton(
"&Add Virtual Joint",
this);
133 btn_add->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
134 btn_add->setMaximumWidth(300);
135 connect(btn_add, SIGNAL(clicked()),
this, SLOT(showNewScreen()));
136 controls_layout->addWidget(btn_add);
137 controls_layout->setAlignment(btn_add, Qt::AlignRight);
140 layout->addLayout(controls_layout);
143 content_widget->setLayout(layout);
145 return content_widget;
151 QWidget* VirtualJointsWidget::createEditWidget()
154 QWidget* edit_widget =
new QWidget(
this);
156 QVBoxLayout* layout =
new QVBoxLayout();
159 QFormLayout* form_layout =
new QFormLayout();
161 form_layout->setRowWrapPolicy(QFormLayout::WrapAllRows);
179 loadJointTypesComboBox();
184 layout->addLayout(form_layout);
188 QHBoxLayout* controls_layout =
new QHBoxLayout();
189 controls_layout->setContentsMargins(0, 25, 0, 15);
192 controls_layout->addItem(
new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum));
195 QPushButton* btn_save =
new QPushButton(
"&Save",
this);
196 btn_save->setMaximumWidth(200);
197 connect(btn_save, SIGNAL(clicked()),
this, SLOT(doneEditing()));
198 controls_layout->addWidget(btn_save);
199 controls_layout->setAlignment(btn_save, Qt::AlignRight);
202 QPushButton* btn_cancel =
new QPushButton(
"&Cancel",
this);
203 btn_cancel->setMaximumWidth(200);
204 connect(btn_cancel, SIGNAL(clicked()),
this, SLOT(cancelEditing()));
205 controls_layout->addWidget(btn_cancel);
206 controls_layout->setAlignment(btn_cancel, Qt::AlignRight);
209 layout->addLayout(controls_layout);
212 edit_widget->setLayout(layout);
220 void VirtualJointsWidget::showNewScreen()
223 current_edit_vjoint_.clear();
241 void VirtualJointsWidget::editDoubleClicked(
int ,
int )
249 void VirtualJointsWidget::previewClicked(
int ,
int )
256 void VirtualJointsWidget::editSelected()
259 QList<QTableWidgetItem*> selected =
data_table_->selectedItems();
262 if (selected.empty())
266 edit(selected[0]->
text().toStdString());
272 void VirtualJointsWidget::edit(
const std::string&
name)
275 current_edit_vjoint_ =
name;
281 if (vjoint ==
nullptr)
283 QMessageBox::critical(
this,
"Error Saving",
"An internal error has occurred while saving. Quitting.");
284 QApplication::quit();
295 QMessageBox::critical(
this,
"Error Loading",
"Unable to find child link in drop down box");
304 QMessageBox::critical(
this,
"Error Loading",
"Unable to find joint type in drop down box");
319 void VirtualJointsWidget::loadJointTypesComboBox()
333 void VirtualJointsWidget::loadChildLinksComboBox()
348 void VirtualJointsWidget::deleteSelected()
351 QList<QTableWidgetItem*> selected =
data_table_->selectedItems();
354 if (selected.empty())
358 current_edit_vjoint_ = selected[0]->text().toStdString();
361 if (QMessageBox::question(
this,
"Confirm Virtual Joint Deletion",
362 QString(
"Are you sure you want to delete the virtual joint '")
363 .
append(current_edit_vjoint_.c_str())
365 QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Cancel)
381 void VirtualJointsWidget::doneEditing()
386 const std::string child_link =
child_link_field_->currentText().trimmed().toStdString();
387 const std::string joint_type =
joint_type_field_->currentText().trimmed().toStdString();
390 if (vjoint_name.empty())
392 QMessageBox::warning(
this,
"Error Saving",
"A name must be given for the virtual joint!");
397 if (parent_name.empty())
399 QMessageBox::warning(
this,
"Error Saving",
"A name must be given for the parent frame");
404 if (joint_type.empty())
406 QMessageBox::warning(
this,
"Error Saving",
"A joint type must be chosen!");
411 if (child_link.empty())
413 QMessageBox::warning(
this,
"Error Saving",
"A child link must be chosen!");
419 srdf::Model::VirtualJoint* vj =
setup_step_.
get(vjoint_name, current_edit_vjoint_);
422 catch (
const std::runtime_error& e)
424 QMessageBox::warning(
this,
"Error Saving", e.what());
445 void VirtualJointsWidget::cancelEditing()
457 void VirtualJointsWidget::loadDataTable()
471 for (
const auto& virtual_joint : virtual_joints)
474 QTableWidgetItem* data_name =
new QTableWidgetItem(virtual_joint.name_.c_str());
475 data_name->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
476 QTableWidgetItem* child_link_name =
new QTableWidgetItem(virtual_joint.child_link_.c_str());
477 child_link_name->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
478 QTableWidgetItem* parent_frame_name =
new QTableWidgetItem(virtual_joint.parent_frame_.c_str());
479 parent_frame_name->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
480 QTableWidgetItem* type_name =
new QTableWidgetItem(virtual_joint.type_.c_str());
481 type_name->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
504 if (!virtual_joints.empty())
520 loadChildLinksComboBox();
526 #include <pluginlib/class_list_macros.hpp>
PLUGINLIB_EXPORT_CLASS(cached_ik_kinematics_plugin::CachedIKKinematicsPlugin< kdl_kinematics_plugin::KDLKinematicsPlugin >, kinematics::KinematicsBase)
T * find(const std::string &name)
Return a pointer to an item with the given name if it exists, otherwise null.
T * get(const std::string &name, const std::string &old_name="")
Get a pointer to an item with the given name, creating if necessary. If old_name is provided (and is ...
bool remove(const std::string &name)
Delete an item with the given name from the list.
void setProperties(srdf::Model::VirtualJoint *vj, const std::string &parent_name, const std::string &child_name, const std::string &joint_type)
std::vector< std::string > getLinkNames() const
std::vector< srdf::Model::VirtualJoint > & getContainer() override
Returns the reference to the vector in the SRDF.
std::string append(const std::string &left, const std::string &right)