Merge branch 'master' into blender2.8
[blender.git] / source / blender / depsgraph / intern / builder / deg_builder_relations_layer_collection.cc
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: Joshua Leung
22  * Contributor(s): Based on original depsgraph.c code - Blender Foundation (2005-2013)
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 /** \file blender/depsgraph/intern/builder/deg_builder_relations_layer_collection.cc
28  *  \ingroup depsgraph
29  *
30  * Methods for constructing depsgraph
31  */
32
33 #include "intern/builder/deg_builder_relations.h"
34
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <cstring>  /* required for STREQ later on. */
38
39 #include "MEM_guardedalloc.h"
40
41 extern "C" {
42 #include "BLI_blenlib.h"
43 #include "BLI_utildefines.h"
44
45 #include "DNA_node_types.h"
46 #include "DNA_object_types.h"
47 #include "DNA_scene_types.h"
48
49 #include "BKE_layer.h"
50 #include "BKE_main.h"
51 #include "BKE_node.h"
52
53 #include "DEG_depsgraph.h"
54 #include "DEG_depsgraph_build.h"
55 } /* extern "C" */
56
57 #include "intern/builder/deg_builder.h"
58 #include "intern/builder/deg_builder_pchanmap.h"
59
60 #include "intern/nodes/deg_node.h"
61 #include "intern/nodes/deg_node_component.h"
62 #include "intern/nodes/deg_node_operation.h"
63
64 #include "intern/depsgraph_intern.h"
65 #include "intern/depsgraph_types.h"
66
67 #include "util/deg_util_foreach.h"
68
69 namespace DEG {
70
71 void DepsgraphRelationBuilder::build_layer_collection(
72         ID *owner_id,
73         LayerCollection *layer_collection,
74         LayerCollectionState *state)
75 {
76         OperationKey layer_key(owner_id,
77                                DEG_NODE_TYPE_LAYER_COLLECTIONS,
78                                DEG_OPCODE_VIEW_LAYER_EVAL,
79                                layer_collection->scene_collection->name,
80                                state->index);
81         add_relation(state->prev_key, layer_key, "Layer collection order");
82
83         ++state->index;
84         state->prev_key = layer_key;
85
86         /* Recurs into nested layer collections. */
87         build_layer_collections(owner_id, &layer_collection->layer_collections, state);
88 }
89
90 void DepsgraphRelationBuilder::build_layer_collections(
91         ID *owner_id,
92         ListBase *layer_collections,
93         LayerCollectionState *state)
94 {
95         LISTBASE_FOREACH (LayerCollection *, layer_collection, layer_collections) {
96                 /* Recurs into the layer. */
97                 build_layer_collection(owner_id, layer_collection, state);
98         }
99 }
100
101 void DepsgraphRelationBuilder::build_view_layer_collections(
102         ID *owner_id,
103         ViewLayer *view_layer)
104 {
105         LayerCollectionState state;
106         state.index = 0;
107
108         OperationKey init_key(owner_id,
109                               DEG_NODE_TYPE_LAYER_COLLECTIONS,
110                               DEG_OPCODE_VIEW_LAYER_INIT);
111         OperationKey done_key(owner_id,
112                               DEG_NODE_TYPE_LAYER_COLLECTIONS,
113                               DEG_OPCODE_VIEW_LAYER_DONE);
114
115         state.init_key = init_key;
116         state.done_key = done_key;
117         state.prev_key = init_key;
118
119         build_layer_collections(owner_id, &view_layer->layer_collections, &state);
120
121         add_relation(state.prev_key, done_key, "Layer collection order");
122 }
123
124 }  // namespace DEG