tf_frame_property.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <algorithm> // for std::sort
31 
32 #include "rviz/frame_manager.h"
33 
35 
36 namespace rviz
37 {
38 
39 const QString TfFrameProperty::FIXED_FRAME_STRING = "<Fixed Frame>";
40 
41 TfFrameProperty::TfFrameProperty( const QString& name,
42  const QString& default_value,
43  const QString& description,
44  Property* parent,
45  FrameManager* frame_manager,
46  bool include_fixed_frame_string,
47  const char *changed_slot,
48  QObject* receiver )
49  : EditableEnumProperty( name, default_value, description, parent, changed_slot, receiver )
50  , frame_manager_( NULL )
51  , include_fixed_frame_string_( include_fixed_frame_string )
52 {
53  // Parent class EditableEnumProperty has requestOptions() signal.
54  connect( this, SIGNAL( requestOptions( EditableEnumProperty* )),
55  this, SLOT( fillFrameList() ));
56  setFrameManager( frame_manager );
57 }
58 
59 bool TfFrameProperty::setValue( const QVariant& new_value )
60 {
61  QString new_string = new_value.toString();
62  if( new_string.size() > 0 && new_string[ 0 ] == '/' )
63  {
64  new_string = new_string.right( new_string.size() - 1 );
65  }
66  bool result = EditableEnumProperty::setValue( new_string );
67 
68  return result;
69 }
70 
72 {
74  {
75  disconnect( frame_manager_, SIGNAL( fixedFrameChanged() ),
76  this, SLOT( handleFixedFrameChange() ));
77  }
78  frame_manager_ = frame_manager;
80  {
81  connect( frame_manager_, SIGNAL( fixedFrameChanged() ),
82  this, SLOT( handleFixedFrameChange() ));
83  }
84 }
85 
87 {
88  std::vector<std::string> std_frames;
89  frame_manager_->getTFClient()->getFrameStrings( std_frames );
90  std::sort( std_frames.begin(), std_frames.end() );
91 
92  clearOptions();
94  {
96  }
97  for( size_t i = 0; i < std_frames.size(); i++ )
98  {
99  addOptionStd( std_frames[ i ]);
100  }
101 }
102 
104 {
105  QString frame = getValue().toString();
106  if( frame == FIXED_FRAME_STRING && frame_manager_ )
107  {
108  return QString::fromStdString( frame_manager_->getFixedFrame() );
109  }
110  return frame;
111 }
112 
113 std::string TfFrameProperty::getFrameStd() const
114 {
115  return getFrame().toStdString();
116 }
117 
119 {
120  if( getValue().toString() == FIXED_FRAME_STRING )
121  {
122  Q_EMIT changed();
123  }
124 }
125 
126 } // end namespace rviz
#define NULL
Definition: global.h:37
void getFrameStrings(std::vector< std::string > &ids) const
void changed()
Emitted by setValue() just after the value has changed.
virtual bool setValue(const QVariant &new_value)
Set the new value for this property. Returns true if the new value is different from the old value...
Definition: property.cpp:130
A single element of a property tree, with a name, value, description, and possibly children...
Definition: property.h:100
virtual bool setValue(const QVariant &new_value)
Override from Property to resolve the frame name on the way in.
virtual void addOption(const QString &option)
Editable Enum property.
void addOptionStd(const std::string &option)
void handleFixedFrameChange()
If this property is currently set to FIXED_FRAME_STRING, this emits changed() to let users know that ...
Helper class for transforming data into Ogre&#39;s world frame (the fixed frame).
Definition: frame_manager.h:63
std::string getFrameStd() const
tf::TransformListener * getTFClient()
Return the tf::TransformListener used to receive transform data.
void requestOptions(EditableEnumProperty *property_in_need_of_options)
requestOptions() is emitted each time createEditor() is called.
const std::string & getFixedFrame()
Return the current fixed frame name.
static const QString FIXED_FRAME_STRING
virtual QVariant getValue() const
Return the value of this Property as a QVariant. If the value has never been set, an invalid QVariant...
Definition: property.cpp:145
void setFrameManager(FrameManager *frame_manager)
TfFrameProperty(const QString &name=QString(), const QString &default_value=QString(), const QString &description=QString(), Property *parent=0, FrameManager *frame_manager=0, bool include_fixed_frame_string=false, const char *changed_slot=0, QObject *receiver=0)
FrameManager * frame_manager_


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Wed Aug 28 2019 04:01:51