00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
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
00059
00060
00061 #if wxMAJOR_VERSION == 2 and wxMINOR_VERSION == 8 // If wxWidgets 2.8.x
00062
00063 property_grid_->SetCaptionForegroundColour( *wxWHITE );
00064 #endif
00065
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
00130
00131
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
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
00181
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
00187 property_grid_->Sort();
00188 #endif
00189
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
00227
00228 property_grid_->Thaw();
00229 }
00230
00231 }