[Bf-blender-cvs] [1ae3ffb] alembic: Write metadata to caches (application name, date of creation, user description).

Lukas Tönne noreply at git.blender.org
Tue Jun 2 15:26:36 CEST 2015


Commit: 1ae3ffb6c95c6ba4a95e7feba18f7e87580a6c5b
Author: Lukas Tönne
Date:   Tue Jun 2 15:25:13 2015 +0200
Branches: alembic
https://developer.blender.org/rB1ae3ffb6c95c6ba4a95e7feba18f7e87580a6c5b

Write metadata to caches (application name, date of creation, user
description).

Cache library output archives now have a description string next to them
that gets written into the archive.

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

M	release/scripts/startup/bl_ui/properties_object.py
M	source/blender/editors/io/io_cache_library.c
M	source/blender/makesdna/DNA_cache_library_types.h
M	source/blender/makesrna/intern/rna_cache_library.c
M	source/blender/pointcache/PTC_api.cpp
M	source/blender/pointcache/PTC_api.h
M	source/blender/pointcache/alembic/abc_writer.cpp
M	source/blender/pointcache/alembic/abc_writer.h
M	source/blender/pointcache/alembic/alembic.cpp
M	source/blender/pointcache/intern/ptc_types.h

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

diff --git a/release/scripts/startup/bl_ui/properties_object.py b/release/scripts/startup/bl_ui/properties_object.py
index 63161bc6..4523d0d 100644
--- a/release/scripts/startup/bl_ui/properties_object.py
+++ b/release/scripts/startup/bl_ui/properties_object.py
@@ -449,9 +449,9 @@ class CacheArchiveInfoPanel():
     def draw_info(self, context, layout, info):
         layout.prop(info, "filepath", text="File")
         row = layout.row(align=True)
-        row.prop(info, "app_name", text="Created by")
-        row.prop(info, "date_written", text="")
-        layout.prop(info, "description", text="")
+        row.label("Created by: {} | {}".format(info.app_name if info.app_name else "-", info.date_written if info.date_written else "-"))
+        if info.description:
+            layout.label(info.description)
 
         if info.root_node:
             row = layout.row()
@@ -526,6 +526,7 @@ class OBJECT_PT_cache_library(CacheArchiveInfoPanel, ObjectButtonsPanel, Panel):
         row2.alignment = 'LEFT'
         row2.prop(cachelib, "data_types", icon_only=True, toggle=True)
         row2.template_ID(cachelib, "filter_group")
+        col.prop(cachelib, "description")
         col = row.column()
         props = col.operator("cachelibrary.bake", text="Bake Preview", icon='RESTRICT_VIEW_OFF')
         props.eval_mode = {'PREVIEW'}
diff --git a/source/blender/editors/io/io_cache_library.c b/source/blender/editors/io/io_cache_library.c
index e2a19eb..def99d0 100644
--- a/source/blender/editors/io/io_cache_library.c
+++ b/source/blender/editors/io/io_cache_library.c
@@ -49,6 +49,7 @@
 #include "DNA_particle_types.h"
 
 #include "BKE_anim.h"
+#include "BKE_blender.h"
 #include "BKE_depsgraph.h"
 #include "BKE_cache_library.h"
 #include "BKE_context.h"
