46#include <interactive_markers/tools.hpp>
48#include <rviz_common/display_context.hpp>
49#include <rviz_common/window_manager_interface.hpp>
52#include <QInputDialog>
54#include "ui_motion_planning_rviz_plugin_frame.h"
61void MotionPlanningFrame::saveSceneButtonClicked()
68 std::unique_ptr<QMessageBox> q;
71 q = std::make_unique<QMessageBox>(
72 QMessageBox::Question,
"Change Planning Scene Name",
73 QString(
"The name for the planning scene should not be empty. Would you like to rename "
74 "the planning scene?'"),
75 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);
86 std::unique_ptr<QPushButton> rename(q->addButton(
"&Rename", QMessageBox::AcceptRole));
87 if (q->exec() != QMessageBox::Yes)
89 if (q->clickedButton() == rename.get())
92 QString new_name = QInputDialog::getText(
this,
"Rename Planning Scene",
93 "New name for the planning scene:", QLineEdit::Normal,
94 QString::fromStdString(name), &ok);
98 rviz_common::properties::Property* prop =
102 bool old = prop->blockSignals(
true);
103 prop->setValue(new_name);
104 prop->blockSignals(old);
106 saveSceneButtonClicked();
118void MotionPlanningFrame::planningSceneItemClicked()
120 checkPlanningSceneTreeEnabledButtons();
123void MotionPlanningFrame::saveQueryButtonClicked()
127 QList<QTreeWidgetItem*> sel =
ui_->planning_scene_tree->selectedItems();
130 QTreeWidgetItem* s = sel.front();
135 std::string scene = s->text(0).toStdString();
141 std::string scene = s->parent()->text(0).toStdString();
142 std::string query_name = s->text(0).toStdString();
146 std::unique_ptr<QMessageBox> q;
147 if (query_name.empty())
149 q = std::make_unique<QMessageBox>(
150 QMessageBox::Question,
"Change Planning Query Name",
151 QString(
"The name for the planning query should not be empty. Would you like to"
152 "rename the planning query?'"),
153 QMessageBox::Cancel,
this);
157 q = std::make_unique<QMessageBox>(QMessageBox::Question,
"Confirm Planning Query Overwrite",
158 QString(
"A planning query named '")
159 .
append(query_name.c_str())
160 .append(
"' already exists. Do you wish "
161 "to overwrite that query?"),
162 QMessageBox::Yes | QMessageBox::No,
this);
164 std::unique_ptr<QPushButton> rename(q->addButton(
"&Rename", QMessageBox::AcceptRole));
165 if (q->exec() == QMessageBox::Yes)
171 if (q->clickedButton() == rename.get())
174 QString new_name = QInputDialog::getText(
this,
"Rename Planning Query",
175 "New name for the planning query:", QLineEdit::Normal,
176 QString::fromStdString(query_name), &ok);
179 query_name = new_name.toStdString();
191 [
this, scene, query_name] { computeSaveQueryButtonClicked(scene, query_name); },
"save query");
197void MotionPlanningFrame::deleteSceneButtonClicked()
202void MotionPlanningFrame::deleteQueryButtonClicked()
207void MotionPlanningFrame::loadSceneButtonClicked()
212void MotionPlanningFrame::loadQueryButtonClicked()
217void MotionPlanningFrame::warehouseItemNameChanged(QTreeWidgetItem* item,
int column)
219 if (item->text(column) == item->toolTip(column) || item->toolTip(column).length() == 0)
222 if (!planning_scene_storage)
227 std::string new_name = item->text(column).toStdString();
229 if (planning_scene_storage->hasPlanningScene(new_name))
232 QMessageBox::warning(
this,
"Scene not renamed",
233 QString(
"The scene name '").
append(item->text(column)).append(
"' already exists"));
238 std::string old_name = item->toolTip(column).toStdString();
239 planning_scene_storage->renamePlanningScene(old_name, new_name);
240 item->setToolTip(column, item->text(column));
245 std::string scene = item->parent()->text(0).toStdString();
246 std::string new_name = item->text(column).toStdString();
247 if (planning_scene_storage->hasPlanningQuery(scene, new_name))
250 QMessageBox::warning(
this,
"Query not renamed",
251 QString(
"The query name '")
252 .
append(item->text(column))
253 .append(
"' already exists for scene ")
254 .append(item->parent()->text(0)));
259 std::string old_name = item->toolTip(column).toStdString();
260 planning_scene_storage->renamePlanningQuery(scene, old_name, new_name);
261 item->setToolTip(column, item->text(column));
266void MotionPlanningFrame::populatePlanningSceneTreeView()
269 if (!planning_scene_storage)
272 ui_->planning_scene_tree->setUpdatesEnabled(
false);
275 std::set<std::string> expanded;
276 for (
int i = 0; i <
ui_->planning_scene_tree->topLevelItemCount(); ++i)
278 QTreeWidgetItem* it =
ui_->planning_scene_tree->topLevelItem(i);
279 if (it->isExpanded())
280 expanded.insert(it->text(0).toStdString());
283 ui_->planning_scene_tree->clear();
284 std::vector<std::string> names;
285 planning_scene_storage->getPlanningSceneNames(names);
287 for (
const std::string& name : names)
289 std::vector<std::string> query_names;
290 planning_scene_storage->getPlanningQueriesNames(query_names, name);
291 QTreeWidgetItem* item =
292 new QTreeWidgetItem(
ui_->planning_scene_tree, QStringList(QString::fromStdString(name)),
ITEM_TYPE_SCENE);
293 item->setFlags(item->flags() | Qt::ItemIsEditable);
294 item->setToolTip(0, item->text(0));
295 for (
const std::string& query_name : query_names)
297 QTreeWidgetItem* subitem =
298 new QTreeWidgetItem(item, QStringList(QString::fromStdString(query_name)),
ITEM_TYPE_QUERY);
299 subitem->setFlags(subitem->flags() | Qt::ItemIsEditable);
300 subitem->setToolTip(0, subitem->text(0));
301 item->addChild(subitem);
304 ui_->planning_scene_tree->insertTopLevelItem(
ui_->planning_scene_tree->topLevelItemCount(), item);
305 if (expanded.find(name) != expanded.end())
306 ui_->planning_scene_tree->expandItem(item);
308 ui_->planning_scene_tree->sortItems(0, Qt::AscendingOrder);
309 ui_->planning_scene_tree->setUpdatesEnabled(
true);
310 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)