Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorNathan Letwory <nathan@letworyinteractive.com>2011-03-25 14:07:57 +0300
committerNathan Letwory <nathan@letworyinteractive.com>2011-03-25 14:07:57 +0300
commit32abf5eca87795f4bf6fca1357a4e66a4403b17c (patch)
tree686fe4df5636e259d8db87885f48ba4a7ed5f6ac /source
parent6d0859768883c96f303fa5be5c44e81f60d262a4 (diff)
Add ExtraTags class for handling tags inside an extra block.
Diffstat (limited to 'source')
-rw-r--r--source/blender/collada/CMakeLists.txt2
-rw-r--r--source/blender/collada/DocumentImporter.cpp21
-rw-r--r--source/blender/collada/DocumentImporter.h6
-rw-r--r--source/blender/collada/ExtraHandler.cpp27
-rw-r--r--source/blender/collada/ExtraHandler.h2
-rw-r--r--source/blender/collada/ExtraTags.cpp50
-rw-r--r--source/blender/collada/ExtraTags.h54
7 files changed, 151 insertions, 11 deletions
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<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 @@ 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<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;
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 <extra> 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 <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
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 <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;
+};