From 32abf5eca87795f4bf6fca1357a4e66a4403b17c Mon Sep 17 00:00:00 2001 From: Nathan Letwory Date: Fri, 25 Mar 2011 11:07:57 +0000 Subject: [PATCH] Add ExtraTags class for handling tags inside an extra block. --- source/blender/collada/CMakeLists.txt | 2 + source/blender/collada/DocumentImporter.cpp | 21 +++++++- source/blender/collada/DocumentImporter.h | 6 ++- source/blender/collada/ExtraHandler.cpp | 27 ++++++++--- source/blender/collada/ExtraHandler.h | 2 + source/blender/collada/ExtraTags.cpp | 50 +++++++++++++++++++ source/blender/collada/ExtraTags.h | 54 +++++++++++++++++++++ 7 files changed, 151 insertions(+), 11 deletions(-) create mode 100644 source/blender/collada/ExtraTags.cpp create mode 100644 source/blender/collada/ExtraTags.h diff --git a/source/blender/collada/CMakeLists.txt b/source/blender/collada/CMakeLists.txt index 830e22f70d7..13c33e63869 100644 --- a/source/blender/collada/CMakeLists.txt +++ b/source/blender/collada/CMakeLists.txt @@ -64,6 +64,7 @@ set(SRC DocumentImporter.cpp EffectExporter.cpp ExtraHandler.cpp + ExtraTags.cpp GeometryExporter.cpp ImageExporter.cpp InstanceWriter.cpp @@ -85,6 +86,7 @@ set(SRC DocumentImporter.h EffectExporter.h ExtraHandler.h + ExtraTags.h GeometryExporter.h ImageExporter.h InstanceWriter.h diff --git a/source/blender/collada/DocumentImporter.cpp b/source/blender/collada/DocumentImporter.cpp index 77c2fc971ac..b0bbe49a182 100644 --- a/source/blender/collada/DocumentImporter.cpp +++ b/source/blender/collada/DocumentImporter.cpp @@ -101,7 +101,15 @@ DocumentImporter::DocumentImporter(bContext *C, const char *filename) : anim_importer(&unit_converter, &armature_importer, CTX_data_scene(C)) {} -DocumentImporter::~DocumentImporter() {} +DocumentImporter::~DocumentImporter() +{ + std::map::iterator etit; + etit = uid_tags_map.begin(); + while(etit!=uid_tags_map.end()) { + delete etit->second; + etit++; + } +} bool DocumentImporter::import() { @@ -997,8 +1005,17 @@ bool DocumentImporter::writeKinematicsScene( const COLLADAFW::KinematicsScene* k 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; } diff --git a/source/blender/collada/DocumentImporter.h b/source/blender/collada/DocumentImporter.h index 949185471f4..1905dfe6a3e 100644 --- a/source/blender/collada/DocumentImporter.h +++ b/source/blender/collada/DocumentImporter.h @@ -45,6 +45,7 @@ #include "AnimationImporter.h" #include "ArmatureImporter.h" #include "MeshImporter.h" +#include "ExtraTags.h" struct Main; @@ -122,7 +123,9 @@ public: 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 @@ private: std::map uid_effect_map; std::map uid_camera_map; std::map uid_lamp_map; + std::map uid_tags_map; std::map material_texture_mapping_map; std::map object_map; std::map node_map; diff --git a/source/blender/collada/ExtraHandler.cpp b/source/blender/collada/ExtraHandler.cpp index 3ab34e70c8c..9dc5f4e4ee6 100644 --- a/source/blender/collada/ExtraHandler.cpp +++ b/source/blender/collada/ExtraHandler.cpp @@ -31,7 +31,7 @@ #include "ExtraHandler.h" -ExtraHandler::ExtraHandler(DocumentImporter *dimp) +ExtraHandler::ExtraHandler(DocumentImporter *dimp) : currentExtraTags(0) { this->dimp = dimp; } @@ -40,22 +40,27 @@ ExtraHandler::~ExtraHandler() {} 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 @@ bool ExtraHandler::parseElement ( 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; } diff --git a/source/blender/collada/ExtraHandler.h b/source/blender/collada/ExtraHandler.h index df26310d696..de3b063290d 100644 --- a/source/blender/collada/ExtraHandler.h +++ b/source/blender/collada/ExtraHandler.h @@ -71,5 +71,7 @@ private: DocumentImporter* dimp; /** Holds Id of element for which XML elements are handled. */ COLLADAFW::UniqueId currentUid; + ExtraTags* currentExtraTags; + std::string currentElement; }; diff --git a/source/blender/collada/ExtraTags.cpp b/source/blender/collada/ExtraTags.cpp new file mode 100644 index 00000000000..4fce2768cee --- /dev/null +++ b/source/blender/collada/ExtraTags.cpp @@ -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 +#include "BLI_string.h" + +#include + +#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 diff --git a/source/blender/collada/ExtraTags.h b/source/blender/collada/ExtraTags.h new file mode 100644 index 00000000000..09a86741481 --- /dev/null +++ b/source/blender/collada/ExtraTags.h @@ -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 +#include +#include + +/** \brief Class for saving 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; +};