25 #include "config_auto.h" 28 #ifndef GRAPHICS_DISABLED 43 #define VARDIR "configs/" 44 #define MAX_ITEMS_IN_SUBMENU 30 50 static std::map<int, ParamContent*> vcMap;
51 static int nrParams = 0;
52 static int writeCommands[2];
96 void ParamsEditor::GetFirstWords(
101 int full_length = strlen(s);
103 const char *next_word = s;
105 while ((n > 0) && reqd_len < full_length) {
106 reqd_len += strcspn(next_word,
"_") + 1;
107 next_word += reqd_len;
110 strncpy(t, s, reqd_len);
121 return "ERROR: ParamContent::GetName()";
143 if (((
STRING) * (sIt)).
string() !=
nullptr) {
170 void ParamsEditor::GetPrefixes(
const char* s,
STRING* level_one,
173 std::unique_ptr<char[]> p(
new char[1024]);
174 GetFirstWords(s, 1, p.get());
175 *level_one = p.get();
176 GetFirstWords(s, 2, p.get());
177 *level_two = p.get();
178 GetFirstWords(s, 3, p.get());
179 *level_three = p.get();
194 ParamContent_LIST vclist;
195 ParamContent_IT vc_it(&vclist);
198 std::map<const char*, int> amount;
202 int num_iterations = (tess->
params() ==
nullptr) ? 1 : 2;
203 for (v = 0; v < num_iterations; ++v) {
205 for (i = 0; i < vec->
int_params.size(); ++i) {
220 for (vc_it.mark_cycle_pt(); !vc_it.cycled_list(); vc_it.forward()) {
226 GetPrefixes(vc->
GetName(), &tag, &tag2, &tag3);
228 amount[tag2.string()]++;
237 vc_it.move_to_first();
238 for (vc_it.mark_cycle_pt(); !vc_it.cycled_list(); vc_it.forward()) {
243 GetPrefixes(vc->
GetName(), &tag, &tag2, &tag3);
245 if (amount[tag.
string()] == 1) {
251 (amount[tag2.string()] <= 1)) {
269 WriteParams(param,
false);
270 }
else if (sve->
command_id == writeCommands[1]) {
271 WriteParams(param,
true);
288 const char* name =
"ParamEditorMAIN";
289 sv =
new ScrollView(name, 1, 1, 200, 200, 300, 200);
297 SVMenuNode* svMenuRoot = BuildListOfAllLeaves(tess);
302 paramfile +=
"edited";
306 writeCommands[0] = nrParams+1;
307 std_menu->
AddChild(
"All Parameters", writeCommands[0],
308 paramfile.
string(),
"Config file name?");
310 writeCommands[1] = nrParams+2;
311 std_menu->
AddChild (
"changed_ Parameters Only", writeCommands[1],
312 paramfile.
string(),
"Config file name?");
319 void ParamsEditor::WriteParams(
char *filename,
324 if ((fp = fopen (filename,
"rb")) !=
nullptr) {
326 sprintf (msg_str,
"Overwrite file " "%s" "? (Y/N)", filename);
334 fp = fopen (filename,
"wb");
337 "Can't write to file " 344 for (std::map<int, ParamContent*>::iterator iter = vcMap.begin();
349 fprintf(fp,
"%-25s %-12s # %s\n",
355 #endif // GRAPHICS_DISABLED const char * GetDescription() const
const char * info_str() const
const char * GetName() const
int ShowYesNoDialog(const char *msg)
GenericVector< IntParam * > int_params
GenericVector< BoolParam * > bool_params
const char * string() const
void set_value(const STRING &value)
GenericVector< StringParam * > string_params
static int Compare(const void *v1, const void *v2)
#define MAX_ITEMS_IN_SUBMENU
const char * string() const
void Notify(const SVEvent *sve)
void SetValue(const char *val)
tesseract::ParamsVectors * GlobalParams()
const char * name_str() const
void add_str_double(const char *str, double number)
SVMenuNode * AddChild(const char *txt)
#define ELISTIZE(CLASSNAME)
static ParamContent * GetParamContentById(int id)
void add_str_int(const char *str, int number)
GenericVector< DoubleParam * > double_params
void set_value(int32_t value)
ParamsEditor(tesseract::Tesseract *, ScrollView *sv=nullptr)
void BuildMenu(ScrollView *sv, bool menu_bar=true)
void set_value(BOOL8 value)
void set_value(double value)
void AddMessage(const char *format,...)