BinToColorXML.cxx
Go to the documentation of this file.
1 
12 // for dll interface warning
13 #ifdef _MSC_VER
14 #include "msdevstudio/MSconfig.h"
15 #endif
16 
17 #include "BinToColorXML.h"
18 
19 #include "XmlController.h"
20 #include "XmlDocument.h"
21 #include "XmlElement.h"
22 
23 #include "colorreps/BinToColor.h"
25 
26 #include <cassert>
27 
28 using std::list;
29 using std::string;
30 using std::vector;
31 
32 namespace hippodraw {
33 
35  : BaseXML ( "BinToColor", controller ),
36  m_ctrlpt ( "CtrlPt" ),
37  m_point ( "point" )
38 {
39 }
40 
42 {
44  tag -> setAttribute ( m_type, btc.name () );
45  bool yes = btc.hasControlPoints ();
46  if ( yes ) {
47  const vector < double > & points = btc.getControlPoints ();
48  unsigned int size = points.size ();
49  for ( unsigned int i = 0; i < size; i++ ) {
50  XmlElement * element
52  element -> setAttribute ( m_point, points [ i ] );
53  tag -> appendChild ( *element );
54  delete element;
55  }
56  }
57 
58  return tag;
59 }
60 
62 {
63  string type;
64  bool ok = element -> attribute ( m_type, type );
65  assert ( ok );
66  BinToColor * btc = 0;
68  try {
69  btc = factory -> create ( type );
70  }
71  catch ( const FactoryException & ) {
72  btc = factory -> create ( "Rainbow" ); // default
73  }
74 
75  ok = btc -> hasControlPoints ();
76  if ( ok ) {
77  vector < double > points;
78  list < XmlElement * > nodelist;
79  element -> fillNodeList ( m_ctrlpt, nodelist );
80  list < XmlElement * > :: const_iterator first = nodelist.begin();
81  while ( first != nodelist.end() ) {
82  XmlElement * pt_element = *first++;
83  double point;
84  ok = pt_element -> attribute ( m_point, point );
85  points.push_back ( point );
86  }
87  btc -> setControlPoints ( points );
88  }
89 
90  return btc;
91 }
92 
93 } // namespace hippodraw
94 
XmlElement * createElement()
Creates a new element node.
Definition: BaseXML.cxx:43
unsigned int i
std::string m_point
The attribute name of a control point.
Definition: BinToColorXML.h:40
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.
const std::vector< double > & getControlPoints() const
Returns a list of control points.
Definition: BinToColor.cxx:71
XmlDocument class interface.
XmlController class interface.
A pure virtual base class of XML element wrapper.
Definition: XmlElement.h:30
void fillNodeList(const XmlElement *element, std::list< XmlElement * > &nodelist)
Fills the nodelist with immediate child nodes of element with nodes that can be handled by this objec...
Definition: BaseXML.cxx:58
std::string m_ctrlpt
The element name for control points.
Definition: BinToColorXML.h:36
return yes
Definition: CanvasView.cxx:883
virtual bool hasControlPoints() const
Returns true if class has control points by which the value to color transform can be varied...
Definition: BinToColor.cxx:64
bool ok
Definition: CanvasView.cxx:163
PyArray_TYPES type(numeric::array arr)
Definition: num_util.cpp:249
hippodraw::BinToColor class interface
intp size(numeric::array arr)
Definition: num_util.cpp:296
XmlElement class interface.
static XmlDocument * m_xml_doc
The current document being generated or read.
const std::string m_type
The attribute name for the type of object.
Definition: BaseXML.h:54
A factory for creation of objects whose class is derived from BinToColor.
A base class of XML element controllers.
Definition: BaseXML.h:35
BinToColor * createObject(const XmlElement *element)
Sets the attributes of the object from the element values.
An exception class that is thrown when the factory fails to find the request class by its name...
BinToColorXML(const BinToColorXML &)
A private copy constructor in order to avoid copying.
A base class that is the interface between GUI and the XML serialization and deserialization.
Definition: XmlController.h:53
const std::string & name() const
Returns the name of the value to color transform.
Definition: BinToColor.cxx:42
BinToColorFactory class interface.

Generated for HippoDraw Class Library by doxygen