00001
00012
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 "reps/BinToColor.h"
00025 #include "reps/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 PointRepXML::PointRepXML ( XmlController * controller )
00035 : BaseXML ( "PointRep", controller ),
00036 a_size ( "size" ),
00037 a_style ( "style" ),
00038 a_xerror ( "xerror" ),
00039 a_yerror ( "yerror" ),
00040 a_value_transform ( "value_transform" )
00041 {
00042 m_color_xml = new ColorXML ( controller );
00043 m_bintocolor_xml = new BinToColorXML ( controller );
00044 }
00045
00046 XmlElement * PointRepXML::createElement ( const RepBase & rep )
00047 {
00048 XmlElement * tag = BaseXML::createElement ();
00049
00050 const Color & color = rep.getColor ();
00051 XmlElement * element = m_color_xml->createElement ( color );
00052 tag->appendChild ( *element );
00053
00054 const BinToColor * btc = rep.getValueTransform ();
00055 if ( btc != 0 ) {
00056 element = m_bintocolor_xml -> createElement ( *btc );
00057 tag -> appendChild ( *element );
00058 }
00059
00060 setAttributes ( *tag, rep );
00061
00062 return tag;
00063 }
00064
00065 void PointRepXML::setAttributes ( XmlElement & tag,
00066 const RepBase & rep )
00067 {
00068 const void * addr = reinterpret_cast < const void * > ( & rep );
00069 int id = m_controller -> getId ( addr );
00070 setId ( tag, id );
00071
00072 tag.setAttribute ( m_type, rep.name() );
00073 tag.setAttribute ( a_size, rep.size () );
00074 tag.setAttribute ( a_style, rep.getStyle () );
00075
00076 string value = rep.xError() ? "yes" : "no";
00077 tag.setAttribute ( a_xerror, value );
00078 value = rep.yError() ? "yes" : "no";
00079 tag.setAttribute ( a_yerror, value );
00080
00081 }
00082
00083 RepBase * PointRepXML::createObject ( const XmlElement * element )
00084 {
00085 string type;
00086 bool ok = element->attribute ( m_type, type );
00087 assert ( ok );
00088
00089 RepBase * rep = 0;
00090 PointRepFactory * factory = PointRepFactory::instance ();
00091 try {
00092 rep = factory->create ( type );
00093 } catch ( const FactoryException & ) {
00094 TextRepFactory * factory = TextRepFactory::instance ();
00095 rep = factory->create ( type );
00096 }
00097
00098 if ( rep == 0 ) return 0;
00099
00100 const XmlElement * color_element = m_color_xml->getNode ( element );
00101 Color * color = m_color_xml->createObject ( color_element );
00102 rep->setColor ( *color );
00103
00104 const XmlElement * btc_element = m_bintocolor_xml -> getNode ( element );
00105 if ( btc_element != 0 ) {
00106 BinToColor * btc = m_bintocolor_xml -> createObject ( btc_element );
00107 rep -> setValueTransform ( btc );
00108 }
00109
00110 float size = 1.;
00111 ok = element->attribute ( a_size, size );
00112 rep->setSize ( size );
00113
00114 unsigned int style = 0;
00115 ok = element -> attribute ( a_style, style );
00116 if ( ok ) rep -> setStyle ( style );
00117
00118 string xerror = "no";
00119 ok = element->attribute ( a_xerror, xerror );
00120 if ( xerror == "yes" ) {
00121 rep->setErrorOn ( "x", true );
00122 }
00123
00124 string yerror = "no";
00125 ok = element->attribute ( a_yerror, yerror );
00126 if ( yerror == "yes" ) {
00127 rep->setErrorOn ( "y", true );
00128 }
00129
00130
00131 string transform;
00132 ok = element -> attribute ( a_value_transform, transform );
00133 if ( ok ) {
00134 BinToColorFactory * factory = BinToColorFactory::instance ();
00135 BinToColor * btc = factory -> create ( transform );
00136 rep -> setValueTransform ( btc );
00137 }
00138
00139 return rep;
00140 }