Note: Goby version 1 (shown here) is now considered obsolete. Please use version 2 for new projects, and consider upgrading old projects.

Goby Underwater Autonomy Project  Series: 1.1, revision: 163, released on 2013-02-06 14:23:27 -0500
moos/iCommander/commander_cdk.h
00001 // t. schneider tes@mit.edu 02.24.09
00002 // ocean engineering graduate student - mit / whoi joint program
00003 // massachusetts institute of technology (mit)
00004 // laboratory for autonomous marine sensing systems (lamss)
00005 // 
00006 // this is commander_cdk.h
00007 //
00008 // see the readme file within this directory for information
00009 // pertaining to usage and purpose of this script.
00010 //
00011 // This program is free software: you can redistribute it and/or modify
00012 // it under the terms of the GNU General Public License as published by
00013 // the Free Software Foundation, either version 3 of the License, or
00014 // (at your option) any later version.
00015 //
00016 // This software is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 // GNU General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU General Public License
00022 // along with this software.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 #include <vector>
00025 #include <string>
00026 #include <iostream>
00027 #include <cmath>
00028 
00029 #include <cdk/cdk.h>
00030 #include <boost/function.hpp>
00031 
00032 typedef boost::function<bool(int, int, std::string &, chtype)> cdk_callback;
00033 
00034 static cdk_callback post_cb_;
00035 static cdk_callback pre_cb_;
00036 
00037 const int GENERIC_WIDTH = 60;
00038 const int GENERIC_HEIGHT = 25;
00039 
00040 class CommanderCdk
00041 {
00042   public:
00043   CommanderCdk()
00044       : matrix_(NULL),
00045         box_(true),
00046         shadow_(false),
00047         info_box_set_(false),
00048         lower_info_box_set_(false),
00049         initialized_(false),
00050         matrix_interrupt_(false),
00051         lower_box_size_(0)
00052         { }
00053     
00054     ~CommanderCdk() { cleanup(); }
00055     
00056     void initialize();
00057     void cleanup();
00058     
00059     bool disp_scroll(std::string title,
00060                     std::vector<std::string>  buttons,
00061                      int & selection,
00062                      bool do_split_title = false);
00063 
00064     bool disp_scroll(std::string title,
00065                      std::vector<std::string>  buttons)
00066     {
00067         int ignored;
00068         return disp_scroll(title, buttons, ignored);
00069     }
00070     
00071     bool disp_alphalist(const std::string title,
00072                        const std::string label,
00073                        const std::vector<std::string> & items,
00074                        int & selection);
00075     
00076     bool disp_matrix(const std::string title,
00077                      int rows,
00078                      int cols,
00079                      int fieldwidth,
00080                      const std::vector<std::string> & rowtitles,
00081                      const std::vector<std::string> & coltitles,
00082                      std::vector<std::string> & values,
00083                      cdk_callback pre_cb = NULL,
00084                      cdk_callback post_cb = NULL,
00085                      int startx = CENTER,
00086                      int starty = CENTER);
00087 
00088     bool disp_matrix_popup(std::string title,
00089                            std::vector<std::string> buttons);
00090     
00091     
00092     bool disp_fselect(const std::string title,
00093                       const std::string label,
00094                       std::string & name);    
00095     
00096     bool disp_info(const std::vector<std::string> & lines);
00097     bool disp_lower_info(const std::vector<std::string> & lines);
00098 
00099     void refresh();
00100 
00101     bool initialized () {return initialized_;}
00102 
00103 
00104     void cursor_on();
00105     void cursor_off();
00106 
00107     void set_matrix_val(int row, int col, std::string s);
00108     void get_matrix_val(int row, int col, std::string & s);
00109     void set_lower_box_size(int size) { lower_box_size_ = size; }
00110 
00111     void resize();
00112 
00113     
00114     
00115   private:
00116     void fail();
00117     void restore_widgets();
00118 
00119     std::string word_wrap(std::string s, int width, const std::string & delim)
00120     {
00121         std::string out;
00122 
00123         while((int)s.length() > width)
00124         {            
00125             std::string::size_type pos_newline = s.find("\n");
00126             std::string::size_type pos_delim = s.substr(0, width).find_last_of(delim);
00127             if((int)pos_newline < width)
00128             {
00129                 out += s.substr(0, pos_newline);
00130                 s = s.substr(pos_newline+1);
00131             }
00132             else if (pos_delim != std::string::npos)
00133             {
00134                 out += s.substr(0, pos_delim+1);
00135                 s = s.substr(pos_delim+1);
00136             }
00137             else
00138             {
00139                 out += s.substr(0, width);
00140                 s = s.substr(width);
00141             }
00142             out += "\n";        
00143         }
00144         out += s;
00145         
00146         return out;
00147     }
00148 
00149     
00150   private:
00151     WINDOW *cursesWin_;
00152     CDKSCREEN * cdkscreen_;
00153     
00154     CDKLABEL * info_box_;
00155     CDKLABEL * lower_info_box_;
00156 
00157     CDKMATRIX * matrix_;
00158     
00159     bool box_;
00160     bool shadow_;
00161     bool info_box_set_;
00162     bool lower_info_box_set_;
00163     bool initialized_;
00164 
00165     bool matrix_interrupt_;       
00166 
00167     int lower_box_size_;
00168 
00169     EObjectType top_widget_type_;
00170     void * top_widget_object_;
00171 
00172 };
00173 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends