43 #include <QApplication>
45 #include <QCloseEvent>
47 #include <QHBoxLayout>
49 #include <QMessageBox>
50 #include <QPushButton>
52 #include <QStackedWidget>
70 rviz_manager_ =
nullptr;
71 rviz_render_panel_ =
nullptr;
74 config_data_ = std::make_shared<MoveItConfigData>();
77 if (
args.count(
"debug"))
78 config_data_->debug_ =
true;
81 std::string moveit_ros_visualization_package_path =
ros::package::getPath(
"moveit_ros_visualization");
82 moveit_ros_visualization_package_path +=
"/icons/classes/MotionPlanning.png";
83 this->setWindowIcon(QIcon(moveit_ros_visualization_package_path.c_str()));
86 QHBoxLayout* layout =
new QHBoxLayout();
87 layout->setAlignment(Qt::AlignTop);
90 main_content_ =
new QStackedWidget();
96 start_screen_widget_ =
new StartScreenWidget(
this, config_data_);
97 start_screen_widget_->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
98 connect(start_screen_widget_, SIGNAL(readyToProgress()),
this, SLOT(progressPastStartScreen()));
99 connect(start_screen_widget_, SIGNAL(loadRviz()),
this, SLOT(loadRviz()));
100 main_content_->addWidget(start_screen_widget_);
103 if (
args.count(
"urdf_path"))
105 start_screen_widget_->urdf_file_->setPath(
args[
"urdf_path"].as<std::string>());
106 start_screen_widget_->select_mode_->btn_new_->click();
108 if (
args.count(
"config_pkg"))
110 start_screen_widget_->stack_path_->setPath(
args[
"config_pkg"].as<std::string>());
111 start_screen_widget_->select_mode_->btn_exist_->click();
115 start_screen_widget_->stack_path_->setPath(QString(getenv(
"PWD")));
119 nav_name_list_ <<
"Start";
120 nav_name_list_ <<
"Self-Collisions";
121 nav_name_list_ <<
"Virtual Joints";
122 nav_name_list_ <<
"Planning Groups";
123 nav_name_list_ <<
"Robot Poses";
124 nav_name_list_ <<
"End Effectors";
125 nav_name_list_ <<
"Passive Joints";
126 nav_name_list_ <<
"Controllers";
127 nav_name_list_ <<
"Simulation";
128 nav_name_list_ <<
"3D Perception";
129 nav_name_list_ <<
"Author Information";
130 nav_name_list_ <<
"Configuration Files";
133 navs_view_ =
new NavigationWidget(
this);
134 navs_view_->setNavs(nav_name_list_);
135 navs_view_->setDisabled(
true);
136 navs_view_->setSelected(0);
139 rviz_container_ =
new QWidget(
this);
140 rviz_container_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
141 rviz_container_->hide();
144 splitter_ =
new QSplitter(Qt::Horizontal,
this);
145 splitter_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
146 splitter_->addWidget(navs_view_);
147 splitter_->addWidget(main_content_);
148 splitter_->addWidget(rviz_container_);
149 splitter_->setHandleWidth(6);
151 layout->addWidget(splitter_);
154 connect(navs_view_, SIGNAL(clicked(
const QModelIndex&)),
this, SLOT(navigationClicked(
const QModelIndex&)));
157 this->setLayout(layout);
160 this->setWindowTitle(
"MoveIt Setup Assistant");
163 QApplication::processEvents();
169 SetupAssistantWidget::~SetupAssistantWidget()
171 if (rviz_manager_ !=
nullptr)
172 rviz_manager_->removeAllDisplays();
173 if (rviz_render_panel_ !=
nullptr)
174 delete rviz_render_panel_;
175 if (rviz_manager_ !=
nullptr)
176 delete rviz_manager_;
179 void SetupAssistantWidget::virtualJointReferenceFrameChanged()
181 if (rviz_manager_ && robot_state_display_)
183 rviz_manager_->setFixedFrame(QString::fromStdString(config_data_->getRobotModel()->getModelFrame()));
184 robot_state_display_->reset();
185 robot_state_display_->setVisible(
true);
192 void SetupAssistantWidget::navigationClicked(
const QModelIndex& index)
195 moveToScreen(
index.row());
201 void SetupAssistantWidget::moveToScreen(
const int index)
203 boost::mutex::scoped_lock slock(change_screen_lock_);
205 if (current_index_ !=
index)
208 SetupScreenWidget* ssw = qobject_cast<SetupScreenWidget*>(main_content_->widget(current_index_));
211 navs_view_->setSelected(current_index_);
215 current_index_ =
index;
221 main_content_->setCurrentIndex(index);
224 ssw = qobject_cast<SetupScreenWidget*>(main_content_->widget(index));
228 navs_view_->setSelected(index);
235 void SetupAssistantWidget::progressPastStartScreen()
241 main_content_->addWidget(default_collisions_widget_);
242 connect(default_collisions_widget_, SIGNAL(highlightLink(
const std::string&,
const QColor&)),
this,
243 SLOT(highlightLink(
const std::string&,
const QColor&)));
244 connect(default_collisions_widget_, SIGNAL(highlightGroup(
const std::string&)),
this,
245 SLOT(highlightGroup(
const std::string&)));
246 connect(default_collisions_widget_, SIGNAL(unhighlightAll()),
this, SLOT(unhighlightAll()));
250 main_content_->addWidget(virtual_joints_widget_);
251 connect(virtual_joints_widget_, SIGNAL(isModal(
bool)),
this, SLOT(setModalMode(
bool)));
252 connect(virtual_joints_widget_, SIGNAL(highlightLink(
const std::string&,
const QColor&)),
this,
253 SLOT(highlightLink(
const std::string&,
const QColor&)));
254 connect(virtual_joints_widget_, SIGNAL(highlightGroup(
const std::string&)),
this,
255 SLOT(highlightGroup(
const std::string&)));
256 connect(virtual_joints_widget_, SIGNAL(unhighlightAll()),
this, SLOT(unhighlightAll()));
257 connect(virtual_joints_widget_, SIGNAL(referenceFrameChanged()),
this, SLOT(virtualJointReferenceFrameChanged()));
261 main_content_->addWidget(planning_groups_widget);
262 connect(planning_groups_widget, SIGNAL(isModal(
bool)),
this, SLOT(setModalMode(
bool)));
263 connect(planning_groups_widget, SIGNAL(highlightLink(
const std::string&,
const QColor&)),
this,
264 SLOT(highlightLink(
const std::string&,
const QColor&)));
265 connect(planning_groups_widget, SIGNAL(highlightGroup(
const std::string&)),
this,
266 SLOT(highlightGroup(
const std::string&)));
267 connect(planning_groups_widget, SIGNAL(unhighlightAll()),
this, SLOT(unhighlightAll()));
271 main_content_->addWidget(robot_poses_widget_);
272 connect(robot_poses_widget_, SIGNAL(isModal(
bool)),
this, SLOT(setModalMode(
bool)));
273 connect(robot_poses_widget_, SIGNAL(highlightLink(
const std::string&,
const QColor&)),
this,
274 SLOT(highlightLink(
const std::string&,
const QColor&)));
275 connect(robot_poses_widget_, SIGNAL(highlightGroup(
const std::string&)),
this,
276 SLOT(highlightGroup(
const std::string&)));
277 connect(robot_poses_widget_, SIGNAL(unhighlightAll()),
this, SLOT(unhighlightAll()));
281 main_content_->addWidget(end_effectors_widget_);
282 connect(end_effectors_widget_, SIGNAL(isModal(
bool)),
this, SLOT(setModalMode(
bool)));
283 connect(end_effectors_widget_, SIGNAL(highlightLink(
const std::string&,
const QColor&)),
this,
284 SLOT(highlightLink(
const std::string&,
const QColor&)));
285 connect(end_effectors_widget_, SIGNAL(highlightGroup(
const std::string&)),
this,
286 SLOT(highlightGroup(
const std::string&)));
287 connect(end_effectors_widget_, SIGNAL(unhighlightAll()),
this, SLOT(unhighlightAll()));
291 main_content_->addWidget(passive_joints_widget_);
292 connect(passive_joints_widget_, SIGNAL(isModal(
bool)),
this, SLOT(setModalMode(
bool)));
293 connect(passive_joints_widget_, SIGNAL(highlightLink(
const std::string&,
const QColor&)),
this,
294 SLOT(highlightLink(
const std::string&,
const QColor&)));
295 connect(passive_joints_widget_, SIGNAL(highlightGroup(
const std::string&)),
this,
296 SLOT(highlightGroup(
const std::string&)));
297 connect(passive_joints_widget_, SIGNAL(unhighlightAll()),
this, SLOT(unhighlightAll()));
301 main_content_->addWidget(controllers_widget_);
302 connect(controllers_widget_, SIGNAL(isModal(
bool)),
this, SLOT(setModalMode(
bool)));
303 connect(controllers_widget_, SIGNAL(highlightLink(
const std::string&,
const QColor&)),
this,
304 SLOT(highlightLink(
const std::string&,
const QColor&)));
305 connect(controllers_widget_, SIGNAL(highlightGroup(
const std::string&)),
this,
306 SLOT(highlightGroup(
const std::string&)));
307 connect(controllers_widget_, SIGNAL(unhighlightAll()),
this, SLOT(unhighlightAll()));
311 main_content_->addWidget(simulation_widget_);
312 connect(simulation_widget_, SIGNAL(isModal(
bool)),
this, SLOT(setModalMode(
bool)));
313 connect(simulation_widget_, SIGNAL(highlightLink(
const std::string&,
const QColor&)),
this,
314 SLOT(highlightLink(
const std::string&,
const QColor&)));
315 connect(simulation_widget_, SIGNAL(highlightGroup(
const std::string&)),
this,
316 SLOT(highlightGroup(
const std::string&)));
317 connect(simulation_widget_, SIGNAL(unhighlightAll()),
this, SLOT(unhighlightAll()));
321 main_content_->addWidget(perception_widget_);
322 connect(perception_widget_, SIGNAL(isModal(
bool)),
this, SLOT(setModalMode(
bool)));
323 connect(perception_widget_, SIGNAL(highlightLink(
const std::string&,
const QColor&)),
this,
324 SLOT(highlightLink(
const std::string&,
const QColor&)));
325 connect(perception_widget_, SIGNAL(highlightGroup(
const std::string&)),
this,
326 SLOT(highlightGroup(
const std::string&)));
327 connect(perception_widget_, SIGNAL(unhighlightAll()),
this, SLOT(unhighlightAll()));
331 main_content_->addWidget(author_information_widget_);
332 connect(author_information_widget_, SIGNAL(isModal(
bool)),
this, SLOT(setModalMode(
bool)));
333 connect(author_information_widget_, SIGNAL(highlightLink(
const std::string&,
const QColor&)),
this,
334 SLOT(highlightLink(
const std::string&,
const QColor&)));
335 connect(author_information_widget_, SIGNAL(highlightGroup(
const std::string&)),
this,
336 SLOT(highlightGroup(
const std::string&)));
337 connect(author_information_widget_, SIGNAL(unhighlightAll()),
this, SLOT(unhighlightAll()));
341 main_content_->addWidget(configuration_files_widget_);
344 for (
int i = 0; i < nav_name_list_.count(); ++i)
346 navs_view_->setEnabled(i,
true);
350 navs_view_->setDisabled(
false);
353 rviz_container_->show();
356 if (config_data_->debug_)
365 void SetupAssistantWidget::updateTimer()
373 void SetupAssistantWidget::loadRviz()
377 rviz_render_panel_->setMinimumWidth(200);
378 rviz_render_panel_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
381 rviz_render_panel_->initialize(rviz_manager_->getSceneManager(), rviz_manager_);
382 rviz_manager_->initialize();
383 rviz_manager_->startUpdate();
386 rviz_manager_->setFixedFrame(QString::fromStdString(config_data_->getRobotModel()->getModelFrame()));
390 robot_state_display_->setName(
"Robot State");
392 rviz_manager_->addDisplay(robot_state_display_,
true);
395 robot_state_display_->subProp(
"Robot State Topic")->setValue(QString::fromStdString(
MOVEIT_ROBOT_STATE));
398 robot_state_display_->subProp(
"Robot Description")->setValue(QString::fromStdString(
ROBOT_DESCRIPTION));
399 robot_state_display_->setVisible(
true);
406 QVBoxLayout* rviz_layout =
new QVBoxLayout();
407 rviz_layout->addWidget(rviz_render_panel_);
408 rviz_container_->setLayout(rviz_layout);
411 auto btn_layout =
new QHBoxLayout();
412 rviz_layout->addLayout(btn_layout);
415 btn_layout->addWidget(btn =
new QCheckBox(
"visual"), 0);
416 btn->setChecked(
true);
417 connect(btn, &QCheckBox::toggled,
418 [
this](
bool checked) { robot_state_display_->subProp(
"Visual Enabled")->setValue(checked); });
420 btn_layout->addWidget(btn =
new QCheckBox(
"collision"), 1);
421 btn->setChecked(
false);
422 connect(btn, &QCheckBox::toggled,
423 [
this](
bool checked) { robot_state_display_->subProp(
"Collision Enabled")->setValue(checked); });
425 rviz_container_->show();
431 void SetupAssistantWidget::highlightLink(
const std::string& link_name,
const QColor& color)
435 robot_state_display_->setLinkColor(link_name, color);
441 void SetupAssistantWidget::highlightGroup(
const std::string& group_name)
444 if (!config_data_->getRobotModel()->hasJointModelGroup(group_name))
448 config_data_->getRobotModel()->getJointModelGroup(group_name);
449 if (joint_model_group)
453 highlightLink(lm->
getName(), QColor(255, 0, 0));
460 void SetupAssistantWidget::unhighlightAll()
463 const std::vector<std::string>& links = config_data_->getRobotModel()->getLinkModelNamesWithCollisionGeometry();
472 if (!rviz_manager_ || !robot_state_display_)
478 for (
const std::string& link : links)
483 robot_state_display_->unsetLinkColor(link);
490 void SetupAssistantWidget::closeEvent(QCloseEvent* event)
493 if (!config_data_->debug_)
495 if (QMessageBox::question(
this,
"Exit Setup Assistant",
496 QString(
"Are you sure you want to exit the MoveIt Setup Assistant?"),
497 QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Cancel)
511 bool SetupAssistantWidget::notify(QObject* , QEvent* )
513 QMessageBox::critical(
this,
"Error",
"An error occurred and was caught by Qt notify event handler.", QMessageBox::Ok);
521 void SetupAssistantWidget::setModalMode(
bool isModal)
523 navs_view_->setDisabled(isModal);
525 for (
int i = 0; i < nav_name_list_.count(); ++i)
527 navs_view_->setEnabled(i, !isModal);