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;
112  FeedbackCallback feedback_cb;
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 
137  EntryHandle current_handle_;
138 
139  std::set<std::string> managed_markers_;
140 };
141 
142 }
143 
144 #endif
EntryHandle doInsert(const std::string &title, const uint8_t command_type, const std::string &command, const FeedbackCallback &feedback_cb)
bool pushMenuEntries(std::vector< EntryHandle > &handles_in, std::vector< visualization_msgs::MenuEntry > &entries_out, EntryHandle parent_handle)
visualization_msgs::MenuEntry makeEntry(EntryContext &context, EntryHandle handle, EntryHandle parent_handle)
bool getCheckState(EntryHandle handle, CheckState &check_state) const
void processFeedback(const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback)
boost::shared_ptr< interactive_markers::InteractiveMarkerServer > server
Definition: bursty_tf.cpp:43
bool apply(InteractiveMarkerServer &server, const std::string &marker_name)
bool getTitle(EntryHandle handle, std::string &title) const
bool setVisible(EntryHandle handle, bool visible)
Specify if an entry should be visible or hidden.
bool setCheckState(EntryHandle handle, CheckState check_state)
Specify if an entry is checked or can&#39;t be checked at all.
EntryHandle insert(const std::string &title, const FeedbackCallback &feedback_cb)
Insert top-level entry with feedback function.
visualization_msgs::InteractiveMarkerFeedbackConstPtr FeedbackConstPtr
Definition: menu_handler.h:53
boost::function< void(const FeedbackConstPtr &) > FeedbackCallback
Definition: menu_handler.h:54
std::set< std::string > managed_markers_
Definition: menu_handler.h:139
bool reApply(InteractiveMarkerServer &server)
Re-apply to all markers that this was applied to previously.
std::vector< EntryHandle > top_level_handles_
Definition: menu_handler.h:133
boost::unordered_map< EntryHandle, EntryContext > entry_contexts_
Definition: menu_handler.h:135


interactive_markers
Author(s): David Gossow, William Woodall
autogenerated on Thu Oct 8 2020 04:02:35