[Bf-blender-cvs] [d4a9111] asset-experiments: Merge branch 'asset-engine' into asset-experiments
Bastien Montagne
noreply at git.blender.org
Wed Apr 27 11:06:55 CEST 2016
Commit: d4a9111f0853faf11dd227cb8310b2ef05eb075f
Author: Bastien Montagne
Date: Wed Apr 27 10:46:05 2016 +0200
Branches: asset-experiments
https://developer.blender.org/rBd4a9111f0853faf11dd227cb8310b2ef05eb075f
Merge branch 'asset-engine' into asset-experiments
Conflicts:
source/blender/windowmanager/intern/wm_operators.c
===================================================================
===================================================================
diff --cc source/blender/windowmanager/intern/wm_files_link.c
index 0000000,86f63e1..6bff253
mode 000000,100644..100644
--- a/source/blender/windowmanager/intern/wm_files_link.c
+++ b/source/blender/windowmanager/intern/wm_files_link.c
@@@ -1,0 -1,810 +1,1205 @@@
+ /*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * 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.
+ *
+ * The Original Code is Copyright (C) 2007 Blender Foundation.
+ * All rights reserved.
+ *
+ *
+ * Contributor(s): Blender Foundation
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+ /** \file blender/windowmanager/intern/wm_files_link.c
+ * \ingroup wm
+ *
+ * Functions for dealing with append/link operators and helpers.
+ */
+
+
+ #include <float.h>
+ #include <string.h>
+ #include <ctype.h>
+ #include <stdio.h>
+ #include <stddef.h>
+ #include <assert.h>
+ #include <errno.h>
+
+ #include "MEM_guardedalloc.h"
+
+ #include "DNA_ID.h"
+ #include "DNA_screen_types.h"
+ #include "DNA_scene_types.h"
+ #include "DNA_space_types.h"
+ #include "DNA_windowmanager_types.h"
+
+ #include "RNA_access.h"
+ #include "RNA_define.h"
+
+ #include "BLI_blenlib.h"
+ #include "BLI_bitmap.h"
+ #include "BLI_linklist.h"
+ #include "BLI_math.h"
+ #include "BLI_memarena.h"
+ #include "BLI_utildefines.h"
+ #include "BLI_ghash.h"
+
+ #include "PIL_time.h"
+
+ #include "BLO_readfile.h"
+
+ #include "BKE_asset.h"
+ #include "BKE_context.h"
+ #include "BKE_depsgraph.h"
+ #include "BKE_library.h"
+ #include "BKE_global.h"
+ #include "BKE_main.h"
+ #include "BKE_report.h"
+ #include "BKE_scene.h"
+ #include "BKE_screen.h" /* BKE_ST_MAXNAME */
+
+ #include "BKE_idcode.h"
+
+ #include "IMB_colormanagement.h"
+
+ #include "ED_screen.h"
+
+ #include "GPU_material.h"
+
+ #include "WM_api.h"
+ #include "WM_types.h"
+
+ #include "wm_files.h"
+
+ /* **************** link/append *************** */
+
+ static int wm_link_append_poll(bContext *C)
+ {
+ if (WM_operator_winactive(C)) {
+ /* linking changes active object which is pretty useful in general,
+ * but which totally confuses edit mode (i.e. it becoming not so obvious
+ * to leave from edit mode and invalid tools in toolbar might be displayed)
+ * so disable link/append when in edit mode (sergey) */
+ if (CTX_data_edit_object(C))
+ return 0;
+
+ return 1;
+ }
+
+ return 0;
+ }
+
+ static int wm_link_append_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+ {
+ if (RNA_struct_property_is_set(op->ptr, "filepath")) {
+ return WM_operator_call_notest(C, op);
+ }
+ else {
+ /* XXX TODO solve where to get last linked library from */
+ if (G.lib[0] != '\0') {
+ RNA_string_set(op->ptr, "filepath", G.lib);
+ }
+ else if (G.relbase_valid) {
+ char path[FILE_MAX];
+ BLI_strncpy(path, G.main->name, sizeof(G.main->name));
+ BLI_parent_dir(path);
+ RNA_string_set(op->ptr, "filepath", path);
+ }
+ WM_event_add_fileselect(C, op);
+ return OPERATOR_RUNNING_MODAL;
+ }
+ }
+
+ static short wm_link_append_flag(wmOperator *op)
+ {
+ PropertyRNA *prop;
+ short flag = 0;
+
+ if (RNA_boolean_get(op->ptr, "autoselect"))
+ flag |= FILE_AUTOSELECT;
+ if (RNA_boolean_get(op->ptr, "active_layer"))
+ flag |= FILE_ACTIVELAY;
+ if ((prop = RNA_struct_find_property(op->ptr, "relative_path")) && RNA_property_boolean_get(op->ptr, prop))
+ flag |= FILE_RELPATH;
+ if (RNA_boolean_get(op->ptr, "link"))
+ flag |= FILE_LINK;
+ if (RNA_boolean_get(op->ptr, "instance_groups"))
+ flag |= FILE_GROUP_INSTANCE;
+
+ return flag;
+ }
+
+ typedef struct WMLinkAppendDataItem {
+ AssetUUID *uuid;
+ char *name;
+ BLI_bitmap *libraries; /* All libs (from WMLinkAppendData.libraries) to try to load this ID from. */
+ short idcode;
+
+ ID *new_id;
+ void *customdata;
+ } WMLinkAppendDataItem;
+
+ typedef struct WMLinkAppendData {
+ const char *root;
+ LinkNodePair libraries;
+ LinkNodePair items;
+ int num_libraries;
+ int num_items;
+ short flag;
+
+ /* Internal 'private' data */
+ MemArena *memarena;
+ } WMLinkAppendData;
+
+ static WMLinkAppendData *wm_link_append_data_new(const int flag)
+ {
+ MemArena *ma = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__);
+ WMLinkAppendData *lapp_data = BLI_memarena_calloc(ma, sizeof(*lapp_data));
+
+ lapp_data->flag = flag;
+ lapp_data->memarena = ma;
+
+ return lapp_data;
+ }
+
+ static void wm_link_append_data_free(WMLinkAppendData *lapp_data)
+ {
+ BLI_memarena_free(lapp_data->memarena);
+ }
+
+ /* WARNING! *Never* call wm_link_append_data_library_add() after having added some items! */
+
+ static void wm_link_append_data_library_add(WMLinkAppendData *lapp_data, const char *libname)
+ {
+ size_t len = strlen(libname) + 1;
+ char *libpath = BLI_memarena_alloc(lapp_data->memarena, len);
+
+ BLI_strncpy(libpath, libname, len);
+ BLI_linklist_append_arena(&lapp_data->libraries, libpath, lapp_data->memarena);
+ lapp_data->num_libraries++;
+ }
+
+ static WMLinkAppendDataItem *wm_link_append_data_item_add(
+ WMLinkAppendData *lapp_data, const char *idname, const short idcode, const AssetUUID *uuid, void *customdata)
+ {
+ WMLinkAppendDataItem *item = BLI_memarena_alloc(lapp_data->memarena, sizeof(*item));
+ size_t len = strlen(idname) + 1;
+
+ if (uuid) {
+ item->uuid = BLI_memarena_alloc(lapp_data->memarena, sizeof(*item->uuid));
+ *item->uuid = *uuid;
+ }
+ else {
+ item->uuid = NULL;
+ }
+ item->name = BLI_memarena_alloc(lapp_data->memarena, len);
+ BLI_strncpy(item->name, idname, len);
+ item->idcode = idcode;
+ item->libraries = BLI_BITMAP_NEW_MEMARENA(lapp_data->memarena, lapp_data->num_libraries);
+
+ item->new_id = NULL;
+ item->customdata = customdata;
+
+ BLI_linklist_append_arena(&lapp_data->items, item, lapp_data->memarena);
+ lapp_data->num_items++;
+
+ return item;
+ }
+
+ static void wm_link_do(
- WMLinkAppendData *lapp_data, ReportList *reports, Main *bmain, AssetEngineType *aet, Scene *scene, View3D *v3d)
++ WMLinkAppendData *lapp_data, ReportList *reports, Main *bmain, AssetEngineType *aet, Scene *scene, View3D *v3d,
++ const bool use_placeholders, const bool force_indirect)
+ {
+ Main *mainl;
+ BlendHandle *bh;
+ Library *lib;
+
+ const int flag = lapp_data->flag;
+
+ LinkNode *liblink, *itemlink;
+ int lib_idx, item_idx;
+
+ BLI_assert(lapp_data->num_items && lapp_data->num_libraries);
+
+ for (lib_idx = 0, liblink = lapp_data->libraries.list; liblink; lib_idx++, liblink = liblink->next) {
+ char *libname = liblink->link;
+
+ bh = BLO_blendhandle_from_file(libname, reports);
+
+ if (bh == NULL) {
+ /* Unlikely since we just browsed it, but possible
+ * Error reports will have been made by BLO_blendhandle_from_file() */
+ continue;
+ }
+
+ /* here appending/linking starts */
+ mainl = BLO_library_link_begin(bmain, &bh, libname);
+ lib = mainl->curlib;
+ BLI_assert(lib);
+ UNUSED_VARS_NDEBUG(lib);
+
+ if (mainl->versionfile < 250) {
+ BKE_reportf(reports, RPT_WARNING,
+ "Linking or appending from a very old .blend file format (%d.%d), no animation conversion will "
+ "be done! You may want to re-save your lib file with current Blender",
+ mainl->versionfile, mainl->subversionfile);
+ }
+
+ /* For each lib file, we try to link all items belonging to that lib,
+ * and tag those successful to not try to load them again with the other libs. */
+ for (item_idx = 0, itemlink = lapp_data->items.list; itemlink; item_idx++, itemlink = itemlink->next) {
+ WMLinkAppendDataItem *item = itemlink->link;
+ ID *new_id;
+
+ if (!BLI_BITMAP_TEST(item->libraries, lib_idx)) {
+ continue;
+ }
+
+ new_id = BLO_library_link_named_part_asset(
- mainl, &bh, aet, lapp_data->root, item->idcode, item->name, item->uuid, flag, scene, v3d);
++ mainl, &bh, aet, lapp_data->root, item->idcode, item->name, item->uuid, flag, scene, v3d,
++ use_placeholders, force_indirect);
+
+ if (new_id) {
+ /* If the link is sucessful, clear item's libs 'todo' flags.
+ * This avoids trying to link same item with other libraries to come. */
+ BLI_BITMAP_SET_ALL(item->libraries, false, lapp_data->num_libraries);
+ item->new_id = new_id;
+ }
+ }
+
+ BLO_library_link_end(mainl, &bh, flag, scene, v3d);
+ BLO_blendhandle_close(bh);
+ }
+ }
+
+ static int wm_link_append_exec(bContext *C, wmOperator *op)
+ {
+ Main *bmain = CTX_data_main(C);
+ Scene *scene = CTX_data_scene(C);
+ PropertyRNA *prop;
+ WMLinkAppendData *lapp_data;
+ char path[FILE_MAX_LIBEXTRA], root[FILE_MAXDIR], libname[FILE_MAX], relname[FILE_MAX];
+ char *group, *name;
+ int totfiles = 0;
+ short flag;
+
+ char asset_engine[BKE_ST_MAXNAME];
+ AssetEngineType *aet = NULL;
+ AssetUUID uuid = {0};
+
+ RNA_string_get(op->ptr, "filename", relname);
+ RNA_string_get(op->ptr, "directory", root);
+
+ BLI_join_dirfile(path, sizeof(path), root, relname);
+
+ RNA_string_get(op->ptr, "asset_engine", asset_engine);
+ if (asset_engine[0] != '\0') {
+ aet = BKE_asset_engines_find(asset_engine);
+ }
+
+ /* test if we have a valid data */
+ if (!BLO_library_path_explode(path, libname, &group, &name)) {
+ BKE_reportf(op->reports, RPT_ERROR, "'%s': not a library", path);
+ return OPERATOR_CANCELLED;
+ }
+ else if (!group) {
+ BKE_reportf(op->reports, RPT_ERROR, "'%s': nothing indicated", path);
+ return OPERATOR_CANCELLED;
+ }
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list