openmbvcppinterface  3.1.0
OpenMBV C++ Interface
group.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_GROUP_H_
21 #define _OPENMBV_GROUP_H_
22 
23 #include <openmbvcppinterface/object.h>
24 #include <vector>
25 #include <map>
26 
27 namespace OpenMBV {
28 
30  class Group : public Object
31 #ifndef SWIG
32  , public std::enable_shared_from_this<Group>
33 #endif
34  {
35  friend class Body;
36  friend class Object;
37  friend class ObjectFactory;
38  protected:
39  std::vector<std::shared_ptr<Object> > object;
40  std::string expandStr;
41  std::string fileName; // the file name of the .ombvx file of this separateFile Group including the absolute or relatvie path
42  bool separateFile{false};
43  std::shared_ptr<H5::File> hdf5File;
44  void createHDF5File() override;
45  void openHDF5File() override;
46 
47  Group();
48  ~Group() override;
49 
53  void writeXML();
54 
58  void readXML();
59 
64  void writeH5();
65 
68  void readH5();
69 
70  public:
72  void setExpand(bool expand) { expandStr=(expand)?"true":"false"; }
73 
74  bool getExpand() { return expandStr=="true"?true:false; }
75 
77  void addObject(const std::shared_ptr<Object>& newObject);
78 
79  std::vector<std::shared_ptr<Object> >& getObjects() {
80  return object;
81  }
82 
84  void setSeparateFile(bool sepFile) { separateFile=sepFile; }
85 
86  bool getSeparateFile() { return separateFile; }
87  std::shared_ptr<H5::File>& getHDF5File() { return hdf5File; }
88 
91  std::string getFileName() { return fileName; }
92 
93  std::string getFullName(bool includingFileName=false, bool stopAtSeparateFile=false) override;
94 
97  void setFileName(const std::string &fn) { fileName=fn; }
98 
102  void write(bool writeXMLFile=true, bool writeH5File=true);
103 
107  void read();
108 
112  void terminate() override;
113 
115  void initializeUsingXML(xercesc::DOMElement *element) override;
116 
117  xercesc::DOMElement* writeXMLFile(xercesc::DOMNode *parent) override;
118 
120  std::shared_ptr<Group> getSeparateGroup() {
121  return separateFile?shared_from_this():parent.lock()->getSeparateGroup();
122  }
123 
125  std::shared_ptr<Group> getTopLevelGroup() {
126  std::shared_ptr<Group> p=parent.lock();
127  return !p?shared_from_this():p->getTopLevelGroup();
128  }
129  };
130 
131 }
132 
133 #endif
std::shared_ptr< Group > getTopLevelGroup()
Definition: group.h:125
void writeH5()
Definition: group.cc:160
void readXML()
Definition: group.cc:198
Definition: objectfactory.h:36
void addObject(const std::shared_ptr< Object > &newObject)
Definition: group.cc:49
std::shared_ptr< Group > getSeparateGroup()
Definition: group.h:120
void setFileName(const std::string &fn)
Definition: group.h:97
void terminate() override
Definition: group.cc:169
void setExpand(bool expand)
Definition: group.h:72
void write(bool writeXMLFile=true, bool writeH5File=true)
Definition: group.cc:222
void read()
Definition: group.cc:269
void initializeUsingXML(xercesc::DOMElement *element) override
Definition: group.cc:177
Definition: object.h:43
std::string getFullName(bool includingFileName=false, bool stopAtSeparateFile=false) override
Definition: group.cc:58
void writeXML()
Definition: group.cc:148
void readH5()
Definition: group.cc:207
std::string getFileName()
Definition: group.h:91
Definition: group.h:30
void setSeparateFile(bool sepFile)
Definition: group.h:84
Definition: body.h:31