Hosted by: BerliOS Developer Logo

OpenMBV C++ Interface

BerliOS Project Page
/home/user/MBSimWindows/openmbv/openmbvcppinterface/openmbvcppinterface/group.h
00001 /*
00002     OpenMBV - Open Multi Body Viewer.
00003     Copyright (C) 2009 Markus Friedrich
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 
00020 #ifndef _OPENMBV_GROUP_H_
00021 #define _OPENMBV_GROUP_H_
00022 
00023 #include <openmbvcppinterface/object.h>
00024 #include <vector>
00025 #include <map>
00026 #include <boost/shared_ptr.hpp>
00027 #include <boost/enable_shared_from_this.hpp>
00028 
00029 namespace OpenMBV {
00030 
00032   class Group : public Object
00033 #ifndef SWIG
00034       , public boost::enable_shared_from_this<Group>
00035 #endif
00036     {
00037     friend class Body;
00038     friend class Object;
00039     friend class ObjectFactory;
00040     protected:
00041       std::vector<boost::shared_ptr<Object> > object;
00042       std::string expandStr;
00043       std::string fileName; // the file name of the .ombv.xml file of this separateFile Group including the absolute or relatvie path
00044       bool separateFile;
00045       boost::shared_ptr<H5::File> hdf5File;
00046       void createHDF5File();
00047       void openHDF5File();
00048 
00049       Group();
00050       virtual ~Group();
00051 
00055       void writeXML();
00056 
00060       void readXML();
00061       
00066       void writeH5();
00067 
00070       void readH5();
00071 
00072     public:
00074       std::string getClassName() { return "Group"; }
00075 
00077       void setExpand(bool expand) { expandStr=(expand==true)?"true":"false"; }
00078 
00079       bool getExpand() { return expandStr=="true"?true:false; }
00080 
00082       void addObject(boost::shared_ptr<Object> object);
00083 
00084       std::vector<boost::shared_ptr<Object> >& getObjects() {
00085         return object;
00086       }
00087       
00089       void setSeparateFile(bool sepFile) { separateFile=sepFile; }
00090 
00091       bool getSeparateFile() { return separateFile; }
00092       boost::shared_ptr<H5::File>& getHDF5File() { return hdf5File; }
00093 
00096       std::string getFileName() { return fileName; }
00097 
00098       std::string getFullName(bool includingFileName=false, bool stopAtSeparateFile=false);
00099       
00102       void setFileName(const std::string &fn) { fileName=fn; }
00103       
00107       void write(bool writeXMLFile=true, bool writeH5File=true);
00108 
00112       void read(bool readXMLFile=true, bool readH5File=true);
00113 
00117       void terminate();
00118 
00120       virtual void initializeUsingXML(xercesc::DOMElement *element);
00121 
00122       xercesc::DOMElement* writeXMLFile(xercesc::DOMNode *parent);
00123 
00125       boost::shared_ptr<Group> getSeparateGroup() {
00126         return separateFile?shared_from_this():parent.lock()->getSeparateGroup();
00127       }
00128 
00130       boost::shared_ptr<Group> getTopLevelGroup() {
00131         boost::shared_ptr<Group> p=parent.lock();
00132         return !p?shared_from_this():p->getTopLevelGroup();
00133       }
00134   };
00135 
00136 }
00137 
00138 #endif