2 * ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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.
18 * The Original Code is Copyright (C) 2013 Blender Foundation.
19 * All rights reserved.
21 * Original Author: Joshua Leung
22 * Contributor(s): None Yet
24 * ***** END GPL LICENSE BLOCK *****
27 /** \file blender/depsgraph/intern/depsgraph_query.cc
30 * Implementation of Querying and Filtering API's
33 #include "MEM_guardedalloc.h"
36 #include "BLI_utildefines.h"
37 #include "BKE_idcode.h"
39 #include "BLI_listbase.h"
42 #include "DNA_object_types.h"
43 #include "DNA_scene_types.h"
45 #include "DEG_depsgraph.h"
46 #include "DEG_depsgraph_query.h"
48 #include "intern/depsgraph_intern.h"
49 #include "intern/nodes/deg_node_id.h"
51 bool DEG_id_type_tagged(Main *bmain, short id_type)
53 return bmain->id_tag_update[BKE_idcode_to_index(id_type)] != 0;
56 short DEG_get_eval_flags_for_id(const Depsgraph *graph, ID *id)
59 /* Happens when converting objects to mesh from a python script
60 * after modifying scene graph.
62 * Currently harmless because it's only called for temporary
63 * objects which are out of the DAG anyway.
68 const DEG::Depsgraph *deg_graph = reinterpret_cast<const DEG::Depsgraph *>(graph);
69 const DEG::IDDepsNode *id_node = deg_graph->find_id_node(id);
70 if (id_node == NULL) {
71 /* TODO(sergey): Does it mean we need to check set scene? */
75 return id_node->eval_flags;
78 Scene *DEG_get_evaluated_scene(const Depsgraph *graph)
80 const DEG::Depsgraph *deg_graph = reinterpret_cast<const DEG::Depsgraph *>(graph);
81 Scene *scene_orig = deg_graph->scene;
82 return reinterpret_cast<Scene *>(deg_graph->get_cow_id(&scene_orig->id));
85 ViewLayer *DEG_get_evaluated_view_layer(const Depsgraph *graph)
87 const DEG::Depsgraph *deg_graph = reinterpret_cast<const DEG::Depsgraph *>(graph);
88 Scene *scene_cow = DEG_get_evaluated_scene(graph);
89 ViewLayer *view_layer_orig = deg_graph->view_layer;
90 ViewLayer *view_layer_cow =
91 (ViewLayer *)BLI_findstring(&scene_cow->view_layers,
92 view_layer_orig->name,
93 offsetof(ViewLayer, name));
94 return view_layer_cow;
97 Object *DEG_get_evaluated_object(const Depsgraph *depsgraph, Object *object)
99 return (Object *)DEG_get_evaluated_id(depsgraph, &object->id);
102 ID *DEG_get_evaluated_id(const Depsgraph *depsgraph, ID *id)
104 /* TODO(sergey): This is a duplicate of Depsgraph::get_cow_id(),
105 * but here we never do assert, since we don't know nature of the
106 * incoming ID datablock.
108 const DEG::Depsgraph *deg_graph = (const DEG::Depsgraph *)depsgraph;
109 const DEG::IDDepsNode *id_node = deg_graph->find_id_node(id);
110 if (id_node == NULL) {
113 return id_node->id_cow;