1 /*
2 Copyright (C) 2005-2007 Feeling Software Inc.
3 Portions of the code are:
4 Copyright (C) 2005-2007 Sony Computer Entertainment America
5
6 MIT License: http://www.opensource.org/licenses/mit-license.php
7 */
8 /*
9 Based on the FS Import classes:
10 Copyright (C) 2005-2006 Feeling Software Inc
11 Copyright (C) 2005-2006 Autodesk Media Entertainment
12 MIT License: http://www.opensource.org/licenses/mit-license.php
13 */
14
15 #include "StdAfx.h"
16 #include "FCDocument/FCDocument.h"
17 #include "FCDocument/FCDAsset.h"
18 #include "FCDocument/FCDEntity.h"
19 #include "FCDocument/FCDExtra.h"
20
21 //
22 // Constants
23 //
24
25 static const size_t MAX_NAME_LENGTH = 512;
26
27 //
28 // FCDEntity
29 //
30
31 ImplementObjectType(FCDEntity);
32 ImplementParameterObject(FCDEntity, FCDAsset, asset, new FCDAsset(parent->GetDocument()));
33 ImplementParameterObject(FCDEntity, FCDExtra, extra, new FCDExtra(parent->GetDocument(), parent));
34
FCDEntity(FCDocument * document,const char * baseId)35 FCDEntity::FCDEntity(FCDocument* document, const char* baseId)
36 : FCDObjectWithId(document, baseId)
37 , InitializeParameterNoArg(name)
38 , InitializeParameterNoArg(extra)
39 , InitializeParameterNoArg(asset)
40 , InitializeParameterNoArg(note)
41 {
42 extra = new FCDExtra(document, this);
43 }
44
~FCDEntity()45 FCDEntity::~FCDEntity()
46 {
47 }
48
49 // Structure cloning
Clone(FCDEntity * clone,bool UNUSED (cloneChildren)) const50 FCDEntity* FCDEntity::Clone(FCDEntity* clone, bool UNUSED(cloneChildren)) const
51 {
52 if (clone == NULL)
53 {
54 clone = new FCDEntity(const_cast<FCDocument*>(GetDocument()));
55 }
56
57 FCDObjectWithId::Clone(clone);
58 clone->name = name;
59 clone->note = note;
60 if (extra != NULL)
61 {
62 extra->Clone(clone->extra);
63 }
64 return clone;
65 }
66
CleanName(const fchar * c)67 fstring FCDEntity::CleanName(const fchar* c)
68 {
69 size_t len = 0;
70 for (; len < MAX_NAME_LENGTH; len++) { if (c[len] == 0) break; }
71 fstring cleanName(len, *c);
72 fchar* id = cleanName.begin();
73 if (*c != 0)
74 {
75
76 // First character: alphabetic or '_'.
77 if ((*c >= 'a' && *c <= 'z') || (*c >= 'A' && *c <= 'Z') || *c == '_') *id = *c;
78 else *id = '_';
79
80 // Other characters: alphabetic, numeric, '_'.
81 // NOTE: ':' and '.' are NOT acceptable characters.
82 for (size_t i = 1; i < len; ++i)
83 {
84 ++id; ++c;
85 if ((*c >= 'a' && *c <= 'z') || (*c >= 'A' && *c <= 'Z') || (*c >= '0' && *c <= '9') || *c == '_' || *c == '-') *id = *c;
86 else *id = '_';
87 }
88 *(++id) = 0;
89 }
90 return cleanName;
91 }
92
SetName(const fstring & _name)93 void FCDEntity::SetName(const fstring& _name)
94 {
95 name = CleanName(_name.c_str());
96 SetDirtyFlag();
97 }
98
GetAsset()99 FCDAsset* FCDEntity::GetAsset()
100 {
101 return (asset != NULL) ? asset : (asset = new FCDAsset(GetDocument()));
102 }
103
GetHierarchicalAssets(FCDAssetConstList & assets) const104 void FCDEntity::GetHierarchicalAssets(FCDAssetConstList& assets) const
105 {
106 if (asset != NULL) assets.push_back(asset);
107 else assets.push_back(GetDocument()->GetAsset());
108 }
109
110 // Look for a children with the given COLLADA Id.
FindDaeId(const fm::string & _daeId) const111 const FCDEntity* FCDEntity::FindDaeId(const fm::string& _daeId) const
112 {
113 if (GetDaeId() == _daeId) return this;
114 return NULL;
115 }
116
HasNote() const117 bool FCDEntity::HasNote() const
118 {
119 return !note->empty();
120 }
121
GetNote() const122 const fstring& FCDEntity::GetNote() const
123 {
124 return *note;
125 }
126
SetNote(const fstring & _note)127 void FCDEntity::SetNote(const fstring& _note)
128 {
129 note = _note;
130 SetDirtyFlag();
131 }
132