openmbvcppinterface 3.1.0 OpenMBV C++ Interface

compoundrigidbody.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_COMPOUNDRIGIDBODY_H_
21 #define _OPENMBV_COMPOUNDRIGIDBODY_H_
22
23 #include <openmbvcppinterface/rigidbody.h>
24 #include <vector>
25
26 namespace OpenMBV {
27
29 class CompoundRigidBody : public RigidBody
30 #ifndef SWIG
31 , public std::enable_shared_from_this<CompoundRigidBody>
32 #endif
33 {
34 friend class RigidBody;
35 friend class ObjectFactory;
36 protected:
37 std::string expandStr;
38 std::vector<std::shared_ptr<RigidBody> > rigidBody;
39
40 CompoundRigidBody();
41 ~CompoundRigidBody() override;
42 public:
44 void addRigidBody(const std::shared_ptr<RigidBody>& rigidBody_) {
45 if(rigidBody_->name.empty()) throw std::runtime_error("the object to be added must have a name");
46 for(auto & i : rigidBody)
47 if(i->name==rigidBody_->name) throw std::runtime_error("a object of the same name already exists");
48 rigidBody.push_back(rigidBody_);
49 rigidBody_->parent.reset();
50 rigidBody_->compound=shared_from_this();
51 }
52
53 std::vector<std::shared_ptr<RigidBody> >& getRigidBodies() {
54 return rigidBody;
55 }
56
58 void initializeUsingXML(xercesc::DOMElement *element) override;
59
60 xercesc::DOMElement* writeXMLFile(xercesc::DOMNode *parent) override;
61
63 void setExpand(bool expand) { expandStr=(expand)?"true":"false"; }
64
65 bool getExpand() { return expandStr=="true"?true:false; }
66 };
67
68 }
69
70 #endif
OpenMBV::CompoundRigidBody::addRigidBody
void addRigidBody(const std::shared_ptr< RigidBody > &rigidBody_)
Definition: compoundrigidbody.h:44
OpenMBV::RigidBody
Abstract base class for all rigid bodies.
Definition: rigidbody.h:68
OpenMBV::ObjectFactory
Definition: objectfactory.h:38
OpenMBV::CompoundRigidBody::setExpand
void setExpand(bool expand)
Definition: compoundrigidbody.h:63
OpenMBV::CompoundRigidBody::initializeUsingXML
void initializeUsingXML(xercesc::DOMElement *element) override
Definition: compoundrigidbody.cc:47
OpenMBV::CompoundRigidBody
Definition: compoundrigidbody.h:29