display.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <stdio.h>
31 
32 #include <QApplication>
33 #include <QColor>
34 #include <QDockWidget>
35 #include <QFont>
36 #include <QMetaObject>
37 #include <QWidget>
38 
39 #include <OgreSceneManager.h>
40 #include <OgreSceneNode.h>
41 
42 #include <rviz/display_context.h>
47 #include <rviz/panel_dock_widget.h>
48 
49 #include "display.h"
50 
51 #include <boost/filesystem.hpp>
52 
53 namespace rviz
54 {
56  : context_(nullptr)
57  , scene_node_(nullptr)
58  , status_(nullptr)
59  , initialized_(false)
60  , visibility_bits_(0xFFFFFFFF)
61  , associated_widget_(nullptr)
62  , associated_widget_panel_(nullptr)
63  , suppress_hiding_associated_widget_panel_(false)
64 {
65  // Needed for timeSignal (see header) to work across threads
66  qRegisterMetaType<ros::Time>();
67 
68  // Make the display-enable checkbox show up, and make it unchecked by default.
69  setValue(false);
70 
72 
74 }
75 
77 {
78  if (scene_node_)
79  {
80  scene_manager_->destroySceneNode(scene_node_);
81  }
82 }
83 
85 {
86  context_ = context;
88  scene_node_ = scene_manager_->getRootSceneNode()->createChildSceneNode();
89 
93 
94  onInitialize();
95 
96  initialized_ = true;
97 }
98 
100 {
101  if (context_)
102  {
104  }
105 }
106 
107 QVariant Display::getViewData(int column, int role) const
108 {
109  switch (role)
110  {
111  case Qt::ForegroundRole:
112  {
113  // if we're item-enabled (not greyed out) and in warn/error state, set appropriate color
114  if (getViewFlags(column) & Qt::ItemIsEnabled)
115  {
116  if (isEnabled())
117  {
119  {
121  }
122  else
123  {
124  // blue means that the enabled checkmark is set
125  return QColor(40, 120, 197);
126  }
127  }
128  else
129  {
130  return QApplication::palette().color(QPalette::Text);
131  }
132  }
133  break;
134  }
135  case Qt::FontRole:
136  {
137  QFont font;
138  if (isEnabled())
139  {
140  font.setBold(true);
141  }
142  return font;
143  }
144  case Qt::DecorationRole:
145  {
146  if (column == 0)
147  {
148  if (isEnabled())
149  {
151  switch (level)
152  {
153  case StatusProperty::Ok:
154  return getIcon();
157  return status_->statusIcon(status_->getLevel());
158  }
159  }
160  else
161  {
162  return getIcon();
163  }
164  }
165  break;
166  }
167  }
168  return BoolProperty::getViewData(column, role);
169 }
170 
171 Qt::ItemFlags Display::getViewFlags(int column) const
172 {
173  return BoolProperty::getViewFlags(column) | Qt::ItemIsDragEnabled;
174 }
175 
176 void Display::setStatus(StatusProperty::Level level, const QString& name, const QString& text)
177 {
178  QMetaObject::invokeMethod(this, "setStatusInternal", Qt::QueuedConnection, Q_ARG(int, level),
179  Q_ARG(QString, name), Q_ARG(QString, text));
180 }
181 
182 void Display::setStatusInternal(int level, const QString& name, const QString& text)
183 {
184  if (!status_)
185  {
186  status_ = new StatusList("Status");
187  addChild(status_, 0);
188  }
189  StatusProperty::Level old_level = status_->getLevel();
190 
191  status_->setStatus((StatusProperty::Level)level, name, text);
192  if (model_ && old_level != status_->getLevel())
193  {
194  // status changes should not trigger a configChanged() signal
195  model_->emitDataChanged(this, false);
196  }
197 }
198 
199 void Display::deleteStatus(const QString& name)
200 {
201  QMetaObject::invokeMethod(this, "deleteStatusInternal", Qt::QueuedConnection, Q_ARG(QString, name));
202 }
203 
204 void Display::deleteStatusInternal(const QString& name)
205 {
206  if (status_)
207  {
208  status_->deleteStatus(name);
209  }
210 }
211 
213 {
214  QMetaObject::invokeMethod(this, "clearStatusesInternal", Qt::QueuedConnection);
215 }
216 
218 {
219  if (status_)
220  {
221  StatusProperty::Level old_level = status_->getLevel();
222  status_->clear();
223  if (model_ && old_level != StatusProperty::Ok)
224  {
225  // status changes should not trigger a configChanged() signal
226  model_->emitDataChanged(this, false);
227  }
228  }
229 }
230 
231 void Display::load(const Config& config)
232 {
233  // Base class loads sub-properties.
235 
236  QString name;
237  if (config.mapGetString("Name", &name))
238  {
239  setObjectName(name);
240  }
241 
242  bool enabled;
243  if (config.mapGetBool("Enabled", &enabled))
244  {
245  setEnabled(enabled);
246  }
247 }
248 
249 void Display::save(Config config) const
250 {
251  // Base class saves sub-properties.
253 
254  config.mapSetValue("Class", getClassId());
255  config.mapSetValue("Name", getName());
256  config.mapSetValue("Enabled", getBool());
257 }
258 
259 void Display::setEnabled(bool enabled)
260 {
261  if (enabled == isEnabled())
262  return;
263  setValue(enabled);
264 }
265 
267 {
268  setEnabled(false);
269 }
270 
271 bool Display::isEnabled() const
272 {
273  return getBool() && (getViewFlags(0) & Qt::ItemIsEnabled);
274 }
275 
276 void Display::setFixedFrame(const QString& fixed_frame)
277 {
278  fixed_frame_ = fixed_frame;
279  if (initialized_)
280  {
282  }
283 }
284 
286 {
287  Q_EMIT(timeSignal(time, QPrivateSignal()));
288 }
289 
291 {
292  clearStatuses();
293 }
294 
296 {
297  QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
298  queueRender();
299  /* We get here, by two different routes:
300  * - First, we might have disabled the display.
301  * In this case we want to close/hide the associated widget.
302  * But there is an exception: tabbed DockWidgets shouldn't be hidden, because then we would loose the
303  * tab.
304  * - Second, the corresponding widget changed visibility and we got here via
305  * associatedPanelVisibilityChange().
306  * In this case, it's usually counterproductive to show/hide the widget here.
307  * Typical cases are: main window was minimized/unminimized, tab was switched.
308  */
309  if (isEnabled())
310  {
311  scene_node_->setVisible(true);
312 
314  associated_widget_panel_->show();
315  else if (associated_widget_)
316  associated_widget_->show();
317 
318  if (isEnabled()) // status might have changed, e.g. if show() failed
319  onEnable();
320  }
321  else
322  {
323  onDisable();
324 
326  {
328  associated_widget_panel_->hide();
329  }
330  else if (associated_widget_)
331  associated_widget_->hide();
332 
333  scene_node_->setVisible(false);
334  }
335  QApplication::restoreOverrideCursor();
336 }
337 
338 void Display::setVisibilityBits(uint32_t bits)
339 {
340  visibility_bits_ |= bits;
342 }
343 
344 void Display::unsetVisibilityBits(uint32_t bits)
345 {
346  visibility_bits_ &= ~bits;
348 }
349 
350 void Display::setAssociatedWidget(QWidget* widget)
351 {
353  {
354  disconnect(associated_widget_panel_, &PanelDockWidget::visibilityChanged, this,
357  }
358 
359  associated_widget_ = widget;
360  if (associated_widget_)
361  {
363  if (wm)
364  {
366  connect(associated_widget_panel_, &PanelDockWidget::visibilityChanged, this,
370  }
371  else
372  {
373  associated_widget_panel_ = nullptr;
374  associated_widget_->setWindowTitle(getName());
375  }
376  }
377  else
378  {
379  associated_widget_panel_ = nullptr;
380  }
381 }
382 
384 {
385  // If something external makes the panel visible/invisible, make sure to enable/disable the display
387  setEnabled(visible);
389  // Remark: vice versa, in Display::onEnableChanged(),
390  // the panel is made visible/invisible when the display is enabled/disabled
391 }
392 
393 void Display::setIcon(const QIcon& icon)
394 {
395  icon_ = icon;
397  {
399  }
400 }
401 
402 void Display::setName(const QString& name)
403 {
404  BoolProperty::setName(name);
405 
407  {
409  // QMainWindow::saveState() needs objectName to be set.
410  associated_widget_panel_->setObjectName(name);
411  }
412  else if (associated_widget_)
413  {
414  associated_widget_->setWindowTitle(name);
415  }
416 }
417 
418 } // end namespace rviz
rviz::BoolProperty::getBool
virtual bool getBool() const
Definition: bool_property.cpp:48
rviz::Display::disable
void disable()
Definition: display.cpp:266
rviz::Display::isEnabled
bool isEnabled() const
Return true if this Display is enabled, false if not.
Definition: display.cpp:271
apply_visibility_bits.h
panel_dock_widget.h
rviz::DisplayContext::getUpdateQueue
virtual ros::CallbackQueueInterface * getUpdateQueue()=0
Return the CallbackQueue using the main GUI thread.
rviz::Display::status_
StatusList * status_
Definition: display.h:325
window_manager_interface.h
rviz::Display::deleteStatusInternal
void deleteStatusInternal(const QString &name)
Definition: display.cpp:204
rviz::DisplayContext::queueRender
virtual void queueRender()=0
Queues a render. Multiple calls before a render happens will only cause a single render.
rviz::Display::emitTimeSignal
void emitTimeSignal(ros::Time time)
Emit a time signal that other Displays can synchronize to.
Definition: display.cpp:285
rviz::Display::suppress_hiding_associated_widget_panel_
bool suppress_hiding_associated_widget_panel_
Definition: display.h:331
rviz::Display::setFixedFrame
void setFixedFrame(const QString &fixed_frame)
Set the fixed frame in this display.
Definition: display.cpp:276
rviz::Property::setName
virtual void setName(const QString &name)
Set the name.
Definition: property.cpp:155
rviz::Display::initialize
void initialize(DisplayContext *context)
Main initialization, called after constructor, before load() or setEnabled().
Definition: display.cpp:84
rviz::Display::deleteStatus
virtual void deleteStatus(const QString &name)
Delete the status entry with the given name. This is thread-safe.
Definition: display.cpp:199
rviz::Display::queueRender
void queueRender()
Convenience function which calls context_->queueRender().
Definition: display.cpp:99
rviz::Display::Display
Display()
Definition: display.cpp:55
rviz::Display::getClassId
virtual QString getClassId() const
Return the class identifier which was used to create this instance. This version just returns whateve...
Definition: display.h:85
rviz::StatusProperty::Error
@ Error
Definition: status_property.h:46
rviz::applyVisibilityBits
void applyVisibilityBits(uint32_t bits, Ogre::SceneNode *node)
Definition: apply_visibility_bits.cpp:38
rviz::Property::getViewData
virtual QVariant getViewData(int column, int role) const
Return data appropriate for the given column (0 or 1) and role for this Property.
Definition: property.cpp:241
rviz::Display::clearStatuses
virtual void clearStatuses()
Delete all status children. This is thread-safe.
Definition: display.cpp:212
rviz::Display::associatedPanelVisibilityChange
void associatedPanelVisibilityChange(bool visible)
Definition: display.cpp:383
status_list.h
rviz::Display::onDisable
virtual void onDisable()
Derived classes override this to do the actual work of disabling themselves.
Definition: display.h:260
rviz::StatusProperty::Level
Level
Definition: status_property.h:42
rviz::Property::addChild
virtual void addChild(Property *child, int index=-1)
Add a child property.
Definition: property.cpp:356
rviz::Display::~Display
~Display() override
Definition: display.cpp:76
rviz::Display::save
void save(Config config) const override
Write this display to the given Config node.
Definition: display.cpp:249
rviz::DisplayContext::getThreadedQueue
virtual ros::CallbackQueueInterface * getThreadedQueue()=0
Return a CallbackQueue using a different thread than the main GUI one.
rviz::BoolProperty::setDisableChildrenIfFalse
void setDisableChildrenIfFalse(bool disable)
Definition: bool_property.cpp:53
rviz::Display::initialized_
bool initialized_
Definition: display.h:327
rviz::Display::fixed_frame_
QString fixed_frame_
A convenience variable equal to context_->getFixedFrame().
Definition: display.h:312
rviz::Property::getIcon
virtual QIcon getIcon() const
Definition: property.h:258
rviz::Display::associated_widget_panel_
PanelDockWidget * associated_widget_panel_
Definition: display.h:330
rviz::Display::setVisibilityBits
void setVisibilityBits(uint32_t bits)
Definition: display.cpp:338
rviz::DisplayContext::getSceneManager
virtual Ogre::SceneManager * getSceneManager() const =0
Returns the Ogre::SceneManager used for the main RenderPanel.
rviz::Property::connect
QMetaObject::Connection connect(const QObject *receiver, const char *slot, Qt::ConnectionType type=Qt::AutoConnection)
Connect changed() signal to given slot of receiver.
Definition: property.cpp:78
rviz::StatusProperty::statusColor
static QColor statusColor(Level level)
Return the color appropriate for the given status level.
Definition: status_property.cpp:81
rviz::PropertyTreeModel::emitDataChanged
void emitDataChanged(Property *property, bool emit_config_changed=true)
Definition: property_tree_model.cpp:294
rviz::Display::setStatus
virtual void setStatus(StatusProperty::Level level, const QString &name, const QString &text)
Show status level and text. This is thread-safe.
Definition: display.cpp:176
rviz::Display::associated_widget_
QWidget * associated_widget_
Definition: display.h:329
rviz::StatusList
Definition: status_list.h:36
rviz::Display::setIcon
void setIcon(const QIcon &icon) override
Set the Display's icon.
Definition: display.cpp:393
rviz::Property::setValue
virtual bool setValue(const QVariant &new_value)
Set the new value for this property. Returns true if the new value is different from the old value,...
Definition: property.cpp:134
rviz::Display::setEnabled
void setEnabled(bool enabled)
Enable or disable this Display.
Definition: display.cpp:259
rviz
Definition: add_display_dialog.cpp:54
rviz::Display::scene_node_
Ogre::SceneNode * scene_node_
The Ogre::SceneNode to hold all 3D scene elements shown by this Display.
Definition: display.h:295
rviz::StatusProperty::getLevel
virtual Level getLevel() const
Definition: status_property.h:73
rviz::Display::fixedFrameChanged
virtual void fixedFrameChanged()
Called by setFixedFrame(). Override to respond to changes to fixed_frame_.
Definition: display.h:270
rviz::Display::timeSignal
void timeSignal(ros::Time time, QPrivateSignal)
rviz::StatusList::setStatus
void setStatus(Level level, const QString &name, const QString &text)
Definition: status_list.cpp:50
rviz::StatusProperty::Ok
@ Ok
Definition: status_property.h:44
rviz::Display::onInitialize
virtual void onInitialize()
Override this function to do subclass-specific initialization.
Definition: display.h:250
rviz::StatusProperty::Warn
@ Warn
Definition: status_property.h:45
rviz::Property::model_
PropertyTreeModel * model_
Pointer to the PropertyTreeModel managing this property tree.
Definition: property.h:560
rviz::PanelDockWidget::closed
void closed()
rviz::StatusList::clear
void clear()
Definition: status_list.cpp:85
rviz::Display::scene_manager_
Ogre::SceneManager * scene_manager_
A convenience variable equal to context_->getSceneManager().
Definition: display.h:292
rviz::Display::getViewData
QVariant getViewData(int column, int role) const override
Return data appropriate for the given column (0 or 1) and role for this Display.
Definition: display.cpp:107
rviz::DisplayContext::getFixedFrame
virtual QString getFixedFrame() const =0
Return the fixed frame name.
rviz::Display::load
void load(const Config &config) override
Load the settings for this display from the given Config node, which must be a map.
Definition: display.cpp:231
property_tree_model.h
rviz::DisplayContext
Pure-virtual base class for objects which give Display subclasses context in which to work.
Definition: display_context.h:81
rviz::Display::unsetVisibilityBits
void unsetVisibilityBits(uint32_t bits)
Definition: display.cpp:344
ros::NodeHandle::setCallbackQueue
void setCallbackQueue(CallbackQueueInterface *queue)
rviz::Display::setName
void setName(const QString &name) override
Overridden from Property to set associated widget title to the new name.
Definition: display.cpp:402
rviz::StatusList::deleteStatus
void deleteStatus(const QString &name)
Definition: status_list.cpp:75
rviz::Property::getViewFlags
virtual Qt::ItemFlags getViewFlags(int column) const
Return item flags appropriate for the given column (0 or 1) for this Property.
Definition: property.cpp:290
rviz::Display::onEnableChanged
virtual void onEnableChanged()
Definition: display.cpp:295
rviz::DisplayContext::getWindowManager
virtual WindowManagerInterface * getWindowManager() const =0
Return the window manager, if any.
rviz::Display::getViewFlags
Qt::ItemFlags getViewFlags(int column) const override
Return item flags appropriate for the given column (0 or 1) for this Display.
Definition: display.cpp:171
display.h
rviz::Property::getName
virtual QString getName() const
Return the name of this Property as a QString.
Definition: property.cpp:164
rviz::Display::context_
DisplayContext * context_
This DisplayContext pointer is the main connection a Display has into the rest of rviz....
Definition: display.h:287
ros::Time
rviz::WindowManagerInterface::addPane
virtual PanelDockWidget * addPane(const QString &name, QWidget *pane, Qt::DockWidgetArea area=Qt::LeftDockWidgetArea, bool floating=false)=0
rviz::Display::clearStatusesInternal
void clearStatusesInternal()
Definition: display.cpp:217
rviz::Display::reset
virtual void reset()
Called to tell the display to clear its state.
Definition: display.cpp:290
rviz::Property::changed
void changed()
Emitted by setValue() just after the value has changed.
rviz::Display::onEnable
virtual void onEnable()
Derived classes override this to do the actual work of enabling themselves.
Definition: display.h:255
rviz::Property::save
virtual void save(Config config) const
Write the value of this property and/or its children into the given Config reference.
Definition: property.cpp:492
rviz::Display::threaded_nh_
ros::NodeHandle threaded_nh_
A NodeHandle whose CallbackQueue is run from a different thread than the GUI.
Definition: display.h:305
rviz::Display::setAssociatedWidget
void setAssociatedWidget(QWidget *widget)
Associate the given widget with this Display.
Definition: display.cpp:350
display_context.h
rviz::WindowManagerInterface
Definition: window_manager_interface.h:40
rviz::Display::setStatusInternal
void setStatusInternal(int level, const QString &name, const QString &text)
Definition: display.cpp:182
rviz::Property::icon_
QIcon icon_
Definition: property.h:569
rviz::Display::visibility_bits_
uint32_t visibility_bits_
Definition: display.h:328
rviz::PanelDockWidget::setIcon
void setIcon(const QIcon &icon)
Definition: panel_dock_widget.cpp:80
rviz::PanelDockWidget::setWindowTitle
void setWindowTitle(const QString &title)
Definition: panel_dock_widget.cpp:73
config
config
rviz::Property::load
virtual void load(const Config &config)
Load the value of this property and/or its children from the given Config reference.
Definition: property.cpp:442
rviz::StatusProperty::statusIcon
QIcon statusIcon(Level level) const
Definition: status_property.cpp:87
rviz::Config
Configuration data storage class.
Definition: config.h:124
rviz::Display::update_nh_
ros::NodeHandle update_nh_
A NodeHandle whose CallbackQueue is run from the main GUI thread (the "update" thread).
Definition: display.h:300


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust, William Woodall
autogenerated on Fri Dec 13 2024 03:31:02