menu_handler.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2011, Willow Garage, Inc.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  * 
00029  * Author: David Gossow
00030  */
00031 
00032 #ifndef INTERACTIVE_MARKER_MENU_HANDLER
00033 #define INTERACTIVE_MARKER_MENU_HANDLER
00034 
00035 #include <visualization_msgs/MenuEntry.h>
00036 #include <interactive_markers/interactive_marker_server.h>
00037 
00038 #include <boost/function.hpp>
00039 #include <boost/unordered_map.hpp>
00040 
00041 namespace interactive_markers
00042 {
00043 
00044 // Simple non-intrusive helper class which creates a menu and maps its
00045 // entries to function callbacks
00046 class MenuHandler
00047 {
00048 public:
00049 
00050   typedef uint32_t EntryHandle;
00051 
00052   typedef visualization_msgs::InteractiveMarkerFeedbackConstPtr FeedbackConstPtr;
00053   typedef boost::function< void ( const FeedbackConstPtr& ) > FeedbackCallback;
00054 
00055   enum CheckState {
00056     NO_CHECKBOX,
00057     CHECKED,
00058     UNCHECKED
00059   };
00060 
00061   MenuHandler( );
00062 
00064   EntryHandle insert( const std::string &title, const FeedbackCallback &feedback_cb );
00065 
00067   EntryHandle insert( const std::string &title,
00068                       const uint8_t command_type = visualization_msgs::MenuEntry::FEEDBACK,
00069                       const std::string &command="" );
00070 
00072   EntryHandle insert( EntryHandle parent, const std::string &title,
00073       const FeedbackCallback &feedback_cb );
00074 
00076   EntryHandle insert( EntryHandle parent, const std::string &title,
00077                       const uint8_t command_type = visualization_msgs::MenuEntry::FEEDBACK,
00078                       const std::string &command="" );
00079 
00081   bool setVisible( EntryHandle handle, bool visible );
00082 
00084   bool setCheckState( EntryHandle handle, CheckState check_state );
00085 
00088   bool getCheckState( EntryHandle handle, CheckState &check_state ) const;
00089 
00092   bool apply( InteractiveMarkerServer &server, const std::string &marker_name );
00093 
00095   bool reApply( InteractiveMarkerServer &server );
00096 
00099   bool getTitle( EntryHandle handle, std::string &title ) const;
00100 
00101 private:
00102 
00103   struct EntryContext
00104   {
00105     std::string title;
00106     std::string command;
00107     uint8_t command_type;
00108     std::vector<EntryHandle> sub_entries;
00109     bool visible;
00110     CheckState check_state;
00111     FeedbackCallback feedback_cb;
00112   };
00113 
00114   // Call registered callback functions for given feedback command
00115   void processFeedback( const visualization_msgs::InteractiveMarkerFeedbackConstPtr &feedback );
00116 
00117   // Create and push MenuEntry objects from handles_in onto
00118   // entries_out.  Calls itself recursively to add the entire menu
00119   // tree.
00120   bool pushMenuEntries( std::vector<EntryHandle>& handles_in,
00121                         std::vector<visualization_msgs::MenuEntry>& entries_out,
00122                         EntryHandle parent_handle );
00123 
00124   visualization_msgs::MenuEntry makeEntry( EntryContext& context, EntryHandle handle, EntryHandle parent_handle );
00125 
00126   // Insert without adding a top-level entry
00127   EntryHandle doInsert( const std::string &title,
00128                         const uint8_t command_type,
00129                         const std::string &command,
00130                         const FeedbackCallback &feedback_cb );
00131 
00132   std::vector<EntryHandle> top_level_handles_;
00133 
00134   boost::unordered_map<EntryHandle, EntryContext> entry_contexts_;
00135 
00136   EntryHandle current_handle_;
00137 
00138   std::set<std::string> managed_markers_;
00139 };
00140 
00141 }
00142 
00143 #endif


interactive_markers
Author(s): David Gossow
autogenerated on Sun Feb 3 2019 03:43:04