Main Page   Namespace List   Class Hierarchy   Compound List   File List   Header Files   Sources   Namespace Members   Compound Members   File Members  

MapDataDocument.h

00001 //$Header: /home/ben/Mapper/include/RCS/MapDataDocument.h,v 6.9 2002/07/09 22:50:56 ben Exp $
00002 #ifndef MAPDATADOCUMENT_H
00003 #define MAPDATADOCUMENT_H
00004 // Copyright Benedict Adamson 2002.
00005 // This file is part of Mapper.
00006 
00007 // Mapper is free software; you can redistribute it and/or modify
00008 // it under the terms of the GNU General Public License as published by
00009 // the Free Software Foundation; either version 2 of the License, or
00010 // (at your option) any later version.
00011 
00012 // Mapper is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 
00017 // You should have received a copy of the GNU General Public License
00018 // along with Mapper; if not, write to the Free Software
00019 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00030 #include <string>
00031 #include <map>
00032 #include <set>
00033 #include <vector>
00034 
00035 #include <dom/DOM_Document.hpp>
00036 #include <dom/DOM_Element.hpp>
00037 
00038 #include "error.h"
00039 #include "vector2.h"
00040 
00041 class ostream;
00042 
00043 class InputSource;
00044 class MapperErrorHandler;
00045 class constraint;
00046 class curve;
00047    
00048 
00055 class order_vector2 {
00056    public:
00057       
00058       bool operator() (
00059          const vector2 &a,
00060          const vector2 &b
00061          ) const
00062       {
00063          if( a.x == b.x ){
00064             return a.y < b.y;
00065          }else{
00066             return a.x < b.x;
00067          };
00068       }
00069 };
00070 
00071 
00072 
00080 class MapDataDocument
00081 {
00082    public: //constructors and destructor
00083       
00100       MapDataDocument(void);
00101 
00102       virtual ~MapDataDocument(void);
00103 
00104    public: //attributes
00105 
00114       inline const vector2 &origin(void) const
00115       {
00116          return this->origin_;
00117       };
00118 
00127       inline double height(void) const
00128       {
00129          return this->height_;
00130       };
00131 
00140       inline double width(void) const
00141       {
00142          return this->width_;
00143       };
00144 
00145 
00146    public: //associations
00147 
00166       inline const map< string, vector2 * > &named_points(void) const
00167       {
00168          return this->named_points_;
00169       };
00170       
00187       inline const vector< vector2 * > &anon_points(void) const
00188       {
00189          return this->anon_points_;
00190       };
00191 
00209       inline const map< string, curve * > &curves(void) const
00210       {
00211          return this->curves_;
00212       };
00213 
00229       inline const set< vector2 * > &fixed_points(void) const
00230       {
00231          return this->fixed_points_;
00232       };
00233 
00254       inline const vector< constraint * > &constraints(void) const
00255       {
00256         return this->constraints_;
00257       };
00258 
00265       set< vector2 * > all_points(void) const;
00266 
00270       unsigned precision;
00271 
00272 
00273    public: //messages
00274    
00275       
00434       void read(
00435          InputSource &source,
00436          MapperErrorHandler &err_handler
00437          );
00438 
00439 
00464       void write(
00465          ostream &out,
00466          const double tol
00467          );
00468 
00469    private: //Helper functions
00470       
00485       static void get_attribute(
00486          string &x, //output
00487          const DOM_Element &elem,
00488          const char *attr
00489          )
00490          throw(
00491             error::attribute_error
00492             );
00493       
00494 
00495       
00512       static void get_attribute(
00513          double &x, //output
00514          const DOM_Element &elem,
00515          const char *attr
00516          )
00517          throw(
00518             error::attribute_error
00519             );
00520       
00521 
00522 
00540       static void get_attribute(
00541          unsigned &x, //output
00542          const DOM_Element &elem,
00543          const char *attr
00544          )
00545          throw(
00546             error::attribute_error
00547             );
00548       
00549 
00550 
00570       void get_attribute(
00571          vector2 *&p, //output
00572          const DOM_Element &elem,
00573          const char *attr
00574          ) const
00575          throw(
00576             error::attribute_error
00577             );
00578       
00579       
00580 
00600       void get_attribute(
00601          curve *&c, //output
00602          const DOM_Element &elem,
00603          const char *attr
00604          ) const
00605          throw(
00606             error::attribute_error
00607             );
00608 
00609 
00610 
00624       static bool has_attribute(
00625          const DOM_Element &node,
00626          const char *attr
00627          );
00628 
00629 
00630 
00640       inline static bool has_attribute(
00641          const DOM_Element &node,
00642          const string &attr
00643          )
00644       {
00645          return has_attribute( node, attr.c_str() );
00646       };
00647 
00648 
00649 
00663       inline static void require_attribute(
00664          const DOM_Element &elem,
00665          const char *attr
00666          )
00667          throw(
00668             error::attribute_error //if attribute absent
00669             )
00670       {
00671          if( !has_attribute( elem, attr ) )
00672             throw error::attribute_error( elem, "absent", attr );
00673          ;
00674       };
00675 
00676 
00677 
00678       void read_Tracing(
00679          DOM_Element &elem,
00680          MapperErrorHandler &err_handler
00681          )
00682          throw(
00683             error::attribute_error
00684             );
00685       
00686       void convert_Angle(
00687          DOM_Element &elem,
00688          const double default_uncertainty
00689          )
00690          throw(
00691             error::attribute_error
00692             );
00693 
00694       void convert_Bearing(
00695          DOM_Element &elem, //input
00696          const double default_uncertainty
00697          )
00698          throw(
00699             error::attribute_error
00700             );
00701 
00702       void convert_Distance(
00703          DOM_Element &elem, //input
00704          const double default_uncertainty_0,
00705          const double default_uncertainty_1
00706          )
00707          throw(
00708             error::attribute_error
00709             );
00710 
00711       void convert_Through(
00712          DOM_Element &elem,
00713          const double default_uncertainty
00714          )
00715          throw(
00716             error::attribute_error
00717             );
00718 
00719       void convert_Vector(
00720          DOM_Element &elem, //input
00721          const double default_uncertainty_0,
00722          const double default_uncertainty_1
00723          )
00724          throw(
00725             error::attribute_error
00726             );
00727 
00728       void convert_Constraint_group(
00729          DOM_Element &elem, //input
00730          MapperErrorHandler &err_handler
00731          )
00732          throw(
00733             error::attribute_error
00734             );
00735 
00736       void convert_Curve(
00737          DOM_Element &elem, //input
00738          MapperErrorHandler &err_handler
00739          )
00740          throw(
00741             error::attribute_error
00742             );
00743 
00744       void convert_Fixed_point(
00745          DOM_Element &elem //input
00746          )
00747          throw(
00748             error::attribute_error
00749             );
00750 
00751       void convert_Point(
00752          DOM_Element &elem //input
00753          )
00754          throw(
00755             error::attribute_error
00756             );
00757 
00758       void convert_Point_alias(
00759          DOM_Element &elem //input
00760          )
00761          throw(
00762             error::attribute_error
00763             );
00764 
00765       void convert_pointrefs(
00766          DOM_Element &elem, //input
00767          const char *tag,
00768          MapperErrorHandler &err_handler
00769          );
00770 
00771       void convert_Curve_segments(
00772          DOM_Element &elem, //input
00773          MapperErrorHandler &err_handler
00774          );
00775 
00776       void convert(
00777          MapperErrorHandler &err_handler //input
00778          );
00779 
00780       vector2 random_position(void) const;
00781 
00782       void convert_Traced_point(
00783          map< vector2, vector2 *, order_vector2 > &traced_points, //input, output
00784          map< vector2, double, order_vector2 > &point_uncertainties, //input, output
00785          DOM_Element &elem, //input
00786          const double tracing_width,
00787          const double tracing_height,
00788          const double default_uncertainty
00789          )
00790          throw(
00791             error::element_error
00792             );
00793 
00794       void add_angle_constraint(
00795          const vector2 &vf, //local coordinates
00796          const vector2 &va,
00797          const vector2 &vt,
00798          vector2 *pf, //points, input
00799          vector2 *pa,
00800          vector2 *pt,
00801          const double uf, //uncertainties
00802          const double ua,
00803          const double ut
00804          );
00805 
00806       void convert_Tracing(
00807          DOM_Element &elem,
00808          MapperErrorHandler &err_handler
00809          )
00810          throw(
00811             error::attribute_error
00812             );
00813 
00814       static void set_attribute(
00815          DOM_Element &elem, //input, output
00816          const string &attr,
00817          const double x,
00818          const unsigned precision
00819          );
00820 
00821       void update_points(
00822          const DOM_NodeList &nodes, //input, output
00823          unsigned &n_points, //input, output
00824          double &left, //input, output
00825          double &right, //input, output
00826          double & top, //input, output
00827          double &bottom //input, output
00828          );
00829 
00830       void update_constraints(
00831          const double tol,
00832          const DOM_NodeList &nodes //input, output
00833          );
00834 
00835       void update_child_Coord(
00836          DOM_Document &doc, //input
00837          DOM_Element &elem, //input
00838          DOM_Node &child, //input, output
00839          const vector2 &p
00840          );
00841 
00842       void update_curve_segments(
00843          const DOM_NodeList &nodes //input
00844          );
00845 
00846       void update(
00847          const double tol
00848          );
00849       
00850    private: //state
00851       map< string, vector2 * > named_points_;
00852       vector< vector2 * > anon_points_;
00853       map< string, curve * > curves_;
00854       set< vector2 * > fixed_points_;
00855       vector< constraint * > constraints_;
00856       DOM_Document doc;
00857       vector2 origin_;
00858       double height_;
00859       double width_;
00860       
00861 };
00862 
00863 #endif

Generated at Sun Jul 14 20:38:08 2002 for Mapper by doxygen 1.0.0 written by Dimitri van Heesch, © 1997-1999