display.cpp
Go to the documentation of this file.
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()
00039   : vis_manager_( 0 )
00040   , scene_manager_( 0 )
00041   , enabled_( false )
00042   , status_( status_levels::Ok )
00043   , property_manager_( NULL )
00044 {
00045 }
00046 
00047 Display::~Display()
00048 {
00049   if ( property_manager_ )
00050   {
00051     property_manager_->deleteByUserData( this );
00052   }
00053 }
00054 
00055 void Display::initialize( const std::string& name, VisualizationManager* manager )
00056 {
00057   setName( name );
00058   vis_manager_ = manager;
00059   scene_manager_ = manager->getSceneManager();
00060   update_nh_.setCallbackQueue(manager->getUpdateQueue());
00061   threaded_nh_.setCallbackQueue(manager->getThreadedQueue());
00062 
00063   // Do subclass initialization, if implemented.
00064   onInitialize();
00065 }
00066 
00067 void Display::setName(const std::string& name)
00068 {
00069   name_ = name;
00070   property_prefix_ = name + ".";
00071 }
00072 
00073 void Display::enable( bool force )
00074 {
00075   if ( enabled_ && !force )
00076   {
00077     return;
00078   }
00079 
00080   enabled_ = true;
00081 
00082   if (StatusPropertyPtr status = status_property_.lock())
00083   {
00084     status->enable();
00085   }
00086 
00087   onEnable();
00088 
00089   Q_EMIT stateChanged( this );
00090 }
00091 
00092 void Display::disable( bool force )
00093 {
00094   if ( !enabled_ && !force )
00095   {
00096     return;
00097   }
00098 
00099   enabled_ = false;
00100 
00101   onDisable();
00102 
00103   if (StatusPropertyPtr status = status_property_.lock())
00104   {
00105     status->disable();
00106   }
00107 
00108   Q_EMIT stateChanged( this );
00109 }
00110 
00111 void Display::setEnabled(bool en, bool force)
00112 {
00113   if (en)
00114   {
00115     enable(force);
00116   }
00117   else
00118   {
00119     disable(force);
00120   }
00121 }
00122 
00123 void Display::setRenderCallback( boost::function<void ()> func )
00124 {
00125   render_callback_ = func;
00126 }
00127 
00128 void Display::setLockRenderCallback( boost::function<void ()> func )
00129 {
00130   render_lock_ = func;
00131 }
00132 
00133 void Display::setUnlockRenderCallback( boost::function<void ()> func )
00134 {
00135   render_unlock_ = func;
00136 }
00137 
00138 
00139 void Display::causeRender()
00140 {
00141   if ( render_callback_ )
00142   {
00143     render_callback_();
00144   }
00145 }
00146 
00147 void Display::lockRender()
00148 {
00149   if ( render_lock_ )
00150   {
00151     render_lock_();
00152   }
00153 }
00154 
00155 void Display::unlockRender()
00156 {
00157   if ( render_unlock_ )
00158   {
00159     render_unlock_();
00160   }
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       Q_EMIT stateChanged( 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       Q_EMIT stateChanged( 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       Q_EMIT stateChanged( 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


rviz
Author(s): Dave Hershberger, Josh Faust
autogenerated on Mon Jan 6 2014 11:54:32