display/varabled.h File Reference

Go to the source code of this file.

Functions


Function Documentation

MENU_L_LIST* build_list_of_all_leaves (  ) 

Find all variables

Generate a list of menu leaves for each of the variables. The list is heterogeneous, different menu leaf types for each variable type.

Definition at line 40 of file varabled.cpp.

References double_VARIABLE::get_head(), STRING_VARIABLE::get_head(), BOOL_VARIABLE::get_head(), and INT_VARIABLE::get_head().

Referenced by start_variables_editor().

00040                                         {  //find all variables
00041   INT_VARIABLE_C_IT int_it (INT_VARIABLE::get_head ());
00042   BOOL_VARIABLE_C_IT bool_it (BOOL_VARIABLE::get_head ());
00043   STRING_VARIABLE_C_IT str_it (STRING_VARIABLE::get_head ());
00044   double_VARIABLE_C_IT dbl_it (double_VARIABLE::get_head ());
00045 
00046   MENU_L_LIST *all_leaves_list = new MENU_L_LIST;
00047   MENU_L_IT it;
00048 
00049   it.set_to_list (all_leaves_list);
00050 
00051   for (int_it.mark_cycle_pt (); !int_it.cycled_list (); int_it.forward ())
00052     it.add_to_end (new MENU_L (new INT_VAR_MENU_LEAF (int_it.data ())));
00053 
00054   for (bool_it.mark_cycle_pt (); !bool_it.cycled_list (); bool_it.forward ())
00055     it.add_to_end (new MENU_L (new BOOL_VAR_MENU_LEAF (bool_it.data ())));
00056 
00057   for (str_it.mark_cycle_pt (); !str_it.cycled_list (); str_it.forward ())
00058     it.add_to_end (new MENU_L (new STR_VAR_MENU_LEAF (str_it.data ())));
00059 
00060   for (dbl_it.mark_cycle_pt (); !dbl_it.cycled_list (); dbl_it.forward ())
00061     it.add_to_end (new MENU_L (new DBL_VAR_MENU_LEAF (dbl_it.data ())));
00062 
00063   return all_leaves_list;
00064 }

MENU_ROOT* build_main_var_menu ( MENU_L_LIST *  all_leaves_list  ) 

Build Menus

Extract each element from the sorted, non empty list of menu leaves & add each to the appropriate menu. Note that ALL menus for ALL variable editor windows are built at this stage. The VAR_SUB_MENU menu leaves used in the leaves of the top level window hold the root menus for the sub windows for use if and when that window is created. A little wastful on space perhaps, but easier than reconstructing/sorting/etc the all_leaves_list.

Definition at line 77 of file varabled.cpp.

References NON_RADIO_MENU::add_child(), VAR_NON_RADIO_MENU::add_child(), MENU_ROOT::add_child(), datadir, extract_sublist(), get_first_words(), KILL_WINDOW_CMD, leaf, NULL, STRING::string(), VARDIR, WRITE_ALL_CMD, and WRITE_CHANGED_CMD.

Referenced by start_variables_editor().

00078                                                              {
00079   MENU_L_IT it;
00080   MENU_L_LIST sub_window_list;
00081   MENU_L_LIST sub_menu_list;
00082 
00083   MENU_ROOT *main_root;
00084   VAR_NON_RADIO_MENU *main_menu;
00085   NON_RADIO_MENU *std_menu;
00086   MENU_ROOT *main_misc_root = NULL;
00087   VAR_NON_RADIO_MENU *main_misc_menu = NULL;
00088   MENU_ROOT *sub_window_root;
00089   VAR_NON_RADIO_MENU *current_sub_win_menu;
00090   VAR_NON_RADIO_MENU *sub_window_misc_menu;
00091   MENU_L *leaf;
00092   const char *full_name;
00093   char first_word[80];
00094   char first_two_words[80];
00095   int header_len;
00096   STRING varfile;                //save config filename
00097 
00098   main_root = new MENU_ROOT;
00099   main_menu = new VAR_NON_RADIO_MENU ("SubMenus");
00100   main_root->add_child (main_menu);
00101 
00102   while (!all_leaves_list->empty ()) {
00103                                  // Whatever is left
00104     it.set_to_list (all_leaves_list);
00105     full_name = (it.data ()->ptr)->cmp_str ();
00106                                  // 1st word delim by _
00107     get_first_words (full_name, 1, first_word);
00108     extract_sublist(all_leaves_list, first_word, &sub_window_list); 
00109 
00110                                  //addto main misc menu
00111     if (sub_window_list.singleton ()) {
00112       if (main_misc_root == NULL) {
00113         main_misc_root = new MENU_ROOT;
00114         main_misc_menu = new VAR_NON_RADIO_MENU ("Miscellaneous");
00115         main_misc_root->add_child (main_misc_menu);
00116       }
00117       it.set_to_list (&sub_window_list);
00118       leaf = it.extract ();
00119       leaf->ptr->new_label (full_name);
00120       main_misc_menu->add_child (leaf);
00121     }
00122     else {                       //build subwindow menu
00123       sub_window_root = new MENU_ROOT;
00124       main_menu->add_child (new VAR_SUB_MENU (first_word,
00125         sub_window_root));
00126       sub_window_misc_menu = new VAR_NON_RADIO_MENU ("Miscellaneous");
00127       sub_window_misc_menu->
00128         add_child (new
00129         SIMPLE_MENU_LEAF ("Kill Sub Window", KILL_WINDOW_CMD));
00130       while (!sub_window_list.empty ()) {
00131         it.set_to_list (&sub_window_list);
00132         full_name = it.data ()->ptr->cmp_str ();
00133         get_first_words (full_name, 2, first_two_words);
00134         extract_sublist(&sub_window_list, first_two_words, &sub_menu_list); 
00135 
00136         it.set_to_list (&sub_menu_list);
00137                                  //addto subwin misc
00138         if (sub_menu_list.singleton ()) {
00139           leaf = it.extract ();
00140           leaf->ptr->new_label (full_name);
00141           sub_window_misc_menu->add_child (leaf);
00142         }
00143         else {
00144                                  //build sub menu
00145           current_sub_win_menu =
00146             new VAR_NON_RADIO_MENU(first_two_words); 
00147           sub_window_root->add_child (current_sub_win_menu);
00148           header_len = strlen (first_two_words);
00149           while (!sub_menu_list.empty ()) {
00150             it.set_to_list (&sub_menu_list);
00151             leaf = it.extract ();
00152             leaf->ptr->new_label (leaf->ptr->cmp_str () +
00153               header_len);
00154             current_sub_win_menu->add_child (leaf);
00155           }
00156         }
00157       }
00158       sub_window_root->add_child (sub_window_misc_menu);
00159     }
00160   }
00161   if (main_misc_root != NULL)
00162     main_root->add_child (main_misc_root);
00163 
00164   varfile = datadir;
00165   varfile += VARDIR;             /*variables dir */
00166   varfile += "edited";           /*actual name */
00167 
00168   std_menu = new NON_RADIO_MENU ("Build Config File");
00169   main_root->add_child (std_menu);
00170   std_menu->add_child (new VARIABLE_MENU_LEAF ("All Variables",
00171     WRITE_ALL_CMD,
00172     varfile.string ()));
00173   std_menu->add_child (new VARIABLE_MENU_LEAF ("Changed Variables Only",
00174     WRITE_CHANGED_CMD,
00175     varfile.string ()));
00176   return main_root;
00177 }

