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