[Bf-blender-cvs] [b8b9788] alembic_pointcache: `New` operator for adding cache libraries.

Lukas Tönne noreply at git.blender.org
Thu Feb 19 17:05:24 CET 2015


Commit: b8b978815847080e8bcdd0f5a740e6317cd97dbb
Author: Lukas Tönne
Date:   Thu Feb 19 13:49:28 2015 +0100
Branches: alembic_pointcache
https://developer.blender.org/rBb8b978815847080e8bcdd0f5a740e6317cd97dbb

`New` operator for adding cache libraries.

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

M	release/scripts/startup/bl_ui/properties_physics_common.py
M	source/blender/blenkernel/BKE_pointcache.h
M	source/blender/blenkernel/intern/pointcache.c
M	source/blender/editors/physics/physics_intern.h
M	source/blender/editors/physics/physics_ops.c
M	source/blender/editors/physics/physics_pointcache.c

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

diff --git a/release/scripts/startup/bl_ui/properties_physics_common.py b/release/scripts/startup/bl_ui/properties_physics_common.py
index e9210ad..8816032 100644
--- a/release/scripts/startup/bl_ui/properties_physics_common.py
+++ b/release/scripts/startup/bl_ui/properties_physics_common.py
@@ -118,7 +118,7 @@ def point_cache_ui(self, context, cache_user, cache, enabled, cachetype):
     layout.context_pointer_set("point_cache", cache)
     layout.context_pointer_set("point_cache_user", cache_user)
 
-    layout.template_ID(cache, "cache_library")
+    layout.template_ID(cache, "cache_library", new="cachelibrary.new")
 
     row = layout.row()
     if supports_external:
diff --git a/source/blender/blenkernel/BKE_pointcache.h b/source/blender/blenkernel/BKE_pointcache.h
index 3a9340f..9b5edf0 100644
--- a/source/blender/blenkernel/BKE_pointcache.h
+++ b/source/blender/blenkernel/BKE_pointcache.h
@@ -39,6 +39,7 @@
 #include <stdio.h> /* for FILE */
 
 CacheLibrary *BKE_cache_library_add(struct Main *bmain, const char *name);
+CacheLibrary *BKE_cache_library_copy(CacheLibrary *cachelib);
 void BKE_cache_library_free(CacheLibrary *cache);
 
 /* Point cache reset options */
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c
index 9846a48..da18e08 100644
--- a/source/blender/blenkernel/intern/pointcache.c
+++ b/source/blender/blenkernel/intern/pointcache.c
@@ -106,10 +106,6 @@
 #endif
 
 
-void BKE_cache_library_free(CacheLibrary *UNUSED(cache))
-{
-}
-
 CacheLibrary *BKE_cache_library_add(Main *bmain, const char *name)
 {
 	CacheLibrary *cachelib;
@@ -119,6 +115,25 @@ CacheLibrary *BKE_cache_library_add(Main *bmain, const char *name)
 	return cachelib;
 }
 
+/* XXX keep synced with next function */
+CacheLibrary *BKE_cache_library_copy(CacheLibrary *cachelib)
+{
+	CacheLibrary *cachelibn;
+	int a;
+	
+	cachelibn = BKE_libblock_copy(&cachelib->id);
+	
+	if (cachelib->id.lib) {
+		BKE_id_lib_local_paths(G.main, cachelib->id.lib, &cachelibn->id);
+	}
+	
+	return cachelibn;
+}
+
+void BKE_cache_library_free(CacheLibrary *UNUSED(cache))
+{
+}
+
 
 /* File open options, for BKE_ptcache_file_open */
 typedef enum ePointCache_FileMode {
diff --git a/source/blender/editors/physics/physics_intern.h b/source/blender/editors/physics/physics_intern.h
index 8854251..8c1c430 100644
--- a/source/blender/editors/physics/physics_intern.h
+++ b/source/blender/editors/physics/physics_intern.h
@@ -103,6 +103,8 @@ void DPAINT_OT_output_toggle(struct wmOperatorType *ot);
 /* physics_pointcache.c */
 void PTCACHE_OT_export(struct wmOperatorType *ot);
 
+void CACHELIBRARY_OT_new(struct wmOperatorType *ot);
+
 /* rigidbody_object.c */
 void RIGIDBODY_OT_object_add(struct wmOperatorType *ot);
 void RIGIDBODY_OT_object_remove(struct wmOperatorType *ot);
diff --git a/source/blender/editors/physics/physics_ops.c b/source/blender/editors/physics/physics_ops.c
index 8f32b0d..9586801 100644
--- a/source/blender/editors/physics/physics_ops.c
+++ b/source/blender/editors/physics/physics_ops.c
@@ -183,6 +183,8 @@ static void operatortypes_fluid(void)
 static void operatortypes_pointcache(void)
 {
 	WM_operatortype_append(PTCACHE_OT_export);
+	
+	WM_operatortype_append(CACHELIBRARY_OT_new);
 }
 
 /********************************* dynamic paint ***********************************/
diff --git a/source/blender/editors/physics/physics_pointcache.c b/source/blender/editors/physics/physics_pointcache.c
index 56dc089..e8cc945 100644
--- a/source/blender/editors/physics/physics_pointcache.c
+++ b/source/blender/editors/physics/physics_pointcache.c
@@ -57,6 +57,10 @@
 #include "WM_api.h"
 #include "WM_types.h"
 
+#include "UI_interface.h"
+
+#include "BLF_translation.h"
+
 #include "RNA_access.h"
 #include "RNA_define.h"
 
@@ -219,3 +223,53 @@ void PTCACHE_OT_export(wmOperatorType *ot)
 	/* no undo for this operator, cannot restore old cache files anyway */
 	ot->flag = OPTYPE_REGISTER;
 }
+
+
+/********************** new material operator *********************/
+
+static int new_cachelib_exec(bContext *C, wmOperator *UNUSED(op))
+{
+	CacheLibrary *cachelib = CTX_data_pointer_get_type(C, "cachelib", &RNA_CacheLibrary).data;
+	Main *bmain = CTX_data_main(C);
+	PointerRNA ptr, idptr;
+	PropertyRNA *prop;
+	
+	/* add or copy material */
+	if (cachelib) {
+		cachelib = BKE_cache_library_copy(cachelib);
+	}
+	else {
+		cachelib = BKE_cache_library_add(bmain, DATA_("CacheLibrary"));
+	}
+	
+	/* hook into UI */
+	UI_context_active_but_prop_get_templateID(C, &ptr, &prop);
+	
+	if (prop) {
+		/* when creating new ID blocks, use is already 1, but RNA
+		 * pointer se also increases user, so this compensates it */
+		cachelib->id.us--;
+		
+		RNA_id_pointer_create(&cachelib->id, &idptr);
+		RNA_property_pointer_set(&ptr, prop, idptr);
+		RNA_property_update(C, &ptr, prop);
+	}
+	
+	WM_event_add_notifier(C, NC_OBJECT, cachelib);
+	
+	return OPERATOR_FINISHED;
+}
+
+void CACHELIBRARY_OT_new(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "New Cache Library";
+	ot->idname = "CACHELIBRARY_OT_new";
+	ot->description = "Add a new cache library";
+	
+	/* api callbacks */
+	ot->exec = new_cachelib_exec;
+
+	/* flags */
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
+}




More information about the Bf-blender-cvs mailing list