6#ifndef MATERIALX_INTERFACE_H
7#define MATERIALX_INTERFACE_H
22class InterfaceElement;
46using CharSet = std::set<char>;
63 using NodePtr = shared_ptr<Node>;
73 setAttribute(NODE_NAME_ATTRIBUTE, node);
79 return hasAttribute(NODE_NAME_ATTRIBUTE);
85 return getAttribute(NODE_NAME_ATTRIBUTE);
95 setAttribute(NODE_GRAPH_ATTRIBUTE, node);
101 return hasAttribute(NODE_GRAPH_ATTRIBUTE);
107 return getAttribute(NODE_GRAPH_ATTRIBUTE);
117 setAttribute(OUTPUT_ATTRIBUTE, output);
123 return hasAttribute(OUTPUT_ATTRIBUTE);
129 return getAttribute(OUTPUT_ATTRIBUTE);
140 setAttribute(CHANNELS_ATTRIBUTE, channels);
146 return hasAttribute(CHANNELS_ATTRIBUTE);
152 return getAttribute(CHANNELS_ATTRIBUTE);
157 static bool validChannelsCharacters(
const string &channels,
const string &sourceType);
161 static bool validChannelsString(
const string& channels,
const string& sourceType,
const string& destinationType);
170 void setConnectedNode(
NodePtr node);
173 virtual NodePtr getConnectedNode()
const;
181 bool validate(
string* message =
nullptr)
const override;
186 static const string NODE_NAME_ATTRIBUTE;
187 static const string NODE_GRAPH_ATTRIBUTE;
188 static const string OUTPUT_ATTRIBUTE;
189 static const string CHANNELS_ATTRIBUTE;
192 static const std::unordered_map<string, CharSet> CHANNELS_CHARACTER_SET;
193 static const std::unordered_map<string, size_t> CHANNELS_PATTERN_LENGTH;
217 setAttribute(DEFAULT_GEOM_PROP_ATTRIBUTE, geomprop);
223 return hasAttribute(DEFAULT_GEOM_PROP_ATTRIBUTE);
229 return getAttribute(DEFAULT_GEOM_PROP_ATTRIBUTE);
240 NodePtr getConnectedNode()
const override;
247 virtual OutputPtr getConnectedOutput()
const;
259 bool validate(
string* message =
nullptr)
const override;
264 static const string CATEGORY;
265 static const string DEFAULT_GEOM_PROP_ATTRIBUTE;
285 Edge getUpstreamEdge(
size_t index = 0)
const override;
294 bool hasUpstreamCycle()
const;
302 bool validate(
string* message =
nullptr)
const override;
307 static const string CATEGORY;
308 static const string DEFAULT_INPUT_ATTRIBUTE;
329 using NodeDefPtr = shared_ptr<NodeDef>;
330 using ConstNodeDefPtr = shared_ptr<const NodeDef>;
339 setAttribute(NODE_DEF_ATTRIBUTE, nodeDef);
345 return hasAttribute(NODE_DEF_ATTRIBUTE);
351 return getAttribute(NODE_DEF_ATTRIBUTE);
365 const string& type = DEFAULT_TYPE_STRING)
367 InputPtr child = addChild<Input>(name);
368 child->setType(type);
375 return getChildOfType<Input>(name);
381 return getChildrenOfType<Input>();
393 removeChildOfType<Input>(name);
398 InputPtr getActiveInput(
const string& name)
const;
402 vector<InputPtr> getActiveInputs()
const;
415 const string& type = DEFAULT_TYPE_STRING)
417 OutputPtr output = addChild<Output>(name);
418 output->setType(type);
425 return getChildOfType<Output>(name);
431 return getChildrenOfType<Output>();
443 removeChildOfType<Output>(name);
448 OutputPtr getActiveOutput(
const string& name)
const;
452 vector<OutputPtr> getActiveOutputs()
const;
457 void setConnectedOutput(
const string& inputName,
OutputPtr output);
461 OutputPtr getConnectedOutput(
const string& inputName)
const;
474 return addChild<Token>(name);
480 return getChildOfType<Token>(name);
486 return getChildrenOfType<Token>();
492 removeChildOfType<Token>(name);
497 TokenPtr getActiveToken(
const string& name)
const;
501 vector<TokenPtr> getActiveTokens()
const;
510 return getChildOfType<ValueElement>(name);
521 vector<ValueElementPtr> getActiveValueElements()
const;
529 template<
class T>
InputPtr setInputValue(
const string& name,
531 const string& type = EMPTY_STRING);
541 ValuePtr getInputValue(
const string& name,
const string& target = EMPTY_STRING)
const;
549 token = addToken(name);
550 token->setValue<
string>(value);
559 return token ? token->getValueString() : EMPTY_STRING;
569 setAttribute(TARGET_ATTRIBUTE, target);
575 return hasAttribute(TARGET_ATTRIBUTE);
581 return getAttribute(TARGET_ATTRIBUTE);
591 setAttribute(VERSION_ATTRIBUTE, version);
597 return hasAttribute(VERSION_ATTRIBUTE);
603 return getAttribute(VERSION_ATTRIBUTE);
607 void setVersionIntegers(
int majorVersion,
int minorVersion);
610 virtual std::pair<int, int> getVersionIntegers()
const;
619 setTypedAttribute<bool>(DEFAULT_VERSION_ATTRIBUTE, defaultVersion);
625 return getTypedAttribute<bool>(DEFAULT_VERSION_ATTRIBUTE);
638 virtual ConstNodeDefPtr getDeclaration(
const string& target = EMPTY_STRING)
const;
652 static const string NODE_DEF_ATTRIBUTE;
653 static const string TARGET_ATTRIBUTE;
654 static const string VERSION_ATTRIBUTE;
655 static const string DEFAULT_VERSION_ATTRIBUTE;
658 void registerChildElement(
ElementPtr child)
override;
659 void unregisterChildElement(
ElementPtr child)
override;
670 InputPtr input = getChildOfType<Input>(name);
673 input->setValue(value, type);
shared_ptr< const NodeDef > ConstNodeDefPtr
A shared pointer to a const NodeDef.
Definition: Definition.h:35
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:49
shared_ptr< const PortElement > ConstPortElementPtr
A shared pointer to a const PortElement.
Definition: Interface.h:29
shared_ptr< const Output > ConstOutputPtr
A shared pointer to a const Output.
Definition: Interface.h:39
shared_ptr< InterfaceElement > InterfaceElementPtr
A shared pointer to an InterfaceElement.
Definition: Interface.h:42
shared_ptr< PortElement > PortElementPtr
A shared pointer to a PortElement.
Definition: Interface.h:27
shared_ptr< const InterfaceElement > ConstInterfaceElementPtr
A shared pointer to a const InterfaceElement.
Definition: Interface.h:44
shared_ptr< const Input > ConstInputPtr
A shared pointer to a const Input.
Definition: Interface.h:34
shared_ptr< Input > InputPtr
A shared pointer to an Input.
Definition: Interface.h:32
shared_ptr< Output > OutputPtr
A shared pointer to an Output.
Definition: Interface.h:37
Import and export declarations for the Core library.
shared_ptr< Node > NodePtr
A shared pointer to a Node.
Definition: Node.h:25
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:31
The base class for interface elements such as Node, NodeDef, and NodeGraph.
Definition: Interface.h:317
OutputPtr addOutput(const string &name=EMPTY_STRING, const string &type=DEFAULT_TYPE_STRING)
Add an Output to this interface.
Definition: Interface.h:414
OutputPtr getOutput(const string &name) const
Return the Output, if any, with the given name.
Definition: Interface.h:423
bool hasNodeDefString() const
Return true if the given interface has a NodeDef string.
Definition: Interface.h:343
TokenPtr getToken(const string &name) const
Return the Token, if any, with the given name.
Definition: Interface.h:478
vector< InputPtr > getInputs() const
Return a vector of all Input elements.
Definition: Interface.h:379
InputPtr addInput(const string &name=EMPTY_STRING, const string &type=DEFAULT_TYPE_STRING)
Add an Input to this interface.
Definition: Interface.h:364
size_t getInputCount() const
Return the number of Input elements.
Definition: Interface.h:385
void removeInput(const string &name)
Remove the Input, if any, with the given name.
Definition: Interface.h:391
void setVersionString(const string &version)
Set the version string of this interface.
Definition: Interface.h:589
vector< TokenPtr > getTokens() const
Return a vector of all Token elements.
Definition: Interface.h:484
InputPtr getInput(const string &name) const
Return the Input, if any, with the given name.
Definition: Interface.h:373
const string & getVersionString() const
Return the version string of this interface.
Definition: Interface.h:601
ValueElementPtr getValueElement(const string &name) const
Return the ValueElement, if any, with the given name.
Definition: Interface.h:508
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:545
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:666
TokenPtr addToken(const string &name=EMPTY_STRING)
Add a Token to this interface.
Definition: Interface.h:472
void setNodeDefString(const string &nodeDef)
Set the NodeDef string for the interface.
Definition: Interface.h:337
vector< OutputPtr > getOutputs() const
Return a vector of all Output elements.
Definition: Interface.h:429
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:556
bool hasVersionString() const
Return true if this interface has a version string.
Definition: Interface.h:595
bool getDefaultVersion() const
Return the default version flag of this element.
Definition: Interface.h:623
const string & getNodeDefString() const
Return the NodeDef string for the interface.
Definition: Interface.h:349
void removeToken(const string &name)
Remove the Token, if any, with the given name.
Definition: Interface.h:490
void removeOutput(const string &name)
Remove the Output, if any, with the given name.
Definition: Interface.h:441
void setTarget(const string &target)
Set the target string of this interface.
Definition: Interface.h:567
void setDefaultVersion(bool defaultVersion)
Set the default version flag of this element.
Definition: Interface.h:617
bool hasTarget() const
Return true if the given interface has a target string.
Definition: Interface.h:573
size_t getOutputCount() const
Return the number of Output elements.
Definition: Interface.h:435
const string & getTarget() const
Return the target string of this interface.
Definition: Interface.h:579
A spatially-varying output element within a NodeGraph or NodeDef.
Definition: Interface.h:271
size_t getUpstreamEdgeCount() const override
Return the number of queriable upstream edges for this element.
Definition: Interface.h:288
The base class for port elements such as Input and Output.
Definition: Interface.h:53
bool hasOutputString() const
Return true if this element has an output string.
Definition: Interface.h:121
const string & getNodeGraphString() const
Return the node graph string of this element.
Definition: Interface.h:105
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:138
const string & getOutputString() const
Return the output string of this element.
Definition: Interface.h:127
bool hasChannels() const
Return true if this element has a channels string.
Definition: Interface.h:144
void setNodeGraphString(const string &node)
Set the node graph string of this element.
Definition: Interface.h:93
bool hasNodeGraphString() const
Return true if this element has a node graph string.
Definition: Interface.h:99
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:71
void setOutputString(const string &output)
Set the output string of this element.
Definition: Interface.h:115
const string & getChannels() const
Return the channels string of this element.
Definition: Interface.h:150
const string & getNodeName() const
Return the node name string of this element.
Definition: Interface.h:83
bool hasNodeName() const
Return true if this element has a node name string.
Definition: Interface.h:77
The base class for typed elements.
Definition: Element.h:842
The base class for elements that support typed values.
Definition: Element.h:899