00001 # ifndef Conjecture_Element_h
00002 # define Conjecture_Element_h Conjecture_Element_h
00003
00004
00005 # include "Root.h"
00006 # include <list>
00007 # include <vector>
00008 # include <iostream>
00009 # include "Coord.h"
00010 # include "ImageArgs.h"
00011
00012
00013 namespace Conjecture {
00014
00015 class Page;
00016 class Region;
00017 class Line;
00018 class Word;
00019 class Glyph;
00020 class Image;
00021
00022
00023 typedef enum ElementType {
00024 ELEMENT_PAGE,
00025 ELEMENT_REGION,
00026 ELEMENT_LINE,
00027 ELEMENT_WORD,
00028 ELEMENT_GLYPH
00029 };
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 class Element : public Root {
00118 public:
00119
00120 typedef std::list<Element*> ElementList;
00121
00140 Element(Element* parent, const Coord& topleft, const Coord& size);
00141 virtual ~Element();
00142
00148 inline void markInvisible(bool invisible = true) { this->invisibleIs(invisible); }
00149
00168 virtual int type() const;
00169
00174 void registerElement(Element* part);
00175 Element* firstElement() const { return ( this->parts().empty() ) ? NULL : this->parts().front(); }
00176 Element* lastElement() const { return ( this->parts().empty() ) ? NULL : this->parts().back(); }
00177
00178 Coord size() const { return Coord( this->width(), this->height() ); }
00179
00188 void allGlyphs(std::vector<Glyph*>& glyphs);
00189 void allGlyphs(std::vector<const Glyph*>& glyphs) const;
00190
00206 Page* containingPage() const;
00207
00219 virtual const Image* pageImage() const;
00220
00225 virtual void writeText(std::ostream& os) const;
00226
00235 virtual Page* asPage() { return NULL; }
00236 virtual Region* asRegion() { return NULL; }
00237 virtual Line* asLine() { return NULL; }
00238 virtual Word* asWord() { return NULL; }
00239 virtual Glyph* asGlyph() { return NULL; }
00240
00241 virtual const Page* asPage() const { return NULL; }
00242 virtual const Region* asRegion() const { return NULL; }
00243 virtual const Line* asLine() const { return NULL; }
00244 virtual const Word* asWord() const { return NULL; }
00245 virtual const Glyph* asGlyph() const { return NULL; }
00246
00251 inline int height() const { return this->bottomright().y - this->topleft().y + 1; }
00252
00257 inline int width() const { return this->bottomright().x - this->topleft().x + 1; }
00258
00259
00260
00261
00262
00267 void printStructure(std::ostream& os = std::cerr, const std::string& indent = "") const;
00268
00273 virtual void printSummary(std::ostream& os = std::cerr, const std::string& indent = "", int index = -1) const;
00274
00279 void writeGlyphs(const std::string& dir, const ImageArgs& adj) const;
00280
00294 virtual std::string id() const;
00295
00304 int findIndex(const Element* image) const;
00305
00315 static void test(int argc = 0, const char* argv[] = NULL);
00316
00317 inline ElementList & partsRef() { return this->_parts; }
00318
00319
00320 inline const Coord & topleft() const { return this->_topleft; }
00321 inline const Coord & bottomright() const { return this->_bottomright; }
00322 inline const ElementList& parts() const { return this->_parts; }
00323 inline const Element* parent() const { return this->_parent; }
00324 inline bool invisible() const { return this->_invisible; }
00325
00326 protected:
00327
00328 inline void topleftIs(const Coord & topleft) { this->_topleft = topleft; }
00329 inline Coord & topleftRef() { return this->_topleft; }
00330 inline void bottomrightIs(const Coord & bottomright) { this->_bottomright = bottomright; }
00331 inline Coord & bottomrightRef() { return this->_bottomright; }
00332 inline void partsIs(const ElementList & parts) { this->_parts = parts; }
00333 inline void parentIs(Element* parent) { this->_parent = parent; }
00334 inline Element* & parentRef() { return this->_parent; }
00335 inline void invisibleIs(bool invisible) { this->_invisible = invisible; }
00336
00337
00338
00339
00340 static char* ClassName[6];
00341
00342 private:
00343
00344 inline bool& invisibleRef() { return this->_invisible; }
00345
00346
00347
00348
00349
00350
00357 Coord _topleft;
00358
00365 Coord _bottomright;
00366
00387 Element* _parent;
00388
00415 ElementList _parts;
00416
00431 bool _invisible;
00432 };
00433 };
00434
00435 # endif // Conjecture_Element_h
00436