Blender V5.3
view3d_context.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2008 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "DNA_object_types.h"
10#include "DNA_screen_types.h"
11#include "DNA_space_types.h"
12
13#include "BKE_context.hh"
14#include "BKE_layer.hh"
15#include "BKE_screen.hh"
16
17#include "ED_view3d.hh"
18
19#include "view3d_intern.hh"
20
21namespace blender {
22
23/* -------------------------------------------------------------------- */
26
27const char *view3d_context_dir[] = {
28 "active_object",
29 "selected_ids",
30 nullptr,
31};
32
33int view3d_context(const bContext *C, const char *member, bContextDataResult *result)
34{
35 /* fall back to the scene layer,
36 * allows duplicate and other object operators to run outside the 3d view */
37
38 if (CTX_data_dir(member)) {
40 return CTX_RESULT_OK;
41 }
42 if (CTX_data_equals(member, "active_object")) {
43 /* In most cases the active object is the `view_layer->basact->object`.
44 * For the 3D view however it can be nullptr when hidden.
45 *
46 * This is ignored in the case the object is in any mode (besides object-mode),
47 * since the object's mode impacts the current tool, cursor, gizmos etc.
48 * If we didn't have this exception, changing visibility would need to perform
49 * many of the same updates as changing the objects mode.
50 *
51 * Further, there are multiple ways to hide objects - by collection, by object type, etc.
52 * it's simplest if all these methods behave consistently - respecting the object-mode
53 * without showing the object.
54 *
55 * See #85532 for alternatives that were considered. */
56 const Main *bmain = CTX_data_main(C);
57 const Scene *scene = CTX_data_scene(C);
58 ViewLayer *view_layer = CTX_data_view_layer(C);
59 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
60 Base *base = BKE_view_layer_active_base_get(view_layer);
61 if (base) {
62 Object *ob = base->object;
63 /* if hidden but in edit mode, we still display, can happen with animation */
65 (ob->mode != OB_MODE_OBJECT))
66 {
68 }
69 }
70
71 return CTX_RESULT_OK;
72 }
73 if (CTX_data_equals(member, "selected_ids")) {
74 Vector<PointerRNA> selected_objects;
75 CTX_data_selected_objects(C, &selected_objects);
76 for (const PointerRNA &ptr : selected_objects) {
77 ID *selected_id = ptr.owner_id;
78 CTX_data_id_list_add(result, selected_id);
79 }
81 return CTX_RESULT_OK;
82 }
83
85}
86
88
89/* -------------------------------------------------------------------- */
92
94{
96
97 if (rv3d == nullptr) {
98 ScrArea *area = CTX_wm_area(C);
99 if (area && area->spacetype == SPACE_VIEW3D) {
101 if (region) {
102 rv3d = static_cast<RegionView3D *>(region->regiondata);
103 }
104 }
105 }
106 return rv3d;
107}
108
110{
111 ScrArea *area = CTX_wm_area(C);
112
113 *r_v3d = nullptr;
114 *r_region = nullptr;
115
116 if (area && area->spacetype == SPACE_VIEW3D) {
117 ARegion *region = CTX_wm_region(C);
118 View3D *v3d = area->spacedata.first_as<View3D>();
119
120 if (region) {
121 RegionView3D *rv3d;
122 if ((region->regiontype == RGN_TYPE_WINDOW) &&
123 (rv3d = static_cast<RegionView3D *>(region->regiondata)) &&
124 (rv3d->viewlock & RV3D_LOCK_ROTATION) == 0)
125 {
126 *r_v3d = v3d;
127 *r_region = region;
128 return true;
129 }
130
131 if (ED_view3d_area_user_region(area, v3d, r_region)) {
132 *r_v3d = v3d;
133 return true;
134 }
135 }
136 }
137
138 return false;
139}
140
142
143} // namespace blender
Object is a sort of wrapper for general info.
#define C
Definition RandGen.cpp:29
BMesh Iterators.
bool ED_view3d_context_user_region(bContext *C, View3D **r_v3d, ARegion **r_region)
ARegion * BKE_area_find_region_active_win(const ScrArea *area)
Definition screen.cc:1037
ScrArea * CTX_wm_area(const bContext *C)
void CTX_data_dir_set(bContextDataResult *result, const char **dir)
@ BASE_ENABLED_AND_MAYBE_VISIBLE_IN_VIEWPORT
Base * BKE_view_layer_active_base_get(ViewLayer *view_layer)
RegionView3D * ED_view3d_context_rv3d(bContext *C)
bool CTX_data_equals(const char *member, const char *str)
ViewLayer * CTX_data_view_layer(const bContext *C)
void CTX_data_id_pointer_set(bContextDataResult *result, ID *id)
int view3d_context(const bContext *C, const char *member, bContextDataResult *result)
void CTX_data_type_set(bContextDataResult *result, ContextDataType type)
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
RegionView3D * CTX_wm_region_view3d(const bContext *C)
const char * view3d_context_dir[]
bool CTX_data_dir(const char *member)
Main * CTX_data_main(const bContext *C)
void CTX_data_id_list_add(bContextDataResult *result, ID *id)
Scene * CTX_data_scene(const bContext *C)
@ CTX_RESULT_MEMBER_NOT_FOUND
bool ED_view3d_area_user_region(const ScrArea *area, const View3D *v3d, ARegion **r_region)
bool CTX_data_selected_objects(const bContext *C, Vector< PointerRNA > *list)
ARegion * CTX_wm_region(const bContext *C)
eRegion_Type regiontype
struct Object * object
eRegionView3D_ViewLock viewlock
ListBaseT< SpaceLink > spacedata