[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [35777] trunk/blender/source/blender/ collada: Add ExtraTags class for handling tags inside an extra block.

Nathan Letwory nathan at letworyinteractive.com
Fri Mar 25 12:07:58 CET 2011


Revision: 35777
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=35777
Author:   jesterking
Date:     2011-03-25 11:07:57 +0000 (Fri, 25 Mar 2011)
Log Message:
-----------
Add ExtraTags class for handling tags inside an extra block.

Modified Paths:
--------------
    trunk/blender/source/blender/collada/CMakeLists.txt
    trunk/blender/source/blender/collada/DocumentImporter.cpp
    trunk/blender/source/blender/collada/DocumentImporter.h
    trunk/blender/source/blender/collada/ExtraHandler.cpp
    trunk/blender/source/blender/collada/ExtraHandler.h

Added Paths:
-----------
    trunk/blender/source/blender/collada/ExtraTags.cpp
    trunk/blender/source/blender/collada/ExtraTags.h

Modified: trunk/blender/source/blender/collada/CMakeLists.txt
===================================================================
--- trunk/blender/source/blender/collada/CMakeLists.txt	2011-03-25 10:41:53 UTC (rev 35776)
+++ trunk/blender/source/blender/collada/CMakeLists.txt	2011-03-25 11:07:57 UTC (rev 35777)
@@ -64,6 +64,7 @@
 	DocumentImporter.cpp
 	EffectExporter.cpp
 	ExtraHandler.cpp
+	ExtraTags.cpp
 	GeometryExporter.cpp
 	ImageExporter.cpp
 	InstanceWriter.cpp
@@ -85,6 +86,7 @@
 	DocumentImporter.h
 	EffectExporter.h
 	ExtraHandler.h
+	ExtraTags.h
 	GeometryExporter.h
 	ImageExporter.h
 	InstanceWriter.h

Modified: trunk/blender/source/blender/collada/DocumentImporter.cpp
===================================================================
--- trunk/blender/source/blender/collada/DocumentImporter.cpp	2011-03-25 10:41:53 UTC (rev 35776)
+++ trunk/blender/source/blender/collada/DocumentImporter.cpp	2011-03-25 11:07:57 UTC (rev 35777)
@@ -101,7 +101,15 @@
 	anim_importer(&unit_converter, &armature_importer, CTX_data_scene(C))
 {}
 
-DocumentImporter::~DocumentImporter() {}
+DocumentImporter::~DocumentImporter()
+{
+	std::map<COLLADAFW::UniqueId, ExtraTags*>::iterator etit;
+	etit = uid_tags_map.begin();
+	while(etit!=uid_tags_map.end()) {
+		delete etit->second;
+		etit++;
+	}
+}
 
 bool DocumentImporter::import()
 {
@@ -997,8 +1005,17 @@
 	return true;
 }
 
-bool DocumentImporter::addElementData( const COLLADAFW::UniqueId &uid)
+ExtraTags* DocumentImporter::getExtraTags(const COLLADAFW::UniqueId &uid)
 {
+	if(uid_tags_map.find(uid)==uid_tags_map.end()) {
+		return NULL;
+	}
+	return uid_tags_map[uid];
+}
+
+bool DocumentImporter::addExtraTags( const COLLADAFW::UniqueId &uid, ExtraTags *extra_tags)
+{
+	uid_tags_map[uid] = extra_tags;
 	return true;
 }
 

Modified: trunk/blender/source/blender/collada/DocumentImporter.h
===================================================================
--- trunk/blender/source/blender/collada/DocumentImporter.h	2011-03-25 10:41:53 UTC (rev 35776)
+++ trunk/blender/source/blender/collada/DocumentImporter.h	2011-03-25 11:07:57 UTC (rev 35777)
@@ -45,6 +45,7 @@
 #include "AnimationImporter.h"
 #include "ArmatureImporter.h"
 #include "MeshImporter.h"
+#include "ExtraTags.h"
 
 
 struct Main;
@@ -122,7 +123,9 @@
 	bool writeKinematicsScene(const COLLADAFW::KinematicsScene*);
 
 	/** Add element and data for UniqueId */
-	bool addElementData(const COLLADAFW::UniqueId &uid);
+	bool addExtraTags(const COLLADAFW::UniqueId &uid, ExtraTags *extra_tags);
+	/** Get an extisting ExtraTags for uid */
+	ExtraTags* getExtraTags(const COLLADAFW::UniqueId &uid);
 
 private:
 
@@ -142,6 +145,7 @@
 	std::map<COLLADAFW::UniqueId, Material*> uid_effect_map;
 	std::map<COLLADAFW::UniqueId, Camera*> uid_camera_map;
 	std::map<COLLADAFW::UniqueId, Lamp*> uid_lamp_map;
+	std::map<COLLADAFW::UniqueId, ExtraTags*> uid_tags_map;
 	std::map<Material*, TexIndexTextureArrayMap> material_texture_mapping_map;
 	std::map<COLLADAFW::UniqueId, Object*> object_map;
 	std::map<COLLADAFW::UniqueId, COLLADAFW::Node*> node_map;

Modified: trunk/blender/source/blender/collada/ExtraHandler.cpp
===================================================================
--- trunk/blender/source/blender/collada/ExtraHandler.cpp	2011-03-25 10:41:53 UTC (rev 35776)
+++ trunk/blender/source/blender/collada/ExtraHandler.cpp	2011-03-25 11:07:57 UTC (rev 35777)
@@ -31,7 +31,7 @@
 
 #include "ExtraHandler.h"
 
-ExtraHandler::ExtraHandler(DocumentImporter *dimp)
+ExtraHandler::ExtraHandler(DocumentImporter *dimp) : currentExtraTags(0)
 {
 	this->dimp = dimp;
 }
@@ -40,22 +40,27 @@
 
 bool ExtraHandler::elementBegin( const char* elementName, const char** attributes)
 {
-	printf("begin: %s\n", elementName);
+	// \todo attribute handling for profile tags
+	currentElement = std::string(elementName);
 	return true;
 }
 
 bool ExtraHandler::elementEnd(const char* elementName )
 {
-	printf("end: %s\n", elementName);
 	currentUid = COLLADAFW::UniqueId();
+	currentExtraTags = 0;
+	currentElement.clear();
 	return true;
 }
 
 bool ExtraHandler::textData(const char* text, size_t textLength)
 {
-	char buf[1024] = {0};
-	BLI_snprintf(buf, textLength, "%s", text);
-	printf("data: %s\n", buf);
+	char buf[1024];
+	
+	if(currentElement.length() == 0) return false;
+	
+	BLI_snprintf(buf, textLength+1, "%s", text);
+	currentExtraTags->addTag(std::string(currentElement), std::string(buf));
 	return true;
 }
 
@@ -64,10 +69,16 @@
 	const unsigned long& elementHash, 
 	const COLLADAFW::UniqueId& uniqueId ) {
 		if(BLI_strcaseeq(profileName, "blender")) {
-			printf("In parseElement for supported profile %s for id %s\n", profileName, uniqueId.toAscii().c_str());
+			//printf("In parseElement for supported profile %s for id %s\n", profileName, uniqueId.toAscii().c_str());
 			currentUid = uniqueId;
+			ExtraTags *et = dimp->getExtraTags(uniqueId);
+			if(!et) {
+				et = new ExtraTags(std::string(profileName));
+				dimp->addExtraTags(uniqueId, et);
+			}
+			currentExtraTags = et;
 			return true;
 		}
-		printf("In parseElement for unsupported profile %s for id %s\n", profileName, uniqueId.toAscii().c_str());
+		//printf("In parseElement for unsupported profile %s for id %s\n", profileName, uniqueId.toAscii().c_str());
 		return false;
 }

