[Bf-blender-cvs] [1be812f] alembic_pointcache: `New` operator for adding cache libraries.
Lukas Tönne
noreply at git.blender.org
Fri Feb 20 15:09:44 CET 2015
Commit: 1be812f426c70ef0cb8875a07179eb08c06d657d
Author: Lukas Tönne
Date: Thu Feb 19 13:49:28 2015 +0100
Branches: alembic_pointcache
https://developer.blender.org/rB1be812f426c70ef0cb8875a07179eb08c06d657d
`New` operator for adding cache libraries.
Conflicts:
release/scripts/startup/bl_ui/properties_physics_common.py
source/blender/blenkernel/BKE_pointcache.h
source/blender/blenkernel/intern/pointcache.c
source/blender/editors/physics/physics_ops.c
source/blender/editors/physics/physics_pointcache.c
===================================================================
M source/blender/blenkernel/BKE_cache_library.h
M source/blender/blenkernel/intern/cache_library.c
M source/blender/editors/io/CMakeLists.txt
A source/blender/editors/io/io_cache_library.c
A source/blender/editors/io/io_cache_library.h
M source/blender/editors/io/io_ops.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_cache_library.h b/source/blender/blenkernel/BKE_cache_library.h
index b88e047..92a1f9d 100644
--- a/source/blender/blenkernel/BKE_cache_library.h
+++ b/source/blender/blenkernel/BKE_cache_library.h
@@ -36,6 +36,7 @@ struct CacheLibrary;
struct Main;
struct CacheLibrary *BKE_cache_library_add(struct Main *bmain, const char *name);
+struct CacheLibrary *BKE_cache_library_copy(struct CacheLibrary *cachelib);
void BKE_cache_library_free(struct CacheLibrary *cache);
#endif
diff --git a/source/blender/blenkernel/intern/cache_library.c b/source/blender/blenkernel/intern/cache_library.c
index c3961d0..ff6f791 100644
--- a/source/blender/blenkernel/intern/cache_library.c
+++ b/source/blender/blenkernel/intern/cache_library.c
@@ -35,13 +35,10 @@
#include "DNA_cache_library_types.h"
#include "BKE_cache_library.h"
+#include "BKE_global.h"
#include "BKE_library.h"
#include "BKE_main.h"
-void BKE_cache_library_free(CacheLibrary *UNUSED(cache))
-{
-}
-
CacheLibrary *BKE_cache_library_add(Main *bmain, const char *name)
{
CacheLibrary *cachelib;
@@ -52,3 +49,21 @@ 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;
+
+ 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))
+{
+}
diff --git a/source/blender/editors/io/CMakeLists.txt b/source/blender/editors/io/CMakeLists.txt
index f331dea..b002a5c 100644
--- a/source/blender/editors/io/CMakeLists.txt
+++ b/source/blender/editors/io/CMakeLists.txt
@@ -35,9 +35,11 @@ set(INC_SYS
)
set(SRC
+ io_cache_library.c
io_collada.c
io_ops.c
+ io_cache_library.h
io_collada.h
io_ops.h
)
diff --git a/source/blender/editors/io/io_cache_library.c b/source/blender/editors/io/io_cache_library.c
new file mode 100644
index 0000000..5e7dc0c
--- /dev/null
+++ b/source/blender/editors/io/io_cache_library.c
@@ -0,0 +1,101 @@
+/*
+ * ***** 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.
+ *
+ * The Original Code is Copyright (C) 2015 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Blender Foundation
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/io/io_cache_library.c
+ * \ingroup editor/io
+ */
+
+#include "BLF_translation.h"
+
+#include "BLI_blenlib.h"
+#include "BLI_utildefines.h"
+
+#include "DNA_cache_library_types.h"
+
+#include "BKE_cache_library.h"
+#include "BKE_context.h"
+#include "BKE_global.h"
+#include "BKE_main.h"
+#include "BKE_report.h"
+
+#include "ED_screen.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "UI_interface.h"
+#include "UI_resources.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+/********************** new cache library 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;
+}
diff --git a/source/blender/editors/io/io_ops.c b/source/blender/editors/io/io_cache_library.h
similarity index 68%
copy from source/blender/editors/io/io_ops.c
copy to source/blender/editors/io/io_cache_library.h
index a70a51a..557e53c 100644
--- a/source/blender/editors/io/io_ops.c
+++ b/source/blender/editors/io/io_cache_library.h
@@ -15,31 +15,23 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
- * The Original Code is Copyright (C) 2008 Blender Foundation.
+ * The Original Code is Copyright (C) 2015 Blender Foundation.
* All rights reserved.
*
- *
* Contributor(s): Blender Foundation
*
* ***** END GPL LICENSE BLOCK *****
*/
-/** \file blender/editors/io/io_ops.c
- * \ingroup collada
+/** \file blender/editors/io/io_cache_library.h
+ * \ingroup editor/io
*/
-#include "io_ops.h" /* own include */
+#ifndef __IO_CACHE_LIBRARY_H__
+#define __IO_CACHE_LIBRARY_H__
-#ifdef WITH_COLLADA
-# include "io_collada.h"
-# include "WM_api.h"
-#endif
+struct wmOperatorType;
+
+void CACHELIBRARY_OT_new(struct wmOperatorType *ot);
-void ED_operatortypes_io(void)
-{
-#ifdef WITH_COLLADA
- /* Collada operators: */
- WM_operatortype_append(WM_OT_collada_export);
- WM_operatortype_append(WM_OT_collada_import);
#endif
-}
diff --git a/source/blender/editors/io/io_ops.c b/source/blender/editors/io/io_ops.c
index a70a51a..f967f85 100644
--- a/source/blender/editors/io/io_ops.c
+++ b/source/blender/editors/io/io_ops.c
@@ -30,13 +30,17 @@
#include "io_ops.h" /* own include */
+#include "io_cache_library.h"
#ifdef WITH_COLLADA
# include "io_collada.h"
-# include "WM_api.h"
#endif
+#include "WM_api.h"
+
void ED_operatortypes_io(void)
{
+ WM_operatortype_append(CACHELIBRARY_OT_new);
+
#ifdef WITH_COLLADA
/* Collada operators: */
WM_operatortype_append(WM_OT_collada_export);
More information about the Bf-blender-cvs
mailing list