[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48729] branches/soc-2012-bratwurst/source /blender/assimp: - bf_assimp: pipe assimp' s logging into the ReportList for the assimp operator, preserving the log level.

Alexander Gessler alexander.gessler at gmx.net
Sun Jul 8 17:15:14 CEST 2012


Revision: 48729
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48729
Author:   aramis_acg
Date:     2012-07-08 15:15:14 +0000 (Sun, 08 Jul 2012)
Log Message:
-----------
- bf_assimp: pipe assimp's logging into the ReportList for the assimp operator, preserving the log level.

Modified Paths:
--------------
    branches/soc-2012-bratwurst/source/blender/assimp/CMakeLists.txt
    branches/soc-2012-bratwurst/source/blender/assimp/SceneImporter.cpp
    branches/soc-2012-bratwurst/source/blender/assimp/SceneImporter.h

Added Paths:
-----------
    branches/soc-2012-bratwurst/source/blender/assimp/LogPipe.cpp
    branches/soc-2012-bratwurst/source/blender/assimp/LogPipe.h

Modified: branches/soc-2012-bratwurst/source/blender/assimp/CMakeLists.txt
===================================================================
--- branches/soc-2012-bratwurst/source/blender/assimp/CMakeLists.txt	2012-07-08 15:11:13 UTC (rev 48728)
+++ branches/soc-2012-bratwurst/source/blender/assimp/CMakeLists.txt	2012-07-08 15:15:14 UTC (rev 48729)
@@ -75,6 +75,9 @@
 
 	SkinImporter.cpp
 	SkinImporter.h
+	
+	LogPipe.cpp
+	LogPipe.h
 )
 
 if(WITH_BUILDINFO)

Added: branches/soc-2012-bratwurst/source/blender/assimp/LogPipe.cpp
===================================================================
--- branches/soc-2012-bratwurst/source/blender/assimp/LogPipe.cpp	                        (rev 0)
+++ branches/soc-2012-bratwurst/source/blender/assimp/LogPipe.cpp	2012-07-08 15:15:14 UTC (rev 48729)
@@ -0,0 +1,131 @@
+/*
+ * ***** 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): Alexander Gessler
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/assimp/bassimp.cpp
+ *  \ingroup assimp
+ */
+
+#include <cassert>
+#include "LogPipe.h"
+
+#include "../../extern/assimp/include/assimp/DefaultLogger.hpp"
+
+extern "C"
+{
+
+#include "BKE_report.h"
+
+}
+
+using namespace Assimp;
+
+namespace {
+
+// custom assimp logging implementation
+class BlenderLogger : public Logger
+{
+public:
+
+	BlenderLogger(ReportList& reports) 
+		: reports(reports)
+	{
+
+	}
+
+	virtual ~BlenderLogger() {
+	}
+
+public:
+
+
+	virtual bool attachStream(LogStream *pStream, unsigned int severity = Debugging | Err | Warn | Info)
+	{
+		// not implemented, not needed
+		return false;
+	}
+
+
+	virtual bool detatchStream(LogStream *pStream, unsigned int severity = Debugging | Err | Warn | Info)
+	{
+		// not implemented, not needed
+		return false;
+	}
+
+public:
+	
+	virtual void OnDebug(const char* message) 
+	{	
+		BKE_report(&reports,RPT_DEBUG,AddPrefix(message).c_str());
+	}
+
+	virtual void OnInfo(const char* message) 
+	{
+		BKE_report(&reports,RPT_INFO,AddPrefix(message).c_str());
+	}
+
+	
+	virtual void OnWarn(const char* message) 
+	{
+		BKE_report(&reports,RPT_WARNING,AddPrefix(message).c_str());
+	}
+
+	
+	virtual void OnError(const char* message) 
+	{
+		BKE_report(&reports,RPT_ERROR,AddPrefix(message).c_str());
+	}
+
+private:
+
+	std::string AddPrefix(const std::string& p) {
+		return "[assimp] " + p;
+	}
+
+private:
+
+	ReportList& reports;
+};
+
+} // !anon
+
+namespace bassimp {
+
+LogPipe::LogPipe(ReportList* reports)
+{
+	if(reports) {
+		DefaultLogger::set(new BlenderLogger(*reports));
+	}
+}
+
+
+LogPipe::~LogPipe()
+{
+	kill();
+}
+
+
+void LogPipe::kill()
+{
+	DefaultLogger::set(NULL);
+}
+
+}

Added: branches/soc-2012-bratwurst/source/blender/assimp/LogPipe.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/assimp/LogPipe.h	                        (rev 0)
+++ branches/soc-2012-bratwurst/source/blender/assimp/LogPipe.h	2012-07-08 15:15:14 UTC (rev 48729)
@@ -0,0 +1,56 @@
+/*
+ * ***** 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): Alexander Gessler.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file LogPipe.h
+ *  \ingroup assimp
+ */
+
+#ifndef INCLUDED_LOG_PIPE_H
+#define INCLUDED_LOG_PIPE_H
+
+struct ReportList;
+
+namespace bassimp {
+
+/** utility class to pipe assimp's logging into Blender. Uses RAII to make
+ *  sure the pipe gets disabled again. This is needed because logging in 
+ *  assimp is (unfortunately) global.
+ *
+ * note: only a single log pipe can be active at a time.  */
+class LogPipe {
+
+
+public:
+	
+	/** setup a assimp log pipe that reports to the given ReportList.
+	  * reports may be NULL, in this case nothing happens. */
+	LogPipe(ReportList* reports);
+	~LogPipe();
+
+public:
+
+	void kill();
+};
+
+}
+
+#endif

Modified: branches/soc-2012-bratwurst/source/blender/assimp/SceneImporter.cpp
===================================================================
--- branches/soc-2012-bratwurst/source/blender/assimp/SceneImporter.cpp	2012-07-08 15:11:13 UTC (rev 48728)
+++ branches/soc-2012-bratwurst/source/blender/assimp/SceneImporter.cpp	2012-07-08 15:15:14 UTC (rev 48729)
@@ -66,6 +66,7 @@
 , out_scene(CTX_data_scene(&C))
 , armature()
 , settings(settings)
+, log_pipe(!!settings.enableAssimpLog ? settings.reports : NULL)
 {
 }
 

Modified: branches/soc-2012-bratwurst/source/blender/assimp/SceneImporter.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/assimp/SceneImporter.h	2012-07-08 15:11:13 UTC (rev 48728)
+++ branches/soc-2012-bratwurst/source/blender/assimp/SceneImporter.h	2012-07-08 15:15:14 UTC (rev 48729)
@@ -29,6 +29,7 @@
 
 #include "bassimp_shared.h"
 #include "bassimp.h"
+#include "LogPipe.h"
 
 #include <set>
 #include <map>
@@ -72,6 +73,7 @@
 	ObjectToMeshMap meshes_by_object;
 
 	const bassimp_import_settings settings;
+	LogPipe log_pipe;
 
 private:
 




More information about the Bf-blender-cvs mailing list