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,
46  const char* changed_slot,
47  QObject* receiver)
48  : EditableEnumProperty(name, default_value, description, parent, changed_slot, receiver)
49  , frame_manager_(nullptr)
50  , include_fixed_frame_string_(include_fixed_frame_string)
51 {
52  // Parent class EditableEnumProperty has requestOptions() signal.
53  connect(this, SIGNAL(requestOptions(EditableEnumProperty*)), this, SLOT(fillFrameList()));
54  setFrameManager(frame_manager);
55 }
56 
57 bool TfFrameProperty::setValue(const QVariant& new_value)
58 {
59  QString new_string = new_value.toString();
60  if (new_string.size() > 0 && new_string[0] == '/')
61  {
62  new_string = new_string.right(new_string.size() - 1);
63  }
64  bool result = EditableEnumProperty::setValue(new_string);
65 
66  return result;
67 }
68 
70 {
72  {
73  disconnect(frame_manager_, SIGNAL(fixedFrameChanged()), this, SLOT(handleFixedFrameChange()));
74  }
75  frame_manager_ = frame_manager;
77  {
78  connect(frame_manager_, SIGNAL(fixedFrameChanged()), this, SLOT(handleFixedFrameChange()));
79  }
80 }
81 
83 {
84  std::vector<std::string> std_frames;
85 // TODO(wjwwood): remove this and use tf2 interface instead
86 #ifndef _WIN32
87 #pragma GCC diagnostic push
88 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
89 #endif
90 
92 
93 #ifndef _WIN32
94 #pragma GCC diagnostic pop
95 #endif
96  std::sort(std_frames.begin(), std_frames.end());
97 
98  clearOptions();
100  {
102  }
103  for (size_t i = 0; i < std_frames.size(); i++)
104  {
105  addOptionStd(std_frames[i]);
106  }
107 }
108 
110 {
111  QString frame = getValue().toString();
112  if (frame == FIXED_FRAME_STRING && frame_manager_)
113  {
114  return QString::fromStdString(frame_manager_->getFixedFrame());
115  }
116  return frame;
117 }
118 
119 std::string TfFrameProperty::getFrameStd() const
120 {
121  return getFrame().toStdString();
122 }
123 
125 {
126  if (getValue().toString() == FIXED_FRAME_STRING)
127  {
128  Q_EMIT changed();
129  }
130 }
131 
132 } // end namespace rviz
std::string getFrameStd() 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:134
A single element of a property tree, with a name, value, description, and possibly children...
Definition: property.h:100
virtual void addOption(const QString &option)
Editable Enum property.
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, const char *changed_slot=nullptr, QObject *receiver=nullptr)
void addOptionStd(const std::string &option)
bool setValue(const QVariant &new_value) override
Override from Property to resolve the frame name on the way in.
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:70
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.
void getFrameStrings(std::vector< std::string > &ids) const
static const QString FIXED_FRAME_STRING
void setFrameManager(FrameManager *frame_manager)
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
FrameManager * frame_manager_


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Mon Aug 15 2022 02:05:17