52 #include <QMessageBox>
53 #include <QInputDialog>
55 #include "ui_motion_planning_rviz_plugin_frame.h"
57 #include <boost/math/constants/constants.hpp>
70 std::unique_ptr<QMessageBox>
q;
72 q = std::make_unique<QMessageBox>(
73 QMessageBox::Question,
"Change Planning Scene Name",
74 QString(
"The name for the planning scene should not be empty. Would you like to rename "
75 "the planning scene?'"),
76 QMessageBox::Cancel,
this);
78 q = std::make_unique<QMessageBox>(QMessageBox::Question,
"Confirm Planning Scene Overwrite",
79 QString(
"A planning scene named '")
81 .append(
"' already exists. Do you wish to "
82 "overwrite that scene?"),
83 QMessageBox::Yes | QMessageBox::No,
this);
84 std::unique_ptr<QPushButton> rename(
q->addButton(
"&Rename", QMessageBox::AcceptRole));
85 if (
q->exec() != QMessageBox::Yes)
87 if (
q->clickedButton() == rename.get())
90 QString new_name = QInputDialog::getText(
this,
"Rename Planning Scene",
91 "New name for the planning scene:", QLineEdit::Normal,
92 QString::fromStdString(name), &ok);
99 bool old = prop->blockSignals(
true);
101 prop->blockSignals(old);
124 QList<QTreeWidgetItem*> sel =
ui_->planning_scene_tree->selectedItems();
127 QTreeWidgetItem*
s = sel.front();
132 std::string scene =
s->text(0).toStdString();
138 std::string scene =
s->parent()->text(0).toStdString();
139 std::string query_name =
s->text(0).toStdString();
143 std::unique_ptr<QMessageBox>
q;
144 if (query_name.empty())
145 q = std::make_unique<QMessageBox>(
146 QMessageBox::Question,
"Change Planning Query Name",
147 QString(
"The name for the planning query should not be empty. Would you like to "
148 "rename the planning query?'"),
149 QMessageBox::Cancel,
this);
151 q = std::make_unique<QMessageBox>(QMessageBox::Question,
"Confirm Planning Query Overwrite",
152 QString(
"A planning query named '")
153 .
append(query_name.c_str())
154 .append(
"' already exists. Do you wish "
155 "to overwrite that query?"),
156 QMessageBox::Yes | QMessageBox::No,
this);
157 std::unique_ptr<QPushButton> rename(
q->addButton(
"&Rename", QMessageBox::AcceptRole));
158 if (
q->exec() == QMessageBox::Yes)
162 if (
q->clickedButton() == rename.get())
165 QString new_name = QInputDialog::getText(
this,
"Rename Planning Query",
166 "New name for the planning query:", QLineEdit::Normal,
167 QString::fromStdString(query_name), &ok);
169 query_name = new_name.toStdString();
206 if (item->text(column) == item->toolTip(column) || item->toolTip(column).length() == 0)
209 if (!planning_scene_storage)
214 std::string new_name = item->text(column).toStdString();
216 if (planning_scene_storage->hasPlanningScene(new_name))
219 QMessageBox::warning(
this,
"Scene not renamed",
220 QString(
"The scene name '").
append(item->text(column)).append(
"' already exists"));
225 std::string old_name = item->toolTip(column).toStdString();
226 planning_scene_storage->renamePlanningScene(old_name, new_name);
227 item->setToolTip(column, item->text(column));
232 std::string scene = item->parent()->text(0).toStdString();
233 std::string new_name = item->text(column).toStdString();
234 if (planning_scene_storage->hasPlanningQuery(scene, new_name))
237 QMessageBox::warning(
this,
"Query not renamed",
238 QString(
"The query name '")
239 .
append(item->text(column))
240 .append(
"' already exists for scene ")
241 .append(item->parent()->text(0)));
246 std::string old_name = item->toolTip(column).toStdString();
247 planning_scene_storage->renamePlanningQuery(scene, old_name, new_name);
248 item->setToolTip(column, item->text(column));
256 if (!planning_scene_storage)
259 ui_->planning_scene_tree->setUpdatesEnabled(
false);
262 std::set<std::string> expanded;
263 for (
int i = 0; i <
ui_->planning_scene_tree->topLevelItemCount(); ++i)
265 QTreeWidgetItem* it =
ui_->planning_scene_tree->topLevelItem(i);
266 if (it->isExpanded())
267 expanded.insert(it->text(0).toStdString());
270 ui_->planning_scene_tree->clear();
271 std::vector<std::string> names;
272 planning_scene_storage->getPlanningSceneNames(names);
274 for (
const std::string& name : names)
276 std::vector<std::string> query_names;
277 planning_scene_storage->getPlanningQueriesNames(query_names, name);
278 QTreeWidgetItem* item =
279 new QTreeWidgetItem(
ui_->planning_scene_tree, QStringList(QString::fromStdString(name)),
ITEM_TYPE_SCENE);
280 item->setFlags(item->flags() | Qt::ItemIsEditable);
281 item->setToolTip(0, item->text(0));
282 for (
const std::string& query_name : query_names)
284 QTreeWidgetItem* subitem =
285 new QTreeWidgetItem(item, QStringList(QString::fromStdString(query_name)),
ITEM_TYPE_QUERY);
286 subitem->setFlags(subitem->flags() | Qt::ItemIsEditable);
287 subitem->setToolTip(0, subitem->text(0));
288 item->addChild(subitem);
291 ui_->planning_scene_tree->insertTopLevelItem(
ui_->planning_scene_tree->topLevelItemCount(), item);
292 if (expanded.find(name) != expanded.end())
293 ui_->planning_scene_tree->expandItem(item);
295 ui_->planning_scene_tree->sortItems(0, Qt::AscendingOrder);
296 ui_->planning_scene_tree->setUpdatesEnabled(
true);