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