ViewBaseXML.cxx
Go to the documentation of this file.
1 
12 // for truncation warning
13 #ifdef _MSC_VER
14 #include "msdevstudio/MSconfig.h"
15 #endif
16 
17 #include "ViewBaseXML.h"
18 
19 #include "PlotterBaseXML.h"
20 #include "XmlController.h"
21 #include "XmlElement.h"
22 
23 #include "graphics/ViewBase.h"
24 #include "plotters/PlotterBase.h"
25 
26 using std::list;
27 using std::string;
28 
29 using namespace hippodraw;
30 
32  : BaseXML ( "ViewBase", controller ),
33  m_x ( "x" ),
34  m_y ( "y" ),
35  m_w ( "w" ),
36  m_h ( "h" )
37 {
38  m_plotter_xml = new PlotterBaseXML ( controller );
39 }
40 
43 {
44  delete m_plotter_xml;
45 }
46 
48 {
49  const PlotterBase * plotter = view.getPlotter ();
50 
51  return m_plotter_xml->areDataSourcesSaved ( *plotter );
52 }
53 
54 void ViewBaseXML::createChild ( XmlElement & tag, const ViewBase & view )
55 {
56  const PlotterBase * plotter = view.getPlotter ();
57  if ( plotter != 0 ) {
58  XmlElement * element = m_plotter_xml->createElement ( *plotter );
59  tag.appendChild ( *element );
60  }
61 }
62 
64 {
66 
67  const void * addr = reinterpret_cast < const void * > ( & view );
68  int id = m_controller -> getId ( addr );
69  setId ( *tag, id );
70 
71  Rect rect = view.getDrawRect ();
72  tag->setAttribute ( m_x, rect.getX() );
73  tag->setAttribute ( m_y, rect.getY() );
74  tag->setAttribute ( m_w, rect.getWidth() );
75  tag->setAttribute ( m_h, rect.getHeight() );
76 
77  createChild ( *tag, view );
78 
79  return tag;
80 }
81 
82 void ViewBaseXML::getObjects ( const XmlElement * view_element )
83 {
84  const XmlElement * element = m_plotter_xml->getNode ( view_element );
85  PlotterBase * plotter = m_plotter_xml->getObject ( element );
86 
87  if ( plotter != 0 ) {
88  ViewBase * view = m_controller->createView ( plotter );
89 
90  float x;
91  bool ok = view_element->attribute ( m_x, x );
92 
93  float y;
94  ok &= view_element->attribute ( m_y, y );
95 
96  float w;
97  ok &= view_element->attribute ( m_w, w );
98 
99  float h;
100  ok &= view_element->attribute ( m_h, h );
101 
102  view->setDrawRect ( x, y, w, h );
103  }
104 }
105 
106 void
108 connectPlotters ( const XmlElement * root )
109 {
110  list < XmlElement * > nodelist;
111  m_plotter_xml -> fillNodeList ( root, nodelist );
112 
113  std::list < XmlElement * > ::const_iterator first = nodelist.begin ();
114  while ( first != nodelist.end () ) {
115  XmlElement * element = *first++;
116  int ref;
117  bool ok = element -> attribute ( "ref", ref );
118  if ( ok ) {
119  int id = element -> getID ();
120  PlotterBase * source = m_controller -> getPlotter ( id );
121  PlotterBase * target = m_controller -> getPlotter ( ref );
122  source -> setParentPlotter ( target );
123  }
124  }
125 }

Generated for HippoDraw Class Library by doxygen