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 property_grid_->SetCaptionForegroundColour( *wxWHITE );
00059
00060 property_grid_->Connect( wxEVT_PG_CHANGING, wxPropertyGridEventHandler( SelectionPanel::onPropertyChanging ), NULL, this );
00061 property_grid_->Connect( wxEVT_PG_CHANGED, wxPropertyGridEventHandler( SelectionPanel::onPropertyChanged ), NULL, this );
00062 property_grid_->Connect( wxEVT_PG_SELECTED, wxPropertyGridEventHandler( SelectionPanel::onPropertySelected ), NULL, this );
00063
00064 property_manager_ = new PropertyManager();
00065 property_manager_->setPropertyGrid(property_grid_);
00066 }
00067
00068 SelectionPanel::~SelectionPanel()
00069 {
00070 Disconnect( refresh_timer_->GetId(), wxEVT_TIMER, wxTimerEventHandler( SelectionPanel::onUpdate ), NULL, this );
00071 refresh_timer_->Stop();
00072 delete refresh_timer_;
00073
00074 delete property_manager_;
00075
00076 property_grid_->Disconnect( wxEVT_PG_CHANGING, wxPropertyGridEventHandler( SelectionPanel::onPropertyChanging ), NULL, this );
00077 property_grid_->Disconnect( wxEVT_PG_CHANGED, wxPropertyGridEventHandler( SelectionPanel::onPropertyChanged ), NULL, this );
00078 property_grid_->Disconnect( wxEVT_PG_SELECTED, wxPropertyGridEventHandler( SelectionPanel::onPropertySelected ), NULL, this );
00079 property_grid_->Destroy();
00080 }
00081
00082 void SelectionPanel::initialize(VisualizationManager* manager)
00083 {
00084 manager_ = manager;
00085
00086 manager_->getSelectionManager()->getSelectionAddedSignal().connect( boost::bind( &SelectionPanel::onSelectionAdded, this, _1 ) );
00087 manager_->getSelectionManager()->getSelectionRemovedSignal().connect( boost::bind( &SelectionPanel::onSelectionRemoved, this, _1 ) );
00088 manager_->getSelectionManager()->getSelectionSetSignal().connect( boost::bind( &SelectionPanel::onSelectionSet, this, _1 ) );
00089 manager_->getSelectionManager()->getSelectionSettingSignal().connect( boost::bind( &SelectionPanel::onSelectionSetting, this, _1 ) );
00090
00091 refresh_timer_ = new wxTimer( this );
00092 refresh_timer_->Start( 200 );
00093 Connect( refresh_timer_->GetId(), wxEVT_TIMER, wxTimerEventHandler( SelectionPanel::onUpdate ), NULL, this );
00094 }
00095
00096 void SelectionPanel::onPropertyChanging( wxPropertyGridEvent& event )
00097 {
00098 wxPGProperty* property = event.GetProperty();
00099
00100 if ( !property )
00101 {
00102 return;
00103 }
00104
00105 property_manager_->propertyChanging( event );
00106 }
00107
00108 void SelectionPanel::onPropertyChanged( wxPropertyGridEvent& event )
00109 {
00110 wxPGProperty* property = event.GetProperty();
00111
00112 if ( !property )
00113 {
00114 return;
00115 }
00116
00117 property_manager_->propertyChanged( event );
00118 }
00119
00120 void SelectionPanel::onPropertySelected( wxPropertyGridEvent& event )
00121 {
00122
00123
00124
00125 wxSize size = GetMinSize();
00126 size.SetHeight( 30 );
00127 SetMinSize( size );
00128 }
00129
00130 void SelectionPanel::onSelectionRemoved(const SelectionRemovedArgs& args)
00131 {
00132 if (setting_)
00133 {
00134 return;
00135 }
00136
00137 property_grid_->Freeze();
00138
00139 SelectionManager* sel_manager = manager_->getSelectionManager();
00140
00141 M_Picked::const_iterator it = args.removed_.begin();
00142 M_Picked::const_iterator end = args.removed_.end();
00143 for (; it != end; ++it)
00144 {
00145 const Picked& picked = it->second;
00146 SelectionHandlerPtr handler = sel_manager->getHandler(picked.handle);
00147 ROS_ASSERT(handler);
00148
00149 handler->destroyProperties(picked, property_manager_);
00150 }
00151
00152
00153
00154 property_grid_->Thaw();
00155 }
00156
00157 void SelectionPanel::onSelectionAdded(const SelectionAddedArgs& args)
00158 {
00159 property_grid_->Freeze();
00160
00161 SelectionManager* sel_manager = manager_->getSelectionManager();
00162
00163 M_Picked::const_iterator it = args.added_.begin();
00164 M_Picked::const_iterator end = args.added_.end();
00165 for (; it != end; ++it)
00166 {
00167 const Picked& picked = it->second;
00168 SelectionHandlerPtr handler = sel_manager->getHandler(picked.handle);
00169 ROS_ASSERT(handler);
00170
00171 handler->createProperties(picked, property_manager_);
00172 }
00173
00174 property_grid_->Sort(property_grid_->GetRoot());
00175
00176 property_grid_->Thaw();
00177 }
00178
00179 void SelectionPanel::onSelectionSetting(const SelectionSettingArgs& args)
00180 {
00181 setting_ = true;
00182
00183 property_grid_->Freeze();
00184 property_manager_->clear();
00185 }
00186
00187 void SelectionPanel::onSelectionSet(const SelectionSetArgs& args)
00188 {
00189 setting_ = false;
00190
00191 property_grid_->Thaw();
00192 }
00193
00194 void SelectionPanel::onUpdate( wxTimerEvent& event )
00195 {
00196 property_grid_->Freeze();
00197
00198 SelectionManager* sel_manager = manager_->getSelectionManager();
00199 const M_Picked& selection = sel_manager->getSelection();
00200 M_Picked::const_iterator it = selection.begin();
00201 M_Picked::const_iterator end = selection.end();
00202 for (; it != end; ++it)
00203 {
00204 CollObjectHandle handle = it->first;
00205 SelectionHandlerPtr handler = sel_manager->getHandler(handle);
00206
00207 handler->updateProperties();
00208 }
00209
00210 property_manager_->update();
00211
00212
00213 property_grid_->Thaw();
00214 }
00215
00216 }