41 #include <QApplication>
42 #include <QCloseEvent>
43 #include <QHBoxLayout>
44 #include <QMessageBox>
45 #include <QPushButton>
47 #include <QStackedWidget>
49 #include <pluginlib/class_loader.hpp>
59 QWidget* parent,
const boost::program_options::variables_map&
args)
61 , node_abstraction_(node)
62 , node_(node_abstraction_.lock()->get_raw_node())
63 , widget_loader_(
"moveit_setup_framework",
"moveit_setup::SetupStepWidget")
66 config_data_ = std::make_shared<DataWarehouse>(node_);
69 if (
args.count(
"debug"))
70 config_data_->debug =
true;
73 auto icon_path =
getSharePath(
"moveit_ros_visualization") /
"icons/classes/MotionPlanning.png";
74 this->setWindowIcon(QIcon(icon_path.c_str()));
77 QHBoxLayout* layout =
new QHBoxLayout();
78 layout->setAlignment(Qt::AlignTop);
81 main_content_ =
new QStackedWidget();
85 std::vector<std::string> setup_steps;
88 setup_steps.push_back(
"moveit_setup::core::StartScreenWidget");
89 setup_steps.push_back(
"moveit_setup::srdf_setup::DefaultCollisionsWidget");
90 setup_steps.push_back(
"moveit_setup::srdf_setup::VirtualJointsWidget");
91 setup_steps.push_back(
"moveit_setup::srdf_setup::PlanningGroupsWidget");
92 setup_steps.push_back(
"moveit_setup::srdf_setup::RobotPosesWidget");
93 setup_steps.push_back(
"moveit_setup::srdf_setup::EndEffectorsWidget");
94 setup_steps.push_back(
"moveit_setup::srdf_setup::PassiveJointsWidget");
95 setup_steps.push_back(
"moveit_setup::controllers::UrdfModificationsWidget");
96 setup_steps.push_back(
"moveit_setup::controllers::ROS2ControllersWidget");
97 setup_steps.push_back(
"moveit_setup::controllers::MoveItControllersWidget");
99 setup_steps.push_back(
"moveit_setup::app::PerceptionWidget");
100 setup_steps.push_back(
"moveit_setup::app::LaunchesWidget");
101 setup_steps.push_back(
"moveit_setup::core::AuthorInformationWidget");
102 setup_steps.push_back(
"moveit_setup::core::ConfigurationFilesWidget");
103 node_->declare_parameter(
"setup_steps", setup_steps);
104 setup_steps = node_->get_parameter(
"setup_steps").as_string_array();
107 rviz_panel_ =
new RVizPanel(
this, node_abstraction_, config_data_);
108 rviz_panel_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
111 for (
const std::string& step_class : setup_steps)
113 auto widget = widget_loader_.createSharedInstance(step_class);
114 widget->initialize(node_,
this, rviz_panel_, config_data_);
116 connect(widget.get(), SIGNAL(dataUpdated()),
this, SLOT(onDataUpdate()));
117 connect(widget.get(), SIGNAL(advanceRequest()),
this, SLOT(onAdvanceRequest()));
118 connect(widget.get(), SIGNAL(setModalMode(
bool)),
this, SLOT(onModalModeUpdate(
bool)));
119 const std::string
name = widget->getSetupStep().getName();
120 steps_.push_back(widget);
122 main_content_->addWidget(widget.get());
124 nav_name_list_ <<
name.c_str();
128 if (
args.count(
"urdf_path"))
130 config_data_->preloadWithURDFPath(
args[
"urdf_path"].as<std::filesystem::path>());
132 if (
args.count(
"config_pkg"))
134 config_data_->preloadWithFullConfig(
args[
"config_pkg"].as<std::string>());
139 navs_view_->
setNavs(nav_name_list_);
147 splitter_ =
new QSplitter(Qt::Horizontal,
this);
148 splitter_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
149 splitter_->addWidget(navs_view_);
150 splitter_->addWidget(main_content_);
151 splitter_->addWidget(rviz_panel_);
152 splitter_->setHandleWidth(6);
154 layout->addWidget(splitter_);
157 connect(navs_view_, SIGNAL(clicked(
const QModelIndex&)),
this, SLOT(navigationClicked(
const QModelIndex&)));
160 this->setLayout(layout);
163 this->setWindowTitle(
"MoveIt Setup Assistant");
166 QApplication::processEvents();
172 void SetupAssistantWidget::navigationClicked(
const QModelIndex& index)
178 void SetupAssistantWidget::onDataUpdate()
180 for (
size_t index = 0; index < steps_.size(); index++)
182 bool ready = steps_[index]->isReady();
194 void SetupAssistantWidget::onAdvanceRequest()
196 if (
static_cast<unsigned int>(current_index_ + 1) < steps_.size())
207 std::scoped_lock slock(change_screen_lock_);
213 if (current_index_ != index)
216 if (current_index_ >= 0)
218 auto ssw = steps_[current_index_];
219 if (!ssw->focusLost())
226 current_index_ = index;
232 main_content_->setCurrentIndex(index);
235 steps_[current_index_]->focusGiven();
245 void SetupAssistantWidget::updateTimer()
257 if (!config_data_->debug)
259 if (QMessageBox::question(
this,
"Exit Setup Assistant",
260 QString(
"Are you sure you want to exit the MoveIt Setup Assistant?"),
261 QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Cancel)
277 QMessageBox::critical(
this,
"Error",
"An error occurred and was caught by Qt notify event handler.", QMessageBox::Ok);
285 void SetupAssistantWidget::onModalModeUpdate(
bool isModal)
287 navs_view_->setDisabled(isModal);
289 for (
int i = 0; i < nav_name_list_.count(); ++i)
291 navs_view_->
setEnabled(i, !isModal && steps_[i]->isReady());
bool isReadyForInitialization() const
std::filesystem::path getSharePath(const std::string &package_name)
Return a path for the given package's share folder.