[Bf-blender-cvs] [059da44fbc3] master: BKE Link/Append: Use BLO's LibraryLink_Params.
Bastien Montagne
noreply at git.blender.org
Mon Nov 22 17:14:49 CET 2021
Commit: 059da44fbc30803e019214c852cb2f3b99f97069
Author: Bastien Montagne
Date: Wed Nov 10 15:23:15 2021 +0100
Branches: master
https://developer.blender.org/rB059da44fbc30803e019214c852cb2f3b99f97069
BKE Link/Append: Use BLO's LibraryLink_Params.
This allows to reduce signature of several functions, and make it eaiser
to integrate more higher-level usages later on.
This should be a non-behavioral-change commit.
Part of T91414: Unify link/append between WM operators and BPY context
manager API, and cleanup usages of `BKE_library_make_local`.
===================================================================
M source/blender/blenkernel/BKE_blendfile_link_append.h
M source/blender/blenkernel/intern/blendfile_link_append.c
M source/blender/blenloader/BLO_readfile.h
M source/blender/windowmanager/intern/wm_files_link.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_blendfile_link_append.h b/source/blender/blenkernel/BKE_blendfile_link_append.h
index 184f1ef1511..e0e38390a70 100644
--- a/source/blender/blenkernel/BKE_blendfile_link_append.h
+++ b/source/blender/blenkernel/BKE_blendfile_link_append.h
@@ -25,6 +25,7 @@ extern "C" {
struct ID;
struct Library;
+struct LibraryLink_Params;
struct Main;
struct ReportList;
struct Scene;
@@ -34,7 +35,8 @@ struct View3D;
typedef struct BlendfileLinkAppendContext BlendfileLinkAppendContext;
typedef struct BlendfileLinkAppendContextItem BlendfileLinkAppendContextItem;
-BlendfileLinkAppendContext *BKE_blendfile_link_append_context_new(const int flag);
+BlendfileLinkAppendContext *BKE_blendfile_link_append_context_new(
+ struct LibraryLink_Params *params);
void BKE_blendfile_link_append_context_free(struct BlendfileLinkAppendContext *lapp_context);
void BKE_blendfile_link_append_context_flag_set(struct BlendfileLinkAppendContext *lapp_context,
const int flag,
@@ -66,25 +68,14 @@ struct ID *BKE_blendfile_link_append_context_item_newid_get(
struct BlendfileLinkAppendContext *lapp_context, struct BlendfileLinkAppendContextItem *item);
void BKE_blendfile_append(struct BlendfileLinkAppendContext *lapp_context,
- struct ReportList *reports,
- struct Main *bmain,
- struct Scene *scene,
- struct ViewLayer *view_layer,
- const struct View3D *v3d);
+ struct ReportList *reports);
void BKE_blendfile_link(struct BlendfileLinkAppendContext *lapp_context,
- struct ReportList *reports,
- struct Main *bmain,
- struct Scene *scene,
- struct ViewLayer *view_layer,
- const struct View3D *v3d);
+ struct ReportList *reports);
void BKE_blendfile_library_relocate(struct BlendfileLinkAppendContext *lapp_context,
struct ReportList *reports,
struct Library *library,
- const bool do_reload,
- struct Main *bmain,
- struct Scene *scene,
- struct ViewLayer *view_layer);
+ const bool do_reload);
#ifdef __cplusplus
}
diff --git a/source/blender/blenkernel/intern/blendfile_link_append.c b/source/blender/blenkernel/intern/blendfile_link_append.c
index f0d41e91340..3ba2287bb0e 100644
--- a/source/blender/blenkernel/intern/blendfile_link_append.c
+++ b/source/blender/blenkernel/intern/blendfile_link_append.c
@@ -101,10 +101,8 @@ typedef struct BlendfileLinkAppendContext {
LinkNodePair items;
int num_libraries;
int num_items;
- /**
- * Combines #eFileSel_Params_Flag from DNA_space_types.h & #eBLOLibLinkFlags from BLO_readfile.h
- */
- int flag;
+ /** Linking/appending parameters. Including bmain, scene, viewlayer and view3d. */
+ LibraryLink_Params *params;
/** Allows to easily find an existing items from an ID pointer. */
GHash *new_id_to_item;
@@ -147,12 +145,12 @@ enum {
* \param flag a combination of #eFileSel_Params_Flag from DNA_space_types.h & #eBLOLibLinkFlags
* from BLO_readfile.h
*/
-BlendfileLinkAppendContext *BKE_blendfile_link_append_context_new(const int flag)
+BlendfileLinkAppendContext *BKE_blendfile_link_append_context_new(LibraryLink_Params *params)
{
MemArena *ma = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__);
BlendfileLinkAppendContext *lapp_context = BLI_memarena_calloc(ma, sizeof(*lapp_context));
- lapp_context->flag = flag;
+ lapp_context->params = params;
lapp_context->memarena = ma;
return lapp_context;
@@ -179,10 +177,10 @@ void BKE_blendfile_link_append_context_flag_set(BlendfileLinkAppendContext *lapp
const bool do_set)
{
if (do_set) {
- lapp_context->flag |= flag;
+ lapp_context->params->flag |= flag;
}
else {
- lapp_context->flag &= ~flag;
+ lapp_context->params->flag &= ~flag;
}
}
@@ -296,11 +294,6 @@ typedef struct LooseDataInstantiateContext {
/* The collection in which to add loose collections/objects. */
Collection *active_collection;
-
- Main *bmain;
- Scene *scene;
- ViewLayer *view_layer;
- const View3D *v3d;
} LooseDataInstantiateContext;
static bool object_in_any_scene(Main *bmain, Object *ob)
@@ -337,7 +330,7 @@ static ID *loose_data_instantiate_process_check(LooseDataInstantiateContext *ins
{
BlendfileLinkAppendContext *lapp_context = instantiate_context->lapp_context;
/* In linking case, we always want to handle instantiation. */
- if (lapp_context->flag & FILE_LINK) {
+ if (lapp_context->params->flag & FILE_LINK) {
return item->new_id;
}
@@ -372,18 +365,18 @@ static void loose_data_instantiate_ensure_active_collection(
{
BlendfileLinkAppendContext *lapp_context = instantiate_context->lapp_context;
- Main *bmain = instantiate_context->bmain;
- Scene *scene = instantiate_context->scene;
- ViewLayer *view_layer = instantiate_context->view_layer;
+ Main *bmain = instantiate_context->lapp_context->params->bmain;
+ Scene *scene = instantiate_context->lapp_context->params->context.scene;
+ ViewLayer *view_layer = instantiate_context->lapp_context->params->context.view_layer;
/* Find or add collection as needed. */
if (instantiate_context->active_collection == NULL) {
- if (lapp_context->flag & FILE_ACTIVE_COLLECTION) {
+ if (lapp_context->params->flag & FILE_ACTIVE_COLLECTION) {
LayerCollection *lc = BKE_layer_collection_get_active(view_layer);
instantiate_context->active_collection = lc->collection;
}
else {
- if (lapp_context->flag & FILE_LINK) {
+ if (lapp_context->params->flag & FILE_LINK) {
instantiate_context->active_collection = BKE_collection_add(
bmain, scene->master_collection, DATA_("Linked Data"));
}
@@ -478,10 +471,10 @@ static void loose_data_instantiate_collection_process(
LooseDataInstantiateContext *instantiate_context)
{
BlendfileLinkAppendContext *lapp_context = instantiate_context->lapp_context;
- Main *bmain = instantiate_context->bmain;
- Scene *scene = instantiate_context->scene;
- ViewLayer *view_layer = instantiate_context->view_layer;
- const View3D *v3d = instantiate_context->v3d;
+ Main *bmain = lapp_context->params->bmain;
+ Scene *scene = lapp_context->params->context.scene;
+ ViewLayer *view_layer = lapp_context->params->context.view_layer;
+ const View3D *v3d = lapp_context->params->context.v3d;
/* NOTE: For collections we only view_layer-instantiate duplicated collections that have
* non-instantiated objects in them. */
@@ -523,19 +516,19 @@ static void loose_data_instantiate_collection_process(
/* In case user requested instantiation of collections as empties, we do so for the one they
* explicitly selected (originally directly linked IDs) only. */
- if ((lapp_context->flag & BLO_LIBLINK_COLLECTION_INSTANCE) != 0 &&
+ if ((lapp_context->params->flag & BLO_LIBLINK_COLLECTION_INSTANCE) != 0 &&
(item->tag & LINK_APPEND_TAG_INDIRECT) == 0) {
/* BKE_object_add(...) messes with the selection. */
Object *ob = BKE_object_add_only_object(bmain, OB_EMPTY, collection->id.name + 2);
ob->type = OB_EMPTY;
ob->empty_drawsize = U.collection_instance_empty_size;
- const bool set_selected = (lapp_context->flag & FILE_AUTOSELECT) != 0;
+ const bool set_selected = (lapp_context->params->flag & FILE_AUTOSELECT) != 0;
/* TODO: why is it OK to make this active here but not in other situations?
* See other callers of #object_base_instance_init */
const bool set_active = set_selected;
loose_data_instantiate_object_base_instance_init(
- bmain, active_collection, ob, view_layer, v3d, lapp_context->flag, set_active);
+ bmain, active_collection, ob, view_layer, v3d, lapp_context->params->flag, set_active);
/* Assign the collection. */
ob->instance_collection = collection;
@@ -547,7 +540,7 @@ static void loose_data_instantiate_collection_process(
/* Add collection as child of active collection. */
BKE_collection_child_add(bmain, active_collection, collection);
- if ((lapp_context->flag & FILE_AUTOSELECT) != 0) {
+ if ((lapp_context->params->flag & FILE_AUTOSELECT) != 0) {
LISTBASE_FOREACH (CollectionObject *, coll_ob, &collection->gobject) {
Object *ob = coll_ob->ob;
Base *base = BKE_view_layer_base_find(view_layer, ob);
@@ -564,9 +557,9 @@ static void loose_data_instantiate_collection_process(
static void loose_data_instantiate_object_process(LooseDataInstantiateContext *instantiate_context)
{
BlendfileLinkAppendContext *lapp_context = instantiate_context->lapp_context;
- Main *bmain = instantiate_context->bmain;
- ViewLayer *view_layer = instantiate_context->view_layer;
- const View3D *v3d = instantiate_context->v3d;
+ Main *bmain = lapp_context->params->bmain;
+ ViewLayer *view_layer = lapp_context->params->context.view_layer;
+ const View3D *v3d = lapp_context->params->context.v3d;
/* Do NOT make base active here! screws up GUI stuff,
* if you want it do it at the editor level. */
@@ -594,18 +587,23 @@ static void loose_data_instantiate_object_process(LooseDataInstantiateContext *i
CLAMP_MIN(ob->id.us, 0);
ob->mode = OB_MODE_OBJECT;
- loose_data_instantiate_object_base_instance_init(
- bmain, active_collection, ob, view_layer, v3d, lapp_context->flag, object_set_active);
+ loose_data_instantiate_object_base_instance_init(bmain,
+ active_collection,
+ ob,
+ view_layer,
+ v3d,
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list