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 ParticleSystem;
71 struct ParticleSettings;
72 struct Scene;
73 struct ViewLayer;
74 struct Tex;
75 struct World;
76 struct EffectorWeights;
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                                            ComponentKey &adt_key,
210                                            OperationDepsNode *operation_from,
211                                            ListBase *curves);
212         void build_animdata_nlastrip_targets(ID *id,
213                                              ComponentKey &adt_key,
214                                              OperationDepsNode *operation_from,
215                                              ListBase *strips);
216         void build_animdata_drivers(ID *id);
217         void build_driver(ID *id, FCurve *fcurve);
218         void build_driver_data(ID *id, FCurve *fcurve);
219         void build_driver_variables(ID *id, FCurve *fcurve);
220         void build_world(World *world);
221         void build_rigidbody(Scene *scene);
222         void build_particles(Object *object);
223         void build_particle_settings(ParticleSettings *part);
224         void build_particles_visualization_object(Object *object,
225                                                   ParticleSystem *psys,
226                                                   Object *draw_object);
227         void build_cloth(Object *object, ModifierData *md);
228         void build_ik_pose(Object *object,
229                            bPoseChannel *pchan,
230                            bConstraint *con,
231                            RootPChanMap *root_map);
232         void build_splineik_pose(Object *object,
233                                  bPoseChannel *pchan,
234                                  bConstraint *con,
235                                  RootPChanMap *root_map);
236         void build_rig(Object *object);
237         void build_proxy_rig(Object *object);
238         void build_shapekeys(ID *obdata, Key *key);
239         void build_obdata_geom(Object *object);
240         void build_camera(Object *object);
241         void build_lamp(Object *object);
242         void build_nodetree(bNodeTree *ntree);
243         void build_material(Material *ma);
244         void build_texture(Tex *tex);
245         void build_texture_stack(MTex **texture_stack);
246         void build_compositor(Scene *scene);
247         void build_gpencil(bGPdata *gpd);
248         void build_cachefile(CacheFile *cache_file);
249         void build_mask(Mask *mask);
250         void build_movieclip(MovieClip *clip);
251         void build_lightprobe(Object *object);
252
253         void add_collision_relations(const OperationKey &key,
254                                      Scene *scene,
255                                      Object *object,
256                                      Group *group,
257                                      bool dupli,
258                                      const char *name);
259         void add_forcefield_relations(const OperationKey &key,
260                                       Scene *scene,
261                                       Object *object,
262                                       ParticleSystem *psys,
263                                       EffectorWeights *eff,
264                                       bool add_absorption, const char *name);
265
266         struct LayerCollectionState {
267                 int index;
268                 OperationKey init_key;
269                 OperationKey done_key;
270                 OperationKey prev_key;
271         };
272         void build_layer_collection(ID *owner_id,
273                                     LayerCollection *layer_collection,
274                                     LayerCollectionState *state);
275         void build_layer_collections(ID *owner_id,
276                                      ListBase *layer_collections,
277                                      LayerCollectionState *state);
278         void build_view_layer_collections(struct ID *owner_id, ViewLayer *view_layer);
279
280         void build_copy_on_write_relations();
281         void build_copy_on_write_relations(IDDepsNode *id_node);
282
283         template <typename KeyType>
284         OperationDepsNode *find_operation_node(const KeyType &key);
285
286         Depsgraph *getGraph();
287
288 protected:
289         TimeSourceDepsNode *get_node(const TimeSourceKey &key) const;
290         ComponentDepsNode *get_node(const ComponentKey &key) const;
291         OperationDepsNode *get_node(const OperationKey &key) const;
292         DepsNode *get_node(const RNAPathKey &key) const;
293
294         OperationDepsNode *find_node(const OperationKey &key) const;
295         bool has_node(const OperationKey &key) const;
296
297         void add_time_relation(TimeSourceDepsNode *timesrc,
298                                DepsNode *node_to,
299                                const char *description,
300                                bool check_unique = false);
301         void add_operation_relation(OperationDepsNode *node_from,
302                                     OperationDepsNode *node_to,
303                                     const char *description,
304                                     bool check_unique = false);
305
306         template <typename KeyType>
307         DepsNodeHandle create_node_handle(const KeyType& key,
308                                           const char *default_name = "");
309
310         /* TODO(sergey): All those is_same* functions are to be generalized. */
311
312         /* Check whether two keys correponds to the same bone from same armature.
313          *
314          * This is used by drivers relations builder to avoid possible fake
315          * dependency cycle when one bone property drives another property of the
316          * same bone.
317          */
318         template <typename KeyFrom, typename KeyTo>
319         bool is_same_bone_dependency(const KeyFrom& key_from, const KeyTo& key_to);
320
321         /* Similar to above, but used to check whether driver is using node from
322          * the same node tree as a driver variable.
323          */
324         template <typename KeyFrom, typename KeyTo>
325         bool is_same_nodetree_node_dependency(const KeyFrom& key_from,
326                                               const KeyTo& key_to);
327
328         /* Similar to above, but used to check whether driver is using key from
329          * the same key datablock as a driver variable.
330          */
331         template <typename KeyFrom, typename KeyTo>
332         bool is_same_shapekey_dependency(const KeyFrom& key_from,
333                                          const KeyTo& key_to);
334
335 private:
336         /* State which never changes, same for the whole builder time. */
337         Main *bmain_;
338         Depsgraph *graph_;
339
340         /* State which demotes currently built entities. */
341         Scene *scene_;
342 };
343
344 struct DepsNodeHandle
345 {
346         DepsNodeHandle(DepsgraphRelationBuilder *builder,
347                        OperationDepsNode *node,
348                        const char *default_name = "")
349                 : builder(builder),
350                   node(node),
351                   default_name(default_name)
352         {
353                 BLI_assert(node != NULL);
354         }
355
356         DepsgraphRelationBuilder *builder;
357         OperationDepsNode *node;
358         const char *default_name;
359 };
360
361 }  // namespace DEG
362
363
364 #include "intern/builder/deg_builder_relations_impl.h"