46 #include <interactive_markers/tools.hpp>
48 #include <rviz_common/display_context.hpp>
49 #include <rviz_common/window_manager_interface.hpp>
51 #include <QMessageBox>
52 #include <QInputDialog>
54 #include "ui_motion_planning_rviz_plugin_frame.h"
56 #include <boost/math/constants/constants.hpp>
62 static const rclcpp::Logger
LOGGER = rclcpp::get_logger(
"moveit_ros_visualization.motion_planning_frame_scenes");
64 void MotionPlanningFrame::saveSceneButtonClicked()
71 std::unique_ptr<QMessageBox> q;
73 q = std::make_unique<QMessageBox>(
74 QMessageBox::Question,
"Change Planning Scene Name",
75 QString(
"The name for the planning scene should not be empty. Would you like to rename "
76 "the planning scene?'"),
77 QMessageBox::Cancel,
this);
79 q = std::make_unique<QMessageBox>(QMessageBox::Question,
"Confirm Planning Scene Overwrite",
80 QString(
"A planning scene named '")
82 .append(
"' already exists. Do you wish to "
83 "overwrite that scene?"),
84 QMessageBox::Yes | QMessageBox::No,
this);
85 std::unique_ptr<QPushButton> rename(q->addButton(
"&Rename", QMessageBox::AcceptRole));
86 if (q->exec() != QMessageBox::Yes)
88 if (q->clickedButton() == rename.get())
91 QString new_name = QInputDialog::getText(
this,
"Rename Planning Scene",
92 "New name for the planning scene:", QLineEdit::Normal,
93 QString::fromStdString(
name), &ok);
97 rviz_common::properties::Property* prop =
101 bool old = prop->blockSignals(
true);
102 prop->setValue(new_name);
103 prop->blockSignals(old);
105 saveSceneButtonClicked();
117 void MotionPlanningFrame::planningSceneItemClicked()
119 checkPlanningSceneTreeEnabledButtons();
122 void MotionPlanningFrame::saveQueryButtonClicked()
126 QList<QTreeWidgetItem*> sel =
ui_->planning_scene_tree->selectedItems();
129 QTreeWidgetItem* s = sel.front();
134 std::string
scene = s->text(0).toStdString();
140 std::string
scene = s->parent()->text(0).toStdString();
141 std::string query_name = s->text(0).toStdString();
145 std::unique_ptr<QMessageBox> q;
146 if (query_name.empty())
147 q = std::make_unique<QMessageBox>(
148 QMessageBox::Question,
"Change Planning Query Name",
149 QString(
"The name for the planning query should not be empty. Would you like to"
150 "rename the planning query?'"),
151 QMessageBox::Cancel,
this);
153 q = std::make_unique<QMessageBox>(QMessageBox::Question,
"Confirm Planning Query Overwrite",
154 QString(
"A planning query named '")
155 .
append(query_name.c_str())
156 .append(
"' already exists. Do you wish "
157 "to overwrite that query?"),
158 QMessageBox::Yes | QMessageBox::No,
this);
159 std::unique_ptr<QPushButton> rename(q->addButton(
"&Rename", QMessageBox::AcceptRole));
160 if (q->exec() == QMessageBox::Yes)
164 if (q->clickedButton() == rename.get())
167 QString new_name = QInputDialog::getText(
this,
"Rename Planning Query",
168 "New name for the planning query:", QLineEdit::Normal,
169 QString::fromStdString(query_name), &ok);
171 query_name = new_name.toStdString();
180 [
this,
scene, query_name] { computeSaveQueryButtonClicked(
scene, query_name); },
"save query");
186 void MotionPlanningFrame::deleteSceneButtonClicked()
191 void MotionPlanningFrame::deleteQueryButtonClicked()
196 void MotionPlanningFrame::loadSceneButtonClicked()
201 void MotionPlanningFrame::loadQueryButtonClicked()
206 void MotionPlanningFrame::warehouseItemNameChanged(QTreeWidgetItem* item,
int column)
208 if (item->text(column) == item->toolTip(column) || item->toolTip(column).length() == 0)
211 if (!planning_scene_storage)
216 std::string new_name = item->text(column).toStdString();
218 if (planning_scene_storage->hasPlanningScene(new_name))
221 QMessageBox::warning(
this,
"Scene not renamed",
222 QString(
"The scene name '").
append(item->text(column)).append(
"' already exists"));
227 std::string old_name = item->toolTip(column).toStdString();
228 planning_scene_storage->renamePlanningScene(old_name, new_name);
229 item->setToolTip(column, item->text(column));
234 std::string
scene = item->parent()->text(0).toStdString();
235 std::string new_name = item->text(column).toStdString();
236 if (planning_scene_storage->hasPlanningQuery(
scene, new_name))
239 QMessageBox::warning(
this,
"Query not renamed",
240 QString(
"The query name '")
241 .
append(item->text(column))
242 .append(
"' already exists for scene ")
243 .append(item->parent()->text(0)));
248 std::string old_name = item->toolTip(column).toStdString();
249 planning_scene_storage->renamePlanningQuery(
scene, old_name, new_name);
250 item->setToolTip(column, item->text(column));
255 void MotionPlanningFrame::populatePlanningSceneTreeView()
258 if (!planning_scene_storage)
261 ui_->planning_scene_tree->setUpdatesEnabled(
false);
264 std::set<std::string> expanded;
265 for (
int i = 0; i <
ui_->planning_scene_tree->topLevelItemCount(); ++i)
267 QTreeWidgetItem* it =
ui_->planning_scene_tree->topLevelItem(i);
268 if (it->isExpanded())
269 expanded.insert(it->text(0).toStdString());
272 ui_->planning_scene_tree->clear();
273 std::vector<std::string> names;
274 planning_scene_storage->getPlanningSceneNames(names);
276 for (
const std::string&
name : names)
278 std::vector<std::string> query_names;
279 planning_scene_storage->getPlanningQueriesNames(query_names,
name);
280 QTreeWidgetItem* item =
281 new QTreeWidgetItem(
ui_->planning_scene_tree, QStringList(QString::fromStdString(
name)),
ITEM_TYPE_SCENE);
282 item->setFlags(item->flags() | Qt::ItemIsEditable);
283 item->setToolTip(0, item->text(0));
284 for (
const std::string& query_name : query_names)
286 QTreeWidgetItem* subitem =
287 new QTreeWidgetItem(item, QStringList(QString::fromStdString(query_name)),
ITEM_TYPE_QUERY);
288 subitem->setFlags(subitem->flags() | Qt::ItemIsEditable);
289 subitem->setToolTip(0, subitem->text(0));
290 item->addChild(subitem);
293 ui_->planning_scene_tree->insertTopLevelItem(
ui_->planning_scene_tree->topLevelItemCount(), item);
294 if (expanded.find(
name) != expanded.end())
295 ui_->planning_scene_tree->expandItem(item);
297 ui_->planning_scene_tree->sortItems(0, Qt::AscendingOrder);
298 ui_->planning_scene_tree->setUpdatesEnabled(
true);
299 checkPlanningSceneTreeEnabledButtons();
moveit_warehouse::PlanningSceneStoragePtr planning_scene_storage_
static const int ITEM_TYPE_SCENE
Ui::MotionPlanningUI * ui_
static const int ITEM_TYPE_QUERY
MotionPlanningDisplay * planning_display_
planning_scene_monitor::LockedPlanningSceneRO getPlanningSceneRO() const
get read-only access to planning scene
planning_scene_monitor::LockedPlanningSceneRW getPlanningSceneRW()
get write access to planning scene
void addMainLoopJob(const std::function< void()> &job)
queue the execution of this function for the next time the main update() loop gets called
void addBackgroundJob(const std::function< void()> &job, const std::string &name)
std::string append(const std::string &left, const std::string &right)
const rclcpp::Logger LOGGER