TrueReality  v0.1.1912
trCore/Nodes/Node.cpp
Go to the documentation of this file.
1 /*
2 * True Reality Open Source Game and Simulation Engine
3 * Copyright © 2021 Acid Rain Studios LLC
4 *
5 * This library is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Lesser General Public License as published by the Free
7 * Software Foundation; either version 3.0 of the License, or (at your option)
8 * any later version.
9 *
10 * This library is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library; if not, write to the Free Software Foundation, Inc.,
17 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * @author Maxim Serebrennik
20 */
21 
22 #include <trCore/Nodes/Node.h>
23 
24 #include <trBase/Base.h>
25 
26 #include <osg/Group>
27 #include <osg/Node>
28 
29 namespace trCore::Nodes
30 {
31  const trUtil::RefStr Node::CLASS_TYPE = trUtil::RefStr("trCore::Nodes::Node");
32 
34  Node::Node(const std::string name) : BaseClass(name)
35  {
36  mNode = new osg::Group(); //Creates our internal OSG node.
37  mNode->setName(name);
38  }
39 
41  Node::Node(osg::Node& node, const std::string name) : Node(name)
42  {
43  mNode = &node;
44  }
45 
48  {
49  }
50 
52  const std::string& Node::GetType() const
53  {
54  return CLASS_TYPE;
55  }
56 
58  void Node::SetName(const std::string& name)
59  {
60  BaseClass::SetName(name);
61  mNode->setName(name);
62  }
63 
65  osg::Node* Node::AsOSGNode()
66  {
67  return mNode.Get();
68  }
69 
71  const osg::Node* Node::AsOSGNode() const
72  {
73  return mNode.Get();
74  }
75 
77  void Node::Accept(osg::NodeVisitor& nv)
78  {
79  mNode->accept(nv);
80  }
81 
83  void Node::Ascend(osg::NodeVisitor& nv)
84  {
85  mNode->ascend(nv);
86  }
87 
89  void Node::Traverse(osg::NodeVisitor& nv)
90  {
91  mNode->traverse(nv);
92  }
93 }
trBase::SmrtPtr< osg::Node > mNode
The node.
virtual void Accept(osg::NodeVisitor &nv)
Visitor Pattern : calls the apply method of a NodeVisitor with this node&#39;s type.
A string wrapper that will make sure that all of the strings with the same value will point to the sa...
Definition: RefStr.h:50
virtual const std::string & GetType() const override
Returns the class type.
static const trUtil::RefStr CLASS_TYPE
Adds an easy and swappable access to the base class.
This class is part of the internal garbage collection system.
Definition: SmrtClass.h:38
Class for wrapping the osg node Internally it contains an OSG Group, that can be accessed by user if ...
virtual void SetName(const std::string &name)
Sets this instances name.
virtual void Traverse(osg::NodeVisitor &nv)
Traverse downwards : calls children&#39;s accept method with NodeVisitor.
virtual void Ascend(osg::NodeVisitor &nv)
Traverse upwards : calls parents&#39; accept method with NodeVisitor.
virtual void SetName(const std::string &name)
Sets this instances name.
Definition: Base.cpp:43
virtual osg::Node * AsOSGNode()
Returns a pointer to the internal OSG Node.
T * Get() const
Returns the stored internal pointer.
Definition: SmrtPtr.h:73
Node(const std::string name=CLASS_TYPE)
Constructor.