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 const QString TfFrameProperty::FIXED_FRAME_STRING = "<Fixed Frame>";
39 
41  const QString& default_value,
42  const QString& description,
43  Property* parent,
44  FrameManager* frame_manager,
45  bool include_fixed_frame_string)
47  , frame_manager_(nullptr)
48  , include_fixed_frame_string_(include_fixed_frame_string)
49 {
50  // Parent class EditableEnumProperty has requestOptions() signal.
52  setFrameManager(frame_manager);
53 }
54 
55 bool TfFrameProperty::setValue(const QVariant& new_value)
56 {
57  QString new_string = new_value.toString();
58  if (new_string.size() > 0 && new_string[0] == '/')
59  {
60  new_string = new_string.right(new_string.size() - 1);
61  }
62  bool result = EditableEnumProperty::setValue(new_string);
63 
64  return result;
65 }
66 
68 {
70  {
73  }
74  frame_manager_ = frame_manager;
76  {
79  }
80 }
81 
83 {
84  std::vector<std::string> std_frames;
85  frame_manager_->getTF2BufferPtr()->_getFrameStrings(std_frames);
86  std::sort(std_frames.begin(), std_frames.end());
87 
88  clearOptions();
90  {
92  }
93  for (size_t i = 0; i < std_frames.size(); i++)
94  {
95  addOptionStd(std_frames[i]);
96  }
97 }
98 
100 {
101  QString frame = getValue().toString();
102  if (frame == FIXED_FRAME_STRING && frame_manager_)
103  {
104  return QString::fromStdString(frame_manager_->getFixedFrame());
105  }
106  return frame;
107 }
108 
109 std::string TfFrameProperty::getFrameStd() const
110 {
111  return getFrame().toStdString();
112 }
113 
115 {
116  if (getValue().toString() == FIXED_FRAME_STRING)
117  {
118  Q_EMIT changed();
119  }
120 }
121 
122 } // end namespace rviz
rviz::FrameManager::getTF2BufferPtr
const std::shared_ptr< tf2_ros::Buffer > getTF2BufferPtr()
Definition: frame_manager.h:209
rviz::FrameManager
Helper class for transforming data into Ogre's world frame (the fixed frame).
Definition: frame_manager.h:64
frame_manager.h
rviz::FrameManager::fixedFrameChanged
void fixedFrameChanged()
Emitted whenever the fixed frame changes.
rviz::EditableEnumProperty
Editable Enum property.
Definition: editable_enum_property.h:43
description
description
rviz::TfFrameProperty::getFrameStd
std::string getFrameStd() const
Definition: tf_frame_property.cpp:109
rviz::TfFrameProperty::include_fixed_frame_string_
bool include_fixed_frame_string_
Definition: tf_frame_property.h:104
rviz::TfFrameProperty::handleFixedFrameChange
void handleFixedFrameChange()
If this property is currently set to FIXED_FRAME_STRING, this emits changed() to let users know that ...
Definition: tf_frame_property.cpp:114
rviz::TfFrameProperty::setValue
bool setValue(const QVariant &new_value) override
Override from Property to resolve the frame name on the way in.
Definition: tf_frame_property.cpp:55
rviz::EditableEnumProperty::addOption
virtual void addOption(const QString &option)
Definition: editable_enum_property.cpp:50
rviz::Property::getValue
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:150
rviz::EditableEnumProperty::addOptionStd
void addOptionStd(const std::string &option)
Definition: editable_enum_property.h:78
rviz::Property::connect
QMetaObject::Connection connect(const QObject *receiver, const char *slot, Qt::ConnectionType type=Qt::AutoConnection)
Connect changed() signal to given slot of receiver.
Definition: property.cpp:78
rviz::Property
A single element of a property tree, with a name, value, description, and possibly children.
Definition: property.h:100
rviz::FrameManager::getFixedFrame
const std::string & getFixedFrame()
Return the current fixed frame name.
Definition: frame_manager.h:204
rviz::Property::setValue
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:134
rviz
Definition: add_display_dialog.cpp:54
rviz::EditableEnumProperty::clearOptions
virtual void clearOptions()
Definition: editable_enum_property.cpp:45
tf_frame_property.h
rviz::TfFrameProperty::FIXED_FRAME_STRING
static const QString FIXED_FRAME_STRING
Definition: tf_frame_property.h:92
rviz::TfFrameProperty::getFrame
QString getFrame() const
Definition: tf_frame_property.cpp:99
rviz::TfFrameProperty::frame_manager_
FrameManager * frame_manager_
Definition: tf_frame_property.h:103
default_value
def default_value(type_)
rviz::Property::changed
void changed()
Emitted by setValue() just after the value has changed.
rviz::TfFrameProperty::setFrameManager
void setFrameManager(FrameManager *frame_manager)
Definition: tf_frame_property.cpp:67
rviz::TfFrameProperty::TfFrameProperty
TfFrameProperty(const QString &name=QString(), const QString &default_value=QString(), const QString &description=QString(), Property *parent=nullptr, FrameManager *frame_manager=nullptr, bool include_fixed_frame_string=false)
Definition: tf_frame_property.cpp:40
rviz::TfFrameProperty::fillFrameList
void fillFrameList()
Definition: tf_frame_property.cpp:82
rviz::EditableEnumProperty::requestOptions
void requestOptions(EditableEnumProperty *property_in_need_of_options)
requestOptions() is emitted each time createEditor() is called.


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust, William Woodall
autogenerated on Fri Dec 13 2024 03:31:03