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 
53 
54 #include <QMessageBox>
55 #include <QInputDialog>
56 
57 #include "ui_motion_planning_rviz_plugin_frame.h"
58 
59 #include <boost/math/constants/constants.hpp>
60 
61 #include <memory>
62 
63 namespace moveit_rviz_plugin
64 {
66 {
68  {
69  const std::string& name = planning_display_->getPlanningSceneRO()->getName();
70  if (name.empty() || planning_scene_storage_->hasPlanningScene(name))
71  {
72  std::unique_ptr<QMessageBox> q;
73  if (name.empty())
74  q.reset(new QMessageBox(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));
78  else
79  q.reset(new QMessageBox(QMessageBox::Question, "Confirm Planning Scene Overwrite",
80  QString("A planning scene named '")
81  .append(name.c_str())
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)
87  {
88  if (q->clickedButton() == rename.get())
89  {
90  bool ok = false;
91  QString new_name = QInputDialog::getText(this, "Rename Planning Scene", "New name for the planning scene:",
92  QLineEdit::Normal, 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  "save scene");
113  }
114 }
115 
117 {
119 }
120 
122 {
124  {
125  QList<QTreeWidgetItem*> sel = ui_->planning_scene_tree->selectedItems();
126  if (!sel.empty())
127  {
128  QTreeWidgetItem* s = sel.front();
129 
130  // if we have selected a PlanningScene, add the query as a new one, under that planning scene
131  if (s->type() == ITEM_TYPE_SCENE)
132  {
133  std::string scene = s->text(0).toStdString();
135  boost::bind(&MotionPlanningFrame::computeSaveQueryButtonClicked, this, scene, ""), "save query");
136  }
137  else
138  {
139  // if we selected a query name, then we overwrite that query
140  std::string scene = s->parent()->text(0).toStdString();
141  std::string query_name = s->text(0).toStdString();
142 
143  while (query_name.empty() || planning_scene_storage_->hasPlanningQuery(scene, query_name))
144  {
145  std::unique_ptr<QMessageBox> q;
146  if (query_name.empty())
147  q.reset(new QMessageBox(QMessageBox::Question, "Change Planning Query Name",
148  QString("The name for the planning query should not be empty. Would you like to "
149  "rename the planning query?'"),
150  QMessageBox::Cancel, this));
151  else
152  q.reset(new QMessageBox(QMessageBox::Question, "Confirm Planning Query Overwrite",
153  QString("A planning query named '")
154  .append(query_name.c_str())
155  .append("' already exists. Do you wish "
156  "to overwrite that query?"),
157  QMessageBox::Yes | QMessageBox::No, this));
158  std::unique_ptr<QPushButton> rename(q->addButton("&Rename", QMessageBox::AcceptRole));
159  if (q->exec() == QMessageBox::Yes)
160  break;
161  else
162  {
163  if (q->clickedButton() == rename.get())
164  {
165  bool ok = false;
166  QString new_name =
167  QInputDialog::getText(this, "Rename Planning Query", "New name for the planning query:",
168  QLineEdit::Normal, QString::fromStdString(query_name), &ok);
169  if (ok)
170  query_name = new_name.toStdString();
171  else
172  return;
173  }
174  else
175  return;
176  }
177  }
179  boost::bind(&MotionPlanningFrame::computeSaveQueryButtonClicked, this, scene, query_name), "save query");
180  }
181  }
182  }
183 }
184 
186 {
188  "delete scene");
189 }
190 
192 {
194  "delete query");
195 }
196 
198 {
200  "load scene");
201 }
202 
204 {
206  "load query");
207 }
208 
209 void MotionPlanningFrame::warehouseItemNameChanged(QTreeWidgetItem* item, int column)
210 {
211  if (item->text(column) == item->toolTip(column) || item->toolTip(column).length() == 0)
212  return;
213  moveit_warehouse::PlanningSceneStoragePtr planning_scene_storage = planning_scene_storage_;
214  if (!planning_scene_storage)
215  return;
216 
217  if (item->type() == ITEM_TYPE_SCENE)
218  {
219  std::string new_name = item->text(column).toStdString();
220 
221  if (planning_scene_storage->hasPlanningScene(new_name))
222  {
224  QMessageBox::warning(this, "Scene not renamed",
225  QString("The scene name '").append(item->text(column)).append("' already exists"));
226  return;
227  }
228  else
229  {
230  std::string old_name = item->toolTip(column).toStdString();
231  planning_scene_storage->renamePlanningScene(old_name, new_name);
232  item->setToolTip(column, item->text(column));
233  }
234  }
235  else
236  {
237  std::string scene = item->parent()->text(0).toStdString();
238  std::string new_name = item->text(column).toStdString();
239  if (planning_scene_storage->hasPlanningQuery(scene, new_name))
240  {
242  QMessageBox::warning(this, "Query not renamed", QString("The query name '")
243  .append(item->text(column))
244  .append("' already exists for scene ")
245  .append(item->parent()->text(0)));
246  return;
247  }
248  else
249  {
250  std::string old_name = item->toolTip(column).toStdString();
251  planning_scene_storage->renamePlanningQuery(scene, old_name, new_name);
252  item->setToolTip(column, item->text(column));
253  }
254  }
255 }
256 
258 {
259  moveit_warehouse::PlanningSceneStoragePtr planning_scene_storage = planning_scene_storage_;
260  if (!planning_scene_storage)
261  return;
262 
263  ui_->planning_scene_tree->setUpdatesEnabled(false);
264 
265  // remember which items were expanded
266  std::set<std::string> expanded;
267  for (int i = 0; i < ui_->planning_scene_tree->topLevelItemCount(); ++i)
268  {
269  QTreeWidgetItem* it = ui_->planning_scene_tree->topLevelItem(i);
270  if (it->isExpanded())
271  expanded.insert(it->text(0).toStdString());
272  }
273 
274  ui_->planning_scene_tree->clear();
275  std::vector<std::string> names;
276  planning_scene_storage->getPlanningSceneNames(names);
277 
278  for (std::size_t i = 0; i < names.size(); ++i)
279  {
280  std::vector<std::string> query_names;
281  planning_scene_storage->getPlanningQueriesNames(query_names, names[i]);
282  QTreeWidgetItem* item =
283  new QTreeWidgetItem(ui_->planning_scene_tree, QStringList(QString::fromStdString(names[i])), ITEM_TYPE_SCENE);
284  item->setFlags(item->flags() | Qt::ItemIsEditable);
285  item->setToolTip(0, item->text(0)); // we use the tool tip as a backup of the old name when renaming
286  for (std::size_t j = 0; j < query_names.size(); ++j)
287  {
288  QTreeWidgetItem* subitem =
289  new QTreeWidgetItem(item, QStringList(QString::fromStdString(query_names[j])), ITEM_TYPE_QUERY);
290  subitem->setFlags(subitem->flags() | Qt::ItemIsEditable);
291  subitem->setToolTip(0, subitem->text(0));
292  item->addChild(subitem);
293  }
294 
295  ui_->planning_scene_tree->insertTopLevelItem(ui_->planning_scene_tree->topLevelItemCount(), item);
296  if (expanded.find(names[i]) != expanded.end())
297  ui_->planning_scene_tree->expandItem(item);
298  }
299  ui_->planning_scene_tree->sortItems(0, Qt::AscendingOrder);
300  ui_->planning_scene_tree->setUpdatesEnabled(true);
302 }
303 }
planning_scene_monitor::LockedPlanningSceneRW getPlanningSceneRW()
get write access to planning scene
q
virtual bool setValue(const QVariant &new_value)
XmlRpcServer s
void computeSaveQueryButtonClicked(const std::string &scene, const std::string &query_name)
name
virtual Property * subProp(const QString &sub_name)
void addBackgroundJob(const boost::function< void()> &job, const std::string &name)
void addMainLoopJob(const boost::function< void()> &job)
queue the execution of this function for the next time the main update() loop gets called ...
void warehouseItemNameChanged(QTreeWidgetItem *item, int column)
ROSCPP_DECL std::string append(const std::string &left, const std::string &right)
moveit_warehouse::PlanningSceneStoragePtr planning_scene_storage_
planning_scene_monitor::LockedPlanningSceneRO getPlanningSceneRO() const
get read-only access to planning scene


visualization
Author(s): Ioan Sucan , Dave Coleman , Sachin Chitta
autogenerated on Sun Oct 18 2020 13:19:09