NodeElement.cpp

Go to the documentation of this file.
00001 /******************************************************************************
00002 *       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3      *
00003 *                (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS                    *
00004 *                                                                             *
00005 * This library is free software; you can redistribute it and/or modify it     *
00006 * under the terms of the GNU Lesser General Public License as published by    *
00007 * the Free Software Foundation; either version 2.1 of the License, or (at     *
00008 * your option) any later version.                                             *
00009 *                                                                             *
00010 * This library is distributed in the hope that it will be useful, but WITHOUT *
00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
00013 * for more details.                                                           *
00014 *                                                                             *
00015 * You should have received a copy of the GNU Lesser General Public License    *
00016 * along with this library; if not, write to the Free Software Foundation,     *
00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.          *
00018 *******************************************************************************
00019 *                               SOFA :: Modules                               *
00020 *                                                                             *
00021 * Authors: The SOFA Team and external contributors (see Authors.txt)          *
00022 *                                                                             *
00023 * Contact information: contact@sofa-framework.org                             *
00024 ******************************************************************************/
00025 #include <sofa/simulation/tree/xml/NodeElement.h>
00026 //#include <sofa/simulation/tree/xml/ObjectElement.h>
00027 #include <sofa/simulation/tree/xml/Element.inl>
00028 
00029 namespace sofa
00030 {
00031 
00032 namespace simulation
00033 {
00034 
00035 namespace tree
00036 {
00037 
00038 namespace xml
00039 {
00040 
00041 using namespace sofa::defaulttype;
00042 
00043 //template class Factory< std::string, xml::BaseElement, Node<xml::BaseElement*>* >;
00044 
00045 NodeElement::NodeElement(const std::string& name, const std::string& type, BaseElement* parent)
00046 : Element<core::objectmodel::BaseNode>(name, type, parent)
00047 {
00048 }
00049 
00050 NodeElement::~NodeElement()
00051 {
00052 }
00053 
00054 bool NodeElement::setParent(BaseElement* newParent)
00055 {
00056     if (newParent != NULL && dynamic_cast<NodeElement*>(newParent)==NULL)
00057         return false;
00058     else
00059         return Element<core::objectmodel::BaseNode>::setParent(newParent);
00060 }
00061 
00062 bool NodeElement::initNode()
00063 {
00064     if (!Element<core::objectmodel::BaseNode>::initNode()) return false;
00065     if (getTypedObject()!=NULL && getParentElement()!=NULL && dynamic_cast<core::objectmodel::BaseNode*>(getParentElement()->getObject())!=NULL)
00066     {
00067 //      std::cout << "Adding Child "<<getName()<<" to "<<getParentElement()->getName()<<std::endl;
00068         dynamic_cast<core::objectmodel::BaseNode*>(getParentElement()->getObject())->addChild(getTypedObject());
00069     }
00070     return true;
00071 }
00072 
00073 bool NodeElement::init()
00074 {
00075     bool res = Element<core::objectmodel::BaseNode>::init();
00076     /*
00077     if (getTypedObject()!=NULL)
00078     {
00079         for (child_iterator<> it = begin();
00080                     it != end(); ++it)
00081         {
00082             objectmodel::BaseObject* obj = dynamic_cast<objectmodel::BaseObject*>(it->getTypedObject());
00083             if (obj!=NULL)
00084             {
00085                 std::cout << "Adding Object "<<it->getName()<<" to "<<getName()<<std::endl;
00086                 getTypedObject()->addObject(obj);
00087             }
00088         }
00089     }
00090     */
00091     return res;
00092 }
00093 
00094 SOFA_DECL_CLASS(Node)
00095 
00096 helper::Creator<BaseElement::NodeFactory, NodeElement> NodeNodeClass("Node");
00097 //helper::Creator<BaseElement::NodeFactory, NodeElement> NodeBodyClass("Body");
00098 //helper::Creator<BaseElement::NodeFactory, NodeElement> NodeGClass("G");
00099 
00100 const char* NodeElement::getClass() const
00101 {
00102     return NodeNodeClass.c_str();
00103 }
00104 
00105 } // namespace xml
00106 
00107 } // namespace tree
00108 
00109 } // namespace simulation
00110 
00111 } // namespace sofa
00112 

Generated on Sun Nov 23 04:05:48 2008 for Sofa by  doxygen 1.5.7.1