Merge branch 'master' into blender2.8
[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/nodes/deg_node.h"
47 #include "intern/nodes/deg_node_component.h"
48 #include "intern/nodes/deg_node_operation.h"
49
50 struct Base;
51 struct bGPdata;
52 struct CacheFile;
53 struct ListBase;
54 struct GHash;
55 struct ID;
56 struct FCurve;
57 struct Group;
58 struct Key;
59 struct LayerCollection;
60 struct Main;
61 struct Mask;
62 struct Material;
63 struct MTex;
64 struct ModifierData;
65 struct MovieClip;
66 struct bNodeTree;
67 struct Object;
68 struct bPoseChannel;
69 struct bConstraint;
70 struct Scene;
71 struct ViewLayer;
72 struct Tex;
73 struct World;
74 struct EffectorWeights;
75 struct ParticleSystem;
76 struct ParticleSettings;
77
78 struct PropertyRNA;
79
80 namespace DEG {
81
82 struct Depsgraph;
83 struct DepsNode;
84 struct DepsNodeHandle;
85 struct RootDepsNode;
86 struct IDDepsNode;
87 struct TimeSourceDepsNode;
88 struct ComponentDepsNode;
89 struct OperationDepsNode;
90 struct RootPChanMap;
91
92 struct TimeSourceKey
93 {
94         TimeSourceKey();
95         TimeSourceKey(ID *id);
96
97         string identifier() const;
98
99         ID *id;
100 };
101
102 struct ComponentKey
103 {
104         ComponentKey();
105         ComponentKey(ID *id, eDepsNode_Type type, const char *name = "");
106
107         string identifier() const;
108
109         ID *id;
110         eDepsNode_Type type;
111         const char *name;
112 };
113
114 struct OperationKey
115 {
116         OperationKey();
117         OperationKey(ID *id,
118                      eDepsNode_Type component_type,
119                      const char *name,
120                      int name_tag = -1);
121         OperationKey(ID *id,
122                      eDepsNode_Type component_type,
123                      const char *component_name,
124                      const char *name,
125                      int name_tag);
126
127         OperationKey(ID *id,
128                      eDepsNode_Type component_type,
129                      eDepsOperation_Code opcode);
130         OperationKey(ID *id,
131                      eDepsNode_Type component_type,
132                      const char *component_name,
133                      eDepsOperation_Code opcode);
134
135         OperationKey(ID *id,
136                      eDepsNode_Type component_type,
137                      eDepsOperation_Code opcode,
138                      const char *name,
139                      int name_tag = -1);
140         OperationKey(ID *id,
141                      eDepsNode_Type component_type,
142                      const char *component_name,
143                      eDepsOperation_Code opcode,
144                      const char *name,
145                      int name_tag = -1);
146
147         string identifier() const;
148
149         ID *id;
150         eDepsNode_Type component_type;
151         const char *component_name;
152         eDepsOperation_Code opcode;
153         const char *name;
154         int name_tag;
155 };
156
157 struct RNAPathKey
158 {
159         /* NOTE: see depsgraph_build.cpp for implementation */
160         RNAPathKey(ID *id, const char *path);
161
162         RNAPathKey(ID *id, const PointerRNA &ptr, PropertyRNA *prop);
163
164         string identifier() const;
165
166         ID *id;
167         PointerRNA ptr;
168         PropertyRNA *prop;
169 };
170
171 struct DepsgraphRelationBuilder
172 {
173         DepsgraphRelationBuilder(Main *bmain, Depsgraph *graph);
174
175         void begin_build();
176
177         template <typename KeyFrom, typename KeyTo>
178         void add_relation(const KeyFrom& key_from,
179                           const KeyTo& key_to,
180                           const char *description,
181                           bool check_unique = false);
182
183         template <typename KeyTo>
184         void add_relation(const TimeSourceKey& key_from,
185                           const KeyTo& key_to,
186                           const char *description,
187                           bool check_unique = false);
188
189         template <typename KeyType>
190         void add_node_handle_relation(const KeyType& key_from,
191                                       const DepsNodeHandle *handle,
192                                       const char *description,
193                                       bool check_unique = false);
194
195         void build_view_layer(Scene *scene, ViewLayer *view_layer);
196         void build_group(Object *object, Group *group);
197         void build_object(Base *base, Object *object);
198         void build_object_flags(Base *base, Object *object);
199         void build_object_data(Object *object);
200         void build_object_parent(Object *object);
201         void build_constraints(ID *id,
202                                eDepsNode_Type component_type,
203                                const char *component_subdata,
204                                ListBase *constraints,
205                                RootPChanMap *root_map);
206         void build_animdata(ID *id);
207         void build_animdata_curves(ID *id);
208         void build_animdata_curves_targets(ID *id);
209         void build_animdata_drivers(ID *id);
210         void build_driver(ID *id, FCurve *fcurve);
211         void build_driver_data(ID *id, FCurve *fcurve);
212         void build_driver_variables(ID *id, FCurve *fcurve);
213         void build_world(World *world);
214         void build_rigidbody(Scene *scene);
215         void build_particles(Object *object);
216         void build_particle_settings(ParticleSettings *part);
217         void build_cloth(Object *object, ModifierData *md);
218         void build_ik_pose(Object *object,
219                            bPoseChannel *pchan,
220                            bConstraint *con,
221                            RootPChanMap *root_map);
222         void build_splineik_pose(Object *object,
223                                  bPoseChannel *pchan,
224                                  bConstraint *con,
225                                  RootPChanMap *root_map);
226         void build_rig(Object *object);
227         void build_proxy_rig(Object *object);
228         void build_shapekeys(ID *obdata, Key *key);
229         void build_obdata_geom(Object *object);
230         void build_camera(Object *object);
231         void build_lamp(Object *object);
232         void build_nodetree(bNodeTree *ntree);
233         void build_material(Material *ma);
234         void build_texture(Tex *tex);
235         void build_texture_stack(MTex **texture_stack);
236         void build_compositor(Scene *scene);
237         void build_gpencil(bGPdata *gpd);
238         void build_cachefile(CacheFile *cache_file);
239         void build_mask(Mask *mask);
240         void build_movieclip(MovieClip *clip);
241         void build_lightprobe(Object *object);
242
243         void add_collision_relations(const OperationKey &key,
244                                      Scene *scene,
245                                      Object *object,
246                                      Group *group,
247                                      bool dupli,
248                                      const char *name);
249         void add_forcefield_relations(const OperationKey &key,
250                                       Scene *scene,
251                                       Object *object,
252                                       ParticleSystem *psys,
253                                       EffectorWeights *eff,
254                                       bool add_absorption, const char *name);
255
256         struct LayerCollectionState {
257                 int index;
258                 OperationKey init_key;
259                 OperationKey done_key;
260                 OperationKey prev_key;
261         };
262         void build_layer_collection(ID *owner_id,
263                                     LayerCollection *layer_collection,
264                                     LayerCollectionState *state);
265         void build_layer_collections(ID *owner_id,
266                                      ListBase *layer_collections,
267                                      LayerCollectionState *state);
268         void build_view_layer_collections(struct ID *owner_id, ViewLayer *view_layer);
269
270         void build_copy_on_write_relations();
271         void build_copy_on_write_relations(IDDepsNode *id_node);
272
273         template <typename KeyType>
274         OperationDepsNode *find_operation_node(const KeyType &key);
275
276         Depsgraph *getGraph();
277
278 protected:
279         TimeSourceDepsNode *get_node(const TimeSourceKey &key) const;
280         ComponentDepsNode *get_node(const ComponentKey &key) const;
281         OperationDepsNode *get_node(const OperationKey &key) const;
282         DepsNode *get_node(const RNAPathKey &key) const;
283
284         OperationDepsNode *find_node(const OperationKey &key) const;
285         bool has_node(const OperationKey &key) const;
286
287         void add_time_relation(TimeSourceDepsNode *timesrc,
288                                DepsNode *node_to,
289                                const char *description,
290                                bool check_unique = false);
291         void add_operation_relation(OperationDepsNode *node_from,
292                                     OperationDepsNode *node_to,
293                                     const char *description,
294                                     bool check_unique = false);
295
296         template <typename KeyType>
297         DepsNodeHandle create_node_handle(const KeyType& key,
298                                           const char *default_name = "");
299
300         /* TODO(sergey): All those is_same* functions are to be generalized. */
301
302         /* Check whether two keys correponds to the same bone from same armature.
303          *
304          * This is used by drivers relations builder to avoid possible fake
305          * dependency cycle when one bone property drives another property of the
306          * same bone.
307          */
308         template <typename KeyFrom, typename KeyTo>
309         bool is_same_bone_dependency(const KeyFrom& key_from, const KeyTo& key_to);
310
311         /* Similar to above, but used to check whether driver is using node from
312          * the same node tree as a driver variable.
313          */
314         template <typename KeyFrom, typename KeyTo>
315         bool is_same_nodetree_node_dependency(const KeyFrom& key_from,
316                                               const KeyTo& key_to);
317
318         /* Similar to above, but used to check whether driver is using key from
319          * the same key datablock as a driver variable.
320          */
321         template <typename KeyFrom, typename KeyTo>
322         bool is_same_shapekey_dependency(const KeyFrom& key_from,
323                                          const KeyTo& key_to);
324
325 private:
326         /* State which never changes, same for the whole builder time. */
327         Main *bmain_;
328         Depsgraph *graph_;
329
330         /* State which demotes currently built entities. */
331         Scene *scene_;
332 };
333
334 struct DepsNodeHandle
335 {
336         DepsNodeHandle(DepsgraphRelationBuilder *builder,
337                        OperationDepsNode *node,
338                        const char *default_name = "")
339                 : builder(builder),
340                   node(node),
341                   default_name(default_name)
342         {
343                 BLI_assert(node != NULL);
344         }
345
346         DepsgraphRelationBuilder *builder;
347         OperationDepsNode *node;
348         const char *default_name;
349 };
350
351 }  // namespace DEG
352
353
354 #include "intern/builder/deg_builder_relations_impl.h"