motion_planning_frame_scenes.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2012, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: Ioan Sucan */
36 
40 
46 
48 
49 #include <rviz/display_context.h>
51 
52 #include <QMessageBox>
53 #include <QInputDialog>
54 
55 #include "ui_motion_planning_rviz_plugin_frame.h"
56 
57 #include <boost/math/constants/constants.hpp>
58 
59 #include <memory>
60 
61 namespace moveit_rviz_plugin
62 {
64 {
66  {
67  const std::string& name = planning_display_->getPlanningSceneRO()->getName();
68  if (name.empty() || planning_scene_storage_->hasPlanningScene(name))
69  {
70  std::unique_ptr<QMessageBox> q;
71  if (name.empty())
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);
77  else
78  q = std::make_unique<QMessageBox>(QMessageBox::Question, "Confirm Planning Scene Overwrite",
79  QString("A planning scene named '")
80  .append(name.c_str())
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)
86  {
87  if (q->clickedButton() == rename.get())
88  {
89  bool ok = false;
90  QString new_name = QInputDialog::getText(this, "Rename Planning Scene",
91  "New name for the planning scene:", QLineEdit::Normal,
92  QString::fromStdString(name), &ok);
93  if (ok)
94  {
95  planning_display_->getPlanningSceneRW()->setName(new_name.toStdString());
96  rviz::Property* prop = planning_display_->subProp("Scene Geometry")->subProp("Scene Name");
97  if (prop)
98  {
99  bool old = prop->blockSignals(true);
100  prop->setValue(new_name);
101  prop->blockSignals(old);
102  }
104  }
105  return;
106  }
107  return;
108  }
109  }
110 
112  }
113 }
114 
116 {
118 }
119 
121 {
123  {
124  QList<QTreeWidgetItem*> sel = ui_->planning_scene_tree->selectedItems();
125  if (!sel.empty())
126  {
127  QTreeWidgetItem* s = sel.front();
128 
129  // if we have selected a PlanningScene, add the query as a new one, under that planning scene
130  if (s->type() == ITEM_TYPE_SCENE)
131  {
132  std::string scene = s->text(0).toStdString();
133  planning_display_->addBackgroundJob([this, scene] { computeSaveQueryButtonClicked(scene, ""); }, "save query");
134  }
135  else
136  {
137  // if we selected a query name, then we overwrite that query
138  std::string scene = s->parent()->text(0).toStdString();
139  std::string query_name = s->text(0).toStdString();
140 
141  while (query_name.empty() || planning_scene_storage_->hasPlanningQuery(scene, query_name))
142  {
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);
150  else
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)
159  break;
160  else
161  {
162  if (q->clickedButton() == rename.get())
163  {
164  bool ok = false;
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);
168  if (ok)
169  query_name = new_name.toStdString();
170  else
171  return;
172  }
173  else
174  return;
175  }
176  }
178  [this, scene, query_name] { computeSaveQueryButtonClicked(scene, query_name); }, "save query");
179  }
180  }
181  }
182 }
183 
185 {
187 }
188 
190 {
192 }
193 
195 {
197 }
198 
200 {
202 }
203 
204 void MotionPlanningFrame::warehouseItemNameChanged(QTreeWidgetItem* item, int column)
205 {
206  if (item->text(column) == item->toolTip(column) || item->toolTip(column).length() == 0)
207  return;
208  moveit_warehouse::PlanningSceneStoragePtr planning_scene_storage = planning_scene_storage_;
209  if (!planning_scene_storage)
210  return;
211 
212  if (item->type() == ITEM_TYPE_SCENE)
213  {
214  std::string new_name = item->text(column).toStdString();
215 
216  if (planning_scene_storage->hasPlanningScene(new_name))
217  {
219  QMessageBox::warning(this, "Scene not renamed",
220  QString("The scene name '").append(item->text(column)).append("' already exists"));
221  return;
222  }
223  else
224  {
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));
228  }
229  }
230  else
231  {
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))
235  {
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)));
242  return;
243  }
244  else
245  {
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));
249  }
250  }
251 }
252 
254 {
255  moveit_warehouse::PlanningSceneStoragePtr planning_scene_storage = planning_scene_storage_;
256  if (!planning_scene_storage)
257  return;
258 
259  ui_->planning_scene_tree->setUpdatesEnabled(false);
260 
261  // remember which items were expanded
262  std::set<std::string> expanded;
263  for (int i = 0; i < ui_->planning_scene_tree->topLevelItemCount(); ++i)
264  {
265  QTreeWidgetItem* it = ui_->planning_scene_tree->topLevelItem(i);
266  if (it->isExpanded())
267  expanded.insert(it->text(0).toStdString());
268  }
269 
270  ui_->planning_scene_tree->clear();
271  std::vector<std::string> names;
272  planning_scene_storage->getPlanningSceneNames(names);
273 
274  for (const std::string& name : names)
275  {
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)); // we use the tool tip as a backup of the old name when renaming
282  for (const std::string& query_name : query_names)
283  {
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);
289  }
290 
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);
294  }
295  ui_->planning_scene_tree->sortItems(0, Qt::AscendingOrder);
296  ui_->planning_scene_tree->setUpdatesEnabled(true);
298 }
299 } // namespace moveit_rviz_plugin
moveit_rviz_plugin::MotionPlanningFrame::deleteQueryButtonClicked
void deleteQueryButtonClicked()
Definition: motion_planning_frame_scenes.cpp:221
moveit_rviz_plugin::MotionPlanningFrame::computeSaveQueryButtonClicked
void computeSaveQueryButtonClicked(const std::string &scene, const std::string &query_name)
Definition: motion_planning_frame_objects.cpp:492
moveit_rviz_plugin::MotionPlanningFrame::computeLoadSceneButtonClicked
void computeLoadSceneButtonClicked()
Definition: motion_planning_frame_objects.cpp:620
motion_planning_display.h
planning_scene_storage.h
utils.h
s
XmlRpcServer s
moveit_rviz_plugin::MotionPlanningFrame::planningSceneItemClicked
void planningSceneItemClicked()
Definition: motion_planning_frame_scenes.cpp:147
constraints_storage.h
rviz::Property::subProp
virtual Property * subProp(const QString &sub_name)
state_storage.h
moveit_rviz_plugin::MotionPlanningFrame::loadQueryButtonClicked
void loadQueryButtonClicked()
Definition: motion_planning_frame_scenes.cpp:231
tools.h
moveit_rviz_plugin::PlanningSceneDisplay::addMainLoopJob
void addMainLoopJob(const boost::function< void()> &job)
queue the execution of this function for the next time the main update() loop gets called
Definition: planning_scene_display.cpp:265
ok
ROSCPP_DECL bool ok()
rviz::Property
moveit_rviz_plugin::MotionPlanningFrame::deleteSceneButtonClicked
void deleteSceneButtonClicked()
Definition: motion_planning_frame_scenes.cpp:216
moveit_rviz_plugin::MotionPlanningFrame::warehouseItemNameChanged
void warehouseItemNameChanged(QTreeWidgetItem *item, int column)
Definition: motion_planning_frame_scenes.cpp:236
interactive_marker_helpers.h
moveit_rviz_plugin::PlanningSceneDisplay::getPlanningSceneRO
planning_scene_monitor::LockedPlanningSceneRO getPlanningSceneRO() const
get read-only access to planning scene
Definition: planning_scene_display.cpp:328
moveit_rviz_plugin::MotionPlanningFrame::ui_
Ui::MotionPlanningUI * ui_
Definition: motion_planning_frame.h:127
moveit_rviz_plugin::MotionPlanningFrame::saveSceneButtonClicked
void saveSceneButtonClicked()
Definition: motion_planning_frame_scenes.cpp:95
rviz::Property::setValue
virtual bool setValue(const QVariant &new_value)
window_manager_interface.h
moveit_rviz_plugin::MotionPlanningFrame::computeDeleteSceneButtonClicked
void computeDeleteSceneButtonClicked()
Definition: motion_planning_frame_objects.cpp:513
moveit_rviz_plugin::MotionPlanningFrame::planning_scene_storage_
moveit_warehouse::PlanningSceneStoragePtr planning_scene_storage_
Definition: motion_planning_frame.h:134
moveit_rviz_plugin::MotionPlanningFrame::loadSceneButtonClicked
void loadSceneButtonClicked()
Definition: motion_planning_frame_scenes.cpp:226
moveit_rviz_plugin::MotionPlanningFrame::computeLoadQueryButtonClicked
void computeLoadQueryButtonClicked()
Definition: motion_planning_frame_objects.cpp:674
name
name
moveit_rviz_plugin::PlanningSceneDisplay::addBackgroundJob
void addBackgroundJob(const boost::function< void()> &job, const std::string &name)
Definition: planning_scene_display.cpp:255
q
q
moveit_rviz_plugin::MotionPlanningFrame::ITEM_TYPE_SCENE
static const int ITEM_TYPE_SCENE
Definition: motion_planning_frame.h:115
moveit_rviz_plugin::MotionPlanningFrame::ITEM_TYPE_QUERY
static const int ITEM_TYPE_QUERY
Definition: motion_planning_frame.h:116
moveit_rviz_plugin
Definition: motion_planning_display.h:80
moveit_rviz_plugin::MotionPlanningFrame::saveQueryButtonClicked
void saveQueryButtonClicked()
Definition: motion_planning_frame_scenes.cpp:152
append
ROSCPP_DECL std::string append(const std::string &left, const std::string &right)
moveit_rviz_plugin::MotionPlanningFrame::computeSaveSceneButtonClicked
void computeSaveSceneButtonClicked()
Definition: motion_planning_frame_objects.cpp:472
moveit_rviz_plugin::MotionPlanningFrame::populatePlanningSceneTreeView
void populatePlanningSceneTreeView()
Definition: motion_planning_frame_scenes.cpp:285
conversions.h
moveit_rviz_plugin::MotionPlanningFrame::planning_display_
MotionPlanningDisplay * planning_display_
Definition: motion_planning_frame.h:125
moveit_rviz_plugin::MotionPlanningFrame::checkPlanningSceneTreeEnabledButtons
void checkPlanningSceneTreeEnabledButtons()
Definition: motion_planning_frame_objects.cpp:584
moveit_rviz_plugin::MotionPlanningFrame::computeDeleteQueryButtonClicked
void computeDeleteQueryButtonClicked()
Definition: motion_planning_frame_objects.cpp:551
motion_planning_frame.h
moveit_rviz_plugin::PlanningSceneDisplay::getPlanningSceneRW
planning_scene_monitor::LockedPlanningSceneRW getPlanningSceneRW()
get write access to planning scene
Definition: planning_scene_display.cpp:333
display_context.h


visualization
Author(s): Ioan Sucan , Dave Coleman , Sachin Chitta
autogenerated on Sat Mar 15 2025 02:27:25