All Classes Namespaces Functions Variables Typedefs Enumerations Pages
object.h
1 /*
2  OpenMBV - Open Multi Body Viewer.
3  Copyright (C) 2009 Markus Friedrich
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 
20 #ifndef _OPENMBV_OBJECT_H_
21 #define _OPENMBV_OBJECT_H_
22 
23 #include <fmatvec/atom.h>
24 #include <string>
25 #include <sstream>
26 #include <openmbvcppinterface/objectfactory.h>
27 #include <hdf5serie/group.h>
28 #include <mbxmlutilshelper/dom.h>
29 #include <xercesc/dom/DOMElement.hpp>
30 #include <xercesc/dom/DOMNode.hpp>
31 #include <xercesc/dom/DOMDocument.hpp>
32 #include <vector>
33 
34 namespace XERCES_CPP_NAMESPACE {
35  class DOMNode;
36  class DOMElement;
37 }
38 
39 namespace OpenMBV {
40 
41 #ifndef SWIG // SWIG can not parse this (swig bug?). However it is not needed for the swig interface -> removed for swig
42  const MBXMLUtils::NamespaceURI OPENMBV("http://www.mbsim-env.de/OpenMBV");
43 #endif
44 
45  class Group;
46 
48  class Object : virtual public fmatvec::Atom {
49  friend class Group;
50  protected:
51  std::string name;
52  std::string enableStr, boundingBoxStr;
53  std::string ID; // Note: the ID is metadata and stored as a processing instruction in XML
54  bool selected; // Note: the selected flag is metadata and not stored in XML but used by OpenMBVGUI
55  boost::weak_ptr<Group> parent;
56 
57  virtual void createHDF5File()=0;
58  virtual void openHDF5File()=0;
59  H5::GroupBase *hdf5Group;
60  virtual void terminate()=0;
61 
62  Object();
63  virtual ~Object();
64  public:
65 
67  virtual std::string getClassName()=0;
68 
70  void setEnable(bool enable) { enableStr=(enable==true)?"true":"false"; }
71 
72  bool getEnable() { return enableStr=="true"?true:false; }
73 
75  void setBoundingBox(bool bbox) { boundingBoxStr=(bbox==true)?"true":"false"; }
76 
77  bool getBoundingBox() { return boundingBoxStr=="true"?true:false; }
78 
80  void setName(const std::string& name_) { name=name_; }
81 
82  std::string getName() { return name; }
83 
85  virtual std::string getFullName(bool includingFileName=false, bool stopAtSeparateFile=false);
86 
88  virtual void initializeUsingXML(xercesc::DOMElement *element);
89 
90  virtual xercesc::DOMElement *writeXMLFile(xercesc::DOMNode *parent);
91 
93  boost::shared_ptr<Group> getSeparateGroup();
94 
96  boost::shared_ptr<Group> getTopLevelGroup();
97 
98  boost::weak_ptr<Group> getParent() { return parent; }
99 
100  H5::GroupBase *getHDF5Group() { return hdf5Group; };
101 
103  std::string getID() const { return ID; }
105  void setID(std::string ID_) { ID=ID_; }
106 
108  bool getSelected() const { return selected; }
110  void setSelected(bool selected_) { selected=selected_; }
111 
112  // FROM NOW ONLY CONVENIENCE FUNCTIONS FOLLOW !!!
113  static double getDouble(xercesc::DOMElement *e);
114  static std::vector<double> getVec(xercesc::DOMElement *e, unsigned int rows=0);
115  static std::vector<std::vector<double> > getMat(xercesc::DOMElement *e, unsigned int rows=0, unsigned int cols=0);
116  static std::vector<int> getIntVec(xercesc::DOMElement *e, unsigned int rows=0);
117 
118  static std::string numtostr(int i) { std::ostringstream oss; oss << i; return oss.str(); }
119  static std::string numtostr(double d) { std::ostringstream oss; oss << d; return oss.str(); }
120 
121 
122  template<class T>
123  static void addElementText(xercesc::DOMElement *parent, const MBXMLUtils::FQN &name, const T &value) {
124  std::ostringstream oss;
125  oss<<value;
126  xercesc::DOMElement *ele = MBXMLUtils::D(parent->getOwnerDocument())->createElement(name);
127  ele->insertBefore(parent->getOwnerDocument()->createTextNode(MBXMLUtils::X()%oss.str()), NULL);
128  parent->insertBefore(ele, NULL);
129  }
130  static void addElementText(xercesc::DOMElement *parent, const MBXMLUtils::FQN &name, double value, double def);
131  static void addElementText(xercesc::DOMElement *parent, const MBXMLUtils::FQN &name, const std::vector<double> &value);
132  static void addElementText(xercesc::DOMElement *parent, const MBXMLUtils::FQN &name, const std::vector<std::vector<double> > &value);
133  static void addElementText(xercesc::DOMElement *parent, const MBXMLUtils::FQN &name, const std::vector<int> &value);
134 
135  template <class T>
136  static void addAttribute(xercesc::DOMNode *node, std::string name, T value) {
137  xercesc::DOMElement *ele = dynamic_cast<xercesc::DOMElement*>(node);
138  if(ele) {
139  std::ostringstream oss;
140  oss<<value;
141  MBXMLUtils::E(ele)->setAttribute(name, oss.str());
142  }
143  }
144 
145  template <class T>
146  static void addAttribute(xercesc::DOMNode *node, std::string name, T value, std::string def) {
147  if(value!=def) addAttribute(node, name, value);
148  }
149 
150  protected:
151  static std::vector<double> toVector(std::string str);
152  static std::vector<std::vector<double> > toMatrix(std::string str);
153  static std::vector<int> toIntVector(std::string str);
154  static std::vector<std::vector<int> > toIntMatrix(std::string str);
155  };
156 
157 }
158 
159 #endif
void setName(const std::string &name_)
Definition: object.h:80
void setBoundingBox(bool bbox)
Definition: object.h:75
void setEnable(bool enable)
Definition: object.h:70
void setID(std::string ID_)
Definition: object.h:105
boost::shared_ptr< Group > getSeparateGroup()
Definition: object.cc:205
virtual std::string getFullName(bool includingFileName=false, bool stopAtSeparateFile=false)
Definition: object.cc:43
bool getSelected() const
Definition: object.h:108
void setSelected(bool selected_)
Definition: object.h:110
virtual std::string getClassName()=0
Definition: object.h:48
std::string getID() const
Definition: object.h:103
boost::shared_ptr< Group > getTopLevelGroup()
Definition: object.cc:209
virtual void initializeUsingXML(xercesc::DOMElement *element)
Definition: object.cc:51
Definition: group.h:32

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Valid HTML