f86959a1693c27ddeab3e42fb03bf525e8809223
[blender.git] / source / blender / depsgraph / intern / builder / deg_builder_relations_keys.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_keys.cc
28  *  \ingroup depsgraph
29  *
30  * Methods for constructing depsgraph
31  */
32
33 #include "intern/builder/deg_builder_relations.h"
34
35 namespace DEG {
36
37 ////////////////////////////////////////////////////////////////////////////////
38 // Time source.
39
40 TimeSourceKey::TimeSourceKey()
41         : id(NULL)
42 {
43 }
44
45 TimeSourceKey::TimeSourceKey(ID *id)
46         : id(id)
47 {
48 }
49
50 string TimeSourceKey::identifier() const
51 {
52         return string("TimeSourceKey");
53 }
54
55 ////////////////////////////////////////////////////////////////////////////////
56 // Component.
57
58 ComponentKey::ComponentKey()
59         : id(NULL),
60           type(DEG_NODE_TYPE_UNDEFINED),
61           name("")
62 {
63 }
64
65 ComponentKey::ComponentKey(ID *id, eDepsNode_Type type, const char *name)
66         : id(id),
67           type(type),
68           name(name)
69 {
70 }
71
72 string ComponentKey::identifier() const
73 {
74         const char *idname = (id) ? id->name : "<None>";
75         string result = string("ComponentKey(");
76         result += idname;
77         result += ", " + string(nodeTypeAsString(type));
78         if (name[0] != '\0') {
79                 result += ", '" + string(name) + "'";
80         }
81         result += ')';
82         return result;
83 }
84
85 ////////////////////////////////////////////////////////////////////////////////
86 // Operation.
87
88 OperationKey::OperationKey()
89         : id(NULL),
90           component_type(DEG_NODE_TYPE_UNDEFINED),
91           component_name(""),
92           opcode(DEG_OPCODE_OPERATION),
93           name(""),
94           name_tag(-1)
95 {
96 }
97
98 OperationKey::OperationKey(ID *id,
99                            eDepsNode_Type component_type,
100                            const char *name,
101                            int name_tag)
102         : id(id),
103           component_type(component_type),
104           component_name(""),
105           opcode(DEG_OPCODE_OPERATION),
106           name(name),
107           name_tag(name_tag)
108 {
109 }
110
111 OperationKey::OperationKey(ID *id,
112                            eDepsNode_Type component_type,
113                            const char *component_name,
114                            const char *name,
115                            int name_tag)
116         : id(id),
117           component_type(component_type),
118           component_name(component_name),
119           opcode(DEG_OPCODE_OPERATION),
120           name(name),
121           name_tag(name_tag)
122 {
123 }
124
125 OperationKey::OperationKey(ID *id,
126                            eDepsNode_Type component_type,
127                            eDepsOperation_Code opcode)
128         : id(id),
129           component_type(component_type),
130           component_name(""),
131           opcode(opcode),
132           name(""),
133           name_tag(-1)
134 {
135 }
136
137 OperationKey::OperationKey(ID *id,
138                            eDepsNode_Type component_type,
139                            const char *component_name,
140                            eDepsOperation_Code opcode)
141         : id(id),
142           component_type(component_type),
143           component_name(component_name),
144           opcode(opcode),
145           name(""),
146           name_tag(-1)
147 {
148 }
149
150 OperationKey::OperationKey(ID *id,
151                            eDepsNode_Type component_type,
152                            eDepsOperation_Code opcode,
153                            const char *name,
154                            int name_tag)
155         : id(id),
156           component_type(component_type),
157           component_name(""),
158           opcode(opcode),
159           name(name),
160           name_tag(name_tag)
161 {
162 }
163
164 OperationKey::OperationKey(ID *id,
165                            eDepsNode_Type component_type,
166                            const char *component_name,
167                            eDepsOperation_Code opcode,
168                            const char *name,
169                            int name_tag)
170         : id(id),
171           component_type(component_type),
172           component_name(component_name),
173           opcode(opcode),
174           name(name),
175           name_tag(name_tag)
176 {
177 }
178
179 string OperationKey::identifier() const
180 {
181         string result = string("OperationKey(");
182         result += "type: " + string(nodeTypeAsString(component_type));
183         result += ", component name: '" + string(component_name) + "'";
184         result += ", operation code: " + string(operationCodeAsString(opcode));
185         if (name[0] != '\0') {
186                 result += ", '" + string(name) + "'";
187         }
188         result += ")";
189         return result;
190 }
191
192 ////////////////////////////////////////////////////////////////////////////////
193 // RNA path.
194
195 RNAPathKey::RNAPathKey(ID *id, const char *path, RNAPointerSource source)
196         : id(id),
197           source(source)
198 {
199         /* Create ID pointer for root of path lookup. */
200         PointerRNA id_ptr;
201         RNA_id_pointer_create(id, &id_ptr);
202         /* Try to resolve path. */
203         int index;
204         if (!RNA_path_resolve_full(&id_ptr, path, &ptr, &prop, &index)) {
205                 ptr = PointerRNA_NULL;
206                 prop = NULL;
207         }
208 }
209
210 RNAPathKey::RNAPathKey(ID *id,
211                        const PointerRNA &ptr,
212                        PropertyRNA *prop,
213                        RNAPointerSource source)
214         : id(id),
215           ptr(ptr),
216           prop(prop),
217           source(source)
218 {
219 }
220
221 string RNAPathKey::identifier() const
222 {
223         const char *id_name   = (id) ?  id->name : "<No ID>";
224         const char *prop_name = (prop) ? RNA_property_identifier(prop) : "<No Prop>";
225         return string("RnaPathKey(") + "id: " + id_name +
226                                        ", prop: '" + prop_name +  "')";
227 }
228
229 }  // namespace DEG