tf_frame_property.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2012, 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 <algorithm> // for std::sort
00031 
00032 #include "rviz/frame_manager.h"
00033 
00034 #include "rviz/properties/tf_frame_property.h"
00035 
00036 namespace rviz
00037 {
00038 
00039 const QString TfFrameProperty::FIXED_FRAME_STRING = "<Fixed Frame>";
00040 
00041 TfFrameProperty::TfFrameProperty( const QString& name,
00042                                   const QString& default_value,
00043                                   const QString& description,
00044                                   Property* parent,
00045                                   FrameManager* frame_manager,
00046                                   bool include_fixed_frame_string,
00047                                   const char *changed_slot,
00048                                   QObject* receiver )
00049   : EditableEnumProperty( name, default_value, description, parent, changed_slot, receiver )
00050   , frame_manager_( NULL )
00051   , include_fixed_frame_string_( include_fixed_frame_string )
00052 {
00053   // Parent class EditableEnumProperty has requestOptions() signal.
00054   connect( this, SIGNAL( requestOptions( EditableEnumProperty* )),
00055            this, SLOT( fillFrameList() ));
00056   setFrameManager( frame_manager );
00057 }
00058 
00059 bool TfFrameProperty::setValue( const QVariant& new_value )
00060 {
00061   QString new_string = new_value.toString();
00062   if( new_string.size() > 0 && new_string[ 0 ] == '/' )
00063   {
00064     new_string = new_string.right( new_string.size() - 1 );
00065   }
00066   bool result = EditableEnumProperty::setValue( new_string );
00067 
00068   return result;
00069 }
00070 
00071 void TfFrameProperty::setFrameManager( FrameManager* frame_manager )
00072 {
00073   if( frame_manager_ && include_fixed_frame_string_ )
00074   {
00075     disconnect( frame_manager_, SIGNAL( fixedFrameChanged() ),
00076                 this, SLOT( handleFixedFrameChange() ));
00077   }
00078   frame_manager_ = frame_manager;
00079   if( frame_manager_ && include_fixed_frame_string_ )
00080   {
00081     connect( frame_manager_, SIGNAL( fixedFrameChanged() ),
00082              this, SLOT( handleFixedFrameChange() ));
00083   }
00084 }
00085 
00086 void TfFrameProperty::fillFrameList()
00087 {
00088   std::vector<std::string> std_frames;
00089   frame_manager_->getTFClient()->getFrameStrings( std_frames );
00090   std::sort( std_frames.begin(), std_frames.end() );
00091 
00092   clearOptions();
00093   if( include_fixed_frame_string_ )
00094   {
00095     addOption( FIXED_FRAME_STRING );
00096   }
00097   for( size_t i = 0; i < std_frames.size(); i++ )
00098   {
00099     addOptionStd( std_frames[ i ]);
00100   }
00101 }
00102 
00103 QString TfFrameProperty::getFrame() const
00104 {
00105   QString frame = getValue().toString();
00106   if( frame == FIXED_FRAME_STRING && frame_manager_ )
00107   {
00108     return QString::fromStdString( frame_manager_->getFixedFrame() );
00109   }
00110   return frame;
00111 }
00112 
00113 std::string TfFrameProperty::getFrameStd() const
00114 {
00115   return getFrame().toStdString();
00116 }
00117 
00118 void TfFrameProperty::handleFixedFrameChange()
00119 {
00120   if( getValue().toString() == FIXED_FRAME_STRING )
00121   {
00122     Q_EMIT changed();
00123   }
00124 }
00125 
00126 } // end namespace rviz


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Thu Aug 27 2015 15:02:28