[Bf-blender-cvs] [613bf67] asset-experiments: Merge branch 'id-remap' into asset-experiments
Bastien Montagne
noreply at git.blender.org
Wed Dec 16 22:28:53 CET 2015
Commit: 613bf6755ea41ddcb58e3f7497064c141cf70946
Author: Bastien Montagne
Date: Wed Dec 16 22:28:31 2015 +0100
Branches: asset-experiments
https://developer.blender.org/rB613bf6755ea41ddcb58e3f7497064c141cf70946
Merge branch 'id-remap' into asset-experiments
Conflicts:
source/blender/blenloader/BLO_readfile.h
source/blender/blenloader/intern/readfile.c
source/blender/windowmanager/intern/wm_operators.c
===================================================================
===================================================================
diff --cc source/blender/blenloader/BLO_readfile.h
index dcf4b09,0d13302..3df6183
--- a/source/blender/blenloader/BLO_readfile.h
+++ b/source/blender/blenloader/BLO_readfile.h
@@@ -101,12 -99,9 +101,14 @@@ struct Main *BLO_library_link_begin(str
struct ID *BLO_library_link_named_part(struct Main *mainl, BlendHandle **bh, const short idcode, const char *name);
struct ID *BLO_library_link_named_part_ex(
struct Main *mainl, BlendHandle **bh,
- const int idcode, const char *name, const short flag,
+ const short idcode, const char *name, const short flag,
- struct Scene *scene, struct View3D *v3d);
++ struct Scene *scene, struct View3D *v3d,
++ const bool use_placeholders, const bool force_indirect);
+struct ID *BLO_library_link_named_part_asset(
+ struct Main *mainl, BlendHandle **bh, const struct AssetEngineType *aet,
+ const short idcode, const char *name, const struct AssetUUID *uuid, const short flag,
- struct Scene *scene, struct View3D *v3d);
+ struct Scene *scene, struct View3D *v3d,
+ const bool use_placeholders, const bool force_indirect);
void BLO_library_link_end(struct Main *mainl, BlendHandle **bh, short flag, struct Scene *scene, struct View3D *v3d);
void BLO_library_link_all(struct Main *mainl, BlendHandle *bh);
diff --cc source/blender/blenloader/intern/readfile.c
index c204362,dd6a350..07d2611
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@@ -9689,11 -9694,10 +9697,12 @@@ void BLO_library_link_all(Main *mainl,
}
static ID *link_named_part_ex(
- Main *mainl, FileData *fd, const int idcode, const char *name, const short flag,
- Scene *scene, View3D *v3d, const bool use_placeholders, const bool force_indirect)
+ Main *mainl, FileData *fd, const AssetEngineType *aet,
+ const short idcode, const char *name, const AssetUUID *uuid, const int flag,
- Scene *scene, View3D *v3d)
++ Scene *scene, View3D *v3d,
++ const bool use_placeholders, const bool force_indirect)
{
- ID *id = link_named_part(mainl, fd, idcode, name);
+ ID *id = link_named_part(mainl, fd, idcode, name, use_placeholders, force_indirect);
if (id && (GS(id->name) == ID_OB)) { /* loose object: give a base */
if (scene) {
@@@ -9761,36 -9767,11 +9772,35 @@@ ID *BLO_library_link_named_part(Main *m
* \return the linked ID when found.
*/
ID *BLO_library_link_named_part_ex(
- Main *mainl, BlendHandle **bh,
- const short idcode, const char *name, const short flag,
- Scene *scene, View3D *v3d)
- Main *mainl, BlendHandle **bh, const int idcode, const char *name, const short flag,
++ Main *mainl, BlendHandle **bh, const short idcode, const char *name, const short flag,
++ Scene *scene, View3D *v3d, const bool use_placeholders, const bool force_indirect)
+{
+ FileData *fd = (FileData*)(*bh);
- return link_named_part_ex(mainl, fd, NULL, idcode, name, NULL, flag, scene, v3d);
++ return link_named_part_ex(mainl, fd, NULL, idcode, name, NULL, flag, scene, v3d, use_placeholders, force_indirect);
+}
+
+/**
+ * Link a named datablock from an external blend file, using given asset engine & asset UUID.
+ * Optionally instantiate the object/group in the scene when the flags are set.
+ *
+ * \param mainl The main database to link from (not the active one).
+ * \param bh The blender file handle.
+ * \param aet The asset engine type (NULL when no asset engine is used).
+ * \param idcode The kind of datablock to link.
+ * \param name The name of the datablock (without the 2 char ID prefix).
+ * \param uuid The asset engine's UUID of this datablock (NULL when no asset engine is used).
+ * \param flag Options for linking, used for instantiating.
+ * \param scene The scene in which to instantiate objects/groups (if NULL, no instantiation is done).
+ * \param v3d The active View3D (only to define active layers for instantiated objects & groups, can be NULL).
+ * \return the linked ID when found.
+ */
+struct ID *BLO_library_link_named_part_asset(
+ Main *mainl, BlendHandle **bh, const AssetEngineType *aet,
+ const short idcode, const char *name, const AssetUUID *uuid, const short flag,
- Scene *scene, View3D *v3d)
+ Scene *scene, View3D *v3d, const bool use_placeholders, const bool force_indirect)
{
FileData *fd = (FileData*)(*bh);
- return link_named_part_ex(mainl, fd, aet, idcode, name, uuid, flag, scene, v3d);
- return link_named_part_ex(mainl, fd, idcode, name, flag, scene, v3d, use_placeholders, force_indirect);
++ return link_named_part_ex(mainl, fd, aet, idcode, name, uuid, flag, scene, v3d, use_placeholders, force_indirect);
}
static void link_id_part(ReportList *reports, FileData *fd, Main *mainvar, ID *id, ID **r_id)
diff --cc source/blender/makesdna/DNA_ID.h
index ed38b0a,de15219..4b6edc0
--- a/source/blender/makesdna/DNA_ID.h
+++ b/source/blender/makesdna/DNA_ID.h
@@@ -147,11 -127,10 +147,12 @@@ typedef struct ID
* to.
*/
short flag;
+ int flag2;
int us;
- int icon_id, pad2;
+ int icon_id;
IDProperty *properties;
+
+ AssetUUID *uuid;
} ID;
/**
diff --cc source/blender/windowmanager/intern/wm_operators.c
index bbb0468,89fe923..188410c
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@@ -2730,7 -2707,8 +2730,8 @@@ static WMLinkAppendDataItem *wm_link_ap
}
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, 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;
@@@ -2777,8 -2755,8 +2778,9 @@@
continue;
}
- new_id = BLO_library_link_named_part_ex(
- mainl, &bh, item->idcode, item->name, flag, scene, v3d, use_placeholders, force_indirect);
+ new_id = BLO_library_link_named_part_asset(
- mainl, &bh, aet, item->idcode, item->name, &item->uuid, flag, scene, v3d);
++ mainl, &bh, aet, 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.
@@@ -2937,7 -2900,7 +2939,7 @@@ static int wm_link_append_exec(bContex
/* XXX We'd need re-entrant locking on Main for this to work... */
/* BKE_main_lock(bmain); */
- wm_link_do(lapp_data, op->reports, bmain, aet, scene, CTX_wm_view3d(C));
- wm_link_do(lapp_data, op->reports, bmain, scene, CTX_wm_view3d(C), false, false);
++ wm_link_do(lapp_data, op->reports, bmain, aet, scene, CTX_wm_view3d(C), false, false);
/* BKE_main_unlock(bmain); */
@@@ -3034,6 -2993,398 +3036,399 @@@ static void WM_OT_append(wmOperatorTyp
wm_link_append_properties_common(ot, false);
}
+
+ static int wm_lib_relocate_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+ {
+ Library *lib;
+ char lib_name[MAX_NAME];
+
+ RNA_string_get(op->ptr, "library", lib_name);
+ lib = (Library *)BKE_libblock_find_name_ex(CTX_data_main(C), ID_LI, lib_name);
+
+ if (lib) {
+ if (lib->parent) {
+ BKE_reportf(op->reports, RPT_ERROR_INVALID_INPUT,
+ "Cannot relocate indirectly linked library '%s'", lib->filepath);
+ return OPERATOR_CANCELLED;
+ }
+ RNA_string_set(op->ptr, "filepath", lib->filepath);
+
+ WM_event_add_fileselect(C, op);
+
+ return OPERATOR_RUNNING_MODAL;
+ }
+
+ return OPERATOR_CANCELLED;
+ }
+
+ static int wm_lib_relocate_exec_do(bContext *C, wmOperator *op, const bool reload)
+ {
+ Library *lib;
+ char lib_name[MAX_NAME];
+
+ RNA_string_get(op->ptr, "library", lib_name);
+ lib = (Library *)BKE_libblock_find_name_ex(CTX_data_main(C), ID_LI, lib_name);
+
+ if (lib) {
+ Main *bmain = CTX_data_main(C);
+ Scene *scene = CTX_data_scene(C);
+ PropertyRNA *prop;
+ WMLinkAppendData *lapp_data;
+
+ ListBase *lbarray[MAX_LIBARRAY];
+ int lba_idx;
+
+ LinkNode *itemlink;
+ int item_idx;
+
+ int num_ids;
+ char path[FILE_MAX], root[FILE_MAXDIR], libname[FILE_MAX], relname[FILE_MAX];
+ short flag = 0;
+
+ if (RNA_boolean_get(op->ptr, "relative_path")) {
+ flag |= FILE_RELPATH;
+ }
+
+ if (lib->parent && !reload) {
+ BKE_reportf(op->reports, RPT_ERROR_INVALID_INPUT,
+ "Cannot relocate indirectly linked library '%s'", lib->filepath);
+ return OPERATOR_CANCELLED;
+ }
+
+ RNA_string_get(op->ptr, "directory", root);
+ RNA_string_get(op->ptr, "filename", libname);
+
+ if (!BLO_has_bfile_extension(libname)) {
+ BKE_report(op->reports, RPT_ERROR, "Not a library");
+ return OPERATOR_CANCELLED;
+ }
+
+ BLI_join_dirfile(path, sizeof(path), root, libname);
+
+ if (BLI_path_cmp(lib->filepath, path) == 0) {
+ printf("We are supposed to reload '%s' lib (%d)...\n", lib->filepath, lib->id.us);
+
+ lapp_data = wm_link_append_data_new(flag);
+ wm_link_append_data_library_add(lapp_data, path);
+
+ BKE_main_lock(bmain);
+
+ lba_idx = set_listbasepointers(bmain, lbarray);
+ while (lba_idx--) {
+ ID *id = lbarray[lba_idx]->first;
+ const short idcode = id ? GS(id->name) : 0;
+
+ if (!id || !BKE_idcode_is_linkable(idcode)) {
+ /* No need to reload non-linkable datatypes, those will get relinked with their 'users ID'. */
+ continue;
+ }
+
+ for (; id; id = id->next) {
+ if (id->lib == lib) {
+ WMLinkAppendDataItem *item;
+
+ /* We remove it from current Main, and add it to items to link... */
+ /* Note that non-linkable IDs (like e.g. shapekeys) are also explicitely linked here... */
+ BLI_remlink(lbarray[lba_idx], id);
- item = wm_link_append_data_item_add(lapp_data, id->name + 2, idcode, id);
++ item = wm_link_append_data_item_add(lapp_data, id->name + 2, idcode, NULL, id);
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list