32 #include "config_auto.h" 35 #ifndef GRAPHICS_DISABLED 44 #define VARDIR "configs/" 45 #define MAX_ITEMS_IN_SUBMENU 30 51 static std::map<int, ParamContent*> vcMap;
52 static int nrParams = 0;
53 static int writeCommands[2];
97 void ParamsEditor::GetFirstWords(
102 int full_length = strlen(s);
104 const char *next_word = s;
106 while ((n > 0) && reqd_len < full_length) {
107 reqd_len += strcspn(next_word,
"_") + 1;
108 next_word += reqd_len;
111 strncpy(t, s, reqd_len);
122 return "ERROR: ParamContent::GetName()";
144 if (((
STRING) * (sIt)).
string() != NULL) {
171 void ParamsEditor::GetPrefixes(
const char* s,
STRING* level_one,
174 char* p =
new char[1024];
175 GetFirstWords(s, 1, p);
177 GetFirstWords(s, 2, p);
179 GetFirstWords(s, 3, p);
196 ParamContent_LIST vclist;
197 ParamContent_IT vc_it(&vclist);
200 std::map<const char*, int> amount;
204 int num_iterations = (tess->
params() == NULL) ? 1 : 2;
205 for (v = 0; v < num_iterations; ++v) {
207 for (i = 0; i < vec->
int_params.size(); ++i) {
222 for (vc_it.mark_cycle_pt(); !vc_it.cycled_list(); vc_it.forward()) {
228 GetPrefixes(vc->
GetName(), &tag, &tag2, &tag3);
230 amount[tag2.string()]++;
239 vc_it.move_to_first();
240 for (vc_it.mark_cycle_pt(); !vc_it.cycled_list(); vc_it.forward()) {
245 GetPrefixes(vc->
GetName(), &tag, &tag2, &tag3);
247 if (amount[tag.
string()] == 1) {
253 (amount[tag2.string()] <= 1)) {
271 WriteParams(param,
false);
272 }
else if (sve->
command_id == writeCommands[1]) {
273 WriteParams(param,
true);
278 sv_window_->AddMessage(
"Setting %s to %s",
290 const char* name =
"ParamEditorMAIN";
291 sv =
new ScrollView(name, 1, 1, 200, 200, 300, 200);
299 SVMenuNode* svMenuRoot = BuildListOfAllLeaves(tess);
304 paramfile +=
"edited";
308 writeCommands[0] = nrParams+1;
309 std_menu->
AddChild(
"All Parameters", writeCommands[0],
310 paramfile.
string(),
"Config file name?");
312 writeCommands[1] = nrParams+2;
313 std_menu->
AddChild (
"changed_ Parameters Only", writeCommands[1],
314 paramfile.
string(),
"Config file name?");
321 void ParamsEditor::WriteParams(
char *
filename,
326 if ((fp = fopen (
filename,
"rb")) != NULL) {
328 sprintf (msg_str,
"Overwrite file " "%s" "? (Y/N)",
filename);
329 int a = sv_window_->ShowYesNoDialog(msg_str);
338 sv_window_->AddMessage(
339 "Can't write to file " 346 for (std::map<int, ParamContent*>::iterator iter = vcMap.begin();
351 fprintf(fp,
"%-25s %-12s # %s\n",
tesseract::ParamsVectors * GlobalParams()
GenericVector< IntParam * > int_params
GenericVector< DoubleParam * > double_params
const char * GetName() const
void set_value(const STRING &value)
static ParamContent * GetParamContentById(int id)
GenericVector< BoolParam * > bool_params
void add_str_int(const char *str, int number)
#define MAX_ITEMS_IN_SUBMENU
ParamsEditor(tesseract::Tesseract *, ScrollView *sv=NULL)
void add_str_double(const char *str, double number)
const char * GetDescription() const
const char * string() const
const char * string() const
void set_value(BOOL8 value)
void SetValue(const char *val)
const char * name_str() const
static int Compare(const void *v1, const void *v2)
const char * info_str() const
GenericVector< StringParam * > string_params
#define ELISTIZE(CLASSNAME)
void BuildMenu(ScrollView *sv, bool menu_bar=true)
void set_value(double value)
SVMenuNode * AddChild(const char *txt)
void set_value(inT32 value)
void Notify(const SVEvent *sve)