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
00068
00069
00070 #if wxMAJOR_VERSION == 2 and wxMINOR_VERSION == 8 // If wxWidgets 2.8.x
00071
00072 property_grid_->SetCaptionForegroundColour( *wxWHITE );
00073 #endif
00074
00075
00076 property_grid_->Connect( wxEVT_PG_CHANGING, wxPropertyGridEventHandler( ToolPropertiesPanel::onPropertyChanging ), NULL, this );
00077 property_grid_->Connect( wxEVT_PG_CHANGED, wxPropertyGridEventHandler( ToolPropertiesPanel::onPropertyChanged ), NULL, this );
00078 property_grid_->Connect( wxEVT_PG_SELECTED, wxPropertyGridEventHandler( ToolPropertiesPanel::onPropertySelected ), NULL, this );
00079 }
00080
00081 ToolPropertiesPanel::~ToolPropertiesPanel()
00082 {
00083 property_grid_->Disconnect( wxEVT_PG_CHANGING, wxPropertyGridEventHandler( ToolPropertiesPanel::onPropertyChanging ), NULL, this );
00084 property_grid_->Disconnect( wxEVT_PG_CHANGED, wxPropertyGridEventHandler( ToolPropertiesPanel::onPropertyChanged ), NULL, this );
00085 property_grid_->Disconnect( wxEVT_PG_SELECTED, wxPropertyGridEventHandler( ToolPropertiesPanel::onPropertySelected ), NULL, this );
00086 property_grid_->Destroy();
00087 }
00088
00089 void ToolPropertiesPanel::initialize(VisualizationManager* manager)
00090 {
00091 manager_ = manager;
00092
00093 manager_->getToolPropertyManager()->setPropertyGrid(property_grid_);
00094 manager_->getToolAddedSignal().connect(boost::bind(&ToolPropertiesPanel::onToolAdded, this, _1));
00095 }
00096
00097 void ToolPropertiesPanel::onToolAdded(Tool* tool)
00098 {
00099 if (tool->hasProperties())
00100 {
00101 std::string name = tool->getName();
00102 CategoryPropertyWPtr cat = manager_->getToolPropertyManager()->createCategory(name, "", CategoryPropertyWPtr(), tool);
00103 tool->enumerateProperties(manager_->getToolPropertyManager(), cat);
00104 }
00105 }
00106
00107 void ToolPropertiesPanel::onPropertyChanging( wxPropertyGridEvent& event )
00108 {
00109 wxPGProperty* property = event.GetProperty();
00110
00111 if ( !property )
00112 {
00113 return;
00114 }
00115
00116 manager_->getToolPropertyManager()->propertyChanging( event );
00117 }
00118
00119 void ToolPropertiesPanel::onPropertyChanged( wxPropertyGridEvent& event )
00120 {
00121 wxPGProperty* property = event.GetProperty();
00122
00123 if ( !property )
00124 {
00125 return;
00126 }
00127
00128 manager_->getToolPropertyManager()->propertyChanged( event );
00129 }
00130
00131 void ToolPropertiesPanel::onPropertySelected( wxPropertyGridEvent& event )
00132 {
00133 event.Skip();
00134 }
00135
00136 void ToolPropertiesPanel::onDisplaysConfigLoaded(const boost::shared_ptr<wxConfigBase>& config)
00137 {
00138 wxString grid_state;
00139 if ( config->Read( PROPERTY_GRID_CONFIG, &grid_state ) )
00140 {
00141 property_grid_->RestoreEditableState( grid_state );
00142 }
00143 }
00144
00145 void ToolPropertiesPanel::onDisplaysConfigSaving(const boost::shared_ptr<wxConfigBase>& config)
00146 {
00147 config->Write( PROPERTY_GRID_CONFIG, property_grid_->SaveEditableState() );
00148 }
00149
00150 }