AxisModelXML.cxx
Go to the documentation of this file.
1 
12 // for iterator member defect
13 #ifdef _MSC_VER
14 #include "msdevstudio/MSconfig.h"
15 #endif
16 
17 #include "AxisModelXML.h"
18 
19 #include "AxisTickXML.h"
20 #include "XmlElement.h"
21 
22 #include "axes//AxisModelBase.h"
23 #include "axes//AxisTick.h"
24 
25 #include <cassert>
26 
27 using std::string;
28 using std::vector;
29 
30 namespace hippodraw {
31 
33  : BaseXML ( "AxisModel", controller ),
34  m_autorange ( "autorange" ),
35  m_low ( "low" ),
36  m_high ( "high" ),
37  m_scale_factor ( "scale_factor" ),
38  m_log ( "log" ),
39  m_auto_tick ( "autotick" )
40 {
41  m_axistick_xml = new AxisTickXML ( controller );
42 }
43 
46 {
47  delete m_axistick_xml;
48 }
49 
51  const AxisModelBase & model )
52 {
53  bool yes = model.isAutoRanging ();
54  if ( yes ) {
55  tag.setAttribute ( m_autorange, 1 );
56  }
57  else {
58  tag.setAttribute ( m_autorange, 0 );
59  }
60  const Range & range = model.getRange ( false );
61  tag.setAttribute ( m_low, range.low() );
62  tag.setAttribute ( m_high, range.high() );
63 
64  tag.setAttribute ( m_scale_factor, model.getScaleFactor () );
65 
66  if ( model.isLog () == true ) {
67  tag.setAttribute ( m_log, 1 );
68  }
69 
70  yes = model.isAutoTicks ();
71  if ( yes ) {
72  tag.setAttribute ( m_auto_tick, 1 );
73  }
74  else {
75  tag.setAttribute ( m_auto_tick, 0 );
76  createChildren ( tag, model );
77  }
78 }
79 
80 void
82 createChildren ( XmlElement & tag, const AxisModelBase & model )
83 {
84  const vector < AxisTick > & ticks = model.getTicks ();
85  unsigned int size = ticks.size ();
86  for ( unsigned int i = 0; i < size; i++ ) {
87  const AxisTick & tick = ticks [ i ];
88  XmlElement * element = m_axistick_xml -> createElement ();
89  m_axistick_xml -> setAttributes ( *element, tick );
90  tag.appendChild ( *element );
91  delete element;
92  }
93 }
94 
97 getAxis ( const XmlElement * element,
98  const std::string & tagname )
99 {
100  string value;
101  bool ok = element->attribute ( tagname, value );
102  assert ( ok );
103 
104  return Axes::convert ( value );
105 }
106 
107 bool AxisModelXML::isLog ( const XmlElement * element )
108 {
109  int value;
110  bool ok = element->attribute ( m_log, value );
111  if ( ok && value != 0 ) return true;
112 
113  return false;
114 }
115 
117  const XmlElement * element )
118 
119 {
120  int value;
121  bool ok = element->attribute ( m_autorange, value );
122  if ( ok && ( value == 0 ) ) model->setAutoRanging ( false );
123 
124  double low = 0.0;
125  ok = element->attribute ( m_low, low );
126  double high = 0.0;
127  ok = element->attribute ( m_high, high );
128 
129  Range range ( low, high );
130 
131  model->setRange ( range, false );
132 
133  double scale_factor;
134  ok = element->attribute ( m_scale_factor, scale_factor );
135  if ( ok ) model->setScaleFactor ( scale_factor );
136 
137  ok = element -> attribute ( m_auto_tick, value );
138  if ( ok ) {
139  bool yes = value != 0;
140  model -> setAutoTicks ( yes );
141  if ( ! yes ) {
142  createChildren ( element, model );
143  }
144  }
145 }
146 
147 void
149 createChildren ( const XmlElement * element, AxisModelBase * model )
150 {
151  vector < AxisTick > ticks;
152  AxisTick tick;
153 
154  NodeList_t nodelist;
155  m_axistick_xml -> fillNodeList ( element, nodelist );
156  if ( nodelist.empty () == false ) {
157  NodeList_t :: const_iterator first = nodelist.begin ();
158  while ( first != nodelist.end() ) {
159  XmlElement * element = *first++;
160  m_axistick_xml -> setAttributes ( & tick, element );
161  ticks.push_back ( tick );
162  }
163  model -> setTicks ( ticks );
164  }
165 }
166 
167 } // namespace hippodraw
168 

Generated for HippoDraw Class Library by doxygen