00001
00012
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 using std::list;
00027 using std::string;
00028
00029 using namespace hippodraw;
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 ViewBaseXML::
00042 ~ViewBaseXML ()
00043 {
00044 delete m_plotter_xml;
00045 }
00046
00047 bool ViewBaseXML::areDataSourcesSaved ( const ViewBase & view )
00048 {
00049 const PlotterBase * plotter = view.getPlotter ();
00050
00051 return m_plotter_xml->areDataSourcesSaved ( *plotter );
00052 }
00053
00054 void ViewBaseXML::createChild ( XmlElement & tag, const ViewBase & view )
00055 {
00056 const PlotterBase * plotter = view.getPlotter ();
00057 if ( plotter != 0 ) {
00058 XmlElement * element = m_plotter_xml->createElement ( *plotter );
00059 tag.appendChild ( *element );
00060 }
00061 }
00062
00063 XmlElement * ViewBaseXML::createElement ( const ViewBase & view )
00064 {
00065 XmlElement * tag = BaseXML::createElement ();
00066
00067 const void * addr = reinterpret_cast < const void * > ( & view );
00068 int id = m_controller -> getId ( addr );
00069 setId ( *tag, id );
00070
00071 Rect rect = view.getDrawRect ();
00072 tag->setAttribute ( m_x, rect.getX() );
00073 tag->setAttribute ( m_y, rect.getY() );
00074 tag->setAttribute ( m_w, rect.getWidth() );
00075 tag->setAttribute ( m_h, rect.getHeight() );
00076
00077 createChild ( *tag, view );
00078
00079 return tag;
00080 }
00081
00082 void ViewBaseXML::getObjects ( const XmlElement * view_element )
00083 {
00084 const XmlElement * element = m_plotter_xml->getNode ( view_element );
00085 PlotterBase * plotter = m_plotter_xml->getObject ( element );
00086
00087 if ( plotter != 0 ) {
00088 ViewBase * view = m_controller->createView ( plotter );
00089
00090 float x;
00091 bool ok = view_element->attribute ( m_x, x );
00092
00093 float y;
00094 ok &= view_element->attribute ( m_y, y );
00095
00096 float w;
00097 ok &= view_element->attribute ( m_w, w );
00098
00099 float h;
00100 ok &= view_element->attribute ( m_h, h );
00101
00102 view->setDrawRect ( x, y, w, h );
00103 }
00104 }
00105
00106 void
00107 ViewBaseXML::
00108 connectPlotters ( const XmlElement * root )
00109 {
00110 list < XmlElement * > nodelist;
00111 m_plotter_xml -> fillNodeList ( root, nodelist );
00112
00113 std::list < XmlElement * > ::const_iterator first = nodelist.begin ();
00114 while ( first != nodelist.end () ) {
00115 XmlElement * element = *first++;
00116 int ref;
00117 bool ok = element -> attribute ( "ref", ref );
00118 if ( ok ) {
00119 int id = element -> getID ();
00120 PlotterBase * source = m_controller -> getPlotter ( id );
00121 PlotterBase * target = m_controller -> getPlotter ( ref );
00122 source -> setParentPlotter ( target );
00123 }
00124 }
00125 }