source: NonGTP/FCollada/FCDocument/FCDEntity.h @ 964

Revision 964, 7.7 KB checked in by igarcia, 18 years ago (diff)
Line 
1/*
2        Copyright (C) 2005-2006 Feeling Software Inc.
3        MIT License: http://www.opensource.org/licenses/mit-license.php
4*/
5/*
6        Based on the FS Import classes:
7        Copyright (C) 2005-2006 Feeling Software Inc
8        Copyright (C) 2005-2006 Autodesk Media Entertainment
9        MIT License: http://www.opensource.org/licenses/mit-license.php
10*/
11
12/**
13        @file FCDEntity.h
14        This file contains the FCDEntity class.
15*/
16
17#ifndef _FCD_ENTITY_H_
18#define _FCD_ENTITY_H_
19
20#include "FCDocument/FCDObject.h"
21
22class FCDocument;
23class FCDExtra;
24
25/**
26        A COLLADA entity.
27
28        A COLLADA entity is an object contained within a COLLADA library.
29        As such, it is based on the FCDObjectWithId class so that it
30        can be accessed by other entities, such as the scene graph.
31
32        The entity adds to the FCDObjectWithId class: a name,
33        an extra tree and an optional note, as well as a way
34        to identity the type of the entity, in order to up-cast it
35        to its correct class.
36
37        @ingroup FCDocument
38*/
39
40class FCOLLADA_EXPORT FCDEntity : public FCDObjectWithId
41{
42public:
43        /** The types of entity classes.
44                Each type corresponds directly to one class that contains the
45                FCDEntity class as a parent, so you can up-cast FCDEntity pointers. */
46        enum Type
47        {
48                ENTITY, /**< A generic entity (FCDEntity). Should never be used. */
49                ANIMATION, /**< An animation (FCDAnimation). */
50                ANIMATION_CLIP, /**< An animation clip (FCDAnimationClip). */
51                CAMERA, /**< A camera (FCDCamera). */
52                LIGHT, /**< A light (FCDLight). */
53                IMAGE, /**< An image (FCDImage). */
54                TEXTURE, /**< A texture (FCDTexture). Used for COLLADA 1.3 backward compatibility only! */
55                MATERIAL, /**< A visual material definition (FCDMaterial). */
56                EFFECT, /**< An effect definition (FCDEffect). */
57                GEOMETRY, /**< A geometric object (FCDGeometry). Includes splines and meshes. */
58                CONTROLLER, /**< A geometric controller (FCDController). Includes skins and morphers. */
59                SCENE_NODE, /**< A visual scene node (FCDSceneNode). */
60                PHYSICS_RIGID_CONSTRAINT, /**< A physics rigid constraint (FCDPhysicsRigidConstraint). */
61                PHYSICS_MATERIAL, /**< A physics material definiton (FCDPhysicsMaterial). */
62                PHYSICS_RIGID_BODY, /**< A physics rigid body (FCDPhysicsRigidBody). */
63                PHYSICS_SHAPE, /**< A physics shape (FCDPhysicsShape). */
64                PHYSICS_ANALYTICAL_GEOMETRY, /**< A physics analytical geometric object (FCDPhysicsAnalyticalGeometry). */
65                PHYSICS_MODEL, /**< A physics model (FCDPhysicsModel). */
66                PHYSICS_SCENE_NODE /**< A physics scene node (FCDPhysicsSceneNode). */
67        };
68
69private:
70        DeclareObjectType;
71        fstring name;
72
73        // Extra information for the entity.
74        FCDExtra* extra;
75
76        // Maya and Max both support custom strings for objects.
77        fstring note;
78
79        // Deprecated ColladaMaya post-processing information.
80        StringList postCmds;
81
82public:
83        /** Constructor: do not use directly.
84                Instead, create objects of the up-classes.
85                @param document The COLLADA document that owns the entity.
86                @param baseId The prefix COLLADA id to be used if no COLLADA id is provided. */
87        FCDEntity(FCDocument* document, const char* baseId = "GenericEntity");
88
89        /** Destructor: do not use directly.
90                Instead, release objects through their libraries or their parent entities. */
91        virtual ~FCDEntity();
92
93        /** Retrieves the entity class type for an entity.
94                You can use the entity class type of up-cast an entity pointer
95                to the correct up-class.
96                This function should be overwritten by all up-classes.
97                @return The entity class type. */
98        virtual Type GetType() const { return ENTITY; }
99
100        /** Retrieves the name of the entity.
101                This value has no direct use in COLLADA but is useful
102                to track the user-friendly name of an entity.
103                @return The name. */
104        const fstring& GetName() const { return name; }
105
106        /** Sets the name of the entity.
107                This value has no direct use in COLLADA but is useful
108                to track the user-friendly name of an entity.
109                @param _name The name. */
110        void SetName(const fstring& _name);
111
112        /** Retrieves the extra information tree for this entity.
113                The prefered way to save extra information in FCollada is at
114                the entity level. Use this extra information tree to store
115                any information you want exported and imported back.
116                @return The extra information tree. */
117        FCDExtra* GetExtra() { return extra; }
118        const FCDExtra* GetExtra() const { return extra; } /**< See above. */
119
120        /** Retrieves whether the entity has a user-defined note.
121                This value is a simpler way, than the extra tree, to store
122                user-defined information that does not belong in COLLADA.
123                @return Whether the entity has an user-defined note. */
124        bool HasNote() const { return !note.empty(); }
125
126        /** Retrieves the user-defined note for this entity.
127                This value is a simpler way, than the extra tree, to store
128                user-defined information that does not belong in COLLADA.
129                @return The user-defined note. */
130        const fstring& GetNote() const { return note; }
131
132        /** Sets the user-defined note for this entity.
133                This value is a simpler way, than the extra tree, to store
134                user-defined information that does not belong in COLLADA.
135                @param _note The user-defined note. */
136        void SetNote(const fstring& _note) { note = _note; }
137
138        /** Retrieves the child entity that has the given COLLADA id.
139                This function is only useful for entities that are hierarchical:
140                visual/physics scene nodes and animations.
141                @param daeId A COLLADA id.
142                @return The child entity with the given id. This pointer will be NULL
143                        if no child entity matches the given id. */
144        virtual FCDEntity* FindDaeId(const string& daeId);
145
146        /** [INTERNAL] Reads in the entity from a given COLLADA XML tree node.
147                This function should be overwritten by all up-classes.
148                @param entityNode The COLLADA XML tree node.
149                @return The status of the import. If the status is not successful,
150                        it may be dangerous to extract information from the entity.*/
151        virtual FUStatus LoadFromXML(xmlNode* entityNode);
152
153        /** [INTERNAL] Writes out the entity to the given COLLADA XML tree node.
154                This function should be overwritten by all up-classes.
155                @param parentNode The COLLADA XML parent node in which to insert the entity.
156                @return The created element XML tree node. */
157        virtual xmlNode* WriteToXML(xmlNode* parentNode) const;
158
159        /** @deprecated Retrieves the like of post-processing commands.
160                Used only in ColladaMaya and should be taken out.
161                @return The list of post-processing commands. */
162        StringList& GetPostProcessCmds() { return postCmds; }
163
164protected:
165        /** [INTERNAL] Writes out the top entity XML node for the entity.
166                This function should be used by all up-classes within the
167                WriteToXML overwritting function to create the top XML node,
168                as it will write out the name and COLLADA id of the entity.
169                @param parentNode The COLLADA XML parent node in which to insert the entity.
170                @param nodeName The COLLADA XML node name for the top entity XML node.
171                @return The created element XML tree node. */
172        xmlNode* WriteToEntityXML(xmlNode* parentNode, const char* nodeName) const;
173
174        /** [INTERNAL] Writes out the extra information for the entity.
175                This function should be used by all up-classes within the
176                WriteToXML overwritting function, at the very end, to write
177                the user-defined note and the extra tree to the COLLADA document.
178                @param entityNode The created element XML tree node returned
179                        by the WriteToEntityXML function. */
180        void WriteToExtraXML(xmlNode* entityNode) const;
181
182        /** [INTERNAL] Copies the entity information into a cloned entity.
183                This function should be used by all up-classes when cloning an entity
184                to copy the COLLADA id and the other entity-level information into a clone.
185                @param clone The cloned entity. */
186        void Clone(FCDEntity* clone);
187};
188
189#endif // _FCD_ENTITY_H_
190
Note: See TracBrowser for help on using the repository browser.