tesseract  4.00.00dev
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 TESSERACT_CCMAIN_PARAMSD_H_
23 #define TESSERACT_CCMAIN_PARAMSD_H_
24 
25 #ifndef GRAPHICS_DISABLED
26 
27 #include "elst.h"
28 #include "params.h"
29 #include "tesseractclass.h"
30 
31 class SVMenuNode;
32 
33 // A list of all possible parameter types used.
34 enum ParamType {
39 };
40 
41 // A rather hackish helper structure which can take any kind of parameter input
42 // (defined by ParamType) and do a couple of common operations on them, like
43 // comparisond or getting its value. It is used in the context of the
44 // ParamsEditor as a bridge from the internal tesseract parameters to the
45 // ones displayed by the ScrollView server.
46 class ParamContent : public ELIST_LINK {
47  public:
48  // Compare two VC objects by their name.
49  static int Compare(const void* v1, const void* v2);
50 
51  // Gets a VC object identified by its ID.
52  static ParamContent* GetParamContentById(int id);
53 
54  // Constructors for the various ParamTypes.
56  }
58  explicit ParamContent(tesseract::IntParam* it);
59  explicit ParamContent(tesseract::BoolParam* it);
61 
62 
63  // Getters and Setters.
64  void SetValue(const char* val);
65  STRING GetValue() const;
66  const char* GetName() const;
67  const char* GetDescription() const;
68 
69  int GetId() { return my_id_; }
70  bool HasChanged() { return changed_; }
71 
72  private:
73  // The unique ID of this VC object.
74  int my_id_;
75  // Whether the parameter was changed_ and thus needs to be rewritten.
76  bool changed_;
77  // The actual ParamType of this VC object.
78  ParamType param_type_;
79 
84 };
85 
87 
88 // The parameters editor enables the user to edit all the parameters used within
89 // tesseract. It can be invoked on its own, but is supposed to be invoked by
90 // the program editor.
91 class ParamsEditor : public SVEventHandler {
92  public:
93  // Integrate the parameters editor as popupmenu into the existing scrollview
94  // window (usually the pg editor). If sv == null, create a new empty
95  // empty window and attach the parameter editor to that window (ugly).
96  explicit ParamsEditor(tesseract::Tesseract*, ScrollView* sv = NULL);
97 
98  // Event listener. Waits for SVET_POPUP events and processes them.
99  void Notify(const SVEvent* sve);
100 
101  private:
102  // Gets the up to the first 3 prefixes from s (split by _).
103  // For example, tesseract_foo_bar will be split into tesseract,foo and bar.
104  void GetPrefixes(const char* s, STRING* level_one,
105  STRING* level_two, STRING* level_three);
106 
107  // Gets the first n words (split by _) and puts them in t.
108  // For example, tesseract_foo_bar with N=2 will yield tesseract_foo_.
109  void GetFirstWords(const char *s, // source string
110  int n, // number of words
111  char *t); // target string
112 
113  // Find all editable parameters used within tesseract and create a
114  // SVMenuNode tree from it.
115  SVMenuNode *BuildListOfAllLeaves(tesseract::Tesseract *tess);
116 
117  // Write all (changed_) parameters to a config file.
118  void WriteParams(char* filename, bool changes_only);
119 
120  ScrollView* sv_window_;
121 };
122 
123 #endif // GRAPHICS_DISABLED
124 #endif // TESSERACT_CCMAIN_PARAMSD_H_
int GetId()
Definition: paramsd.h:69
ParamContent()
Definition: paramsd.h:55
#define ELISTIZEH(CLASSNAME)
Definition: elst.h:948
ParamType
Definition: paramsd.h:34
STRING GetValue() const
Definition: paramsd.cpp:135
const char * GetDescription() const
Definition: paramsd.cpp:126
Definition: strngs.h:45
static ParamContent * GetParamContentById(int id)
Definition: paramsd.cpp:91
static int Compare(const void *v1, const void *v2)
Definition: paramsd.cpp:185
const char * GetName() const
Definition: paramsd.cpp:116
const char * filename
Definition: ioapi.h:38
void SetValue(const char *val)
Definition: paramsd.cpp:154
bool HasChanged()
Definition: paramsd.h:70