6#ifndef MATERIALX_NODE_H
7#define MATERIALX_NODE_H
46using NodePredicate = std::function<bool(
NodePtr node)>;
68 void setConnectedNode(
const string& inputName,
NodePtr node);
72 NodePtr getConnectedNode(
const string& inputName)
const;
76 void setConnectedNodeName(
const string& inputName,
const string& nodeName);
80 string getConnectedNodeName(
const string& inputName)
const;
85 void setConnectedOutput(
const string& inputName,
OutputPtr output);
89 OutputPtr getConnectedOutput(
const string& inputName)
const;
101 NodeDefPtr getNodeDef(
const string& target = EMPTY_STRING)
const;
116 NodeDefPtr nodeDef = getNodeDef(target);
126 Edge getUpstreamEdge(
size_t index = 0)
const override;
131 return getInputCount();
143 vector<PortElementPtr> getDownstreamPorts()
const;
151 ConstNodeDefPtr
getDeclaration(
const string& target = EMPTY_STRING)
const override
153 return getNodeDef(target);
158 InputPtr addInputFromNodeDef(
const string& name);
166 bool validate(
string* message =
nullptr)
const override;
171 static const string CATEGORY;
197 const string& name = EMPTY_STRING,
198 const string& type = DEFAULT_TYPE_STRING)
200 NodePtr node = addChild<Node>(name);
201 node->setCategory(category);
209 NodePtr node = addNode(nodeDef->getNodeString(), name, nodeDef->getType());
210 node->setNodeDefString(nodeDef->getName());
217 return getChildOfType<Node>(name);
222 vector<NodePtr>
getNodes(
const string& category = EMPTY_STRING)
const
224 return getChildrenOfType<Node>(category);
230 vector<NodePtr> nodes;
231 for (
auto node : getNodes())
233 if (node->getType() == nodeType)
235 nodes.push_back(node);
244 removeChildOfType<Node>(name);
253 NodePtr addMaterialNode(
const string& name = EMPTY_STRING,
ConstNodePtr shaderNode =
nullptr);
258 return getNodesOfType(MATERIAL_TYPE_STRING);
268 return addChild<Backdrop>(name);
274 return getChildOfType<Backdrop>(name);
280 return getChildrenOfType<Backdrop>();
286 removeChildOfType<Backdrop>(name);
295 void flattenSubgraphs(
const string& target = EMPTY_STRING, NodePredicate filter=
nullptr);
300 vector<ElementPtr> topologicalSort()
const;
308 string asStringDot()
const;
328 void setNodeDef(ConstNodeDefPtr nodeDef);
331 NodeDefPtr getNodeDef()
const;
344 ConstNodeDefPtr getDeclaration(
const string& target = EMPTY_STRING)
const override;
349 void addInterfaceName(
const string& inputPath,
const string& interfaceName);
353 void removeInterfaceName(
const string& inputPath);
358 void modifyInterfaceName(
const string& inputPath,
const string& interfaceName);
366 bool validate(
string* message =
nullptr)
const override;
371 static const string CATEGORY;
380 Element(parent, CATEGORY, name)
391 setAttribute(CONTAINS_ATTRIBUTE, contains);
397 return hasAttribute(CONTAINS_ATTRIBUTE);
403 return getAttribute(CONTAINS_ATTRIBUTE);
413 setTypedAttribute<float>(WIDTH_ATTRIBUTE, width);
419 return hasAttribute(WIDTH_ATTRIBUTE);
425 return getTypedAttribute<float>(WIDTH_ATTRIBUTE);
435 setTypedAttribute<float>(HEIGHT_ATTRIBUTE, height);
441 return hasAttribute(HEIGHT_ATTRIBUTE);
447 return getTypedAttribute<float>(HEIGHT_ATTRIBUTE);
455 void setContainsElements(
const vector<ConstTypedElementPtr>& nodes);
458 vector<TypedElementPtr> getContainsElements()
const;
466 bool validate(
string* message =
nullptr)
const override;
471 static const string CATEGORY;
472 static const string CONTAINS_ATTRIBUTE;
473 static const string WIDTH_ATTRIBUTE;
474 static const string HEIGHT_ATTRIBUTE;
Definition element subclasses.
shared_ptr< Element > ElementPtr
A shared pointer to an Element.
Definition: Element.h:31
shared_ptr< InterfaceElement > InterfaceElementPtr
A shared pointer to an InterfaceElement.
Definition: Interface.h:42
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< const NodeGraph > ConstNodeGraphPtr
A shared pointer to a const NodeGraph.
Definition: Node.h:37
shared_ptr< NodeGraph > NodeGraphPtr
A shared pointer to a NodeGraph.
Definition: Node.h:35
shared_ptr< Backdrop > BackdropPtr
A shared pointer to a Backdrop.
Definition: Node.h:40
shared_ptr< GraphElement > GraphElementPtr
A shared pointer to a GraphElement.
Definition: Node.h:30
shared_ptr< const Backdrop > ConstBackdropPtr
A shared pointer to a const Backdrop.
Definition: Node.h:42
shared_ptr< const Node > ConstNodePtr
A shared pointer to a const Node.
Definition: Node.h:27
shared_ptr< Node > NodePtr
A shared pointer to a Node.
Definition: Node.h:25
shared_ptr< const GraphElement > ConstGraphElementPtr
A shared pointer to a const GraphElement.
Definition: Node.h:32
A layout element used to contain, group and document nodes within a graph.
Definition: Node.h:377
void setContainsString(const string &contains)
Set the contains string for this backdrop.
Definition: Node.h:389
void setHeight(float height)
Set the height attribute of the backdrop.
Definition: Node.h:433
void setWidth(float width)
Set the width attribute of the backdrop.
Definition: Node.h:411
bool hasHeight() const
Return true if this backdrop has a height attribute.
Definition: Node.h:439
float getWidth() const
Return the width attribute of the backdrop.
Definition: Node.h:423
string getContainsString() const
Return the contains string for this backdrop.
Definition: Node.h:401
float getHeight() const
Return the height attribute of the backdrop.
Definition: Node.h:445
bool hasContainsString() const
Return true if this backdrop has a contains string.
Definition: Node.h:395
bool hasWidth() const
Return true if this backdrop has a width attribute.
Definition: Node.h:417
An edge between two connected Elements, returned during graph traversal.
Definition: Traversal.h:31
The base class for MaterialX elements.
Definition: Element.h:75
The base class for graph elements such as NodeGraph and Document.
Definition: Node.h:177
vector< NodePtr > getNodes(const string &category=EMPTY_STRING) const
Return a vector of all Nodes in the graph, optionally filtered by the given category string.
Definition: Node.h:222
vector< BackdropPtr > getBackdrops() const
Return a vector of all Backdrop elements in the graph.
Definition: Node.h:278
BackdropPtr addBackdrop(const string &name=EMPTY_STRING)
Add a Backdrop to the graph.
Definition: Node.h:266
NodePtr addNodeInstance(ConstNodeDefPtr nodeDef, const string &name=EMPTY_STRING)
Add a Node that is an instance of the given NodeDef.
Definition: Node.h:207
vector< NodePtr > getMaterialNodes() const
Return a vector of all material nodes.
Definition: Node.h:256
NodePtr addNode(const string &category, const string &name=EMPTY_STRING, const string &type=DEFAULT_TYPE_STRING)
Add a Node to the graph.
Definition: Node.h:196
NodePtr getNode(const string &name) const
Return the Node, if any, with the given name.
Definition: Node.h:215
BackdropPtr getBackdrop(const string &name) const
Return the Backdrop, if any, with the given name.
Definition: Node.h:272
void removeNode(const string &name)
Remove the Node, if any, with the given name.
Definition: Node.h:242
void removeBackdrop(const string &name)
Remove the Backdrop, if any, with the given name.
Definition: Node.h:284
vector< NodePtr > getNodesOfType(const string &nodeType) const
Return a vector of nodes in the graph which have a given type.
Definition: Node.h:228
The base class for interface elements such as Node, NodeDef, and NodeGraph.
Definition: Interface.h:317
A node graph element within a Document.
Definition: Node.h:316
A node element within a NodeGraph or Document.
Definition: Node.h:54
InterfaceElementPtr getImplementation(const string &target=EMPTY_STRING) const
Return the first implementation for this node, optionally filtered by the given target and language n...
Definition: Node.h:114
size_t getUpstreamEdgeCount() const override
Return the number of queriable upstream edges for this element.
Definition: Node.h:129
ConstNodeDefPtr getDeclaration(const string &target=EMPTY_STRING) const override
Return the first declaration of this interface, optionally filtered by the given target name.
Definition: Node.h:151