display_group_visibility_property.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  * display_visibility_manager.cpp
31  *
32  * Created on: Aug 27, 2012
33  * Author: gossow
34  */
35 
37 
39 #include "rviz/display_context.h"
40 #include "rviz/bit_allocator.h"
41 #include "rviz/display.h"
42 #include "rviz/display_group.h"
43 
44 namespace rviz
45 {
46 
47 
49  uint32_t vis_bit,
50  DisplayGroup* display_group,
51  Display* parent_display,
52  const QString& name,
53  bool default_value,
54  const QString& description,
55  Property* parent,
56  const char *changed_slot,
57  QObject* receiver )
58 : DisplayVisibilityProperty( vis_bit, display_group, name, default_value, description, parent, changed_slot, receiver )
59 , display_group_(display_group)
60 , parent_display_(parent_display)
61 {
62  connect( display_group, SIGNAL( displayAdded( rviz::Display* ) ), this, SLOT( onDisplayAdded( rviz::Display* ) ));
63  connect( display_group, SIGNAL( displayRemoved( rviz::Display* ) ), this, SLOT( onDisplayRemoved( rviz::Display* ) ));
64 
65  for( int i = 0; i < display_group->numDisplays(); i++ )
66  {
67  rviz::Display* display = display_group->getDisplayAt( i );
68  if ( display != parent_display )
69  {
70  onDisplayAdded( display );
71  }
72  }
73 
75 }
76 
78 {
80  std::map<rviz::Display*, DisplayVisibilityProperty*>::iterator it = disp_vis_props_.begin();
81  for( ; it != disp_vis_props_.end(); it++ )
82  {
83  it->second->update();
84  }
85 }
86 
88 {
89  // remove and re-add everything in our property list
90  // in the same order as it appears in the display group
91  for( int i = 0; i < display_group_->numDisplays(); i++ )
92  {
93  rviz::Display* display = display_group_->getDisplayAt( i );
94  std::map<rviz::Display*, DisplayVisibilityProperty*>::iterator it = disp_vis_props_.find( display );
95  if ( it != disp_vis_props_.end() )
96  {
97  takeChild( it->second );
98  addChild( it->second );
99  }
100  }
101 }
102 
104 {
105  DisplayGroup* display_group = qobject_cast<DisplayGroup*>( display );
106  DisplayVisibilityProperty* vis_prop;
107  if( display_group )
108  {
109  vis_prop = new DisplayGroupVisibilityProperty( vis_bit_, display_group, parent_display_, "", true, "Uncheck to hide everything in this Display Group", this );
110  }
111  else
112  {
113  vis_prop = new DisplayVisibilityProperty( vis_bit_, display, "", true, "Show or hide this Display", this );
114  }
115  disp_vis_props_[ display ] = vis_prop;
116  sortDisplayList();
117 }
118 
120 {
121  std::map<rviz::Display*, DisplayVisibilityProperty*>::iterator it = disp_vis_props_.find( display );
122  if ( it != disp_vis_props_.end() )
123  {
124  Property* child = takeChild( it->second );
125  child->setParent( NULL );
126  delete child;
127  disp_vis_props_.erase( display );
128  }
129 }
130 
131 
133 {
134 }
135 
136 }
#define NULL
Definition: global.h:37
void setDisableChildrenIfFalse(bool disable)
A single element of a property tree, with a name, value, description, and possibly children...
Definition: property.h:100
virtual int numDisplays() const
Return the number of child Displays.
DisplayVisibilityProperty(uint32_t vis_bit, Display *display, const QString &name=QString(), bool default_value=false, const QString &description=QString(), Property *parent=0, const char *changed_slot=0, QObject *receiver=0)
std::map< rviz::Display *, DisplayVisibilityProperty * > disp_vis_props_
Property * takeChild(Property *child)
Remove a given child object and return a pointer to it.
Definition: property.cpp:316
DisplayGroupVisibilityProperty(uint32_t vis_bit, DisplayGroup *display_group, Display *parent_display, const QString &name=QString(), bool default_value=false, const QString &description=QString(), Property *parent=0, const char *changed_slot=0, QObject *receiver=0)
void setParent(Property *new_parent)
Set parent property, without telling the parent.
Definition: property.cpp:231
A Display object which stores other Displays as children.
Definition: display_group.h:47
virtual Display * getDisplayAt(int index) const
Return the index-th Display in this group, or NULL if the index is invalid.
virtual void addChild(Property *child, int index=-1)
Add a child property.
Definition: property.cpp:350


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Wed Aug 28 2019 04:01:50