Modified: trunk/blender/source/blender/collada/ExtraHandler.h
===================================================================
--- trunk/blender/source/blender/collada/ExtraHandler.h	2011-03-25 10:41:53 UTC (rev 35776)
+++ trunk/blender/source/blender/collada/ExtraHandler.h	2011-03-25 11:07:57 UTC (rev 35777)
@@ -71,5 +71,7 @@
 	DocumentImporter* dimp;
 	/** Holds Id of element for which <extra> XML elements are handled. */
 	COLLADAFW::UniqueId currentUid;
+	ExtraTags* currentExtraTags;
+	std::string currentElement;
 };
 

Added: trunk/blender/source/blender/collada/ExtraTags.cpp
===================================================================
--- trunk/blender/source/blender/collada/ExtraTags.cpp	                        (rev 0)
+++ trunk/blender/source/blender/collada/ExtraTags.cpp	2011-03-25 11:07:57 UTC (rev 35777)
@@ -0,0 +1,50 @@
+/*
+ * $Id$
+ *
+ * ***** 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): Nathan Letwory.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/collada/ExtraTags.cpp
+ *  \ingroup collada
+ */
+
+#include <stddef.h>
+#include "BLI_string.h"
+
+#include <iostream>
+
+#include "ExtraTags.h"
+
+ExtraTags::ExtraTags(const std::string profile)
+{
+	this->profile = profile;
+}
+
+ExtraTags::~ExtraTags()
+{
+}
+
+bool ExtraTags::addTag(const std::string tag, const std::string data)
+{
+	//std::cout << "ready to add " << tag << ": " << data << "." << std::endl;
+	
+	return true;
+}
\ No newline at end of file


Property changes on: trunk/blender/source/blender/collada/ExtraTags.cpp
___________________________________________________________________
Added: svn:keywords
   + Author Date Id Revision
Added: svn:eol-style
   + native

Added: trunk/blender/source/blender/collada/ExtraTags.h
===================================================================
--- trunk/blender/source/blender/collada/ExtraTags.h	                        (rev 0)
+++ trunk/blender/source/blender/collada/ExtraTags.h	2011-03-25 11:07:57 UTC (rev 35777)
@@ -0,0 +1,54 @@
+/*
+ * $Id$
+ *
+ * ***** 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): Nathan Letwory.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/collada/ExtraTags.h
+ *  \ingroup collada
+ */
+
+#include <string>
+#include <map>
+#include <vector>
+
+/** \brief Class for saving <extra> tags for a specific UniqueId.
+ */
+class ExtraTags
+{
+public:
+	/** Constructor. */
+	ExtraTags(const std::string profile);
+
+	/** Destructor. */
+	virtual ~ExtraTags();
+
+	/** Handle the beginning of an element. */
+	bool addTag( const std::string tag, const std::string data);
+	
+private:
+	/** Disable default copy constructor. */
+	ExtraTags( const ExtraTags& pre );
+	/** Disable default assignment operator. */
+	const ExtraTags& operator= ( const ExtraTags& pre );
+	
+	std::string profile;
+};


Property changes on: trunk/blender/source/blender/collada/ExtraTags.h
___________________________________________________________________
Added: svn:keywords
   + Author Date Id Revision
Added: svn:eol-style
   + native



More information about the Bf-blender-cvs mailing list