00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _OPENMBV_OBJECT_H_
00021 #define _OPENMBV_OBJECT_H_
00022
00023 #include <fmatvec/atom.h>
00024 #include <string>
00025 #include <H5Cpp.h>
00026 #include <sstream>
00027 #include <openmbvcppinterface/objectfactory.h>
00028 #include <mbxmlutilshelper/dom.h>
00029 #include <xercesc/dom/DOMElement.hpp>
00030 #include <xercesc/dom/DOMNode.hpp>
00031 #include <xercesc/dom/DOMDocument.hpp>
00032 #include <vector>
00033
00034 namespace XERCES_CPP_NAMESPACE {
00035 class DOMNode;
00036 class DOMElement;
00037 }
00038
00039 namespace OpenMBV {
00040
00041 #ifndef SWIG // SWIG can not parse this (swig bug?). However it is not needed for the swig interface -> removed for swig
00042 const MBXMLUtils::NamespaceURI OPENMBV("http://openmbv.berlios.de/OpenMBV");
00043 const MBXMLUtils::NamespaceURI MBXMLUTILSPARAM("http://openmbv.berlios.de/MBXMLUtils/parameter");
00044 #endif
00045
00046 class Group;
00047
00049 class Object : public fmatvec::Atom {
00050 friend class Group;
00051 protected:
00052 std::string name;
00053 std::string enableStr, boundingBoxStr;
00054 std::string ID;
00055 bool selected;
00056 Group* parent;
00057
00058 virtual void createHDF5File()=0;
00059 virtual void openHDF5File()=0;
00060 H5::Group *hdf5Group;
00061 virtual void terminate()=0;
00062
00064 virtual ~Object();
00065 public:
00067 Object();
00068
00071 virtual void destroy() const;
00072
00074 virtual std::string getClassName()=0;
00075
00077 void setEnable(bool enable) { enableStr=(enable==true)?"true":"false"; }
00078
00079 bool getEnable() { return enableStr=="true"?true:false; }
00080
00082 void setBoundingBox(bool bbox) { boundingBoxStr=(bbox==true)?"true":"false"; }
00083
00084 bool getBoundingBox() { return boundingBoxStr=="true"?true:false; }
00085
00087 void setName(const std::string& name_) { name=name_; }
00088
00089 std::string getName() { return name; }
00090
00092 virtual std::string getFullName(bool includingFileName=false, bool stopAtSeparateFile=false);
00093
00095 virtual void initializeUsingXML(xercesc::DOMElement *element);
00096
00097 virtual xercesc::DOMElement *writeXMLFile(xercesc::DOMNode *parent);
00098
00100 Group* getSeparateGroup();
00101
00103 Group* getTopLevelGroup();
00104
00105 Group* getParent() { return parent; }
00106
00108 std::string getID() const { return ID; }
00110 void setID(std::string ID_) { ID=ID_; }
00111
00113 bool getSelected() const { return selected; }
00115 void setSelected(bool selected_) { selected=selected_; }
00116
00117
00118 static double getDouble(xercesc::DOMElement *e);
00119 static std::vector<double> getVec(xercesc::DOMElement *e, unsigned int rows=0);
00120 static std::vector<std::vector<double> > getMat(xercesc::DOMElement *e, unsigned int rows=0, unsigned int cols=0);
00121
00122 static std::string numtostr(int i) { std::ostringstream oss; oss << i; return oss.str(); }
00123 static std::string numtostr(double d) { std::ostringstream oss; oss << d; return oss.str(); }
00124
00125
00126 template<class T>
00127 static void addElementText(xercesc::DOMElement *parent, const MBXMLUtils::FQN &name, const T &value) {
00128 std::ostringstream oss;
00129 oss<<value;
00130 xercesc::DOMElement *ele = MBXMLUtils::D(parent->getOwnerDocument())->createElement(name);
00131 ele->insertBefore(parent->getOwnerDocument()->createTextNode(MBXMLUtils::X()%oss.str()), NULL);
00132 parent->insertBefore(ele, NULL);
00133 }
00134 static void addElementText(xercesc::DOMElement *parent, const MBXMLUtils::FQN &name, double value, double def);
00135 static void addElementText(xercesc::DOMElement *parent, const MBXMLUtils::FQN &name, const std::vector<double> &value);
00136 static void addElementText(xercesc::DOMElement *parent, const MBXMLUtils::FQN &name, const std::vector<std::vector<double> > &value);
00137
00138 template <class T>
00139 static void addAttribute(xercesc::DOMNode *node, std::string name, T value) {
00140 xercesc::DOMElement *ele = dynamic_cast<xercesc::DOMElement*>(node);
00141 if(ele) {
00142 std::ostringstream oss;
00143 oss<<value;
00144 MBXMLUtils::E(ele)->setAttribute(name, oss.str());
00145 }
00146 }
00147
00148 template <class T>
00149 static void addAttribute(xercesc::DOMNode *node, std::string name, T value, std::string def) {
00150 if(value!=def) addAttribute(node, name, value);
00151 }
00152
00153 protected:
00154 static std::vector<double> toVector(std::string str);
00155 static std::vector<std::vector<double> > toMatrix(std::string str);
00156 };
00157
00158 }
00159
00160 #endif