24# include "config_auto.h"
27#ifndef GRAPHICS_DISABLED
46# define VARDIR "configs/"
47# define MAX_ITEMS_IN_SUBMENU 30
53static std::map<int, ParamContent *> vcMap;
54static int nrParams = 0;
55static int writeCommands[2];
97void ParamsEditor::GetFirstWords(
const char *s,
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);
125 return "ERROR: ParamContent::GetName()";
148 result += std::to_string(*
iIt);
150 result += std::to_string(*
bIt);
152 result += std::to_string(*
dIt);
169 std::stringstream stream(val);
171 stream.imbue(std::locale::classic());
182void ParamsEditor::GetPrefixes(
const char *s, std::string *level_one, std::string *level_two,
183 std::string *level_three) {
184 std::unique_ptr<char[]>
p(
new char[1024]);
185 GetFirstWords(s, 1,
p.get());
186 *level_one =
p.get();
187 GetFirstWords(s, 2,
p.get());
188 *level_two =
p.get();
189 GetFirstWords(s, 3,
p.get());
190 *level_three =
p.get();
205 ParamContent_LIST vclist;
206 ParamContent_IT vc_it(&vclist);
209 std::map<const char *, int> amount;
212 int num_iterations = (tess->
params() ==
nullptr) ? 1 : 2;
213 for (
int v = 0; v < num_iterations; ++v) {
219 vc_it.add_after_then_move(
new ParamContent(param));
222 vc_it.add_after_then_move(
new ParamContent(param));
225 vc_it.add_after_then_move(
new ParamContent(param));
230 for (vc_it.mark_cycle_pt(); !vc_it.cycled_list(); vc_it.forward()) {
231 ParamContent *vc = vc_it.data();
236 GetPrefixes(vc->GetName(), &tag, &tag2, &tag3);
237 amount[tag.c_str()]++;
238 amount[tag2.c_str()]++;
239 amount[tag3.c_str()]++;
244 SVMenuNode *other = mr->AddChild(
"OTHER");
247 vc_it.move_to_first();
248 for (vc_it.mark_cycle_pt(); !vc_it.cycled_list(); vc_it.forward()) {
249 ParamContent *vc = vc_it.data();
253 GetPrefixes(vc->GetName(), &tag, &tag2, &tag3);
255 if (amount[tag.c_str()] == 1) {
256 other->AddChild(vc->GetName(), vc->GetId(), vc->GetValue().c_str(), vc->GetDescription());
258 SVMenuNode *sv = mr->AddChild(tag.c_str());
260 sv->AddChild(vc->GetName(), vc->GetId(), vc->GetValue().c_str(), vc->GetDescription());
262 SVMenuNode *sv2 = sv->AddChild(tag2.c_str());
263 sv2->AddChild(vc->GetName(), vc->GetId(), vc->GetValue().c_str(), vc->GetDescription());
275 WriteParams(param,
false);
276 }
else if (sve->
command_id == writeCommands[1]) {
277 WriteParams(param,
true);
291 const char *name =
"ParamEditorMAIN";
292 sv =
new ScrollView(name, 1, 1, 200, 200, 300, 200);
300 SVMenuNode *svMenuRoot = BuildListOfAllLeaves(tess);
302 std::string paramfile;
305 paramfile +=
"edited";
309 writeCommands[0] = nrParams + 1;
310 std_menu->
AddChild(
"All Parameters", writeCommands[0], paramfile.c_str(),
"Config file name?");
312 writeCommands[1] = nrParams + 2;
313 std_menu->
AddChild(
"changed_ Parameters Only", writeCommands[1], paramfile.c_str(),
314 "Config file name?");
320void ParamsEditor::WriteParams(
char *filename,
bool changes_only) {
323 if ((fp = fopen(filename,
"rb")) !=
nullptr) {
325 std::stringstream msg;
326 msg <<
"Overwrite file " << filename <<
"? (Y/N)";
333 fp = fopen(filename,
"wb");
335 sv_window_->
AddMessageF(
"Can't write to file %s", filename);
338 for (
auto &iter : vcMap) {
339 ParamContent *cur = iter.second;
340 if (!changes_only || cur->HasChanged()) {
341 fprintf(fp,
"%-25s %-12s # %s\n", cur->GetName(), cur->GetValue().c_str(),
342 cur->GetDescription());
#define MAX_ITEMS_IN_SUBMENU
tesseract::ParamsVectors * GlobalParams()
void SetValue(const char *val)
std::string GetValue() const
static int Compare(const void *v1, const void *v2)
tesseract::StringParam * sIt
const char * GetDescription() const
static ParamContent * GetParamContentById(int id)
tesseract::IntParam * iIt
const char * GetName() const
tesseract::BoolParam * bIt
tesseract::DoubleParam * dIt
void Notify(const SVEvent *sve) override
ParamsEditor(tesseract::Tesseract *, ScrollView *sv=nullptr)
std::vector< BoolParam * > bool_params
std::vector< StringParam * > string_params
std::vector< IntParam * > int_params
std::vector< DoubleParam * > double_params
const char * name_str() const
const char * info_str() const
void set_value(int32_t value)
void set_value(bool value)
void set_value(const std::string &value)
const char * c_str() const
void set_value(double value)
int ShowYesNoDialog(const char *msg)
void AddMessageF(const char *format,...) __attribute__((format(gnu_printf
SVMenuNode * AddChild(const char *txt)
void BuildMenu(ScrollView *sv, bool menu_bar=true)