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 }
XmlElement * createElement()
Creates a new element node.
Definition: BaseXML.cxx:43
void createChild(XmlElement &tag, const ViewBase &view)
Create the child element, i.e.
Definition: ViewBaseXML.cxx:54
XmlElement * createElement(const PlotterBase &plotter)
Returns a newly created XmlElement with attributes set for plotter.
double getHeight() const
A shortcut to get size.height.
Definition: Rectangle.cxx:113
virtual bool attribute(const std::string &name, bool &value) const =0
Sets value to the attribute name&#39;s value.
virtual void getObjects(const XmlElement *element)
Creates an object derived from ViewBase.
Definition: ViewBaseXML.cxx:82
XmlController class interface.
PlotterBaseXML class interface.
virtual Rect getDrawRect() const =0
Returns the drawing Rectangle in the devices coordinate system.
std::string m_y
Attribute name for the Y coordinate.
Definition: ViewBaseXML.h:38
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
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_x
Attribute name for the X coordinate.
Definition: ViewBaseXML.h:35
ViewBaseXML(const ViewBaseXML &)
A private copy constructor in order to avoid copying.
double getWidth() const
A shortcut to get size.width.
Definition: Rectangle.cxx:108
bool areDataSourcesSaved(const PlotterBase &plotter)
Returns true if all the NTuple objects used by the plotter are save to or read from a file...
void setId(XmlElement &tag, int id)
Sets the unique identification of the object.
Definition: BaseXML.cxx:64
The base class for the PlotterBase hierarchy.
Definition: PlotterBase.h:55
PlotterBase * getPlotter() const
Returns the plotter used by this view.
Definition: ViewBase.cxx:50
bool ok
Definition: CanvasView.cxx:163
virtual void appendChild(const XmlNode &child)=0
Appends a child element to the element.
bool areDataSourcesSaved(const ViewBase &view)
Returns true if all the NTuple objects used by the view have been save to or read from a file...
Definition: ViewBaseXML.cxx:47
virtual void setDrawRect(float x, float y, float w, float h)=0
Sets the drawing Rectangle in the devices coordinate system.
Class representing a rectangle.
Definition: Rectangle.h:34
std::string m_w
Attribute name for the width.
Definition: ViewBaseXML.h:41
XmlController * m_controller
The singleton XML controller object.
Definition: BaseXML.h:60
PlotterBaseXML * m_plotter_xml
The PlotterBaseXML instance used by this object.
Definition: ViewBaseXML.h:50
XmlElement class interface.
The abstract base class for views.
Definition: ViewBase.h:62
std::string m_h
Attribute name for the height.
Definition: ViewBaseXML.h:44
double getX() const
A shortcut to get origin.X.
Definition: Rectangle.h:154
virtual PlotterBase * getObject(const XmlElement *element)
Returns the PlotterBase object represented by the element.
A base class of XML element controllers.
Definition: BaseXML.h:35
A class that is does XML serialization and de-serialization of derived classes of PlotterBase...
~ViewBaseXML()
The destructor.
Definition: ViewBaseXML.cxx:42
void connectPlotters(const XmlElement *root)
Connects the plotters that reference each other.
A base class that is the interface between GUI and the XML serialization and deserialization.
Definition: XmlController.h:53
ViewBaseXML class interface.
hippodraw::ViewBase class interface
double getY() const
A shortcut to get origin.Y.
Definition: Rectangle.h:162
ViewBase * createView(PlotterBase *)
Creates a new view for the current PlotterBase object and adds it to the list of views.
hippodraw::PlotterBase class interface.
virtual void setAttribute(const std::string &name, bool value)=0
Sets attribute named name to the int value value.

Generated for HippoDraw Class Library by doxygen