1 | /*
|
---|
2 | Copyright (C) 2005-2006 Feeling Software Inc.
|
---|
3 | MIT License: http://www.opensource.org/licenses/mit-license.php
|
---|
4 | */
|
---|
5 |
|
---|
6 | /**
|
---|
7 | @file FCDExtra.h
|
---|
8 | This file contains the FCDExtra class and its sub-classes:
|
---|
9 | FCDENode, FCDETechnique and FCDEAttribute.
|
---|
10 | */
|
---|
11 |
|
---|
12 | #ifndef _FCD_EXTRA_H_
|
---|
13 | #define _FCD_EXTRA_H_
|
---|
14 |
|
---|
15 | #include "FCDocument/FCDObject.h"
|
---|
16 |
|
---|
17 | class FCDAnimated;
|
---|
18 | class FCDAnimatedCustom;
|
---|
19 | class FCDETechnique;
|
---|
20 | class FCDENode;
|
---|
21 |
|
---|
22 | /**
|
---|
23 | An extra tree attribute.
|
---|
24 | Contains a name and a value string.
|
---|
25 | */
|
---|
26 | struct FCDEAttribute
|
---|
27 | {
|
---|
28 | string name; /**< The attribute name. Must be provided. */
|
---|
29 | fstring value; /**< The attribute value. Is optional. */
|
---|
30 | };
|
---|
31 |
|
---|
32 | typedef vector<FCDETechnique*> FCDETechniqueList; /**< A dynamically-sized array of extra tree techniques. */
|
---|
33 | typedef vector<FCDENode*> FCDENodeList; /**< A dynamically-sized array of extra tree nodes. */
|
---|
34 | typedef vector<FCDEAttribute*> FCDEAttributeList; /**< A dynamically-sized array of extra tree attributes. */
|
---|
35 |
|
---|
36 | /**
|
---|
37 | A COLLADA extra tree.
|
---|
38 |
|
---|
39 | An extra tree contains the user-defined COLLADA information
|
---|
40 | contained within \<extra\> elements. For this, the extra tree
|
---|
41 | root simply contains a list of techniques. Each technique
|
---|
42 | belongs to a different application-specific profile.
|
---|
43 | */
|
---|
44 | class FCOLLADA_EXPORT FCDExtra : public FCDObject
|
---|
45 | {
|
---|
46 | private:
|
---|
47 | DeclareObjectType;
|
---|
48 | FCDETechniqueList techniques;
|
---|
49 |
|
---|
50 | public:
|
---|
51 | /** Constructor: do not use directly.
|
---|
52 | The structures that contain extra trees will create them.
|
---|
53 | @param document The COLLADA document that owns the extra tree. */
|
---|
54 | FCDExtra(FCDocument* document);
|
---|
55 |
|
---|
56 | /** Destructor: do not use directly.
|
---|
57 | The structures that contain extra trees will release them. */
|
---|
58 | virtual ~FCDExtra();
|
---|
59 |
|
---|
60 | /** Retrieves the list of techniques contained by this extra tree.
|
---|
61 | @return The list of techniques. */
|
---|
62 | FCDETechniqueList& GetTechniques() { return techniques; }
|
---|
63 | const FCDETechniqueList& GetTechniques() const { return techniques; } /**< See above. */
|
---|
64 |
|
---|
65 | /** Retrieves the number of techniques contained by this extra tree.
|
---|
66 | @return The number of techniques. */
|
---|
67 | size_t GetTechniqueCount() const { return techniques.size(); }
|
---|
68 |
|
---|
69 | /** Retrieves a specific technique contained by this extra tree.
|
---|
70 | @param index The index of the technique.
|
---|
71 | @return The technique. This pointer will be NULL if the
|
---|
72 | index is out-of-bounds. */
|
---|
73 | FCDETechnique* GetTechnique(size_t index) { FUAssert(index < techniques.size(), return NULL); return techniques.at(index); }
|
---|
74 | const FCDETechnique* GetTechnique(size_t index) const { FUAssert(index < techniques.size(), return NULL); return techniques.at(index); } /**< See above. */
|
---|
75 |
|
---|
76 | /** Adds a new application-specific profile technique to the extra tree.
|
---|
77 | If the given application-specific profile already exists
|
---|
78 | within the extra tree, the old technique will be returned.
|
---|
79 | @param profile The application-specific profile name.
|
---|
80 | @return A technique for this application-specific profile. */
|
---|
81 | FCDETechnique* AddTechnique(const char* profile);
|
---|
82 | inline FCDETechnique* AddTechnique(const string& profile) { return AddTechnique(profile.c_str()); } /**< See above. */
|
---|
83 |
|
---|
84 | /** Releases a technique contained within the extra tree.
|
---|
85 | @param technique The technique to release. */
|
---|
86 | void ReleaseTechnique(FCDETechnique* technique);
|
---|
87 |
|
---|
88 | /** Retrieves a specific technique contained by this extra tree.
|
---|
89 | @param profile The application-specific profile name of the technique.
|
---|
90 | @return The technique that matches the profile name. This pointer may
|
---|
91 | be NULL if no technique matches the profile name. */
|
---|
92 | FCDETechnique* FindTechnique(const char* profile);
|
---|
93 | const FCDETechnique* FindTechnique(const char* profile) const; /**< See above. */
|
---|
94 | inline FCDETechnique* FindTechnique(const string& profile) { return FindTechnique(profile.c_str()); } /**< See above. */
|
---|
95 | inline const FCDETechnique* FindTechnique(const string& profile) const { return FindTechnique(profile.c_str()); } /**< See above. */
|
---|
96 |
|
---|
97 | /** Retrieves the extra tree node that has a given element name.
|
---|
98 | This function searches for the extra tree node within all the
|
---|
99 | techniques.
|
---|
100 | @param name An element name.
|
---|
101 | @return The extra tree node that matches the element name. This pointer
|
---|
102 | will be NULL if no extra tree node matches the element name. */
|
---|
103 | FCDENode* FindRootNode(const char* name);
|
---|
104 | const FCDENode* FindRootNode(const char* name) const; /**< See above. */
|
---|
105 | inline FCDENode* FindRootNode(const string& name) { return FindRootNode(name.c_str()); } /**< See above. */
|
---|
106 | inline const FCDENode* FindRootNode(const string& name) const { return FindRootNode(name.c_str()); } /**< See above. */
|
---|
107 |
|
---|
108 | /** [INTERNAL] Reads in the extra tree from a given COLLADA XML tree node.
|
---|
109 | @param extraNode The COLLADA \<extra\> element XML tree node.
|
---|
110 | @return The status of the import. If the status is not successful,
|
---|
111 | it may be dangerous to extract information from the entity.*/
|
---|
112 | FUStatus LoadFromXML(xmlNode* extraNode);
|
---|
113 |
|
---|
114 | /** [INTERNAL] Writes out the extra tree to the given COLLADA XML tree node.
|
---|
115 | @param parentNode The COLLADA XML parent node in which to insert the \<extra\> element.
|
---|
116 | @return The created element XML tree node. */
|
---|
117 | xmlNode* WriteToXML(xmlNode* parentNode) const;
|
---|
118 | };
|
---|
119 |
|
---|
120 | /**
|
---|
121 | A COLLADA extra tree node.
|
---|
122 |
|
---|
123 | The extra tree node is a hierarchical structure that contains child
|
---|
124 | extra tree nodes as well as attributes. If the extra tree node is a leaf
|
---|
125 | of the tree, it may contain textual content.
|
---|
126 |
|
---|
127 | The extra tree node leaf may be animated, if it has the 'sid' attribute.
|
---|
128 | */
|
---|
129 | class FCOLLADA_EXPORT FCDENode : public FCDObject
|
---|
130 | {
|
---|
131 | private:
|
---|
132 | DeclareObjectType;
|
---|
133 |
|
---|
134 | string name;
|
---|
135 | fstring content;
|
---|
136 |
|
---|
137 | FCDENode* parent;
|
---|
138 | FCDENodeList children;
|
---|
139 | FCDEAttributeList attributes;
|
---|
140 |
|
---|
141 | FCDAnimatedCustom* animated;
|
---|
142 |
|
---|
143 | public:
|
---|
144 | /** Constructor: do not use directly.
|
---|
145 | Instead, call the FCDENode::AddChild function of the parent within the hierarchy.
|
---|
146 | @param document The COLLADA document that owns the extra tree node.
|
---|
147 | @param parent The extra tree node that contains this extra tree node. */
|
---|
148 | FCDENode(FCDocument* document, FCDENode* parent);
|
---|
149 |
|
---|
150 | /** Destructor: do not use directly.
|
---|
151 | Instead, for hierarchical nodes: call the Release function
|
---|
152 | or the parent's ReleaseChildNode function and for techniques:
|
---|
153 | call the FCDExtra::ReleaseTechnique function. */
|
---|
154 | virtual ~FCDENode();
|
---|
155 |
|
---|
156 | /** Releases this extra tree node.
|
---|
157 | This function is a shortcut to the parent's FCDENode::ReleaseChildNode function. */
|
---|
158 | void Release();
|
---|
159 |
|
---|
160 | /** Retrieves the name of the extra tree node.
|
---|
161 | The name of the extra tree node is the name of the equivalent XML tree node.
|
---|
162 | @return The name of the extra tree node. */
|
---|
163 | inline const char* GetName() const { return name.c_str(); }
|
---|
164 |
|
---|
165 | /** Sets the name of the extra tree node.
|
---|
166 | The name of the extra tree node is the name of the equivalent XML tree node.
|
---|
167 | @param _name The name of the extra tree node. */
|
---|
168 | inline void SetName(const char* _name) { name = _name; }
|
---|
169 | inline void SetName(const string& _name) { name = _name; } /**< See above. */
|
---|
170 |
|
---|
171 | /** Retrieves the textual content of the extra tree node.
|
---|
172 | This value is only valid for extra tree node that have no children,
|
---|
173 | as COLLADA doesn't allow for mixed-content.
|
---|
174 | @return The textual content of the extra tree node. */
|
---|
175 | const fchar* GetContent() const { return content.c_str(); }
|
---|
176 |
|
---|
177 | /** Sets the textual content of the extra tree node.
|
---|
178 | This function will release all the child node of this extra tree node,
|
---|
179 | as COLLADA doesn't allow for mixed-content.
|
---|
180 | @param _content The textual content. */
|
---|
181 | void SetContent(const fchar* _content);
|
---|
182 | inline void SetContent(const fstring& _content) { return SetContent(_content.c_str()); } /**< See above. */
|
---|
183 |
|
---|
184 | /** Retrieves the animated values associated with this extra tree node.
|
---|
185 | Extra tree node leaves may be animated. If this extra tree node leaf
|
---|
186 | is animated, this animated value will contain the animation curves.
|
---|
187 | @return The animated value. */
|
---|
188 | FCDAnimatedCustom* GetAnimated() { return animated; }
|
---|
189 | const FCDAnimatedCustom* GetAnimated() const { return animated; } /**< See above. */
|
---|
190 |
|
---|
191 | /** Retrieves the parent of an extra tree node.
|
---|
192 | The hierarchy cannot be changed dynamically. If you to move an extra tree node,
|
---|
193 | you will need to clone it manually and release the old extra tree node.
|
---|
194 | @return The parent extra tree node within the hierarchy. This pointer
|
---|
195 | will be NULL if the extra tree node is a extra tree technique. */
|
---|
196 | FCDENode* GetParent() { return parent; }
|
---|
197 | const FCDENode* GetParent() const { return parent; } /**< See above. */
|
---|
198 |
|
---|
199 | /** Retrieves the children of an extra tree node.
|
---|
200 | @return The list of child extra tree nodes. */
|
---|
201 | FCDENodeList& GetChildNodes() { return children; }
|
---|
202 | const FCDENodeList& GetChildNodes() const { return children; } /**< See above. */
|
---|
203 |
|
---|
204 | /** Retrieves the number of children of an extra tree node.
|
---|
205 | @return The number of children. */
|
---|
206 | size_t GetChildNodeCount() const { return children.size(); }
|
---|
207 |
|
---|
208 | /** Retrieves a specific child extra tree node.
|
---|
209 | @param index The index of the child extra tree node.
|
---|
210 | @return The child extra tree node. This pointer will be NULL if the index
|
---|
211 | is out-of-bounds. */
|
---|
212 | FCDENode* GetChildNode(size_t index) { FUAssert(index < children.size(), return NULL); return children.at(index); }
|
---|
213 | const FCDENode* GetChildNode(size_t index) const { FUAssert(index < children.size(), return NULL); return children.at(index); } /**< See above. */
|
---|
214 |
|
---|
215 | /** Adds a new child extra tree to this extra tree node.
|
---|
216 | @return The new child extra tree node. */
|
---|
217 | FCDENode* AddChildNode();
|
---|
218 |
|
---|
219 | /** Releases a child extra tree node of this extra tree node.
|
---|
220 | @param childNode The child to release. */
|
---|
221 | void ReleaseChildNode(FCDENode* childNode);
|
---|
222 |
|
---|
223 | /** Retrieves the child extra tree node with the given name.
|
---|
224 | @param name A name.
|
---|
225 | @return The child extra tree node that matches the given name.
|
---|
226 | This pointer will be NULL if no child extra tree node matches
|
---|
227 | the given name. */
|
---|
228 | FCDENode* FindChildNode(const char* name);
|
---|
229 | const FCDENode* FindChildNode(const char* name) const; /**< See above. */
|
---|
230 | inline FCDENode* FindChildNode(const string& name) { return FindChildNode(name.c_str()); } /**< See above. */
|
---|
231 | inline const FCDENode* FindChildNode(const string& name) const { return FindChildNode(name.c_str()); } /**< See above. */
|
---|
232 |
|
---|
233 | /** Retrieves the child extra tree node with the given name.
|
---|
234 | This function is used for COLLADA 1.3 backward compatibility,
|
---|
235 | where all parameters were described as \<param name='X'>value\</param\>.
|
---|
236 | So, if the child extra tree node with the name 'X' as searched for:
|
---|
237 | both the above COLLADA 1.3 parameter and the COLLADA 1.4+
|
---|
238 | \<X\>value\</X\> parameters will be returned.
|
---|
239 | @param name The parameter name.
|
---|
240 | @return The first child extra tree node holding the wanted parameter within the hierarchy.
|
---|
241 | This pointer will be NULL to indicate that no parameter matches the given name. */
|
---|
242 | FCDENode* FindParameter(const char* name);
|
---|
243 |
|
---|
244 | /** Retrieves a list of all the parameters contained within the hierarchy.
|
---|
245 | This function is used for COLLADA 1.3 backward compatibility,
|
---|
246 | where all parameters were described as \<param name='X'>value\</param\>.
|
---|
247 | In COLLADA 1.4+, the same parameter should be described as: \<X\>value\</X\>.
|
---|
248 | Using this function, both parameters would be returned with the name 'X'.
|
---|
249 | @param nodes The list of parameters to fill in. This list is not emptied by the function.
|
---|
250 | @param names The list of names of the parameters. This list is not emptied by the function. */
|
---|
251 | void FindParameters(FCDENodeList& nodes, StringList& names);
|
---|
252 |
|
---|
253 | /** Retrieves the list of attributes for this extra tree node.
|
---|
254 | @return The list of attributes. */
|
---|
255 | FCDEAttributeList& GetAttributes() { return attributes; }
|
---|
256 | const FCDEAttributeList& GetAttributes() const { return attributes; } /**< See above. */
|
---|
257 |
|
---|
258 | /** Retrieves the number of attributes for this extra tree node.
|
---|
259 | @return The number of attributes. */
|
---|
260 | size_t GetAttributeCount() const { return attributes.size(); }
|
---|
261 |
|
---|
262 | /** Retrieves a specific attribute of this extra tree node.
|
---|
263 | @param index The index.
|
---|
264 | @return The attribute at this index. This pointer will be NULL
|
---|
265 | if the index is out-of-bounds. */
|
---|
266 | FCDEAttribute* GetAttribute(size_t index) { FUAssert(index < attributes.size(), return NULL); return attributes.at(index); }
|
---|
267 | const FCDEAttribute* GetAttribute(size_t index) const { FUAssert(index < attributes.size(), return NULL); return attributes.at(index); } /**< See above. */
|
---|
268 |
|
---|
269 | /** Adds a new attribute to this extra tree node.
|
---|
270 | If an attribute with the same name already exists, this function simply
|
---|
271 | assigns the new value to the existing attribute and returns the existing attribute.
|
---|
272 | @param _name The name of the attribute.
|
---|
273 | @param _value The value of the attribute.
|
---|
274 | @return The new attribute. */
|
---|
275 | FCDEAttribute* AddAttribute(const char* _name, const fchar* _value);
|
---|
276 | inline FCDEAttribute* AddAttribute(const string& _name, const fchar* _value) { return AddAttribute(_name.c_str(), _value); } /**< See above. */
|
---|
277 | inline FCDEAttribute* AddAttribute(const char* _name, const fstring& _value) { return AddAttribute(_name, _value.c_str()); } /**< See above. */
|
---|
278 | inline FCDEAttribute* AddAttribute(const string& _name, const fstring& _value) { return AddAttribute(_name.c_str(), _value.c_str()); } /**< See above. */
|
---|
279 | template <typename T> inline FCDEAttribute* AddAttribute(const char* _name, const T& _value) { return AddAttribute(_name, TO_FSTRING(_value)); } /**< See above. */
|
---|
280 | template <typename T> inline FCDEAttribute* AddAttribute(const string& _name, const T& _value) { return AddAttribute(_name.c_str(), TO_FSTRING(_value)); } /**< See above. */
|
---|
281 |
|
---|
282 | /** Releases an attribute of this extra tree node.
|
---|
283 | @param attribute The attribute to release. */
|
---|
284 | void ReleaseAttribute(FCDEAttribute* attribute);
|
---|
285 |
|
---|
286 | /** Retrieve the attribute of this extra tree node with the given name.
|
---|
287 | Attribute names are unique within an extra tree node.
|
---|
288 | @param name The attribute name.
|
---|
289 | @return The attribute that matches the name. This pointer will be NULL if
|
---|
290 | there is no attribute with the given name. */
|
---|
291 | FCDEAttribute* FindAttribute(const char* name);
|
---|
292 | const FCDEAttribute* FindAttribute(const char* name) const; /**< See above. */
|
---|
293 |
|
---|
294 | /** [INTERNAL] Reads in the extra tree node from a given COLLADA XML tree node.
|
---|
295 | @param customNode The COLLADA XML tree node.
|
---|
296 | @return The status of the import. If the status is not successful,
|
---|
297 | it may be dangerous to extract information from the extra tree node.*/
|
---|
298 | virtual FUStatus LoadFromXML(xmlNode* customNode);
|
---|
299 |
|
---|
300 | /** [INTERNAL] Writes out the extra tree node to the given COLLADA XML tree node.
|
---|
301 | @param parentNode The COLLADA XML parent node in which to insert the extra tree node.
|
---|
302 | @return The created element XML tree node. */
|
---|
303 | virtual xmlNode* WriteToXML(xmlNode* parentNode) const;
|
---|
304 |
|
---|
305 | protected:
|
---|
306 | /** [INTERNAL] Reads in the children nodes of the extra tree node.
|
---|
307 | Used by the FCDETechnique class exclusively.
|
---|
308 | @param customNode The COLLADA XML tree node.
|
---|
309 | @return The status of the import. If the status is not successful,
|
---|
310 | it may be dangerous to extract information from the extra tree node.*/
|
---|
311 | FUStatus ReadChildrenFromXML(xmlNode* customNode);
|
---|
312 |
|
---|
313 | /** [INTERNAL] Writes out the children nodes of extra tree node.
|
---|
314 | Used by the FCDETechnique class exclusively.
|
---|
315 | @param customNode The COLLADA XML node for the extra tree node. */
|
---|
316 | void WriteChildrenToXML(xmlNode* customNode) const;
|
---|
317 | };
|
---|
318 |
|
---|
319 | /**
|
---|
320 | A COLLADA extra tree technique.
|
---|
321 |
|
---|
322 | For convenience, this extra tree technique is based on top of the FCDENode class.
|
---|
323 | An extra tree technique is the root of the extra tree specific to
|
---|
324 | the profile of an application.
|
---|
325 |
|
---|
326 | @ingroup FCDocument
|
---|
327 | */
|
---|
328 | class FCOLLADA_EXPORT FCDETechnique : public FCDENode
|
---|
329 | {
|
---|
330 | private:
|
---|
331 | DeclareObjectType;
|
---|
332 |
|
---|
333 | string profile;
|
---|
334 |
|
---|
335 | public:
|
---|
336 | /** Constructor: do not use directly.
|
---|
337 | Instead, use the FCDExtra::AddTechnique function.
|
---|
338 | @param document The COLLADA document that owns the technique.
|
---|
339 | @param profile The application-specific profile name. */
|
---|
340 | FCDETechnique(FCDocument* document, const char* profile);
|
---|
341 |
|
---|
342 | /** Destructor: do not use directly.
|
---|
343 | Instead, release a technique using the FCDExtra::ReleaseTechnique function. */
|
---|
344 | virtual ~FCDETechnique();
|
---|
345 |
|
---|
346 | /** Retrieves the name of the application-specific profile of the technique.
|
---|
347 | @return The name of the application-specific profile. */
|
---|
348 | const char* GetProfile() const { return profile.c_str(); }
|
---|
349 |
|
---|
350 | /** [INTERNAL] Reads in the extra tree technique from a given COLLADA XML tree node.
|
---|
351 | @param techniqueNode The COLLADA XML tree node.
|
---|
352 | @return The status of the import. If the status is not successful,
|
---|
353 | it may be dangerous to extract information from the extra tree technique.*/
|
---|
354 | virtual FUStatus LoadFromXML(xmlNode* techniqueNode);
|
---|
355 |
|
---|
356 | /** [INTERNAL] Writes out the extra tree technique to the given COLLADA XML tree node.
|
---|
357 | @param parentNode The COLLADA XML parent node in which to insert the extra tree technique.
|
---|
358 | @return The created element XML tree node. */
|
---|
359 | virtual xmlNode* WriteToXML(xmlNode* parentNode) const;
|
---|
360 | };
|
---|
361 |
|
---|
362 | #endif // _FCD_EXTRA_H_
|
---|