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/objectfactory.h>
24#include <openmbvcppinterface/object.h>
25#include <vector>
26#include <map>
27
28namespace OpenMBV {
29
31 class Group : public Object
32#ifndef SWIG
33 , public std::enable_shared_from_this<Group>
34#endif
35 {
36 friend class Body;
37 friend class Object;
38 friend class ObjectFactory;
39 protected:
40 std::vector<std::shared_ptr<Object> > object;
41 std::string expandStr;
42 std::string fileName; // the file name of the .ombvx file including the absolute or relatvie path
43 std::shared_ptr<H5::File> hdf5File;
44 std::function<void()> closeRequestCallback;
45 std::function<void()> refreshCallback;
46 void createHDF5File() override;
47 void openHDF5File() override;
48
49 Group();
50 ~Group() override;
51
55 void writeXML();
56
60 void readXML();
61
62 public:
64 void setExpand(bool expand) { expandStr=(expand)?"true":"false"; }
65
66 bool getExpand() { return expandStr=="true"?true:false; }
67
69 void addObject(const std::shared_ptr<Object>& newObject);
70
71 std::vector<std::shared_ptr<Object> >& getObjects() {
72 return object;
73 }
74
75 std::shared_ptr<H5::File>& getHDF5File() { return hdf5File; }
76
78 std::string getFileName() { return fileName; }
79
80 std::string getFullName() override;
81
83 void setFileName(const std::string &fn) { fileName=fn; }
84
89 void write(bool writeXMLFile=true, bool writeH5File=true);
90
92 void read();
93
95 void enableSWMR();
96
98 void flushIfRequested();
99
101 void refresh();
102
104 void requestFlush();
105
107 void setCloseRequestCallback(const std::function<void()> &closeRequestCallback_) { closeRequestCallback=closeRequestCallback_; }
108
111 void setRefreshCallback(const std::function<void()> &refreshCallback_) { refreshCallback=refreshCallback_; }
112
114 void initializeUsingXML(xercesc::DOMElement *element) override;
115
116 xercesc::DOMElement* writeXMLFile(xercesc::DOMNode *parent) override;
117
119 std::shared_ptr<Group> getTopLevelGroup() {
120 std::shared_ptr<Group> p=parent.lock();
121 return !p?shared_from_this():p->getTopLevelGroup();
122 }
123 };
124
125}
126
127#endif
Definition: body.h:32
Definition: group.h:35
void setCloseRequestCallback(const std::function< void()> &closeRequestCallback_)
Definition: group.h:107
void readXML()
Definition: group.cc:131
void addObject(const std::shared_ptr< Object > &newObject)
Definition: group.cc:43
void refresh()
Definition: group.cc:175
void flushIfRequested()
Definition: group.cc:171
void initializeUsingXML(xercesc::DOMElement *element) override
Definition: group.cc:108
void writeXML()
Definition: group.cc:97
void setExpand(bool expand)
Definition: group.h:64
std::string getFullName() override
Definition: group.cc:52
void write(bool writeXMLFile=true, bool writeH5File=true)
Definition: group.cc:143
std::shared_ptr< Group > getTopLevelGroup()
Definition: group.h:119
void setRefreshCallback(const std::function< void()> &refreshCallback_)
Definition: group.h:111
void requestFlush()
Definition: group.cc:179
void read()
Definition: group.cc:184
void enableSWMR()
Definition: group.cc:167
std::string getFileName()
Definition: group.h:78
void setFileName(const std::string &fn)
Definition: group.h:83
Definition: objectfactory.h:38
Definition: object.h:48