[Bf-blender-cvs] [47e3d34] asset-experiments: RNA listdir: add some more accessors, and ability to remove/clear list of entries (assets).

Bastien Montagne noreply at git.blender.org
Thu Mar 12 19:42:04 CET 2015


Commit: 47e3d34d94f8bee062948c89247f0c66c0915afa
Author: Bastien Montagne
Date:   Thu Mar 12 15:19:27 2015 +0100
Branches: asset-experiments
https://developer.blender.org/rB47e3d34d94f8bee062948c89247f0c66c0915afa

RNA listdir: add some more accessors, and ability to remove/clear list of entries (assets).

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

M	source/blender/blenkernel/BKE_asset.h
M	source/blender/blenkernel/intern/asset.c
M	source/blender/makesrna/intern/rna_asset.c

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

diff --git a/source/blender/blenkernel/BKE_asset.h b/source/blender/blenkernel/BKE_asset.h
index 8a3a173..c37a1b5 100644
--- a/source/blender/blenkernel/BKE_asset.h
+++ b/source/blender/blenkernel/BKE_asset.h
@@ -42,6 +42,8 @@ struct AssetEngine;
 struct AssetEngineType;
 struct FileDirEntryArr;
 struct FileDirEntry;
+struct FileDirEntryVariant;
+struct FileDirEntryRevision;
 struct ExtensionRNA;
 struct ID;
 struct ListBase;
@@ -149,10 +151,10 @@ typedef enum FileCheckType {
 	CHECK_ALL   = CHECK_DIRS | CHECK_FILES,
 } FileCheckType;
 
-#if 0  /* Unused */
+void BKE_filedir_variant_free(struct FileDirEntryVariant *var);
+
 void BKE_filedir_entry_free(struct FileDirEntry *entry);
 void BKE_filedir_entry_clear(struct FileDirEntry *entry);
-#endif
 struct FileDirEntry *BKE_filedir_entry_copy(struct FileDirEntry *entry);
 
 void BKE_filedir_entryarr_clear(struct FileDirEntryArr *array);
diff --git a/source/blender/blenkernel/intern/asset.c b/source/blender/blenkernel/intern/asset.c
index f451cc9..7cfae41 100644
--- a/source/blender/blenkernel/intern/asset.c
+++ b/source/blender/blenkernel/intern/asset.c
@@ -169,7 +169,17 @@ void BKE_asset_engine_load_pre(AssetEngine *engine, FileDirEntryArr *r_entries)
 
 /* FileDirxxx handling. */
 
