$search
00001 /* 00002 * Copyright (c) 2008, 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 "display.h" 00031 #include "visualization_manager.h" 00032 #include "properties/property_manager.h" 00033 #include "properties/property.h" 00034 00035 namespace rviz 00036 { 00037 00038 Display::Display( const std::string& name, VisualizationManager* manager ) 00039 : vis_manager_( manager ) 00040 , scene_manager_( manager->getSceneManager() ) 00041 , name_( name ) 00042 , enabled_( false ) 00043 , status_(status_levels::Ok) 00044 , target_frame_( "base" ) 00045 , property_prefix_( name_ + "." ) 00046 , property_manager_( NULL ) 00047 { 00048 update_nh_.setCallbackQueue(manager->getUpdateQueue()); 00049 threaded_nh_.setCallbackQueue(manager->getThreadedQueue()); 00050 } 00051 00052 Display::~Display() 00053 { 00054 if ( property_manager_ ) 00055 { 00056 property_manager_->deleteByUserData( this ); 00057 } 00058 } 00059 00060 void Display::setName(const std::string& name) 00061 { 00062 name_ = name; 00063 property_prefix_ = name + "."; 00064 } 00065 00066 void Display::enable( bool force ) 00067 { 00068 if ( enabled_ && !force ) 00069 { 00070 return; 00071 } 00072 00073 enabled_ = true; 00074 00075 if (StatusPropertyPtr status = status_property_.lock()) 00076 { 00077 status->enable(); 00078 } 00079 00080 onEnable(); 00081 00082 state_changed_(this); 00083 } 00084 00085 void Display::disable( bool force ) 00086 { 00087 if ( !enabled_ && !force ) 00088 { 00089 return; 00090 } 00091 00092 enabled_ = false; 00093 00094 onDisable(); 00095 00096 if (StatusPropertyPtr status = status_property_.lock()) 00097 { 00098 status->disable(); 00099 } 00100 00101 state_changed_(this); 00102 } 00103 00104 void Display::setEnabled(bool en, bool force) 00105 { 00106 if (en) 00107 { 00108 enable(force); 00109 } 00110 else 00111 { 00112 disable(force); 00113 } 00114 } 00115 00116 void Display::setRenderCallback( boost::function<void ()> func ) 00117 { 00118 render_callback_ = func; 00119 } 00120 00121 void Display::setLockRenderCallback( boost::function<void ()> func ) 00122 { 00123 render_lock_ = func; 00124 } 00125 00126 void Display::setUnlockRenderCallback( boost::function<void ()> func ) 00127 { 00128 render_unlock_ = func; 00129 } 00130 00131 00132 void Display::causeRender() 00133 { 00134 if ( render_callback_ ) 00135 { 00136 render_callback_(); 00137 } 00138 } 00139 00140 void Display::lockRender() 00141 { 00142 if ( render_lock_ ) 00143 { 00144 render_lock_(); 00145 } 00146 } 00147 00148 void Display::unlockRender() 00149 { 00150 if ( render_unlock_ ) 00151 { 00152 render_unlock_(); 00153 } 00154 } 00155 00156 void Display::setTargetFrame( const std::string& frame ) 00157 { 00158 target_frame_ = frame; 00159 00160 targetFrameChanged(); 00161 } 00162 00163 void Display::setFixedFrame( const std::string& frame ) 00164 { 00165 fixed_frame_ = frame; 00166 00167 fixedFrameChanged(); 00168 } 00169 00170 StatusLevel Display::getStatus() 00171 { 00172 return status_; 00173 } 00174 00175 void Display::setStatus(StatusLevel level, const std::string& name, const std::string& text) 00176 { 00177 if (StatusPropertyPtr status = status_property_.lock()) 00178 { 00179 status->setStatus(level, name, text); 00180 00181 StatusLevel new_status = status->getTopLevelStatus(); 00182 if (new_status != status_) 00183 { 00184 status_ = new_status; 00185 state_changed_(this); 00186 } 00187 } 00188 } 00189 00190 void Display::deleteStatus(const std::string& name) 00191 { 00192 if (StatusPropertyPtr status = status_property_.lock()) 00193 { 00194 status->deleteStatus(name); 00195 00196 StatusLevel new_status = status->getTopLevelStatus(); 00197 if (new_status != status_) 00198 { 00199 status_ = new_status; 00200 state_changed_(this); 00201 } 00202 } 00203 } 00204 00205 void Display::clearStatuses() 00206 { 00207 if (StatusPropertyPtr status = status_property_.lock()) 00208 { 00209 status->clear(); 00210 00211 StatusLevel new_status = status->getTopLevelStatus(); 00212 if (new_status != status_) 00213 { 00214 status_ = new_status; 00215 state_changed_(this); 00216 } 00217 } 00218 } 00219 00220 void Display::setPropertyManager( PropertyManager* manager, const CategoryPropertyWPtr& parent ) 00221 { 00222 ROS_ASSERT(!property_manager_); 00223 00224 property_manager_ = manager; 00225 00226 parent_category_ = parent; 00227 status_property_ = property_manager_->createStatus("Status", property_prefix_, parent_category_, this); 00228 00229 createProperties(); 00230 } 00231 00232 void Display::reset() 00233 { 00234 clearStatuses(); 00235 } 00236 00237 } // namespace rviz