display_group_visibility_property.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2012, Willow Garage, Inc.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 /*
00030  * display_visibility_manager.cpp
00031  *
00032  *  Created on: Aug 27, 2012
00033  *      Author: gossow
00034  */
00035 
00036 #include "display_group_visibility_property.h"
00037 
00038 #include "rviz/properties/bool_property.h"
00039 #include "rviz/display_context.h"
00040 #include "rviz/bit_allocator.h"
00041 #include "rviz/display.h"
00042 #include "rviz/display_group.h"
00043 
00044 namespace rviz
00045 {
00046 
00047 
00048 DisplayGroupVisibilityProperty::DisplayGroupVisibilityProperty(
00049     uint32_t vis_bit,
00050     DisplayGroup* display_group,
00051     Display* parent_display,
00052     const QString& name,
00053     bool default_value,
00054     const QString& description,
00055     Property* parent,
00056     const char *changed_slot,
00057     QObject* receiver )
00058 : DisplayVisibilityProperty( vis_bit, display_group, name, default_value, description, parent, changed_slot, receiver )
00059 , display_group_(display_group)
00060 , parent_display_(parent_display)
00061 {
00062   connect( display_group, SIGNAL( displayAdded( rviz::Display* ) ), this, SLOT( onDisplayAdded( rviz::Display* ) ));
00063   connect( display_group, SIGNAL( displayRemoved( rviz::Display* ) ), this, SLOT( onDisplayRemoved( rviz::Display* ) ));
00064 
00065   for( int i = 0; i < display_group->numDisplays(); i++ )
00066   {
00067     rviz::Display* display = display_group->getDisplayAt( i );
00068     if ( display != parent_display )
00069     {
00070       onDisplayAdded( display );
00071     }
00072   }
00073 
00074   setDisableChildrenIfFalse(true);
00075 }
00076 
00077 void DisplayGroupVisibilityProperty::update()
00078 {
00079   DisplayVisibilityProperty::update();
00080   std::map<rviz::Display*, DisplayVisibilityProperty*>::iterator it = disp_vis_props_.begin();
00081   for( ; it != disp_vis_props_.end(); it++ )
00082   {
00083     it->second->update();
00084   }
00085 }
00086 
00087 void DisplayGroupVisibilityProperty::sortDisplayList()
00088 {
00089   // remove and re-add everything in our property list
00090   // in the same order as it appears in the display group
00091   for( int i = 0; i < display_group_->numDisplays(); i++ )
00092   {
00093     rviz::Display* display = display_group_->getDisplayAt( i );
00094     std::map<rviz::Display*, DisplayVisibilityProperty*>::iterator it = disp_vis_props_.find( display );
00095     if ( it != disp_vis_props_.end() )
00096     {
00097       takeChild( it->second );
00098       addChild( it->second );
00099     }
00100   }
00101 }
00102 
00103 void DisplayGroupVisibilityProperty::onDisplayAdded( Display* display )
00104 {
00105   DisplayGroup* display_group = qobject_cast<DisplayGroup*>( display );
00106   DisplayVisibilityProperty* vis_prop;
00107   if( display_group )
00108   {
00109     vis_prop = new DisplayGroupVisibilityProperty( vis_bit_, display_group, parent_display_, "", true, "Uncheck to hide everything in this Display Group", this );
00110   }
00111   else
00112   {
00113     vis_prop = new DisplayVisibilityProperty( vis_bit_, display, "", true, "Show or hide this Display", this );
00114   }
00115   disp_vis_props_[ display ] = vis_prop;
00116   sortDisplayList();
00117 }
00118 
00119 void DisplayGroupVisibilityProperty::onDisplayRemoved( Display* display )
00120 {
00121   std::map<rviz::Display*, DisplayVisibilityProperty*>::iterator it = disp_vis_props_.find( display );
00122   if ( it != disp_vis_props_.end() )
00123   {
00124     Property* child = takeChild( it->second );
00125     child->setParent( NULL );
00126     delete child;
00127     disp_vis_props_.erase( display );
00128   }
00129 }
00130 
00131 
00132 DisplayGroupVisibilityProperty::~DisplayGroupVisibilityProperty()
00133 {
00134 }
00135 
00136 }


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Thu Aug 27 2015 15:02:27