void extract_sublist ( MENU_L_LIST *  source_list,
char *  leading_str,
MENU_L_LIST *  extracted_list 
)

Remove initial items

Extract a sublist containing elements whose name initially matches the specified string

Definition at line 186 of file varabled.cpp.

Referenced by build_main_var_menu().

00190                       {
00191   MENU_L_IT start_it(source_list); 
00192   MENU_L_IT end_it(source_list); 
00193   int match_len = strlen (leading_str);
00194 
00195   while (!end_it.at_last () &&
00196     (strncmp (leading_str, end_it.data_relative (1)->ptr->cmp_str (),
00197     match_len) == 0))
00198     end_it.forward ();
00199   extracted_list->assign_to_sublist (&start_it, &end_it);
00200 }

void get_first_words ( const char *  s,
int  n,
char *  t 
)

Copy first N words

Copy the first N words from the source string to the target string. Words are delimited by "_"

Definition at line 209 of file varabled.cpp.

Referenced by build_main_var_menu().

00213                       {
00214   int full_length = strlen (s);
00215   int reqd_len = 0;              //No. of chars requird
00216   const char *next_word = s;
00217 
00218   while ((n > 0) && reqd_len < full_length) {
00219     reqd_len += strcspn (next_word, "_") + 1;
00220     next_word += reqd_len;
00221     n--;
00222   }
00223   strncpy(t, s, reqd_len); 
00224   t[reqd_len] = '\0';            //ensure null terminal
00225 }

int menu_item_sorter ( const void *  item1,
const void *  item2 
)

Sorter

Given two MENU_L items, sort them on the basis of their cmp_str; LIST SORT COMPARATOR

Definition at line 234 of file varabled.cpp.

References MENU_NODE::cmp_str(), and MENU_L::ptr.

Referenced by start_variables_editor().

00236                                         {
00237   MENU_L *menu_l_1 = (*(MENU_L **) item1);
00238   MENU_L *menu_l_2 = (*(MENU_L **) item2);
00239 
00240   MENU_NODE *node1;
00241   MENU_NODE *node2;
00242 
00243   const char *str1;
00244   const char *str2;
00245 
00246   node1 = menu_l_1->ptr;
00247   node2 = menu_l_2->ptr;
00248 
00249   str1 = node1->cmp_str ();
00250   str2 = node2->cmp_str ();
00251 
00252   return strcmp (str1, str2);
00253 }

void start_variables_editor (  ) 

Create top level win

Create the top level variables editor window. Build all the menus for all the subwindows in the process.

Definition at line 262 of file varabled.cpp.

References build_list_of_all_leaves(), build_main_var_menu(), ERRCODE::error(), LOG, menu_item_sorter(), NO_VARIABLES_TO_EDIT, and NULL.

Referenced by TessBaseAPI::Recognize().

00262                               {  //create top level win
00263   MENU_L_LIST *all_leaves_list = new MENU_L_LIST;
00264   MENU_L_IT it;
00265 
00266   all_leaves_list = build_list_of_all_leaves ();
00267   it.set_to_list (all_leaves_list);
00268   if (it.empty ()) {
00269     NO_VARIABLES_TO_EDIT.error ("start_variables_editor", LOG, NULL);
00270   }
00271   it.sort (&menu_item_sorter);
00272 
00273   new VARIABLES_WINDOW ("VarEditorMAIN",
00274     build_main_var_menu (all_leaves_list), NULL);
00275 }


Generated on Wed Feb 28 19:49:24 2007 for Tesseract by  doxygen 1.5.1