[Bf-blender-cvs] [45164ac] asset-engine: WIP work to pass asset data to operator.
Bastien Montagne
noreply at git.blender.org
Thu Apr 16 18:30:48 CEST 2015
Commit: 45164ac6e36e30174fbb702b94400bf3ea89022f
Author: Bastien Montagne
Date: Thu Apr 16 18:28:59 2015 +0200
Branches: asset-engine
https://developer.blender.org/rB45164ac6e36e30174fbb702b94400bf3ea89022f
WIP work to pass asset data to operator.
Asset engine ID, asset/variant/revision uuids, root path...
First goal is link code!
===================================================================
M release/scripts/startup/bl_operators/amber.py
M source/blender/blenkernel/BKE_asset.h
M source/blender/blenkernel/intern/asset.c
M source/blender/editors/space_file/file_ops.c
M source/blender/editors/space_file/filelist.c
M source/blender/editors/space_file/filelist.h
M source/blender/makesdna/DNA_space_types.h
M source/blender/makesrna/RNA_access.h
M source/blender/makesrna/intern/rna_asset.c
M source/blender/makesrna/intern/rna_wm.c
M source/blender/windowmanager/intern/wm_operators.c
===================================================================
diff --git a/release/scripts/startup/bl_operators/amber.py b/release/scripts/startup/bl_operators/amber.py
index d100584..25befc0 100644
--- a/release/scripts/startup/bl_operators/amber.py
+++ b/release/scripts/startup/bl_operators/amber.py
@@ -433,6 +433,13 @@ class AssetEngineAmber(AssetEngine):
entry.blender_type = e["blen_type"]
# archive part not yet implemented!
entry.relpath = r["path"]
+ entry.uuid = euuid
+ var = entry.variants.add()
+ var.uuid = vuuid
+ rev = var.revisions.add()
+ rev.uuid = ruuid
+ var.revisions.active = rev
+ entry.variants.active = var
entries.root_path = self.root
return True
return False
diff --git a/source/blender/blenkernel/BKE_asset.h b/source/blender/blenkernel/BKE_asset.h
index ccabc0d..bc02de0 100644
--- a/source/blender/blenkernel/BKE_asset.h
+++ b/source/blender/blenkernel/BKE_asset.h
@@ -163,7 +163,7 @@ AssetEngine *BKE_asset_engine_create(AssetEngineType *type);
AssetEngine *BKE_asset_engine_copy(AssetEngine *engine);
void BKE_asset_engine_free(AssetEngine *engine);
-void BKE_asset_engine_load_pre(AssetEngine *engine, struct FileDirEntryArr *r_entries);
+AssetUUIDList *BKE_asset_engine_load_pre(AssetEngine *engine, struct FileDirEntryArr *r_entries);
/* File listing utils... */
diff --git a/source/blender/blenkernel/intern/asset.c b/source/blender/blenkernel/intern/asset.c
index 0768cbe..c2ea630 100644
--- a/source/blender/blenkernel/intern/asset.c
+++ b/source/blender/blenkernel/intern/asset.c
@@ -144,38 +144,62 @@ void BKE_asset_engine_free(AssetEngine *engine)
/* API helpers. */
-void BKE_asset_engine_load_pre(AssetEngine *engine, FileDirEntryArr *r_entries)
+AssetUUIDList *BKE_asset_engine_load_pre(AssetEngine *engine, FileDirEntryArr *r_entries)
{
- if (engine->type->load_pre) {
- AssetUUIDList *uuids = MEM_mallocN(sizeof(*uuids), __func__);
- FileDirEntry *en;
- const int nbr_entries = r_entries->nbr_entries;
- int i;
+ AssetUUIDList *uuids = MEM_mallocN(sizeof(*uuids), __func__);
+ FileDirEntry *en;
+ const int nbr_entries = r_entries->nbr_entries;
+ int i;
- uuids->uuids = MEM_mallocN(sizeof(*uuids->uuids) * nbr_entries, __func__);
- uuids->nbr_uuids = nbr_entries;
+ uuids->uuids = MEM_mallocN(sizeof(*uuids->uuids) * nbr_entries, __func__);
+ uuids->nbr_uuids = nbr_entries;
- for (i = 0, en = r_entries->entries.first; en; i++, en = en->next) {
- FileDirEntryVariant *var = BLI_findlink(&en->variants, en->act_variant);
- AssetUUID *uuid = &uuids->uuids[i];
+ for (i = 0, en = r_entries->entries.first; en; i++, en = en->next) {
+ FileDirEntryVariant *var = BLI_findlink(&en->variants, en->act_variant);
+ AssetUUID *uuid = &uuids->uuids[i];
- memcpy(uuid->uuid_asset, en->uuid, sizeof(uuid->uuid_asset));
+ memcpy(uuid->uuid_asset, en->uuid, sizeof(uuid->uuid_asset));
- BLI_assert(var);
- memcpy(uuid->uuid_variant, var->uuid, sizeof(uuid->uuid_variant));
+ BLI_assert(var);
+ memcpy(uuid->uuid_variant, var->uuid, sizeof(uuid->uuid_variant));
- memcpy(uuid->uuid_revision, en->entry->uuid, sizeof(uuid->uuid_revision));
- }
+ memcpy(uuid->uuid_revision, en->entry->uuid, sizeof(uuid->uuid_revision));
+ }
+
+ if (engine->type->load_pre) {
+ BKE_filedir_entryarr_clear(r_entries);
if (!engine->type->load_pre(engine, uuids, r_entries)) {
/* If load_pre returns false (i.e. fails), clear all paths! */
/* TODO: report!!! */
BKE_filedir_entryarr_clear(r_entries);
+
+ MEM_freeN(uuids->uuids);
+ MEM_freeN(uuids);
+ return NULL;
}
- MEM_freeN(uuids->uuids);
- MEM_freeN(uuids);
+ /* load_pre may change things, we have to rebuild our uuids list from returned entries. */
+ r_entries->nbr_entries = uuids->nbr_uuids = BLI_listbase_count(&r_entries->entries);
+ uuids->uuids = MEM_reallocN(uuids->uuids, sizeof(*uuids->uuids) * uuids->nbr_uuids);
+ for (i = 0, en = r_entries->entries.first; en; i++, en = en->next) {
+ FileDirEntryVariant *var;
+ FileDirEntryRevision *rev;
+ AssetUUID *uuid = &uuids->uuids[i];
+
+ memcpy(uuid->uuid_asset, en->uuid, sizeof(uuid->uuid_asset));
+
+ var = BLI_findlink(&en->variants, en->act_variant);
+ BLI_assert(var);
+ memcpy(uuid->uuid_variant, var->uuid, sizeof(uuid->uuid_variant));
+
+ rev = BLI_findlink(&var->revisions, var->act_revision);
+ BLI_assert(rev);
+ memcpy(uuid->uuid_revision, rev->uuid, sizeof(uuid->uuid_revision));
+ }
}
+
+ return uuids;
}
diff --git a/source/blender/editors/space_file/file_ops.c b/source/blender/editors/space_file/file_ops.c
index 72ffb48..9f9b32d 100644
--- a/source/blender/editors/space_file/file_ops.c
+++ b/source/blender/editors/space_file/file_ops.c
@@ -841,10 +841,12 @@ void FILE_OT_cancel(struct wmOperatorType *ot)
}
-static void file_sfile_to_operator(wmOperator *op, SpaceFile *sfile, char filepath[FILE_MAX_LIBEXTRA], const bool is_fake)
+static void file_sfile_to_operator(
+ wmOperator *op, SpaceFile *sfile, char filepath[FILE_MAX_LIBEXTRA], const bool is_fake)
{
PropertyRNA *prop, *prop_files, *prop_dirs;
AssetEngine *ae = filelist_assetengine_get(sfile->files);
+ AssetUUIDList *uuids;
FileDirEntryArr *selection;
FileCheckType check = CHECK_NONE;
@@ -857,7 +859,11 @@ static void file_sfile_to_operator(wmOperator *op, SpaceFile *sfile, char filepa
BLI_assert(STREQ(sfile->params->dir, filelist_dir(sfile->files)));
- selection = filelist_selection_get(sfile->files, check, sfile->params->file, !is_fake);
+ selection = filelist_selection_get(sfile->files, check, sfile->params->file, &uuids, !is_fake);
+
+ if (ae && selection->nbr_entries) {
+ BLI_assert(uuids);
+ }
if ((prop = RNA_struct_find_property(op->ptr, "directory"))) {
RNA_property_string_set(op->ptr, prop, selection->root);
@@ -881,6 +887,17 @@ static void file_sfile_to_operator(wmOperator *op, SpaceFile *sfile, char filepa
if ((prop = RNA_struct_find_property(op->ptr, "filepath"))) {
RNA_property_string_set(op->ptr, prop, filepath);
}
+ if (ae) {
+ if ((prop = RNA_struct_find_property(op->ptr, "asset_uuid"))) {
+ RNA_property_int_set_array(op->ptr, prop, uuids->uuids[0].uuid_asset);
+ }
+ if ((prop = RNA_struct_find_property(op->ptr, "variant_uuid"))) {
+ RNA_property_int_set_array(op->ptr, prop, uuids->uuids[0].uuid_variant);
+ }
+ if ((prop = RNA_struct_find_property(op->ptr, "revision_uuid"))) {
+ RNA_property_int_set_array(op->ptr, prop, uuids->uuids[0].uuid_revision);
+ }
+ }
/* some ops have multiple files to select */
/* this is called on operators check() so clear collections first since
@@ -889,12 +906,19 @@ static void file_sfile_to_operator(wmOperator *op, SpaceFile *sfile, char filepa
if (prop_files) {
FileDirEntry *entry;
PointerRNA itemptr;
+ int i;
RNA_property_collection_clear(op->ptr, prop_files);
- for (entry = selection->entries.first; entry; entry = entry->next) {
+ for (i = 0, entry = selection->entries.first; entry; entry = entry->next, i++) {
if (!(entry->typeflag & FILE_TYPE_DIR)) {
RNA_property_collection_add(op->ptr, prop_files, &itemptr);
RNA_string_set(&itemptr, "name", entry->relpath);
+ if (ae) {
+ BLI_assert(i < uuids->nbr_uuids);
+ RNA_int_set_array(&itemptr, "asset_uuid", uuids->uuids[i].uuid_asset);
+ RNA_int_set_array(&itemptr, "variant_uuid", uuids->uuids[i].uuid_variant);
+ RNA_int_set_array(&itemptr, "revision_uuid", uuids->uuids[i].uuid_revision);
+ }
}
}
}
@@ -938,11 +962,12 @@ static void file_sfile_to_operator(wmOperator *op, SpaceFile *sfile, char filepa
}
if (!is_fake && ae && (prop = RNA_struct_find_property(op->ptr, "asset_engine"))) {
- PointerRNA ptr;
+ RNA_property_string_set(op->ptr, prop, ae->type->idname);
+ }
- ae = BKE_asset_engine_copy(ae); /* Operator is responsible to free/release that! */
- RNA_pointer_create(NULL, &RNA_AssetEngine, ae, &ptr);
- RNA_property_pointer_set(op->ptr, prop, ptr);
+ if (uuids) {
+ MEM_freeN(uuids->uuids);
+ MEM_freeN(uuids);
}
BKE_filedir_entryarr_clear(selection);
diff --git a/source/blender/editors/space_file/filelist.c b/source/blender/editors/space_file/filelist.c
index e76723c..54058f3 100644
--- a/source/blender/editors/space_file/filelist.c
+++ b/source/blender/editors/space_file/filelist.c
@@ -2115,7 +2115,8 @@ unsigned int filelist_entry_select_index_get(FileList *filelist, const int index
* Returns a list of selected entries, if use_ae is set also calls asset engine's load_pre callback.
* Note first item of returned list shall be used as 'active' file.
*/
-FileDirEntryArr *filelist_selection_get(FileList *filelist, FileCheckType check, const char *name, const bool use_ae)
+FileDirEntryArr *filelist_selection_get(
+ FileList *filelist, FileCheckType check, const char *name, AssetUUIDList **r_uuids, const bool use_ae)
{
FileDirEntryArr *selection;
GHashIterator *iter = BLI_ghashIterator_new(filelist->selection_state);
@@ -2155,7 +2156,10 @@ FileDirEntryArr *filelist_selection_get(FileList *filelist, FileCheckType check,
if (use_ae && filelist->ae) {
/* This will 'rewrite' selection list, returned paths are expected to be valid! */
- BKE_asset_engine_load_pre(filelist->ae, selection);
+ *r_uuids = BKE_asset_engine_load_pre(filelist->ae, selection);
+ }
+ else {
+ *r_uuids = NULL;
}
return selection;
diff --git a/source/blender/editors/space_file/filelist.h b/source/blender/editors/space_file/filelist.h
index 1ef5855..be8b313 100644
--- a/source/blender/editors/space_file/filelist.h
+++ b/source/blender/editors/space_file/filelist.h
@@ -105,7 +105,8 @@ void filelist_entry_select_index_set(struct FileList *filelist, c
void filelist_entries_select_index_range_set(struct FileList *filelist, FileSelection *sel, FileSelType select, unsigned int flag, FileCheckType check);
unsigned int filelist_entry_select_get(struct FileList *filelist, struct FileDirEntry *entry, FileCheckType check);
unsigned int filelist_entry_select_index_get(struct F
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list