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