Blender  V2.93
spreadsheet_context.cc
Go to the documentation of this file.
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 
17 #include "MEM_guardedalloc.h"
18 
19 #include "BLI_hash.h"
20 #include "BLI_hash.hh"
21 #include "BLI_hash_mm2a.h"
22 #include "BLI_listbase.h"
23 #include "BLI_string.h"
24 #include "BLI_utildefines.h"
25 #include "BLI_vector.hh"
26 
27 #include "ED_spreadsheet.h"
28 
29 #include "DEG_depsgraph.h"
30 
31 #include "BKE_main.h"
32 #include "BKE_modifier.h"
33 #include "BKE_object.h"
34 
35 #include "spreadsheet_context.hh"
36 
37 namespace blender::ed::spreadsheet {
38 
40 {
42  sizeof(SpreadsheetContextObject), __func__);
44  return context;
45 }
46 
48  const SpreadsheetContextObject *src_context)
49 {
51  new_context->object = src_context->object;
52  return new_context;
53 }
54 
56  BLI_HashMurmur2A *mm2)
57 {
58  BLI_hash_mm2a_add(mm2, (const uchar *)&context->object, sizeof(Object *));
59 }
60 
62 {
64 }
65 
67 {
69  sizeof(SpreadsheetContextModifier), __func__);
71  return context;
72 }
73 
75  const SpreadsheetContextModifier *src_context)
76 {
78  if (src_context->modifier_name) {
79  new_context->modifier_name = BLI_strdup(src_context->modifier_name);
80  }
81  return new_context;
82 }
83 
85  BLI_HashMurmur2A *mm2)
86 {
87  if (context->modifier_name) {
88  BLI_hash_mm2a_add(mm2, (const uchar *)context->modifier_name, strlen(context->modifier_name));
89  }
90 }
91 
93 {
94  if (context->modifier_name) {
95  MEM_freeN(context->modifier_name);
96  }
98 }
99 
101 {
103  sizeof(SpreadsheetContextNode), __func__);
104  context->base.type = SPREADSHEET_CONTEXT_NODE;
105  return context;
106 }
107 
109  const SpreadsheetContextNode *src_context)
110 {
112  if (src_context->node_name) {
113  new_context->node_name = BLI_strdup(src_context->node_name);
114  }
115  return new_context;
116 }
117 
119  BLI_HashMurmur2A *mm2)
120 {
121  if (context->node_name) {
122  BLI_hash_mm2a_add(mm2, (const uchar *)context->node_name, strlen(context->node_name));
123  }
124 }
125 
127 {
128  if (context->node_name) {
129  MEM_freeN(context->node_name);
130  }
132 }
133 
135 {
136  switch (type) {
139  }
142  }
145  }
146  }
148  return nullptr;
149 }
150 
152 {
153  switch (old_context->type) {
156  (const SpreadsheetContextObject *)old_context);
157  }
160  (const SpreadsheetContextModifier *)old_context);
161  }
164  (const SpreadsheetContextNode *)old_context);
165  }
166  }
168  return nullptr;
169 }
170 
172 {
173  BLI_hash_mm2a_add_int(mm2, context->type);
174  switch (context->type) {
177  break;
178  }
181  break;
182  }
185  break;
186  }
187  }
188 }
189 
191 {
192  switch (context->type) {
195  }
198  }
201  }
202  }
204 }
205 
211 {
212  using namespace blender;
213  Vector<const SpreadsheetContext *> context_path = sspreadsheet->context_path;
214  if (context_path.is_empty()) {
215  return;
216  }
217  if (context_path[0]->type != SPREADSHEET_CONTEXT_OBJECT) {
218  return;
219  }
220  SpreadsheetContextObject *object_context = (SpreadsheetContextObject *)context_path[0];
221  Object *object = object_context->object;
222  if (object == nullptr) {
223  return;
224  }
225  if (context_path.size() == 1) {
226  /* No need to reevaluate, when the final or original object is viewed. */
227  return;
228  }
229 
231 }
232 
233 } // namespace blender::ed::spreadsheet
234 
236 {
238 }
239 
241 {
243 }
244 
246 {
249  }
250  BLI_listbase_clear(&sspreadsheet->context_path);
251 }
252 
254 {
256 }
257 
259 {
260  BLI_HashMurmur2A mm2;
261  BLI_hash_mm2a_init(&mm2, 1234);
264  }
265  return BLI_hash_mm2a_end(&mm2);
266 }
267 
269  struct SpaceNode *snode,
270  struct bNode *node)
271 {
272  using namespace blender::ed::spreadsheet;
273  ED_spreadsheet_context_path_clear(sspreadsheet);
274 
275  Object *object = (Object *)snode->id;
276  ModifierData *modifier = BKE_object_active_modifier(object);
277 
278  {
280  context->object = object;
281  BLI_addtail(&sspreadsheet->context_path, context);
282  }
283  {
285  context->modifier_name = BLI_strdup(modifier->name);
286  BLI_addtail(&sspreadsheet->context_path, context);
287  }
288  {
289  int i;
290  LISTBASE_FOREACH_INDEX (bNodeTreePath *, path, &snode->treepath, i) {
291  if (i == 0) {
292  continue;
293  }
295  context->node_name = BLI_strdup(path->node_name);
296  BLI_addtail(&sspreadsheet->context_path, context);
297  }
298  }
299  {
301  context->node_name = BLI_strdup(node->name);
302  BLI_addtail(&sspreadsheet->context_path, context);
303  }
304 
306 }
General operations, lookup, etc. for blender objects.
struct ModifierData * BKE_object_active_modifier(const struct Object *ob)
#define BLI_assert_unreachable()
Definition: BLI_assert.h:96
void BLI_hash_mm2a_init(BLI_HashMurmur2A *mm2, uint32_t seed)
Definition: hash_mm2a.c:75
void BLI_hash_mm2a_add(BLI_HashMurmur2A *mm2, const unsigned char *data, size_t len)
Definition: hash_mm2a.c:83
void BLI_hash_mm2a_add_int(BLI_HashMurmur2A *mm2, int data)
Definition: hash_mm2a.c:98
uint32_t BLI_hash_mm2a_end(BLI_HashMurmur2A *mm2)
Definition: hash_mm2a.c:103
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:172
#define LISTBASE_FOREACH_MUTABLE(type, var, list)
Definition: BLI_listbase.h:188
BLI_INLINE void BLI_listbase_clear(struct ListBase *lb)
Definition: BLI_listbase.h:128
#define LISTBASE_FOREACH_INDEX(type, var, list, index_var)
Definition: BLI_listbase.h:180
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:110
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL() ATTR_MALLOC
Definition: string.c:70
unsigned char uchar
Definition: BLI_sys_types.h:86
void DEG_id_tag_update(struct ID *id, int flag)
@ ID_RECALC_GEOMETRY
Definition: DNA_ID.h:611
eSpaceSpreadsheet_ContextType
@ SPREADSHEET_CONTEXT_OBJECT
@ SPREADSHEET_CONTEXT_MODIFIER
@ SPREADSHEET_CONTEXT_NODE
@ SPREADSHEET_OBJECT_EVAL_STATE_EVALUATED
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
Read Guarded memory(de)allocation.
int64_t size() const
Definition: BLI_vector.hh:662
bool is_empty() const
Definition: BLI_vector.hh:674
OperationNode * node
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
static SpreadsheetContextModifier * spreadsheet_context_modifier_new()
SpreadsheetContext * spreadsheet_context_copy(const SpreadsheetContext *old_context)
void spreadsheet_context_free(SpreadsheetContext *context)
static void spreadsheet_context_update_tag(SpaceSpreadsheet *sspreadsheet)
static void spreadsheet_context_modifier_hash(const SpreadsheetContextModifier *context, BLI_HashMurmur2A *mm2)
static SpreadsheetContextModifier * spreadsheet_context_modifier_copy(const SpreadsheetContextModifier *src_context)
static SpreadsheetContextNode * spreadsheet_context_node_copy(const SpreadsheetContextNode *src_context)
static void spreadsheet_context_modifier_free(SpreadsheetContextModifier *context)
static void spreadsheet_context_node_hash(const SpreadsheetContextNode *context, BLI_HashMurmur2A *mm2)
static void spreadsheet_context_node_free(SpreadsheetContextNode *context)
static void spreadsheet_context_object_free(SpreadsheetContextObject *context)
SpreadsheetContext * spreadsheet_context_new(eSpaceSpreadsheet_ContextType type)
static void spreadsheet_context_hash(const SpreadsheetContext *context, BLI_HashMurmur2A *mm2)
static SpreadsheetContextObject * spreadsheet_context_object_new()
static SpreadsheetContextObject * spreadsheet_context_object_copy(const SpreadsheetContextObject *src_context)
static SpreadsheetContextNode * spreadsheet_context_node_new()
static void spreadsheet_context_object_hash(const SpreadsheetContextObject *context, BLI_HashMurmur2A *mm2)
struct SELECTID_Context context
Definition: select_engine.c:47
uint64_t ED_spreadsheet_context_path_hash(SpaceSpreadsheet *sspreadsheet)
SpreadsheetContext * ED_spreadsheet_context_new(int type)
void ED_spreadsheet_context_path_update_tag(SpaceSpreadsheet *sspreadsheet)
void ED_spreadsheet_context_path_clear(struct SpaceSpreadsheet *sspreadsheet)
void ED_spreadsheet_context_free(struct SpreadsheetContext *context)
void ED_spreadsheet_set_geometry_node_context(struct SpaceSpreadsheet *sspreadsheet, struct SpaceNode *snode, struct bNode *node)
unsigned __int64 uint64_t
Definition: stdint.h:93
ListBase treepath
struct ID * id