Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ViewBaseXML.cxx

Go to the documentation of this file.
00001 
00012 // for truncation warning
00013 #ifdef _MSC_VER
00014 #include "msdevstudio/MSconfig.h"
00015 #endif
00016 
00017 #include "ViewBaseXML.h"
00018 
00019 #include "PlotterBaseXML.h"
00020 #include "XmlController.h"
00021 #include "XmlElement.h"
00022 
00023 #include "graphics/ViewBase.h"
00024 #include "plotters/PlotterBase.h"
00025 
00026 #include <list>
00027 
00028 using std::list;
00029 using std::string;
00030 
00031 ViewBaseXML::ViewBaseXML ( XmlController * controller )
00032   : BaseXML ( "ViewBase", controller ),
00033     m_x ( "x" ),
00034     m_y ( "y" ),
00035     m_w ( "w" ),
00036     m_h ( "h" )
00037 {
00038   m_plotter_xml = new PlotterBaseXML ( controller );
00039 }
00040 
00041 bool ViewBaseXML::areDataSourcesSaved ( const ViewBase & view )
00042 {
00043   const PlotterBase * plotter = view.getPlotter ();
00044 
00045   return m_plotter_xml->areDataSourcesSaved ( *plotter );
00046 }
00047 
00048 void ViewBaseXML::createChild ( XmlElement & tag, const ViewBase & view )
00049 {
00050   const PlotterBase * plotter = view.getPlotter ();
00051   XmlElement * element =  m_plotter_xml->createElement ( *plotter );
00052 
00053   tag.appendChild ( *element );
00054 }
00055 
00056 XmlElement * ViewBaseXML::createElement ( const ViewBase & view )
00057 {
00058   XmlElement * tag = BaseXML::createElement ();
00059 
00060   const void * addr = reinterpret_cast < const void * > ( & view );
00061   int id = m_controller -> getId ( addr );
00062   setId ( *tag, id );
00063 
00064   HippoRectangle rect = view.getDrawRect ();
00065   tag->setAttribute ( m_x, rect.getX() );
00066   tag->setAttribute ( m_y, rect.getY() );
00067   tag->setAttribute ( m_w, rect.getWidth() );
00068   tag->setAttribute ( m_h, rect.getHeight() );
00069 
00070   createChild ( *tag, view );
00071 
00072   return tag;
00073 }
00074 
00075 void ViewBaseXML::getObjects ( const XmlElement * view_element )
00076 {
00077   const XmlElement * element = m_plotter_xml->getNode ( view_element );
00078   PlotterBase * plotter = m_plotter_xml->getObject ( element );
00079   if ( plotter == 0 ) return;
00080 
00081   ViewBase * view = m_controller->createView ( plotter );
00082 
00083   float x;
00084   bool ok = view_element->attribute ( m_x, x );
00085 
00086   float y;
00087   ok &= view_element->attribute ( m_y, y );
00088 
00089   float w;
00090   ok &= view_element->attribute ( m_w, w );
00091 
00092   float h;
00093   ok &= view_element->attribute ( m_h, h );
00094 
00095   view->setDrawRect ( x, y, w, h );
00096 }
00097 
00098 void
00099 ViewBaseXML::
00100 connectPlotters ( const XmlElement * root )
00101 {
00102   list < XmlElement * > nodelist;
00103   m_plotter_xml -> fillNodeList ( root, nodelist );
00104 
00105   std::list < XmlElement * > ::const_iterator first = nodelist.begin ();
00106   while ( first != nodelist.end () ) {
00107     XmlElement * element = *first++;
00108     int ref;
00109     bool ok = element -> attribute ( "ref", ref );
00110     if ( ok ) {
00111       int id = element -> getID ();
00112       PlotterBase * source = m_controller -> getPlotter ( id );
00113       PlotterBase * target = m_controller -> getPlotter ( ref );
00114       source -> setParentPlotter ( target );
00115     }
00116   }
00117 }
00118 

Generated for HippoDraw-1.14.8.5 by doxygen 1.4.3