tool.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, 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 <ros/package.h>
31 
32 #include "rviz/display_context.h"
34 #include "rviz/load_resource.h"
36 
37 #include "rviz/tool.h"
38 
39 namespace rviz
40 {
41 Tool::Tool() : property_container_(new Property())
42 {
43  access_all_keys_ = false;
44  shortcut_key_ = '\0';
45 }
46 
48 {
49  delete property_container_;
50 }
51 
53 {
54  context_ = context;
56 
57  // Let subclasses do initialization if they want.
58  onInitialize();
59 }
60 
61 void Tool::setIcon(const QIcon& icon)
62 {
63  icon_ = icon;
64  cursor_ = makeIconCursor(icon.pixmap(16), "tool_cursor:" + name_);
65 }
66 
67 void Tool::setCursor(const QCursor& cursor)
68 {
69  cursor_ = cursor;
70 }
71 
72 void Tool::setName(const QString& name)
73 {
74  // Early return if the name did not change
75  if (name == name_)
76  return;
77 
78  // Change the name and emit a signal to let slots know
79  name_ = name;
81  Q_EMIT nameChanged(name_);
82 }
83 
84 void Tool::setDescription(const QString& description)
85 {
86  description_ = description;
88 }
89 
90 void Tool::load(const Config& config)
91 {
92  property_container_->load(config);
93 }
94 
95 void Tool::save(Config config) const
96 {
97  property_container_->save(config);
98  config.mapSetValue("Class", getClassId());
99 }
100 
101 void Tool::setStatus(const QString& message)
102 {
103  if (context_)
104  {
105  context_->setStatus(message);
106  }
107 }
108 
109 
110 } // end namespace rviz
virtual void setStatus(const QString &message)=0
QString name_
Definition: tool.h:219
Ogre::SceneManager * scene_manager_
Definition: tool.h:206
~Tool() override
Definition: tool.cpp:47
virtual void save(Config config) const
Write the value of this property and/or its children into the given Config reference.
Definition: property.cpp:490
QCursor makeIconCursor(QString url, bool fill_cache)
virtual void save(Config config) const
Save this entire tool into the given Config node.
Definition: tool.cpp:95
virtual void load(const Config &config)
Load the value of this property and/or its children from the given Config reference.
Definition: property.cpp:440
A single element of a property tree, with a name, value, description, and possibly children...
Definition: property.h:100
virtual QString getClassId() const
Return the class identifier which was used to create this instance. This version just returns whateve...
Definition: tool.h:147
virtual void setName(const QString &name)
Set the name.
Definition: property.cpp:155
virtual void onInitialize()
Definition: tool.h:202
char shortcut_key_
Definition: tool.h:209
virtual void setDescription(const QString &description)
Set the description.
Definition: property.cpp:169
QIcon icon_
Definition: tool.h:212
void mapSetValue(const QString &key, QVariant value)
Set a named child to the given value.
Definition: config.cpp:196
Configuration data storage class.
Definition: config.h:124
Pure-virtual base class for objects which give Display subclasses context in which to work...
virtual void load(const Config &config)
Load properties from the given Config.
Definition: tool.cpp:90
void setName(const QString &name)
Set the name of the tool.
Definition: tool.cpp:72
Tool()
Definition: tool.cpp:41
void initialize(DisplayContext *context)
Definition: tool.cpp:52
QString description_
Definition: tool.h:220
virtual Ogre::SceneManager * getSceneManager() const =0
Returns the Ogre::SceneManager used for the main RenderPanel.
void nameChanged(const QString &name)
QCursor cursor_
Definition: tool.h:214
DisplayContext * context_
Definition: tool.h:207
void setIcon(const QIcon &icon)
Set the toolbar icon for this tool (will also set its cursor).
Definition: tool.cpp:61
void setStatus(const QString &message)
Definition: tool.cpp:101
void setCursor(const QCursor &cursor)
Set the cursor for this tool.
Definition: tool.cpp:67
Property * property_container_
Definition: tool.h:218
void setDescription(const QString &description)
Definition: tool.cpp:84
bool access_all_keys_
Definition: tool.h:210


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Sat May 27 2023 02:06:25