diff options
Diffstat (limited to 'source/blender/nodes/NOD_node_tree_ref.hh')
-rw-r--r-- | source/blender/nodes/NOD_node_tree_ref.hh | 134 |
1 files changed, 133 insertions, 1 deletions
diff --git a/source/blender/nodes/NOD_node_tree_ref.hh b/source/blender/nodes/NOD_node_tree_ref.hh index 7fcc117ba93..3c898aaf0ff 100644 --- a/source/blender/nodes/NOD_node_tree_ref.hh +++ b/source/blender/nodes/NOD_node_tree_ref.hh @@ -25,6 +25,7 @@ * The following queries are supported efficiently: * - socket -> index of socket * - socket -> directly linked sockets + * - socket -> directly linked links * - socket -> linked sockets when skipping reroutes * - socket -> node * - socket/node -> rna pointer @@ -65,6 +66,8 @@ class InputSocketRef; class OutputSocketRef; class NodeRef; class NodeTreeRef; +class LinkRef; +class InternalLinkRef; class SocketRef : NonCopyable, NonMovable { protected: @@ -76,12 +79,14 @@ class SocketRef : NonCopyable, NonMovable { PointerRNA rna_; Vector<SocketRef *> linked_sockets_; Vector<SocketRef *> directly_linked_sockets_; + Vector<LinkRef *> directly_linked_links_; friend NodeTreeRef; public: Span<const SocketRef *> linked_sockets() const; Span<const SocketRef *> directly_linked_sockets() const; + Span<const LinkRef *> directly_linked_links() const; bool is_linked() const; const NodeRef &node() const; @@ -102,16 +107,21 @@ class SocketRef : NonCopyable, NonMovable { StringRefNull idname() const; StringRefNull name() const; StringRefNull identifier() const; + bNodeSocketType *typeinfo() const; bNodeSocket *bsocket() const; bNode *bnode() const; bNodeTree *btree() const; + + bool is_available() const; }; class InputSocketRef final : public SocketRef { public: Span<const OutputSocketRef *> linked_sockets() const; Span<const OutputSocketRef *> directly_linked_sockets() const; + + bool is_multi_input_socket() const; }; class OutputSocketRef final : public SocketRef { @@ -128,6 +138,7 @@ class NodeRef : NonCopyable, NonMovable { int id_; Vector<InputSocketRef *> inputs_; Vector<OutputSocketRef *> outputs_; + Vector<InternalLinkRef *> internal_links_; friend NodeTreeRef; @@ -136,6 +147,7 @@ class NodeRef : NonCopyable, NonMovable { Span<const InputSocketRef *> inputs() const; Span<const OutputSocketRef *> outputs() const; + Span<const InternalLinkRef *> internal_links() const; const InputSocketRef &input(int index) const; const OutputSocketRef &output(int index) const; @@ -146,6 +158,7 @@ class NodeRef : NonCopyable, NonMovable { PointerRNA *rna() const; StringRefNull idname() const; StringRefNull name() const; + bNodeType *typeinfo() const; int id() const; @@ -156,6 +169,36 @@ class NodeRef : NonCopyable, NonMovable { bool is_muted() const; }; +class LinkRef : NonCopyable, NonMovable { + private: + OutputSocketRef *from_; + InputSocketRef *to_; + bNodeLink *blink_; + + friend NodeTreeRef; + + public: + const OutputSocketRef &from() const; + const InputSocketRef &to() const; + + bNodeLink *blink() const; +}; + +class InternalLinkRef : NonCopyable, NonMovable { + private: + InputSocketRef *from_; + OutputSocketRef *to_; + bNodeLink *blink_; + + friend NodeTreeRef; + + public: + const InputSocketRef &from() const; + const OutputSocketRef &to() const; + + bNodeLink *blink() const; +}; + class NodeTreeRef : NonCopyable, NonMovable { private: LinearAllocator<> allocator_; @@ -164,6 +207,7 @@ class NodeTreeRef : NonCopyable, NonMovable { Vector<SocketRef *> sockets_by_id_; Vector<InputSocketRef *> input_sockets_; Vector<OutputSocketRef *> output_sockets_; + Vector<LinkRef *> links_; MultiValueMap<const bNodeType *, NodeRef *> nodes_by_type_; public: @@ -178,6 +222,8 @@ class NodeTreeRef : NonCopyable, NonMovable { Span<const InputSocketRef *> input_sockets() const; Span<const OutputSocketRef *> output_sockets() const; + Span<const LinkRef *> links() const; + bool has_link_cycles() const; bNodeTree *btree() const; @@ -195,6 +241,19 @@ class NodeTreeRef : NonCopyable, NonMovable { void find_targets_skipping_reroutes(OutputSocketRef &socket_ref, Vector<SocketRef *> &r_targets); }; +using NodeTreeRefMap = Map<bNodeTree *, std::unique_ptr<const NodeTreeRef>>; + +const NodeTreeRef &get_tree_ref_from_map(NodeTreeRefMap &node_tree_refs, bNodeTree &btree); + +namespace node_tree_ref_types { +using nodes::InputSocketRef; +using nodes::NodeRef; +using nodes::NodeTreeRef; +using nodes::NodeTreeRefMap; +using nodes::OutputSocketRef; +using nodes::SocketRef; +} // namespace node_tree_ref_types + /* -------------------------------------------------------------------- * SocketRef inline methods. */ @@ -209,6 +268,11 @@ inline Span<const SocketRef *> SocketRef::directly_linked_sockets() const return directly_linked_sockets_; } +inline Span<const LinkRef *> SocketRef::directly_linked_links() const +{ + return directly_linked_links_; +} + inline bool SocketRef::is_linked() const { return linked_sockets_.size() > 0; @@ -281,6 +345,11 @@ inline StringRefNull SocketRef::identifier() const return bsocket_->identifier; } +inline bNodeSocketType *SocketRef::typeinfo() const +{ + return bsocket_->typeinfo; +} + inline bNodeSocket *SocketRef::bsocket() const { return bsocket_; @@ -296,6 +365,11 @@ inline bNodeTree *SocketRef::btree() const return node_->btree(); } +inline bool SocketRef::is_available() const +{ + return (bsocket_->flag & SOCK_UNAVAIL) == 0; +} + /* -------------------------------------------------------------------- * InputSocketRef inline methods. */ @@ -310,6 +384,11 @@ inline Span<const OutputSocketRef *> InputSocketRef::directly_linked_sockets() c return directly_linked_sockets_.as_span().cast<const OutputSocketRef *>(); } +inline bool InputSocketRef::is_multi_input_socket() const +{ + return bsocket_->flag & SOCK_MULTI_INPUT; +} + /* -------------------------------------------------------------------- * OutputSocketRef inline methods. */ @@ -343,6 +422,11 @@ inline Span<const OutputSocketRef *> NodeRef::outputs() const return outputs_; } +inline Span<const InternalLinkRef *> NodeRef::internal_links() const +{ + return internal_links_; +} + inline const InputSocketRef &NodeRef::input(int index) const { return *inputs_[index]; @@ -378,6 +462,11 @@ inline StringRefNull NodeRef::name() const return bnode_->name; } +inline bNodeType *NodeRef::typeinfo() const +{ + return bnode_->typeinfo; +} + inline int NodeRef::id() const { return id_; @@ -409,7 +498,45 @@ inline bool NodeRef::is_muted() const } /* -------------------------------------------------------------------- - * NodeRef inline methods. + * LinkRef inline methods. + */ + +inline const OutputSocketRef &LinkRef::from() const +{ + return *from_; +} + +inline const InputSocketRef &LinkRef::to() const +{ + return *to_; +} + +inline bNodeLink *LinkRef::blink() const +{ + return blink_; +} + +/* -------------------------------------------------------------------- + * InternalLinkRef inline methods. + */ + +inline const InputSocketRef &InternalLinkRef::from() const +{ + return *from_; +} + +inline const OutputSocketRef &InternalLinkRef::to() const +{ + return *to_; +} + +inline bNodeLink *InternalLinkRef::blink() const +{ + return blink_; +} + +/* -------------------------------------------------------------------- + * NodeTreeRef inline methods. */ inline Span<const NodeRef *> NodeTreeRef::nodes() const @@ -443,6 +570,11 @@ inline Span<const OutputSocketRef *> NodeTreeRef::output_sockets() const return output_sockets_; } +inline Span<const LinkRef *> NodeTreeRef::links() const +{ + return links_; +} + inline bNodeTree *NodeTreeRef::btree() const { return btree_; |