forked from bartvdbraak/blender
Add ExtraTags class for handling tags inside an extra block.
This commit is contained in:
parent
6d08597688
commit
32abf5eca8
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
50
source/blender/collada/ExtraTags.cpp
Normal file
50
source/blender/collada/ExtraTags.cpp
Normal file
@ -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;
|
||||
}
|
54
source/blender/collada/ExtraTags.h
Normal file
54
source/blender/collada/ExtraTags.h
Normal file
@ -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;
|
||||
};
|
Loading…
Reference in New Issue
Block a user