aafd351cbc581cce1221f4bc2f9e02287b4aaadd
[blender.git] / source / blender / depsgraph / intern / builder / deg_builder_relations.h
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2013 Blender Foundation.
19  * All rights reserved.
20  *
21  * Original Author: Lukas Toenne
22  * Contributor(s): None Yet
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 /** \file blender/depsgraph/intern/builder/deg_builder_relations.h
28  *  \ingroup depsgraph
29  */
30
31 #pragma once
32
33 #include <cstdio>
34 #include <cstring>
35
36 #include "intern/depsgraph_types.h"
37
38 #include "DNA_ID.h"
39
40 #include "RNA_access.h"
41 #include "RNA_types.h"
42
43 #include "BLI_utildefines.h"
44 #include "BLI_string.h"
45
46 #include "intern/builder/deg_builder_map.h"
47 #include "intern/depsgraph.h"
48 #include "intern/nodes/deg_node.h"
49 #include "intern/nodes/deg_node_component.h"
50 #include "intern/nodes/deg_node_operation.h"
51
52 struct Base;
53 struct CacheFile;
54 struct Camera;
55 struct Collection;
56 struct EffectorWeights;
57 struct FCurve;
58 struct GHash;
59 struct ID;
60 struct Key;
61 struct Lamp;
62 struct LayerCollection;
63 struct LightProbe;
64 struct ListBase;
65 struct MTex;
66 struct Main;
67 struct Mask;
68 struct Material;
69 struct ModifierData;
70 struct MovieClip;
71 struct Object;
72 struct ParticleSettings;
73 struct ParticleSystem;
74 struct Scene;
75 struct Speaker;
76 struct Tex;
77 struct ViewLayer;
78 struct World;
79 struct bAction;
80 struct bArmature;
81 struct bConstraint;
82 struct bGPdata;
83 struct bNodeTree;
84 struct bPoseChannel;
85
86 struct PropertyRNA;
87
88 namespace DEG {
89
90 struct ComponentDepsNode;
91 struct DepsNode;
92 struct DepsNodeHandle;
93 struct DepsRelation;
94 struct Depsgraph;
95 struct IDDepsNode;
96 struct OperationDepsNode;
97 struct RootPChanMap;
98 struct TimeSourceDepsNode;
99
100 struct TimeSourceKey
101 {
102         TimeSourceKey();
103         TimeSourceKey(ID *id);
104
105         string identifier() const;
106
107         ID *id;
108 };
109
110 struct ComponentKey
111 {
112         ComponentKey();
113         ComponentKey(ID *id, eDepsNode_Type type, const char *name = "");
114
115         string identifier() const;
116
117         ID *id;
118         eDepsNode_Type type;
119         const char *name;
120 };
121
122 struct OperationKey
123 {
124         OperationKey();
125         OperationKey(ID *id,
126                      eDepsNode_Type component_type,
127                      const char *name,
128                      int name_tag = -1);
129         OperationKey(ID *id,
130                      eDepsNode_Type component_type,
131                      const char *component_name,
132                      const char *name,
133                      int name_tag);
134
135         OperationKey(ID *id,
136                      eDepsNode_Type component_type,
137                      eDepsOperation_Code opcode);
138         OperationKey(ID *id,
139                      eDepsNode_Type component_type,
140                      const char *component_name,
141                      eDepsOperation_Code opcode);
142
143         OperationKey(ID *id,
144                      eDepsNode_Type component_type,
145                      eDepsOperation_Code opcode,
146                      const char *name,
147                      int name_tag = -1);
148         OperationKey(ID *id,
149                      eDepsNode_Type component_type,
150                      const char *component_name,
151                      eDepsOperation_Code opcode,
152                      const char *name,
153                      int name_tag = -1);
154
155         string identifier() const;
156
157         ID *id;
158         eDepsNode_Type component_type;
159         const char *component_name;
160         eDepsOperation_Code opcode;
161         const char *name;
162         int name_tag;
163 };
164
165 struct RNAPathKey
166 {
167         RNAPathKey(ID *id, const char *path, RNAPointerSource source);
168         RNAPathKey(ID *id,
169                    const PointerRNA &ptr,
170                    PropertyRNA *prop,
171                    RNAPointerSource source);
172
173         string identifier() const;
174
175         ID *id;
176         PointerRNA ptr;
177         PropertyRNA *prop;
178         RNAPointerSource source;
179 };
180
181 struct DepsgraphRelationBuilder
182 {
183         DepsgraphRelationBuilder(Main *bmain, Depsgraph *graph);
184
185         void begin_build();
186
187         template <typename KeyFrom, typename KeyTo>
188         DepsRelation *add_relation(const KeyFrom& key_from,
189                                    const KeyTo& key_to,
190                                    const char *description,
191                                    bool check_unique = false,
192                                    int flags = 0);
193
194         template <typename KeyFrom, typename KeyTo>
195         DepsRelation *add_relation(const KeyFrom& key_from,
196                                    const KeyTo& key_to,
197                                    const char *description,
198                                    eDepsRelation_Flag flag);
199
200         template <typename KeyTo>
201         DepsRelation *add_relation(const TimeSourceKey& key_from,
202                                    const KeyTo& key_to,
203                                    const char *description,
204                                    bool check_unique = false,
205                                    int flags = 0);
206
207         template <typename KeyType>
208         DepsRelation *add_node_handle_relation(const KeyType& key_from,
209                                                const DepsNodeHandle *handle,
210                                                const char *description,
211                                                bool check_unique = false,
212                                                int flags = 0);
213
214         void add_customdata_mask(Object *object, uint64_t mask);
215         void add_special_eval_flag(ID *object, uint32_t flag);
216
217         void build_id(ID *id);
218         void build_layer_collections(ListBase *lb);
219         void build_view_layer(Scene *scene, ViewLayer *view_layer);
220         void build_collection(LayerCollection *from_layer_collection,
221                               Object *object,
222                               Collection *collection);
223         void build_object(Base *base, Object *object);
224         void build_object_flags(Base *base, Object *object);
225         void build_object_data(Object *object);
226         void build_object_data_camera(Object *object);
227         void build_object_data_geometry(Object *object);
228         void build_object_data_geometry_datablock(ID *obdata);
229         void build_object_data_lamp(Object *object);
230         void build_object_data_lightprobe(Object *object);
231         void build_object_data_speaker(Object *object);
232         void build_object_parent(Object *object);
233         void build_object_pointcache(Object *object);
234         void build_constraints(ID *id,
235                                eDepsNode_Type component_type,
236                                const char *component_subdata,
237                                ListBase *constraints,
238                                RootPChanMap *root_map);
239         void build_animdata(ID *id);
240         void build_animdata_curves(ID *id);
241         void build_animdata_curves_targets(ID *id,
242                                            ComponentKey &adt_key,
243                                            OperationDepsNode *operation_from,
244                                            ListBase *curves);
245         void build_animdata_nlastrip_targets(ID *id,
246                                              ComponentKey &adt_key,
247                                              OperationDepsNode *operation_from,
248                                              ListBase *strips);
249         void build_animdata_drivers(ID *id);
250         void build_action(bAction *action);
251         void build_driver(ID *id, FCurve *fcurve);
252         void build_driver_data(ID *id, FCurve *fcurve);
253         void build_driver_variables(ID *id, FCurve *fcurve);
254         void build_world(World *world);
255         void build_rigidbody(Scene *scene);
256         void build_particle_systems(Object *object);
257         void build_particle_settings(ParticleSettings *part);
258         void build_particle_system_visualization_object(Object *object,
259                                                         ParticleSystem *psys,
260                                                         Object *draw_object);
261         void build_ik_pose(Object *object,
262                            bPoseChannel *pchan,
263                            bConstraint *con,
264                            RootPChanMap *root_map);
265         void build_splineik_pose(Object *object,
266                                  bPoseChannel *pchan,
267                                  bConstraint *con,
268                                  RootPChanMap *root_map);
269         void build_rig(Object *object);
270         void build_proxy_rig(Object *object);
271         void build_shapekeys(Key *key);
272         void build_armature(bArmature *armature);
273         void build_camera(Camera *camera);
274         void build_lamp(Lamp *lamp);
275         void build_nodetree(bNodeTree *ntree);
276         void build_material(Material *ma);
277         void build_texture(Tex *tex);
278         void build_compositor(Scene *scene);
279         void build_gpencil(bGPdata *gpd);
280         void build_cachefile(CacheFile *cache_file);
281         void build_mask(Mask *mask);
282         void build_movieclip(MovieClip *clip);
283         void build_lightprobe(LightProbe *probe);
284         void build_speaker(Speaker *speaker);
285
286         void build_nested_datablock(ID *owner, ID *id);
287         void build_nested_nodetree(ID *owner, bNodeTree *ntree);
288         void build_nested_shapekey(ID *owner, Key *key);
289
290         void add_particle_collision_relations(const OperationKey &key,
291                                               Object *object,
292                                               Collection *collection,
293                                               const char *name);
294         void add_particle_forcefield_relations(const OperationKey &key,
295                                                Object *object,
296                                                ParticleSystem *psys,
297                                                EffectorWeights *eff,
298                                                bool add_absorption, const char *name);
299
300         void build_copy_on_write_relations();
301         void build_copy_on_write_relations(IDDepsNode *id_node);
302
303         template <typename KeyType>
304         OperationDepsNode *find_operation_node(const KeyType &key);
305
306         Depsgraph *getGraph();
307
308 protected:
309         TimeSourceDepsNode *get_node(const TimeSourceKey &key) const;
310         ComponentDepsNode *get_node(const ComponentKey &key) const;
311         OperationDepsNode *get_node(const OperationKey &key) const;
312         DepsNode *get_node(const RNAPathKey &key) const;
313
314         OperationDepsNode *find_node(const OperationKey &key) const;
315         bool has_node(const OperationKey &key) const;
316
317         DepsRelation *add_time_relation(TimeSourceDepsNode *timesrc,
318                                         DepsNode *node_to,
319                                         const char *description,
320                                         bool check_unique = false,
321                                         int flags = 0);
322         DepsRelation *add_operation_relation(OperationDepsNode *node_from,
323                                              OperationDepsNode *node_to,
324                                              const char *description,
325                                              bool check_unique = false,
326                                              int flags = 0);
327
328         template <typename KeyType>
329         DepsNodeHandle create_node_handle(const KeyType& key,
330                                           const char *default_name = "");
331
332         /* TODO(sergey): All those is_same* functions are to be generalized. */
333
334         /* Check whether two keys corresponds to the same bone from same armature.
335          *
336          * This is used by drivers relations builder to avoid possible fake
337          * dependency cycle when one bone property drives another property of the
338          * same bone.
339          */
340         template <typename KeyFrom, typename KeyTo>
341         bool is_same_bone_dependency(const KeyFrom& key_from, const KeyTo& key_to);
342
343         /* Similar to above, but used to check whether driver is using node from
344          * the same node tree as a driver variable.
345          */
346         template <typename KeyFrom, typename KeyTo>
347         bool is_same_nodetree_node_dependency(const KeyFrom& key_from,
348                                               const KeyTo& key_to);
349
350 private:
351         struct BuilderWalkUserData {
352                 DepsgraphRelationBuilder *builder;
353         };
354
355         static void modifier_walk(void *user_data,
356                                   struct Object *object,
357                                   struct ID **idpoin,
358                                   int cb_flag);
359
360         static void constraint_walk(bConstraint *con,
361                                     ID **idpoin,
362                                     bool is_reference,
363                                     void *user_data);
364
365         /* State which never changes, same for the whole builder time. */
366         Main *bmain_;
367         Depsgraph *graph_;
368
369         /* State which demotes currently built entities. */
370         Scene *scene_;
371
372         BuilderMap built_map_;
373 };
374
375 struct DepsNodeHandle
376 {
377         DepsNodeHandle(DepsgraphRelationBuilder *builder,
378                        OperationDepsNode *node,
379                        const char *default_name = "")
380                 : builder(builder),
381                   node(node),
382                   default_name(default_name)
383         {
384                 BLI_assert(node != NULL);
385         }
386
387         DepsgraphRelationBuilder *builder;
388         OperationDepsNode *node;
389         const char *default_name;
390 };
391
392 }  // namespace DEG
393
394
395 #include "intern/builder/deg_builder_relations_impl.h"