72256e35ea8e46ddfb61865b5f4d03f1e82088b3
[blender.git] / source / blender / depsgraph / intern / node / deg_node_operation.cc
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  * The Original Code is Copyright (C) 2013 Blender Foundation.
17  * All rights reserved.
18  *
19  * Original Author: Joshua Leung
20  */
21
22 /** \file blender/depsgraph/intern/node/deg_node_operation.cc
23  *  \ingroup depsgraph
24  */
25
26 #include "intern/node/deg_node_operation.h"
27
28 #include "MEM_guardedalloc.h"
29
30 #include "BLI_utildefines.h"
31 #include "BLI_ghash.h"
32
33 #include "intern/depsgraph.h"
34 #include "intern/node/deg_node_factory.h"
35 #include "intern/node/deg_node_component.h"
36 #include "intern/node/deg_node_id.h"
37
38 namespace DEG {
39
40 const char *operationCodeAsString(OperationCode opcode)
41 {
42         switch (opcode) {
43                 /* Generic Operations. */
44                 case OperationCode::OPERATION: return "OPERATION";
45                 case OperationCode::ID_PROPERTY: return "ID_PROPERTY";
46                 case OperationCode::PARAMETERS_EVAL: return "PARAMETERS_EVAL";
47                 case OperationCode::PLACEHOLDER: return "PLACEHOLDER";
48                 /* Animation, Drivers, etc. */
49                 case OperationCode::ANIMATION: return "ANIMATION";
50                 case OperationCode::DRIVER: return "DRIVER";
51                 /* Object related. */
52                 case OperationCode::OBJECT_BASE_FLAGS: return "OBJECT_BASE_FLAGS";
53                 /* Transform. */
54                 case OperationCode::TRANSFORM_LOCAL: return "TRANSFORM_LOCAL";
55                 case OperationCode::TRANSFORM_PARENT: return "TRANSFORM_PARENT";
56                 case OperationCode::TRANSFORM_CONSTRAINTS:
57                         return "TRANSFORM_CONSTRAINTS";
58                 case OperationCode::TRANSFORM_FINAL: return "TRANSFORM_FINAL";
59                 case OperationCode::TRANSFORM_OBJECT_UBEREVAL:
60                         return "TRANSFORM_OBJECT_UBEREVAL";
61                 /* Rigid body. */
62                 case OperationCode::RIGIDBODY_REBUILD: return "RIGIDBODY_REBUILD";
63                 case OperationCode::RIGIDBODY_SIM: return "RIGIDBODY_SIM";
64                 case OperationCode::RIGIDBODY_TRANSFORM_COPY:
65                         return "RIGIDBODY_TRANSFORM_COPY";
66                 /* Geometry. */
67                 case OperationCode::GEOMETRY_EVAL_INIT: return "GEOMETRY_EVAL_INIT";
68                 case OperationCode::GEOMETRY_EVAL: return "GEOMETRY_EVAL";
69                 case OperationCode::GEOMETRY_EVAL_DONE: return "GEOMETRY_EVAL_DONE";
70                 case OperationCode::GEOMETRY_SHAPEKEY: return "GEOMETRY_SHAPEKEY";
71                 /* Object data. */
72                 case OperationCode::LIGHT_PROBE_EVAL: return "LIGHT_PROBE_EVAL";
73                 case OperationCode::SPEAKER_EVAL: return "SPEAKER_EVAL";
74                 /* Pose. */
75                 case OperationCode::POSE_INIT: return "POSE_INIT";
76                 case OperationCode::POSE_INIT_IK: return "POSE_INIT_IK";
77                 case OperationCode::POSE_CLEANUP: return "POSE_CLEANUP";
78                 case OperationCode::POSE_DONE: return "POSE_DONE";
79                 case OperationCode::POSE_IK_SOLVER: return "POSE_IK_SOLVER";
80                 case OperationCode::POSE_SPLINE_IK_SOLVER:
81                         return "POSE_SPLINE_IK_SOLVER";
82                 /* Bone. */
83                 case OperationCode::BONE_LOCAL: return "BONE_LOCAL";
84                 case OperationCode::BONE_POSE_PARENT: return "BONE_POSE_PARENT";
85                 case OperationCode::BONE_CONSTRAINTS: return "BONE_CONSTRAINTS";
86                 case OperationCode::BONE_READY: return "BONE_READY";
87                 case OperationCode::BONE_DONE: return "BONE_DONE";
88                 case OperationCode::BONE_SEGMENTS: return "BONE_SEGMENTS";
89                 /* Particle System. */
90                 case OperationCode::PARTICLE_SYSTEM_INIT: return "PARTICLE_SYSTEM_INIT";
91                 case OperationCode::PARTICLE_SYSTEM_EVAL: return "PARTICLE_SYSTEM_EVAL";
92                 case OperationCode::PARTICLE_SYSTEM_DONE: return "PARTICLE_SYSTEM_DONE";
93                 /* Particles Settings. */
94                 case OperationCode::PARTICLE_SETTINGS_INIT:
95                         return "PARTICLE_SETTINGS_INIT";
96                 case OperationCode::PARTICLE_SETTINGS_EVAL:
97                         return "PARTICLE_SETTINGS_EVAL";
98                 case OperationCode::PARTICLE_SETTINGS_RESET:
99                         return "PARTICLE_SETTINGS_RESET";
100                 /* Point Cache. */
101                 case OperationCode::POINT_CACHE_RESET: return "POINT_CACHE_RESET";
102                 /* Batch cache. */
103                 case OperationCode::GEOMETRY_SELECT_UPDATE:
104                         return "GEOMETRY_SELECT_UPDATE";
105                 /* Masks. */
106                 case OperationCode::MASK_ANIMATION: return "MASK_ANIMATION";
107                 case OperationCode::MASK_EVAL: return "MASK_EVAL";
108                 /* Collections. */
109                 case OperationCode::VIEW_LAYER_EVAL: return "VIEW_LAYER_EVAL";
110                 /* Copy on write. */
111                 case OperationCode::COPY_ON_WRITE: return "COPY_ON_WRITE";
112                 /* Shading. */
113                 case OperationCode::SHADING: return "SHADING";
114                 case OperationCode::MATERIAL_UPDATE: return "MATERIAL_UPDATE";
115                 case OperationCode::WORLD_UPDATE: return "WORLD_UPDATE";
116                 /* Movie clip. */
117                 case OperationCode::MOVIECLIP_EVAL: return "MOVIECLIP_EVAL";
118                 case OperationCode::MOVIECLIP_SELECT_UPDATE:
119                         return "MOVIECLIP_SELECT_UPDATE";
120                 /* Synchronization. */
121                 case OperationCode::SYNCHRONIZE_TO_ORIGINAL:
122                         return "SYNCHRONIZE_TO_ORIGINAL";
123                 /* Generic datablock. */
124                 case OperationCode::GENERIC_DATABLOCK_UPDATE:
125                         return "GENERIC_DATABLOCK_UPDATE";
126         }
127         BLI_assert(!"Unhandled operation code, should never happen.");
128         return "UNKNOWN";
129 }
130
131 OperationNode::OperationNode() :
132     name_tag(-1),
133     flag(0)
134 {
135 }
136
137 OperationNode::~OperationNode()
138 {
139 }
140
141 string OperationNode::identifier() const
142 {
143         return string(operationCodeAsString(opcode)) + "(" + name + ")";
144 }
145
146 /* Full node identifier, including owner name.
147  * used for logging and debug prints. */
148 string OperationNode::full_identifier() const
149 {
150         string owner_str = "";
151         if (owner->type == NodeType::BONE) {
152                 owner_str = string(owner->owner->name) + "." + owner->name;
153         }
154         else {
155                 owner_str = owner->owner->name;
156         }
157         return owner_str + "." + identifier();
158 }
159
160 void OperationNode::tag_update(Depsgraph *graph, eUpdateSource source)
161 {
162         if ((flag & DEPSOP_FLAG_NEEDS_UPDATE) == 0) {
163                 graph->add_entry_tag(this);
164         }
165         /* Tag for update, but also note that this was the source of an update. */
166         flag |= (DEPSOP_FLAG_NEEDS_UPDATE | DEPSOP_FLAG_DIRECTLY_MODIFIED);
167         switch (source) {
168                 case DEG_UPDATE_SOURCE_TIME:
169                 case DEG_UPDATE_SOURCE_RELATIONS:
170                 case DEG_UPDATE_SOURCE_VISIBILITY:
171                         /* Currently nothing. */
172                         break;
173                 case DEG_UPDATE_SOURCE_USER_EDIT:
174                         flag |= DEPSOP_FLAG_USER_MODIFIED;
175                         break;
176         }
177 }
178
179 void OperationNode::set_as_entry()
180 {
181         BLI_assert(owner != NULL);
182         owner->set_entry_operation(this);
183 }
184
185 void OperationNode::set_as_exit()
186 {
187         BLI_assert(owner != NULL);
188         owner->set_exit_operation(this);
189 }
190
191 DEG_DEPSNODE_DEFINE(OperationNode, NodeType::OPERATION, "Operation");
192 static DepsNodeFactoryImpl<OperationNode> DNTI_OPERATION;
193
194 void deg_register_operation_depsnodes()
195 {
196         register_node_typeinfo(&DNTI_OPERATION);
197 }
198
199 }  // namespace DEG