Remove "_base*" from context API
We are not exposing RNA_ObjectBase in the 2.80 API. Thus we can't have operators relying on it (e.g, CTX_data_visible_bases, CTX_data_active_base, ...). Otherwise users won't be able to override context for these operators. This commit keep the CTX_data_.*bases() functions around so we don't need to change the operators and potentially break things that late into 2.80. However as far as the Python scripters are concerned there is no base to be overriden, ever. That also simplify the guessing game addon developers have to play when trying to override an operatori context. They still need to find whether an operator requires editables, visibles, selected, ... objects. But at least they don't need to find out whether the operators need base or object.
This commit is contained in:
@@ -399,6 +399,41 @@ static int ctx_data_collection_get(const bContext *C, const char *member, ListBa
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ctx_data_base_collection_get(const bContext *C, const char *member, ListBase *list)
|
||||
{
|
||||
ListBase ctx_object_list;
|
||||
bool ok = false;
|
||||
|
||||
if (!ctx_data_collection_get(C, member, &ctx_object_list)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (BLI_listbase_is_empty(&ctx_object_list)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bContextDataResult result;
|
||||
memset(&result, 0, sizeof(bContextDataResult));
|
||||
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
ViewLayer *view_layer = CTX_data_view_layer(C);
|
||||
|
||||
CollectionPointerLink *ctx_object;
|
||||
for (ctx_object = ctx_object_list.first; ctx_object; ctx_object = ctx_object->next) {
|
||||
Object *ob = ctx_object->ptr.data;
|
||||
Base *base = BKE_view_layer_base_find(view_layer, ob);
|
||||
if (base != NULL) {
|
||||
CTX_data_list_add(&result, &scene->id, &RNA_ObjectBase, base);
|
||||
ok = true;
|
||||
}
|
||||
}
|
||||
CTX_data_type_set(&result, CTX_DATA_TYPE_COLLECTION);
|
||||
BLI_freelistN(&ctx_object_list);
|
||||
|
||||
*list = result.list;
|
||||
return ok;
|
||||
}
|
||||
|
||||
PointerRNA CTX_data_pointer_get(const bContext *C, const char *member)
|
||||
{
|
||||
bContextDataResult result;
|
||||
@@ -1150,7 +1185,7 @@ int CTX_data_selected_editable_objects(const bContext *C, ListBase *list)
|
||||
|
||||
int CTX_data_selected_editable_bases(const bContext *C, ListBase *list)
|
||||
{
|
||||
return ctx_data_collection_get(C, "selected_editable_bases", list);
|
||||
return ctx_data_base_collection_get(C, "selected_editable_objects", list);
|
||||
}
|
||||
|
||||
int CTX_data_editable_objects(const bContext *C, ListBase *list)
|
||||
@@ -1160,7 +1195,7 @@ int CTX_data_editable_objects(const bContext *C, ListBase *list)
|
||||
|
||||
int CTX_data_editable_bases(const bContext *C, ListBase *list)
|
||||
{
|
||||
return ctx_data_collection_get(C, "editable_bases", list);
|
||||
return ctx_data_base_collection_get(C, "editable_objects", list);
|
||||
}
|
||||
|
||||
int CTX_data_selected_objects(const bContext *C, ListBase *list)
|
||||
@@ -1170,7 +1205,7 @@ int CTX_data_selected_objects(const bContext *C, ListBase *list)
|
||||
|
||||
int CTX_data_selected_bases(const bContext *C, ListBase *list)
|
||||
{
|
||||
return ctx_data_collection_get(C, "selected_bases", list);
|
||||
return ctx_data_base_collection_get(C, "selected_objects", list);
|
||||
}
|
||||
|
||||
int CTX_data_visible_objects(const bContext *C, ListBase *list)
|
||||
@@ -1180,7 +1215,7 @@ int CTX_data_visible_objects(const bContext *C, ListBase *list)
|
||||
|
||||
int CTX_data_visible_bases(const bContext *C, ListBase *list)
|
||||
{
|
||||
return ctx_data_collection_get(C, "visible_bases", list);
|
||||
return ctx_data_base_collection_get(C, "visible_objects", list);
|
||||
}
|
||||
|
||||
int CTX_data_selectable_objects(const bContext *C, ListBase *list)
|
||||
@@ -1190,7 +1225,7 @@ int CTX_data_selectable_objects(const bContext *C, ListBase *list)
|
||||
|
||||
int CTX_data_selectable_bases(const bContext *C, ListBase *list)
|
||||
{
|
||||
return ctx_data_collection_get(C, "selectable_bases", list);
|
||||
return ctx_data_base_collection_get(C, "selectable_objects", list);
|
||||
}
|
||||
|
||||
struct Object *CTX_data_active_object(const bContext *C)
|
||||
@@ -1200,7 +1235,14 @@ struct Object *CTX_data_active_object(const bContext *C)
|
||||
|
||||
struct Base *CTX_data_active_base(const bContext *C)
|
||||
{
|
||||
return ctx_data_pointer_get(C, "active_base");
|
||||
Object *ob = ctx_data_pointer_get(C, "active_object");
|
||||
|
||||
if (ob == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ViewLayer *view_layer = CTX_data_view_layer(C);
|
||||
return BKE_view_layer_base_find(view_layer, ob);
|
||||
}
|
||||
|
||||
struct Object *CTX_data_edit_object(const bContext *C)
|
||||
|
||||
@@ -69,15 +69,10 @@ const char *screen_context_dir[] = {
|
||||
"scene",
|
||||
"view_layer",
|
||||
"visible_objects",
|
||||
"visible_bases",
|
||||
"selectable_objects",
|
||||
"selectable_bases",
|
||||
"selected_objects",
|
||||
"selected_bases",
|
||||
"editable_objects",
|
||||
"editable_bases",
|
||||
"selected_editable_objects",
|
||||
"selected_editable_bases",
|
||||
"objects_in_mode",
|
||||
"objects_in_mode_unique_data",
|
||||
"visible_bones",
|
||||
@@ -89,7 +84,6 @@ const char *screen_context_dir[] = {
|
||||
"selected_pose_bones_from_active_object",
|
||||
"active_bone",
|
||||
"active_pose_bone",
|
||||
"active_base",
|
||||
"active_object",
|
||||
"object",
|
||||
"edit_object",
|
||||
@@ -179,52 +173,6 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
|
||||
CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
|
||||
return 1;
|
||||
}
|
||||
else if (CTX_data_equals(member, "visible_bases")) {
|
||||
for (Base *base = view_layer->object_bases.first; base; base = base->next) {
|
||||
if (BASE_VISIBLE(v3d, base)) {
|
||||
CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
|
||||
}
|
||||
}
|
||||
CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
|
||||
return 1;
|
||||
}
|
||||
else if (CTX_data_equals(member, "selectable_bases")) {
|
||||
for (Base *base = view_layer->object_bases.first; base; base = base->next) {
|
||||
if (BASE_SELECTABLE(v3d, base)) {
|
||||
CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
|
||||
}
|
||||
}
|
||||
CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
|
||||
return 1;
|
||||
}
|
||||
else if (CTX_data_equals(member, "selected_bases")) {
|
||||
for (Base *base = view_layer->object_bases.first; base; base = base->next) {
|
||||
if (BASE_SELECTED(v3d, base)) {
|
||||
CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
|
||||
}
|
||||
}
|
||||
CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
|
||||
return 1;
|
||||
}
|
||||
else if (CTX_data_equals(member, "selected_editable_bases")) {
|
||||
for (Base *base = view_layer->object_bases.first; base; base = base->next) {
|
||||
if (BASE_SELECTED_EDITABLE(v3d, base)) {
|
||||
CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
|
||||
}
|
||||
}
|
||||
CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
|
||||
return 1;
|
||||
}
|
||||
else if (CTX_data_equals(member, "editable_bases")) {
|
||||
/* Visible + Editable, but not necessarily selected */
|
||||
for (Base *base = view_layer->object_bases.first; base; base = base->next) {
|
||||
if (BASE_EDITABLE(v3d, base)) {
|
||||
CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
|
||||
}
|
||||
}
|
||||
CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
|
||||
return 1;
|
||||
}
|
||||
else if (CTX_data_equals(member, "objects_in_mode")) {
|
||||
if (obact && (obact->mode != OB_MODE_OBJECT)) {
|
||||
FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, v3d, obact->type, obact->mode, ob_iter) {
|
||||
@@ -455,13 +403,6 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else if (CTX_data_equals(member, "active_base")) {
|
||||
if (view_layer->basact) {
|
||||
CTX_data_pointer_set(result, &scene->id, &RNA_ObjectBase, view_layer->basact);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
else if (CTX_data_equals(member, "active_object")) {
|
||||
if (obact) {
|
||||
CTX_data_id_pointer_set(result, &obact->id);
|
||||
|
||||
Reference in New Issue
Block a user