1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2017 Klaralvdalens Datakonsult AB (KDAB). |
4 | ** Contact: http://www.qt-project.org/legal |
5 | ** |
6 | ** This file is part of the Qt3D module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL3$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see http://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at http://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or later as published by the Free |
28 | ** Software Foundation and appearing in the file LICENSE.GPL included in |
29 | ** the packaging of this file. Please review the following information to |
30 | ** ensure the GNU General Public License version 2.0 requirements will be |
31 | ** met: http://www.gnu.org/licenses/gpl-2.0.html. |
32 | ** |
33 | ** $QT_END_LICENSE$ |
34 | ** |
35 | ****************************************************************************/ |
36 | |
37 | #include "clipblendnodevisitor_p.h" |
38 | #include <Qt3DAnimation/private/managers_p.h> |
39 | #include <Qt3DAnimation/private/clipblendnode_p.h> |
40 | |
41 | QT_BEGIN_NAMESPACE |
42 | |
43 | namespace Qt3DAnimation { |
44 | namespace Animation { |
45 | |
46 | /*! |
47 | \class ClipBlendNodeVisitor |
48 | \internal |
49 | Visits a blend tree in either pre- or post-order manner, optionally taking care |
50 | to only visit the nodes that are dependencies of evaluating the blend |
51 | tree. |
52 | */ |
53 | ClipBlendNodeVisitor::ClipBlendNodeVisitor(ClipBlendNodeManager *manager, |
54 | TraversalOrder order, |
55 | NodeFilter filter) |
56 | : m_manager(manager) |
57 | , m_order(order) |
58 | , m_filter(filter) |
59 | { |
60 | } |
61 | |
62 | void ClipBlendNodeVisitor::traverse(Qt3DCore::QNodeId rootId, |
63 | const VisitFunction &visitFunction) const |
64 | { |
65 | ClipBlendNode *node = m_manager->lookupNode(id: rootId); |
66 | if (node != nullptr) { |
67 | switch (m_order) { |
68 | case PreOrder: { |
69 | switch (m_filter) { |
70 | case VisitAllNodes: |
71 | visitPreOrderAllNodes(node, visitFunction); |
72 | break; |
73 | |
74 | case VisitOnlyDependencies: |
75 | visitPreOrderDependencyNodes(node, visitFunction); |
76 | break; |
77 | } |
78 | |
79 | break; |
80 | } |
81 | |
82 | case PostOrder: { |
83 | switch (m_filter) { |
84 | case VisitAllNodes: |
85 | visitPostOrderAllNodes(node, visitFunction); |
86 | break; |
87 | |
88 | case VisitOnlyDependencies: |
89 | visitPostOrderDependencyNodes(node, visitFunction); |
90 | break; |
91 | } |
92 | |
93 | break; |
94 | } |
95 | } |
96 | } |
97 | } |
98 | |
99 | /*! |
100 | \internal |
101 | Leaf to root traversal (Pre-order traversal) visiting all nodes even if |
102 | they will not participate in current evaluation of the blend tree. |
103 | */ |
104 | void ClipBlendNodeVisitor::visitPreOrderAllNodes(ClipBlendNode *node, |
105 | const VisitFunction &visitFunction) const |
106 | { |
107 | visitFunction(node); |
108 | const Qt3DCore::QNodeIdVector childIds = node->allDependencyIds(); |
109 | for (const Qt3DCore::QNodeId childId: childIds) { |
110 | ClipBlendNode *childNode = m_manager->lookupNode(id: childId); |
111 | if (childNode != nullptr) |
112 | visitPreOrderAllNodes(node: childNode, visitFunction); |
113 | } |
114 | } |
115 | |
116 | /*! |
117 | \internal |
118 | Leaf to root traversal (Post-order traversal) visiting all nodes even if |
119 | they will not participate in current evaluation of the blend tree. |
120 | */ |
121 | void ClipBlendNodeVisitor::visitPostOrderAllNodes(ClipBlendNode *node, |
122 | const VisitFunction &visitFunction) const |
123 | { |
124 | const Qt3DCore::QNodeIdVector childIds = node->allDependencyIds(); |
125 | for (const Qt3DCore::QNodeId childId: childIds) { |
126 | ClipBlendNode *childNode = m_manager->lookupNode(id: childId); |
127 | if (childNode != nullptr) |
128 | visitPostOrderAllNodes(node: childNode, visitFunction); |
129 | } |
130 | visitFunction(node); |
131 | } |
132 | |
133 | /*! |
134 | \internal |
135 | Leaf to root traversal (Pre-order traversal) visiting only nodes required |
136 | to evaluate the blend tree given its current state. |
137 | */ |
138 | void ClipBlendNodeVisitor::visitPreOrderDependencyNodes(ClipBlendNode *node, |
139 | const VisitFunction &visitFunction) const |
140 | { |
141 | visitFunction(node); |
142 | const Qt3DCore::QNodeIdVector childIds = node->currentDependencyIds(); |
143 | for (const Qt3DCore::QNodeId childId: childIds) { |
144 | ClipBlendNode *childNode = m_manager->lookupNode(id: childId); |
145 | if (childNode != nullptr) |
146 | visitPreOrderDependencyNodes(node: childNode, visitFunction); |
147 | } |
148 | } |
149 | |
150 | /*! |
151 | \internal |
152 | Leaf to root traversal (Post-order traversal) visiting only nodes required |
153 | to evaluate the blend tree given its current state. |
154 | */ |
155 | void ClipBlendNodeVisitor::visitPostOrderDependencyNodes(ClipBlendNode *node, |
156 | const VisitFunction &visitFunction) const |
157 | { |
158 | const Qt3DCore::QNodeIdVector childIds = node->currentDependencyIds(); |
159 | for (const Qt3DCore::QNodeId childId: childIds) { |
160 | ClipBlendNode *childNode = m_manager->lookupNode(id: childId); |
161 | if (childNode != nullptr) |
162 | visitPostOrderDependencyNodes(node: childNode, visitFunction); |
163 | } |
164 | visitFunction(node); |
165 | } |
166 | |
167 | } // Animation |
168 | } // Qt3DAnimation |
169 | |
170 | QT_END_NAMESPACE |
171 | |