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 "tool_properties_panel.h"
00032 #include "visualization_manager.h"
00033 #include "display.h"
00034 #include "display_wrapper.h"
00035 #include "new_display_dialog.h"
00036 #include "properties/property.h"
00037 #include "properties/property_manager.h"
00038 #include "plugin/type_registry.h"
00039 #include "plugin/plugin_manager.h"
00040 #include "plugin/plugin.h"
00041 #include "tools/tool.h"
00042
00043 #include <wx/propgrid/propgrid.h>
00044 #include <wx/msgdlg.h>
00045 #include <wx/confbase.h>
00046 #include <wx/artprov.h>
00047
00048 #include <boost/bind.hpp>
00049
00050 static const wxString PROPERTY_GRID_CONFIG(wxT("Property Grid State"));
00051
00052 namespace rviz
00053 {
00054
00055 ToolPropertiesPanel::ToolPropertiesPanel( wxWindow* parent )
00056 : wxPanel( parent, wxID_ANY )
00057 , manager_(NULL)
00058 {
00059 wxBoxSizer* top_sizer = new wxBoxSizer(wxVERTICAL);
00060
00061 property_grid_ = new wxPropertyGrid( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxPG_SPLITTER_AUTO_CENTER | wxPG_DEFAULT_STYLE );
00062 top_sizer->Add(property_grid_, 1, wxEXPAND, 5);
00063 SetSizer(top_sizer);
00064
00065 property_grid_->SetExtraStyle(wxPG_EX_DISABLE_TLP_TRACKING);
00066 property_grid_->SetCaptionBackgroundColour( wxColour( 4, 89, 127 ) );
00067 property_grid_->SetCaptionForegroundColour( *wxWHITE );
00068
00069 property_grid_->Connect( wxEVT_PG_CHANGING, wxPropertyGridEventHandler( ToolPropertiesPanel::onPropertyChanging ), NULL, this );
00070 property_grid_->Connect( wxEVT_PG_CHANGED, wxPropertyGridEventHandler( ToolPropertiesPanel::onPropertyChanged ), NULL, this );
00071 property_grid_->Connect( wxEVT_PG_SELECTED, wxPropertyGridEventHandler( ToolPropertiesPanel::onPropertySelected ), NULL, this );
00072 }
00073
00074 ToolPropertiesPanel::~ToolPropertiesPanel()
00075 {
00076 property_grid_->Disconnect( wxEVT_PG_CHANGING, wxPropertyGridEventHandler( ToolPropertiesPanel::onPropertyChanging ), NULL, this );
00077 property_grid_->Disconnect( wxEVT_PG_CHANGED, wxPropertyGridEventHandler( ToolPropertiesPanel::onPropertyChanged ), NULL, this );
00078 property_grid_->Disconnect( wxEVT_PG_SELECTED, wxPropertyGridEventHandler( ToolPropertiesPanel::onPropertySelected ), NULL, this );
00079 property_grid_->Destroy();
00080 }
00081
00082 void ToolPropertiesPanel::initialize(VisualizationManager* manager)
00083 {
00084 manager_ = manager;
00085
00086 manager_->getToolPropertyManager()->setPropertyGrid(property_grid_);
00087 manager_->getToolAddedSignal().connect(boost::bind(&ToolPropertiesPanel::onToolAdded, this, _1));
00088 }
00089
00090 void ToolPropertiesPanel::onToolAdded(Tool* tool)
00091 {
00092 if (tool->hasProperties())
00093 {
00094 std::string name = tool->getName();
00095 CategoryPropertyWPtr cat = manager_->getToolPropertyManager()->createCategory(name, "", CategoryPropertyWPtr(), tool);
00096 tool->enumerateProperties(manager_->getToolPropertyManager(), cat);
00097 }
00098 }
00099
00100 void ToolPropertiesPanel::onPropertyChanging( wxPropertyGridEvent& event )
00101 {
00102 wxPGProperty* property = event.GetProperty();
00103
00104 if ( !property )
00105 {
00106 return;
00107 }
00108
00109 manager_->getToolPropertyManager()->propertyChanging( event );
00110 }
00111
00112 void ToolPropertiesPanel::onPropertyChanged( wxPropertyGridEvent& event )
00113 {
00114 wxPGProperty* property = event.GetProperty();
00115
00116 if ( !property )
00117 {
00118 return;
00119 }
00120
00121 manager_->getToolPropertyManager()->propertyChanged( event );
00122 }
00123
00124 void ToolPropertiesPanel::onPropertySelected( wxPropertyGridEvent& event )
00125 {
00126 event.Skip();
00127 }
00128
00129 void ToolPropertiesPanel::onDisplaysConfigLoaded(const boost::shared_ptr<wxConfigBase>& config)
00130 {
00131 wxString grid_state;
00132 if ( config->Read( PROPERTY_GRID_CONFIG, &grid_state ) )
00133 {
00134 property_grid_->RestoreEditableState( grid_state );
00135 }
00136 }
00137
00138 void ToolPropertiesPanel::onDisplaysConfigSaving(const boost::shared_ptr<wxConfigBase>& config)
00139 {
00140 config->Write( PROPERTY_GRID_CONFIG, property_grid_->SaveEditableState() );
00141 }
00142
00143 }