Tesseract  3.02
tesseract-ocr/ccmain/paramsd.h
Go to the documentation of this file.
00001 
00002 // File:        paramsd.cpp
00003 // Description: Tesseract parameter editor
00004 // Author:      Joern Wanke
00005 // Created:     Wed Jul 18 10:05:01 PDT 2007
00006 //
00007 // (C) Copyright 2007, Google Inc.
00008 // Licensed under the Apache License, Version 2.0 (the "License");
00009 // you may not use this file except in compliance with the License.
00010 // You may obtain a copy of the License at
00011 // http://www.apache.org/licenses/LICENSE-2.0
00012 // Unless required by applicable law or agreed to in writing, software
00013 // distributed under the License is distributed on an "AS IS" BASIS,
00014 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015 // See the License for the specific language governing permissions and
00016 // limitations under the License.
00017 //
00019 //
00020 // Tesseract parameter editor is used to edit all the parameters used
00021 // within tesseract from the ui.
00022 #ifndef GRAPHICS_DISABLED
00023 #ifndef VARABLED_H
00024 #define VARABLED_H
00025 
00026 #include "elst.h"
00027 #include "scrollview.h"
00028 #include "params.h"
00029 #include "tesseractclass.h"
00030 
00031 class SVMenuNode;
00032 
00033 // A list of all possible parameter types used.
00034 enum ParamType {
00035   VT_INTEGER,
00036   VT_BOOLEAN,
00037   VT_STRING,
00038   VT_DOUBLE
00039 };
00040 
00041 // A rather hackish helper structure which can take any kind of parameter input
00042 // (defined by ParamType) and do a couple of common operations on them, like
00043 // comparisond or getting its value. It is used in the context of the
00044 // ParamsEditor as a bridge from the internal tesseract parameters to the
00045 // ones displayed by the ScrollView server.
00046 class ParamContent : public ELIST_LINK {
00047  public:
00048   // Compare two VC objects by their name.
00049   static int Compare(const void* v1, const void* v2);
00050 
00051   // Gets a VC object identified by its ID.
00052   static ParamContent* GetParamContentById(int id);
00053 
00054   // Constructors for the various ParamTypes.
00055   ParamContent() {
00056   }
00057   ParamContent(tesseract::StringParam* it);
00058   ParamContent(tesseract::IntParam* it);
00059   ParamContent(tesseract::BoolParam* it);
00060   ParamContent(tesseract::DoubleParam* it);
00061 
00062 
00063   // Getters and Setters.
00064   void SetValue(const char* val);
00065   const char* GetValue() const;
00066   const char* GetName() const;
00067   const char* GetDescription() const;
00068 
00069   int GetId() { return my_id_; }
00070   bool HasChanged() { return changed_; }
00071 
00072  private:
00073   // The unique ID of this VC object.
00074   int my_id_;
00075   // Whether the parameter was changed_ and thus needs to be rewritten.
00076   bool changed_;
00077   // The actual ParamType of this VC object.
00078   ParamType param_type_;
00079 
00080   tesseract::StringParam* sIt;
00081   tesseract::IntParam* iIt;
00082   tesseract::BoolParam* bIt;
00083   tesseract::DoubleParam* dIt;
00084 };
00085 
00086 ELISTIZEH(ParamContent)
00087 
00088 // The parameters editor enables the user to edit all the parameters used within
00089 // tesseract. It can be invoked on its own, but is supposed to be invoked by
00090 // the program editor.
00091 class ParamsEditor : public SVEventHandler {
00092  public:
00093   // Integrate the parameters editor as popupmenu into the existing scrollview
00094   // window (usually the pg editor). If sv == null, create a new empty
00095   // empty window and attach the parameter editor to that window (ugly).
00096   ParamsEditor(tesseract::Tesseract*, ScrollView* sv = NULL);
00097 
00098   // Event listener. Waits for SVET_POPUP events and processes them.
00099   void Notify(const SVEvent* sve);
00100 
00101  private:
00102   // Gets the up to the first 3 prefixes from s (split by _).
00103   // For example, tesseract_foo_bar will be split into tesseract,foo and bar.
00104   void GetPrefixes(const char* s, STRING* level_one,
00105                    STRING* level_two, STRING* level_three);
00106 
00107   // Gets the first n words (split by _) and puts them in t.
00108   // For example, tesseract_foo_bar with N=2 will yield tesseract_foo_.
00109   void GetFirstWords(const char *s,  // source string
00110                      int n,          // number of words
00111                      char *t);       // target string
00112 
00113   // Find all editable parameters used within tesseract and create a
00114   // SVMenuNode tree from it.
00115   SVMenuNode *BuildListOfAllLeaves(tesseract::Tesseract *tess);
00116 
00117   // Write all (changed_) parameters to a config file.
00118   void WriteParams(char* filename, bool changes_only);
00119 
00120   ScrollView* sv_window_;
00121 };
00122 
00123 #endif
00124 #endif