00001
00012
00013 #ifdef _MSC_VER
00014 #include "msdevstudio/MSconfig.h"
00015 #endif
00016
00017 #include "TupleCutXML.h"
00018
00019 #include "XmlController.h"
00020 #include "XmlDocument.h"
00021 #include "XmlElement.h"
00022
00023 #include "datasrcs//TupleCut.h"
00024
00025 #include <cassert>
00026
00027 using namespace hippodraw;
00028
00029 TupleCutXML::TupleCutXML ( XmlController * controller )
00030 : BaseXML ( "TupleCut", controller ),
00031 m_low ( "low" ),
00032 m_high ( "high" ),
00033 m_invert ( "invert" ),
00034 m_column ( "column" ),
00035 m_dim ( "dimension" ),
00036 m_axis ( "axis" )
00037 {
00038 }
00039
00040 XmlElement *
00041 TupleCutXML::
00042 createElement ( unsigned int i, const TupleCut & cut )
00043 {
00044 XmlElement * tag = BaseXML::createElement ();
00045
00046 const void * addr = reinterpret_cast < const void * > ( & cut );
00047 int id = m_controller -> getId ( addr );
00048 setId ( *tag, id );
00049
00050 tag -> setAttribute ( m_dim, -1 );
00051 XmlElement * element
00052 = XmlController::m_xml_doc -> createElement ( "TupleCutAxis" );
00053 element -> setAttribute ( m_axis, i );
00054
00055 int tmp = cut.getInversion () ? 1 : 0;
00056 element -> setAttribute ( m_invert, tmp );
00057
00058 const Range & range = cut.getRange ();
00059 element -> setAttribute ( m_low, range.low() );
00060 element -> setAttribute ( m_high, range.high() );
00061
00062 int col = cut.getColumn ( );
00063 element -> setAttribute ( m_column, col );
00064
00065 tag -> appendChild ( *element );
00066 delete element;
00067
00068 return tag;
00069 }
00070
00071 TupleCut * TupleCutXML::getObject ( const XmlElement & tag ) const
00072 {
00073 TupleCut * cut = 0;
00074 setAttributes ( cut, &tag );
00075
00076 return cut;
00077 }
00078
00081 void
00082 TupleCutXML::
00083 setAxisAttributes ( TupleCut * cut,
00084 hippodraw::Axes::Type,
00085 const XmlElement * element ) const
00086 {
00087 int value;
00088 bool ok = element->attribute ( m_invert, value );
00089 if ( ok && ( value == 1 ) ) cut -> setInversion( true );
00090
00091 double low = 0.0;
00092 ok = element->attribute( m_low, low );
00093 double high = 0.0;
00094 ok = element->attribute( m_high, high );
00095
00096 Range range ( low, high );
00097
00098 cut->setRange( range );
00099
00100 int col = -2;
00101 ok = element->attribute ( m_column, col );
00102 cut->setColumn( col );
00103 }
00104
00105 bool
00106 TupleCutXML::
00107 hasMultiDimTupleCut ( const XmlElement * element ) const
00108 {
00109 bool yes = true;
00110 int dim;
00111 bool ok = element -> attribute ( m_dim, dim );
00112 if ( ok && dim < 0 ) yes = false;
00113
00114 return yes;
00115 }
00116
00117 void
00118 TupleCutXML::
00119 getObjects ( const XmlElement * element, std::vector <TupleCut * > & cuts )
00120 {
00121 int dim;
00122 bool ok = element -> attribute ( m_dim, dim );
00123 if ( ! ok ) {
00124 TupleCut * cut = new TupleCut ();
00125 setAxisAttributes ( cut, Axes::X, element );
00126 cuts.push_back ( cut );
00127 }
00128 else {
00129 XmlElement::NodeList_t nodelist;
00130 element -> fillNodeList ( "TupleCutAxis", nodelist );
00131 assert ( nodelist.empty () == false );
00132 XmlElement::NodeList_t::const_iterator first = nodelist.begin();
00133
00134 while ( first != nodelist.end() ) {
00135 XmlElement * node = *first++;
00136 int axis;
00137 bool ok = node -> attribute ( m_axis, axis );
00138 assert ( ok );
00139 Axes::Type axis_t = axis == 0 ? Axes::X : Axes::Y;
00140 TupleCut * cut = new TupleCut ();
00141 setAxisAttributes ( cut, axis_t, node );
00142 cuts.push_back ( cut );
00143 }
00144 }
00145 }
00146
00147 void TupleCutXML::setAttributes ( TupleCut * & cut,
00148 const XmlElement * element ) const
00149 {
00150 int dim;
00151 bool ok = element->attribute ( m_dim, dim );
00152
00153 if ( ! ok ) {
00154 cut = new TupleCut ();
00155 setAxisAttributes ( cut, Axes::X, element );
00156 }
00157 else {
00158 cut = new TupleCut ( );
00159 XmlElement::NodeList_t nodelist;
00160 element -> fillNodeList ( "TupleCutAxis", nodelist );
00161 assert ( nodelist.empty () == false );
00162 XmlElement::NodeList_t::const_iterator first = nodelist.begin();
00163
00164 while ( first != nodelist.end() ) {
00165 XmlElement * node = *first++;
00166 int axis;
00167 bool ok = node -> attribute ( m_axis, axis );
00168 assert ( ok );
00169 Axes::Type axis_t = axis == 0 ? Axes::X : Axes::Y;
00170 setAxisAttributes ( cut, axis_t, node );
00171 }
00172 }
00173 }