@@ -366,6 +367,7 @@ static void cache_library_bake_start(void *customdata, short *stop, short *do_up
 	const PTCArchiveResolution archive_res = (do_preview ? PTC_RESOLUTION_PREVIEW : 0) | (do_render ? PTC_RESOLUTION_RENDER : 0);
 	Scene *scene = data->scene;
 	char filename[FILE_MAX];
+	char app_name[MAX_NAME];
 	
 	data->stop = stop;
 	data->do_update = do_update;
@@ -376,7 +378,8 @@ static void cache_library_bake_start(void *customdata, short *stop, short *do_up
 	scene->r.framelen = 1.0f;
 	
 	BKE_cache_archive_output_path(data->cachelib, filename, sizeof(filename));
-	data->archive = PTC_open_writer_archive(FPS, data->start_frame, filename, archive_res);
+	BLI_snprintf(app_name, sizeof(app_name), "Blender %s", versionstr);
+	data->archive = PTC_open_writer_archive(FPS, data->start_frame, filename, archive_res, app_name, data->cachelib->description, NULL);
 	
 	if (data->archive) {
 		
@@ -625,6 +628,7 @@ static int cache_library_archive_slice_exec(bContext *C, wmOperator *op)
 	struct PTCReaderArchive *input_archive;
 	struct PTCWriterArchive *output_archive;
 	PTCArchiveResolution archive_res;
+	CacheArchiveInfo info;
 	
 	RNA_string_get(op->ptr, "input_filepath", input_filepath);
 	if (input_filepath[0] == '\0')
@@ -646,7 +650,9 @@ static int cache_library_archive_slice_exec(bContext *C, wmOperator *op)
 	}
 	
 	archive_res = PTC_reader_archive_get_resolutions(input_archive);
-	output_archive = PTC_open_writer_archive(FPS, start_frame, output_filename, archive_res);
+	PTC_get_archive_info(input_archive, &info);
+	
+	output_archive = PTC_open_writer_archive(FPS, start_frame, output_filename, archive_res, info.app_name, info.description, NULL);
 	if (!output_archive) {
 		BKE_reportf(op->reports, RPT_ERROR, "Cannot write to cache file at '%s'", output_filepath);
 		return OPERATOR_CANCELLED;
diff --git a/source/blender/makesdna/DNA_cache_library_types.h b/source/blender/makesdna/DNA_cache_library_types.h
index 5a00368..0def355 100644
--- a/source/blender/makesdna/DNA_cache_library_types.h
+++ b/source/blender/makesdna/DNA_cache_library_types.h
@@ -88,6 +88,7 @@ typedef struct CacheLibrary {
 	int render_flag DNA_DEPRECATED;
 	int data_types;
 	struct Group *filter_group;
+	char description[256];
 	
 	char input_filepath[1024]; /* 1024 = FILE_MAX */
 	char output_filepath[1024]; /* 1024 = FILE_MAX */
diff --git a/source/blender/makesrna/intern/rna_cache_library.c b/source/blender/makesrna/intern/rna_cache_library.c
index 41424c8..4c8b883 100644
--- a/source/blender/makesrna/intern/rna_cache_library.c
+++ b/source/blender/makesrna/intern/rna_cache_library.c
@@ -925,13 +925,14 @@ static void rna_def_cache_library(BlenderRNA *brna)
 	RNA_def_property_enum_items(prop, cache_library_data_type_items);
 	RNA_def_property_flag(prop, PROP_ENUM_FLAG);
 	RNA_def_property_ui_text(prop, "Data Types", "Types of data to store in the cache");
-	RNA_def_property_update(prop, 0, "rna_CacheLibrary_update");
 	
 	prop = RNA_def_property(srna, "filter_group", PROP_POINTER, PROP_NONE);
 	RNA_def_property_pointer_sdna(prop, NULL, "filter_group");
 	RNA_def_property_flag(prop, PROP_EDITABLE);
 	RNA_def_property_ui_text(prop, "Filter Group", "If set, only objects in this group will be cached");
-	RNA_def_property_update(prop, 0, "rna_CacheLibrary_update");
+	
+	prop = RNA_def_property(srna, "description", PROP_STRING, PROP_NONE);
+	RNA_def_property_ui_text(prop, "Description", "Description of the output archive");
 	
 	/* modifiers */
 	prop = RNA_def_property(srna, "modifiers", PROP_COLLECTION, PROP_NONE);
diff --git a/source/blender/pointcache/PTC_api.cpp b/source/blender/pointcache/PTC_api.cpp
index e248e9a..4aecf55 100644
--- a/source/blender/pointcache/PTC_api.cpp
+++ b/source/blender/pointcache/PTC_api.cpp
@@ -51,7 +51,8 @@ using namespace PTC;
 
 class StubFactory : public Factory {
 	const std::string &get_default_extension() { static std::string ext = ""; return ext; }
-	WriterArchive *open_writer_archive(double /*fps*/, float /*start_frame*/, const std::string &/*name*/, PTCArchiveResolution /*resolutions*/, ErrorHandler */*error_handler*/) { return NULL; }
+	WriterArchive *open_writer_archive(double /*fps*/, float /*start_frame*/, const std::string &/*name*/, PTCArchiveResolution /*resolutions*/,
+	                                   const char */*app_name*/, const char */*description*/, const struct tm */*t*/, ErrorHandler */*error_handler*/) { return NULL; }
 	ReaderArchive *open_reader_archive(double /*fps*/, float /*start_frame*/, const std::string &/*name*/, ErrorHandler * /*error_handler*/) { return NULL; }
 	void slice(ReaderArchive * /*in*/, WriterArchive * /*out*/, float /*start_frame*/, float /*end_frame*/) {}
 	Writer *create_writer_object(const std::string &/*name*/, Scene */*scene*/, Object */*ob*/) { return NULL; }
@@ -129,9 +130,10 @@ const char *PTC_get_default_archive_extension(void)
 	return PTC::Factory::alembic->get_default_extension().c_str();
 }
 
-PTCWriterArchive *PTC_open_writer_archive(double fps, float start_frame, const char *path, PTCArchiveResolution resolutions)
+PTCWriterArchive *PTC_open_writer_archive(double fps, float start_frame, const char *path, PTCArchiveResolution resolutions,
+                                          const char *app_name, const char *description, const struct tm *time)
 {
-	return (PTCWriterArchive *)PTC::Factory::alembic->open_writer_archive(fps, start_frame, path, resolutions, NULL);
+	return (PTCWriterArchive *)PTC::Factory::alembic->open_writer_archive(fps, start_frame, path, resolutions, app_name, description, time, NULL);
 }
 
 void PTC_close_writer_archive(PTCWriterArchive *_archive)
diff --git a/source/blender/pointcache/PTC_api.h b/source/blender/pointcache/PTC_api.h
index 6c9ad08..e00739e 100644
--- a/source/blender/pointcache/PTC_api.h
+++ b/source/blender/pointcache/PTC_api.h
@@ -25,6 +25,8 @@
 extern "C" {
 #endif
 
+struct tm;
+
 struct Main;
 struct Scene;
 struct EvaluationContext;
@@ -59,7 +61,8 @@ void PTC_error_handler_modifier(struct ModifierData *md);
 
 const char *PTC_get_default_archive_extension(void);
 
-struct PTCWriterArchive *PTC_open_writer_archive(double fps, float start_frame, const char *path, PTCArchiveResolution resolutions);
+struct PTCWriterArchive *PTC_open_writer_archive(double fps, float start_frame, const char *path, PTCArchiveResolution resolutions,
+                                                 const char *app_name, const char *description, const struct tm *time);
 void PTC_close_writer_archive(struct PTCWriterArchive *archive);
 void PTC_writer_archive_use_render(struct PTCWriterArchive *archive, bool enable);
 
diff --git a/source/blender/pointcache/alembic/abc_writer.cpp b/source/blender/pointcache/alembic/abc_writer.cpp
index 88b1048..7951483 100644
--- a/source/blender/pointcache/alembic/abc_writer.cpp
+++ b/source/blender/pointcache/alembic/abc_writer.cpp
@@ -19,12 +19,15 @@
 //#include <Alembic/AbcCoreHDF5/ReadWrite.h>
 #include <Alembic/AbcCoreOgawa/ReadWrite.h>
 #include <Alembic/Abc/OObject.h>
+#include <Alembic/Abc/ArchiveInfo.h>
 
 #include "abc_writer.h"
 
 #include "util_error_handler.h"
 
 extern "C" {
+#include <ctime>
+
 #include "BLI_fileops.h"
 #include "BLI_path_util.h"
 }
@@ -41,14 +44,38 @@ static void ensure_directory(const char *filename)
 	BLI_dir_create_recursive(dir);
 }
 
-AbcWriterArchive *AbcWriterArchive::open(double fps, float start_frame, const std::string &filename, PTCArchiveResolution resolutions, ErrorHandler *error_handler)
+static MetaData create_archive_info(const char *app_name, const char *description, const struct tm *t)
+{
+	MetaData md;
+	
+	md.set(kApplicationNameKey, app_name);
+	md.set(kUserDescriptionKey, description);
+	
+	if (!t) {
+		time_t curtime = time(NULL);
+		t = localtime(&curtime);
+	}
+	
+	if (t) {
+		char buf[256];
+		strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M", t);
+		md.set(kDateWrittenKey, buf);
+	}
+	
+	return md;
+}
+
+AbcWriterArchive *AbcWriterArchive::open(double fps, float start_frame, const std::string &filename, PTCArchiveResolution resolutions,
+                                         const char *app_name, const char *description, const struct tm *time, ErrorHandler *error_handler)
 {
 	ensure_directory(filename.c_str());
 	
+	MetaData md = create_archive_info(app_name, description, time);
+	
 	OArchive abc_archive;
 	PTC_SAFE_CALL_BEGIN
-//	abc_archive = OArchive(AbcCoreHDF5::WriteArchive(), filename, Abc::ErrorHandler::kThrowPolicy);
-	abc

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list