1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2013 Blender Foundation.
17  * All rights reserved.
18  */
19 
20 /** \file
21  * \ingroup depsgraph
22  *
23  * Methods for constructing depsgraph
24  */
25 
26 #include "intern/builder/deg_builder_relations.h"
27 
28 namespace blender {
29 namespace deg {
30 
31 ////////////////////////////////////////////////////////////////////////////////
32 // Time source.
33 
TimeSourceKey()34 TimeSourceKey::TimeSourceKey() : id(nullptr)
35 {
36 }
37 
TimeSourceKey(ID * id)38 TimeSourceKey::TimeSourceKey(ID *id) : id(id)
39 {
40 }
41 
identifier() const42 string TimeSourceKey::identifier() const
43 {
44   return string("TimeSourceKey");
45 }
46 
47 ////////////////////////////////////////////////////////////////////////////////
48 // Component.
49 
ComponentKey()50 ComponentKey::ComponentKey() : id(nullptr), type(NodeType::UNDEFINED), name("")
51 {
52 }
53 
ComponentKey(ID * id,NodeType type,const char * name)54 ComponentKey::ComponentKey(ID *id, NodeType type, const char *name)
55     : id(id), type(type), name(name)
56 {
57 }
58 
identifier() const59 string ComponentKey::identifier() const
60 {
61   const char *idname = (id) ? id->name : "<None>";
62   string result = string("ComponentKey(");
63   result += idname;
64   result += ", " + string(nodeTypeAsString(type));
65   if (name[0] != '\0') {
66     result += ", '" + string(name) + "'";
67   }
68   result += ')';
69   return result;
70 }
71 
72 ////////////////////////////////////////////////////////////////////////////////
73 // Operation.
74 
OperationKey()75 OperationKey::OperationKey()
76     : id(nullptr),
77       component_type(NodeType::UNDEFINED),
78       component_name(""),
79       opcode(OperationCode::OPERATION),
80       name(""),
81       name_tag(-1)
82 {
83 }
84 
OperationKey(ID * id,NodeType component_type,const char * name,int name_tag)85 OperationKey::OperationKey(ID *id, NodeType component_type, const char *name, int name_tag)
86     : id(id),
87       component_type(component_type),
88       component_name(""),
89       opcode(OperationCode::OPERATION),
90       name(name),
91       name_tag(name_tag)
92 {
93 }
94 
OperationKey(ID * id,NodeType component_type,const char * component_name,const char * name,int name_tag)95 OperationKey::OperationKey(
96     ID *id, NodeType component_type, const char *component_name, const char *name, int name_tag)
97     : id(id),
98       component_type(component_type),
99       component_name(component_name),
100       opcode(OperationCode::OPERATION),
101       name(name),
102       name_tag(name_tag)
103 {
104 }
105 
OperationKey(ID * id,NodeType component_type,OperationCode opcode)106 OperationKey::OperationKey(ID *id, NodeType component_type, OperationCode opcode)
107     : id(id),
108       component_type(component_type),
109       component_name(""),
110       opcode(opcode),
111       name(""),
112       name_tag(-1)
113 {
114 }
115 
OperationKey(ID * id,NodeType component_type,const char * component_name,OperationCode opcode)116 OperationKey::OperationKey(ID *id,
117                            NodeType component_type,
118                            const char *component_name,
119                            OperationCode opcode)
120     : id(id),
121       component_type(component_type),
122       component_name(component_name),
123       opcode(opcode),
124       name(""),
125       name_tag(-1)
126 {
127 }
128 
OperationKey(ID * id,NodeType component_type,OperationCode opcode,const char * name,int name_tag)129 OperationKey::OperationKey(
130     ID *id, NodeType component_type, OperationCode opcode, const char *name, int name_tag)
131     : id(id),
132       component_type(component_type),
133       component_name(""),
134       opcode(opcode),
135       name(name),
136       name_tag(name_tag)
137 {
138 }
139 
OperationKey(ID * id,NodeType component_type,const char * component_name,OperationCode opcode,const char * name,int name_tag)140 OperationKey::OperationKey(ID *id,
141                            NodeType component_type,
142                            const char *component_name,
143                            OperationCode opcode,
144                            const char *name,
145                            int name_tag)
146     : id(id),
147       component_type(component_type),
148       component_name(component_name),
149       opcode(opcode),
150       name(name),
151       name_tag(name_tag)
152 {
153 }
154 
identifier() const155 string OperationKey::identifier() const
156 {
157   string result = string("OperationKey(");
158   result += "type: " + string(nodeTypeAsString(component_type));
159   result += ", component name: '" + string(component_name) + "'";
160   result += ", operation code: " + string(operationCodeAsString(opcode));
161   if (name[0] != '\0') {
162     result += ", '" + string(name) + "'";
163   }
164   result += ")";
165   return result;
166 }
167 
168 ////////////////////////////////////////////////////////////////////////////////
169 // RNA path.
170 
RNAPathKey(ID * id,const char * path,RNAPointerSource source)171 RNAPathKey::RNAPathKey(ID *id, const char *path, RNAPointerSource source) : id(id), source(source)
172 {
173   /* Create ID pointer for root of path lookup. */
174   PointerRNA id_ptr;
175   RNA_id_pointer_create(id, &id_ptr);
176   /* Try to resolve path. */
177   int index;
178   if (!RNA_path_resolve_full(&id_ptr, path, &ptr, &prop, &index)) {
179     ptr = PointerRNA_NULL;
180     prop = nullptr;
181   }
182 }
183 
RNAPathKey(ID * id,const PointerRNA & ptr,PropertyRNA * prop,RNAPointerSource source)184 RNAPathKey::RNAPathKey(ID *id, const PointerRNA &ptr, PropertyRNA *prop, RNAPointerSource source)
185     : id(id), ptr(ptr), prop(prop), source(source)
186 {
187 }
188 
identifier() const189 string RNAPathKey::identifier() const
190 {
191   const char *id_name = (id) ? id->name : "<No ID>";
192   const char *prop_name = (prop) ? RNA_property_identifier(prop) : "<No Prop>";
193   return string("RnaPathKey(") + "id: " + id_name + ", prop: '" + prop_name + "')";
194 }
195 
196 }  // namespace deg
197 }  // namespace blender
198