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