[Bf-blender-cvs] [eb67851] gooseberry: Name string construction for cache items, to use as a unique identifier in the cache library.
Lukas Tönne
noreply at git.blender.org
Mon Mar 23 13:00:54 CET 2015
Commit: eb6785112b9234648b96aae0953b214936a3a544
Author: Lukas Tönne
Date: Tue Feb 24 11:34:44 2015 +0100
Branches: gooseberry
https://developer.blender.org/rBeb6785112b9234648b96aae0953b214936a3a544
Name string construction for cache items, to use as a unique identifier
in the cache library.
===================================================================
M release/scripts/startup/bl_ui/properties_scene.py
M source/blender/blenkernel/BKE_cache_library.h
M source/blender/blenkernel/intern/cache_library.c
M source/blender/makesrna/intern/rna_cache_library.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_scene.py b/release/scripts/startup/bl_ui/properties_scene.py
index 970843a..d68fdd4 100644
--- a/release/scripts/startup/bl_ui/properties_scene.py
+++ b/release/scripts/startup/bl_ui/properties_scene.py
@@ -420,25 +420,28 @@ class SCENE_PT_cache_manager(SceneButtonsPanel, Panel):
props.index = index
else:
layout.prop(item, "enabled", text="")
- return bool(item and item.enabled)
+ return item
def draw_cache_item(self, context, layout, cachelib, ob, type, index=-1):
+ from bpy.types import CacheItem
+
buttons = layout.row()
- enabled = self.draw_cache_item_button(context, buttons, cachelib, ob, type, index)
+ item = self.draw_cache_item_button(context, buttons, cachelib, ob, type, index)
sub = buttons.column()
- sub.enabled = enabled
+ sub.enabled = bool(item and item.enabled)
+ name = item.name if item else CacheItem.get_name(ob, type, index)
row = sub.row()
if type == 'OBJECT':
- row.label(text=ob.name, icon=self.item_type_icon[type])
+ row.label(text=name, icon=self.item_type_icon[type])
elif type == 'DERIVED_MESH':
- row.label(text="Mesh", icon=self.item_type_icon[type])
+ row.label(text=name, icon=self.item_type_icon[type])
#sub.label(text="Mesh", icon_value=layout.enum_item_icon())
elif type == 'HAIR':
- row.label(text="Hair", icon=self.item_type_icon[type])
+ row.label(text=name, icon=self.item_type_icon[type])
elif type == 'HAIR_PATHS':
- row.label(text="Hair Paths", icon=self.item_type_icon[type])
+ row.label(text=name, icon=self.item_type_icon[type])
return sub
diff --git a/source/blender/blenkernel/BKE_cache_library.h b/source/blender/blenkernel/BKE_cache_library.h
index b81318b..f4fb0ab 100644
--- a/source/blender/blenkernel/BKE_cache_library.h
+++ b/source/blender/blenkernel/BKE_cache_library.h
@@ -73,6 +73,10 @@ typedef void (*CacheGroupWalkFunc)(void *userdata, struct CacheLibrary *cachelib
void BKE_cache_library_walk(struct CacheLibrary *cachelib, CacheGroupWalkFunc walk, void *userdata);
#endif
+const char *BKE_cache_item_name_prefix(int type);
+void BKE_cache_item_name(struct Object *ob, int type, int index, char *name);
+int BKE_cache_item_name_length(struct Object *ob, int type, int index);
+
struct CacheItem *BKE_cache_library_find_item(struct CacheLibrary *cachelib, struct Object *ob, int type, int index);
struct CacheItem *BKE_cache_library_add_item(struct CacheLibrary *cachelib, struct Object *ob, int type, int index);
void BKE_cache_library_remove_item(struct CacheLibrary *cachelib, struct CacheItem *item);
diff --git a/source/blender/blenkernel/intern/cache_library.c b/source/blender/blenkernel/intern/cache_library.c
index 7cc6369..752ecc3 100644
--- a/source/blender/blenkernel/intern/cache_library.c
+++ b/source/blender/blenkernel/intern/cache_library.c
@@ -322,6 +322,36 @@ static bool cache_item_cmp(const void *key_a, const void *key_b)
return false;
}
+const char *BKE_cache_item_name_prefix(int type)
+{
+ /* note: avoid underscores and the like here,
+ * the prefixes must be unique and safe when combined with arbitrary strings!
+ */
+ switch (type) {
+ case CACHE_TYPE_OBJECT: return "OBJECT";
+ case CACHE_TYPE_DERIVED_MESH: return "MESH";
+ case CACHE_TYPE_HAIR: return "HAIR";
+ case CACHE_TYPE_HAIR_PATHS: return "HAIRPATHS";
+ default: BLI_assert(false); break;
+ }
+}
+
+void BKE_cache_item_name(Object *ob, int type, int index, char *name)
+{
+ if (index >= 0)
+ sprintf(name, "%s_%s_%d", BKE_cache_item_name_prefix(type), ob->id.name+2, index);
+ else
+ sprintf(name, "%s_%s", BKE_cache_item_name_prefix(type), ob->id.name+2);
+}
+
+int BKE_cache_item_name_length(Object *ob, int type, int index)
+{
+ if (index >= 0)
+ return snprintf(NULL, 0, "%s_%s_%d", BKE_cache_item_name_prefix(type), ob->id.name+2, index);
+ else
+ return snprintf(NULL, 0, "%s_%s", BKE_cache_item_name_prefix(type), ob->id.name+2);
+}
+
static void cache_library_insert_item_hash(CacheLibrary *cachelib, CacheItem *item, bool replace)
{
CacheItem *exist = BLI_ghash_lookup(cachelib->items_hash, item);
diff --git a/source/blender/makesrna/intern/rna_cache_library.c b/source/blender/makesrna/intern/rna_cache_library.c
index 3007035..b9819bf 100644
--- a/source/blender/makesrna/intern/rna_cache_library.c
+++ b/source/blender/makesrna/intern/rna_cache_library.c
@@ -26,6 +26,7 @@
#include <stdlib.h>
#include <assert.h>
+#include <string.h>
#include "DNA_cache_library_types.h"
@@ -49,6 +50,7 @@ EnumPropertyItem cache_library_item_type_items[] = {
#include "MEM_guardedalloc.h"
#include "BLI_listbase.h"
+#include "BLI_string.h"
#include "DNA_object_types.h"
@@ -59,6 +61,25 @@ EnumPropertyItem cache_library_item_type_items[] = {
#include "WM_api.h"
+static void rna_CacheItem_name_get(PointerRNA *ptr, char *value)
+{
+ CacheItem *item = ptr->data;
+ BKE_cache_item_name(item->ob, item->type, item->index, value);
+}
+
+static int rna_CacheItem_name_length(PointerRNA *ptr)
+{
+ CacheItem *item = ptr->data;
+ return BKE_cache_item_name_length(item->ob, item->type, item->index);
+}
+
+static void rna_CacheItem_get_name(struct Object *ob, int type, int index, char *name)
+{
+ BKE_cache_item_name(ob, type, index, name);
+}
+
+/* ========================================================================= */
+
static void rna_CacheLibrary_update(Main *UNUSED(main), Scene *UNUSED(scene), PointerRNA *UNUSED(ptr))
{
}
@@ -170,7 +191,8 @@ PointerRNA rna_ObjectCache_caches_get(CollectionPropertyIterator *iter)
static void rna_def_cache_item(BlenderRNA *brna)
{
StructRNA *srna;
- PropertyRNA *prop;
+ FunctionRNA *func;
+ PropertyRNA *prop, *parm;
srna = RNA_def_struct(brna, "CacheItem", NULL);
RNA_def_struct_ui_text(srna, "Cache Item", "Description of a cacheable item in an object");
@@ -195,6 +217,25 @@ static void rna_def_cache_item(BlenderRNA *brna)
prop = RNA_def_property(srna, "enabled", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", CACHE_ITEM_ENABLED);
RNA_def_property_ui_text(prop, "Enabled", "Enable caching for this item");
+
+ prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
+ RNA_def_property_string_maxlength(prop, 2*MAX_NAME);
+ RNA_def_property_string_funcs(prop, "rna_CacheItem_name_get", "rna_CacheItem_name_length", NULL);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_ui_text(prop, "Name", "");
+ RNA_def_struct_name_property(srna, prop);
+
+ func = RNA_def_function(srna, "get_name", "rna_CacheItem_get_name");
+ RNA_def_function_flag(func, FUNC_NO_SELF);
+ RNA_def_function_ui_description(func, "Get name of items from properties without an instance");
+ parm = RNA_def_pointer(func, "object", "Object", "Object", "");
+ RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL);
+ parm = RNA_def_enum(func, "type", cache_library_item_type_items, CACHE_TYPE_OBJECT, "Type", "Type of cache item");
+ RNA_def_property_flag(parm, PROP_REQUIRED);
+ RNA_def_int(func, "index", -1, -1, INT_MAX, "Index", "Index of the data in it's' collection", -1, INT_MAX);
+ parm = RNA_def_string(func, "name", NULL, 2*MAX_NAME, "Name", "");
+ RNA_def_property_flag(parm, PROP_THICK_WRAP);
+ RNA_def_function_output(func, parm);
}
static void rna_def_object_cache(BlenderRNA *brna)
More information about the Bf-blender-cvs
mailing list