Set face-map to active when selecting
[blender.git] / source / blender / depsgraph / intern / depsgraph_type_defines.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): None Yet
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 /** \file blender/depsgraph/intern/depsgraph_type_defines.cc
28  *  \ingroup depsgraph
29  *
30  * Defines and code for core node types.
31  */
32
33 #include <cstdlib>  // for BLI_assert()
34
35
36 #include "BLI_utildefines.h"
37 #include "BLI_ghash.h"
38
39 #include "DEG_depsgraph.h"
40
41 #include "intern/nodes/deg_node.h"
42 #include "intern/nodes/deg_node_component.h"
43 #include "intern/nodes/deg_node_operation.h"
44
45 #include "intern/depsgraph_intern.h"
46
47 namespace DEG {
48
49 /* ************ */
50 /* External API */
51
52 /* Global type registry */
53
54 /**
55  * \note For now, this is a hashtable not array, since the core node types
56  * currently do not have contiguous ID values. Using a hash here gives us
57  * more flexibility, albeit using more memory and also sacrificing a little
58  * speed. Later on, when things stabilise we may turn this back to an array
59  * since there are only just a few node types that an array would cope fine...
60  */
61 static GHash *_depsnode_typeinfo_registry = NULL;
62
63 /* Registration ------------------------------------------- */
64
65 /* Register node type */
66 void deg_register_node_typeinfo(DepsNodeFactory *factory)
67 {
68         BLI_assert(factory != NULL);
69         BLI_ghash_insert(_depsnode_typeinfo_registry,
70                          SET_INT_IN_POINTER(factory->type()),
71                          factory);
72 }
73
74 /* Getters ------------------------------------------------- */
75
76 /* Get typeinfo for specified type */
77 DepsNodeFactory *deg_get_node_factory(const eDepsNode_Type type)
78 {
79         /* look up type - at worst, it doesn't exist in table yet, and we fail */
80         return (DepsNodeFactory *)BLI_ghash_lookup(_depsnode_typeinfo_registry,
81                                                    SET_INT_IN_POINTER(type));
82 }
83
84 /* Get typeinfo for provided node */
85 DepsNodeFactory *deg_node_get_factory(const DepsNode *node)
86 {
87         if (node != NULL) {
88                 return NULL;
89         }
90         return deg_get_node_factory(node->type);
91 }
92
93 /* Stringified opcodes ------------------------------------- */
94
95 DepsOperationStringifier DEG_OPNAMES;
96
97 static const char *stringify_opcode(eDepsOperation_Code opcode)
98 {
99         switch (opcode) {
100 #define STRINGIFY_OPCODE(name) case DEG_OPCODE_##name: return #name
101                 /* Generic Operations. */
102                 STRINGIFY_OPCODE(OPERATION);
103                 STRINGIFY_OPCODE(PARAMETERS_EVAL);
104                 STRINGIFY_OPCODE(PLACEHOLDER);
105                 /* Animation, Drivers, etc. */
106                 STRINGIFY_OPCODE(ANIMATION);
107                 STRINGIFY_OPCODE(DRIVER);
108                 /* Transform. */
109                 STRINGIFY_OPCODE(TRANSFORM_LOCAL);
110                 STRINGIFY_OPCODE(TRANSFORM_PARENT);
111                 STRINGIFY_OPCODE(TRANSFORM_CONSTRAINTS);
112                 STRINGIFY_OPCODE(TRANSFORM_FINAL);
113                 STRINGIFY_OPCODE(TRANSFORM_OBJECT_UBEREVAL);
114                 /* Rigid body. */
115                 STRINGIFY_OPCODE(RIGIDBODY_REBUILD);
116                 STRINGIFY_OPCODE(RIGIDBODY_SIM);
117                 STRINGIFY_OPCODE(RIGIDBODY_TRANSFORM_COPY);
118                 /* Geometry. */
119                 STRINGIFY_OPCODE(GEOMETRY_UBEREVAL);
120                 STRINGIFY_OPCODE(GEOMETRY_PATH);
121                 /* Pose. */
122                 STRINGIFY_OPCODE(POSE_INIT);
123                 STRINGIFY_OPCODE(POSE_DONE);
124                 STRINGIFY_OPCODE(POSE_IK_SOLVER);
125                 STRINGIFY_OPCODE(POSE_SPLINE_IK_SOLVER);
126                 /* Bone. */
127                 STRINGIFY_OPCODE(BONE_LOCAL);
128                 STRINGIFY_OPCODE(BONE_POSE_PARENT);
129                 STRINGIFY_OPCODE(BONE_CONSTRAINTS);
130                 STRINGIFY_OPCODE(BONE_READY);
131                 STRINGIFY_OPCODE(BONE_DONE);
132                 /* Particles. */
133                 STRINGIFY_OPCODE(PARTICLE_SYSTEM_EVAL);
134                 STRINGIFY_OPCODE(PARTICLE_SETTINGS_EVAL);
135                 STRINGIFY_OPCODE(PARTICLE_SETTINGS_RECALC_CLEAR);
136                 /* Collections. */
137                 STRINGIFY_OPCODE(SCENE_LAYER_INIT);
138                 STRINGIFY_OPCODE(SCENE_LAYER_EVAL);
139                 STRINGIFY_OPCODE(SCENE_LAYER_DONE);
140                 /* Copy on write. */
141                 STRINGIFY_OPCODE(COPY_ON_WRITE);
142                 /* Shading. */
143                 STRINGIFY_OPCODE(SHADING);
144                 STRINGIFY_OPCODE(MATERIAL_UPDATE);
145                 STRINGIFY_OPCODE(WORLD_UPDATE);
146
147                 case DEG_NUM_OPCODES: return "SpecialCase";
148 #undef STRINGIFY_OPCODE
149         }
150         return "UNKNOWN";
151 }
152
153 DepsOperationStringifier::DepsOperationStringifier()
154 {
155         for (int i = 0; i < DEG_NUM_OPCODES; ++i) {
156                 names_[i] = stringify_opcode((eDepsOperation_Code)i);
157         }
158 }
159
160 const char *DepsOperationStringifier::operator[](eDepsOperation_Code opcode)
161 {
162         BLI_assert((opcode >= 0) && (opcode < DEG_NUM_OPCODES));
163         if (opcode >= 0 && opcode < DEG_NUM_OPCODES) {
164                 return names_[opcode];
165         }
166         return "UnknownOpcode";
167 }
168
169 }  // namespace DEG
170
171 /* Register all node types */
172 void DEG_register_node_types(void)
173 {
174         /* initialise registry */
175         DEG::_depsnode_typeinfo_registry = BLI_ghash_int_new("Depsgraph Node Type Registry");
176
177         /* register node types */
178         DEG::deg_register_base_depsnodes();
179         DEG::deg_register_component_depsnodes();
180         DEG::deg_register_operation_depsnodes();
181 }
182
183 /* Free registry on exit */
184 void DEG_free_node_types(void)
185 {
186         BLI_ghash_free(DEG::_depsnode_typeinfo_registry, NULL, NULL);
187 }