$search
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 "selection_panel.h" 00032 #include "visualization_manager.h" 00033 #include "selection/selection_manager.h" 00034 #include "properties/property.h" 00035 #include "properties/property_manager.h" 00036 00037 #include <wx/timer.h> 00038 00039 #include <wx/propgrid/propgrid.h> 00040 #include <boost/bind.hpp> 00041 00042 namespace rviz 00043 { 00044 00045 SelectionPanel::SelectionPanel( wxWindow* parent ) 00046 : wxPanel( parent, wxID_ANY ) 00047 , manager_(NULL) 00048 , setting_(false) 00049 { 00050 wxBoxSizer* top_sizer = new wxBoxSizer(wxVERTICAL); 00051 00052 property_grid_ = new wxPropertyGrid( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxPG_SPLITTER_AUTO_CENTER | wxPG_DEFAULT_STYLE ); 00053 top_sizer->Add(property_grid_, 1, wxEXPAND, 5); 00054 SetSizer(top_sizer); 00055 00056 property_grid_->SetExtraStyle(wxPG_EX_DISABLE_TLP_TRACKING); 00057 property_grid_->SetCaptionBackgroundColour( wxColour( 4, 89, 127 ) ); 00058 /* START_WX-2.9_COMPAT_CODE 00059 This code is related to ticket: https://code.ros.org/trac/ros-pkg/ticket/5157 00060 */ 00061 #if wxMAJOR_VERSION == 2 and wxMINOR_VERSION == 8 // If wxWidgets 2.8.x 00062 // This function is no longer available in wxPropgrid for wx-2.9 00063 property_grid_->SetCaptionForegroundColour( *wxWHITE ); 00064 #endif 00065 /* END_WX-2.9_COMPAT_CODE */ 00066 00067 property_grid_->Connect( wxEVT_PG_CHANGING, wxPropertyGridEventHandler( SelectionPanel::onPropertyChanging ), NULL, this ); 00068 property_grid_->Connect( wxEVT_PG_CHANGED, wxPropertyGridEventHandler( SelectionPanel::onPropertyChanged ), NULL, this ); 00069 property_grid_->Connect( wxEVT_PG_SELECTED, wxPropertyGridEventHandler( SelectionPanel::onPropertySelected ), NULL, this ); 00070 00071 property_manager_ = new PropertyManager(); 00072 property_manager_->setPropertyGrid(property_grid_); 00073 } 00074 00075 SelectionPanel::~SelectionPanel() 00076 { 00077 Disconnect( refresh_timer_->GetId(), wxEVT_TIMER, wxTimerEventHandler( SelectionPanel::onUpdate ), NULL, this ); 00078 refresh_timer_->Stop(); 00079 delete refresh_timer_; 00080 00081 delete property_manager_; 00082 00083 property_grid_->Disconnect( wxEVT_PG_CHANGING, wxPropertyGridEventHandler( SelectionPanel::onPropertyChanging ), NULL, this ); 00084 property_grid_->Disconnect( wxEVT_PG_CHANGED, wxPropertyGridEventHandler( SelectionPanel::onPropertyChanged ), NULL, this ); 00085 property_grid_->Disconnect( wxEVT_PG_SELECTED, wxPropertyGridEventHandler( SelectionPanel::onPropertySelected ), NULL, this ); 00086 property_grid_->Destroy(); 00087 } 00088 00089 void SelectionPanel::initialize(VisualizationManager* manager) 00090 { 00091 manager_ = manager; 00092 00093 manager_->getSelectionManager()->getSelectionAddedSignal().connect( boost::bind( &SelectionPanel::onSelectionAdded, this, _1 ) ); 00094 manager_->getSelectionManager()->getSelectionRemovedSignal().connect( boost::bind( &SelectionPanel::onSelectionRemoved, this, _1 ) ); 00095 manager_->getSelectionManager()->getSelectionSetSignal().connect( boost::bind( &SelectionPanel::onSelectionSet, this, _1 ) ); 00096 manager_->getSelectionManager()->getSelectionSettingSignal().connect( boost::bind( &SelectionPanel::onSelectionSetting, this, _1 ) ); 00097 00098 refresh_timer_ = new wxTimer( this ); 00099 refresh_timer_->Start( 200 ); 00100 Connect( refresh_timer_->GetId(), wxEVT_TIMER, wxTimerEventHandler( SelectionPanel::onUpdate ), NULL, this ); 00101 } 00102 00103 void SelectionPanel::onPropertyChanging( wxPropertyGridEvent& event ) 00104 { 00105 wxPGProperty* property = event.GetProperty(); 00106 00107 if ( !property ) 00108 { 00109 return; 00110 } 00111 00112 property_manager_->propertyChanging( event ); 00113 } 00114 00115 void SelectionPanel::onPropertyChanged( wxPropertyGridEvent& event ) 00116 { 00117 wxPGProperty* property = event.GetProperty(); 00118 00119 if ( !property ) 00120 { 00121 return; 00122 } 00123 00124 property_manager_->propertyChanged( event ); 00125 } 00126 00127 void SelectionPanel::onPropertySelected( wxPropertyGridEvent& event ) 00128 { 00129 // Hack to fix (corrollary of) bug #4885. If I put this in the 00130 // constructor or in initialize() this has no effect. Similarly, 00131 // GetSizer()->SetMinSize() has no effect. -hersh 00132 wxSize size = GetMinSize(); 00133 size.SetHeight( 30 ); 00134 SetMinSize( size ); 00135 } 00136 00137 void SelectionPanel::onSelectionRemoved(const SelectionRemovedArgs& args) 00138 { 00139 if (setting_) 00140 { 00141 return; 00142 } 00143 00144 property_grid_->Freeze(); 00145 00146 SelectionManager* sel_manager = manager_->getSelectionManager(); 00147 00148 M_Picked::const_iterator it = args.removed_.begin(); 00149 M_Picked::const_iterator end = args.removed_.end(); 00150 for (; it != end; ++it) 00151 { 00152 const Picked& picked = it->second; 00153 SelectionHandlerPtr handler = sel_manager->getHandler(picked.handle); 00154 ROS_ASSERT(handler); 00155 00156 handler->destroyProperties(picked, property_manager_); 00157 } 00158 00159 //property_grid_->Sort(property_grid_->GetRoot()); 00160 00161 property_grid_->Thaw(); 00162 } 00163 00164 void SelectionPanel::onSelectionAdded(const SelectionAddedArgs& args) 00165 { 00166 property_grid_->Freeze(); 00167 00168 SelectionManager* sel_manager = manager_->getSelectionManager(); 00169 00170 M_Picked::const_iterator it = args.added_.begin(); 00171 M_Picked::const_iterator end = args.added_.end(); 00172 for (; it != end; ++it) 00173 { 00174 const Picked& picked = it->second; 00175 SelectionHandlerPtr handler = sel_manager->getHandler(picked.handle); 00176 ROS_ASSERT(handler); 00177 00178 handler->createProperties(picked, property_manager_); 00179 } 00180 /* START_WX-2.9_COMPAT_CODE 00181 This code is related to ticket: https://code.ros.org/trac/ros-pkg/ticket/5157 00182 */ 00183 #if wxMAJOR_VERSION == 2 and wxMINOR_VERSION == 8 // If wxWidgets 2.8.x 00184 property_grid_->Sort(property_grid_->GetRoot()); 00185 #else 00186 // This is the new way to sort a wxPropertyGrid 00187 property_grid_->Sort(); 00188 #endif 00189 /* END_WX-2.9_COMPAT_CODE */ 00190 00191 property_grid_->Thaw(); 00192 } 00193 00194 void SelectionPanel::onSelectionSetting(const SelectionSettingArgs& args) 00195 { 00196 setting_ = true; 00197 00198 property_grid_->Freeze(); 00199 property_manager_->clear(); 00200 } 00201 00202 void SelectionPanel::onSelectionSet(const SelectionSetArgs& args) 00203 { 00204 setting_ = false; 00205 00206 property_grid_->Thaw(); 00207 } 00208 00209 void SelectionPanel::onUpdate( wxTimerEvent& event ) 00210 { 00211 property_grid_->Freeze(); 00212 00213 SelectionManager* sel_manager = manager_->getSelectionManager(); 00214 const M_Picked& selection = sel_manager->getSelection(); 00215 M_Picked::const_iterator it = selection.begin(); 00216 M_Picked::const_iterator end = selection.end(); 00217 for (; it != end; ++it) 00218 { 00219 CollObjectHandle handle = it->first; 00220 SelectionHandlerPtr handler = sel_manager->getHandler(handle); 00221 00222 handler->updateProperties(); 00223 } 00224 00225 property_manager_->update(); 00226 //property_grid_->Sort(property_grid_->GetRoot()); 00227 00228 property_grid_->Thaw(); 00229 } 00230 00231 } // namespace rviz