| 1 |
/****************************************************************************** |
| 2 |
This source file is part of the Avogadro project. |
| 3 |
This source code is released under the 3-Clause BSD License, (see "LICENSE"). |
| 4 |
******************************************************************************/ |
| 5 |
|
| 6 |
#ifndef AVOGADRO_RENDERING_NODE_H |
| 7 |
#define AVOGADRO_RENDERING_NODE_H |
| 8 |
|
| 9 |
#include "avogadrorenderingexport.h" |
| 10 |
#include <avogadro/core/avogadrocore.h> |
| 11 |
|
| 12 |
namespace Avogadro { |
| 13 |
namespace Rendering { |
| 14 |
|
| 15 |
class GroupNode; |
| 16 |
class Visitor; |
| 17 |
|
| 18 |
/** |
| 19 |
* @class Node node.h <avogadro/rendering/node.h> |
| 20 |
* @brief The Node class is the base class for all items in the scene. |
| 21 |
* @author Marcus D. Hanwell |
| 22 |
* |
| 23 |
* The Node class is the base class for nodes in the Scene, providing common |
| 24 |
* API and functionality. |
| 25 |
*/ |
| 26 |
|
| 27 |
class AVOGADRORENDERING_EXPORT Node |
| 28 |
{ |
| 29 |
public: |
| 30 |
Node(); |
| 31 |
virtual ~Node(); |
| 32 |
|
| 33 |
/** |
| 34 |
* Accept a visit from our friendly visitor. |
| 35 |
*/ |
| 36 |
virtual void accept(Visitor&) { return; } |
| 37 |
|
| 38 |
/** |
| 39 |
* @brief Get a pointer to the node's parent. |
| 40 |
* @return Pointer to the parent node, nullptr if no parent. |
| 41 |
*/ |
| 42 |
const GroupNode* parent() const { return m_parent; } |
| 43 |
GroupNode* parent() { return m_parent; } |
| 44 |
|
| 45 |
/** |
| 46 |
* @brief Set the visibility of the node. |
| 47 |
* @param visibility True if the node is visible, false if invisible. |
| 48 |
*/ |
| 49 |
void setVisible(bool visibility) { m_visible = visibility; } |
| 50 |
|
| 51 |
/** |
| 52 |
* @brief Get the current visibility of the node. |
| 53 |
* @return True if visible. |
| 54 |
*/ |
| 55 |
bool isVisible() const { return m_visible; } |
| 56 |
|
| 57 |
/** |
| 58 |
* @brief Attempt to dynamic_cast to specified node type. |
| 59 |
* @return Valid pointer to specified type, or null. |
| 60 |
*/ |
| 61 |
template <typename T> |
| 62 |
T* cast(); |
| 63 |
template <typename T> |
| 64 |
const T* cast() const; |
| 65 |
|
| 66 |
protected: |
| 67 |
friend class GroupNode; |
| 68 |
|
| 69 |
/** |
| 70 |
* @brief Set the parent node for the node. |
| 71 |
* @param parent The parent, a value of nullptr denotes no parent node. |
| 72 |
*/ |
| 73 |
void setParent(GroupNode* parent); |
| 74 |
|
| 75 |
GroupNode* m_parent; |
| 76 |
bool m_visible; |
| 77 |
}; |
| 78 |
|
| 79 |
template <typename T> |
| 80 |
T* Node::cast() |
| 81 |
{ |
| 82 |
return dynamic_cast<T*>(this); |
| 83 |
} |
| 84 |
|
| 85 |
template <typename T> |
| 86 |
const T* Node::cast() const |
| 87 |
{ |
| 88 |
return dynamic_cast<const T*>(this); |
| 89 |
} |
| 90 |
|
| 91 |
} // End namespace Rendering |
| 92 |
} // End namespace Avogadro |
| 93 |
|
| 94 |
#endif // AVOGADRO_RENDERING_NODE_H |