[Bf-blender-cvs] [bc00ac3] tmp-id-users: Move Py-side of 'users of ID' from rna to bpy.

Bastien Montagne noreply at git.blender.org
Tue Jan 5 17:42:00 CET 2016


Commit: bc00ac3a9ee5f9f1c0944a3441613ddee42d720a
Author: Bastien Montagne
Date:   Tue Jan 5 17:03:26 2016 +0100
Branches: tmp-id-users
https://developer.blender.org/rBbc00ac3a9ee5f9f1c0944a3441613ddee42d720a

Move Py-side of 'users of ID' from rna to bpy.

Note that I kept 'user_of_id' in RNA for now (this one is not an issue re looping over whole main),
but not really sure it's that useful in the end, we could just keep the bpy dict generator I guess...

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

M	release/scripts/modules/bpy_types.py
M	source/blender/blenkernel/BKE_library_query.h
M	source/blender/blenkernel/intern/library_query.c
M	source/blender/makesrna/RNA_types.h
M	source/blender/makesrna/intern/makesrna.c
M	source/blender/makesrna/intern/rna_ID.c
M	source/blender/python/intern/CMakeLists.txt
M	source/blender/python/intern/bpy.c
A	source/blender/python/intern/bpy_data.c
A	source/blender/python/intern/bpy_data.h
M	source/blender/python/intern/bpy_rna.c

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

diff --git a/release/scripts/modules/bpy_types.py b/release/scripts/modules/bpy_types.py
index 1c08fc5..71fb209 100644
--- a/release/scripts/modules/bpy_types.py
+++ b/release/scripts/modules/bpy_types.py
@@ -26,6 +26,7 @@ StructMetaPropGroup = bpy_types.bpy_struct_meta_idprop
 # StructRNA = bpy_types.Struct
 
 bpy_types.BlendDataLibraries.load = _bpy._library_load
+bpy_types.BlendData.user_map = _bpy._data_user_map
 
 
 class Context(StructRNA):
diff --git a/source/blender/blenkernel/BKE_library_query.h b/source/blender/blenkernel/BKE_library_query.h
index 4e2142f..f07644d 100644
--- a/source/blender/blenkernel/BKE_library_query.h
+++ b/source/blender/blenkernel/BKE_library_query.h
@@ -32,7 +32,6 @@
  */
 
 struct ID;
