$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 "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 /* START_WX-2.9_COMPAT_CODE 00068 This code is related to ticket: https://code.ros.org/trac/ros-pkg/ticket/5157 00069 */ 00070 #if wxMAJOR_VERSION == 2 and wxMINOR_VERSION == 8 // If wxWidgets 2.8.x 00071 // This function is no longer available in wxPropgrid for wx-2.9 00072 property_grid_->SetCaptionForegroundColour( *wxWHITE ); 00073 #endif 00074 /* END_WX-2.9_COMPAT_CODE */ 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 } // namespace rviz