From fa68f489ccac4d58a252a64e98376fc5c364df9f Mon Sep 17 00:00:00 2001 From: granzuglia Date: Wed, 8 Nov 2006 19:49:57 +0000 Subject: [PATCH] import, export and util semantically-correct for visual studio 2005 --- wrap/io_trimesh/export_dae.h | 82 +++++++++++++++++++++++++----------- wrap/io_trimesh/import_dae.h | 4 +- wrap/io_trimesh/util_dae.h | 16 ++++--- 3 files changed, 70 insertions(+), 32 deletions(-) diff --git a/wrap/io_trimesh/export_dae.h b/wrap/io_trimesh/export_dae.h index b7fd088c..49494f9d 100644 --- a/wrap/io_trimesh/export_dae.h +++ b/wrap/io_trimesh/export_dae.h @@ -14,28 +14,26 @@ class ExporterDAE : public UtilDAE { private: - static void SaveTexture(QDomDocument& doc,QDomNode& n,const std::vector& stv) - { - removeChildNode(doc,"library_images"); - QDomElement el = doc.createElement("library_images"); - for(int img = 0;img < stv.size();++img) - { - QDomElement imgnode = doc.createElement("image"); - imgnode.setAttribute("id","file"+QString::number(img)); - imgnode.setAttribute("name","file"+QString::number(img)); - QDomElement tex = doc.createElement("init_from"); - QDomText txname = doc.createTextNode(stv[img]); - tex.appendChild(txname); - imgnode.appendChild(tex); - el.appendChild(imgnode); - } - n.appendChild(el); - } + //static void SaveTexture(QDomDocument& doc,QDomNode& n,const std::vector& stv) + //{ + // removeChildNode(doc,"library_images"); + // QDomElement el = doc.createElement("library_images"); + // for(int img = 0;img < stv.size();++img) + // { + // QDomElement imgnode = doc.createElement("image"); + // imgnode.setAttribute("id","file"+QString::number(img)); + // imgnode.setAttribute("name","file"+QString::number(img)); + // QDomElement tex = doc.createElement("init_from"); + // QDomText txname = doc.createTextNode(stv[img]); + // tex.appendChild(txname); + // imgnode.appendChild(tex); + // el.appendChild(imgnode); + // } + // n.appendChild(el); + //} - static void SaveTexture(QDomDocument& doc,QDomNode& n,const std::vector& stv) + static void SaveTextureName(QDomDocument& doc,QDomNode& lbim,const std::vector& stv) { - removeChildNode(doc,"library_images"); - QDomElement el = doc.createElement("library_images"); for(int img = 0;img < stv.size();++img) { QDomElement imgnode = doc.createElement("image"); @@ -45,9 +43,24 @@ private: QDomText txname = doc.createTextNode(QString(stv[img].c_str())); tex.appendChild(txname); imgnode.appendChild(tex); - el.appendChild(imgnode); + lbim.appendChild(imgnode); } - n.appendChild(el); + } + + static void SaveTexture(QDomDocument& doc,QDomNode& n,const std::vector& stv) + { + QDomElement el = doc.createElement("library_images"); + SaveTextureName(doc,el,stv); + n.appendChild(el); + } + + static void SaveTexture(QDomDocument& doc,const std::vector& stv) + { + QDomNodeList lbim = doc.elementsByTagName("library_images"); + assert(lbim.size() == 1); + removeChildNode(lbim.at(0)); + + SaveTextureName(doc,lbim.at(0),stv); } static void CreateVertInput(QDomDocument& doc,QDomNode& vert,const QString& attr,const QString& ref) @@ -271,7 +284,11 @@ public: coll.appendChild(ass); if (m.textures.size() != 0) - SaveTexture(doc,doc.firstChild(),m.textures); + { + QDomNodeList cl = doc.elementsByTagName("COLLADA"); + assert(cl.size() == 1); + SaveTexture(doc,cl.at(0),m.textures); + } QDomElement geolib = doc.createElement("library_geometries"); QDomElement geonode = doc.createElement("geometry"); @@ -337,9 +354,13 @@ public: assert(scenelst.size() == 1); if (m.textures.size() != 0) - SaveTexture(*(info->doc),info->doc->firstChild(),m.textures); + SaveTexture(*(info->doc),m.textures); QDomNodeList vsscene = info->doc->elementsByTagName("library_visual_scenes"); + + QDomNodeList geolib = info->doc->elementsByTagName("library_geometries"); + assert(geolib.size() == 1); + if (info->doc->elementsByTagName("instance_geometry").size() != 0) { QDomNodeList invisscnlst = info->doc->elementsByTagName("instance_visual_scene"); @@ -352,8 +373,17 @@ public: for(int no = 0;no < sc.childNodes().size();++no) { QDomNode oldnode = sc.childNodes().at(no); - if (sc.childNodes().at(no).toElement().elementsByTagName("instance_geometry").size() != 0) + QDomNodeList lst = sc.childNodes().at(no).toElement().elementsByTagName("instance_geometry"); + int lst_size = lst.size(); + if (lst_size != 0) { + for(int ingeo = 0;ingeo < lst_size;++ingeo) + { + QString url; + referenceToANodeAttribute(lst.at(ingeo),"url",url); + QDomNode oldgeo = findNodeBySpecificAttributeValue(geolib.at(0),"geometry","id",url); + geolib.at(0).removeChild(oldgeo); + } sc.removeChild(oldnode); } } @@ -372,6 +402,8 @@ public: QDomNodeList geolib = info->doc->elementsByTagName("library_geometries"); assert(geolib.size() == 1); //removeChildNode(geolib.at(0)); + + /*QDomElement mshnode; mshnode.setTagName("mesh");*/ diff --git a/wrap/io_trimesh/import_dae.h b/wrap/io_trimesh/import_dae.h index 1affc681..c8272632 100644 --- a/wrap/io_trimesh/import_dae.h +++ b/wrap/io_trimesh/import_dae.h @@ -388,11 +388,11 @@ namespace io { QDomDocument* doc = new QDomDocument(filename); QFile file(filename); if (!file.open(QIODevice::ReadOnly)) - return E_CANTOPEN; + return false; if (!doc->setContent(&file)) { file.close(); - return E_CANTOPEN; + return false; } file.close(); diff --git a/wrap/io_trimesh/util_dae.h b/wrap/io_trimesh/util_dae.h index d8b6ed86..154777d1 100644 --- a/wrap/io_trimesh/util_dae.h +++ b/wrap/io_trimesh/util_dae.h @@ -171,13 +171,13 @@ namespace io { return true; } - /* inline static bool removeChildNode(QDomNode& node,const QString& tag = "", const QString& attribname = "", const QString& attribvalue = "") + inline static bool removeChildNode(QDomNode& node,const QString& tag = "", const QString& attribname = "", const QString& attribvalue = "") { return removeChildNode((QDomDocument&) node.toElement(),tag,attribname,attribvalue); - }*/ + } - //inline static bool removeChildNode(QDomDocument& node,const QString& tag = "", const QString& attribname = "", const QString& attribvalue = "") - inline static bool removeChildNode(QDomNode& node,const QString& tag = "", const QString& attribname = "", const QString& attribvalue = "") + inline static bool removeChildNode(QDomDocument& node,const QString& tag = "", const QString& attribname = "", const QString& attribvalue = "") + //inline static bool removeChildNode(QDomNode node,const QString& tag = "", const QString& attribname = "", const QString& attribvalue = "") { QDomNodeList clst = node.childNodes(); for(int ii = 0;ii < clst.size();++ii) @@ -190,8 +190,14 @@ namespace io { if (clst.at(ii).toElement().attribute(attribname) == attribvalue) node.removeChild(oldchild); } - else if (clst.at(ii).nodeName() == tag) + else + { + QString nm = clst.at(ii).nodeName(); + if (clst.at(ii).nodeName() == tag) + { node.removeChild(oldchild); + } + } } else node.removeChild(oldchild); }