[Bf-blender-cvs] [e216660382e] master: Merge branch 'blender-v3.0-release'

Bastien Montagne noreply at git.blender.org
Thu Nov 25 15:00:18 CET 2021


Commit: e216660382e46935e8241e9c877c0b2914481da9
Author: Bastien Montagne
Date:   Thu Nov 25 15:00:06 2021 +0100
Branches: master
https://developer.blender.org/rBe216660382e46935e8241e9c877c0b2914481da9

Merge branch 'blender-v3.0-release'

Conflicts:
	source/blender/windowmanager/intern/wm_files_link.c

===================================================================



===================================================================

diff --cc source/blender/blenkernel/intern/blendfile_link_append.c
index 36f03990953,00000000000..c2bf3b4a5f9
mode 100644,000000..100644
--- a/source/blender/blenkernel/intern/blendfile_link_append.c
+++ b/source/blender/blenkernel/intern/blendfile_link_append.c
@@@ -1,1566 -1,0 +1,1571 @@@
 +/*
 + * This program is free software; you can redistribute it and/or
 + * modify it under the terms of the GNU General Public License
 + * as published by the Free Software Foundation; either version 2
 + * of the License, or (at your option) any later version.
 + *
 + * This program is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 + * GNU General Public License for more details.
 + *
 + * You should have received a copy of the GNU General Public License
 + * along with this program; if not, write to the Free Software Foundation,
 + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 + */
 +
 +/** \file
 + * \ingroup bke
 + *
 + * High level `.blend` file link/append code,
 + * including linking/appending several IDs from different libraries, handling instanciations of
 + * collections/objects/obdata in current scene.
 + */
 +
 +#include <stdlib.h>
 +#include <string.h>
 +
 +#include "CLG_log.h"
 +
 +#include "MEM_guardedalloc.h"
 +
 +#include "DNA_ID.h"
 +#include "DNA_collection_types.h"
 +#include "DNA_key_types.h"
 +#include "DNA_object_types.h"
 +#include "DNA_scene_types.h"
 +#include "DNA_screen_types.h"
 +#include "DNA_space_types.h"
 +
 +#include "BLI_bitmap.h"
 +#include "BLI_blenlib.h"
 +#include "BLI_ghash.h"
 +#include "BLI_linklist.h"
 +#include "BLI_math.h"
 +#include "BLI_memarena.h"
 +#include "BLI_utildefines.h"
 +
 +#include "BLT_translation.h"
 +
 +#include "BKE_idtype.h"
 +#include "BKE_key.h"
 +#include "BKE_layer.h"
 +#include "BKE_lib_id.h"
 +#include "BKE_lib_override.h"
 +#include "BKE_lib_query.h"
 +#include "BKE_lib_remap.h"
 +#include "BKE_main.h"
 +#include "BKE_material.h"
 +#include "BKE_object.h"
 +#include "BKE_report.h"
 +#include "BKE_rigidbody.h"
 +#include "BKE_scene.h"
 +
 +#include "BKE_blendfile_link_append.h"
 +
 +#include "BLO_readfile.h"
 +#include "BLO_writefile.h"
 +
 +static CLG_LogRef LOG = {"bke.blendfile_link_append"};
 +
 +/* -------------------------------------------------------------------- */
 +/** \name Link/append context implementation and public management API.
 + * \{ */
 +
 +typedef struct BlendfileLinkAppendContextItem {
 +  /** Name of the ID (without the heading two-chars IDcode). */
 +  char *name;
 +  /** All libs (from BlendfileLinkAppendContext.libraries) to try to load this ID from. */
 +  BLI_bitmap *libraries;
 +  /** ID type. */
 +  short idcode;
 +
 +  /** Type of action to perform on this item, and general status tag information.
 +   *  NOTE: Mostly used by append post-linking processing. */
 +  char action;
 +  char tag;
 +
 +  /** Newly linked ID (NULL until it has been successfully linked). */
 +  ID *new_id;
 +  /** Library ID from which the #new_id has been linked (NULL until it has been successfully
 +   * linked). */
 +  Library *source_library;
 +  /** Opaque user data pointer. */
 +  void *userdata;
 +} BlendfileLinkAppendContextItem;
 +
 +/* A blendfile library entry in the `libraries` list of #BlendfileLinkAppendContext. */
 +typedef struct BlendfileLinkAppendContextLibrary {
 +  char *path;               /* Absolute .blend file path. */
 +  BlendHandle *blo_handle;  /* Blend file handle, if any. */
 +  bool blo_handle_is_owned; /* Whether the blend file handle is owned, or borrowed. */
 +  /* The blendfile report associated with the `blo_handle`, if owned. */
 +  BlendFileReadReport bf_reports;
 +} BlendfileLinkAppendContextLibrary;
 +
 +typedef struct BlendfileLinkAppendContext {
 +  /** List of library paths to search IDs in. */
 +  LinkNodePair libraries;
 +  /** List of all ID to try to link from #libraries. */
 +  LinkNodePair items;
 +  int num_libraries;
 +  int num_items;
 +  /** 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;
 +
 +  /** Runtime info used by append code to manage re-use of already appended matching IDs. */
 +  GHash *library_weak_reference_mapping;
 +
 +  /** Embedded blendfile and its size, if needed. */
 +  const void *blendfile_mem;
 +  size_t blendfile_memsize;
 +
 +  /** Internal 'private' data */
 +  MemArena *memarena;
 +} BlendfileLinkAppendContext;
 +
 +typedef struct BlendfileLinkAppendContextCallBack {
 +  BlendfileLinkAppendContext *lapp_context;
 +  BlendfileLinkAppendContextItem *item;
 +  ReportList *reports;
 +
 +} BlendfileLinkAppendContextCallBack;
 +
 +/* Actions to apply to an item (i.e. linked ID). */
 +enum {
 +  LINK_APPEND_ACT_UNSET = 0,
 +  LINK_APPEND_ACT_KEEP_LINKED,
 +  LINK_APPEND_ACT_REUSE_LOCAL,
 +  LINK_APPEND_ACT_MAKE_LOCAL,
 +  LINK_APPEND_ACT_COPY_LOCAL,
 +};
 +
 +/* Various status info about an item (i.e. linked ID). */
 +enum {
 +  /* An indirectly linked ID. */
 +  LINK_APPEND_TAG_INDIRECT = 1 << 0,
 +};
 +
 +static BlendHandle *link_append_context_library_blohandle_ensure(
 +    BlendfileLinkAppendContext *lapp_context,
 +    BlendfileLinkAppendContextLibrary *lib_context,
 +    ReportList *reports)
 +{
 +  if (reports != NULL) {
 +    lib_context->bf_reports.reports = reports;
 +  }
 +
 +  char *libname = lib_context->path;
 +  BlendHandle *blo_handle = lib_context->blo_handle;
 +  if (blo_handle == NULL) {
 +    if (STREQ(libname, BLO_EMBEDDED_STARTUP_BLEND)) {
 +      blo_handle = BLO_blendhandle_from_memory(lapp_context->blendfile_mem,
 +                                               (int)lapp_context->blendfile_memsize,
 +                                               &lib_context->bf_reports);
 +    }
 +    else {
 +      blo_handle = BLO_blendhandle_from_file(libname, &lib_context->bf_reports);
 +    }
 +    lib_context->blo_handle = blo_handle;
 +    lib_context->blo_handle_is_owned = true;
 +  }
 +
 +  return blo_handle;
 +}
 +
 +static void link_append_context_library_blohandle_release(
 +    BlendfileLinkAppendContext *UNUSED(lapp_context),
 +    BlendfileLinkAppendContextLibrary *lib_context)
 +{
 +  if (lib_context->blo_handle_is_owned && lib_context->blo_handle != NULL) {
 +    BLO_blendhandle_close(lib_context->blo_handle);
 +    lib_context->blo_handle = NULL;
 +  }
 +}
 +
 +/** Allocate and initialize a new context to link/append datablocks.
 + *
 + *  \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(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->params = params;
 +  lapp_context->memarena = ma;
 +
 +  return lapp_context;
 +}
 +
 +/** Free a link/append context. */
 +void BKE_blendfile_link_append_context_free(BlendfileLinkAppendContext *lapp_context)
 +{
 +  if (lapp_context->new_id_to_item != NULL) {
 +    BLI_ghash_free(lapp_context->new_id_to_item, NULL, NULL);
 +  }
 +
 +  for (LinkNode *liblink = lapp_context->libraries.list; liblink != NULL;
 +       liblink = liblink->next) {
 +    BlendfileLinkAppendContextLibrary *lib_context = liblink->link;
 +    link_append_context_library_blohandle_release(lapp_context, lib_context);
 +  }
 +
 +  BLI_assert(lapp_context->library_weak_reference_mapping == NULL);
 +
 +  BLI_memarena_free(lapp_context->memarena);
 +}
 +
 +/** Set or clear flags in given \a lapp_context.
 + *
 + * \param do_set Set the given \a flag if true, clear it otherwise.
 + */
 +void BKE_blendfile_link_append_context_flag_set(BlendfileLinkAppendContext *lapp_context,
 +                                                const int flag,
 +                                                const bool do_set)
 +{
 +  if (do_set) {
 +    lapp_context->params->flag |= flag;
 +  }
 +  else {
 +    lapp_context->params->flag &= ~flag;
 +  }
 +}
 +
 +/** Store reference to a Blender's embedded memfile into the context.
 + *
 + * \note This is required since embedded startup blender file is handled in `ED` module, which
 + * cannot be linked in BKE code.
 + */
 +void BKE_blendfile_link_append_context_embedded_blendfile_set(
 +    BlendfileLinkAppendContext *lapp_context, const void *blendfile_mem, int blendfile_memsize)
 +{
 +  BLI_assert_msg(lapp_context->blendfile_mem == NULL,
 +                 "Please explicitely clear reference to an embedded blender memfile before "
 +                 "setting a new one");
 +  lapp_context->blendfile_mem = blendfile_mem;
 +  lapp_context->blendfile_memsize = (size_t)blendfile_memsize;
 +}
 +
 +/** Clear reference to Blender's embedded startup file into the context. */
 +void BKE_blendfile_link_append_context_embedded_blendfile_clear(
 +    BlendfileLinkAppendContext *lapp_context)
 +{
 +  lapp_context->blendfile_mem = NULL;
 +  lapp_context->blendfile_memsize = 0;
 +}
 +
 +/** Add a new source library to search for items to be linked to the given link/append context.
 + *
 + * \param libname: the absolute path to the library blend file.
 + * \param blo_handle: the blend file handle of the library, NULL is not available. Note that this
 + *                    is only borrowed for linking purpose, no releasing or other management will
 + *                    be performed by #BKE_blendfile_link_append code on it.
 + *
 + * \note *Never* call BKE_blendfile_link_append_context_library_add() after having added some
 + * items. */
 +void BKE_blendfile_link_append_context_library_add(BlendfileLinkAppendContext *lapp_context,
 +                                                   const char *libname,
 +                                                   BlendHandle *blo_handle)
 +{
 +  BLI_assert(lapp_context->items.list == NULL);
 +
 +  BlendfileLinkAppendContextLibrary *lib_context = BLI_memarena_calloc(lapp_context->memarena,
 +    

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list