selection_panel.cpp
Go to the documentation of this file.
00001 
00002 /*
00003  * Copyright (c) 2008, Willow Garage, Inc.
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions are met:
00008  *
00009  *     * Redistributions of source code must retain the above copyright
00010  *       notice, this list of conditions and the following disclaimer.
00011  *     * Redistributions in binary form must reproduce the above copyright
00012  *       notice, this list of conditions and the following disclaimer in the
00013  *       documentation and/or other materials provided with the distribution.
00014  *     * Neither the name of the Willow Garage, Inc. nor the names of its
00015  *       contributors may be used to endorse or promote products derived from
00016  *       this software without specific prior written permission.
00017  *
00018  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00022  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00028  * POSSIBILITY OF SUCH DAMAGE.
00029  */
00030 
00031 #include <QTimer>
00032 
00033 #include "visualization_manager.h"
00034 #include "selection/selection_manager.h"
00035 #include "properties/property.h"
00036 #include "properties/property_manager.h"
00037 
00038 #include "selection_panel.h"
00039 
00040 namespace rviz
00041 {
00042 
00043 SelectionPanel::SelectionPanel( QWidget* parent )
00044   : PropertyTreeWidget( parent )
00045   , manager_( NULL )
00046   , setting_( false )
00047 {
00048   // Ignore change signals emitted by the tree widget. None of the
00049   // selection properties are editable, so the only change signals are
00050   // spurious and should be ignored.
00051   setIgnoreChanges( true );
00052 
00053   property_manager_ = new PropertyManager();
00054   property_manager_->setPropertyTreeWidget( this );
00055 }
00056 
00057 SelectionPanel::~SelectionPanel()
00058 {
00059   delete property_manager_;
00060 }
00061 
00062 void SelectionPanel::initialize(VisualizationManager* manager)
00063 {
00064   manager_ = manager;
00065 
00066   SelectionManager* sel_man = manager_->getSelectionManager();
00067 
00068   connect( sel_man, SIGNAL( selectionAdded( const M_Picked& )), this, SLOT( onSelectionAdded( const M_Picked& )));
00069   connect( sel_man, SIGNAL( selectionRemoved( const M_Picked& )), this, SLOT( onSelectionRemoved( const M_Picked& )));
00070   connect( sel_man, SIGNAL( selectionSet( const M_Picked&, const M_Picked& )), this, SLOT( onSelectionSet() ));
00071   connect( sel_man, SIGNAL( selectionSetting() ), this, SLOT( onSelectionSetting() ));
00072 
00073   QTimer* timer = new QTimer( this );
00074   connect( timer, SIGNAL( timeout() ), this, SLOT( onUpdate() ));
00075   timer->start( 200 );
00076 }
00077 
00078 void SelectionPanel::onSelectionRemoved( const M_Picked& removed )
00079 {
00080   if (setting_)
00081   {
00082     return;
00083   }
00084 
00085   SelectionManager* sel_manager = manager_->getSelectionManager();
00086 
00087   M_Picked::const_iterator it = removed.begin();
00088   M_Picked::const_iterator end = removed.end();
00089   for (; it != end; ++it)
00090   {
00091     const Picked& picked = it->second;
00092     SelectionHandlerPtr handler = sel_manager->getHandler(picked.handle);
00093     ROS_ASSERT(handler);
00094 
00095     handler->destroyProperties(picked, property_manager_);
00096   }
00097 
00098   //property_grid_->Sort(property_grid_->GetRoot());
00099 }
00100 
00101 void SelectionPanel::onSelectionAdded( const M_Picked& added )
00102 {
00103   SelectionManager* sel_manager = manager_->getSelectionManager();
00104 
00105   M_Picked::const_iterator it = added.begin();
00106   M_Picked::const_iterator end = added.end();
00107   for (; it != end; ++it)
00108   {
00109     const Picked& picked = it->second;
00110     SelectionHandlerPtr handler = sel_manager->getHandler(picked.handle);
00111     ROS_ASSERT(handler);
00112 
00113     handler->createProperties(picked, property_manager_);
00114   }
00115   sortItems( 0, Qt::AscendingOrder );
00116 }
00117 
00118 void SelectionPanel::onSelectionSetting()
00119 {
00120   setting_ = true;
00121 
00122   property_manager_->clear();
00123 }
00124 
00125 void SelectionPanel::onSelectionSet()
00126 {
00127   setting_ = false;
00128 }
00129 
00130 void SelectionPanel::onUpdate()
00131 {
00132   SelectionManager* sel_manager = manager_->getSelectionManager();
00133   const M_Picked& selection = sel_manager->getSelection();
00134   M_Picked::const_iterator it = selection.begin();
00135   M_Picked::const_iterator end = selection.end();
00136   for (; it != end; ++it)
00137   {
00138     CollObjectHandle handle = it->first;
00139     SelectionHandlerPtr handler = sel_manager->getHandler(handle);
00140 
00141     handler->updateProperties();
00142   }
00143 
00144   property_manager_->update();
00145   //property_grid_->Sort(property_grid_->GetRoot());
00146 }
00147 
00148 } // namespace rviz


rviz
Author(s): Dave Hershberger, Josh Faust
autogenerated on Mon Jan 6 2014 11:54:32