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 
XmlElement * createElement()
Creates a new element node.
Definition: BaseXML.cxx:43
Type * create(const std::string &name)
Creates a new object from a prototype named name.
Definition: Factory.h:160
A singleton class that is does XML serialization and deserialization of derived classes of Color with...
Definition: ColorXML.h:28
hippodraw::TextRepFactory class interface
virtual bool attribute(const std::string &name, bool &value) const =0
Sets value to the attribute name&#39;s value.
XmlElement * createElement(const Color &color)
Create a Color XML element.
Definition: ColorXML.cxx:34
BinToColorXML class interface.
The base class for the value to the color transformation.
Definition: BinToColor.h:30
static BinToColorFactory * instance()
Returns a pointer to the singleton instance.
PointRepXML class interface.
PointRepFactory class interface.
XmlController class interface.
static PointRepFactory * instance()
Returns a pointer to the singleton instance.
BinToColorXML * m_bintocolor_xml
The BinToColorXML instance used by this object.
Definition: PointRepXML.h:40
const XmlElement * getNode(const XmlElement *element) const
Returns the single child node of element of the type that can be handled by this object.
Definition: BaseXML.cxx:53
A pure virtual base class of XML element wrapper.
Definition: XmlElement.h:30
ColorXML class interface.
RepBase * createObject(const XmlElement *element)
Creates an object derived from RepBase from information in the XmlElement.
Definition: PointRepXML.cxx:97
return rep
Definition: Inspector.cxx:3843
const std::string & getText() const
Gets the text.
Definition: RepBase.cxx:139
std::string a_xerror
The x error attribute name.
Definition: PointRepXML.h:52
A singleton class that is does XML serialization and deserialization of derived classes of BinToColor...
Definition: BinToColorXML.h:29
virtual bool yError() const
Returns true if the point representation displays error on the Y axis.
Definition: RepBase.cxx:122
A Color class for creating the color object following the standard RGB color space.
Definition: Color.h:37
void setId(XmlElement &tag, int id)
Sets the unique identification of the object.
Definition: BaseXML.cxx:64
std::string a_value_transform
The type of value transform.
Definition: PointRepXML.h:64
bool ok
Definition: CanvasView.cxx:163
PyArray_TYPES type(numeric::array arr)
Definition: num_util.cpp:249
static TextRepFactory * instance()
Returns a pointer to the singleton instance.
A factory for textual representations.
std::string a_style
The style attribute name.
Definition: PointRepXML.h:48
virtual void appendChild(const XmlNode &child)=0
Appends a child element to the element.
hippodraw::BinToColor class interface
intp size(numeric::array arr)
Definition: num_util.cpp:296
ColorXML * m_color_xml
The ColorXML instance used by this object.
Definition: PointRepXML.h:36
virtual void setSize(float value)
Sets the size of the representation.
Definition: RepBase.cxx:96
virtual void setColor(const Color &)
Sets the color of the representation.
Definition: RepBase.cxx:53
hippodraw::RepBase class interface
std::string a_text
The text attribute name.
Definition: PointRepXML.h:60
A factory for creation of objects whose class is derived from PointRepBase.
XmlController * m_controller
The singleton XML controller object.
Definition: BaseXML.h:60
XmlElement class interface.
std::string a_yerror
The y error attribute name.
Definition: PointRepXML.h:56
Color * createObject(const XmlElement *element)
Sets the attributes of the object from the element values.
Definition: ColorXML.cxx:45
virtual void setErrorOn(hippodraw::Axes::Type axis, bool yes=true)
Sets the error representation on specified axis, if any, to yes.
Definition: RepBase.cxx:129
PointRepXML(const PointRepXML &)
A private copy constructor in order to avoid copying.
virtual const BinToColor * getValueTransform() const
Returns the value transform.
Definition: RepBase.cxx:147
const std::string m_type
The attribute name for the type of object.
Definition: BaseXML.h:54
std::string a_size
The size attribute name.
Definition: PointRepXML.h:44
virtual unsigned int getStyle() const
Returns the style of the point representation.
Definition: RepBase.cxx:110
A factory for creation of objects whose class is derived from BinToColor.
A base class of XML element controllers.
Definition: BaseXML.h:35
const std::string & name() const
Returns the name of the representation.
Definition: RepBase.cxx:47
virtual const Color & getColor() const
Get the color of the representation.
Definition: RepBase.cxx:58
virtual bool xError() const
Returns true if the point representation displays error on the X axis.
Definition: RepBase.cxx:116
An exception class that is thrown when the factory fails to find the request class by its name...
A base class that is the interface between GUI and the XML serialization and deserialization.
Definition: XmlController.h:53
void setAttributes(XmlElement &tag, const RepBase &rep)
Sets the attributes of a PointRep element tag.
Definition: PointRepXML.cxx:77
~PointRepXML()
The destructor.
Definition: PointRepXML.cxx:50
void setText(const std::string &text)
Sets the text.
Definition: RepBase.cxx:133
float size() const
Returns the size of the representation.
Definition: RepBase.cxx:91
The base class for the point representation hierarchy.
Definition: RepBase.h:45
virtual void setAttribute(const std::string &name, bool value)=0
Sets attribute named name to the int value value.
BinToColorFactory class interface.

Generated for HippoDraw Class Library by doxygen