9558a726402c0bb953436302dc6340d596d35b99
[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 Scene;
70 struct Tex;
71 struct World;
72 struct EffectorWeights;
73 struct ParticleSystem;
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         void build_animdata_drivers(ID *id);
206         void build_driver(ID *id, FCurve *fcurve);
207         void build_driver_data(ID *id, FCurve *fcurve);
208         void build_driver_variables(ID *id, FCurve *fcurve);
209         void build_world(World *world);
210         void build_rigidbody(Scene *scene);
211         void build_particles(Object *object);
212         void build_cloth(Object *object, ModifierData *md);
213         void build_ik_pose(Object *object,
214                            bPoseChannel *pchan,
215                            bConstraint *con,
216                            RootPChanMap *root_map);
217         void build_splineik_pose(Object *object,
218                                  bPoseChannel *pchan,
219                                  bConstraint *con,
220                                  RootPChanMap *root_map);
221         void build_rig(Object *object);
222         void build_proxy_rig(Object *object);
223         void build_shapekeys(ID *obdata, Key *key);
224         void build_obdata_geom(Object *object);
225         void build_camera(Object *object);
226         void build_lamp(Object *object);
227         void build_nodetree(bNodeTree *ntree);
228         void build_material(Material *ma);
229         void build_texture(Tex *tex);
230         void build_texture_stack(MTex **texture_stack);
231         void build_compositor(Scene *scene);
232         void build_gpencil(bGPdata *gpd);
233         void build_cachefile(CacheFile *cache_file);
234         void build_mask(Mask *mask);
235         void build_movieclip(MovieClip *clip);
236
237         void add_collision_relations(const OperationKey &key,
238                                      Scene *scene,
239                                      Object *object,
240                                      Group *group,
241                                      int layer,
242                                      bool dupli,
243                                      const char *name);
244         void add_forcefield_relations(const OperationKey &key,
245                                       Scene *scene,
246                                       Object *object,
247                                       ParticleSystem *psys,
248                                       EffectorWeights *eff,
249                                       bool add_absorption,
250                                       const char *name);
251
252         template <typename KeyType>
253         OperationDepsNode *find_operation_node(const KeyType &key);
254
255         Depsgraph *getGraph();
256
257 protected:
258         TimeSourceDepsNode *get_node(const TimeSourceKey &key) const;
259         ComponentDepsNode *get_node(const ComponentKey &key) const;
260         OperationDepsNode *get_node(const OperationKey &key) const;
261         DepsNode *get_node(const RNAPathKey &key) const;
262
263         OperationDepsNode *find_node(const OperationKey &key) const;
264         bool has_node(const OperationKey &key) const;
265
266         void add_time_relation(TimeSourceDepsNode *timesrc,
267                                DepsNode *node_to,
268                                const char *description,
269                                bool check_unique = false);
270         void add_operation_relation(OperationDepsNode *node_from,
271                                     OperationDepsNode *node_to,
272                                     const char *description,
273                                     bool check_unique = false);
274
275         template <typename KeyType>
276         DepsNodeHandle create_node_handle(const KeyType& key,
277                                           const char *default_name = "");
278
279         template <typename KeyFrom, typename KeyTo>
280         bool is_same_bone_dependency(const KeyFrom& key_from, const KeyTo& key_to);
281
282 private:
283         /* State which never changes, same for the whole builder time. */
284         Main *bmain_;
285         Depsgraph *graph_;
286
287         /* State which demotes currently built entities. */
288         Scene *scene_;
289 };
290
291 struct DepsNodeHandle
292 {
293         DepsNodeHandle(DepsgraphRelationBuilder *builder,
294                        OperationDepsNode *node,
295                        const char *default_name = "")
296                 : builder(builder),
297                   node(node),
298                   default_name(default_name)
299         {
300                 BLI_assert(node != NULL);
301         }
302
303         DepsgraphRelationBuilder *builder;
304         OperationDepsNode *node;
305         const char *default_name;
306 };
307
308 }  // namespace DEG
309
310
311 #include "intern/builder/deg_builder_relations_impl.h"