All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
paramsd.h
Go to the documentation of this file.
1 // File: paramsd.cpp
3 // Description: Tesseract parameter editor
4 // Author: Joern Wanke
5 // Created: Wed Jul 18 10:05:01 PDT 2007
6 //
7 // (C) Copyright 2007, Google Inc.
8 // Licensed under the Apache License, Version 2.0 (the "License");
9 // you may not use this file except in compliance with the License.
10 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
17 //
19 //
20 // Tesseract parameter editor is used to edit all the parameters used
21 // within tesseract from the ui.
22 #ifndef GRAPHICS_DISABLED
23 #ifndef VARABLED_H
24 #define VARABLED_H
25 
26 #include "elst.h"
27 #ifndef ANDROID_BUILD
28 #include "scrollview.h"
29 #endif
30 #include "params.h"
31 #include "tesseractclass.h"
32 
33 class SVMenuNode;
34 
35 // A list of all possible parameter types used.
36 enum ParamType {
41 };
42 
43 // A rather hackish helper structure which can take any kind of parameter input
44 // (defined by ParamType) and do a couple of common operations on them, like
45 // comparisond or getting its value. It is used in the context of the
46 // ParamsEditor as a bridge from the internal tesseract parameters to the
47 // ones displayed by the ScrollView server.
48 class ParamContent : public ELIST_LINK {
49  public:
50  // Compare two VC objects by their name.
51  static int Compare(const void* v1, const void* v2);
52 
53  // Gets a VC object identified by its ID.
54  static ParamContent* GetParamContentById(int id);
55 
56  // Constructors for the various ParamTypes.
58  }
60  explicit ParamContent(tesseract::IntParam* it);
61  explicit ParamContent(tesseract::BoolParam* it);
63 
64 
65  // Getters and Setters.
66  void SetValue(const char* val);
67  STRING GetValue() const;
68  const char* GetName() const;
69  const char* GetDescription() const;
70 
71  int GetId() { return my_id_; }
72  bool HasChanged() { return changed_; }
73 
74  private:
75  // The unique ID of this VC object.
76  int my_id_;
77  // Whether the parameter was changed_ and thus needs to be rewritten.
78  bool changed_;
79  // The actual ParamType of this VC object.
80  ParamType param_type_;
81 
86 };
87 
89 
90 // The parameters editor enables the user to edit all the parameters used within
91 // tesseract. It can be invoked on its own, but is supposed to be invoked by
92 // the program editor.
93 class ParamsEditor : public SVEventHandler {
94  public:
95  // Integrate the parameters editor as popupmenu into the existing scrollview
96  // window (usually the pg editor). If sv == null, create a new empty
97  // empty window and attach the parameter editor to that window (ugly).
99 
100  // Event listener. Waits for SVET_POPUP events and processes them.
101  void Notify(const SVEvent* sve);
102 
103  private:
104  // Gets the up to the first 3 prefixes from s (split by _).
105  // For example, tesseract_foo_bar will be split into tesseract,foo and bar.
106  void GetPrefixes(const char* s, STRING* level_one,
107  STRING* level_two, STRING* level_three);
108 
109  // Gets the first n words (split by _) and puts them in t.
110  // For example, tesseract_foo_bar with N=2 will yield tesseract_foo_.
111  void GetFirstWords(const char *s, // source string
112  int n, // number of words
113  char *t); // target string
114 
115  // Find all editable parameters used within tesseract and create a
116  // SVMenuNode tree from it.
117  SVMenuNode *BuildListOfAllLeaves(tesseract::Tesseract *tess);
118 
119  // Write all (changed_) parameters to a config file.
120  void WriteParams(char* filename, bool changes_only);
121 
122  ScrollView* sv_window_;
123 };
124 
125 #endif
126 #endif
STRING GetValue() const
Definition: paramsd.cpp:135
bool HasChanged()
Definition: paramsd.h:72
ParamContent()
Definition: paramsd.h:57
int GetId()
Definition: paramsd.h:71
ParamType
Definition: paramsd.h:36
static ParamContent * GetParamContentById(int id)
Definition: paramsd.cpp:91
void SetValue(const char *val)
Definition: paramsd.cpp:154
const char * GetName() const
Definition: paramsd.cpp:116
#define ELISTIZEH(CLASSNAME)
Definition: elst.h:981
Definition: strngs.h:44
#define NULL
Definition: host.h:144
static int Compare(const void *v1, const void *v2)
Definition: paramsd.cpp:185
const char * GetDescription() const
Definition: paramsd.cpp:126