Blender  V2.93
NodeGroup.cpp
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
24 #include "NodeGroup.h"
25 
26 namespace Freestyle {
27 
29 {
30  if (nullptr == iChild) {
31  return;
32  }
33 
34  _Children.push_back(iChild);
35  iChild->addRef();
36 }
37 
39 {
45  int refThis = Node::destroy();
46 
47  // if refThis != 0, we can't destroy the tree
48  if (0 != refThis) {
49  return refThis;
50  }
51 
52  // If we are here, that means that nobody else needs our NodeGroup and we can destroy it.
53  int refCount = 0;
54  vector<Node *>::iterator node;
55 
56  for (node = _Children.begin(); node != _Children.end(); ++node) {
57  refCount = (*node)->destroy();
58  if (0 == refCount) {
59  delete (*node);
60  }
61  }
62 
63  _Children.clear();
64 
65  return refThis;
66 }
67 
69 {
70  v.visitNodeGroup(*this);
71 
72  v.visitNodeGroupBefore(*this);
73  for (vector<Node *>::iterator node = _Children.begin(), end = _Children.end(); node != end;
74  ++node) {
75  (*node)->accept(v);
76  }
77  v.visitNodeGroupAfter(*this);
78 }
79 
81 {
82  vector<Node *>::iterator node;
83 
84  for (node = _Children.begin(); node != _Children.end(); ++node) {
85  (*node)->release();
86  }
87 
88  _Children.clear();
89 }
90 
92 {
93  /* int found = 0; */ /* UNUSED */
94  vector<Node *>::iterator node;
95 
96  for (node = _Children.begin(); node != _Children.end(); ++node) {
97  if ((*node) == iChild) {
98  (*node)->release();
99  _Children.erase(node);
100  /* found = 1; */ /* UNUSED */
101  break;
102  }
103  }
104 }
105 
106 void NodeGroup::RetrieveChildren(vector<Node *> &oNodes)
107 {
108  oNodes = _Children;
109 }
110 
112 {
113  vector<Node *>::iterator node;
114  clearBBox();
115  for (node = _Children.begin(); node != _Children.end(); ++node) {
116  AddBBox((*node)->UpdateBBox());
117  }
118 
119  return Node::UpdateBBox();
120 }
121 
122 } /* namespace Freestyle */
Class to represent a group node. This node can contains several children.
ATTR_WARN_UNUSED_RESULT const BMVert * v
virtual int destroy()
Definition: BaseObject.h:45
virtual void RetrieveChildren(vector< Node * > &oNodes)
Definition: NodeGroup.cpp:106
virtual void DetachChildren()
Definition: NodeGroup.cpp:80
virtual void AddChild(Node *iChild)
Definition: NodeGroup.cpp:28
virtual const BBox< Vec3r > & UpdateBBox()
Definition: NodeGroup.cpp:111
vector< Node * > _Children
Definition: NodeGroup.h:78
virtual int destroy()
Definition: NodeGroup.cpp:38
virtual void DetachChild(Node *iChild)
Definition: NodeGroup.cpp:91
virtual void accept(SceneVisitor &v)
Definition: NodeGroup.cpp:68
virtual const BBox< Vec3r > & UpdateBBox()
Definition: Node.h:94
virtual void clearBBox()
Definition: Node.h:100
virtual void AddBBox(const BBox< Vec3r > &iBox)
Definition: Node.h:79
OperationNode * node
inherits from class Rep
Definition: AppCanvas.cpp:32