PointRepXML.cxx
Go to the documentation of this file.
1 
12 // inconsistent dll linkage
13 #ifdef _MSC_VER
14 #include "msdevstudio/MSconfig.h"
15 #endif
16 
17 #include "PointRepXML.h"
18 #include "XmlController.h"
19 
20 #include "BinToColorXML.h"
21 #include "ColorXML.h"
22 #include "XmlElement.h"
23 
24 #include "colorreps/BinToColor.h"
26 #include "reps/RepBase.h"
27 #include "reps/PointRepFactory.h"
28 #include "reps/TextRepFactory.h"
29 
30 #include <cassert>
31 
32 using std::string;
33 
34 namespace hippodraw {
35 
37  : BaseXML ( "PointRep", controller ),
38  a_size ( "size" ),
39  a_style ( "style" ),
40  a_xerror ( "xerror" ),
41  a_yerror ( "yerror" ),
42  a_text ( "text" ),
43  a_value_transform ( "value_transform" )
44 {
45  m_color_xml = new ColorXML ( controller );
46  m_bintocolor_xml = new BinToColorXML ( controller );
47 }
48 
51 {
52  delete m_color_xml;
53  delete m_bintocolor_xml;
54 }
55 
57 {
59 
60  const Color & color = rep.getColor ();
61  XmlElement * element = m_color_xml->createElement ( color );
62  tag->appendChild ( *element );
63  delete element;
64 
65  const BinToColor * btc = rep.getValueTransform ();
66  if ( btc != 0 ) {
67  element = m_bintocolor_xml -> createElement ( *btc );
68  tag -> appendChild ( *element );
69  delete element;
70  }
71 
72  setAttributes ( *tag, rep );
73 
74  return tag;
75 }
76 
78  const RepBase & rep )
79 {
80  const void * addr = reinterpret_cast < const void * > ( & rep );
81  int id = m_controller -> getId ( addr );
82  setId ( tag, id );
83 
84  tag.setAttribute ( m_type, rep.name() );
85  tag.setAttribute ( a_size, rep.size () );
86  tag.setAttribute ( a_style, rep.getStyle () );
87 
88  string value = rep.xError() ? "yes" : "no";
89  tag.setAttribute ( a_xerror, value );
90  value = rep.yError() ? "yes" : "no";
91  tag.setAttribute ( a_yerror, value );
92 
93  tag.setAttribute ( a_text, rep.getText () );
94 
95 }
96 
98 {
99  string type;
100  bool ok = element->attribute ( m_type, type );
101  assert ( ok );
102 
103  RepBase * rep = 0;
105  try {
106  rep = factory->create ( type );
107  } catch ( const FactoryException & ) {
109  rep = factory->create ( type );
110  }
111 
112  if ( rep == 0 ) return 0;
113 
114  const XmlElement * color_element = m_color_xml->getNode ( element );
115  Color * color = m_color_xml->createObject ( color_element );
116  rep->setColor ( *color );
117 
118  const XmlElement * btc_element = m_bintocolor_xml -> getNode ( element );
119  if ( btc_element != 0 ) {
120  BinToColor * btc = m_bintocolor_xml -> createObject ( btc_element );
121  rep -> setValueTransform ( btc );
122  }
123 
124  float size = 1.;
125  ok = element->attribute ( a_size, size );
126  rep->setSize ( size );
127 
128  unsigned int style = 0;
129  ok = element -> attribute ( a_style, style );
130  if ( ok ) rep -> setStyle ( style );
131 
132  string xerror = "no";
133  ok = element->attribute ( a_xerror, xerror );
134  if ( xerror == "yes" ) {
135  rep->setErrorOn ( Axes::X, true );
136  }
137 
138  string yerror = "no";
139  ok = element->attribute ( a_yerror, yerror );
140  if ( yerror == "yes" ) {
141  rep->setErrorOn ( Axes::Y, true );
142  }
143 
144  string text = "";
145  ok = element->attribute ( a_text, text );
146  if ( text != "" ) {
147  rep->setText(text);
148  }
149 
150 
151  // The following for backward compatiblity
152  string transform;
153  ok = element -> attribute ( a_value_transform, transform );
154  if ( ok ) {
156  BinToColor * btc = factory -> create ( transform );
157  rep -> setValueTransform ( btc );
158  }
159 
160  return rep;
161 }
162 
163 } // namespace hippodraw
164 

Generated for HippoDraw Class Library by doxygen