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>
37 
38 #include <boost/function.hpp>
39 #include <boost/unordered_map.hpp>
40 
41 namespace interactive_markers
42 {
43 
44 // Simple non-intrusive helper class which creates a menu and maps its
45 // entries to function callbacks
47 {
48 public:
49 
50  typedef uint32_t EntryHandle;
51 
52  typedef visualization_msgs::InteractiveMarkerFeedbackConstPtr FeedbackConstPtr;
53  typedef boost::function< void ( const FeedbackConstPtr& ) > FeedbackCallback;
54 
55  enum CheckState {
59  };
60 
61  MenuHandler( );
62 
64  EntryHandle insert( const std::string &title, const FeedbackCallback &feedback_cb );
65 
67  EntryHandle insert( const std::string &title,
68  const uint8_t command_type = visualization_msgs::MenuEntry::FEEDBACK,
69  const std::string &command="" );
70 
72  EntryHandle insert( EntryHandle parent, const std::string &title,
73  const FeedbackCallback &feedback_cb );
74 
76  EntryHandle insert( EntryHandle parent, const std::string &title,
77  const uint8_t command_type = visualization_msgs::MenuEntry::FEEDBACK,
78  const std::string &command="" );
79 
81  bool setVisible( EntryHandle handle, bool visible );
82 
84  bool setCheckState( EntryHandle handle, CheckState check_state );
85 
88  bool getCheckState( EntryHandle handle, CheckState &check_state ) const;
89 
92  bool apply( InteractiveMarkerServer &server, const std::string &marker_name );
93 
96 
99  bool getTitle( EntryHandle handle, std::string &title ) const;
100 
101 private:
102 
104  {
105  std::string title;
106  std::string command;
107  uint8_t command_type;
108  std::vector<EntryHandle> sub_entries;
109  bool visible;
111  FeedbackCallback feedback_cb;
112  };
113 
114  // Call registered callback functions for given feedback command
115  void processFeedback( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
116 
117  // Create and push MenuEntry objects from handles_in onto
118  // entries_out. Calls itself recursively to add the entire menu
119  // tree.
120  bool pushMenuEntries( std::vector<EntryHandle>& handles_in,
121  std::vector<visualization_msgs::MenuEntry>& entries_out,
122  EntryHandle parent_handle );
123 
124  visualization_msgs::MenuEntry makeEntry( EntryContext& context, EntryHandle handle, EntryHandle parent_handle );
125 
126  // Insert without adding a top-level entry
127  EntryHandle doInsert( const std::string &title,
128  const uint8_t command_type,
129  const std::string &command,
130  const FeedbackCallback &feedback_cb );
131 
132  std::vector<EntryHandle> top_level_handles_;
133 
134  boost::unordered_map<EntryHandle, EntryContext> entry_contexts_;
135 
136  EntryHandle current_handle_;
137 
138  std::set<std::string> managed_markers_;
139 };
140 
141 }
142 
143 #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:40
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:52
boost::function< void(const FeedbackConstPtr &) > FeedbackCallback
Definition: menu_handler.h:53
std::set< std::string > managed_markers_
Definition: menu_handler.h:138
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:132
boost::unordered_map< EntryHandle, EntryContext > entry_contexts_
Definition: menu_handler.h:134


interactive_markers
Author(s): David Gossow
autogenerated on Sun Feb 3 2019 03:24:09