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 library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library 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 GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 including the absolute or relatvie path
42  std::shared_ptr<H5::File> hdf5File;
43  std::function<void()> closeRequestCallback;
44  std::function<void()> refreshCallback;
45  void createHDF5File() override;
46  void openHDF5File() override;
47 
48  Group();
49  ~Group() override;
50 
54  void writeXML();
55 
59  void readXML();
60 
61  public:
63  void setExpand(bool expand) { expandStr=(expand)?"true":"false"; }
64 
65  bool getExpand() { return expandStr=="true"?true:false; }
66 
68  void addObject(const std::shared_ptr<Object>& newObject);
69 
70  std::vector<std::shared_ptr<Object> >& getObjects() {
71  return object;
72  }
73 
74  std::shared_ptr<H5::File>& getHDF5File() { return hdf5File; }
75 
77  std::string getFileName() { return fileName; }
78 
79  std::string getFullName() override;
80 
82  void setFileName(const std::string &fn) { fileName=fn; }
83 
88  void write(bool writeXMLFile=true, bool writeH5File=true);
89 
91  void read();
92 
94  void enableSWMR();
95 
97  void flushIfRequested();
98 
100  void refresh();
101 
103  void requestFlush();
104 
106  void setCloseRequestCallback(const std::function<void()> &closeRequestCallback_) { closeRequestCallback=closeRequestCallback_; }
107 
110  void setRefreshCallback(const std::function<void()> &refreshCallback_) { refreshCallback=refreshCallback_; }
111 
113  void initializeUsingXML(xercesc::DOMElement *element) override;
114 
115  xercesc::DOMElement* writeXMLFile(xercesc::DOMNode *parent) override;
116 
118  std::shared_ptr<Group> getTopLevelGroup() {
119  std::shared_ptr<Group> p=parent.lock();
120  return !p?shared_from_this():p->getTopLevelGroup();
121  }
122  };
123 
124 }
125 
126 #endif
std::shared_ptr< Group > getTopLevelGroup()
Definition: group.h:118
void setRefreshCallback(const std::function< void()> &refreshCallback_)
Definition: group.h:110
void refresh()
Definition: group.cc:173
void readXML()
Definition: group.cc:132
std::string getFullName() override
Definition: group.cc:53
Definition: objectfactory.h:36
void addObject(const std::shared_ptr< Object > &newObject)
Definition: group.cc:44
void flushIfRequested()
Definition: group.cc:169
void setFileName(const std::string &fn)
Definition: group.h:82
void setCloseRequestCallback(const std::function< void()> &closeRequestCallback_)
Definition: group.h:106
void setExpand(bool expand)
Definition: group.h:63
void write(bool writeXMLFile=true, bool writeH5File=true)
Definition: group.cc:141
void read()
Definition: group.cc:182
void initializeUsingXML(xercesc::DOMElement *element) override
Definition: group.cc:109
Definition: object.h:43
void writeXML()
Definition: group.cc:98
void requestFlush()
Definition: group.cc:177
void enableSWMR()
Definition: group.cc:165
std::string getFileName()
Definition: group.h:77
Definition: group.h:30
Definition: body.h:31