|
tesseract 3.04.01
|
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 #ifndef NO_CUBE_BUILD 00028 #include "scrollview.h" 00029 #endif 00030 #include "params.h" 00031 #include "tesseractclass.h" 00032 00033 class SVMenuNode; 00034 00035 // A list of all possible parameter types used. 00036 enum ParamType { 00037 VT_INTEGER, 00038 VT_BOOLEAN, 00039 VT_STRING, 00040 VT_DOUBLE 00041 }; 00042 00043 // A rather hackish helper structure which can take any kind of parameter input 00044 // (defined by ParamType) and do a couple of common operations on them, like 00045 // comparisond or getting its value. It is used in the context of the 00046 // ParamsEditor as a bridge from the internal tesseract parameters to the 00047 // ones displayed by the ScrollView server. 00048 class ParamContent : public ELIST_LINK { 00049 public: 00050 // Compare two VC objects by their name. 00051 static int Compare(const void* v1, const void* v2); 00052 00053 // Gets a VC object identified by its ID. 00054 static ParamContent* GetParamContentById(int id); 00055 00056 // Constructors for the various ParamTypes. 00057 ParamContent() { 00058 } 00059 explicit ParamContent(tesseract::StringParam* it); 00060 explicit ParamContent(tesseract::IntParam* it); 00061 explicit ParamContent(tesseract::BoolParam* it); 00062 explicit ParamContent(tesseract::DoubleParam* it); 00063 00064 00065 // Getters and Setters. 00066 void SetValue(const char* val); 00067 STRING GetValue() const; 00068 const char* GetName() const; 00069 const char* GetDescription() const; 00070 00071 int GetId() { return my_id_; } 00072 bool HasChanged() { return changed_; } 00073 00074 private: 00075 // The unique ID of this VC object. 00076 int my_id_; 00077 // Whether the parameter was changed_ and thus needs to be rewritten. 00078 bool changed_; 00079 // The actual ParamType of this VC object. 00080 ParamType param_type_; 00081 00082 tesseract::StringParam* sIt; 00083 tesseract::IntParam* iIt; 00084 tesseract::BoolParam* bIt; 00085 tesseract::DoubleParam* dIt; 00086 }; 00087 00088 ELISTIZEH(ParamContent) 00089 00090 // The parameters editor enables the user to edit all the parameters used within 00091 // tesseract. It can be invoked on its own, but is supposed to be invoked by 00092 // the program editor. 00093 class ParamsEditor : public SVEventHandler { 00094 public: 00095 // Integrate the parameters editor as popupmenu into the existing scrollview 00096 // window (usually the pg editor). If sv == null, create a new empty 00097 // empty window and attach the parameter editor to that window (ugly). 00098 explicit ParamsEditor(tesseract::Tesseract*, ScrollView* sv = NULL); 00099 00100 // Event listener. Waits for SVET_POPUP events and processes them. 00101 void Notify(const SVEvent* sve); 00102 00103 private: 00104 // Gets the up to the first 3 prefixes from s (split by _). 00105 // For example, tesseract_foo_bar will be split into tesseract,foo and bar. 00106 void GetPrefixes(const char* s, STRING* level_one, 00107 STRING* level_two, STRING* level_three); 00108 00109 // Gets the first n words (split by _) and puts them in t. 00110 // For example, tesseract_foo_bar with N=2 will yield tesseract_foo_. 00111 void GetFirstWords(const char *s, // source string 00112 int n, // number of words 00113 char *t); // target string 00114 00115 // Find all editable parameters used within tesseract and create a 00116 // SVMenuNode tree from it. 00117 SVMenuNode *BuildListOfAllLeaves(tesseract::Tesseract *tess); 00118 00119 // Write all (changed_) parameters to a config file. 00120 void WriteParams(char* filename, bool changes_only); 00121 00122 ScrollView* sv_window_; 00123 }; 00124 00125 #endif 00126 #endif