menu_handler.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011, 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  * Author: David Gossow
30  */
31 
32 #ifndef INTERACTIVE_MARKER_MENU_HANDLER
33 #define INTERACTIVE_MARKER_MENU_HANDLER
34 
35 #include <visualization_msgs/MenuEntry.h>
38 
39 #include <boost/function.hpp>
40 #include <boost/unordered_map.hpp>
41 
42 namespace interactive_markers
43 {
44 
45 // Simple non-intrusive helper class which creates a menu and maps its
46 // entries to function callbacks
48 {
49 public:
50 
51  typedef uint32_t EntryHandle;
52 
53  typedef visualization_msgs::InteractiveMarkerFeedbackConstPtr FeedbackConstPtr;
54  typedef boost::function< void ( const FeedbackConstPtr& ) > FeedbackCallback;
55 
56  enum CheckState {
60  };
61 
62  MenuHandler( );
63 
65  EntryHandle insert( const std::string &title, const FeedbackCallback &feedback_cb );
66 
68  EntryHandle insert( const std::string &title,
69  const uint8_t command_type = visualization_msgs::MenuEntry::FEEDBACK,
70  const std::string &command="" );
71 
73  EntryHandle insert( EntryHandle parent, const std::string &title,
74  const FeedbackCallback &feedback_cb );
75 
77  EntryHandle insert( EntryHandle parent, const std::string &title,
78  const uint8_t command_type = visualization_msgs::MenuEntry::FEEDBACK,
79  const std::string &command="" );
80 
82  bool setVisible( EntryHandle handle, bool visible );
83 
85  bool setCheckState( EntryHandle handle, CheckState check_state );
86 
89  bool getCheckState( EntryHandle handle, CheckState &check_state ) const;
90 
93  bool apply( InteractiveMarkerServer &server, const std::string &marker_name );
94 
97 
100  bool getTitle( EntryHandle handle, std::string &title ) const;
101 
102 private:
103 
105  {
106  std::string title;
107  std::string command;
108  uint8_t command_type;
109  std::vector<EntryHandle> sub_entries;
110  bool visible;
113  };
114 
115  // Call registered callback functions for given feedback command
116  void processFeedback( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
117 
118  // Create and push MenuEntry objects from handles_in onto
119  // entries_out. Calls itself recursively to add the entire menu
120  // tree.
121  bool pushMenuEntries( std::vector<EntryHandle>& handles_in,
122  std::vector<visualization_msgs::MenuEntry>& entries_out,
123  EntryHandle parent_handle );
124 
125  visualization_msgs::MenuEntry makeEntry( EntryContext& context, EntryHandle handle, EntryHandle parent_handle );
126 
127  // Insert without adding a top-level entry
128  EntryHandle doInsert( const std::string &title,
129  const uint8_t command_type,
130  const std::string &command,
131  const FeedbackCallback &feedback_cb );
132 
133  std::vector<EntryHandle> top_level_handles_;
134 
135  boost::unordered_map<EntryHandle, EntryContext> entry_contexts_;
136 
138 
139  std::set<std::string> managed_markers_;
140 };
141 
142 }
143 
144 #endif
interactive_markers::MenuHandler::makeEntry
visualization_msgs::MenuEntry makeEntry(EntryContext &context, EntryHandle handle, EntryHandle parent_handle)
Definition: menu_handler.cpp:228
interactive_markers::MenuHandler::managed_markers_
std::set< std::string > managed_markers_
Definition: menu_handler.h:139
interactive_markers::MenuHandler::EntryContext::visible
bool visible
Definition: menu_handler.h:110
interactive_markers::MenuHandler::processFeedback
void processFeedback(const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback)
Definition: menu_handler.cpp:254
interactive_markers::MenuHandler::EntryHandle
uint32_t EntryHandle
Definition: menu_handler.h:51
interactive_marker_server.h
interactive_markers::MenuHandler::entry_contexts_
boost::unordered_map< EntryHandle, EntryContext > entry_contexts_
Definition: menu_handler.h:135
interactive_markers::MenuHandler::MenuHandler
MenuHandler()
Definition: menu_handler.cpp:40
interactive_markers::MenuHandler::UNCHECKED
@ UNCHECKED
Definition: menu_handler.h:59
interactive_markers::MenuHandler::pushMenuEntries
bool pushMenuEntries(std::vector< EntryHandle > &handles_in, std::vector< visualization_msgs::MenuEntry > &entries_out, EntryHandle parent_handle)
Definition: menu_handler.cpp:160
interactive_markers::MenuHandler::apply
bool apply(InteractiveMarkerServer &server, const std::string &marker_name)
Definition: menu_handler.cpp:139
interactive_markers::MenuHandler
Definition: menu_handler.h:47
interactive_markers::MenuHandler::EntryContext::feedback_cb
FeedbackCallback feedback_cb
Definition: menu_handler.h:112
interactive_markers::MenuHandler::EntryContext::title
std::string title
Definition: menu_handler.h:106
interactive_markers::MenuHandler::EntryContext
Definition: menu_handler.h:104
interactive_markers::MenuHandler::setVisible
bool setVisible(EntryHandle handle, bool visible)
Specify if an entry should be visible or hidden.
Definition: menu_handler.cpp:93
interactive_markers::MenuHandler::CHECKED
@ CHECKED
Definition: menu_handler.h:58
interactive_markers::MenuHandler::setCheckState
bool setCheckState(EntryHandle handle, CheckState check_state)
Specify if an entry is checked or can't be checked at all.
Definition: menu_handler.cpp:108
interactive_markers::MenuHandler::EntryContext::command_type
uint8_t command_type
Definition: menu_handler.h:108
interactive_markers::MenuHandler::NO_CHECKBOX
@ NO_CHECKBOX
Definition: menu_handler.h:57
interactive_markers::InteractiveMarkerServer
Definition: interactive_marker_server.h:56
server
boost::shared_ptr< interactive_markers::InteractiveMarkerServer > server
Definition: bursty_tf.cpp:43
interactive_markers::MenuHandler::FeedbackConstPtr
visualization_msgs::InteractiveMarkerFeedbackConstPtr FeedbackConstPtr
Definition: menu_handler.h:53
interactive_markers::MenuHandler::EntryContext::command
std::string command
Definition: menu_handler.h:107
visibility_control.hpp
interactive_markers::MenuHandler::current_handle_
EntryHandle current_handle_
Definition: menu_handler.h:137
interactive_markers::MenuHandler::insert
EntryHandle insert(const std::string &title, const FeedbackCallback &feedback_cb)
Insert top-level entry with feedback function.
Definition: menu_handler.cpp:46
interactive_markers::MenuHandler::getTitle
bool getTitle(EntryHandle handle, std::string &title) const
Definition: menu_handler.cpp:265
interactive_markers::MenuHandler::reApply
bool reApply(InteractiveMarkerServer &server)
Re-apply to all markers that this was applied to previously.
Definition: menu_handler.cpp:192
interactive_markers::MenuHandler::CheckState
CheckState
Definition: menu_handler.h:56
interactive_markers
Definition: message_context.h:45
interactive_markers::MenuHandler::FeedbackCallback
boost::function< void(const FeedbackConstPtr &) > FeedbackCallback
Definition: menu_handler.h:54
interactive_markers::MenuHandler::EntryContext::check_state
CheckState check_state
Definition: menu_handler.h:111
interactive_markers::MenuHandler::top_level_handles_
std::vector< EntryHandle > top_level_handles_
Definition: menu_handler.h:133
interactive_markers::MenuHandler::doInsert
EntryHandle doInsert(const std::string &title, const uint8_t command_type, const std::string &command, const FeedbackCallback &feedback_cb)
Definition: menu_handler.cpp:208
interactive_markers::MenuHandler::EntryContext::sub_entries
std::vector< EntryHandle > sub_entries
Definition: menu_handler.h:109
interactive_markers::MenuHandler::getCheckState
bool getCheckState(EntryHandle handle, CheckState &check_state) const
Definition: menu_handler.cpp:123


interactive_markers
Author(s): David Gossow, William Woodall
autogenerated on Fri Oct 27 2023 02:31:54