$search
00001 /* 00002 * Copyright (c) 2011, Willow Garage, Inc. 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * 00008 * * Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * * Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * * Neither the name of the Willow Garage, Inc. nor the names of its 00014 * contributors may be used to endorse or promote products derived from 00015 * this software without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00018 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00021 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00022 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00023 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00024 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00025 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00026 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00027 * POSSIBILITY OF SUCH DAMAGE. 00028 */ 00029 00030 #include "visualization_panel.h" 00031 #include "render_panel.h" 00032 #include "displays_panel.h" 00033 #include "visualization_manager.h" 00034 #include "config.h" 00035 00036 #include <ros/package.h> 00037 #include <ros/console.h> 00038 00039 #include <ogre_tools/initialization.h> 00040 #include <ogre_tools/render_system.h> 00041 00042 namespace rviz 00043 { 00044 00045 VisualizationPanel::VisualizationPanel(QWidget* parent) 00046 : QSplitter( parent ) 00047 { 00048 if( !ros::isInitialized() ) 00049 { 00050 int argc = 0; 00051 ros::init(argc, 0, "rviz", ros::init_options::AnonymousName); 00052 } 00053 00054 displays_panel_ = new DisplaysPanel( this ); 00055 render_panel_ = new RenderPanel( ogre_tools::RenderSystem::get(), 0, this ); 00056 00057 QList<int> sizes; 00058 sizes.push_back( 300 ); 00059 sizes.push_back( 500 ); 00060 setSizes( sizes ); 00061 00062 std::string package_path = ros::package::getPath("rviz_qt"); 00063 ogre_tools::V_string paths; 00064 paths.push_back(package_path + "/ogre_media/textures"); 00065 ogre_tools::initializeResources( paths ); 00066 00067 manager_ = new VisualizationManager( render_panel_ ); 00068 render_panel_->initialize( manager_->getSceneManager(), manager_ ); 00069 displays_panel_->initialize( manager_ ); 00070 00071 manager_->initialize(); 00072 manager_->startUpdate(); 00073 } 00074 00075 VisualizationPanel::~VisualizationPanel() 00076 { 00077 // TODO: make Properties, PropertyWidgetItems, and things that hold 00078 // Ogre Node pointers less tightly connected so they can be moved 00079 // around easier. The tricky dependencies are a big source of bugs. 00080 00081 // Have to remove displays before destroying DisplaysPanel, because 00082 // Displays own Properties, and Properties own children of 00083 // DisplaysPanel (PropertyWidgetItems). DisplaysPanel notices when 00084 // PropertyWidgetItems are destroyed, but Properties don't notice 00085 // when PropertyWidgetItems are destroyed, so must destroy in the 00086 // right order. 00087 if( manager_ ) 00088 { 00089 manager_->removeAllDisplays(); 00090 } 00091 00092 delete render_panel_; 00093 // Have to delete render_panel_ before manager_ because 00094 // ~VisualizationManager destroys ogre SceneManager which destroys 00095 // all attached nodes. RenderPanel indirectly holds pointers to 00096 // nodes which it destroys. 00097 delete manager_; 00098 } 00099 00100 void VisualizationPanel::loadGeneralConfig(const std::string& filepath) 00101 { 00102 boost::shared_ptr<Config> config( new Config() ); 00103 config->readFromFile( filepath ); 00104 manager_->loadGeneralConfig( config ); 00105 } 00106 00107 void VisualizationPanel::loadDisplayConfig(const std::string& filepath) 00108 { 00109 manager_->removeAllDisplays(); 00110 00111 boost::shared_ptr<Config> config( new Config() ); 00112 config->readFromFile( filepath ); 00113 manager_->loadDisplayConfig( config ); 00114 } 00115 00116 }