-#if 0 /* Unused */
+void BKE_filedir_variant_free(FileDirEntryVariant *var)
+{
+	if (var->name) {
+		MEM_freeN(var->name);
+	}
+	if (var->description) {
+		MEM_freeN(var->description);
+	}
+	BLI_freelistN(&var->revisions);
+}
+
 void BKE_filedir_entry_free(FileDirEntry *entry)
 {
 	if (entry->name) {
@@ -190,13 +200,7 @@ void BKE_filedir_entry_free(FileDirEntry *entry)
 		FileDirEntryVariant *var;
 
 		for (var = entry->variants.first; var; var = var->next) {
-			if (var->name) {
-				MEM_freeN(var->name);
-			}
-			if (var->description) {
-				MEM_freeN(var->description);
-			}
-			BLI_freelistN(&var->revisions);
+			BKE_filedir_variant_free(var);
 		}
 
 		BLI_freelistN(&entry->variants);
@@ -213,45 +217,6 @@ void BKE_filedir_entry_clear(FileDirEntry *entry)
 	BKE_filedir_entry_free(entry);
 	memset(entry, 0, sizeof(*entry));
 }
-#else
-static void BKE_filedir_entry_free(FileDirEntry *entry)
-{
-	if (entry->name) {
-		MEM_freeN(entry->name);
-	}
-	if (entry->description) {
-		MEM_freeN(entry->description);
-	}
-	if (entry->relpath) {
-		MEM_freeN(entry->relpath);
-	}
-	if (entry->image) {
-		IMB_freeImBuf(entry->image);
-	}
-	/* For now, consider FileDirEntryRevision::poin as not owned here, so no need to do anything about it */
-
-	if (!BLI_listbase_is_empty(&entry->variants)) {
-		FileDirEntryVariant *var;
-
-		for (var = entry->variants.first; var; var = var->next) {
-			if (var->name) {
-				MEM_freeN(var->name);
-			}
-			if (var->description) {
-				MEM_freeN(var->description);
-			}
-			BLI_freelistN(&var->revisions);
-		}
-
-		BLI_freelistN(&entry->variants);
-	}
-	else if (entry->entry){
-		MEM_freeN(entry->entry);
-	}
-
-	/* TODO: tags! */
-}
-#endif
 
 /** Perform and return a full (deep) duplicate of given entry. */
 FileDirEntry *BKE_filedir_entry_copy(FileDirEntry *entry)
diff --git a/source/blender/makesrna/intern/rna_asset.c b/source/blender/makesrna/intern/rna_asset.c
index f3e13ee..f44ff82 100644
--- a/source/blender/makesrna/intern/rna_asset.c
+++ b/source/blender/makesrna/intern/rna_asset.c
@@ -153,16 +153,6 @@ static void rna_AssetVariant_description_set(struct PointerRNA *ptr, const char
 }
 
 /* Entries. */
-static FileDirEntryVariant *rna_AssetEntry_variants_add(FileDirEntry *entry/*, ReportList *reports,*/)
-{
-	FileDirEntryVariant *variant = MEM_callocN(sizeof(*variant), __func__);
-
-	BLI_addtail(&entry->variants, variant);
-	entry->nbr_variants++;
-
-	return variant;
-}
-
 static PointerRNA rna_AssetEntry_active_variant_get(PointerRNA *ptr)
 {
 	FileDirEntry *entry = ptr->data;
@@ -177,6 +167,16 @@ static void rna_AssetEntry_active_variant_set(PointerRNA *ptr, PointerRNA value)
 	entry->act_variant = BLI_findindex(&entry->variants, variant);
 }
 
+static FileDirEntryVariant *rna_AssetEntry_variants_add(FileDirEntry *entry/*, ReportList *reports,*/)
+{
+	FileDirEntryVariant *variant = MEM_callocN(sizeof(*variant), __func__);
+
+	BLI_addtail(&entry->variants, variant);
+	entry->nbr_variants++;
+
+	return variant;
+}
+
 static void rna_AssetEntry_relpath_get(struct PointerRNA *ptr, char *value)
 {
 	FileDirEntry *entry = ptr->data;
@@ -256,7 +256,27 @@ static void rna_AssetEntry_description_set(struct PointerRNA *ptr, const char *v
 }
 
 /* Entries Array. */
-static FileDirEntry *rna_AssetList_entries_add(FileDirEntryArr *dirlist/*, ReportList *reports,*/)
+static PointerRNA rna_AssetList_active_entry_get(PointerRNA *ptr)
+{
+	FileDirEntryArr *arr = ptr->data;
+	return rna_pointer_inherit_refine(ptr, &RNA_AssetEntry, BLI_findlink(&arr->entries, 0));
+}
+
+static void rna_AssetList_active_entry_set(PointerRNA *ptr, PointerRNA value)
+{
+	FileDirEntryArr *arr = ptr->data;
+	FileDirEntry *entry = value.data;
+
+	BLI_remlink_safe(&arr->entries, entry);
+	BLI_addhead(&arr->entries, entry);
+}
+
+static int rna_AssetList_active_entry_index_get(PointerRNA *UNUSED(ptr))
+{
+	return 0;
+}
+
+static FileDirEntry *rna_AssetList_entries_add(FileDirEntryArr *dirlist)
 {
 	FileDirEntry *entry = MEM_callocN(sizeof(*entry), __func__);
 
@@ -266,6 +286,23 @@ static FileDirEntry *rna_AssetList_entries_add(FileDirEntryArr *dirlist/*, Repor
 	return entry;
 }
 
+static void rna_AssetList_entries_remove(FileDirEntryArr *dirlist, ReportList *reports, PointerRNA *ptr)
+{
+	FileDirEntry *entry = ptr->data;
+
+	if (!BLI_remlink_safe(&dirlist->entries, entry)) {
+		BKE_report(reports, RPT_ERROR, "Trying to remove an entry for a list which does not contain it!");
+		return;
+	}
+
+	BKE_filedir_entry_free(entry);
+	MEM_freeN(entry);
+}
+
+static void rna_AssetList_entries_clear(FileDirEntryArr *dirlist)
+{
+	BKE_filedir_entryarr_clear(dirlist);
+}
 
 /* AssetEngine callbacks. */
 
@@ -549,14 +586,6 @@ static void rna_def_asset_variants(BlenderRNA *brna, PropertyRNA *cprop)
 	RNA_def_struct_sdna(srna, "FileDirEntry");
 	RNA_def_struct_ui_text(srna, "Asset Entry Variants", "Collection of asset entry's variants");
 
-	/* Add Variant */
-	func = RNA_def_function(srna, "add", "rna_AssetEntry_variants_add");
-	RNA_def_function_ui_description(func, "Add a new variant to the entry");
-//	RNA_def_function_flag(func, FUNC_USE_REPORTS);
-	/* return arg */
-	parm = RNA_def_pointer(func, "variant", "AssetVariant", "New Variant", "New asset entry variant");
-	RNA_def_function_return(func, parm);
-
 	prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
 	RNA_def_property_struct_type(prop, "AssetVariant");
 	RNA_def_property_flag(prop, PROP_EDITABLE);
@@ -567,6 +596,14 @@ static void rna_def_asset_variants(BlenderRNA *brna, PropertyRNA *cprop)
 	prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_NONE);
 	RNA_def_property_int_sdna(prop, NULL, "act_variant");
 	RNA_def_property_ui_text(prop, "Active Index", "Index of asset's variant curently active (selected)");
+
+	/* Add Variant */
+	func = RNA_def_function(srna, "add", "rna_AssetEntry_variants_add");
+	RNA_def_function_ui_description(func, "Add a new variant to the entry");
+//	RNA_def_function_flag(func, FUNC_USE_REPORTS);
+	/* return arg */
+	parm = RNA_def_pointer(func, "variant", "AssetVariant", "New Variant", "New asset entry variant");
+	RNA_def_function_return(func, parm);
 }
 
 static void rna_def_asset_entry(BlenderRNA *brna)
@@ -644,51 +681,45 @@ static void rna_def_asset_entries(BlenderRNA *brna, PropertyRNA *cprop)
 {
 	StructRNA *srna;
 	FunctionRNA *func;
-	PropertyRNA *parm;
+	PropertyRNA *parm, *prop;
 
 	RNA_def_property_srna(cprop, "AssetEntries");
 	srna = RNA_def_struct(brna, "AssetEntries", NULL);
 	RNA_def_struct_sdna(srna, "FileDirEntryArr");
 	RNA_def_struct_ui_text(srna, "Asset List entries", "Collection of asset entries");
 
+	/* Currently, 'active' entry (i.e. the one passed to single-file arg of operators) is always the
+	 * first of the list... */
+	prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
+	RNA_def_property_struct_type(prop, "AssetEntry");
+	RNA_def_property_flag(prop, PROP_EDITABLE);
+	RNA_def_property_pointer_funcs(prop, "rna_AssetList_active_entry_get",
+	                               "rna_AssetList_active_entry_set", NULL, NULL);
+	RNA_def_property_ui_text(prop, "Active Entry", "Active (selected) entry of the list");
+
+	prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_NONE);
+	RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+	RNA_def_property_int_funcs(prop, "rna_AssetList_active_entry_index_get", NULL, NULL);
+	RNA_def_property_ui_text(prop, "Active Index", "Index of entry curently active (selected)");
+
 	/* Add Entry */
 	func = RNA_def_function(srna, "add", "rna_AssetList_entries_add");
 	RNA_def_function_ui_description(func, "Add a new asset entry to the list");
-//	RNA_def_function_flag(func, FUNC_USE_REPORTS);
 	/* return arg */
 	parm = RNA_def_pointer(func, "entry", "AssetEntry", "New Entry", "New asset entry");
 	RNA_def_function_return(func, parm);
 
-#if 0
-	/* Remove Path */
-	func = RNA_def_function(srna, "remove", "rna_KeyingSet_paths_remove");
-	RNA_def_function_ui_description(func, "Remove the given path from the Keying Set");
+	/* Remove Entry */
+	func = RNA_def_function(srna, "remove", "rna_AssetList_entries_remove");
+	RNA_def_function_ui_description(func, "Remove the given entry from the list (entry is freeded)");
 	RNA_def_function_flag(func, FUNC_USE_REPORTS);
-	/* path to remove */
-	parm = RNA_def_pointer(func, "path", "KeyingSetPath", "Path", "");
+	parm = RNA_def_pointer(func, "entry", "AssetEntry", "Entry", "");
 	RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL | PROP_RNAPTR);
 	RNA_def_property_clear_flag(parm, PROP_THICK_WRAP);
 
-
-	/* Remove All Paths */
-	func = RNA_def_function(srna, "clear", "rna_KeyingSet_paths_clear");
-	RNA_def_function_ui_description(func, "Remove all the paths from the Keying Set");
-	RNA_def_function_flag(func, FUNC_USE_REPORTS);
-
-	prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
-	RNA_def_property_struct_type(prop, "KeyingSetPath");
-	RNA_def_property_flag(prop, PROP_EDITABLE);
-	RNA_def_property_

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list