00001 00012 // for dll interface warning 00013 #ifdef _MSC_VER 00014 #include "msdevstudio/MSconfig.h" 00015 #endif 00016 00017 #include "BinToColorXML.h" 00018 00019 #include "XmlController.h" 00020 #include "XmlDocument.h" 00021 #include "XmlElement.h" 00022 00023 #include "colorreps/BinToColor.h" 00024 #include "colorreps/BinToColorFactory.h" 00025 00026 #include <cassert> 00027 00028 using std::list; 00029 using std::string; 00030 using std::vector; 00031 00032 namespace hippodraw { 00033 00034 BinToColorXML::BinToColorXML ( XmlController * controller ) 00035 : BaseXML ( "BinToColor", controller ), 00036 m_ctrlpt ( "CtrlPt" ), 00037 m_point ( "point" ) 00038 { 00039 } 00040 00041 XmlElement * BinToColorXML::createElement ( const BinToColor & btc ) 00042 { 00043 XmlElement * tag = BaseXML::createElement (); 00044 tag -> setAttribute ( m_type, btc.name () ); 00045 bool yes = btc.hasControlPoints (); 00046 if ( yes ) { 00047 const vector < double > & points = btc.getControlPoints (); 00048 unsigned int size = points.size (); 00049 for ( unsigned int i = 0; i < size; i++ ) { 00050 XmlElement * element 00051 = XmlController::m_xml_doc -> createElement ( m_ctrlpt ); 00052 element -> setAttribute ( m_point, points [ i ] ); 00053 tag -> appendChild ( *element ); 00054 delete element; 00055 } 00056 } 00057 00058 return tag; 00059 } 00060 00061 BinToColor * BinToColorXML::createObject ( const XmlElement * element ) 00062 { 00063 string type; 00064 bool ok = element -> attribute ( m_type, type ); 00065 assert ( ok ); 00066 BinToColor * btc = 0; 00067 BinToColorFactory * factory = BinToColorFactory::instance (); 00068 try { 00069 btc = factory -> create ( type ); 00070 } 00071 catch ( const FactoryException & ) { 00072 btc = factory -> create ( "Rainbow" ); // default 00073 } 00074 00075 ok = btc -> hasControlPoints (); 00076 if ( ok ) { 00077 vector < double > points; 00078 list < XmlElement * > nodelist; 00079 element -> fillNodeList ( m_ctrlpt, nodelist ); 00080 list < XmlElement * > :: const_iterator first = nodelist.begin(); 00081 while ( first != nodelist.end() ) { 00082 XmlElement * pt_element = *first++; 00083 double point; 00084 ok = pt_element -> attribute ( m_point, point ); 00085 points.push_back ( point ); 00086 } 00087 btc -> setControlPoints ( points ); 00088 } 00089 00090 return btc; 00091 } 00092 00093 } // namespace hippodraw 00094