PointRepXML.cxx

Go to the documentation of this file.
00001 
00012 // inconsistent dll linkage
00013 #ifdef _MSC_VER
00014 #include "msdevstudio/MSconfig.h"
00015 #endif
00016 
00017 #include "PointRepXML.h"
00018 #include "XmlController.h"
00019 
00020 #include "BinToColorXML.h"
00021 #include "ColorXML.h"
00022 #include "XmlElement.h"
00023 
00024 #include "colorreps/BinToColor.h"
00025 #include "colorreps/BinToColorFactory.h"
00026 #include "reps/RepBase.h"
00027 #include "reps/PointRepFactory.h"
00028 #include "reps/TextRepFactory.h"
00029 
00030 #include <cassert>
00031 
00032 using std::string;
00033 
00034 namespace hippodraw {
00035 
00036 PointRepXML::PointRepXML ( XmlController * controller )
00037   : BaseXML ( "PointRep", controller ),
00038     a_size ( "size" ),
00039     a_style ( "style" ),
00040     a_xerror ( "xerror" ),
00041     a_yerror ( "yerror" ),
00042     a_text ( "text" ),
00043     a_value_transform ( "value_transform" )
00044 {
00045   m_color_xml = new ColorXML ( controller );
00046   m_bintocolor_xml = new BinToColorXML ( controller );
00047 }
00048 
00049 PointRepXML::
00050 ~PointRepXML ()
00051 {
00052   delete m_color_xml;
00053   delete m_bintocolor_xml;
00054 }
00055 
00056 XmlElement * PointRepXML::createElement ( const RepBase & rep )
00057 {
00058   XmlElement * tag = BaseXML::createElement ();
00059 
00060   const Color & color = rep.getColor ();
00061   XmlElement * element = m_color_xml->createElement ( color );
00062   tag->appendChild ( *element );
00063   delete element;
00064 
00065   const BinToColor * btc = rep.getValueTransform ();
00066   if ( btc != 0 ) {
00067     element = m_bintocolor_xml -> createElement ( *btc );
00068     tag -> appendChild ( *element );
00069     delete element;
00070   }
00071 
00072   setAttributes ( *tag, rep );
00073 
00074   return tag;
00075 }
00076 
00077 void PointRepXML::setAttributes ( XmlElement & tag,
00078                                   const RepBase & rep )
00079 {
00080   const void * addr = reinterpret_cast < const void * > ( & rep );
00081   int id = m_controller -> getId ( addr );
00082   setId ( tag, id );
00083 
00084   tag.setAttribute ( m_type, rep.name() );
00085   tag.setAttribute ( a_size,  rep.size () );
00086   tag.setAttribute ( a_style, rep.getStyle () );
00087 
00088   string value =  rep.xError() ? "yes" : "no";
00089   tag.setAttribute ( a_xerror,  value );
00090   value = rep.yError() ? "yes" : "no";
00091   tag.setAttribute ( a_yerror,  value );
00092 
00093   tag.setAttribute ( a_text, rep.getText () );
00094 
00095 }
00096 
00097 RepBase * PointRepXML::createObject ( const XmlElement * element )
00098 {
00099   string type;
00100   bool ok = element->attribute ( m_type, type );
00101   assert ( ok );
00102 
00103   RepBase * rep = 0;
00104   PointRepFactory * factory = PointRepFactory::instance ();
00105   try { 
00106     rep = factory->create ( type );
00107   } catch ( const FactoryException & ) {
00108     TextRepFactory * factory = TextRepFactory::instance ();
00109       rep = factory->create ( type );
00110   }
00111 
00112   if ( rep == 0 ) return 0;
00113 
00114   const XmlElement * color_element = m_color_xml->getNode ( element );
00115   Color * color = m_color_xml->createObject ( color_element );
00116   rep->setColor ( *color );
00117 
00118   const XmlElement * btc_element = m_bintocolor_xml -> getNode ( element );
00119   if ( btc_element != 0 ) {
00120     BinToColor * btc = m_bintocolor_xml -> createObject ( btc_element );
00121     rep -> setValueTransform ( btc );
00122   }
00123 
00124   float size = 1.;
00125   ok = element->attribute ( a_size, size );
00126   rep->setSize ( size );
00127 
00128   unsigned int style = 0;
00129   ok = element -> attribute ( a_style, style );
00130   if ( ok ) rep -> setStyle ( style );
00131 
00132   string xerror = "no";
00133   ok = element->attribute ( a_xerror, xerror );
00134   if ( xerror ==  "yes" ) {
00135     rep->setErrorOn ( Axes::X, true );
00136   }
00137 
00138   string yerror = "no";
00139   ok = element->attribute ( a_yerror, yerror );
00140   if ( yerror == "yes" ) {
00141     rep->setErrorOn ( Axes::Y, true );
00142   }
00143 
00144   string text = "";
00145   ok = element->attribute ( a_text, text );
00146   if ( text != "" ) {
00147     rep->setText(text);
00148   }
00149 
00150 
00151   // The following for backward compatiblity
00152   string transform;
00153   ok = element -> attribute ( a_value_transform, transform );
00154   if ( ok ) {
00155     BinToColorFactory * factory = BinToColorFactory::instance ();
00156     BinToColor * btc = factory -> create ( transform );
00157     rep -> setValueTransform ( btc );
00158   }
00159 
00160   return rep;
00161 }
00162 
00163 } // namespace hippodraw
00164 

Generated for HippoDraw Class Library by doxygen