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