Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ColladaPlugin/src/OgreColladaUtils.cpp @ 24

Last change on this file since 24 was 21, checked in by nicolasc, 16 years ago

added ogreode and Colladaplugin

File size: 4.8 KB
Line 
1/**
2 * This source file is part of OgreColladaPlugin
3 * an addon for OGRE (Object-oriented Graphics Rendering Engine)
4 * For the latest info, see http://www.ogre3d.org/
5 *
6 * This program is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Lesser General Public License as published by the Free Software
8 * Foundation; either version 2 of the License, or (at your option) any later
9 * version.
10
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14
15 * You should have received a copy of the GNU Lesser General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
17 * Place - Suite 330, Boston, MA 02111-1307, USA, or go to
18 * http://www.gnu.org/copyleft/lesser.txt.
19 *
20 * @author      Philipp Hartl
21 * @see         README
22 */
23
24#include "OgreColladaUtils.h"
25#include "OgreColladaSyntax.h"
26
27#include "OgreColourValue.h"
28#include "OgreStringVector.h"
29
30namespace Ogre
31{
32        //-------------------------------------------------------------------------
33        xmlNode *ColladaUtils::getChildById(xmlNode *start, const char *id)
34        {
35                if (start != NULL && id != NULL)
36                {
37                        // we are looking for strings without '#'
38                        if (*id == '#') ++id;
39
40                        // walk through all children
41                        for (xmlNode *c = start->children; c != NULL; c = c->next)
42                        {
43                                // we are interested on element nodes only
44                                if (c->type != XML_ELEMENT_NODE) continue;
45
46                                String cid = getProperty(c, CS_ATR_ID);
47                                if (!cid.empty())
48                                {
49                                        if (cid == id) return c;
50                                }
51                        }
52                }
53
54                return NULL;
55        }
56
57        //-------------------------------------------------------------------------
58        xmlNode *ColladaUtils::getChildByTagName(xmlNode *start, const String &tagname)
59        {
60                if (start != NULL && !tagname.empty())
61                {
62                        for (xmlNode *c = start->children; c != NULL; c = c->next)
63                        {       
64                                if (c->type != XML_ELEMENT_NODE) continue;
65
66                                if (tagname == (const char *)c->name) return c;
67                        }
68                }
69
70                return NULL;
71        }
72
73        //-------------------------------------------------------------------------
74        xmlNodePtrVector ColladaUtils::getChildsByTagName(xmlNode *start, const String &tagname)
75        {
76                xmlNodePtrVector nodes;
77
78                if (start != NULL && !tagname.empty())
79                {
80                        for (xmlNode *c = start->children; c != NULL; c = c->next)
81                        {
82                                if (c->type != XML_ELEMENT_NODE) continue;
83
84                                if (tagname == (const char *)c->name) nodes.push_back(c);
85                        }
86                }
87
88                return nodes;
89        }
90
91        //-------------------------------------------------------------------------
92        String ColladaUtils::getContent(xmlNode *node)
93        {
94                String result = "";
95                if (node != NULL)
96                {
97                        xmlChar *data = xmlNodeGetContent(node);
98
99                        if (data != NULL)
100                        {
101                                result = (const char *)data;
102                                xmlFree(data);
103                        }
104                }
105                return result;
106        }
107
108        //-------------------------------------------------------------------------
109        String ColladaUtils::getContentDirect(xmlNode *node)
110        {
111                String result = "";
112                if (node != NULL)
113                {
114                        if (node->children != NULL &&
115                                node->children->type == XML_TEXT_NODE &&
116                                node->children->content != NULL)
117                        {
118                                result = (const char *)node->children->content;
119                        }
120                }
121                return result;
122        }
123
124        //-------------------------------------------------------------------------
125        String ColladaUtils::getProperty(xmlNode *node, const char *property)
126        {
127                String result = "";
128                if (node != NULL && property != NULL)
129                {
130                        xmlChar *data = xmlGetProp(node, (const xmlChar *)property);
131               
132                        if (data != NULL)
133                        {
134                                result = (const char *)data;
135                                xmlFree(data);
136                        }
137                }
138
139                return result;
140        }
141
142        //-------------------------------------------------------------------------
143        String ColladaUtils::getProperty(xmlNode *node, const String &property)
144        {
145                String result = "";
146                if (node != NULL && !property.empty())
147                {
148                        xmlChar *data = xmlGetProp(node, (const xmlChar *)property.c_str());
149               
150                        if (data != NULL)
151                        {
152                                result = (const char *)data;
153                                xmlFree(data);
154                        }
155                }
156
157                return result;
158        }
159
160        //-------------------------------------------------------------------------
161        void ColladaUtils::printChildElements(xmlNode *node)
162        {
163                for (xmlNode *child = node->children; child != NULL; child = child->next)
164                {
165                        if (child->type != XML_ELEMENT_NODE) continue;
166                        LogManager::getSingleton().logMessage("ColladaUtils::printElementNames - xml element: " + String((const char *)child->name));
167                }
168        }
169
170        //-------------------------------------------------------------------------
171        void ColladaUtils::printAllElements(xmlNode *node)
172        {
173                for (xmlNode *cur_node = node; cur_node != NULL; cur_node = cur_node->next)
174                {
175                        if (cur_node->type != XML_ELEMENT_NODE) continue;
176                        LogManager::getSingleton().logMessage("ColladaUtils::printElementNames - xml element: " + String((const char *)cur_node->name));
177
178                        printAllElements(cur_node->children);
179                }
180        }
181}
Note: See TracBrowser for help on using the repository browser.