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 
std::string m_autorange
The auto ranging attribute name.
Definition: AxisModelXML.h:44
XmlElement * createElement()
Creates a new element node.
Definition: BaseXML.cxx:43
unsigned int i
AxisModelXML(const AxisModelXML &)
A private copy constructor in order to avoid copying.
std::list< XmlElement * > NodeList_t
The container type for element nodes.
Definition: BaseXML.h:47
double high() const
Returns the maximum of the range object.
Definition: Range.cxx:100
A class to maintain tick coordinates and string values.
Definition: AxisTick.h:29
bool isAutoRanging() const
Returns true if auto-ranging is enabled; otherwise, returns false.
virtual bool attribute(const std::string &name, bool &value) const =0
Sets value to the attribute name&#39;s value.
std::string m_log
The attribute name for axis model that is logarithmic.
Definition: AxisModelXML.h:56
std::string m_low
The low end of Range attribute name.
Definition: AxisModelXML.h:47
bool isAutoTicks() const
Returns true if position of the ticks should be automatically generated.
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_scale_factor
the scale factor attribute name.
Definition: AxisModelXML.h:53
return yes
Definition: CanvasView.cxx:883
void setRange(double low, double high, double pos)
Sets the Range to the low and high values.
AxisModelXML class interface.
void createChildren(XmlElement &, const AxisModelBase &)
Creates the children elements.
void setAutoRanging(bool flag)
Sets the auto-ranging flag to flag.
bool ok
Definition: CanvasView.cxx:163
virtual void appendChild(const XmlNode &child)=0
Appends a child element to the element.
intp size(numeric::array arr)
Definition: num_util.cpp:296
The AxisModelBase class maintains the Range and scaling of an axis.
Definition: AxisModelBase.h:33
AxisTickXML * m_axistick_xml
The AxisTick XML handler.
Definition: AxisModelXML.h:41
double getScaleFactor() const
Returns the scale factor.
std::string m_high
The high end of Range attribute name.
Definition: AxisModelXML.h:50
virtual bool isLog() const =0
Returns a boolean describing the type of the scale of the axis.
XmlElement class interface.
const std::vector< AxisTick > & getTicks() const
Returns a reference of generated ticks.
void setScaleFactor(double)
Sets the value of the scale factor.
~AxisModelXML()
The destructor.
hippodraw::AxisModelBase class interface
std::string m_auto_tick
The attribute name for axis model that wants auto tick generation.
Definition: AxisModelXML.h:61
const Range & getRange(bool scaled) const
Returns the range represented by this AxisModel.
A base class of XML element controllers.
Definition: BaseXML.h:35
double low() const
Returns the minimum of the range object.
Definition: Range.cxx:87
Expresses a range of values.
Definition: Range.h:33
A class that is does XML serialization and de-serialization of AxisTick with XML. ...
Definition: AxisTickXML.h:28
bool isLog(const XmlElement *element)
Returns true if the element represents an axis model that is on a logarithmic scale.
Type convert(const std::string &axis)
Converts from string representation ot Axes::Type representation.
Definition: AxesType.cxx:32
A base class that is the interface between GUI and the XML serialization and deserialization.
Definition: XmlController.h:53
void setAttributes(XmlElement &tag, const AxisModelBase &plotter)
Sets the attributes of the XmlElement tag from information in the AxisModel object plotter...
Type
Axes constants.
Definition: AxesType.h:31
AxisTickXML class interface.
hippodraw::Axes::Type getAxis(const XmlElement *element, const std::string &tagname)
Returns the Axis attribute value.
virtual void setAttribute(const std::string &name, bool value)=0
Sets attribute named name to the int value value.
AxisTick class interface.

Generated for HippoDraw Class Library by doxygen