MaterialX 1.39.2
Loading...
Searching...
No Matches
Document.h
Go to the documentation of this file.
1//
2// Copyright Contributors to the MaterialX Project
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#ifndef MATERIALX_DOCUMENT
7#define MATERIALX_DOCUMENT
8
11
13
14#include <MaterialXCore/Look.h>
15#include <MaterialXCore/Node.h>
16
17MATERIALX_NAMESPACE_BEGIN
18
19class Document;
20
22using DocumentPtr = shared_ptr<Document>;
24using ConstDocumentPtr = shared_ptr<const Document>;
25
31class MX_CORE_API Document : public GraphElement
32{
33 public:
34 Document(ElementPtr parent, const string& name);
35 virtual ~Document();
36
38 template <class T> static shared_ptr<T> createDocument()
39 {
40 shared_ptr<T> doc = std::make_shared<T>(ElementPtr(), EMPTY_STRING);
41 doc->initialize();
42 return doc;
43 }
44
46 virtual void initialize();
47
49 virtual DocumentPtr copy() const
50 {
52 doc->copyContentFrom(getSelf());
53 doc->setDataLibrary(getDataLibrary());
54 return doc;
55 }
56
59
62
65 {
66 _dataLibrary = dataLibrary;
67 }
68
70 bool hasDataLibrary() const
71 {
72 return (_dataLibrary != nullptr);
73 }
74
77 {
78 return _dataLibrary;
79 }
80
85 void importLibrary(const ConstDocumentPtr& library);
86
90
96 NodeGraphPtr addNodeGraph(const string& name = EMPTY_STRING)
97 {
98 return addChild<NodeGraph>(name);
99 }
100
102 NodeGraphPtr getNodeGraph(const string& name) const
103 {
104 return getChildOfType<NodeGraph>(name);
105 }
106
108 vector<NodeGraphPtr> getNodeGraphs() const
109 {
111 }
112
114 void removeNodeGraph(const string& name)
115 {
117 }
118
122 vector<PortElementPtr> getMatchingPorts(const string& nodeName) const;
123
127
134 GeomInfoPtr addGeomInfo(const string& name = EMPTY_STRING, const string& geom = UNIVERSAL_GEOM_NAME)
135 {
136 GeomInfoPtr geomInfo = addChild<GeomInfo>(name);
137 geomInfo->setGeom(geom);
138 return geomInfo;
139 }
140
142 GeomInfoPtr getGeomInfo(const string& name) const
143 {
144 return getChildOfType<GeomInfo>(name);
145 }
146
148 vector<GeomInfoPtr> getGeomInfos() const
149 {
151 }
152
154 void removeGeomInfo(const string& name)
155 {
157 }
158
160 ValuePtr getGeomPropValue(const string& geomPropName, const string& geom = UNIVERSAL_GEOM_NAME) const;
161
165
170 GeomPropDefPtr addGeomPropDef(const string& name, const string& geomprop)
171 {
172 GeomPropDefPtr geomPropDef = addChild<GeomPropDef>(name);
173 geomPropDef->setGeomProp(geomprop);
174 return geomPropDef;
175 }
176
178 GeomPropDefPtr getGeomPropDef(const string& name) const
179 {
180 return getChildOfType<GeomPropDef>(name);
181 }
182
184 vector<GeomPropDefPtr> getGeomPropDefs() const
185 {
187 }
188
190 void removeGeomPropDef(const string& name)
191 {
193 }
194
198
200 vector<OutputPtr> getMaterialOutputs() const;
201
205
211 LookPtr addLook(const string& name = EMPTY_STRING)
212 {
213 return addChild<Look>(name);
214 }
215
217 LookPtr getLook(const string& name) const
218 {
219 return getChildOfType<Look>(name);
220 }
221
223 vector<LookPtr> getLooks() const
224 {
226 }
227
229 void removeLook(const string& name)
230 {
232 }
233
237
243 LookGroupPtr addLookGroup(const string& name = EMPTY_STRING)
244 {
245 return addChild<LookGroup>(name);
246 }
247
249 LookGroupPtr getLookGroup(const string& name) const
250 {
251 return getChildOfType<LookGroup>(name);
252 }
253
255 vector<LookGroupPtr> getLookGroups() const
256 {
258 }
259
261 void removeLookGroup(const string& name)
262 {
264 }
265
269
275 CollectionPtr addCollection(const string& name = EMPTY_STRING)
276 {
277 return addChild<Collection>(name);
278 }
279
281 CollectionPtr getCollection(const string& name) const
282 {
283 return getChildOfType<Collection>(name);
284 }
285
287 vector<CollectionPtr> getCollections() const
288 {
290 }
291
293 void removeCollection(const string& name)
294 {
296 }
297
301
307 TypeDefPtr addTypeDef(const string& name)
308 {
309 return addChild<TypeDef>(name);
310 }
311
313 TypeDefPtr getTypeDef(const string& name) const
314 {
315 return getChildOfType<TypeDef>(name);
316 }
317
319 vector<TypeDefPtr> getTypeDefs() const
320 {
322 }
323
325 void removeTypeDef(const string& name)
326 {
328 }
329
333
343 NodeDefPtr addNodeDef(const string& name = EMPTY_STRING,
344 const string& type = DEFAULT_TYPE_STRING,
345 const string& node = EMPTY_STRING)
346 {
347 NodeDefPtr child = addChild<NodeDef>(name);
348 if (!type.empty() && type != MULTI_OUTPUT_TYPE_STRING)
349 {
350 child->addOutput("out", type);
351 }
352 if (!node.empty())
353 {
354 child->setNodeString(node);
355 }
356 return child;
357 }
358
365 NodeDefPtr addNodeDefFromGraph(NodeGraphPtr nodeGraph, const string& nodeDefName,
366 const string& category, const string& newGraphName);
367
369 NodeDefPtr getNodeDef(const string& name) const
370 {
371 return getChildOfType<NodeDef>(name);
372 }
373
375 vector<NodeDefPtr> getNodeDefs() const
376 {
378 }
379
381 void removeNodeDef(const string& name)
382 {
384 }
385
387 vector<NodeDefPtr> getMatchingNodeDefs(const string& nodeName) const;
388
392
398 AttributeDefPtr addAttributeDef(const string& name = EMPTY_STRING)
399 {
400 return addChild<AttributeDef>(name);
401 }
402
404 AttributeDefPtr getAttributeDef(const string& name) const
405 {
406 return getChildOfType<AttributeDef>(name);
407 }
408
410 vector<AttributeDefPtr> getAttributeDefs() const
411 {
413 }
414
416 void removeAttributeDef(const string& name)
417 {
419 }
420
424
430 TargetDefPtr addTargetDef(const string& name = EMPTY_STRING)
431 {
432 return addChild<TargetDef>(name);
433 }
434
436 TargetDefPtr getTargetDef(const string& name) const
437 {
438 return getChildOfType<TargetDef>(name);
439 }
440
442 vector<TargetDefPtr> getTargetDefs() const
443 {
445 }
446
448 void removeTargetDef(const string& name)
449 {
451 }
452
456
462 PropertySetPtr addPropertySet(const string& name = EMPTY_STRING)
463 {
464 return addChild<PropertySet>(name);
465 }
466
468 PropertySetPtr getPropertySet(const string& name) const
469 {
470 return getChildOfType<PropertySet>(name);
471 }
472
474 vector<PropertySetPtr> getPropertySets() const
475 {
477 }
478
480 void removePropertySet(const string& name)
481 {
483 }
484
488
494 VariantSetPtr addVariantSet(const string& name = EMPTY_STRING)
495 {
496 return addChild<VariantSet>(name);
497 }
498
500 VariantSetPtr getVariantSet(const string& name) const
501 {
502 return getChildOfType<VariantSet>(name);
503 }
504
506 vector<VariantSetPtr> getVariantSets() const
507 {
509 }
510
512 void removeVariantSet(const string& name)
513 {
515 }
516
520
526 ImplementationPtr addImplementation(const string& name = EMPTY_STRING)
527 {
528 return addChild<Implementation>(name);
529 }
530
532 ImplementationPtr getImplementation(const string& name) const
533 {
535 }
536
538 vector<ImplementationPtr> getImplementations() const
539 {
541 }
542
544 void removeImplementation(const string& name)
545 {
547 }
548
552 vector<InterfaceElementPtr> getMatchingImplementations(const string& nodeDef) const;
553
557
558 UnitDefPtr addUnitDef(const string& name)
559 {
560 if (name.empty())
561 {
562 throw Exception("A unit definition name cannot be empty");
563 }
564 return addChild<UnitDef>(name);
565 }
566
568 UnitDefPtr getUnitDef(const string& name) const
569 {
570 return getChildOfType<UnitDef>(name);
571 }
572
574 vector<UnitDefPtr> getUnitDefs() const
575 {
577 }
578
580 void removeUnitDef(const string& name)
581 {
583 }
584
588
589 UnitTypeDefPtr addUnitTypeDef(const string& name)
590 {
591 if (name.empty())
592 {
593 throw Exception("A unit type definition name cannot be empty");
594 }
595 return addChild<UnitTypeDef>(name);
596 }
597
599 UnitTypeDefPtr getUnitTypeDef(const string& name) const
600 {
601 return getChildOfType<UnitTypeDef>(name);
602 }
603
605 vector<UnitTypeDefPtr> getUnitTypeDefs() const
606 {
608 }
609
611 void removeUnitTypeDef(const string& name)
612 {
614 }
615
619
621 std::pair<int, int> getVersionIntegers() const override;
622
626
630
632 void setColorManagementSystem(const string& cms)
633 {
634 setAttribute(CMS_ATTRIBUTE, cms);
635 }
636
639 {
640 return hasAttribute(CMS_ATTRIBUTE);
641 }
642
644 const string& getColorManagementSystem() const
645 {
646 return getAttribute(CMS_ATTRIBUTE);
647 }
648
652
654 void setColorManagementConfig(const string& cmsConfig)
655 {
656 setAttribute(CMS_CONFIG_ATTRIBUTE, cmsConfig);
657 }
658
661 {
662 return hasAttribute(CMS_CONFIG_ATTRIBUTE);
663 }
664
666 const string& getColorManagementConfig() const
667 {
668 return getAttribute(CMS_CONFIG_ATTRIBUTE);
669 }
670
674
680 bool validate(string* message = nullptr) const override;
681
685
688
690
691 //
692 // These are deprecated wrappers for older versions of the function interfaces in this module.
693 // Clients using these interfaces should update them to the latest API.
694 //
695 [[deprecated]] NodeDefPtr addNodeDefFromGraph(NodeGraphPtr nodeGraph, const string& nodeDefName, const string& node, const string& version,
696 bool isDefaultVersion, const string& nodeGroup, const string& newGraphName);
697
698 public:
699 static const string CATEGORY;
700 static const string CMS_ATTRIBUTE;
701 static const string CMS_CONFIG_ATTRIBUTE;
702
703 private:
704 class Cache;
705
706 private:
707 ConstDocumentPtr _dataLibrary;
708 std::unique_ptr<Cache> _cache;
709};
710
713MX_CORE_API DocumentPtr createDocument();
714
715MATERIALX_NAMESPACE_END
716
717#endif
shared_ptr< TargetDef > TargetDefPtr
A shared pointer to a TargetDef.
Definition Definition.h:47
shared_ptr< UnitDef > UnitDefPtr
A shared pointer to a UnitDef.
Definition Definition.h:62
shared_ptr< Implementation > ImplementationPtr
A shared pointer to an Implementation.
Definition Definition.h:37
shared_ptr< AttributeDef > AttributeDefPtr
A shared pointer to an AttributeDef.
Definition Definition.h:72
shared_ptr< UnitTypeDef > UnitTypeDefPtr
A shared pointer to a UnitTypeDef.
Definition Definition.h:67
shared_ptr< const Document > ConstDocumentPtr
A shared pointer to a const Document.
Definition Document.h:24
shared_ptr< Document > DocumentPtr
A shared pointer to a Document.
Definition Document.h:22
shared_ptr< Element > ElementPtr
A shared pointer to an Element.
Definition Element.h:31
shared_ptr< GeomInfo > GeomInfoPtr
A shared pointer to a GeomInfo.
Definition Geom.h:38
shared_ptr< Collection > CollectionPtr
A shared pointer to a Collection.
Definition Geom.h:53
shared_ptr< GeomPropDef > GeomPropDefPtr
A shared pointer to a GeomPropDef.
Definition Geom.h:48
Look element subclasses.
shared_ptr< LookGroup > LookGroupPtr
A shared pointer to a LookGroup.
Definition Look.h:32
shared_ptr< Look > LookPtr
A shared pointer to a Look.
Definition Look.h:27
Import and export declarations for the Core library.
std::set< string > StringSet
A set of strings.
Definition Library.h:64
Node element subclasses.
shared_ptr< NodeGraph > NodeGraphPtr
A shared pointer to a NodeGraph.
Definition Node.h:34
shared_ptr< PropertySet > PropertySetPtr
A shared pointer to a PropertySet.
Definition Property.h:34
shared_ptr< Value > ValuePtr
A shared pointer to a Value.
Definition Value.h:30
shared_ptr< VariantSet > VariantSetPtr
A shared pointer to a VariantSet.
Definition Variant.h:28
A MaterialX document, which represents the top-level element in the MaterialX ownership hierarchy.
Definition Document.h:32
vector< PropertySetPtr > getPropertySets() const
Return a vector of all PropertySet elements in the document.
Definition Document.h:474
TargetDefPtr addTargetDef(const string &name=EMPTY_STRING)
Add an TargetDef to the document.
Definition Document.h:430
void removeLookGroup(const string &name)
Remove the LookGroup, if any, with the given name.
Definition Document.h:261
void removeNodeDef(const string &name)
Remove the NodeDef, if any, with the given name.
Definition Document.h:381
vector< LookPtr > getLooks() const
Return a vector of all Look elements in the document.
Definition Document.h:223
void removeUnitTypeDef(const string &name)
Remove the UnitTypeDef, if any, with the given name.
Definition Document.h:611
void removeVariantSet(const string &name)
Remove the VariantSet, if any, with the given name.
Definition Document.h:512
vector< UnitTypeDefPtr > getUnitTypeDefs() const
Return a vector of all UnitTypeDef elements in the document.
Definition Document.h:605
AttributeDefPtr addAttributeDef(const string &name=EMPTY_STRING)
Add an AttributeDef to the document.
Definition Document.h:398
GeomInfoPtr getGeomInfo(const string &name) const
Return the GeomInfo, if any, with the given name.
Definition Document.h:142
vector< InterfaceElementPtr > getMatchingImplementations(const string &nodeDef) const
Return a vector of all node implementations that match the given NodeDef string.
GeomPropDefPtr getGeomPropDef(const string &name) const
Return the GeomPropDef, if any, with the given name.
Definition Document.h:178
TargetDefPtr getTargetDef(const string &name) const
Return the AttributeDef, if any, with the given name.
Definition Document.h:436
ImplementationPtr getImplementation(const string &name) const
Return the Implementation, if any, with the given name.
Definition Document.h:532
UnitTypeDefPtr getUnitTypeDef(const string &name) const
Return the UnitTypeDef, if any, with the given name.
Definition Document.h:599
void setColorManagementSystem(const string &cms)
Set the color management system string.
Definition Document.h:632
vector< PortElementPtr > getMatchingPorts(const string &nodeName) const
Return a vector of all port elements that match the given node name.
void removeImplementation(const string &name)
Remove the Implementation, if any, with the given name.
Definition Document.h:544
void removeNodeGraph(const string &name)
Remove the NodeGraph, if any, with the given name.
Definition Document.h:114
bool hasColorManagementSystem() const
Return true if a color management system string has been set.
Definition Document.h:638
TypeDefPtr getTypeDef(const string &name) const
Return the TypeDef, if any, with the given name.
Definition Document.h:313
vector< NodeDefPtr > getMatchingNodeDefs(const string &nodeName) const
Return a vector of all NodeDef elements that match the given node name.
CollectionPtr addCollection(const string &name=EMPTY_STRING)
Add a Collection to the document.
Definition Document.h:275
vector< ImplementationPtr > getImplementations() const
Return a vector of all Implementation elements in the document.
Definition Document.h:538
vector< TypeDefPtr > getTypeDefs() const
Return a vector of all TypeDef elements in the document.
Definition Document.h:319
const string & getColorManagementConfig() const
Return the color management config string.
Definition Document.h:666
bool validate(string *message=nullptr) const override
Validate that the given document is consistent with the MaterialX specification.
void removeGeomInfo(const string &name)
Remove the GeomInfo, if any, with the given name.
Definition Document.h:154
vector< NodeGraphPtr > getNodeGraphs() const
Return a vector of all NodeGraph elements in the document.
Definition Document.h:108
NodeDefPtr addNodeDefFromGraph(NodeGraphPtr nodeGraph, const string &nodeDefName, const string &category, const string &newGraphName)
Create a NodeDef and Functional Graph based on a Compound NodeGraph.
vector< UnitDefPtr > getUnitDefs() const
Return a vector of all Member elements in the TypeDef.
Definition Document.h:574
CollectionPtr getCollection(const string &name) const
Return the Collection, if any, with the given name.
Definition Document.h:281
void removeTypeDef(const string &name)
Remove the TypeDef, if any, with the given name.
Definition Document.h:325
static shared_ptr< T > createDocument()
Create a new document of the given subclass.
Definition Document.h:38
bool hasColorManagementConfig() const
Return true if a color management config string has been set.
Definition Document.h:660
vector< TargetDefPtr > getTargetDefs() const
Return a vector of all TargetDef elements in the document.
Definition Document.h:442
GeomPropDefPtr addGeomPropDef(const string &name, const string &geomprop)
Add a GeomPropDef to the document.
Definition Document.h:170
StringSet getReferencedSourceUris() const
Get a list of source URIs referenced by the document.
LookGroupPtr addLookGroup(const string &name=EMPTY_STRING)
Add a LookGroup to the document.
Definition Document.h:243
virtual void initialize()
Initialize the document, removing any existing content.
ConstDocumentPtr getDataLibrary() const
Return the data library, if any, referenced by this document.
Definition Document.h:76
void setColorManagementConfig(const string &cmsConfig)
Set the color management config string.
Definition Document.h:654
void removeTargetDef(const string &name)
Remove the TargetDef, if any, with the given name.
Definition Document.h:448
GeomInfoPtr addGeomInfo(const string &name=EMPTY_STRING, const string &geom=UNIVERSAL_GEOM_NAME)
Add a GeomInfo to the document.
Definition Document.h:134
NodeGraphPtr getNodeGraph(const string &name) const
Return the NodeGraph, if any, with the given name.
Definition Document.h:102
LookPtr addLook(const string &name=EMPTY_STRING)
Add a Look to the document.
Definition Document.h:211
vector< AttributeDefPtr > getAttributeDefs() const
Return a vector of all AttributeDef elements in the document.
Definition Document.h:410
UnitDefPtr getUnitDef(const string &name) const
Return the UnitDef, if any, with the given name.
Definition Document.h:568
void removeLook(const string &name)
Remove the Look, if any, with the given name.
Definition Document.h:229
vector< GeomInfoPtr > getGeomInfos() const
Return a vector of all GeomInfo elements in the document.
Definition Document.h:148
NodeGraphPtr addNodeGraph(const string &name=EMPTY_STRING)
Add a NodeGraph to the document.
Definition Document.h:96
NodeDefPtr addNodeDef(const string &name=EMPTY_STRING, const string &type=DEFAULT_TYPE_STRING, const string &node=EMPTY_STRING)
Add a NodeDef to the document.
Definition Document.h:343
vector< VariantSetPtr > getVariantSets() const
Return a vector of all VariantSet elements in the document.
Definition Document.h:506
VariantSetPtr addVariantSet(const string &name=EMPTY_STRING)
Add a VariantSet to the document.
Definition Document.h:494
NodeDefPtr getNodeDef(const string &name) const
Return the NodeDef, if any, with the given name.
Definition Document.h:369
void upgradeVersion()
Upgrade the content of this document from earlier supported versions to the library version.
AttributeDefPtr getAttributeDef(const string &name) const
Return the AttributeDef, if any, with the given name.
Definition Document.h:404
std::pair< int, int > getVersionIntegers() const override
Return the major and minor versions as an integer pair.
vector< OutputPtr > getMaterialOutputs() const
Return material-type outputs for all nodegraphs in the document.
ImplementationPtr addImplementation(const string &name=EMPTY_STRING)
Add an Implementation to the document.
Definition Document.h:526
void removeAttributeDef(const string &name)
Remove the AttributeDef, if any, with the given name.
Definition Document.h:416
vector< CollectionPtr > getCollections() const
Return a vector of all Collection elements in the document.
Definition Document.h:287
virtual DocumentPtr copy() const
Create a deep copy of the document.
Definition Document.h:49
vector< LookGroupPtr > getLookGroups() const
Return a vector of all LookGroup elements in the document.
Definition Document.h:255
LookGroupPtr getLookGroup(const string &name) const
Return the LookGroup, if any, with the given name.
Definition Document.h:249
PropertySetPtr getPropertySet(const string &name) const
Return the PropertySet, if any, with the given name.
Definition Document.h:468
bool hasDataLibrary() const
Return true if this document has a data library.
Definition Document.h:70
const string & getColorManagementSystem() const
Return the color management system string.
Definition Document.h:644
LookPtr getLook(const string &name) const
Return the Look, if any, with the given name.
Definition Document.h:217
void importLibrary(const ConstDocumentPtr &library)
Import the given data library into this document.
VariantSetPtr getVariantSet(const string &name) const
Return the VariantSet, if any, with the given name.
Definition Document.h:500
void invalidateCache()
Invalidate cached data for optimized lookups within the given document.
vector< GeomPropDefPtr > getGeomPropDefs() const
Return a vector of all GeomPropDef elements in the document.
Definition Document.h:184
void removeCollection(const string &name)
Remove the Collection, if any, with the given name.
Definition Document.h:293
void setDataLibrary(ConstDocumentPtr dataLibrary)
Store a reference to a data library in this document.
Definition Document.h:64
void removeGeomPropDef(const string &name)
Remove the GeomPropDef, if any, with the given name.
Definition Document.h:190
void removeUnitDef(const string &name)
Remove the UnitDef, if any, with the given name.
Definition Document.h:580
vector< NodeDefPtr > getNodeDefs() const
Return a vector of all NodeDef elements in the document.
Definition Document.h:375
TypeDefPtr addTypeDef(const string &name)
Add a TypeDef to the document.
Definition Document.h:307
PropertySetPtr addPropertySet(const string &name=EMPTY_STRING)
Add a PropertySet to the document.
Definition Document.h:462
void removePropertySet(const string &name)
Remove the PropertySet, if any, with the given name.
Definition Document.h:480
ValuePtr getGeomPropValue(const string &geomPropName, const string &geom=UNIVERSAL_GEOM_NAME) const
Return the value of a geometric property for the given geometry string.
const string & getAttribute(const string &attrib) const
Return the value string of the given attribute.
Definition Element.h:489
shared_ptr< T > addChild(const string &name=EMPTY_STRING)
Add a child element of the given subclass and name.
Definition Element.h:1399
void setAttribute(const string &attrib, const string &value)
Set the value string of the given attribute.
shared_ptr< T > getChildOfType(const string &name) const
Return the child element, if any, with the given name and subclass.
ElementPtr getSelf()
Return our self pointer.
Definition Element.h:535
bool hasAttribute(const string &attrib) const
Return true if the given attribute is present.
Definition Element.h:482
void removeChildOfType(const string &name)
Remove the child element, if any, with the given name and subclass.
Definition Element.h:468
vector< shared_ptr< T > > getChildrenOfType(const string &category=EMPTY_STRING) const
Return a vector of all child elements that are instances of the given subclass, optionally filtered b...
The base class for exceptions that are propagated from the MaterialX library to the client applicatio...
Definition Exception.h:22