6#ifndef MATERIALX_INTERFACE_H
7#define MATERIALX_INTERFACE_H
16MATERIALX_NAMESPACE_BEGIN
45using CharSet = std::set<char>;
63 using NodePtr = shared_ptr<Node>;
64 using ConstNodePtr = shared_ptr<const Node>;
132 virtual OutputPtr getConnectedOutput()
const;
165 static bool validChannelsCharacters(
const string& channels,
const string& sourceType);
169 static bool validChannelsString(
const string& channels,
const string& sourceType,
const string& destinationType);
181 virtual NodePtr getConnectedNode()
const;
189 bool validate(
string* message =
nullptr)
const override;
194 static const string NODE_NAME_ATTRIBUTE;
195 static const string NODE_GRAPH_ATTRIBUTE;
196 static const string OUTPUT_ATTRIBUTE;
197 static const string CHANNELS_ATTRIBUTE;
200 static const std::unordered_map<string, CharSet> CHANNELS_CHARACTER_SET;
201 static const std::unordered_map<string, size_t> CHANNELS_PATTERN_LENGTH;
248 NodePtr getConnectedNode()
const override;
260 bool validate(
string* message =
nullptr)
const override;
265 static const string CATEGORY;
266 static const string DEFAULT_GEOM_PROP_ATTRIBUTE;
295 bool hasUpstreamCycle()
const;
303 bool validate(
string* message =
nullptr)
const override;
308 static const string CATEGORY;
309 static const string DEFAULT_INPUT_ATTRIBUTE;
331 using NodeDefPtr = shared_ptr<NodeDef>;
332 using ConstNodeDefPtr = shared_ptr<const NodeDef>;
367 const string& type = DEFAULT_TYPE_STRING)
369 InputPtr child = addChild<Input>(name);
370 child->setType(type);
377 return getChildOfType<Input>(name);
383 return getChildrenOfType<Input>();
395 removeChildOfType<Input>(name);
400 InputPtr getActiveInput(
const string& name)
const;
404 vector<InputPtr> getActiveInputs()
const;
417 const string& type = DEFAULT_TYPE_STRING)
419 OutputPtr output = addChild<Output>(name);
420 output->setType(type);
427 return getChildOfType<Output>(name);
433 return getChildrenOfType<Output>();
445 removeChildOfType<Output>(name);
450 OutputPtr getActiveOutput(
const string& name)
const;
454 vector<OutputPtr> getActiveOutputs()
const;
459 void setConnectedOutput(
const string& inputName,
OutputPtr output);
463 OutputPtr getConnectedOutput(
const string& inputName)
const;
476 return addChild<Token>(name);
482 return getChildOfType<Token>(name);
488 return getChildrenOfType<Token>();
494 removeChildOfType<Token>(name);
499 TokenPtr getActiveToken(
const string& name)
const;
503 vector<TokenPtr> getActiveTokens()
const;
512 return getChildOfType<ValueElement>(name);
523 vector<ValueElementPtr> getActiveValueElements()
const;
531 template <
class T>
InputPtr setInputValue(
const string& name,
533 const string& type = EMPTY_STRING);
543 ValuePtr getInputValue(
const string& name,
const string& target = EMPTY_STRING)
const;
551 token = addToken(name);
552 token->setValue<
string>(value);
561 return token ? token->getValueString() : EMPTY_STRING;
609 void setVersionIntegers(
int majorVersion,
int minorVersion);
612 virtual std::pair<int, int> getVersionIntegers()
const;
621 setTypedAttribute<bool>(DEFAULT_VERSION_ATTRIBUTE, defaultVersion);
627 return getTypedAttribute<bool>(DEFAULT_VERSION_ATTRIBUTE);
656 static const string NODE_DEF_ATTRIBUTE;
657 static const string TARGET_ATTRIBUTE;
658 static const string VERSION_ATTRIBUTE;
659 static const string DEFAULT_VERSION_ATTRIBUTE;
662 void registerChildElement(
ElementPtr child)
override;
663 void unregisterChildElement(
ElementPtr child)
override;
674 InputPtr input = getChildOfType<Input>(name);
677 input->setValue(value, type);
681MATERIALX_NAMESPACE_END
shared_ptr< Token > TokenPtr
A shared pointer to a Token.
Definition: Element.h:46
shared_ptr< Element > ElementPtr
A shared pointer to an Element.
Definition: Element.h:31
shared_ptr< ValueElement > ValueElementPtr
A shared pointer to a ValueElement.
Definition: Element.h:41
Geometric element subclasses.
shared_ptr< GeomPropDef > GeomPropDefPtr
A shared pointer to a GeomPropDef.
Definition: Geom.h:48
shared_ptr< const PortElement > ConstPortElementPtr
A shared pointer to a const PortElement.
Definition: Interface.h:28
shared_ptr< const Output > ConstOutputPtr
A shared pointer to a const Output.
Definition: Interface.h:38
shared_ptr< InterfaceElement > InterfaceElementPtr
A shared pointer to an InterfaceElement.
Definition: Interface.h:41
shared_ptr< PortElement > PortElementPtr
A shared pointer to a PortElement.
Definition: Interface.h:26
shared_ptr< const InterfaceElement > ConstInterfaceElementPtr
A shared pointer to a const InterfaceElement.
Definition: Interface.h:43
shared_ptr< const Input > ConstInputPtr
A shared pointer to a const Input.
Definition: Interface.h:33
shared_ptr< Input > InputPtr
A shared pointer to an Input.
Definition: Interface.h:31
shared_ptr< Output > OutputPtr
A shared pointer to an Output.
Definition: Interface.h:36
Import and export declarations for the Core library.
shared_ptr< const Node > ConstNodePtr
A shared pointer to a const Node.
Definition: Node.h:26
shared_ptr< Node > NodePtr
A shared pointer to a Node.
Definition: Node.h:24
shared_ptr< Value > ValuePtr
A shared pointer to a Value.
Definition: Value.h:29
An edge between two connected Elements, returned during graph traversal.
Definition: Traversal.h:30
virtual void clearContent()
Clear all attributes and descendants from this element.
Definition: Element.cpp:385
const string & getAttribute(const string &attrib) const
Return the value string of the given attribute.
Definition: Element.h:504
void setAttribute(const string &attrib, const string &value)
Set the value string of the given attribute.
Definition: Element.cpp:191
virtual Edge getUpstreamEdge(size_t index=0) const
Return the Edge with the given index that lies directly upstream from this element in the dataflow gr...
Definition: Element.cpp:345
bool hasAttribute(const string &attrib) const
Return true if the given attribute is present.
Definition: Element.h:497
The base class for interface elements such as Node, NodeDef, and NodeGraph.
Definition: Interface.h:318
OutputPtr addOutput(const string &name=EMPTY_STRING, const string &type=DEFAULT_TYPE_STRING)
Add an Output to this interface.
Definition: Interface.h:416
OutputPtr getOutput(const string &name) const
Return the Output, if any, with the given name.
Definition: Interface.h:425
bool hasNodeDefString() const
Return true if the given interface has a NodeDef string.
Definition: Interface.h:345
TokenPtr getToken(const string &name) const
Return the Token, if any, with the given name.
Definition: Interface.h:480
vector< InputPtr > getInputs() const
Return a vector of all Input elements.
Definition: Interface.h:381
InputPtr addInput(const string &name=EMPTY_STRING, const string &type=DEFAULT_TYPE_STRING)
Add an Input to this interface.
Definition: Interface.h:366
size_t getInputCount() const
Return the number of Input elements.
Definition: Interface.h:387
void removeInput(const string &name)
Remove the Input, if any, with the given name.
Definition: Interface.h:393
void setVersionString(const string &version)
Set the version string of this interface.
Definition: Interface.h:591
vector< TokenPtr > getTokens() const
Return a vector of all Token elements.
Definition: Interface.h:486
InputPtr getInput(const string &name) const
Return the Input, if any, with the given name.
Definition: Interface.h:375
const string & getVersionString() const
Return the version string of this interface.
Definition: Interface.h:603
ValueElementPtr getValueElement(const string &name) const
Return the ValueElement, if any, with the given name.
Definition: Interface.h:510
TokenPtr setTokenValue(const string &name, const string &value)
Set the string value of a Token by its name, creating a child element to hold the Token if needed.
Definition: Interface.h:547
InputPtr setInputValue(const string &name, const T &value, const string &type=EMPTY_STRING)
Set the typed value of an input by its name, creating a child element to hold the input if needed.
Definition: Interface.h:670
TokenPtr addToken(const string &name=EMPTY_STRING)
Add a Token to this interface.
Definition: Interface.h:474
void setNodeDefString(const string &nodeDef)
Set the NodeDef string for the interface.
Definition: Interface.h:339
vector< OutputPtr > getOutputs() const
Return a vector of all Output elements.
Definition: Interface.h:431
string getTokenValue(const string &name)
Return the string value of a Token by its name, or an empty string if the given Token is not present.
Definition: Interface.h:558
bool hasVersionString() const
Return true if this interface has a version string.
Definition: Interface.h:597
bool getDefaultVersion() const
Return the default version flag of this element.
Definition: Interface.h:625
const string & getNodeDefString() const
Return the NodeDef string for the interface.
Definition: Interface.h:351
void removeToken(const string &name)
Remove the Token, if any, with the given name.
Definition: Interface.h:492
void removeOutput(const string &name)
Remove the Output, if any, with the given name.
Definition: Interface.h:443
void setTarget(const string &target)
Set the target string of this interface.
Definition: Interface.h:569
void setDefaultVersion(bool defaultVersion)
Set the default version flag of this element.
Definition: Interface.h:619
bool hasTarget() const
Return true if the given interface has a target string.
Definition: Interface.h:575
size_t getOutputCount() const
Return the number of Output elements.
Definition: Interface.h:437
const string & getTarget() const
Return the target string of this interface.
Definition: Interface.h:581
A node definition element within a Document.
Definition: Definition.h:82
A node element within a NodeGraph or Document.
Definition: Node.h:53
A spatially-varying output element within a NodeGraph or NodeDef.
Definition: Interface.h:272
size_t getUpstreamEdgeCount() const override
Return the number of queriable upstream edges for this element.
Definition: Interface.h:289
The base class for port elements such as Input and Output.
Definition: Interface.h:52
bool hasOutputString() const
Return true if this element has an output string.
Definition: Interface.h:122
const string & getNodeGraphString() const
Return the node graph string of this element.
Definition: Interface.h:106
void setChannels(const string &channels)
Set the channels string of this element, defining a channel swizzle that will be applied to the upstr...
Definition: Interface.h:146
const string & getOutputString() const
Return the output string of this element.
Definition: Interface.h:135
bool hasChannels() const
Return true if this element has a channels string.
Definition: Interface.h:152
void setNodeGraphString(const string &node)
Set the node graph string of this element.
Definition: Interface.h:94
bool hasNodeGraphString() const
Return true if this element has a node graph string.
Definition: Interface.h:100
void setNodeName(const string &node)
Set the node name string of this element, creating a connection to the Node with the given name withi...
Definition: Interface.h:72
void setOutputString(const string &output)
Set the output string of this element.
Definition: Interface.h:116
const string & getChannels() const
Return the channels string of this element.
Definition: Interface.h:158
const string & getNodeName() const
Return the node name string of this element.
Definition: Interface.h:84
bool hasNodeName() const
Return true if this element has a node name string.
Definition: Interface.h:78
The base class for typed elements.
Definition: Element.h:837
The base class for elements that support typed values.
Definition: Element.h:895
bool validate(string *message=nullptr) const override
Validate that the given element tree, including all descendants, is consistent with the MaterialX spe...
Definition: Element.cpp:535