6#ifndef MATERIALX_INTERFACE_H
7#define MATERIALX_INTERFACE_H
16MATERIALX_NAMESPACE_BEGIN
45using CharSet = std::set<char>;
51class MX_CORE_API PortElement :
public ValueElement
54 PortElement(
ElementPtr parent,
const string& category,
const string& name) :
55 ValueElement(parent, category, name)
60 virtual ~PortElement() { }
63 using NodePtr = shared_ptr<Node>;
64 using ConstNodePtr = shared_ptr<const Node>;
158 bool validate(
string* message =
nullptr)
const override;
163 static const string NODE_NAME_ATTRIBUTE;
164 static const string NODE_GRAPH_ATTRIBUTE;
165 static const string OUTPUT_ATTRIBUTE;
173class MX_CORE_API Input :
public PortElement
176 Input(
ElementPtr parent,
const string& name) :
177 PortElement(parent, CATEGORY, name)
239 void setHint(
const string& hint)
250 bool validate(
string* message =
nullptr)
const override;
255 static const string CATEGORY;
256 static const string DEFAULT_GEOM_PROP_ATTRIBUTE;
257 static const string HINT_ATTRIBUTE;
258 static const string TRANSPARENCY_HINT;
259 static const string OPACITY_HINT;
260 static const string ANISOTROPY_HINT;
265class MX_CORE_API Output :
public PortElement
268 Output(
ElementPtr parent,
const string& name) :
269 PortElement(parent, CATEGORY, name)
272 virtual ~Output() { }
297 bool validate(
string* message =
nullptr)
const override;
302 static const string CATEGORY;
303 static const string DEFAULT_INPUT_ATTRIBUTE;
311class MX_CORE_API InterfaceElement :
public TypedElement
314 InterfaceElement(
ElementPtr parent,
const string& category,
const string& name) :
315 TypedElement(parent, category, name),
322 virtual ~InterfaceElement() { }
325 using NodeDefPtr = shared_ptr<NodeDef>;
326 using ConstNodeDefPtr = shared_ptr<const NodeDef>;
361 const string& type = DEFAULT_TYPE_STRING)
364 child->setType(type);
411 const string& type = DEFAULT_TYPE_STRING)
414 output->setType(type);
527 const string& type = EMPTY_STRING);
546 token->setValue<
string>(value);
555 return token ? token->getValueString() : EMPTY_STRING;
650 static const string NODE_DEF_ATTRIBUTE;
651 static const string TARGET_ATTRIBUTE;
652 static const string VERSION_ATTRIBUTE;
653 static const string DEFAULT_VERSION_ATTRIBUTE;
656 void registerChildElement(
ElementPtr child)
override;
657 void unregisterChildElement(
ElementPtr child)
override;
671 input->setValue(value, type);
675MATERIALX_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< Value > ValuePtr
A shared pointer to a Value.
Definition Value.h:30
An edge between two connected Elements, returned during graph traversal.
Definition Traversal.h:30
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.
void setTypedAttribute(const string &attrib, const T &data)
Set the value of an implicitly typed attribute.
Definition Element.h:504
T getTypedAttribute(const string &attrib) const
Return the value of an implicitly typed attribute.
Definition Element.h:512
shared_ptr< T > getChildOfType(const string &name) const
Return the child element, if any, with the given name and subclass.
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 interface elements such as Node, NodeDef, and NodeGraph.
Definition Interface.h:312
OutputPtr addOutput(const string &name=EMPTY_STRING, const string &type=DEFAULT_TYPE_STRING)
Add an Output to this interface.
Definition Interface.h:410
ValuePtr getInputValue(const string &name, const string &target=EMPTY_STRING) const
Return the typed value of an input by its name, taking both the calling element and its declaration i...
OutputPtr getOutput(const string &name) const
Return the Output, if any, with the given name.
Definition Interface.h:419
bool hasNodeDefString() const
Return true if the given interface has a NodeDef string.
Definition Interface.h:339
TokenPtr getToken(const string &name) const
Return the Token, if any, with the given name.
Definition Interface.h:474
vector< InputPtr > getInputs() const
Return a vector of all Input elements.
Definition Interface.h:375
InputPtr addInput(const string &name=EMPTY_STRING, const string &type=DEFAULT_TYPE_STRING)
Add an Input to this interface.
Definition Interface.h:360
size_t getInputCount() const
Return the number of Input elements.
Definition Interface.h:381
void removeInput(const string &name)
Remove the Input, if any, with the given name.
Definition Interface.h:387
void setVersionString(const string &version)
Set the version string of this interface.
Definition Interface.h:585
virtual std::pair< int, int > getVersionIntegers() const
Return the major and minor versions as an integer pair.
vector< TokenPtr > getTokens() const
Return a vector of all Token elements.
Definition Interface.h:480
vector< ValueElementPtr > getActiveValueElements() const
Return a vector of all value elements that belong to this interface, taking inheritance into account.
InputPtr getInput(const string &name) const
Return the Input, if any, with the given name.
Definition Interface.h:369
const string & getVersionString() const
Return the version string of this interface.
Definition Interface.h:597
vector< OutputPtr > getActiveOutputs() const
Return a vector of all Output elements that belong to this interface, taking inheritance into account...
void setVersionIntegers(int majorVersion, int minorVersion)
Set the major and minor versions as an integer pair.
ValueElementPtr getValueElement(const string &name) const
Return the ValueElement, if any, with the given name.
Definition Interface.h:504
void clearContent() override
Clear all attributes and descendants from this element.
TokenPtr getActiveToken(const string &name) const
Return the first Token with the given name that belongs to this interface, taking interface inheritan...
OutputPtr getConnectedOutput(const string &inputName) const
Return the output connected to the given input.
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:541
OutputPtr getActiveOutput(const string &name) const
Return the first Output with the given name that belongs to this interface, taking interface inherita...
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:664
TokenPtr addToken(const string &name=EMPTY_STRING)
Add a Token to this interface.
Definition Interface.h:468
void setNodeDefString(const string &nodeDef)
Set the NodeDef string for the interface.
Definition Interface.h:333
ValueElementPtr getActiveValueElement(const string &name) const
Return the first value element with the given name that belongs to this interface,...
vector< InputPtr > getActiveInputs() const
Return a vector of all Input elements that belong to this interface, taking inheritance into account.
bool hasExactInputMatch(ConstInterfaceElementPtr declaration, string *message=nullptr) const
Return true if this instance has an exact input match with the given declaration, where each input of...
vector< OutputPtr > getOutputs() const
Return a vector of all Output elements.
Definition Interface.h:425
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:552
virtual ConstInterfaceElementPtr getDeclaration(const string &target=EMPTY_STRING) const
Return the first declaration of this interface, optionally filtered by the given target name.
void setConnectedOutput(const string &inputName, OutputPtr output)
Set the output to which the given input is connected, creating a child input if needed.
bool hasVersionString() const
Return true if this interface has a version string.
Definition Interface.h:591
bool getDefaultVersion() const
Return the default version flag of this element.
Definition Interface.h:619
const string & getNodeDefString() const
Return the NodeDef string for the interface.
Definition Interface.h:345
void removeToken(const string &name)
Remove the Token, if any, with the given name.
Definition Interface.h:486
void removeOutput(const string &name)
Remove the Output, if any, with the given name.
Definition Interface.h:437
void setTarget(const string &target)
Set the target string of this interface.
Definition Interface.h:563
InputPtr getActiveInput(const string &name) const
Return the first Input with the given name that belongs to this interface, taking interface inheritan...
void setDefaultVersion(bool defaultVersion)
Set the default version flag of this element.
Definition Interface.h:613
bool hasTarget() const
Return true if the given interface has a target string.
Definition Interface.h:569
size_t getOutputCount() const
Return the number of Output elements.
Definition Interface.h:431
const string & getTarget() const
Return the target string of this interface.
Definition Interface.h:575
vector< TokenPtr > getActiveTokens() const
Return a vector of all Token elements that belong to this interface, taking inheritance into account.
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:266
Edge getUpstreamEdge(size_t index=0) const override
Return the Edge with the given index that lies directly upstream from this element in the dataflow gr...
bool validate(string *message=nullptr) const override
Validate that the given element tree, including all descendants, is consistent with the MaterialX spe...
size_t getUpstreamEdgeCount() const override
Return the number of queryable upstream edges for this element.
Definition Interface.h:283
bool hasUpstreamCycle() const
Return true if a cycle exists in any upstream path from this element.
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
const string & getOutputString() const
Return the output string of this element.
Definition Interface.h:135
virtual NodePtr getConnectedNode() const
Return the node, if any, to which this element is connected.
bool validate(string *message=nullptr) const override
Validate that the given element tree, including all descendants, is consistent with the MaterialX spe...
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 setConnectedOutput(ConstOutputPtr output)
Set the output to which this input is connected.
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 setConnectedNode(ConstNodePtr node)
Set the node to which this element is connected.
void setOutputString(const string &output)
Set the output string of this element.
Definition Interface.h:116
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
OutputPtr getConnectedOutput() const
Return the output, if any, to which this input is connected.