marker_selection_handler.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009, 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 <OgreQuaternion.h>
32 
41 
43 
44 namespace rviz
45 {
47  const MarkerID& id,
48  DisplayContext* context)
49  : SelectionHandler(context)
50  , marker_(marker)
51  , marker_id_(QString::fromStdString(id.first) + "/" + QString::number(id.second))
52 {
53 }
54 
56 {
57 }
58 
60 {
61  return marker_->getPosition();
62 }
63 
65 {
66  return marker_->getOrientation();
67 }
68 
69 Ogre::Vector3 MarkerSelectionHandler::getScale() const
70 {
71  return Ogre::Vector3(marker_->getMessage()->scale.x, marker_->getMessage()->scale.y,
72  marker_->getMessage()->scale.z);
73 }
74 
76 {
77  return QColor((int)(marker_->getMessage()->color.r * 255), (int)(marker_->getMessage()->color.g * 255),
78  (int)(marker_->getMessage()->color.b * 255),
79  (int)(marker_->getMessage()->color.a * 255));
80 }
81 
82 namespace
83 {
84 VectorProperty* createScaleProperty(const visualization_msgs::Marker& marker,
85  const Ogre::Vector3 scale,
86  Property* parent_property)
87 {
88  VectorProperty* p = new VectorProperty("Scale", scale, "", parent_property);
89  Property* x = p->childAt(0);
90  Property* y = p->childAt(1);
91  Property* z = p->childAt(2);
92  // Change scale dimension titles
93  switch (marker.type)
94  {
95  case visualization_msgs::Marker::ARROW:
96  x->setName("Length");
97  y->setName("Width");
98  z->setName("Height");
99  break;
100  case visualization_msgs::Marker::CYLINDER:
101  z->setName("Height");
102  break;
103  case visualization_msgs::Marker::LINE_STRIP:
104  case visualization_msgs::Marker::LINE_LIST:
105  x->setName("Thickness");
106  y->hide();
107  z->hide();
108  break;
109  case visualization_msgs::Marker::POINTS:
110  x->setName("Width");
111  y->setName("Height");
112  z->hide();
113  break;
114  case visualization_msgs::Marker::TEXT_VIEW_FACING:
115  x->hide();
116  y->hide();
117  z->setName("Size");
118  break;
119  }
120  return p;
121 }
122 
123 } // namespace
124 
125 void MarkerSelectionHandler::createProperties(const Picked& /*obj*/, Property* parent_property)
126 {
127  Property* group = new Property("Marker " + marker_id_, getMarkerTypeName(marker_->getMessage()->type),
128  "", parent_property);
129  properties_.push_back(group);
130 
131  position_property_ = new VectorProperty("Position", getPosition(), "", group);
133 
134  orientation_property_ = new QuaternionProperty("Orientation", getOrientation(), "", group);
136 
137  scale_property_ = createScaleProperty(*marker_->getMessage(), getScale(), group);
139 
140  color_property_ = new ColorProperty("Color", getColor(), "", group);
142 
143  group->expand();
144 }
145 
147 {
152 }
153 
154 } // end namespace rviz
rviz::Property::childAt
Property * childAt(int index) const
Return the child Property with the given index, or NULL if the index is out of bounds or if the child...
Definition: property.cpp:202
marker_selection_handler.h
rviz::MarkerSelectionHandler::~MarkerSelectionHandler
~MarkerSelectionHandler() override
Definition: marker_selection_handler.cpp:55
rviz::Property::setName
virtual void setName(const QString &name)
Set the name.
Definition: property.cpp:155
rviz::MarkerBase
Definition: marker_base.h:53
rviz::MarkerSelectionHandler::marker_id_
QString marker_id_
Definition: marker_selection_handler.h:61
property.h
marker_display.h
rviz::MarkerBase::getOrientation
const Ogre::Quaternion & getOrientation() const
Definition: marker_base.cpp:139
rviz::QuaternionProperty::setReadOnly
void setReadOnly(bool read_only) override
Overridden from Property to propagate read-only-ness to children.
Definition: quaternion_property.cpp:158
rviz::MarkerSelectionHandler::getPosition
Ogre::Vector3 getPosition() const
Definition: marker_selection_handler.cpp:59
rviz::MarkerSelectionHandler::position_property_
VectorProperty * position_property_
Definition: marker_selection_handler.h:62
rviz::ColorProperty
Definition: color_property.h:40
quaternion_property.h
rviz::QuaternionProperty
Definition: quaternion_property.h:38
rviz::Picked
Definition: forwards.h:53
rviz::Property
A single element of a property tree, with a name, value, description, and possibly children.
Definition: property.h:100
rviz::MarkerSelectionHandler::orientation_property_
QuaternionProperty * orientation_property_
Definition: marker_selection_handler.h:63
rviz::Property::hide
void hide()
Hide this Property in any PropertyTreeWidgets.
Definition: property.h:462
rviz::Property::expand
virtual void expand()
Expand (show the children of) this Property.
Definition: property.cpp:578
rviz
Definition: add_display_dialog.cpp:54
rviz::VectorProperty::setVector
virtual bool setVector(const Ogre::Vector3 &vector)
Definition: vector_property.cpp:55
rviz::QuaternionProperty::setQuaternion
virtual bool setQuaternion(const Ogre::Quaternion &quaternion)
Definition: quaternion_property.cpp:60
rviz::MarkerSelectionHandler::MarkerSelectionHandler
MarkerSelectionHandler(const MarkerBase *marker, const MarkerID &id, DisplayContext *context)
Definition: marker_selection_handler.cpp:46
color_property.h
rviz::MarkerSelectionHandler::marker_
const MarkerBase * marker_
Definition: marker_selection_handler.h:60
ogre_vector.h
rviz::MarkerBase::getPosition
const Ogre::Vector3 & getPosition() const
Definition: marker_base.cpp:134
rviz::DisplayContext
Pure-virtual base class for objects which give Display subclasses context in which to work.
Definition: display_context.h:81
rviz::MarkerBase::getMessage
const MarkerConstPtr & getMessage() const
Definition: marker_base.h:69
rviz::MarkerSelectionHandler::getColor
QColor getColor() const
Definition: marker_selection_handler.cpp:75
rviz::MarkerSelectionHandler::updateProperties
void updateProperties() override
Override to update property values.
Definition: marker_selection_handler.cpp:146
rviz::Property::setReadOnly
virtual void setReadOnly(bool read_only)
Prevent or allow users to edit this property from a PropertyTreeWidget.
Definition: property.h:497
vector_property.h
rviz::MarkerID
std::pair< std::string, int32_t > MarkerID
Definition: interactive_marker_display.h:58
rviz::MarkerSelectionHandler::getOrientation
Ogre::Quaternion getOrientation() const
Definition: marker_selection_handler.cpp:64
rviz::SelectionHandler
Definition: selection_handler.h:64
marker_utils.h
rviz::VectorProperty::setReadOnly
void setReadOnly(bool read_only) override
Overridden from Property to propagate read-only-ness to children.
Definition: vector_property.cpp:143
rviz::SelectionHandler::properties_
QList< Property * > properties_
Definition: selection_handler.h:149
rviz::MarkerSelectionHandler::scale_property_
VectorProperty * scale_property_
Definition: marker_selection_handler.h:64
rviz::MarkerSelectionHandler::color_property_
ColorProperty * color_property_
Definition: marker_selection_handler.h:65
marker_base.h
rviz::MarkerSelectionHandler::createProperties
void createProperties(const Picked &obj, Property *parent_property) override
Override to create properties of the given picked object(s).
Definition: marker_selection_handler.cpp:125
rviz::VectorProperty
Definition: vector_property.h:39
rviz::getMarkerTypeName
QString getMarkerTypeName(unsigned int type)
Definition: marker_utils.cpp:90
rviz::ColorProperty::setColor
virtual bool setColor(const QColor &color)
Definition: color_property.cpp:50
rviz::MarkerSelectionHandler::getScale
Ogre::Vector3 getScale() const
Definition: marker_selection_handler.cpp:69
interactive_marker_control.h


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