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  typedef int Index;
42 
43 #ifndef SWIG // SWIG can not parse this (swig bug?). However it is not needed for the swig interface -> removed for swig
44  const MBXMLUtils::NamespaceURI OPENMBV("http://www.mbsim-env.de/OpenMBV");
45 #endif
46 
47  class Group;
48 
50  class Object
51 #ifndef SWIG
52  // with swig we do not need any access to fmatvec::Atom members. To avoid problems with other projects
53  // deriving from fmatvec::Atomm we skip this completely from swig processing.
54  : virtual public fmatvec::Atom
55 #endif
56  {
57  friend class Group;
58  protected:
59  std::string name;
60  std::string enableStr, boundingBoxStr;
61  std::string ID; // Note: the ID is metadata and stored as a processing instruction in XML
62  bool selected; // Note: the selected flag is metadata and not stored in XML but used by OpenMBVGUI
63  std::weak_ptr<Group> parent;
64 
65  virtual void createHDF5File()=0;
66  virtual void openHDF5File()=0;
67  H5::GroupBase *hdf5Group;
68  virtual void terminate()=0;
69 
70  Object();
71  virtual ~Object();
72  public:
73 
75  virtual std::string getClassName()=0;
76 
78  void setEnable(bool enable) { enableStr=(enable==true)?"true":"false"; }
79 
80  bool getEnable() { return enableStr=="true"?true:false; }
81 
83  void setBoundingBox(bool bbox) { boundingBoxStr=(bbox==true)?"true":"false"; }
84 
85  bool getBoundingBox() { return boundingBoxStr=="true"?true:false; }
86 
88  void setName(const std::string& name_) { name=name_; }
89 
90  std::string getName() { return name; }
91 
93  virtual std::string getFullName(bool includingFileName=false, bool stopAtSeparateFile=false);
94 
96  virtual void initializeUsingXML(xercesc::DOMElement *element);
97 
98  virtual xercesc::DOMElement *writeXMLFile(xercesc::DOMNode *parent);
99 
101  std::shared_ptr<Group> getSeparateGroup();
102 
104  std::shared_ptr<Group> getTopLevelGroup();
105 
106  std::weak_ptr<Group> getParent() { return parent; }
107 
108  H5::GroupBase *getHDF5Group() { return hdf5Group; };
109 
111  std::string getID() const { return ID; }
113  void setID(std::string ID_) { ID=ID_; }
114 
116  bool getSelected() const { return selected; }
118  void setSelected(bool selected_) { selected=selected_; }
119 
120  // FROM NOW ONLY CONVENIENCE FUNCTIONS FOLLOW !!!
121  static int getInt(xercesc::DOMElement *e);
122  static double getDouble(xercesc::DOMElement *e);
123  static std::vector<double> getVec(xercesc::DOMElement *e, unsigned int rows=0);
124  static std::vector<std::vector<double> > getMat(xercesc::DOMElement *e, unsigned int rows=0, unsigned int cols=0);
125  static std::vector<int> getIntVec(xercesc::DOMElement *e, unsigned int rows=0);
126 
127  static std::string numtostr(int i) { std::ostringstream oss; oss << i; return oss.str(); }
128  static std::string numtostr(double d) { std::ostringstream oss; oss << d; return oss.str(); }
129 
130 
131  template<class T>
132  static void addElementText(xercesc::DOMElement *parent, const MBXMLUtils::FQN &name, const T &value) {
133  std::ostringstream oss;
134  oss<<value;
135  xercesc::DOMElement *ele = MBXMLUtils::D(parent->getOwnerDocument())->createElement(name);
136  ele->insertBefore(parent->getOwnerDocument()->createTextNode(MBXMLUtils::X()%oss.str()), NULL);
137  parent->insertBefore(ele, NULL);
138  }
139  static void addElementText(xercesc::DOMElement *parent, const MBXMLUtils::FQN &name, double value, double def);
140  static void addElementText(xercesc::DOMElement *parent, const MBXMLUtils::FQN &name, const std::vector<double> &value);
141  static void addElementText(xercesc::DOMElement *parent, const MBXMLUtils::FQN &name, const std::vector<std::vector<double> > &value);
142  static void addElementText(xercesc::DOMElement *parent, const MBXMLUtils::FQN &name, const std::vector<int> &value);
143 
144  template <class T>
145  static void addAttribute(xercesc::DOMNode *node, std::string name, T value) {
146  xercesc::DOMElement *ele = dynamic_cast<xercesc::DOMElement*>(node);
147  if(ele) {
148  std::ostringstream oss;
149  oss<<value;
150  MBXMLUtils::E(ele)->setAttribute(name, oss.str());
151  }
152  }
153 
154  template <class T>
155  static void addAttribute(xercesc::DOMNode *node, std::string name, T value, std::string def) {
156  if(value!=def) addAttribute(node, name, value);
157  }
158 
159  protected:
160  static std::vector<double> toVector(std::string str);
161  static std::vector<std::vector<double> > toMatrix(std::string str);
162  static std::vector<int> toIntVector(std::string str);
163  static std::vector<std::vector<int> > toIntMatrix(std::string str);
164  };
165 
166 }
167 
168 #endif
void setName(const std::string &name_)
Definition: object.h:88
void setBoundingBox(bool bbox)
Definition: object.h:83
void setEnable(bool enable)
Definition: object.h:78
void setID(std::string ID_)
Definition: object.h:113
virtual std::string getFullName(bool includingFileName=false, bool stopAtSeparateFile=false)
Definition: object.cc:43
bool getSelected() const
Definition: object.h:116
void setSelected(bool selected_)
Definition: object.h:118
virtual std::string getClassName()=0
Definition: object.h:50
std::shared_ptr< Group > getSeparateGroup()
Definition: object.cc:218
std::string getID() const
Definition: object.h:111
std::shared_ptr< Group > getTopLevelGroup()
Definition: object.cc:222
virtual void initializeUsingXML(xercesc::DOMElement *element)
Definition: object.cc:51
Definition: group.h:30

Impressum / Disclaimer / Datenschutz Generated by doxygen 1.8.5 Valid HTML