Blender  V3.3
context.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include <stddef.h>
8 #include <stdlib.h>
9 #include <string.h>
10 
11 #include "MEM_guardedalloc.h"
12 
13 #include "DNA_collection_types.h"
14 #include "DNA_gpencil_types.h"
15 #include "DNA_linestyle_types.h"
16 #include "DNA_object_types.h"
17 #include "DNA_scene_types.h"
18 #include "DNA_screen_types.h"
19 #include "DNA_space_types.h"
20 #include "DNA_view3d_types.h"
22 #include "DNA_workspace_types.h"
23 
24 #include "DEG_depsgraph.h"
25 
26 #include "BLI_listbase.h"
27 #include "BLI_string.h"
28 #include "BLI_threads.h"
29 #include "BLI_utildefines.h"
30 
31 #include "BLT_translation.h"
32 
33 #include "BKE_context.h"
34 #include "BKE_layer.h"
35 #include "BKE_main.h"
36 #include "BKE_scene.h"
37 #include "BKE_screen.h"
38 #include "BKE_sound.h"
39 #include "BKE_workspace.h"
40 
41 #include "RE_engine.h"
42 
43 #include "RNA_access.h"
44 #include "RNA_prototypes.h"
45 
46 #include "CLG_log.h"
47 
48 #ifdef WITH_PYTHON
49 # include "BPY_extern.h"
50 #endif
51 
52 static CLG_LogRef LOG = {"bke.context"};
53 
54 /* struct */
55 
56 struct bContext {
57  int thread;
58 
59  /* windowmanager context */
60  struct {
62  struct wmWindow *window;
64  struct bScreen *screen;
65  struct ScrArea *area;
66  struct ARegion *region;
67  struct ARegion *menu;
70 
71  /* Operator poll. */
76  const char *operator_poll_msg;
81  } wm;
82 
83  /* data context */
84  struct {
85  struct Main *main;
86  struct Scene *scene;
87 
88  int recursion;
90  bool py_init;
91  void *py_context;
97  } data;
98 };
99 
100 /* context */
101 
103 {
104  bContext *C = MEM_callocN(sizeof(bContext), "bContext");
105 
106  return C;
107 }
108 
110 {
111  bContext *newC = MEM_dupallocN((void *)C);
112 
113  memset(&newC->wm.operator_poll_msg_dyn_params, 0, sizeof(newC->wm.operator_poll_msg_dyn_params));
114 
115  return newC;
116 }
117 
119 {
120  /* This may contain a dynamically allocated message, free. */
122 
123  MEM_freeN(C);
124 }
125 
126 /* store */
127 
128 bContextStore *CTX_store_add(ListBase *contexts, const char *name, const PointerRNA *ptr)
129 {
130  /* ensure we have a context to put the entry in, if it was already used
131  * we have to copy the context to ensure */
132  bContextStore *ctx = contexts->last;
133 
134  if (!ctx || ctx->used) {
135  if (ctx) {
136  bContextStore *lastctx = ctx;
137  ctx = MEM_dupallocN(lastctx);
138  BLI_duplicatelist(&ctx->entries, &lastctx->entries);
139  }
140  else {
141  ctx = MEM_callocN(sizeof(bContextStore), "bContextStore");
142  }
143 
144  BLI_addtail(contexts, ctx);
145  }
146 
147  bContextStoreEntry *entry = MEM_callocN(sizeof(bContextStoreEntry), "bContextStoreEntry");
148  BLI_strncpy(entry->name, name, sizeof(entry->name));
149  entry->ptr = *ptr;
150 
151  BLI_addtail(&ctx->entries, entry);
152 
153  return ctx;
154 }
155 
157 {
158  /* ensure we have a context to put the entries in, if it was already used
159  * we have to copy the context to ensure */
160  bContextStore *ctx = contexts->last;
161 
162  if (!ctx || ctx->used) {
163  if (ctx) {
164  bContextStore *lastctx = ctx;
165  ctx = MEM_dupallocN(lastctx);
166  BLI_duplicatelist(&ctx->entries, &lastctx->entries);
167  }
168  else {
169  ctx = MEM_callocN(sizeof(bContextStore), "bContextStore");
170  }
171 
172  BLI_addtail(contexts, ctx);
173  }
174 
175  LISTBASE_FOREACH (bContextStoreEntry *, tentry, &context->entries) {
176  bContextStoreEntry *entry = MEM_dupallocN(tentry);
177  BLI_addtail(&ctx->entries, entry);
178  }
179 
180  return ctx;
181 }
182 
184 {
185  return C->wm.store;
186 }
187 
189 {
190  C->wm.store = store;
191 }
192 
194  const char *name,
195  const StructRNA *type)
196 {
198  &store->entries, name, offsetof(bContextStoreEntry, name));
199  if (!entry) {
200  return NULL;
201  }
202 
203  if (type && !RNA_struct_is_a(entry->ptr.type, type)) {
204  return NULL;
205  }
206  return &entry->ptr;
207 }
208 
210 {
211  bContextStore *ctx = MEM_dupallocN(store);
212  BLI_duplicatelist(&ctx->entries, &store->entries);
213 
214  return ctx;
215 }
216 
218 {
219  BLI_freelistN(&store->entries);
220  MEM_freeN(store);
221 }
222 
224 {
225  bContextStore *ctx;
226  while ((ctx = BLI_pophead(contexts))) {
227  CTX_store_free(ctx);
228  }
229 }
230 
231 /* is python initialized? */
232 
234 {
235  return C->data.py_init;
236 }
237 void CTX_py_init_set(bContext *C, bool value)
238 {
239  C->data.py_init = value;
240 }
241 
243 {
244  return C->data.py_context;
245 }
247 {
248  return C->data.py_context_orig;
249 }
250 
251 void CTX_py_state_push(bContext *C, struct bContext_PyState *pystate, void *value)
252 {
253  pystate->py_context = C->data.py_context;
254  pystate->py_context_orig = C->data.py_context_orig;
255 
256  C->data.py_context = value;
257  C->data.py_context_orig = value;
258 }
260 {
261  C->data.py_context = pystate->py_context;
262  C->data.py_context_orig = pystate->py_context_orig;
263 }
264 
265 /* data context utility functions */
266 
270  const char **dir;
271  short type; /* 0: normal, 1: seq */
272 };
273 
275  const char *member,
276  const StructRNA *member_type,
277  void *fall_through)
278 {
279 #ifdef WITH_PYTHON
280  if (UNLIKELY(C && CTX_py_dict_get(C))) {
282  memset(&result, 0, sizeof(bContextDataResult));
283  BPY_context_member_get((bContext *)C, member, &result);
284 
285  if (result.ptr.data) {
286  if (RNA_struct_is_a(result.ptr.type, member_type)) {
287  return result.ptr.data;
288  }
289 
290  CLOG_WARN(&LOG,
291  "PyContext '%s' is a '%s', expected a '%s'",
292  member,
293  RNA_struct_identifier(result.ptr.type),
294  RNA_struct_identifier(member_type));
295  }
296  }
297 #else
298  UNUSED_VARS(C, member, member_type);
299 #endif
300 
301  /* don't allow UI context access from non-main threads */
302  if (!BLI_thread_is_main()) {
303  return NULL;
304  }
305 
306  return fall_through;
307 }
308 
310 {
311  bScreen *screen;
312  ScrArea *area;
313  ARegion *region;
314  int done = 0, recursion = C->data.recursion;
315  int ret = 0;
316 
317  memset(result, 0, sizeof(bContextDataResult));
318 #ifdef WITH_PYTHON
319  if (CTX_py_dict_get(C)) {
320  if (BPY_context_member_get(C, member, result)) {
321  return 1;
322  }
323  }
324 #endif
325 
326  /* don't allow UI context access from non-main threads */
327  if (!BLI_thread_is_main()) {
328  return done;
329  }
330 
331  /* we check recursion to ensure that we do not get infinite
332  * loops requesting data from ourselves in a context callback */
333 
334  /* Ok, this looks evil...
335  * if (ret) done = -(-ret | -done);
336  *
337  * Values in order of importance
338  * (0, -1, 1) - Where 1 is highest priority
339  */
340  if (done != 1 && recursion < 1 && C->wm.store) {
341  C->data.recursion = 1;
342 
343  const PointerRNA *ptr = CTX_store_ptr_lookup(C->wm.store, member, NULL);
344 
345  if (ptr) {
346  result->ptr = *ptr;
347  done = 1;
348  }
349  }
350  if (done != 1 && recursion < 2 && (region = CTX_wm_region(C))) {
351  C->data.recursion = 2;
352  if (region->type && region->type->context) {
353  ret = region->type->context(C, member, result);
354  if (ret) {
355  done = -(-ret | -done);
356  }
357  }
358  }
359  if (done != 1 && recursion < 3 && (area = CTX_wm_area(C))) {
360  C->data.recursion = 3;
361  if (area->type && area->type->context) {
362  ret = area->type->context(C, member, result);
363  if (ret) {
364  done = -(-ret | -done);
365  }
366  }
367  }
368 
369  if (done != 1 && recursion < 4 && (screen = CTX_wm_screen(C))) {
370  bContextDataCallback cb = screen->context;
371  C->data.recursion = 4;
372  if (cb) {
373  ret = cb(C, member, result);
374  if (ret) {
375  done = -(-ret | -done);
376  }
377  }
378  }
379 
380  C->data.recursion = recursion;
381 
382  return done;
383 }
384 
385 static void *ctx_data_pointer_get(const bContext *C, const char *member)
386 {
388  if (C && ctx_data_get((bContext *)C, member, &result) == CTX_RESULT_OK) {
390  return result.ptr.data;
391  }
392 
393  return NULL;
394 }
395 
396 static int ctx_data_pointer_verify(const bContext *C, const char *member, void **pointer)
397 {
398  /* if context is NULL, pointer must be NULL too and that is a valid return */
399  if (C == NULL) {
400  *pointer = NULL;
401  return 1;
402  }
403 
405  if (ctx_data_get((bContext *)C, member, &result) == CTX_RESULT_OK) {
407  *pointer = result.ptr.data;
408  return 1;
409  }
410 
411  *pointer = NULL;
412  return 0;
413 }
414 
415 static int ctx_data_collection_get(const bContext *C, const char *member, ListBase *list)
416 {
418  if (ctx_data_get((bContext *)C, member, &result) == CTX_RESULT_OK) {
420  *list = result.list;
421  return 1;
422  }
423 
424  BLI_listbase_clear(list);
425 
426  return 0;
427 }
428 
429 static int ctx_data_base_collection_get(const bContext *C, const char *member, ListBase *list)
430 {
431  ListBase ctx_object_list;
432  if ((ctx_data_collection_get(C, member, &ctx_object_list) == false) ||
433  BLI_listbase_is_empty(&ctx_object_list)) {
434  BLI_listbase_clear(list);
435  return 0;
436  }
437 
439  memset(&result, 0, sizeof(bContextDataResult));
440 
442  ViewLayer *view_layer = CTX_data_view_layer(C);
443 
444  bool ok = false;
445 
446  CollectionPointerLink *ctx_object;
447  for (ctx_object = ctx_object_list.first; ctx_object; ctx_object = ctx_object->next) {
448  Object *ob = ctx_object->ptr.data;
449  Base *base = BKE_view_layer_base_find(view_layer, ob);
450  if (base != NULL) {
451  CTX_data_list_add(&result, &scene->id, &RNA_ObjectBase, base);
452  ok = true;
453  }
454  }
456  BLI_freelistN(&ctx_object_list);
457 
458  *list = result.list;
459  return ok;
460 }
461 
462 PointerRNA CTX_data_pointer_get(const bContext *C, const char *member)
463 {
465  if (ctx_data_get((bContext *)C, member, &result) == CTX_RESULT_OK) {
467  return result.ptr;
468  }
469 
470  return PointerRNA_NULL;
471 }
472 
474 {
476 
477  if (ptr.data) {
478  if (RNA_struct_is_a(ptr.type, type)) {
479  return ptr;
480  }
481 
482  CLOG_WARN(&LOG,
483  "member '%s' is '%s', not '%s'",
484  member,
487  }
488 
489  return PointerRNA_NULL;
490 }
491 
493 {
495 
496  if (ptr.data && RNA_struct_is_a(ptr.type, type)) {
497  return ptr;
498  }
499 
500  return PointerRNA_NULL;
501 }
502 
503 ListBase CTX_data_collection_get(const bContext *C, const char *member)
504 {
506  if (ctx_data_get((bContext *)C, member, &result) == CTX_RESULT_OK) {
508  return result.list;
509  }
510 
511  ListBase list = {NULL, NULL};
512  return list;
513 }
514 
515 int /*eContextResult*/ CTX_data_get(
516  const bContext *C, const char *member, PointerRNA *r_ptr, ListBase *r_lb, short *r_type)
517 {
520 
521  if (ret == CTX_RESULT_OK) {
522  *r_ptr = result.ptr;
523  *r_lb = result.list;
524  *r_type = result.type;
525  }
526  else {
527  memset(r_ptr, 0, sizeof(*r_ptr));
528  memset(r_lb, 0, sizeof(*r_lb));
529  *r_type = 0;
530  }
531 
532  return ret;
533 }
534 
535 static void data_dir_add(ListBase *lb, const char *member, const bool use_all)
536 {
537  LinkData *link;
538 
539  if ((use_all == false) && STREQ(member, "scene")) { /* exception */
540  return;
541  }
542 
543  if (BLI_findstring(lb, member, offsetof(LinkData, data))) {
544  return;
545  }
546 
547  link = MEM_callocN(sizeof(LinkData), "LinkData");
548  link->data = (void *)member;
549  BLI_addtail(lb, link);
550 }
551 
553  const bool use_store,
554  const bool use_rna,
555  const bool use_all)
556 {
558  ListBase lb;
559  bScreen *screen;
560  ScrArea *area;
561  ARegion *region;
562  int a;
563 
564  memset(&lb, 0, sizeof(lb));
565 
566  if (use_rna) {
567  char name[256], *nameptr;
568  int namelen;
569 
570  PropertyRNA *iterprop;
571  PointerRNA ctx_ptr;
572  RNA_pointer_create(NULL, &RNA_Context, (void *)C, &ctx_ptr);
573 
574  iterprop = RNA_struct_iterator_property(ctx_ptr.type);
575 
576  RNA_PROP_BEGIN (&ctx_ptr, itemptr, iterprop) {
577  nameptr = RNA_struct_name_get_alloc(&itemptr, name, sizeof(name), &namelen);
578  data_dir_add(&lb, name, use_all);
579  if (nameptr) {
580  if (name != nameptr) {
581  MEM_freeN(nameptr);
582  }
583  }
584  }
585  RNA_PROP_END;
586  }
587  if (use_store && C->wm.store) {
588  bContextStoreEntry *entry;
589 
590  for (entry = C->wm.store->entries.first; entry; entry = entry->next) {
591  data_dir_add(&lb, entry->name, use_all);
592  }
593  }
594  if ((region = CTX_wm_region(C)) && region->type && region->type->context) {
595  memset(&result, 0, sizeof(result));
596  region->type->context(C, "", &result);
597 
598  if (result.dir) {
599  for (a = 0; result.dir[a]; a++) {
600  data_dir_add(&lb, result.dir[a], use_all);
601  }
602  }
603  }
604  if ((area = CTX_wm_area(C)) && area->type && area->type->context) {
605  memset(&result, 0, sizeof(result));
606  area->type->context(C, "", &result);
607 
608  if (result.dir) {
609  for (a = 0; result.dir[a]; a++) {
610  data_dir_add(&lb, result.dir[a], use_all);
611  }
612  }
613  }
614  if ((screen = CTX_wm_screen(C)) && screen->context) {
615  bContextDataCallback cb = screen->context;
616  memset(&result, 0, sizeof(result));
617  cb(C, "", &result);
618 
619  if (result.dir) {
620  for (a = 0; result.dir[a]; a++) {
621  data_dir_add(&lb, result.dir[a], use_all);
622  }
623  }
624  }
625 
626  return lb;
627 }
628 
630 {
631  return CTX_data_dir_get_ex(C, true, false, false);
632 }
633 
634 bool CTX_data_equals(const char *member, const char *str)
635 {
636  return (STREQ(member, str));
637 }
638 
639 bool CTX_data_dir(const char *member)
640 {
641  return member[0] == '\0';
642 }
643 
645 {
646  RNA_id_pointer_create(id, &result->ptr);
647 }
648 
650 {
651  RNA_pointer_create(id, type, data, &result->ptr);
652 }
653 
655 {
656  result->ptr = *ptr;
657 }
658 
660 {
661  CollectionPointerLink *link = MEM_callocN(sizeof(CollectionPointerLink), "CTX_data_id_list_add");
662  RNA_id_pointer_create(id, &link->ptr);
663 
664  BLI_addtail(&result->list, link);
665 }
666 
668 {
669  CollectionPointerLink *link = MEM_callocN(sizeof(CollectionPointerLink), "CTX_data_list_add");
670  RNA_pointer_create(id, type, data, &link->ptr);
671 
672  BLI_addtail(&result->list, link);
673 }
674 
676 {
677  CollectionPointerLink *link = MEM_callocN(sizeof(CollectionPointerLink), "CTX_data_list_add");
678  link->ptr = *ptr;
679 
680  BLI_addtail(&result->list, link);
681 }
682 
683 int ctx_data_list_count(const bContext *C, int (*func)(const bContext *, ListBase *))
684 {
685  ListBase list;
686 
687  if (func(C, &list)) {
688  int tot = BLI_listbase_count(&list);
689  BLI_freelistN(&list);
690  return tot;
691  }
692 
693  return 0;
694 }
695 
697 {
698  result->dir = dir;
699 }
700 
702 {
703  result->type = type;
704 }
705 
707 {
708  return result->type;
709 }
710 
711 /* window manager context */
712 
714 {
715  return C->wm.manager;
716 }
717 
719 {
720  return (bool)C->wm.manager->is_interface_locked;
721 }
722 
724 {
725  return ctx_wm_python_context_get(C, "window", &RNA_Window, C->wm.window);
726 }
727 
729 {
730  return ctx_wm_python_context_get(C, "workspace", &RNA_WorkSpace, C->wm.workspace);
731 }
732 
734 {
735  return ctx_wm_python_context_get(C, "screen", &RNA_Screen, C->wm.screen);
736 }
737 
739 {
740  return ctx_wm_python_context_get(C, "area", &RNA_Area, C->wm.area);
741 }
742 
744 {
746  return (area) ? area->spacedata.first : NULL;
747 }
748 
750 {
751  return ctx_wm_python_context_get(C, "region", &RNA_Region, C->wm.region);
752 }
753 
755 {
756  ARegion *region = CTX_wm_region(C);
757  return (region) ? region->regiondata : NULL;
758 }
759 
760 struct ARegion *CTX_wm_menu(const bContext *C)
761 {
762  return C->wm.menu;
763 }
764 
766 {
767  return C->wm.gizmo_group;
768 }
769 
771 {
772  return C->wm.manager ? C->wm.manager->message_bus : NULL;
773 }
774 
776 {
777  if (C->wm.manager) {
778  return &(C->wm.manager->reports);
779  }
780 
781  return NULL;
782 }
783 
785 {
787  if (area && area->spacetype == SPACE_VIEW3D) {
788  return area->spacedata.first;
789  }
790  return NULL;
791 }
792 
794 {
796  ARegion *region = CTX_wm_region(C);
797 
798  if (area && area->spacetype == SPACE_VIEW3D) {
799  if (region && region->regiontype == RGN_TYPE_WINDOW) {
800  return region->regiondata;
801  }
802  }
803  return NULL;
804 }
805 
807 {
809  if (area && area->spacetype == SPACE_TEXT) {
810  return area->spacedata.first;
811  }
812  return NULL;
813 }
814 
816 {
818  if (area && area->spacetype == SPACE_CONSOLE) {
819  return area->spacedata.first;
820  }
821  return NULL;
822 }
823 
825 {
827  if (area && area->spacetype == SPACE_IMAGE) {
828  return area->spacedata.first;
829  }
830  return NULL;
831 }
832 
834 {
836  if (area && area->spacetype == SPACE_PROPERTIES) {
837  return area->spacedata.first;
838  }
839  return NULL;
840 }
841 
843 {
845  if (area && area->spacetype == SPACE_FILE) {
846  return area->spacedata.first;
847  }
848  return NULL;
849 }
850 
852 {
854  if (area && area->spacetype == SPACE_SEQ) {
855  return area->spacedata.first;
856  }
857  return NULL;
858 }
859 
861 {
863  if (area && area->spacetype == SPACE_OUTLINER) {
864  return area->spacedata.first;
865  }
866  return NULL;
867 }
868 
870 {
872  if (area && area->spacetype == SPACE_NLA) {
873  return area->spacedata.first;
874  }
875  return NULL;
876 }
877 
879 {
881  if (area && area->spacetype == SPACE_NODE) {
882  return area->spacedata.first;
883  }
884  return NULL;
885 }
886 
888 {
890  if (area && area->spacetype == SPACE_GRAPH) {
891  return area->spacedata.first;
892  }
893  return NULL;
894 }
895 
897 {
899  if (area && area->spacetype == SPACE_ACTION) {
900  return area->spacedata.first;
901  }
902  return NULL;
903 }
904 
906 {
908  if (area && area->spacetype == SPACE_INFO) {
909  return area->spacedata.first;
910  }
911  return NULL;
912 }
913 
915 {
917  if (area && area->spacetype == SPACE_USERPREF) {
918  return area->spacedata.first;
919  }
920  return NULL;
921 }
922 
924 {
926  if (area && area->spacetype == SPACE_CLIP) {
927  return area->spacedata.first;
928  }
929  return NULL;
930 }
931 
933 {
935  if (area && area->spacetype == SPACE_TOPBAR) {
936  return area->spacedata.first;
937  }
938  return NULL;
939 }
940 
942 {
944  if (area && area->spacetype == SPACE_SPREADSHEET) {
945  return area->spacedata.first;
946  }
947  return NULL;
948 }
949 
951 {
952  C->wm.manager = wm;
953  C->wm.window = NULL;
954  C->wm.screen = NULL;
955  C->wm.area = NULL;
956  C->wm.region = NULL;
957 }
958 
959 #ifdef WITH_PYTHON
960 # define PYCTX_REGION_MEMBERS "region", "region_data"
961 # define PYCTX_AREA_MEMBERS "area", "space_data", PYCTX_REGION_MEMBERS
962 # define PYCTX_SCREEN_MEMBERS "screen", PYCTX_AREA_MEMBERS
963 # define PYCTX_WINDOW_MEMBERS "window", "scene", "workspace", PYCTX_SCREEN_MEMBERS
964 #endif
965 
967 {
968  C->wm.window = win;
969  if (win) {
970  C->data.scene = win->scene;
971  }
972  C->wm.workspace = (win) ? BKE_workspace_active_get(win->workspace_hook) : NULL;
973  C->wm.screen = (win) ? BKE_workspace_active_screen_get(win->workspace_hook) : NULL;
974  C->wm.area = NULL;
975  C->wm.region = NULL;
976 
977 #ifdef WITH_PYTHON
978  if (C->data.py_context != NULL) {
979  BPY_context_dict_clear_members(C, PYCTX_WINDOW_MEMBERS);
980  }
981 #endif
982 }
983 
985 {
986  C->wm.screen = screen;
987  C->wm.area = NULL;
988  C->wm.region = NULL;
989 
990 #ifdef WITH_PYTHON
991  if (C->data.py_context != NULL) {
992  BPY_context_dict_clear_members(C, PYCTX_SCREEN_MEMBERS);
993  }
994 #endif
995 }
996 
998 {
999  C->wm.area = area;
1000  C->wm.region = NULL;
1001 
1002 #ifdef WITH_PYTHON
1003  if (C->data.py_context != NULL) {
1004  BPY_context_dict_clear_members(C, PYCTX_AREA_MEMBERS);
1005  }
1006 #endif
1007 }
1008 
1010 {
1011  C->wm.region = region;
1012 
1013 #ifdef WITH_PYTHON
1014  if (C->data.py_context != NULL) {
1015  BPY_context_dict_clear_members(C, PYCTX_REGION_MEMBERS);
1016  }
1017 #endif
1018 }
1019 
1021 {
1022  C->wm.menu = menu;
1023 }
1024 
1026 {
1027  C->wm.gizmo_group = gzgroup;
1028 }
1029 
1031 {
1032  struct bContextPollMsgDyn_Params *params = &C->wm.operator_poll_msg_dyn_params;
1033  if (params->free_fn != NULL) {
1034  params->free_fn(C, params->user_data);
1035  }
1036  params->get_fn = NULL;
1037  params->free_fn = NULL;
1038  params->user_data = NULL;
1039 
1040  C->wm.operator_poll_msg = NULL;
1041 }
1042 void CTX_wm_operator_poll_msg_set(bContext *C, const char *msg)
1043 {
1045 
1046  C->wm.operator_poll_msg = msg;
1047 }
1048 
1050  const struct bContextPollMsgDyn_Params *params)
1051 {
1053 
1054  C->wm.operator_poll_msg_dyn_params = *params;
1055 }
1056 
1057 const char *CTX_wm_operator_poll_msg_get(bContext *C, bool *r_free)
1058 {
1059  struct bContextPollMsgDyn_Params *params = &C->wm.operator_poll_msg_dyn_params;
1060  if (params->get_fn != NULL) {
1061  char *msg = params->get_fn(C, params->user_data);
1062  if (msg != NULL) {
1063  *r_free = true;
1064  }
1065  return msg;
1066  }
1067 
1068  *r_free = false;
1069  return IFACE_(C->wm.operator_poll_msg);
1070 }
1071 
1072 /* data context */
1073 
1075 {
1076  Main *bmain;
1077  if (ctx_data_pointer_verify(C, "blend_data", (void *)&bmain)) {
1078  return bmain;
1079  }
1080 
1081  return C->data.main;
1082 }
1083 
1085 {
1086  C->data.main = bmain;
1087  BKE_sound_init_main(bmain);
1088 }
1089 
1091 {
1092  Scene *scene;
1093  if (ctx_data_pointer_verify(C, "scene", (void *)&scene)) {
1094  return scene;
1095  }
1096 
1097  return C->data.scene;
1098 }
1099 
1101 {
1102  ViewLayer *view_layer;
1103 
1104  if (ctx_data_pointer_verify(C, "view_layer", (void *)&view_layer)) {
1105  return view_layer;
1106  }
1107 
1108  wmWindow *win = CTX_wm_window(C);
1110  if (win) {
1111  view_layer = BKE_view_layer_find(scene, win->view_layer_name);
1112  if (view_layer) {
1113  return view_layer;
1114  }
1115  }
1116 
1118 }
1119 
1121 {
1123  return RE_engines_find(scene->r.engine);
1124 }
1125 
1127 {
1128  ViewLayer *view_layer = CTX_data_view_layer(C);
1129  LayerCollection *layer_collection;
1130 
1131  if (ctx_data_pointer_verify(C, "layer_collection", (void *)&layer_collection)) {
1132  if (BKE_view_layer_has_collection(view_layer, layer_collection->collection)) {
1133  return layer_collection;
1134  }
1135  }
1136 
1137  /* fallback */
1138  return BKE_layer_collection_get_active(view_layer);
1139 }
1140 
1142 {
1143  Collection *collection;
1144  if (ctx_data_pointer_verify(C, "collection", (void *)&collection)) {
1145  return collection;
1146  }
1147 
1148  LayerCollection *layer_collection = CTX_data_layer_collection(C);
1149  if (layer_collection) {
1150  return layer_collection->collection;
1151  }
1152 
1153  /* fallback */
1155  return scene->master_collection;
1156 }
1157 
1159  const Object *ob,
1160  const eObjectMode object_mode)
1161 {
1162  // Object *obedit = CTX_data_edit_object(C);
1163  if (obedit) {
1164  switch (obedit->type) {
1165  case OB_MESH:
1166  return CTX_MODE_EDIT_MESH;
1167  case OB_CURVES_LEGACY:
1168  return CTX_MODE_EDIT_CURVE;
1169  case OB_SURF:
1170  return CTX_MODE_EDIT_SURFACE;
1171  case OB_FONT:
1172  return CTX_MODE_EDIT_TEXT;
1173  case OB_ARMATURE:
1174  return CTX_MODE_EDIT_ARMATURE;
1175  case OB_MBALL:
1176  return CTX_MODE_EDIT_METABALL;
1177  case OB_LATTICE:
1178  return CTX_MODE_EDIT_LATTICE;
1179  case OB_CURVES:
1180  return CTX_MODE_EDIT_CURVES;
1181  }
1182  }
1183  else {
1184  // Object *ob = CTX_data_active_object(C);
1185  if (ob) {
1186  if (object_mode & OB_MODE_POSE) {
1187  return CTX_MODE_POSE;
1188  }
1189  if (object_mode & OB_MODE_SCULPT) {
1190  return CTX_MODE_SCULPT;
1191  }
1192  if (object_mode & OB_MODE_WEIGHT_PAINT) {
1193  return CTX_MODE_PAINT_WEIGHT;
1194  }
1195  if (object_mode & OB_MODE_VERTEX_PAINT) {
1196  return CTX_MODE_PAINT_VERTEX;
1197  }
1198  if (object_mode & OB_MODE_TEXTURE_PAINT) {
1199  return CTX_MODE_PAINT_TEXTURE;
1200  }
1201  if (object_mode & OB_MODE_PARTICLE_EDIT) {
1202  return CTX_MODE_PARTICLE;
1203  }
1204  if (object_mode & OB_MODE_PAINT_GPENCIL) {
1205  return CTX_MODE_PAINT_GPENCIL;
1206  }
1207  if (object_mode & OB_MODE_EDIT_GPENCIL) {
1208  return CTX_MODE_EDIT_GPENCIL;
1209  }
1210  if (object_mode & OB_MODE_SCULPT_GPENCIL) {
1211  return CTX_MODE_SCULPT_GPENCIL;
1212  }
1213  if (object_mode & OB_MODE_WEIGHT_GPENCIL) {
1214  return CTX_MODE_WEIGHT_GPENCIL;
1215  }
1216  if (object_mode & OB_MODE_VERTEX_GPENCIL) {
1217  return CTX_MODE_VERTEX_GPENCIL;
1218  }
1219  if (object_mode & OB_MODE_SCULPT_CURVES) {
1220  return CTX_MODE_SCULPT_CURVES;
1221  }
1222  }
1223  }
1224 
1225  return CTX_MODE_OBJECT;
1226 }
1227 
1229 {
1230  Object *obedit = CTX_data_edit_object(C);
1231  Object *obact = obedit ? NULL : CTX_data_active_object(C);
1232  return CTX_data_mode_enum_ex(obedit, obact, obact ? obact->mode : OB_MODE_OBJECT);
1233 }
1234 
1240 static const char *data_mode_strings[] = {
1241  "mesh_edit",
1242  "curve_edit",
1243  "surface_edit",
1244  "text_edit",
1245  "armature_edit",
1246  "mball_edit",
1247  "lattice_edit",
1248  "curves_edit",
1249  "posemode",
1250  "sculpt_mode",
1251  "weightpaint",
1252  "vertexpaint",
1253  "imagepaint",
1254  "particlemode",
1255  "objectmode",
1256  "greasepencil_paint",
1257  "greasepencil_edit",
1258  "greasepencil_sculpt",
1259  "greasepencil_weight",
1260  "greasepencil_vertex",
1261  "curves_sculpt",
1262  NULL,
1263 };
1265  "Must have a string for each context mode")
1266 const char *CTX_data_mode_string(const bContext *C)
1267 {
1269 }
1270 
1272 {
1273  C->data.scene = scene;
1274 
1275 #ifdef WITH_PYTHON
1276  if (C->data.py_context != NULL) {
1278  }
1279 #endif
1280 }
1281 
1283 {
1285 
1286  if (scene) {
1287  return scene->toolsettings;
1288  }
1289 
1290  return NULL;
1291 }
1292 
1294 {
1295  return ctx_data_collection_get(C, "selected_ids", list);
1296 }
1297 
1299 {
1300  return ctx_data_collection_get(C, "selected_nodes", list);
1301 }
1302 
1304 {
1305  return ctx_data_collection_get(C, "selected_editable_objects", list);
1306 }
1307 
1309 {
1310  return ctx_data_base_collection_get(C, "selected_editable_objects", list);
1311 }
1312 
1314 {
1315  return ctx_data_collection_get(C, "editable_objects", list);
1316 }
1317 
1319 {
1320  return ctx_data_base_collection_get(C, "editable_objects", list);
1321 }
1322 
1324 {
1325  return ctx_data_collection_get(C, "selected_objects", list);
1326 }
1327 
1329 {
1330  return ctx_data_base_collection_get(C, "selected_objects", list);
1331 }
1332 
1334 {
1335  return ctx_data_collection_get(C, "visible_objects", list);
1336 }
1337 
1339 {
1340  return ctx_data_base_collection_get(C, "visible_objects", list);
1341 }
1342 
1344 {
1345  return ctx_data_collection_get(C, "selectable_objects", list);
1346 }
1347 
1349 {
1350  return ctx_data_base_collection_get(C, "selectable_objects", list);
1351 }
1352 
1354 {
1355  return ctx_data_pointer_get(C, "active_object");
1356 }
1357 
1359 {
1360  Object *ob = ctx_data_pointer_get(C, "active_object");
1361 
1362  if (ob == NULL) {
1363  return NULL;
1364  }
1365 
1366  ViewLayer *view_layer = CTX_data_view_layer(C);
1367  return BKE_view_layer_base_find(view_layer, ob);
1368 }
1369 
1371 {
1372  return ctx_data_pointer_get(C, "edit_object");
1373 }
1374 
1376 {
1377  return ctx_data_pointer_get(C, "edit_image");
1378 }
1379 
1381 {
1382  return ctx_data_pointer_get(C, "edit_text");
1383 }
1384 
1386 {
1387  return ctx_data_pointer_get(C, "edit_movieclip");
1388 }
1389 
1391 {
1392  return ctx_data_pointer_get(C, "edit_mask");
1393 }
1394 
1396 {
1397  return ctx_data_pointer_get(C, "active_bone");
1398 }
1399 
1401 {
1402  return ctx_data_pointer_get(C, "edit_cachefile");
1403 }
1404 
1406 {
1407  return ctx_data_collection_get(C, "selected_bones", list);
1408 }
1409 
1411 {
1412  return ctx_data_collection_get(C, "selected_editable_bones", list);
1413 }
1414 
1416 {
1417  return ctx_data_collection_get(C, "visible_bones", list);
1418 }
1419 
1421 {
1422  return ctx_data_collection_get(C, "editable_bones", list);
1423 }
1424 
1426 {
1427  return ctx_data_pointer_get(C, "active_pose_bone");
1428 }
1429 
1431 {
1432  return ctx_data_collection_get(C, "selected_pose_bones", list);
1433 }
1434 
1436 {
1437  return ctx_data_collection_get(C, "selected_pose_bones_from_active_object", list);
1438 }
1439 
1441 {
1442  return ctx_data_collection_get(C, "visible_pose_bones", list);
1443 }
1444 
1446 {
1447  return ctx_data_pointer_get(C, "gpencil_data");
1448 }
1449 
1451 {
1452  return ctx_data_pointer_get(C, "active_gpencil_layer");
1453 }
1454 
1456 {
1457  return ctx_data_pointer_get(C, "active_gpencil_frame");
1458 }
1459 
1461 {
1462  return ctx_data_collection_get(C, "visible_gpencil_layers", list);
1463 }
1464 
1466 {
1467  return ctx_data_collection_get(C, "editable_gpencil_layers", list);
1468 }
1469 
1471 {
1472  return ctx_data_collection_get(C, "editable_gpencil_strokes", list);
1473 }
1474 
1476 {
1477  return ctx_data_pointer_get(C, "asset_library_ref");
1478 }
1479 
1480 AssetHandle CTX_wm_asset_handle(const bContext *C, bool *r_is_valid)
1481 {
1482  AssetHandle *asset_handle_p =
1483  (AssetHandle *)CTX_data_pointer_get_type(C, "asset_handle", &RNA_AssetHandle).data;
1484  if (asset_handle_p) {
1485  *r_is_valid = true;
1486  return *asset_handle_p;
1487  }
1488 
1489  /* If the asset handle was not found in context directly, try if there's an active file with
1490  * asset data there instead. Not nice to have this here, would be better to have this in
1491  * `ED_asset.h`, but we can't include that in BKE. Even better would be not needing this at all
1492  * and being able to have editors return this in the usual `context` callback. But that would
1493  * require returning a non-owning pointer, which we don't have in the Asset Browser (yet). */
1494  FileDirEntry *file =
1495  (FileDirEntry *)CTX_data_pointer_get_type(C, "active_file", &RNA_FileSelectEntry).data;
1496  if (file && file->asset_data) {
1497  *r_is_valid = true;
1498  return (AssetHandle){.file_data = file};
1499  }
1500 
1501  *r_is_valid = false;
1502  return (AssetHandle){0};
1503 }
1504 
1506 {
1507  Main *bmain = CTX_data_main(C);
1509  ViewLayer *view_layer = CTX_data_view_layer(C);
1510  Depsgraph *depsgraph = BKE_scene_ensure_depsgraph(bmain, scene, view_layer);
1511  /* Dependency graph might have been just allocated, and hence it will not be marked.
1512  * This confuses redo system due to the lack of flushing changes back to the original data.
1513  * In the future we would need to check whether the CTX_wm_window(C) is in editing mode (as an
1514  * opposite of playback-preview-only) and set active flag based on that. */
1516  return depsgraph;
1517 }
1518 
1520 {
1522  /* TODO(sergey): Assert that the dependency graph is fully evaluated.
1523  * Note that first the depsgraph and scene post-eval hooks needs to run extra round of updates
1524  * first to make check here really reliable. */
1525  return depsgraph;
1526 }
1527 
1529 {
1531  Main *bmain = CTX_data_main(C);
1533  return depsgraph;
1534 }
1535 
1537 {
1539  ViewLayer *view_layer = CTX_data_view_layer(C);
1540  return BKE_scene_get_depsgraph(scene, view_layer);
1541 }
@ CTX_DATA_TYPE_POINTER
Definition: BKE_context.h:232
@ CTX_DATA_TYPE_COLLECTION
Definition: BKE_context.h:233
eContextObjectMode
Definition: BKE_context.h:103
@ CTX_MODE_EDIT_GPENCIL
Definition: BKE_context.h:120
@ CTX_MODE_EDIT_CURVE
Definition: BKE_context.h:105
@ CTX_MODE_PAINT_TEXTURE
Definition: BKE_context.h:116
@ CTX_MODE_EDIT_SURFACE
Definition: BKE_context.h:106
@ CTX_MODE_WEIGHT_GPENCIL
Definition: BKE_context.h:122
@ CTX_MODE_PARTICLE
Definition: BKE_context.h:117
@ CTX_MODE_SCULPT
Definition: BKE_context.h:113
@ CTX_MODE_VERTEX_GPENCIL
Definition: BKE_context.h:123
@ CTX_MODE_OBJECT
Definition: BKE_context.h:118
@ CTX_MODE_EDIT_MESH
Definition: BKE_context.h:104
@ CTX_MODE_SCULPT_CURVES
Definition: BKE_context.h:124
@ CTX_MODE_EDIT_TEXT
Definition: BKE_context.h:107
@ CTX_MODE_EDIT_CURVES
Definition: BKE_context.h:111
@ CTX_MODE_EDIT_ARMATURE
Definition: BKE_context.h:108
@ CTX_MODE_SCULPT_GPENCIL
Definition: BKE_context.h:121
@ CTX_MODE_EDIT_LATTICE
Definition: BKE_context.h:110
@ CTX_MODE_PAINT_GPENCIL
Definition: BKE_context.h:119
@ CTX_MODE_PAINT_VERTEX
Definition: BKE_context.h:115
@ CTX_MODE_EDIT_METABALL
Definition: BKE_context.h:109
@ CTX_MODE_PAINT_WEIGHT
Definition: BKE_context.h:114
@ CTX_MODE_POSE
Definition: BKE_context.h:112
#define CTX_MODE_NUM
Definition: BKE_context.h:126
const char * CTX_data_mode_string(const bContext *C)
eContextResult
Definition: BKE_context.h:70
@ CTX_RESULT_OK
Definition: BKE_context.h:72
int(* bContextDataCallback)(const bContext *C, const char *member, bContextDataResult *result)
Definition: BKE_context.h:83
struct LayerCollection * BKE_layer_collection_get_active(struct ViewLayer *view_layer)
Definition: layer.c:636
bool BKE_view_layer_has_collection(const struct ViewLayer *view_layer, const struct Collection *collection)
struct ViewLayer * BKE_view_layer_default_view(const struct Scene *scene)
struct Base * BKE_view_layer_base_find(struct ViewLayer *view_layer, struct Object *ob)
Definition: layer.c:379
struct ViewLayer * BKE_view_layer_find(const struct Scene *scene, const char *layer_name)
struct Depsgraph * BKE_scene_get_depsgraph(const struct Scene *scene, const struct ViewLayer *view_layer)
struct Depsgraph * BKE_scene_ensure_depsgraph(struct Main *bmain, struct Scene *scene, struct ViewLayer *view_layer)
Definition: scene.cc:3456
void BKE_scene_graph_evaluated_ensure(struct Depsgraph *depsgraph, struct Main *bmain)
Definition: scene.cc:2653
void BKE_sound_init_main(struct Main *bmain)
struct WorkSpace * BKE_workspace_active_get(struct WorkSpaceInstanceHook *hook) GETTER_ATTRS
Definition: workspace.c:516
struct bScreen * BKE_workspace_active_screen_get(const struct WorkSpaceInstanceHook *hook) GETTER_ATTRS
#define BLI_assert(a)
Definition: BLI_assert.h:46
BLI_INLINE bool BLI_listbase_is_empty(const struct ListBase *lb)
Definition: BLI_listbase.h:269
void * BLI_pophead(ListBase *listbase) ATTR_NONNULL(1)
Definition: listbase.c:221
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:336
void void void void void BLI_duplicatelist(struct ListBase *dst, const struct ListBase *src) ATTR_NONNULL(1
BLI_INLINE void BLI_listbase_clear(struct ListBase *lb)
Definition: BLI_listbase.h:273
void void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1)
Definition: listbase.c:466
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:80
void * BLI_findstring(const struct ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void * BLI_rfindstring(const struct ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
int BLI_listbase_count(const struct ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL()
Definition: string.c:64
int BLI_thread_is_main(void)
Definition: threads.cc:207
#define ARRAY_SIZE(arr)
#define UNUSED_VARS(...)
#define UNLIKELY(x)
#define STREQ(a, b)
#define IFACE_(msgid)
int BPY_context_member_get(struct bContext *C, const char *member, struct bContextDataResult *result)
#define BPY_context_dict_clear_members(C,...)
Definition: BPY_extern.h:109
#define CLOG_WARN(clg_ref,...)
Definition: CLG_log.h:189
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:35
void DEG_make_active(struct Depsgraph *depsgraph)
Definition: depsgraph.cc:325
Object groups, one object can be in many groups at once.
eObjectMode
@ OB_MODE_VERTEX_GPENCIL
@ OB_MODE_EDIT_GPENCIL
@ OB_MODE_PARTICLE_EDIT
@ OB_MODE_WEIGHT_PAINT
@ OB_MODE_WEIGHT_GPENCIL
@ OB_MODE_SCULPT
@ OB_MODE_SCULPT_CURVES
@ OB_MODE_SCULPT_GPENCIL
@ OB_MODE_POSE
@ OB_MODE_TEXTURE_PAINT
@ OB_MODE_OBJECT
@ OB_MODE_VERTEX_PAINT
@ OB_MODE_PAINT_GPENCIL
Object is a sort of wrapper for general info.
@ OB_LATTICE
@ OB_MBALL
@ OB_SURF
@ OB_FONT
@ OB_ARMATURE
@ OB_MESH
@ OB_CURVES_LEGACY
@ OB_CURVES
@ RGN_TYPE_WINDOW
@ SPACE_TEXT
@ SPACE_CLIP
@ SPACE_ACTION
@ SPACE_CONSOLE
@ SPACE_OUTLINER
@ SPACE_TOPBAR
@ SPACE_NODE
@ SPACE_SPREADSHEET
@ SPACE_USERPREF
@ SPACE_FILE
@ SPACE_PROPERTIES
@ SPACE_NLA
@ SPACE_SEQ
@ SPACE_IMAGE
@ SPACE_GRAPH
@ SPACE_VIEW3D
@ SPACE_INFO
_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.
#define RNA_PROP_END
Definition: RNA_access.h:563
#define RNA_PROP_BEGIN(sptr, itemptr, prop)
Definition: RNA_access.h:556
#define C
Definition: RandGen.cpp:25
short CTX_data_type_get(bContextDataResult *result)
Definition: context.c:706
int CTX_data_get(const bContext *C, const char *member, PointerRNA *r_ptr, ListBase *r_lb, short *r_type)
Definition: context.c:515
struct SpaceTopBar * CTX_wm_space_topbar(const bContext *C)
Definition: context.c:932
int CTX_data_visible_pose_bones(const bContext *C, ListBase *list)
Definition: context.c:1440
void CTX_data_main_set(bContext *C, Main *bmain)
Definition: context.c:1084
int CTX_data_selectable_objects(const bContext *C, ListBase *list)
Definition: context.c:1343
ScrArea * CTX_wm_area(const bContext *C)
Definition: context.c:738
PointerRNA CTX_data_pointer_get(const bContext *C, const char *member)
Definition: context.c:462
bContext * CTX_copy(const bContext *C)
Definition: context.c:109
void CTX_store_set(bContext *C, bContextStore *store)
Definition: context.c:188
int CTX_data_visible_bones(const bContext *C, ListBase *list)
Definition: context.c:1415
bool CTX_wm_interface_locked(const bContext *C)
Definition: context.c:718
BLI_STATIC_ASSERT(ARRAY_SIZE(data_mode_strings)==CTX_MODE_NUM+1, "Must have a string for each context mode") const
Definition: context.c:1264
struct SpaceClip * CTX_wm_space_clip(const bContext *C)
Definition: context.c:923
int ctx_data_list_count(const bContext *C, int(*func)(const bContext *, ListBase *))
Definition: context.c:683
struct SpaceInfo * CTX_wm_space_info(const bContext *C)
Definition: context.c:905
bGPDframe * CTX_data_active_gpencil_frame(const bContext *C)
Definition: context.c:1455
void CTX_data_dir_set(bContextDataResult *result, const char **dir)
Definition: context.c:696
struct ARegion * CTX_wm_menu(const bContext *C)
Definition: context.c:760
PointerRNA CTX_data_pointer_get_type_silent(const bContext *C, const char *member, StructRNA *type)
Definition: context.c:492
struct SpaceNode * CTX_wm_space_node(const bContext *C)
Definition: context.c:878
struct SpaceProperties * CTX_wm_space_properties(const bContext *C)
Definition: context.c:833
void CTX_data_id_list_add(bContextDataResult *result, ID *id)
Definition: context.c:659
int CTX_data_selected_bones(const bContext *C, ListBase *list)
Definition: context.c:1405
struct Object * CTX_data_edit_object(const bContext *C)
Definition: context.c:1370
bool CTX_data_equals(const char *member, const char *str)
Definition: context.c:634
bool CTX_py_init_get(bContext *C)
Definition: context.c:233
int CTX_data_visible_objects(const bContext *C, ListBase *list)
Definition: context.c:1333
void CTX_data_pointer_set(bContextDataResult *result, ID *id, StructRNA *type, void *data)
Definition: context.c:649
Depsgraph * CTX_data_depsgraph_on_load(const bContext *C)
Definition: context.c:1536
int CTX_data_editable_objects(const bContext *C, ListBase *list)
Definition: context.c:1313
Scene * CTX_data_scene(const bContext *C)
Definition: context.c:1090
static eContextResult ctx_data_get(bContext *C, const char *member, bContextDataResult *result)
Definition: context.c:309
int CTX_data_selected_editable_bases(const bContext *C, ListBase *list)
Definition: context.c:1308
int CTX_data_selected_objects(const bContext *C, ListBase *list)
Definition: context.c:1323
bContextStore * CTX_store_add(ListBase *contexts, const char *name, const PointerRNA *ptr)
Definition: context.c:128
Collection * CTX_data_collection(const bContext *C)
Definition: context.c:1141
struct Base * CTX_data_active_base(const bContext *C)
Definition: context.c:1358
RegionView3D * CTX_wm_region_view3d(const bContext *C)
Definition: context.c:793
void CTX_py_state_push(bContext *C, struct bContext_PyState *pystate, void *value)
Definition: context.c:251
bool CTX_data_dir(const char *member)
Definition: context.c:639
static void data_dir_add(ListBase *lb, const char *member, const bool use_all)
Definition: context.c:535
void CTX_data_id_pointer_set(bContextDataResult *result, ID *id)
Definition: context.c:644
AssetHandle CTX_wm_asset_handle(const bContext *C, bool *r_is_valid)
Definition: context.c:1480
static const char * data_mode_strings[]
Definition: context.c:1240
void * CTX_py_dict_get(const bContext *C)
Definition: context.c:242
struct SpaceOutliner * CTX_wm_space_outliner(const bContext *C)
Definition: context.c:860
void * CTX_py_dict_get_orig(const bContext *C)
Definition: context.c:246
void CTX_wm_gizmo_group_set(bContext *C, struct wmGizmoGroup *gzgroup)
Definition: context.c:1025
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C)
Definition: context.c:1528
void CTX_wm_manager_set(bContext *C, wmWindowManager *wm)
Definition: context.c:950
bContext * CTX_create(void)
Definition: context.c:102
Depsgraph * CTX_data_expect_evaluated_depsgraph(const bContext *C)
Definition: context.c:1519
void CTX_wm_operator_poll_msg_clear(bContext *C)
Definition: context.c:1030
void CTX_py_init_set(bContext *C, bool value)
Definition: context.c:237
int CTX_data_editable_gpencil_layers(const bContext *C, ListBase *list)
Definition: context.c:1465
int CTX_data_selected_editable_bones(const bContext *C, ListBase *list)
Definition: context.c:1410
struct Mask * CTX_data_edit_mask(const bContext *C)
Definition: context.c:1390
struct SpaceSeq * CTX_wm_space_seq(const bContext *C)
Definition: context.c:851
PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type)
Definition: context.c:473
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
Definition: context.c:1505
struct SpaceNla * CTX_wm_space_nla(const bContext *C)
Definition: context.c:869
int CTX_data_editable_bones(const bContext *C, ListBase *list)
Definition: context.c:1420
struct SpaceSpreadsheet * CTX_wm_space_spreadsheet(const bContext *C)
Definition: context.c:941
bContextStore * CTX_store_copy(bContextStore *store)
Definition: context.c:209
void CTX_store_free(bContextStore *store)
Definition: context.c:217
int CTX_data_visible_bases(const bContext *C, ListBase *list)
Definition: context.c:1338
void CTX_wm_operator_poll_msg_set(bContext *C, const char *msg)
Definition: context.c:1042
static int ctx_data_pointer_verify(const bContext *C, const char *member, void **pointer)
Definition: context.c:396
struct MovieClip * CTX_data_edit_movieclip(const bContext *C)
Definition: context.c:1385
Main * CTX_data_main(const bContext *C)
Definition: context.c:1074
int CTX_data_editable_bases(const bContext *C, ListBase *list)
Definition: context.c:1318
struct wmGizmoGroup * CTX_wm_gizmo_group(const bContext *C)
Definition: context.c:765
SpaceLink * CTX_wm_space_data(const bContext *C)
Definition: context.c:743
void CTX_free(bContext *C)
Definition: context.c:118
ListBase CTX_data_dir_get(const bContext *C)
Definition: context.c:629
struct Object * CTX_data_active_object(const bContext *C)
Definition: context.c:1353
wmWindow * CTX_wm_window(const bContext *C)
Definition: context.c:723
bContextStore * CTX_store_add_all(ListBase *contexts, bContextStore *context)
Definition: context.c:156
ARegion * CTX_wm_region(const bContext *C)
Definition: context.c:749
struct EditBone * CTX_data_active_bone(const bContext *C)
Definition: context.c:1395
void CTX_py_state_pop(bContext *C, struct bContext_PyState *pystate)
Definition: context.c:259
const AssetLibraryReference * CTX_wm_asset_library_ref(const bContext *C)
Definition: context.c:1475
struct SpaceUserPref * CTX_wm_space_userpref(const bContext *C)
Definition: context.c:914
LayerCollection * CTX_data_layer_collection(const bContext *C)
Definition: context.c:1126
void CTX_wm_screen_set(bContext *C, bScreen *screen)
Definition: context.c:984
void CTX_data_scene_set(bContext *C, Scene *scene)
Definition: context.c:1271
int CTX_data_selected_ids(const bContext *C, ListBase *list)
Definition: context.c:1293
ListBase CTX_data_dir_get_ex(const bContext *C, const bool use_store, const bool use_rna, const bool use_all)
Definition: context.c:552
struct SpaceGraph * CTX_wm_space_graph(const bContext *C)
Definition: context.c:887
bGPDlayer * CTX_data_active_gpencil_layer(const bContext *C)
Definition: context.c:1450
const char * CTX_wm_operator_poll_msg_get(bContext *C, bool *r_free)
Definition: context.c:1057
struct Image * CTX_data_edit_image(const bContext *C)
Definition: context.c:1375
static int ctx_data_collection_get(const bContext *C, const char *member, ListBase *list)
Definition: context.c:415
void * CTX_wm_region_data(const bContext *C)
Definition: context.c:754
void CTX_data_list_add(bContextDataResult *result, ID *id, StructRNA *type, void *data)
Definition: context.c:667
ViewLayer * CTX_data_view_layer(const bContext *C)
Definition: context.c:1100
int CTX_data_selected_pose_bones(const bContext *C, ListBase *list)
Definition: context.c:1430
void CTX_store_free_list(ListBase *contexts)
Definition: context.c:223
int CTX_data_visible_gpencil_layers(const bContext *C, ListBase *list)
Definition: context.c:1460
enum eContextObjectMode CTX_data_mode_enum_ex(const Object *obedit, const Object *ob, const eObjectMode object_mode)
Definition: context.c:1158
void CTX_wm_window_set(bContext *C, wmWindow *win)
Definition: context.c:966
void CTX_wm_menu_set(bContext *C, ARegion *menu)
Definition: context.c:1020
View3D * CTX_wm_view3d(const bContext *C)
Definition: context.c:784
bGPdata * CTX_data_gpencil_data(const bContext *C)
Definition: context.c:1445
static int ctx_data_base_collection_get(const bContext *C, const char *member, ListBase *list)
Definition: context.c:429
struct SpaceAction * CTX_wm_space_action(const bContext *C)
Definition: context.c:896
static void * ctx_data_pointer_get(const bContext *C, const char *member)
Definition: context.c:385
WorkSpace * CTX_wm_workspace(const bContext *C)
Definition: context.c:728
void CTX_data_list_add_ptr(bContextDataResult *result, const PointerRNA *ptr)
Definition: context.c:675
int CTX_data_selectable_bases(const bContext *C, ListBase *list)
Definition: context.c:1348
struct ReportList * CTX_wm_reports(const bContext *C)
Definition: context.c:775
static CLG_LogRef LOG
Definition: context.c:52
int CTX_data_selected_bases(const bContext *C, ListBase *list)
Definition: context.c:1328
static void * ctx_wm_python_context_get(const bContext *C, const char *member, const StructRNA *member_type, void *fall_through)
Definition: context.c:274
void CTX_data_pointer_set_ptr(bContextDataResult *result, const PointerRNA *ptr)
Definition: context.c:654
void CTX_wm_operator_poll_msg_set_dynamic(bContext *C, const struct bContextPollMsgDyn_Params *params)
Definition: context.c:1049
struct wmMsgBus * CTX_wm_message_bus(const bContext *C)
Definition: context.c:770
bScreen * CTX_wm_screen(const bContext *C)
Definition: context.c:733
struct SpaceText * CTX_wm_space_text(const bContext *C)
Definition: context.c:806
int CTX_data_selected_nodes(const bContext *C, ListBase *list)
Definition: context.c:1298
RenderEngineType * CTX_data_engine_type(const bContext *C)
Definition: context.c:1120
int CTX_data_selected_editable_objects(const bContext *C, ListBase *list)
Definition: context.c:1303
ToolSettings * CTX_data_tool_settings(const bContext *C)
Definition: context.c:1282
void CTX_wm_area_set(bContext *C, ScrArea *area)
Definition: context.c:997
const PointerRNA * CTX_store_ptr_lookup(const bContextStore *store, const char *name, const StructRNA *type)
Definition: context.c:193
void CTX_wm_region_set(bContext *C, ARegion *region)
Definition: context.c:1009
struct CacheFile * CTX_data_edit_cachefile(const bContext *C)
Definition: context.c:1400
int CTX_data_editable_gpencil_strokes(const bContext *C, ListBase *list)
Definition: context.c:1470
struct SpaceImage * CTX_wm_space_image(const bContext *C)
Definition: context.c:824
ListBase CTX_data_collection_get(const bContext *C, const char *member)
Definition: context.c:503
int CTX_data_selected_pose_bones_from_active_object(const bContext *C, ListBase *list)
Definition: context.c:1435
struct SpaceConsole * CTX_wm_space_console(const bContext *C)
Definition: context.c:815
wmWindowManager * CTX_wm_manager(const bContext *C)
Definition: context.c:713
struct SpaceFile * CTX_wm_space_file(const bContext *C)
Definition: context.c:842
void CTX_data_type_set(bContextDataResult *result, short type)
Definition: context.c:701
struct Text * CTX_data_edit_text(const bContext *C)
Definition: context.c:1380
enum eContextObjectMode CTX_data_mode_enum(const bContext *C)
Definition: context.c:1228
struct bPoseChannel * CTX_data_active_pose_bone(const bContext *C)
Definition: context.c:1425
bContextStore * CTX_store_get(bContext *C)
Definition: context.c:183
FILE * file
Scene scene
const Depsgraph * depsgraph
RenderEngineType * RE_engines_find(const char *idname)
Definition: engine.c:98
#define str(s)
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void *(* MEM_dupallocN)(const void *vmemh)
Definition: mallocn.c:28
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:31
static unsigned a[3]
Definition: RandGen.cpp:78
static void area(int d1, int d2, int e1, int e2, float weights[2])
return ret
const char * RNA_struct_identifier(const StructRNA *type)
Definition: rna_access.c:586
bool RNA_struct_is_a(const StructRNA *type, const StructRNA *srna)
Definition: rna_access.c:695
void RNA_pointer_create(ID *id, StructRNA *type, void *data, PointerRNA *r_ptr)
Definition: rna_access.c:136
void RNA_id_pointer_create(ID *id, PointerRNA *r_ptr)
Definition: rna_access.c:112
char * RNA_struct_name_get_alloc(PointerRNA *ptr, char *fixedbuf, int fixedlen, int *r_len)
Definition: rna_access.c:907
const PointerRNA PointerRNA_NULL
Definition: rna_access.c:61
PropertyRNA * RNA_struct_iterator_property(StructRNA *type)
Definition: rna_access.c:634
bContextDataCallback context
Definition: BKE_screen.h:182
void * regiondata
short regiontype
struct ARegionType * type
Definition: DNA_ID.h:368
struct Collection * collection
void * data
Definition: DNA_listBase.h:26
void * last
Definition: DNA_listBase.h:31
void * first
Definition: DNA_listBase.h:31
Definition: BKE_main.h:121
struct StructRNA * type
Definition: RNA_types.h:37
void * data
Definition: RNA_types.h:38
char engine[32]
struct Collection * master_collection
string name
Definition: scene.h:198
struct ToolSettings * toolsettings
struct RenderData r
const char ** dir
Definition: context.c:270
ListBase list
Definition: context.c:269
PointerRNA ptr
Definition: context.c:268
PointerRNA ptr
Definition: BKE_context.h:91
struct bContextStoreEntry * next
Definition: BKE_context.h:88
ListBase entries
Definition: BKE_context.h:97
void * py_context_orig
Definition: BKE_context.h:157
struct bContext::@87 data
struct wmWindow * window
Definition: context.c:62
struct bContextPollMsgDyn_Params operator_poll_msg_dyn_params
Definition: context.c:80
struct Main * main
Definition: context.c:85
const char * operator_poll_msg
Definition: context.c:76
struct bContextStore * store
Definition: context.c:69
struct bContext::@86 wm
struct bScreen * screen
Definition: context.c:64
struct ARegion * region
Definition: context.c:66
int recursion
Definition: context.c:88
void * py_context_orig
Definition: context.c:96
struct wmGizmoGroup * gizmo_group
Definition: context.c:68
void * py_context
Definition: context.c:91
struct WorkSpace * workspace
Definition: context.c:63
struct ScrArea * area
Definition: context.c:65
int thread
Definition: context.c:57
struct wmWindowManager * manager
Definition: context.c:61
struct ARegion * menu
Definition: context.c:67
bool py_init
Definition: context.c:90
struct Scene * scene
Definition: context.c:86
void * context
struct Scene * scene
char view_layer_name[64]
struct WorkSpaceInstanceHook * workspace_hook
PointerRNA * ptr
Definition: wm_files.c:3480