11 #ifndef smtk_io_ItemDefinitionsHelper_h
12 #define smtk_io_ItemDefinitionsHelper_h
14 #include "smtk/io/XmlDocV1Parser.h"
16 #include "smtk/attribute/ComponentItemDefinition.h"
17 #include "smtk/attribute/CustomItemDefinition.h"
18 #include "smtk/attribute/DateTimeItemDefinition.h"
19 #include "smtk/attribute/DirectoryItemDefinition.h"
20 #include "smtk/attribute/DoubleItemDefinition.h"
21 #include "smtk/attribute/FileItemDefinition.h"
23 #include "smtk/attribute/IntItemDefinition.h"
24 #include "smtk/attribute/Item.h"
25 #include "smtk/attribute/ItemDefinition.h"
26 #include "smtk/attribute/ReferenceItemDefinition.h"
27 #include "smtk/attribute/Resource.h"
28 #include "smtk/attribute/ResourceItemDefinition.h"
29 #include "smtk/attribute/StringItemDefinition.h"
30 #include "smtk/attribute/ValueItemDefinition.h"
31 #include "smtk/attribute/VoidItemDefinition.h"
56 template<
typename DefType>
59 pugi::xml_node& itemsNode,
61 const std::string& defName,
62 const std::string& attType)
64 std::string itemName, nodeName;
68 for (node = itemsNode.first_child(); node; node = node.next_sibling())
70 pugi::xml_attribute xatt = node.attribute(
"Name");
76 "Item Definition of " << attType <<
": " << defName <<
" is missing Name attribute");
80 itemName = xatt.value();
81 nodeName = node.
name();
83 if ((nodeName ==
"Block") || (nodeName ==
"Template"))
85 pugi::xml_node instancedTemplateNode;
88 this->processItemDefinitions<DefType>(
89 parser, instancedTemplateNode, def, defName, attType);
95 itype = attribute::Item::string2Type(nodeName);
101 def->template addItemDefinition<attribute::ComponentItemDefinition>(itemName);
106 "Failed to create Ref Item definition Type: " << node.
name() <<
" needed to create "
107 << attType <<
": " << defName);
110 parser->processRefDef(node, itemdef);
113 case attribute::Item::ComponentType:
116 def->template addItemDefinition<attribute::ComponentItemDefinition>(itemName);
121 "Failed to create Component Item definition Type: "
122 << node.
name() <<
" needed to create " << attType <<
": " << defName);
125 parser->processComponentDef(node, itemdef);
128 case attribute::Item::DateTimeType:
131 def->template addItemDefinition<attribute::DateTimeItemDefinition>(itemName);
136 "Failed to create DateTime Item definition Type: "
137 << node.
name() <<
" needed to create " << attType <<
": " << defName);
140 parser->processDateTimeDef(node, itemdef);
143 case attribute::Item::DirectoryType:
146 def->template addItemDefinition<attribute::DirectoryItemDefinition>(itemName);
151 "Failed to create Directory Item definition Type: "
152 << node.
name() <<
" needed to create " << attType <<
": " << defName);
155 parser->processDirectoryDef(node, itemdef);
158 case attribute::Item::DoubleType:
160 auto itemdef = def->template addItemDefinition<attribute::DoubleItemDefinition>(itemName);
165 "Failed to create Double Item definition Type: "
166 << node.
name() <<
" needed to create " << attType <<
": " << defName);
169 parser->processDoubleDef(node, itemdef);
172 case attribute::Item::FileType:
174 auto itemdef = def->template addItemDefinition<attribute::FileItemDefinition>(itemName);
179 "Failed to create File Item definition Type: " << node.
name() <<
" needed to create "
180 << attType <<
": " << defName);
183 parser->processFileDef(node, itemdef);
186 case attribute::Item::GroupType:
188 auto itemdef = def->template addItemDefinition<attribute::GroupItemDefinition>(itemName);
193 "Failed to create Group Item definition Type: " << node.
name() <<
" needed to create "
194 << attType <<
": " << defName);
197 parser->processGroupDef(node, itemdef);
200 case attribute::Item::IntType:
202 auto itemdef = def->template addItemDefinition<attribute::IntItemDefinition>(itemName);
207 "Failed to create Int Item definition Type: " << node.
name() <<
" needed to create "
208 << attType <<
": " << defName);
211 parser->processIntDef(node, itemdef);
217 def->template addItemDefinition<attribute::ComponentItemDefinition>(itemName);
222 "Failed to create MeshEntity Item definition Type: "
223 << node.
name() <<
" needed to create " << attType <<
": " << defName);
226 parser->processMeshEntityDef(node, itemdef);
229 case attribute::Item::ModelEntityType:
232 def->template addItemDefinition<attribute::ComponentItemDefinition>(itemName);
237 "Failed to create ModelEntity Item definition Type: "
238 << node.
name() <<
" needed to create " << attType <<
": " << defName);
241 parser->processModelEntityDef(node, itemdef);
244 case attribute::Item::ReferenceType:
247 def->template addItemDefinition<attribute::ReferenceItemDefinition>(itemName);
252 "Failed to create Reference Item definition Type: "
253 << node.
name() <<
" needed to create " << attType <<
": " << defName);
256 parser->processReferenceDef(node, itemdef);
259 case attribute::Item::ResourceType:
262 def->template addItemDefinition<attribute::ResourceItemDefinition>(itemName);
267 "Failed to create Resource Item definition Type: "
268 << node.
name() <<
" needed to create " << attType <<
": " << defName);
271 parser->processResourceDef(node, itemdef);
274 case attribute::Item::StringType:
276 auto itemdef = def->template addItemDefinition<attribute::StringItemDefinition>(itemName);
281 "Failed to create String Item definition Type: "
282 << node.
name() <<
" needed to create " << attType <<
": " << defName);
285 parser->processStringDef(node, itemdef);
288 case attribute::Item::VoidType:
290 auto itemdef = def->template addItemDefinition<attribute::VoidItemDefinition>(itemName);
295 "Failed to create Void Item definition Type: " << node.
name() <<
" needed to create "
296 << attType <<
": " << defName);
299 parser->processItemDef(node, itemdef);
304 auto typeName = node.attribute(
"TypeName");
307 parser->m_resource->customItemDefinitionFactory().contains(
typeName.value()))
309 idef = parser->m_resource->customItemDefinitionFactory().createFromName(
310 typeName.value(), std::string(node.attribute(
"Name").value()));
312 def->addItemDefinition(idef);
313 parser->processItemDef(node, idef);
319 "Unsupported Item definition Type: " << node.
name() <<
" needed to create " << attType