-struct Main;
 
 /* Tips for the callback for cases it's gonna to modify the pointer. */
 enum {
@@ -66,13 +65,6 @@ enum {
 void BKE_library_foreach_ID_link(struct ID *id, LibraryIDLinkCallback callback, void *user_data, int flag);
 void BKE_library_update_ID_link_user(struct ID *id_dst, struct ID *id_src, const int cd_flag);
 
-/* Iterator over all ID users of a given datablock. */
-struct IDUsersIter;
-
 int BKE_library_ID_use_ID(struct ID *id_user, struct ID *id_used);
 
-struct IDUsersIter *BKE_library_ID_users_iter_init(struct Main *bmain, struct ID *id);
-struct ID *BKE_library_ID_users_iter_next(struct IDUsersIter *iter, int *r_count);
-void BKE_library_ID_users_iter_end(struct IDUsersIter **iter);
-
 #endif  /* __BKE_LIBRARY_QUERY_H__ */
diff --git a/source/blender/blenkernel/intern/library_query.c b/source/blender/blenkernel/intern/library_query.c
index b7c917e..7936aab 100644
--- a/source/blender/blenkernel/intern/library_query.c
+++ b/source/blender/blenkernel/intern/library_query.c
@@ -29,7 +29,6 @@
 
 #include <stdlib.h>
 
-#include "MEM_guardedalloc.h"
 
 #include "DNA_actuator_types.h"
 #include "DNA_anim_types.h"
@@ -62,14 +61,12 @@
 #include "DNA_world_types.h"
 
 #include "BLI_utildefines.h"
-#include "BLI_listbase.h"
 
 #include "BKE_animsys.h"
 #include "BKE_constraint.h"
 #include "BKE_fcurve.h"
 #include "BKE_library.h"
 #include "BKE_library_query.h"
-#include "BKE_main.h"
 #include "BKE_modifier.h"
 #include "BKE_particle.h"
 #include "BKE_rigidbody.h"
@@ -714,79 +711,3 @@ int BKE_library_ID_use_ID(ID *id_user, ID *id_used)
 
 	return iter.count;
 }
-
-/**
- * Initialize an id user iterator.
- *
- * \param bmain the Main database in which to search for \a id users.
- * \param id the datablock to find users of.
- * \return an opaque pointer to the initialized iterator.
- */
-IDUsersIter *BKE_library_ID_users_iter_init(Main *bmain, ID *id)
-{
-	IDUsersIter *iter = MEM_mallocN(sizeof(*iter), __func__);
-
-	iter->id = id;
-	iter->lb_idx = set_listbasepointers(bmain, iter->lb_array);
-	iter->curr_id = NULL;
-	iter->count = 0;
-
-	return iter;
-}
-
-/**
- * Return the next ID using the datablock this \a iter was built from.
- *
- * \param iter the iterator pointer (as returned by \a BKE_library_ID_users_iter_init).
- * \param r_count if non-null, will be set to the number of usages detected for returned ID.
- * \return a pointer to the next ID using the searched datablock, or NULL if none found anymore.
- */
-ID *BKE_library_ID_users_iter_next(IDUsersIter *iter, int *r_count)
-{
-	ID *ret = NULL;
-
-	if (iter == NULL) {
-		if (r_count) {
-			*r_count = 0;
-		}
-		return ret;
-	}
-
-	iter->count = 0;
-	while (ret == NULL) {
-		while (iter->curr_id == NULL) {
-			if (iter->lb_idx-- == 0) {
-				break;
-			}
-			iter->curr_id = iter->lb_array[iter->lb_idx]->first;
-		}
-		if (iter->curr_id == NULL) {
-			break;
-		}
-
-		iter->count = 0;
-		BKE_library_foreach_ID_link(iter->curr_id, foreach_libblock_id_users_callback, (void *)iter, IDWALK_NOP);
-
-		if (iter->count > 0) {
-			ret = iter->curr_id;
-		}
-
-		iter->curr_id = iter->curr_id->next;
-	}
-
-	if (r_count) {
-		*r_count = iter->count;
-	}
-	return ret;
-}
-
-/**
- * Finalize (clean up) an IDUsers iterator.
- *
- * \param iter the address of the iterator pointer to finalize.
- */
-void BKE_library_ID_users_iter_end(IDUsersIter **iter)
-{
-	MEM_SAFE_FREE(*iter);
-}
-
diff --git a/source/blender/makesrna/RNA_types.h b/source/blender/makesrna/RNA_types.h
index a302bc6..04a2361 100644
--- a/source/blender/makesrna/RNA_types.h
+++ b/source/blender/makesrna/RNA_types.h
@@ -285,11 +285,6 @@ typedef struct CollectionPointerLink {
 	PointerRNA ptr;
 } CollectionPointerLink;
 
-/* Copy of ListBase for RNA... */
-typedef struct CollectionListBase {
-	struct CollectionPointerLink *first, *last;
-} CollectionListBase;
-
 typedef enum RawPropertyType {
 	PROP_RAW_UNSET = -1,
 	PROP_RAW_INT, // XXX - abused for types that are not set, eg. MFace.verts, needs fixing.
diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c
index fa0acae..ce977da 100644
--- a/source/blender/makesrna/intern/makesrna.c
+++ b/source/blender/makesrna/intern/makesrna.c
@@ -466,7 +466,7 @@ static const char *rna_parameter_type_name(PropertyRNA *parm)
 		}
 		case PROP_COLLECTION:
 		{
-			return "CollectionListBase";
+			return "ListBase";
 		}
 		default:
 			return "<error, no type specified>";
diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c
index ae8df64..63ea836 100644
--- a/source/blender/makesrna/intern/rna_ID.c
+++ b/source/blender/makesrna/intern/rna_ID.c
@@ -87,8 +87,6 @@ EnumPropertyItem rna_enum_id_type_items[] = {
 
 #include "DNA_anim_types.h"
 
-#include "BLI_listbase.h"
-
 #include "BKE_font.h"
 #include "BKE_idprop.h"
 #include "BKE_library.h"
@@ -335,28 +333,6 @@ static void rna_ID_user_clear(ID *id)
 	id->us = 0; /* don't save */
 }
 
-static CollectionListBase rna_ID_used_by_ids(ID *id, Main *bmain)
-{
-	ListBase ret = {0};
-	struct IDUsersIter *iter = BKE_library_ID_users_iter_init(bmain, id);
-	ID *id_user;
-
-	do {
-		id_user = BKE_library_ID_users_iter_next(iter, NULL);
-
-		if (id_user) {
-			CollectionPointerLink *lnk = MEM_mallocN(sizeof(*lnk), __func__);
-			RNA_id_pointer_create(id_user, &lnk->ptr);
-			BLI_addtail(&ret, lnk);
-		}
-	} while (id_user != NULL);
-
-	BKE_library_ID_users_iter_end(&iter);
-
-	/* CollectionListBase is a mere RNA redefinition of ListBase. */
-	return *(CollectionListBase *)&ret;
-}
-
 static AnimData * rna_ID_animation_data_create(ID *id, Main *bmain)
 {
 	AnimData *adt = BKE_animdata_add_id(id);
@@ -1009,12 +985,6 @@ static void rna_def_ID(BlenderRNA *brna)
 	                   "", "Number of usages/references of given id by current datablock", 0, INT_MAX);
 	RNA_def_function_return(func, parm);
 
-	func = RNA_def_function(srna, "used_by_ids", "rna_ID_used_by_ids");
-	RNA_def_function_ui_description(func, "Return a list of all datablocks using/referencing current one");
-	RNA_def_function_flag(func, FUNC_USE_MAIN);
-	parm = RNA_def_collection(func, "ids", "ID", "", "All datablocks using current ID");
-	RNA_def_function_return(func, parm);
-
 	func = RNA_def_function(srna, "animation_data_create", "rna_ID_animation_data_create");
 	RNA_def_function_flag(func, FUNC_USE_MAIN);
 	RNA_def_function_ui_description(func, "Create animation data to this ID, note that not all ID types support this");
diff --git a/source/blender/python/intern/CMakeLists.txt b/source/blender/python/intern/CMakeLists.txt
index f04bca7..1f66af8 100644
--- a/source/blender/python/intern/CMakeLists.txt
+++ b/source/blender/python/intern/CMakeLists.txt
@@ -56,6 +56,7 @@ set(SRC
 	bpy_app_oiio.c
 	bpy_app_sdl.c
 	bpy_app_translations.c
+	bpy_data.c
 	bpy_driver.c
 	bpy_interface.c
 	bpy_interface_atexit.c
@@ -85,6 +86,7 @@ set(SRC
 	bpy_app_oiio.h
 	bpy_app_sdl.h
 	bpy_app_translations.h
+	bpy_data.h
 	bpy_driver.h
 	bpy_intern_string.h
 	bpy_library.h
diff --git a/source/blender/python/intern/bpy.c b/source/blender/python/intern/bpy.c
index bdae2a7..b37e108 100644
--- a/source/blender/python/intern/bpy.c
+++ b/source/blender/python/intern/bpy.c
@@ -45,6 +45,7 @@
 #include "bpy_util.h"
 #include "bpy_rna.h"
 #include "bpy_app.h"
+#include "bpy_data.h"
 #include "bpy_props.h"
 #include "bpy_library.h"
 #include "bpy_operator.h"
@@ -322,6 +323,7 @@ void BPy_init_modules(void)
 
 	/* needs to be first so bpy_types can run */
 	BPY_library_module(mod);
+	BPY_data_module(mod);
 
 	bpy_import_test("bpy_types");
 	PyModule_AddObject(mod, "data", BPY_rna_module()); /* imports bpy_types by running this */
diff --git a/source/blender/python/intern/bpy_data.c b/source/blender/python/intern/bpy_data.c
new file mode 100644
index 0000000..d56d4ef
--- /dev/null
+++ b/source/blender/python/intern/bpy_data.c
@@ -0,0 +1,177 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Bastien Montagne
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/python/intern/bpy_data.c
+ *  \ingroup pythonintern
+ *
+ * This file exposed blend file library appending/linking to python, typically
+ * this would be done via RNA api but in this case a hand written python api
+ * allows us to use pythons context manager (__enter__ and __exit__).
+ *
+ * Everything here is exposed via bpy.data.libraries.load(...) which returns
+ * a context manager.
+ */
+
+#include <Python.h>
+#include <stddef.h>
+
+#include "BLI_utildefines.h"
+
+#include "BKE_global.h"
+#include "BKE_main.h"
+#include "BKE_library.h"
+#include "BKE_library_query.h"
+
+#include "DNA_ID.h"
+
+#include "bpy_util.h"
+#include "bpy_data.h"
+
+#include "../generic/py_capi_utils.h"
+#include "../generic/python_utild

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list