Blender V5.3
blenkernel/intern/context.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstddef>
10#include <cstdlib>
11#include <cstring>
12
13#include <fmt/format.h>
14
15#include "MEM_guardedalloc.h"
16
18#include "DNA_object_types.h"
19#include "DNA_scene_types.h"
20#include "DNA_screen_types.h"
21#include "DNA_space_types.h"
22#include "DNA_view3d_types.h"
24#include "DNA_workspace_types.h"
25
26#include "DEG_depsgraph.hh"
28
29#include "BLI_listbase.hh"
30#include "BLI_threads.hh"
31#include "BLI_utildefines.hh"
32
33#include "BLT_translation.hh"
34
35#include "BKE_context.hh"
36#include "BKE_layer.hh"
37#include "BKE_main.hh"
38#include "BKE_scene.hh"
39#include "BKE_screen.hh"
40#include "BKE_sound.hh"
41#include "BKE_wm_runtime.hh"
42#include "BKE_workspace.hh"
43
44#include "RE_engine.h"
45
46#include "RNA_access.hh"
47#include "RNA_prototypes.hh"
48#include "RNA_types.hh"
49
50#include "CLG_log.h"
51
52#ifdef WITH_PYTHON
53# include "BPY_extern.hh"
54#endif
55
56namespace blender {
57
58/* Logging. */
60
61static CLG_LogRef LOG = {"context"};
62
63/* struct */
64
65struct bContext {
66 int thread = 0;
67
68 /* windowmanager context */
69 struct {
70 wmWindowManager *manager = nullptr;
71 wmWindow *window = nullptr;
72 WorkSpace *workspace = nullptr;
73 bScreen *screen = nullptr;
74 ScrArea *area = nullptr;
75 ARegion *region = nullptr;
76 ARegion *region_popup = nullptr;
77 wmGizmoGroup *gizmo_group = nullptr;
78 const bContextStore *store = nullptr;
79
80 /* Operator poll. */
85 std::optional<std::string> operator_poll_msg = {};
90 } wm;
91
92 /* data context */
93 struct {
94 Main *main = nullptr;
95 Scene *scene = nullptr;
96
97 int recursion = 0;
98
100 bool ui_data_access_deny = false;
101
103 bool py_init = false;
104 void *py_context = nullptr;
109 void *py_context_orig = nullptr;
113 const bool *rna_disallow_writes = nullptr;
115};
116
117/* context */
118
120{
121 bContext *C = MEM_new<bContext>(__func__);
122 return C;
123}
124
126{
127 bContext *newC = MEM_new<bContext>(__func__, *C);
128 /* This may contain a dynamically allocated data, which cannot be shallow-copied, reset. */
129 newC->wm.operator_poll_msg_dyn_params = {};
130 return newC;
131}
132
134{
135 /* This may contain a dynamically allocated data, free. */
137
138 MEM_delete(C);
139}
140
141/* store */
142
146static bContextStore *ctx_store_extend(Vector<std::unique_ptr<bContextStore>> &contexts)
147{
148 /* ensure we have a context to put the entry in, if it was already used
149 * we have to copy the context to ensure */
150 if (contexts.is_empty()) {
151 contexts.append(std::make_unique<bContextStore>());
152 }
153 else if (contexts.last()->used) {
154 auto new_ctx = std::make_unique<bContextStore>(bContextStore{contexts.last()->entries, false});
155 contexts.append(std::move(new_ctx));
156 }
157
158 return contexts.last().get();
159}
160
161bContextStore *CTX_store_add(Vector<std::unique_ptr<bContextStore>> &contexts,
162 const StringRef name,
163 const PointerRNA *ptr)
164{
165 bContextStore *ctx = ctx_store_extend(contexts);
166 ctx->entries.append(bContextStoreEntry{name, *ptr});
167 return ctx;
168}
169
170bContextStore *CTX_store_add(Vector<std::unique_ptr<bContextStore>> &contexts,
171 const StringRef name,
172 const StringRef str)
173{
174 bContextStore *ctx = ctx_store_extend(contexts);
175 ctx->entries.append(bContextStoreEntry{name, std::string{str}});
176 return ctx;
177}
178
179bContextStore *CTX_store_add(Vector<std::unique_ptr<bContextStore>> &contexts,
180 const StringRef name,
181 const int64_t value)
182{
183 bContextStore *ctx = ctx_store_extend(contexts);
184 ctx->entries.append(bContextStoreEntry{name, value});
185 return ctx;
186}
187
188bContextStore *CTX_store_add_all(Vector<std::unique_ptr<bContextStore>> &contexts,
189 const bContextStore *context)
190{
191 bContextStore *ctx = ctx_store_extend(contexts);
192 for (const bContextStoreEntry &src_entry : context->entries) {
193 ctx->entries.append(src_entry);
194 }
195 return ctx;
196}
197
199{
200 return C->wm.store;
201}
202
204{
205 C->wm.store = store;
206}
207
209 const StringRef name,
210 const StructRNA *type)
211{
212 for (auto entry = store->entries.rbegin(); entry != store->entries.rend(); ++entry) {
213 if (entry->name == name && std::holds_alternative<PointerRNA>(entry->value)) {
214 const PointerRNA &ptr = std::get<PointerRNA>(entry->value);
215 if (!type || RNA_struct_is_a(ptr.type, type)) {
216 return &ptr;
217 }
218 }
219 }
220 return nullptr;
221}
222
223template<typename T>
224const T *ctx_store_lookup_impl(const bContextStore *store, const StringRef name)
225{
226 for (auto entry = store->entries.rbegin(); entry != store->entries.rend(); ++entry) {
227 if (entry->name == name && std::holds_alternative<T>(entry->value)) {
228 return &std::get<T>(entry->value);
229 }
230 }
231 return nullptr;
232}
233
234std::optional<StringRefNull> CTX_store_string_lookup(const bContextStore *store,
235 const StringRef name)
236{
237 if (const std::string *value = ctx_store_lookup_impl<std::string>(store, name)) {
238 return *value;
239 }
240 return {};
241}
242
243std::optional<int64_t> CTX_store_int_lookup(const bContextStore *store, const StringRef name)
244{
245 if (const int64_t *value = ctx_store_lookup_impl<int64_t>(store, name)) {
246 return *value;
247 }
248 return {};
249}
250
251/* is python initialized? */
252
254{
255 return C->data.py_init;
256}
257void CTX_py_init_set(bContext *C, bool value)
258{
259 C->data.py_init = value;
260}
261
263{
264 return C->data.py_context;
265}
267{
268 return C->data.py_context_orig;
269}
270
271void CTX_py_state_push(bContext *C, bContext_PyState *pystate, void *value)
272{
273 pystate->py_context = C->data.py_context;
274 pystate->py_context_orig = C->data.py_context_orig;
275
276 C->data.py_context = value;
277 C->data.py_context_orig = value;
278}
280{
281 C->data.py_context = pystate->py_context;
282 C->data.py_context_orig = pystate->py_context_orig;
283}
284
285void CTX_rna_disallow_write_set_p(bContext *C, const bool *rna_disallow_writes)
286{
287 C->data.rna_disallow_writes = rna_disallow_writes;
288}
289
290/* data context utility functions */
291
302
305{
306 switch (result.type) {
308 if (result.ptr) {
309 const char *rna_type_name = result.ptr.has_type() ?
310 RNA_struct_identifier(result.ptr.type) :
311 "Unknown";
312 /* Try to get the name property if it exists. */
313 std::string member_name;
314 if (result.ptr.has_type()) {
315 PropertyRNA *name_prop = RNA_struct_name_property(result.ptr.type);
316 if (name_prop) {
317 char name_buf[256];
318 PointerRNA ptr_copy = result.ptr; /* Make a non-const copy. */
320 &ptr_copy, name_prop, name_buf, sizeof(name_buf), nullptr);
321 if (name && name[0] != '\0') {
322 member_name = name;
323 if (name != name_buf) {
324 MEM_delete(name);
325 }
326 }
327 }
328 }
329 /* Format like PyRNA: '<Type("name") at 0xAddress>' or '<Type at 0xAddress>'. */
330 if (!member_name.empty()) {
331 return fmt::format("<{}(\"{}\") at 0x{:x}>",
332 rna_type_name,
333 member_name,
334 reinterpret_cast<uintptr_t>(result.ptr.data));
335 }
336 return fmt::format(
337 "<{} at 0x{:x}>", rna_type_name, reinterpret_cast<uintptr_t>(result.ptr.data));
338 }
339 return "None";
340
342 return fmt::format("[{} item(s)]", result.list.size());
343
345 if (!result.str.is_empty()) {
346 return "\"" + result.str + "\"";
347 }
348 else {
349 return "\"\"";
350 }
351
353 if (result.prop && result.ptr) {
354 const char *prop_name = RNA_property_identifier(result.prop);
355 const char *rna_type_name = result.ptr.has_type() ?
356 RNA_struct_identifier(result.ptr.type) :
357 "Unknown";
358 if (result.index >= 0) {
359 return fmt::format("<Property({}.{}[{}])>", rna_type_name, prop_name, result.index);
360 }
361 return fmt::format("<Property({}.{})>", rna_type_name, prop_name);
362 }
363 return "<Property(None)>";
364
366 if (result.int_value.has_value()) {
367 return std::to_string(result.int_value.value());
368 }
369 else {
370 return "None";
371 }
372 }
373 /* Unhandled context type. Update if new types are added. */
375 return "<UNKNOWN>";
376}
377
380 const char *member,
382 const eContextResult lookup_result)
383{
384 const bool use_logging = CLOG_CHECK(BKE_LOG_CONTEXT, CLG_LEVEL_TRACE) ||
386
387 if (!use_logging) {
388 return;
389 }
390
391 /* If hiding missing is enabled and the member was not found, skip logging. */
392 if (C && bool(C->data.log_flag & CTX_LogFlag::HideMissing)) {
393 if (lookup_result == CTX_RESULT_MEMBER_NOT_FOUND) {
394 return;
395 }
396 }
397
398 std::string value_repr = ctx_result_brief_repr(result);
399 const char *value_desc = value_repr.c_str();
400
401#ifdef WITH_PYTHON
402 /* Get current Python location if available and Python is properly initialized. */
403 std::optional<std::string> python_location;
404 if (CTX_py_init_get(C)) {
405 python_location = BPY_python_current_file_and_line();
406 }
407 const char *location = python_location ? python_location->c_str() : "unknown:0";
408#else
409 const char *location = "unknown:0";
410#endif
411
412 /* Use TRACE level when available, otherwise force output when Python logging is enabled. */
413 const char *format = "%s: %s=%s";
415 CLOG_TRACE(BKE_LOG_CONTEXT, format, location, member, value_desc);
416 }
417 else if (CTX_member_logging_get(C)) {
418 /* Force output at TRACE level even if not enabled via command line. */
419 CLOG_AT_LEVEL_NOCHECK(BKE_LOG_CONTEXT, CLG_LEVEL_TRACE, format, location, member, value_desc);
420 }
421}
422
424 const char *member,
425 const StructRNA *member_type,
426 void *fall_through)
427{
428 void *return_data = nullptr;
429 bool found_member = false;
430
431#ifdef WITH_PYTHON
432 if (CTX_py_dict_get(C)) [[unlikely]] {
434 if (BPY_context_member_get(const_cast<bContext *>(C), member, &result)) {
435 found_member = true;
436
437 if (result.ptr) {
438 if (RNA_struct_is_a(result.ptr.type, member_type)) {
439 return_data = result.ptr.data;
440 }
441 else {
442 CLOG_WARN(&LOG,
443 "PyContext '%s' is a '%s', expected a '%s'",
444 member,
446 RNA_struct_identifier(member_type));
447 }
448 }
449
450 /* Log context member access directly without storing a copy. */
452 }
453 }
454#else
455 UNUSED_VARS(C, member, member_type);
456#endif
457
458 /* If no member was found, use the fallback value and create a simple result for logging. */
459 if (!found_member) {
460 bContextDataResult fallback_result{};
461 fallback_result.ptr.data = fall_through;
462 fallback_result.ptr.type = const_cast<StructRNA *>(
463 member_type); /* Use the expected RNA type */
464 fallback_result.type = ContextDataType::Pointer;
465 return_data = fall_through;
466
467 /* Log fallback context member access. */
468 ctx_member_log_access(C, member, fallback_result, CTX_RESULT_MEMBER_NOT_FOUND);
469 }
470
471 /* Don't allow UI context access from non-main threads. */
472 if (!BLI_thread_is_main()) {
473 return nullptr;
474 }
475
476 return return_data;
477}
478
480{
481 bScreen *screen;
482 ScrArea *area;
483 ARegion *region;
484 int done = 0, recursion = C->data.recursion;
485 int ret = 0;
486
487 *result = {};
488
489 /* NOTE: We'll log access when we have actual results. */
490
491#ifdef WITH_PYTHON
492 if (CTX_py_dict_get(C)) {
493 if (BPY_context_member_get(C, member, result)) {
494 /* Log the Python context result if we're in a temp_override. */
496 return CTX_RESULT_OK;
497 }
498 }
499#endif
500
501 /* Don't allow UI context access from non-main threads or when access has been explicitly denied.
502 */
503 if (!BLI_thread_is_main() || C->data.ui_data_access_deny) {
505 }
506
507 /* we check recursion to ensure that we do not get infinite
508 * loops requesting data from ourselves in a context callback */
509
510 /* Ok, this looks evil...
511 * if (ret) done = -(-ret | -done);
512 *
513 * Values in order of importance
514 * (0, -1, 1) - Where 1 is highest priority
515 */
516 if (done != 1 && recursion < 1 && C->wm.store) {
517 C->data.recursion = 1;
518
519 if (const PointerRNA *ptr = CTX_store_ptr_lookup(C->wm.store, member, nullptr)) {
520 result->ptr = *ptr;
521 done = 1;
522 }
523 else if (std::optional<StringRefNull> str = CTX_store_string_lookup(C->wm.store, member)) {
524 result->str = *str;
526 done = 1;
527 }
528 else if (std::optional<int64_t> int_value = CTX_store_int_lookup(C->wm.store, member)) {
529 result->int_value = int_value;
531 done = 1;
532 }
533 }
534 if (done != 1 && recursion < 2 && (region = CTX_wm_region(C))) {
535 C->data.recursion = 2;
536 if (region->runtime->type && region->runtime->type->context) {
537 ret = region->runtime->type->context(C, member, result);
538 if (ret) {
539 done = -(-ret | -done);
540 }
541 }
542 }
543 if (done != 1 && recursion < 3 && (area = CTX_wm_area(C))) {
544 C->data.recursion = 3;
545 if (area->type && area->type->context) {
546 ret = area->type->context(C, member, result);
547 if (ret) {
548 done = -(-ret | -done);
549 }
550 }
551 }
552
553 if (done != 1 && recursion < 4 && (screen = CTX_wm_screen(C))) {
554 bContextDataCallback cb = reinterpret_cast<bContextDataCallback>(screen->context);
555 C->data.recursion = 4;
556 if (cb) {
557 ret = cb(C, member, result);
558 if (ret) {
559 done = -(-ret | -done);
560 }
561 }
562 }
563
564 C->data.recursion = recursion;
565
566 eContextResult final_result = eContextResult(done);
567
568 /* Log context result if we're in a temp_override and we got a successful or no-data result. */
569 if (ELEM(final_result, CTX_RESULT_OK, CTX_RESULT_NO_DATA)) {
570 ctx_member_log_access(C, member, *result, final_result);
571 }
572
573 return final_result;
574}
575
576static void *ctx_data_pointer_get(const bContext *C, const char *member)
577{
579 if (ctx_data_get(const_cast<bContext *>(C), member, &result) == CTX_RESULT_OK) {
581 return result.ptr.data;
582 }
583
584 return nullptr;
585}
586
587static bool ctx_data_pointer_verify(const bContext *C, const char *member, void **pointer)
588{
590 if (ctx_data_get(const_cast<bContext *>(C), member, &result) == CTX_RESULT_OK) {
592 *pointer = result.ptr.data;
593 return true;
594 }
595
596 *pointer = nullptr;
597 return false;
598}
599
601 const char *member,
603{
605 if (ctx_data_get(const_cast<bContext *>(C), member, &result) == CTX_RESULT_OK) {
607 *list = std::move(result.list);
608 return true;
609 }
610
611 list->clear();
612 return false;
613}
614
616 const char *member,
618{
619 Vector<PointerRNA> ctx_object_list;
620 if ((ctx_data_collection_get(C, member, &ctx_object_list) == false) ||
621 ctx_object_list.is_empty())
622 {
623 list->clear();
624 return false;
625 }
626
628
629 const Main *bmain = CTX_data_main(C);
630 Scene *scene = CTX_data_scene(C);
631 ViewLayer *view_layer = CTX_data_view_layer(C);
632 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
633
634 bool ok = false;
635
636 for (PointerRNA &ctx_object : ctx_object_list) {
637 Object *ob = static_cast<Object *>(ctx_object.data);
638 Base *base = BKE_view_layer_base_find(view_layer, ob);
639 if (base != nullptr) {
640 CTX_data_list_add(&result, &scene->id, RNA_ObjectBase, base);
641 ok = true;
642 }
643 }
645
646 *list = std::move(result.list);
647 return ok;
648}
649
650PointerRNA CTX_data_pointer_get(const bContext *C, const char *member)
651{
653 if (ctx_data_get(const_cast<bContext *>(C), member, &result) == CTX_RESULT_OK) {
655 return result.ptr;
656 }
657
658 return {};
659}
660
661PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type)
662{
663 PointerRNA ptr = CTX_data_pointer_get(C, member);
664
665 if (ptr) {
666 if (RNA_struct_is_a(ptr.type, type)) {
667 return ptr;
668 }
669
670 CLOG_WARN(&LOG,
671 "member '%s' is '%s', not '%s'",
672 member,
675 }
676
677 return {};
678}
679
681{
682 PointerRNA ptr = CTX_data_pointer_get(C, member);
683
684 if (ptr && RNA_struct_is_a(ptr.type, type)) {
685 return ptr;
686 }
687
688 return {};
689}
690
692{
694 if (ctx_data_get(const_cast<bContext *>(C), member, &result) == CTX_RESULT_OK) {
696 return result.list;
697 }
698 return {};
699}
700
702 const char *propname)
703{
704 for (PointerRNA &ptr : collection_pointers) {
705 ptr = RNA_pointer_get(&ptr, propname);
706 }
707}
708
709std::optional<StringRefNull> CTX_data_string_get(const bContext *C, const char *member)
710{
712 if (ctx_data_get(const_cast<bContext *>(C), member, &result) == CTX_RESULT_OK) {
714 return result.str;
715 }
716
717 return {};
718}
719
720std::optional<int64_t> CTX_data_int_get(const bContext *C, const char *member)
721{
723 if (ctx_data_get(const_cast<bContext *>(C), member, &result) == CTX_RESULT_OK) {
725 return result.int_value;
726 }
727
728 return {};
729}
730
731int /*eContextResult*/ CTX_data_get(const bContext *C,
732 const char *member,
733 PointerRNA *r_ptr,
734 Vector<PointerRNA> *r_lb,
735 PropertyRNA **r_prop,
736 int *r_index,
737 StringRef *r_str,
738 std::optional<int64_t> *r_int_value,
739 ContextDataType *r_type)
740{
742 eContextResult ret = ctx_data_get(const_cast<bContext *>(C), member, &result);
743
744 if (ret == CTX_RESULT_OK) {
745 *r_ptr = result.ptr;
746 *r_lb = result.list;
747 *r_prop = result.prop;
748 *r_index = result.index;
749 *r_str = result.str;
750 *r_int_value = result.int_value;
751 *r_type = result.type;
752 }
753 else {
754 *r_ptr = {};
755 r_lb->clear();
756 *r_str = "";
757 *r_int_value = {};
758 *r_type = ContextDataType::Pointer;
759 }
760
761 return ret;
762}
763
764static void data_dir_add(ListBaseT<LinkData> *lb, const char *member, const bool use_all)
765{
766 LinkData *link;
767
768 if ((use_all == false) && STREQ(member, "scene")) { /* exception */
769 return;
770 }
771
772 if (BLI_findstring(lb, member, offsetof(LinkData, data))) {
773 return;
774 }
775
776 link = MEM_new_zeroed<LinkData>(__func__);
777 link->data = const_cast<char *>(member);
778 BLI_addtail(lb, link);
779}
780
781ListBaseT<LinkData> CTX_data_dir_get_ex(const bContext *C,
782 const bool use_store,
783 const bool use_rna,
784 const bool use_all)
785{
787 ListBaseT<LinkData> lb;
788 bScreen *screen;
789 ScrArea *area;
790 ARegion *region;
791 int a;
792
793 memset(&lb, 0, sizeof(lb));
794
795 if (use_rna) {
796 char name_buf[256], *name;
797 int namelen;
798
799 PropertyRNA *iterprop;
801 nullptr, RNA_Context, const_cast<bContext *>(C));
802
803 iterprop = RNA_struct_iterator_property(ctx_ptr.type);
804
805 RNA_PROP_BEGIN (&ctx_ptr, itemptr, iterprop) {
806 name = RNA_struct_name_get_alloc(&itemptr, name_buf, sizeof(name_buf), &namelen);
807 data_dir_add(&lb, name, use_all);
808 if (name != name_buf) {
809 MEM_delete(name);
810 }
811 }
813 }
814 if (use_store && C->wm.store) {
815 for (const bContextStoreEntry &entry : C->wm.store->entries) {
816 data_dir_add(&lb, entry.name.c_str(), use_all);
817 }
818 }
819 if ((region = CTX_wm_region(C)) && region->runtime->type && region->runtime->type->context) {
820 region->runtime->type->context(C, "", &result);
821
822 if (result.dir) {
823 for (a = 0; result.dir[a]; a++) {
824 data_dir_add(&lb, result.dir[a], use_all);
825 }
826 }
827 }
828 if ((area = CTX_wm_area(C)) && area->type && area->type->context) {
829 area->type->context(C, "", &result);
830
831 if (result.dir) {
832 for (a = 0; result.dir[a]; a++) {
833 data_dir_add(&lb, result.dir[a], use_all);
834 }
835 }
836 }
837 if ((screen = CTX_wm_screen(C)) && screen->context) {
838 bContextDataCallback cb = reinterpret_cast<bContextDataCallback>(screen->context);
839 cb(C, "", &result);
840
841 if (result.dir) {
842 for (a = 0; result.dir[a]; a++) {
843 data_dir_add(&lb, result.dir[a], use_all);
844 }
845 }
846 }
847
848 return lb;
849}
850
851ListBaseT<LinkData> CTX_data_dir_get(const bContext *C)
852{
853 return CTX_data_dir_get_ex(C, true, false, false);
854}
855
856bool CTX_data_equals(const char *member, const char *str)
857{
858 return STREQ(member, str);
859}
860
861bool CTX_data_dir(const char *member)
862{
863 return member[0] == '\0';
864}
865
870
872{
873 result->ptr = RNA_pointer_create_discrete(id, type, data);
874}
875
877{
878 result->ptr = *ptr;
879}
880
885
887{
888 result->list.append(RNA_pointer_create_discrete(id, type, data));
889}
890
892{
893 result->list.append(*ptr);
894}
895
896int ctx_data_list_count(const bContext *C, bool (*func)(const bContext *, Vector<PointerRNA> *))
897{
899 if (func(C, &list)) {
900 return list.size();
901 }
902 return 0;
903}
904
906{
907 result->prop = prop;
908 result->index = index;
909}
910
912{
913 result->dir = dir;
914}
915
917{
918 result->type = type;
919}
920
925
926/* window manager context */
927
929{
930 return C->wm.manager;
931}
932
934{
935 return C->wm.manager->runtime->is_interface_locked;
936}
937
939{
940 return static_cast<wmWindow *>(ctx_wm_python_context_get(C, "window", RNA_Window, C->wm.window));
941}
942
944{
945 return static_cast<WorkSpace *>(
946 ctx_wm_python_context_get(C, "workspace", RNA_WorkSpace, C->wm.workspace));
947}
948
950{
951 return static_cast<bScreen *>(ctx_wm_python_context_get(C, "screen", RNA_Screen, C->wm.screen));
952}
953
955{
956 return static_cast<ScrArea *>(ctx_wm_python_context_get(C, "area", RNA_Area, C->wm.area));
957}
958
960{
961 ScrArea *area = CTX_wm_area(C);
962 return (area) ? area->spacedata.first() : nullptr;
963}
964
966{
967 return static_cast<ARegion *>(ctx_wm_python_context_get(C, "region", RNA_Region, C->wm.region));
968}
969
971{
972 ARegion *region = CTX_wm_region(C);
973 return (region) ? region->regiondata : nullptr;
974}
975
977{
978 return C->wm.region_popup;
979}
980
982{
983 return C->wm.gizmo_group;
984}
985
987{
988 return C->wm.manager ? C->wm.manager->runtime->message_bus : nullptr;
989}
990
992{
993 if (C->wm.manager) {
994 return &(C->wm.manager->runtime->reports);
995 }
996
997 return nullptr;
998}
999
1001{
1002 ScrArea *area = CTX_wm_area(C);
1003 if (area && area->spacetype == SPACE_VIEW3D) {
1004 return area->spacedata.first_as<View3D>();
1005 }
1006 return nullptr;
1007}
1008
1010{
1011 ScrArea *area = CTX_wm_area(C);
1012 ARegion *region = CTX_wm_region(C);
1013
1014 if (area && area->spacetype == SPACE_VIEW3D) {
1015 if (region && region->regiontype == RGN_TYPE_WINDOW) {
1016 return static_cast<RegionView3D *>(region->regiondata);
1017 }
1018 }
1019 return nullptr;
1020}
1021
1023{
1024 ScrArea *area = CTX_wm_area(C);
1025 if (area && area->spacetype == SPACE_TEXT) {
1026 return area->spacedata.first_as<SpaceText>();
1027 }
1028 return nullptr;
1029}
1030
1032{
1033 ScrArea *area = CTX_wm_area(C);
1034 if (area && area->spacetype == SPACE_CONSOLE) {
1035 return area->spacedata.first_as<SpaceConsole>();
1036 }
1037 return nullptr;
1038}
1039
1041{
1042 ScrArea *area = CTX_wm_area(C);
1043 if (area && area->spacetype == SPACE_IMAGE) {
1044 return area->spacedata.first_as<SpaceImage>();
1045 }
1046 return nullptr;
1047}
1048
1050{
1051 ScrArea *area = CTX_wm_area(C);
1052 if (area && area->spacetype == SPACE_PROPERTIES) {
1053 return area->spacedata.first_as<SpaceProperties>();
1054 }
1055 return nullptr;
1056}
1057
1059{
1060 ScrArea *area = CTX_wm_area(C);
1061 if (area && area->spacetype == SPACE_FILE) {
1062 return area->spacedata.first_as<SpaceFile>();
1063 }
1064 return nullptr;
1065}
1066
1068{
1069 ScrArea *area = CTX_wm_area(C);
1070 if (area && area->spacetype == SPACE_SEQ) {
1071 return area->spacedata.first_as<SpaceSeq>();
1072 }
1073 return nullptr;
1074}
1075
1077{
1078 ScrArea *area = CTX_wm_area(C);
1079 if (area && area->spacetype == SPACE_OUTLINER) {
1080 return area->spacedata.first_as<SpaceOutliner>();
1081 }
1082 return nullptr;
1083}
1084
1086{
1087 ScrArea *area = CTX_wm_area(C);
1088 if (area && area->spacetype == SPACE_NLA) {
1089 return area->spacedata.first_as<SpaceNla>();
1090 }
1091 return nullptr;
1092}
1093
1095{
1096 ScrArea *area = CTX_wm_area(C);
1097 if (area && area->spacetype == SPACE_NODE) {
1098 return area->spacedata.first_as<SpaceNode>();
1099 }
1100 return nullptr;
1101}
1102
1104{
1105 ScrArea *area = CTX_wm_area(C);
1106 if (area && area->spacetype == SPACE_GRAPH) {
1107 return area->spacedata.first_as<SpaceGraph>();
1108 }
1109 return nullptr;
1110}
1111
1113{
1114 ScrArea *area = CTX_wm_area(C);
1115 if (area && area->spacetype == SPACE_ACTION) {
1116 return area->spacedata.first_as<SpaceAction>();
1117 }
1118 return nullptr;
1119}
1120
1122{
1123 ScrArea *area = CTX_wm_area(C);
1124 if (area && area->spacetype == SPACE_INFO) {
1125 return area->spacedata.first_as<SpaceInfo>();
1126 }
1127 return nullptr;
1128}
1129
1131{
1132 ScrArea *area = CTX_wm_area(C);
1133 if (area && area->spacetype == SPACE_USERPREF) {
1134 return area->spacedata.first_as<SpaceUserPref>();
1135 }
1136 return nullptr;
1137}
1138
1140{
1141 ScrArea *area = CTX_wm_area(C);
1142 if (area && area->spacetype == SPACE_CLIP) {
1143 return area->spacedata.first_as<SpaceClip>();
1144 }
1145 return nullptr;
1146}
1147
1149{
1150 ScrArea *area = CTX_wm_area(C);
1151 if (area && area->spacetype == SPACE_TOPBAR) {
1152 return area->spacedata.first_as<SpaceTopBar>();
1153 }
1154 return nullptr;
1155}
1156
1158{
1159 ScrArea *area = CTX_wm_area(C);
1160 if (area && area->spacetype == SPACE_SPREADSHEET) {
1161 return area->spacedata.first_as<SpaceSpreadsheet>();
1162 }
1163 return nullptr;
1164}
1165
1167{
1168 ScrArea *area = CTX_wm_area(C);
1169 if (area && area->spacetype == SPACE_PROJECT) {
1170 return area->spacedata.first_as<SpaceProject>();
1171 }
1172 return nullptr;
1173}
1174
1176{
1177 C->wm.manager = wm;
1178 C->wm.window = nullptr;
1179 C->wm.screen = nullptr;
1180 C->wm.area = nullptr;
1181 C->wm.region = nullptr;
1182}
1183
1184#ifdef WITH_PYTHON
1185# define PYCTX_REGION_MEMBERS "region", "region_data"
1186# define PYCTX_AREA_MEMBERS "area", "space_data", PYCTX_REGION_MEMBERS
1187# define PYCTX_SCREEN_MEMBERS "screen", PYCTX_AREA_MEMBERS
1188# define PYCTX_WINDOW_MEMBERS "window", "scene", "workspace", PYCTX_SCREEN_MEMBERS
1189#endif
1190
1192{
1193 C->wm.window = win;
1194 if (win) {
1195 C->data.scene = win->scene;
1196 }
1197 C->wm.workspace = (win) ? BKE_workspace_active_get(win->workspace_hook) : nullptr;
1198 C->wm.screen = (win) ? BKE_workspace_active_screen_get(win->workspace_hook) : nullptr;
1199 C->wm.area = nullptr;
1200 C->wm.region = nullptr;
1201
1202#ifdef WITH_PYTHON
1203 if (C->data.py_context != nullptr) {
1204 const char *members[] = {PYCTX_WINDOW_MEMBERS};
1206 &C->data.py_context, C->data.py_context_orig, members, ARRAY_SIZE(members));
1207 }
1208#endif
1209}
1210
1212{
1213 C->wm.screen = screen;
1214 C->wm.area = nullptr;
1215 C->wm.region = nullptr;
1216
1217#ifdef WITH_PYTHON
1218 if (C->data.py_context != nullptr) {
1219 const char *members[] = {PYCTX_SCREEN_MEMBERS};
1221 &C->data.py_context, C->data.py_context_orig, members, ARRAY_SIZE(members));
1222 }
1223#endif
1224}
1225
1227{
1228 C->wm.area = area;
1229 C->wm.region = nullptr;
1230
1231#ifdef WITH_PYTHON
1232 if (C->data.py_context != nullptr) {
1233 const char *members[] = {PYCTX_AREA_MEMBERS};
1235 &C->data.py_context, C->data.py_context_orig, members, ARRAY_SIZE(members));
1236 }
1237#endif
1238}
1239
1241{
1242 C->wm.region = region;
1243
1244#ifdef WITH_PYTHON
1245 if (C->data.py_context != nullptr) {
1246 const char *members[] = {PYCTX_REGION_MEMBERS};
1248 &C->data.py_context, C->data.py_context_orig, members, ARRAY_SIZE(members));
1249 }
1250#endif
1251}
1252
1254{
1255 BLI_assert(region_popup == nullptr || region_popup->regiontype == RGN_TYPE_TEMPORARY);
1256 C->wm.region_popup = region_popup;
1257}
1258
1260{
1261 C->wm.gizmo_group = gzgroup;
1262}
1263
1265{
1266 bContextPollMsgDyn_Params *params = &C->wm.operator_poll_msg_dyn_params;
1267 if (params->free_fn != nullptr) {
1268 params->free_fn(C, params->user_data);
1269 }
1270 params->get_fn = nullptr;
1271 params->free_fn = nullptr;
1272 params->user_data = nullptr;
1273
1274 C->wm.operator_poll_msg = {};
1275}
1277{
1279
1280 C->wm.operator_poll_msg = msg ? std::make_optional(msg) : std::nullopt;
1281}
1283{
1285
1286 C->wm.operator_poll_msg = msg;
1287}
1288
1290{
1292
1293 C->wm.operator_poll_msg_dyn_params = *params;
1294}
1295
1296const char *CTX_wm_operator_poll_msg_get(bContext *C, bool *r_free)
1297{
1298 bContextPollMsgDyn_Params *params = &C->wm.operator_poll_msg_dyn_params;
1299 if (params->get_fn != nullptr) {
1300 char *msg = params->get_fn(C, params->user_data);
1301 if (msg != nullptr) {
1302 *r_free = true;
1303 }
1304 return msg;
1305 }
1306
1307 *r_free = false;
1308 return C->wm.operator_poll_msg ? IFACE_(C->wm.operator_poll_msg->c_str()) : nullptr;
1309}
1310
1311/* data context */
1312
1314{
1315 Main *bmain;
1316 if (ctx_data_pointer_verify(C, "blend_data", reinterpret_cast<void **>(&bmain))) {
1317 return bmain;
1318 }
1319
1320 return C->data.main;
1321}
1322
1324{
1325 C->data.main = bmain;
1327}
1328
1330{
1331 Scene *scene;
1332 if (ctx_data_pointer_verify(C, "scene", reinterpret_cast<void **>(&scene))) {
1333 return scene;
1334 }
1335
1336 return C->data.scene;
1337}
1338
1340{
1341 Scene *scene;
1342 if (ctx_data_pointer_verify(C, "sequencer_scene", reinterpret_cast<void **>(&scene))) {
1343 return scene;
1344 }
1345 WorkSpace *workspace = CTX_wm_workspace(C);
1346 if (workspace) {
1347 return workspace->sequencer_scene;
1348 }
1349 return nullptr;
1350}
1351
1353{
1354 ViewLayer *view_layer;
1355
1356 if (ctx_data_pointer_verify(C, "view_layer", reinterpret_cast<void **>(&view_layer))) {
1357 return view_layer;
1358 }
1359
1360 wmWindow *win = CTX_wm_window(C);
1361 Scene *scene = CTX_data_scene(C);
1362 if (win) {
1363 view_layer = BKE_view_layer_find(scene, win->view_layer_name);
1364 if (view_layer) {
1365 return view_layer;
1366 }
1367 }
1368
1369 return BKE_view_layer_default_view(scene);
1370}
1371
1373{
1374 Scene *scene = CTX_data_scene(C);
1375 return RE_engines_find(scene->r.engine);
1376}
1377
1379{
1380 ViewLayer *view_layer = CTX_data_view_layer(C);
1381 LayerCollection *layer_collection;
1382
1383 if (ctx_data_pointer_verify(C, "layer_collection", reinterpret_cast<void **>(&layer_collection)))
1384 {
1385 if (BKE_view_layer_has_collection(view_layer, layer_collection->collection)) {
1386 return layer_collection;
1387 }
1388 }
1389
1390 /* fallback */
1391 return BKE_layer_collection_get_active(view_layer);
1392}
1393
1395{
1396 Collection *collection;
1397 if (ctx_data_pointer_verify(C, "collection", reinterpret_cast<void **>(&collection))) {
1398 return collection;
1399 }
1400
1401 LayerCollection *layer_collection = CTX_data_layer_collection(C);
1402 if (layer_collection) {
1403 return layer_collection->collection;
1404 }
1405
1406 /* fallback */
1407 Scene *scene = CTX_data_scene(C);
1408 return scene->master_collection;
1409}
1410
1412 const Object *ob,
1413 const eObjectMode object_mode)
1414{
1415 // Object *obedit = CTX_data_edit_object(C);
1416 if (obedit) {
1417 switch (obedit->type) {
1418 case OB_MESH:
1419 return CTX_MODE_EDIT_MESH;
1420 case OB_CURVES_LEGACY:
1421 return CTX_MODE_EDIT_CURVE;
1422 case OB_SURF:
1423 return CTX_MODE_EDIT_SURFACE;
1424 case OB_FONT:
1425 return CTX_MODE_EDIT_TEXT;
1426 case OB_ARMATURE:
1428 case OB_MBALL:
1430 case OB_LATTICE:
1431 return CTX_MODE_EDIT_LATTICE;
1432 case OB_CURVES:
1433 return CTX_MODE_EDIT_CURVES;
1434 case OB_GREASE_PENCIL:
1436 case OB_POINTCLOUD:
1438 default:
1439 break;
1440 }
1441 }
1442 else {
1443 // Object *ob = CTX_data_active_object(C);
1444 if (ob) {
1445 if (object_mode & OB_MODE_POSE) {
1446 return CTX_MODE_POSE;
1447 }
1448 if (object_mode & OB_MODE_SCULPT) {
1449 return CTX_MODE_SCULPT;
1450 }
1451 if (object_mode & OB_MODE_WEIGHT_PAINT) {
1452 return CTX_MODE_PAINT_WEIGHT;
1453 }
1454 if (object_mode & OB_MODE_VERTEX_PAINT) {
1455 return CTX_MODE_PAINT_VERTEX;
1456 }
1457 if (object_mode & OB_MODE_TEXTURE_PAINT) {
1459 }
1460 if (object_mode & OB_MODE_PARTICLE_EDIT) {
1461 return CTX_MODE_PARTICLE;
1462 }
1463 if (object_mode & OB_MODE_PAINT_GREASE_PENCIL) {
1464 if (ob->type == OB_GREASE_PENCIL) {
1466 }
1467 }
1468 if (object_mode & OB_MODE_EDIT_GPENCIL_LEGACY) {
1470 }
1471 if (object_mode & OB_MODE_SCULPT_GREASE_PENCIL) {
1472 if (ob->type == OB_GREASE_PENCIL) {
1474 }
1475 }
1476 if (object_mode & OB_MODE_WEIGHT_GREASE_PENCIL) {
1477 if (ob->type == OB_GREASE_PENCIL) {
1479 }
1480 }
1481 if (object_mode & OB_MODE_VERTEX_GREASE_PENCIL) {
1482 if (ob->type == OB_GREASE_PENCIL) {
1484 }
1485 }
1486 if (object_mode & OB_MODE_SCULPT_CURVES) {
1488 }
1489 }
1490 }
1491
1492 return CTX_MODE_OBJECT;
1493}
1494
1496{
1497 Object *obedit = CTX_data_edit_object(C);
1498 Object *obact = obedit ? nullptr : CTX_data_active_object(C);
1499 return CTX_data_mode_enum_ex(obedit, obact, obact ? obact->mode : OB_MODE_OBJECT);
1500}
1501
1507static const char *data_mode_strings[] = {
1508 "mesh_edit",
1509 "curve_edit",
1510 "surface_edit",
1511 "text_edit",
1512 "armature_edit",
1513 "mball_edit",
1514 "lattice_edit",
1515 "curves_edit",
1516 "grease_pencil_edit",
1517 "pointcloud_edit",
1518 "posemode",
1519 "sculpt_mode",
1520 "weightpaint",
1521 "vertexpaint",
1522 "imagepaint",
1523 "particlemode",
1524 "objectmode",
1525 "greasepencil_paint",
1526 "greasepencil_edit",
1527 "greasepencil_sculpt",
1528 "greasepencil_weight",
1529 "greasepencil_vertex",
1530 "curves_sculpt",
1531 "grease_pencil_paint",
1532 "grease_pencil_sculpt",
1533 "grease_pencil_weight",
1534 "grease_pencil_vertex",
1535 nullptr,
1536};
1538 "Must have a string for each context mode")
1539const char *CTX_data_mode_string(const bContext *C)
1540{
1542}
1543
1545{
1546 C->data.scene = scene;
1547
1548#ifdef WITH_PYTHON
1549 if (C->data.py_context != nullptr) {
1550 const char *members[] = {"scene"};
1551 BPY_context_dict_clear_members_array(&C->data.py_context, C->data.py_context_orig, members, 1);
1552 }
1553#endif
1554}
1555
1557{
1558 C->data.ui_data_access_deny = deny;
1559}
1560
1562{
1563 ToolSettings *toolsettings;
1564 if (ctx_data_pointer_verify(C, "tool_settings", reinterpret_cast<void **>(&toolsettings))) {
1565 return toolsettings;
1566 }
1567
1568 Scene *scene = CTX_data_scene(C);
1569 if (scene) {
1570 return scene->toolsettings;
1571 }
1572
1573 return nullptr;
1574}
1575
1577{
1578 return ctx_data_collection_get(C, "selected_ids", list);
1579}
1580
1582{
1583 return ctx_data_collection_get(C, "selected_nodes", list);
1584}
1585
1587{
1588 return ctx_data_collection_get(C, "selected_editable_objects", list);
1589}
1590
1592{
1593 return ctx_data_base_collection_get(C, "selected_editable_objects", list);
1594}
1595
1597{
1598 return ctx_data_collection_get(C, "editable_objects", list);
1599}
1600
1602{
1603 return ctx_data_base_collection_get(C, "editable_objects", list);
1604}
1605
1607{
1608 return ctx_data_collection_get(C, "selected_objects", list);
1609}
1610
1612{
1613 return ctx_data_base_collection_get(C, "selected_objects", list);
1614}
1615
1617{
1618 return ctx_data_collection_get(C, "visible_objects", list);
1619}
1620
1622{
1623 return ctx_data_base_collection_get(C, "visible_objects", list);
1624}
1625
1627{
1628 return ctx_data_collection_get(C, "selectable_objects", list);
1629}
1630
1632{
1633 return ctx_data_base_collection_get(C, "selectable_objects", list);
1634}
1635
1637{
1638 return static_cast<Object *>(ctx_data_pointer_get(C, "active_object"));
1639}
1640
1642{
1644
1645 if (ob == nullptr) {
1646 return nullptr;
1647 }
1648
1649 const Main *bmain = CTX_data_main(C);
1650 const Scene *scene = CTX_data_scene(C);
1651 ViewLayer *view_layer = CTX_data_view_layer(C);
1652 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
1653 return BKE_view_layer_base_find(view_layer, ob);
1654}
1655
1657{
1658 return static_cast<Object *>(ctx_data_pointer_get(C, "edit_object"));
1659}
1660
1662{
1663 return static_cast<Image *>(ctx_data_pointer_get(C, "edit_image"));
1664}
1665
1667{
1668 return static_cast<Text *>(ctx_data_pointer_get(C, "edit_text"));
1669}
1670
1672{
1673 return static_cast<MovieClip *>(ctx_data_pointer_get(C, "edit_movieclip"));
1674}
1675
1677{
1678 return static_cast<Mask *>(ctx_data_pointer_get(C, "edit_mask"));
1679}
1680
1682{
1683 return static_cast<EditBone *>(ctx_data_pointer_get(C, "active_bone"));
1684}
1685
1687{
1688 return static_cast<CacheFile *>(ctx_data_pointer_get(C, "edit_cachefile"));
1689}
1690
1692{
1693 return ctx_data_collection_get(C, "selected_bones", list);
1694}
1695
1697{
1698 return ctx_data_collection_get(C, "selected_editable_bones", list);
1699}
1700
1702{
1703 return ctx_data_collection_get(C, "visible_bones", list);
1704}
1705
1707{
1708 return ctx_data_collection_get(C, "editable_bones", list);
1709}
1710
1712{
1713 return static_cast<bPoseChannel *>(ctx_data_pointer_get(C, "active_pose_bone"));
1714}
1715
1717{
1718 return CTX_data_pointer_get(C, "active_pose_bone");
1719}
1720
1722{
1723 return ctx_data_collection_get(C, "selected_pose_bones", list);
1724}
1725
1727{
1728 return ctx_data_collection_get(C, "selected_pose_bones_from_active_object", list);
1729}
1730
1732{
1733 return ctx_data_collection_get(C, "visible_pose_bones", list);
1734}
1735
1737{
1738 return static_cast<AssetLibraryReference *>(ctx_data_pointer_get(C, "asset_library_reference"));
1739}
1740
1745
1747{
1748 Main *bmain = CTX_data_main(C);
1749 Scene *scene = CTX_data_scene(C);
1750 ViewLayer *view_layer = CTX_data_view_layer(C);
1751 Depsgraph *depsgraph = BKE_scene_ensure_depsgraph(bmain, scene, view_layer);
1752 /* Dependency graph might have been just allocated, and hence it will not be marked.
1753 * This confuses redo system due to the lack of flushing changes back to the original data.
1754 * In the future we would need to check whether the CTX_wm_window(C) is in editing mode (as an
1755 * opposite of playback-preview-only) and set active flag based on that. */
1756 DEG_make_active(depsgraph);
1757 return depsgraph;
1758}
1759
1761{
1762 Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
1763 /* TODO(sergey): Assert that the dependency graph is fully evaluated.
1764 * Note that first the depsgraph and scene post-evaluation hooks needs to run extra round of
1765 * updates first to make check here really reliable. */
1766 return depsgraph;
1767}
1768
1769Depsgraph *CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check)
1770{
1771 Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
1772 if (rna_write_check && !CTX_member_rna_write_check(C)) {
1773 return depsgraph;
1774 }
1776
1777 Main *bmain = CTX_data_main(C);
1778 BKE_scene_graph_evaluated_ensure(depsgraph, bmain);
1779 return depsgraph;
1780}
1781
1783{
1784 Scene *scene = CTX_data_scene(C);
1785 ViewLayer *view_layer = CTX_data_view_layer(C);
1786 return BKE_scene_get_depsgraph(scene, view_layer);
1787}
1788
1790{
1791 C->data.log_flag = flag;
1792}
1793
1795{
1796 /* Needed by Python bindings to get the full flags value, since bContext is only forward
1797 * declared in the header file and cannot be accessed directly from Python code. */
1798 return C->data.log_flag;
1799}
1800
1802{
1803 return (C->data.log_flag & CTX_LogFlag::Access) != CTX_LogFlag(0);
1804}
1805
1807{
1808 return C->data.rna_disallow_writes ? !(*C->data.rna_disallow_writes) : true;
1809}
1810
1811} // namespace blender
#define CTX_MODE_NUM
#define IFACE_(msgid)
#define CLOG_WARN(clg_ref,...)
Definition CLG_log.h:189
#define CLOG_AT_LEVEL_NOCHECK(clg_ref, verbose_level,...)
Definition CLG_log.h:159
#define CLOG_CHECK(clg_ref, verbose_level,...)
Definition CLG_log.h:147
@ CLG_LEVEL_TRACE
Definition CLG_log.h:64
#define CLOG_TRACE(clg_ref,...)
Definition CLG_log.h:192
Object groups, one object can be in many groups at once.
Object is a sort of wrapper for general info.
Read Blender memory allocation and freeing.
#define RNA_PROP_END
#define RNA_PROP_BEGIN(sptr, itemptr, prop)
#define C
Definition RandGen.cpp:29
#define BLI_assert_unreachable()
#define UNUSED_VARS(...)
#define ELEM(...)
#define STREQ(a, b)
bool is_empty() const
#define offsetof(t, d)
#define str(s)
#define T
BMesh Iterators.
bool CTX_data_selected_ids(const bContext *C, Vector< PointerRNA > *list)
char * RNA_property_string_get_alloc(PointerRNA *ptr, PropertyRNA *prop, char *fixedbuf, int fixedlen, int *r_len)
SpaceNla * CTX_wm_space_nla(const bContext *C)
static const char * data_mode_strings[]
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
const char * CTX_data_mode_string(const bContext *C)
Vector< PointerRNA > CTX_data_collection_get(const bContext *C, const char *member)
static bContextStore * ctx_store_extend(Vector< std::unique_ptr< bContextStore > > &contexts)
static void ctx_member_log_access(const bContext *C, const char *member, const bContextDataResult &result, const eContextResult lookup_result)
ScrArea * CTX_wm_area(const bContext *C)
__int64 int64_t
Definition BKE_text.h:90
void * CTX_py_dict_get(const bContext *C)
BLI_STATIC_ASSERT(ARRAY_SIZE(data_mode_strings)==CTX_MODE_NUM+1, "Must have a string for each context mode") const char *CTX_data_mode_string(const bContext *C)
bool CTX_data_editable_bases(const bContext *C, Vector< PointerRNA > *list)
SpaceAction * CTX_wm_space_action(const bContext *C)
bool CTX_data_selected_bases(const bContext *C, Vector< PointerRNA > *list)
bool CTX_data_visible_bases(const bContext *C, Vector< PointerRNA > *list)
Scene * CTX_data_sequencer_scene(const bContext *C)
static void * ctx_data_pointer_get(const bContext *C, const char *member)
const PointerRNA * CTX_store_ptr_lookup(const bContextStore *store, StringRef name, const StructRNA *type=nullptr)
bool CTX_py_init_get(const bContext *C)
wmGizmoGroup * CTX_wm_gizmo_group(const bContext *C)
void CTX_data_dir_set(bContextDataResult *result, const char **dir)
bool RNA_struct_is_a(const StructRNA *type, const StructRNA *srna)
void BPY_context_dict_clear_members_array(void **dict_p, void *dict_orig, const char *context_members[], uint context_members_len)
bool DEG_is_fully_evaluated(const Depsgraph *depsgraph)
CacheFile * CTX_data_edit_cachefile(const bContext *C)
const T * ctx_store_lookup_impl(const bContextStore *store, const StringRef name)
SpaceConsole * CTX_wm_space_console(const bContext *C)
Depsgraph * BKE_scene_get_depsgraph(const Scene *scene, const ViewLayer *view_layer)
Definition scene.cc:3631
WorkSpace * CTX_wm_workspace(const bContext *C)
SpaceOutliner * CTX_wm_space_outliner(const bContext *C)
void BKE_sound_refresh_callback_bmain(Main *bmain)
PointerRNA RNA_id_pointer_create(ID *id)
LayerCollection * BKE_layer_collection_get_active(ViewLayer *view_layer)
std::optional< std::string > BPY_python_current_file_and_line()
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
const char * RNA_property_identifier(const PropertyRNA *prop)
class asset_system::AssetRepresentation * CTX_wm_asset(const bContext *C)
static bool ctx_data_base_collection_get(const bContext *C, const char *member, Vector< PointerRNA > *list)
void CTX_wm_window_set(bContext *C, wmWindow *win)
SpaceClip * CTX_wm_space_clip(const bContext *C)
SpaceTopBar * CTX_wm_space_topbar(const bContext *C)
CTX_LogFlag CTX_member_logging_flag_get(const bContext *C)
bContextStore * CTX_store_add(Vector< std::unique_ptr< bContextStore > > &contexts, StringRef name, const PointerRNA *ptr)
Image * CTX_data_edit_image(const bContext *C)
SpaceUserPref * CTX_wm_space_userpref(const bContext *C)
bool CTX_data_selected_bones(const bContext *C, Vector< PointerRNA > *list)
void * BLI_findstring(const ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:615
wmWindow * CTX_wm_window(const bContext *C)
void CTX_py_init_set(bContext *C, bool value)
char * RNA_struct_name_get_alloc(PointerRNA *ptr, char *fixedbuf, int fixedlen, int *r_len)
enum eContextObjectMode CTX_data_mode_enum(const bContext *C)
static std::string ctx_result_brief_repr(const bContextDataResult &result)
PropertyRNA * RNA_struct_iterator_property(StructRNA *type)
bScreen * BKE_workspace_active_screen_get(const WorkSpaceInstanceHook *hook) GETTER_ATTRS
Definition workspace.cc:684
void DEG_make_active(Depsgraph *depsgraph)
Definition depsgraph.cc:337
bool CTX_member_logging_get(const bContext *C)
bool CTX_data_equals(const char *member, const char *str)
RenderEngineType * CTX_data_engine_type(const bContext *C)
Text * CTX_data_edit_text(const bContext *C)
void * CTX_wm_region_data(const bContext *C)
CLG_LogRef * BKE_LOG_CONTEXT
Base * CTX_data_active_base(const bContext *C)
std::optional< StringRefNull > CTX_data_string_get(const bContext *C, const char *member)
@ CTX_MODE_VERTEX_GREASE_PENCIL
@ CTX_MODE_PARTICLE
@ CTX_MODE_EDIT_TEXT
@ CTX_MODE_EDIT_SURFACE
@ CTX_MODE_PAINT_VERTEX
@ CTX_MODE_EDIT_GPENCIL_LEGACY
@ CTX_MODE_SCULPT_CURVES
@ CTX_MODE_EDIT_ARMATURE
@ CTX_MODE_SCULPT
@ CTX_MODE_EDIT_CURVES
@ CTX_MODE_EDIT_LATTICE
@ CTX_MODE_PAINT_GREASE_PENCIL
@ CTX_MODE_SCULPT_GREASE_PENCIL
@ CTX_MODE_EDIT_POINTCLOUD
@ CTX_MODE_EDIT_MESH
@ CTX_MODE_PAINT_TEXTURE
@ CTX_MODE_EDIT_METABALL
@ CTX_MODE_OBJECT
@ CTX_MODE_EDIT_GREASE_PENCIL
@ CTX_MODE_WEIGHT_GREASE_PENCIL
@ CTX_MODE_EDIT_CURVE
@ CTX_MODE_PAINT_WEIGHT
ViewLayer * BKE_view_layer_default_view(const Scene *scene)
ViewLayer * CTX_data_view_layer(const bContext *C)
SpaceSeq * CTX_wm_space_seq(const bContext *C)
void BKE_scene_graph_evaluated_ensure(Depsgraph *depsgraph, Main *bmain)
Definition scene.cc:2872
bContext * CTX_create()
static eContextResult ctx_data_get(bContext *C, const char *member, bContextDataResult *result)
WorkSpace * BKE_workspace_active_get(WorkSpaceInstanceHook *hook) GETTER_ATTRS
Definition workspace.cc:633
EditBone * CTX_data_active_bone(const bContext *C)
const bContextStore * CTX_store_get(const bContext *C)
void CTX_data_id_pointer_set(bContextDataResult *result, ID *id)
SpaceText * CTX_wm_space_text(const bContext *C)
bContextStore * CTX_store_add_all(Vector< std::unique_ptr< bContextStore > > &contexts, const bContextStore *context)
void CTX_wm_operator_poll_msg_set(bContext *C, const char *msg)
void * CTX_py_dict_get_orig(const bContext *C)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
int(*)(const bContext *C, const char *member, bContextDataResult *result) bContextDataCallback
void CTX_wm_screen_set(bContext *C, bScreen *screen)
std::optional< int64_t > CTX_store_int_lookup(const bContextStore *store, StringRef name)
int ctx_data_list_count(const bContext *C, bool(*func)(const bContext *, Vector< PointerRNA > *))
bool CTX_data_visible_objects(const bContext *C, Vector< PointerRNA > *list)
static bool ctx_data_pointer_verify(const bContext *C, const char *member, void **pointer)
void CTX_data_type_set(bContextDataResult *result, ContextDataType type)
@ OB_MODE_VERTEX_GREASE_PENCIL
@ OB_MODE_TEXTURE_PAINT
@ OB_MODE_SCULPT_GREASE_PENCIL
@ OB_MODE_SCULPT_CURVES
@ OB_MODE_EDIT_GPENCIL_LEGACY
@ OB_MODE_PARTICLE_EDIT
@ OB_MODE_WEIGHT_GREASE_PENCIL
@ OB_MODE_PAINT_GREASE_PENCIL
BMesh const char void * data
SpaceInfo * CTX_wm_space_info(const bContext *C)
int CTX_data_get(const bContext *C, const char *member, PointerRNA *r_ptr, Vector< PointerRNA > *r_lb, PropertyRNA **r_prop, int *r_index, StringRef *r_str, std::optional< int64_t > *r_int_value, ContextDataType *r_type)
PointerRNA CTX_data_active_pose_bone_ptr(const bContext *C)
PointerRNA CTX_data_pointer_get(const bContext *C, const char *member)
wmWindowManager * CTX_wm_manager(const bContext *C)
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check=false)
bool CTX_data_visible_pose_bones(const bContext *C, Vector< PointerRNA > *list)
void CTX_data_pointer_set_ptr(bContextDataResult *result, const PointerRNA *ptr)
Object * CTX_data_edit_object(const bContext *C)
void CTX_data_pointer_set(bContextDataResult *result, ID *id, StructRNA *type, void *data)
static void data_dir_add(ListBaseT< LinkData > *lb, const char *member, const bool use_all)
void CTX_free(bContext *C)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
bool CTX_member_rna_write_check(const bContext *C)
PointerRNA CTX_data_pointer_get_type_silent(const bContext *C, const char *member, StructRNA *type)
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
MovieClip * CTX_data_edit_movieclip(const bContext *C)
int BLI_thread_is_main()
Definition threads.cc:184
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
SpaceNode * CTX_wm_space_node(const bContext *C)
static void * ctx_wm_python_context_get(const bContext *C, const char *member, const StructRNA *member_type, void *fall_through)
bool BPY_context_member_get(bContext *C, const char *member, bContextDataResult *result)
Mask * CTX_data_edit_mask(const bContext *C)
SpaceGraph * CTX_wm_space_graph(const bContext *C)
bool CTX_data_selected_editable_objects(const bContext *C, Vector< PointerRNA > *list)
const char * CTX_wm_operator_poll_msg_get(bContext *C, bool *r_free)
RegionView3D * CTX_wm_region_view3d(const bContext *C)
ToolSettings * CTX_data_tool_settings(const bContext *C)
void CTX_wm_region_popup_set(bContext *C, ARegion *region_popup)
bool CTX_data_selected_pose_bones_from_active_object(const bContext *C, Vector< PointerRNA > *list)
bContext * CTX_copy(const bContext *C)
PropertyRNA * RNA_struct_name_property(const StructRNA *type)
bool CTX_data_selected_pose_bones(const bContext *C, Vector< PointerRNA > *list)
wmMsgBus * CTX_wm_message_bus(const bContext *C)
bool CTX_data_selected_nodes(const bContext *C, Vector< PointerRNA > *list)
RenderEngineType * RE_engines_find(const char *idname)
bool CTX_data_dir(const char *member)
PointerRNA RNA_pointer_get(PointerRNA *ptr, const char *name)
_W64 unsigned int uintptr_t
Definition BKE_text.h:120
void CTX_rna_disallow_write_set_p(bContext *C, const bool *rna_disallow_writes)
void CTX_py_state_push(bContext *C, bContext_PyState *pystate, void *value)
const char * RNA_struct_identifier(const StructRNA *type)
ListBaseT< LinkData > CTX_data_dir_get_ex(const bContext *C, bool use_store, bool use_rna, bool use_all)
void CTX_py_state_pop(bContext *C, bContext_PyState *pystate)
SpaceImage * CTX_wm_space_image(const bContext *C)
SpaceLink * CTX_wm_space_data(const bContext *C)
ViewLayer * BKE_view_layer_find(const Scene *scene, const char *layer_name)
Depsgraph * CTX_data_depsgraph_on_load(const bContext *C)
Depsgraph * CTX_data_expect_evaluated_depsgraph(const bContext *C)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
Main * CTX_data_main(const bContext *C)
void CTX_wm_operator_poll_msg_set_dynamic(bContext *C, const bContextPollMsgDyn_Params *params)
void CTX_data_collection_remap_property(MutableSpan< PointerRNA > collection_pointers, const char *propname)
ARegion * CTX_wm_region_popup(const bContext *C)
void CTX_data_id_list_add(bContextDataResult *result, ID *id)
bool CTX_data_selected_editable_bones(const bContext *C, Vector< PointerRNA > *list)
Base * BKE_view_layer_base_find(ViewLayer *view_layer, Object *ob)
bPoseChannel * CTX_data_active_pose_bone(const bContext *C)
bool CTX_data_editable_bones(const bContext *C, Vector< PointerRNA > *list)
void CTX_wm_manager_set(bContext *C, wmWindowManager *wm)
static CLG_LogRef LOG
Definition logging.cpp:12
std::optional< StringRefNull > CTX_store_string_lookup(const bContextStore *store, StringRef name)
void CTX_data_list_add_ptr(bContextDataResult *result, const PointerRNA *ptr)
SpaceFile * CTX_wm_space_file(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
bScreen * CTX_wm_screen(const bContext *C)
void CTX_wm_region_set(bContext *C, ARegion *region)
void CTX_data_main_set(bContext *C, Main *bmain)
Depsgraph * BKE_scene_ensure_depsgraph(Main *bmain, Scene *scene, ViewLayer *view_layer)
Definition scene.cc:3644
SpaceSpreadsheet * CTX_wm_space_spreadsheet(const bContext *C)
ListBaseT< LinkData > CTX_data_dir_get(const bContext *C)
void CTX_data_prop_set(bContextDataResult *result, PropertyRNA *prop, int index)
std::optional< int64_t > CTX_data_int_get(const bContext *C, const char *member)
SpaceProject * CTX_wm_space_project(const bContext *C)
@ CTX_RESULT_MEMBER_NOT_FOUND
@ CTX_RESULT_NO_DATA
void CTX_data_list_add(bContextDataResult *result, ID *id, StructRNA *type, void *data)
bool CTX_data_visible_bones(const bContext *C, Vector< PointerRNA > *list)
bool CTX_data_selected_objects(const bContext *C, Vector< PointerRNA > *list)
void CTX_data_ui_context_access_deny(bContext *C, bool deny)
void CTX_store_set(bContext *C, const bContextStore *store)
void CTX_member_logging_flag_set(bContext *C, CTX_LogFlag flag)
ReportList * CTX_wm_reports(const bContext *C)
bool CTX_data_selectable_objects(const bContext *C, Vector< PointerRNA > *list)
bool CTX_data_selected_editable_bases(const bContext *C, Vector< PointerRNA > *list)
bool CTX_wm_interface_locked(const bContext *C)
SpaceProperties * CTX_wm_space_properties(const bContext *C)
ContextDataType CTX_data_type_get(bContextDataResult *result)
Object * CTX_data_active_object(const bContext *C)
void CTX_wm_operator_poll_msg_clear(bContext *C)
void CTX_wm_gizmo_group_set(bContext *C, wmGizmoGroup *gzgroup)
ARegion * CTX_wm_region(const bContext *C)
static bool ctx_data_collection_get(const bContext *C, const char *member, Vector< PointerRNA > *list)
CLG_LOGREF_DECLARE_GLOBAL(BKE_LOG_CONTEXT, "context")
PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type)
void CTX_data_scene_set(bContext *C, Scene *scene)
View3D * CTX_wm_view3d(const bContext *C)
bool BKE_view_layer_has_collection(const ViewLayer *view_layer, const Collection *collection)
bool CTX_data_selectable_bases(const bContext *C, Vector< PointerRNA > *list)
LayerCollection * CTX_data_layer_collection(const bContext *C)
const AssetLibraryReference * CTX_wm_asset_library_ref(const bContext *C)
Collection * CTX_data_collection(const bContext *C)
bool CTX_data_editable_objects(const bContext *C, Vector< PointerRNA > *list)
void CTX_wm_area_set(bContext *C, ScrArea *area)
enum eContextObjectMode CTX_data_mode_enum_ex(const Object *obedit, const Object *ob, eObjectMode object_mode)
bContextDataCallback context
bke::ARegionRuntime * runtime
eRegion_Type regiontype
struct Collection * collection
StructRNA * type
Definition RNA_types.hh:63
struct Collection * master_collection
struct RenderData r
struct ToolSettings * toolsettings
ListBaseT< SpaceLink > spacedata
struct SpaceType * type
bContextDataCallback context
struct Scene * sequencer_scene
char *(*) get_fn(bContext *C, void *user_data)
void(*) free_fn(bContext *C, void *user_data)
Vector< bContextStoreEntry > entries
const bContextStore * store
std::optional< std::string > operator_poll_msg
bContextPollMsgDyn_Params operator_poll_msg_dyn_params
struct blender::bContext::@375357320202003026027156133251050270266311335321 wm
struct ARegionType * type
struct WorkSpaceInstanceHook * workspace_hook