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()";
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);
198 ParamContent_LIST vclist;
199 ParamContent_IT vc_it(&vclist);
202 std::map<const char*, int> amount;
206 int num_iterations = (tess->
params() ==
NULL) ? 1 : 2;
207 for (v = 0; v < num_iterations; ++v) {
209 for (i = 0; i < vec->
int_params.size(); ++i) {
224 for (vc_it.mark_cycle_pt(); !vc_it.cycled_list(); vc_it.forward()) {
230 GetPrefixes(vc->
GetName(), &tag, &tag2, &tag3);
232 amount[tag2.string()]++;
241 vc_it.move_to_first();
242 for (vc_it.mark_cycle_pt(); !vc_it.cycled_list(); vc_it.forward()) {
247 GetPrefixes(vc->
GetName(), &tag, &tag2, &tag3);
249 if (amount[tag.
string()] == 1) {
255 (amount[tag2.string()] <= 1)) {
273 WriteParams(param,
false);
274 }
else if (sve->
command_id == writeCommands[1]) {
275 WriteParams(param,
true);
292 const char*
name =
"ParamEditorMAIN";
293 sv =
new ScrollView(name, 1, 1, 200, 200, 300, 200);
301 SVMenuNode* svMenuRoot = BuildListOfAllLeaves(tess);
306 paramfile +=
"edited";
310 writeCommands[0] = nrParams+1;
311 std_menu->
AddChild(
"All Parameters", writeCommands[0],
312 paramfile.
string(),
"Config file name?");
314 writeCommands[1] = nrParams+2;
315 std_menu->
AddChild (
"changed_ Parameters Only", writeCommands[1],
316 paramfile.
string(),
"Config file name?");
323 void ParamsEditor::WriteParams(
char *
filename,
328 if ((fp = fopen (filename,
"rb")) !=
NULL) {
330 sprintf (msg_str,
"Overwrite file " "%s" "? (Y/N)", filename);
332 if (a ==
'n') {
return; }
336 fp = fopen (filename,
"wb");
338 sv_window_->
AddMessage(
"Cant write to file " "%s" "", filename);
342 for (std::map<int, ParamContent*>::iterator iter = vcMap.begin();
347 fprintf(fp,
"%-25s %-12s # %s\n",
#define ELISTIZE(CLASSNAME)
void BuildMenu(ScrollView *sv, bool menu_bar=true)
void AddMessage(const char *format,...)
#define MAX_ITEMS_IN_SUBMENU
void set_value(BOOL8 value)
const char * name_str() const
void set_value(double value)
void Notify(const SVEvent *sve)
static ParamContent * GetParamContentById(int id)
GenericVector< IntParam * > int_params
void SetValue(const char *val)
const char * GetName() const
const char * info_str() const
GenericVector< BoolParam * > bool_params
void add_str_int(const char *str, int number)
GenericVector< DoubleParam * > double_params
void set_value(inT32 value)
ParamsEditor(tesseract::Tesseract *, ScrollView *sv=NULL)
void add_str_double(const char *str, double number)
tesseract::ParamsVectors * GlobalParams()
SVMenuNode * AddChild(const char *txt)
const char * string() const
static int Compare(const void *v1, const void *v2)
int ShowYesNoDialog(const char *msg)
const char * GetDescription() const
GenericVector< StringParam * > string_params
const char * string() const
void set_value(const STRING &value)