[Bf-blender-cvs] [87dc360] gooseberry: Updated hash table for lookup of enabled cache items and added basic UI support.
Lukas Tönne
noreply at git.blender.org
Mon Mar 23 13:00:51 CET 2015
Commit: 87dc360d7e323bc91d7e01711c469bfd21c3210e
Author: Lukas Tönne
Date: Mon Feb 23 19:24:53 2015 +0100
Branches: gooseberry
https://developer.blender.org/rB87dc360d7e323bc91d7e01711c469bfd21c3210e
Updated hash table for lookup of enabled cache items and added basic
UI support.
===================================================================
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/editors/io/io_cache_library.c
M source/blender/editors/io/io_cache_library.h
M source/blender/editors/io/io_ops.c
M source/blender/makesdna/DNA_cache_library_types.h
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 ea46788..7beed41 100644
--- a/release/scripts/startup/bl_ui/properties_scene.py
+++ b/release/scripts/startup/bl_ui/properties_scene.py
@@ -406,6 +406,20 @@ class SCENE_PT_cache_manager(SceneButtonsPanel, Panel):
bl_label = "Cache Manager"
COMPAT_ENGINES = {'BLENDER_RENDER'}
+ # returns True if the item exists and is enabled
+ def draw_cache_item_button(self, context, layout, cachelib, ob, type, index=-1):
+ item = cachelib.cache_item_find(ob, type, index)
+ if not item:
+ sub = layout.row()
+ sub.context_pointer_set("cachelib", cachelib)
+ sub.context_pointer_set("cache_object", ob)
+ props = sub.operator("cachelibrary.item_enable", text="", icon='ZOOMIN', emboss=True)
+ props.type = type
+ props.index = index
+ else:
+ layout.prop(item, "enabled", text="")
+ return bool(item and item.enabled)
+
def draw_cachelib(self, context, layout, cachelib):
first = True
for obcache in cachelib.object_caches:
@@ -415,7 +429,12 @@ class SCENE_PT_cache_manager(SceneButtonsPanel, Panel):
layout.separator()
first = False
- row.label(text=ob.name, icon_value=layout.icon(ob))
+ row = layout.row()
+ enabled = self.draw_cache_item_button(context, row, cachelib, ob, 'OBJECT')
+
+ sub = row.row()
+ sub.enabled = enabled
+ sub.label(text=ob.name, icon_value=layout.icon(ob))
def draw(self, context):
layout = self.layout
diff --git a/source/blender/blenkernel/BKE_cache_library.h b/source/blender/blenkernel/BKE_cache_library.h
index 123bf6e..b81318b 100644
--- a/source/blender/blenkernel/BKE_cache_library.h
+++ b/source/blender/blenkernel/BKE_cache_library.h
@@ -74,9 +74,7 @@ void BKE_cache_library_walk(struct CacheLibrary *cachelib, CacheGroupWalkFunc wa
#endif
struct CacheItem *BKE_cache_library_find_item(struct CacheLibrary *cachelib, struct Object *ob, int type, int index);
-#if 0
-struct CacheItem *BKE_cache_library_add_item(struct CacheLibrary *cachelib, const struct CacheItem *path);
-bool BKE_cache_library_remove_item(struct CacheLibrary *cachelib, const struct CacheItem *path);
-#endif
+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);
#endif
diff --git a/source/blender/blenkernel/intern/cache_library.c b/source/blender/blenkernel/intern/cache_library.c
index e001ac1..7cc6369 100644
--- a/source/blender/blenkernel/intern/cache_library.c
+++ b/source/blender/blenkernel/intern/cache_library.c
@@ -76,6 +76,9 @@ CacheLibrary *BKE_cache_library_copy(CacheLibrary *cachelib)
void BKE_cache_library_free(CacheLibrary *cachelib)
{
BLI_freelistN(&cachelib->items);
+
+ if (cachelib->items_hash)
+ BLI_ghash_free(cachelib->items_hash, NULL, NULL);
}
/* ========================================================================= */
@@ -331,19 +334,17 @@ static void cache_library_insert_item_hash(CacheLibrary *cachelib, CacheItem *it
BLI_ghash_insert(cachelib->items_hash, item, item);
}
-static void UNUSED_FUNCTION(cache_library_ensure_items_hash)(CacheLibrary *cachelib)
+/* make sure the items hash exists (lazy init after loading files) */
+static void cache_library_ensure_items_hash(CacheLibrary *cachelib)
{
CacheItem *item;
- if (cachelib->items_hash) {
- BLI_ghash_clear(cachelib->items_hash, NULL, NULL);
- }
- else {
+ if (!cachelib->items_hash) {
cachelib->items_hash = BLI_ghash_new(cache_item_hash, cache_item_cmp, "cache item hash");
- }
-
- for (item = cachelib->items.first; item; item = item->next) {
- cache_library_insert_item_hash(cachelib, item, true);
+
+ for (item = cachelib->items.first; item; item = item->next) {
+ cache_library_insert_item_hash(cachelib, item, true);
+ }
}
}
@@ -354,17 +355,25 @@ CacheItem *BKE_cache_library_find_item(CacheLibrary *cachelib, Object *ob, int t
item.ob = ob;
item.type = type;
item.index = index;
+
+ cache_library_ensure_items_hash(cachelib);
+
return BLI_ghash_lookup(cachelib->items_hash, &item);
}
-#if 0
-CacheItem *BKE_cache_library_add_item(CacheLibrary *cachelib, const CacheItemPath *path)
+CacheItem *BKE_cache_library_add_item(CacheLibrary *cachelib, struct Object *ob, int type, int index)
{
- CacheItem *item = BLI_ghash_lookup(cachelib->items_hash, path);
+ CacheItem *item;
+
+ cache_library_ensure_items_hash(cachelib);
+
+ item = BKE_cache_library_find_item(cachelib, ob, type, index);
if (!item) {
item = MEM_callocN(sizeof(CacheItem), "cache library item");
- cache_path_copy(&item->path, path);
+ item->ob = ob;
+ item->type = type;
+ item->index = index;
BLI_addtail(&cachelib->items, item);
cache_library_insert_item_hash(cachelib, item, false);
@@ -373,19 +382,15 @@ CacheItem *BKE_cache_library_add_item(CacheLibrary *cachelib, const CacheItemPat
return item;
}
-bool BKE_cache_library_remove_item(CacheLibrary *cachelib, const CacheItemPath *path)
+void BKE_cache_library_remove_item(CacheLibrary *cachelib, CacheItem *item)
{
- CacheItem *item = BLI_ghash_lookup(cachelib->items_hash, path);
if (item) {
- BLI_ghash_remove(cachelib->items_hash, (CacheItemPath *)path, NULL, NULL);
+ if (cachelib->items_hash)
+ BLI_ghash_remove(cachelib->items_hash, item, NULL, NULL);
BLI_remlink(&cachelib->items, item);
MEM_freeN(item);
- return true;
}
- else
- return false;
}
-#endif
/* ========================================================================= */
diff --git a/source/blender/editors/io/io_cache_library.c b/source/blender/editors/io/io_cache_library.c
index a35f9dc..361f940 100644
--- a/source/blender/editors/io/io_cache_library.c
+++ b/source/blender/editors/io/io_cache_library.c
@@ -33,6 +33,7 @@
#include "BLI_utildefines.h"
#include "DNA_cache_library_types.h"
+#include "DNA_object_types.h"
#include "BKE_cache_library.h"
#include "BKE_context.h"
@@ -44,6 +45,7 @@
#include "RNA_access.h"
#include "RNA_define.h"
+#include "RNA_enum_types.h"
#include "UI_interface.h"
#include "UI_resources.h"
@@ -101,3 +103,52 @@ void CACHELIBRARY_OT_new(wmOperatorType *ot)
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
}
+
+/********************** enable cache item operator *********************/
+
+static int cache_item_enable_poll(bContext *C)
+{
+ CacheLibrary *cachelib = CTX_data_pointer_get_type(C, "cachelib", &RNA_CacheLibrary).data;
+ Object *obcache = CTX_data_pointer_get_type(C, "cache_object", &RNA_Object).data;
+
+ if (!cachelib || !obcache)
+ return false;
+
+ return true;
+}
+
+static int cache_item_enable_exec(bContext *C, wmOperator *op)
+{
+ CacheLibrary *cachelib = CTX_data_pointer_get_type(C, "cachelib", &RNA_CacheLibrary).data;
+ Object *obcache = CTX_data_pointer_get_type(C, "cache_object", &RNA_Object).data;
+ int type = RNA_enum_get(op->ptr, "type");
+ int index = RNA_int_get(op->ptr, "index");
+
+ CacheItem *item = BKE_cache_library_add_item(cachelib, obcache, type, index);
+ item->flag |= CACHE_ITEM_ENABLED;
+
+ WM_event_add_notifier(C, NC_OBJECT, cachelib);
+
+ return OPERATOR_FINISHED;
+}
+
+void CACHELIBRARY_OT_item_enable(wmOperatorType *ot)
+{
+ PropertyRNA *prop;
+
+ /* identifiers */
+ ot->name = "Enable Cache Item";
+ ot->idname = "CACHELIBRARY_OT_item_enable";
+ ot->description = "Enable a cache item";
+
+ /* api callbacks */
+ ot->poll = cache_item_enable_poll;
+ ot->exec = cache_item_enable_exec;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
+
+ prop = RNA_def_enum(ot->srna, "type", cache_library_item_type_items, CACHE_TYPE_OBJECT, "Type", "Type of cache item to add");
+ RNA_def_property_flag(prop, PROP_REQUIRED);
+ RNA_def_int(ot->srna, "index", -1, -1, INT_MAX, "Index", "Index of data in the object", -1, INT_MAX);
+}
diff --git a/source/blender/editors/io/io_cache_library.h b/source/blender/editors/io/io_cache_library.h
index 557e53c..c071c54 100644
--- a/source/blender/editors/io/io_cache_library.h
+++ b/source/blender/editors/io/io_cache_library.h
@@ -34,4 +34,6 @@ struct wmOperatorType;
void CACHELIBRARY_OT_new(struct wmOperatorType *ot);
+void CACHELIBRARY_OT_item_enable(struct wmOperatorType *ot);
+
#endif
diff --git a/source/blender/editors/io/io_ops.c b/source/blender/editors/io/io_ops.c
index f967f85..d897f3e 100644
--- a/source/blender/editors/io/io_ops.c
+++ b/source/blender/editors/io/io_ops.c
@@ -40,6 +40,7 @@
void ED_operatortypes_io(void)
{
WM_operatortype_append(CACHELIBRARY_OT_new);
+ WM_operatortype_append(CACHELIBRARY_OT_item_enable);
#ifdef WITH_COLLADA
/* Collada operators: */
diff --git a/source/blender/makesdna/DNA_cache_library_types.h b/source/blender/makesdna/DNA_cache_library_types.h
index 7d65778..dba34e0 100644
--- a/source/blender/makesdna/DNA_cache_library_types.h
+++ b/source/blender/makesdna/DNA_cache_library_types.h
@@ -51,8 +51,15 @@ typedef struct CacheItem {
struct Object *ob;
int type;
int index;
+
+ int flag;
+ int pad;
} CacheItem;
+typedef enum eCacheItem_Flag {
+ CACHE_ITEM_ENABLED = 1,
+} eCacheItem_Flag;
+
typedef struct CacheLibrary {
ID id;
diff --git a/source/blender/makesrna/intern/rna_cache_library.c b/source/blender/makesrna/intern/rna_cache_library.c
index 2e9af36..3007035 100644
--- a/source/blender/makesrna/intern/rna_cache_library.c
+++ b/source/blender/makesrna/intern/rna_cache_library.c
@@ -175,6 +175,12 @@ static void rna_def_cache_item(BlenderRNA *brna)
srna = RNA_def_struct(brna, "CacheItem", NULL);
RNA_def_struct_ui_text(srna, "Cache Item", "Description of a cacheable item in an object");
+ prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
+ RNA_def_property_pointer_sdna(prop, NULL, "ob");
+ RNA_def_property_struct_type(prop, "Object");
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_ui_text(prop, "Object", "");
+
prop
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list