| 
									
										
										
										
											2022-02-11 09:07:11 +11:00
										 |  |  | /* SPDX-License-Identifier: GPL-2.0-or-later */ | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-17 11:36:59 +02:00
										 |  |  | #pragma once
 | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** \file
 | 
					
						
							| 
									
										
										
										
											2020-07-17 11:36:59 +02:00
										 |  |  |  * \ingroup nodes | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  |  * | 
					
						
							|  |  |  |  * NodeTreeRef makes querying information about a bNodeTree more efficient. It is an immutable data | 
					
						
							|  |  |  |  * structure. It should not be used after anymore, after the underlying node tree changed. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The following queries are supported efficiently: | 
					
						
							|  |  |  |  *  - socket -> index of socket | 
					
						
							|  |  |  |  *  - socket -> directly linked sockets | 
					
						
							| 
									
										
										
										
											2021-03-03 07:59:07 +01:00
										 |  |  |  *  - socket -> directly linked links | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  |  *  - socket -> linked sockets when skipping reroutes | 
					
						
							|  |  |  |  *  - socket -> node | 
					
						
							|  |  |  |  *  - socket/node -> rna pointer | 
					
						
							|  |  |  |  *  - node -> inputs/outputs | 
					
						
							|  |  |  |  *  - node -> tree | 
					
						
							|  |  |  |  *  - tree -> all nodes | 
					
						
							|  |  |  |  *  - tree -> all (input/output) sockets | 
					
						
							|  |  |  |  *  - idname -> nodes | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Every socket has an id. The id-space is shared between input and output sockets. | 
					
						
							|  |  |  |  * When storing data per socket, it is often better to use the id as index into an array, instead | 
					
						
							|  |  |  |  * of a hash table. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Every node has an id as well. The same rule regarding hash tables applies. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * There is an utility to export this data structure as graph in dot format. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BLI_array.hh"
 | 
					
						
							| 
									
										
										
										
											2021-03-17 16:43:06 +01:00
										 |  |  | #include "BLI_function_ref.hh"
 | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | #include "BLI_linear_allocator.hh"
 | 
					
						
							|  |  |  | #include "BLI_map.hh"
 | 
					
						
							| 
									
										
										
										
											2020-07-24 12:15:13 +02:00
										 |  |  | #include "BLI_multi_value_map.hh"
 | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | #include "BLI_string_ref.hh"
 | 
					
						
							|  |  |  | #include "BLI_timeit.hh"
 | 
					
						
							|  |  |  | #include "BLI_utility_mixins.hh"
 | 
					
						
							|  |  |  | #include "BLI_vector.hh"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BKE_node.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "DNA_node_types.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "RNA_access.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-17 11:36:59 +02:00
										 |  |  | namespace blender::nodes { | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | class SocketRef; | 
					
						
							|  |  |  | class InputSocketRef; | 
					
						
							|  |  |  | class OutputSocketRef; | 
					
						
							|  |  |  | class NodeRef; | 
					
						
							|  |  |  | class NodeTreeRef; | 
					
						
							| 
									
										
										
										
											2021-03-03 07:59:07 +01:00
										 |  |  | class LinkRef; | 
					
						
							| 
									
										
										
										
											2021-03-04 18:15:22 +01:00
										 |  |  | class InternalLinkRef; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-11 16:21:08 +02:00
										 |  |  | using SocketIndexByIdentifierMap = Map<std::string, int>; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-30 10:35:50 +02:00
										 |  |  | class SocketRef : NonCopyable, NonMovable { | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  |  protected: | 
					
						
							| 
									
										
										
										
											2020-07-03 14:15:05 +02:00
										 |  |  |   NodeRef *node_; | 
					
						
							|  |  |  |   bNodeSocket *bsocket_; | 
					
						
							|  |  |  |   bool is_input_; | 
					
						
							| 
									
										
										
										
											2020-07-20 12:16:20 +02:00
										 |  |  |   int id_; | 
					
						
							|  |  |  |   int index_; | 
					
						
							| 
									
										
										
										
											2020-07-03 14:15:05 +02:00
										 |  |  |   PointerRNA rna_; | 
					
						
							| 
									
										
										
										
											2021-03-03 07:59:07 +01:00
										 |  |  |   Vector<LinkRef *> directly_linked_links_; | 
					
						
							| 
									
										
										
										
											2021-03-19 21:10:55 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-21 13:18:20 +11:00
										 |  |  |   /* These sockets are linked directly, i.e. with a single link in between. */ | 
					
						
							| 
									
										
										
										
											2021-04-01 13:10:22 +02:00
										 |  |  |   MutableSpan<const SocketRef *> directly_linked_sockets_; | 
					
						
							| 
									
										
										
										
											2021-03-19 21:10:55 +01:00
										 |  |  |   /* These sockets are linked when reroutes, muted links and muted nodes have been taken into
 | 
					
						
							|  |  |  |    * account. */ | 
					
						
							| 
									
										
										
										
											2021-04-01 13:10:22 +02:00
										 |  |  |   MutableSpan<const SocketRef *> logically_linked_sockets_; | 
					
						
							| 
									
										
										
										
											2021-04-01 22:20:53 +11:00
										 |  |  |   /* These are the sockets that have been skipped when searching for logically linked sockets.
 | 
					
						
							|  |  |  |    * That includes for example the input and output socket of an intermediate reroute node. */ | 
					
						
							| 
									
										
										
										
											2021-04-01 13:10:22 +02:00
										 |  |  |   MutableSpan<const SocketRef *> logically_linked_skipped_sockets_; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   friend NodeTreeRef; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  public: | 
					
						
							| 
									
										
										
										
											2021-03-19 21:10:55 +01:00
										 |  |  |   Span<const SocketRef *> logically_linked_sockets() const; | 
					
						
							| 
									
										
										
										
											2021-04-01 13:10:22 +02:00
										 |  |  |   Span<const SocketRef *> logically_linked_skipped_sockets() const; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  |   Span<const SocketRef *> directly_linked_sockets() const; | 
					
						
							| 
									
										
										
										
											2021-03-03 07:59:07 +01:00
										 |  |  |   Span<const LinkRef *> directly_linked_links() const; | 
					
						
							| 
									
										
										
										
											2021-03-19 21:10:55 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   bool is_directly_linked() const; | 
					
						
							|  |  |  |   bool is_logically_linked() const; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   const NodeRef &node() const; | 
					
						
							|  |  |  |   const NodeTreeRef &tree() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-20 12:16:20 +02:00
										 |  |  |   int id() const; | 
					
						
							|  |  |  |   int index() const; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   bool is_input() const; | 
					
						
							|  |  |  |   bool is_output() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const SocketRef &as_base() const; | 
					
						
							|  |  |  |   const InputSocketRef &as_input() const; | 
					
						
							|  |  |  |   const OutputSocketRef &as_output() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   PointerRNA *rna() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   StringRefNull idname() const; | 
					
						
							|  |  |  |   StringRefNull name() const; | 
					
						
							| 
									
										
										
										
											2020-12-02 13:25:25 +01:00
										 |  |  |   StringRefNull identifier() const; | 
					
						
							| 
									
										
										
										
											2021-03-04 18:15:22 +01:00
										 |  |  |   bNodeSocketType *typeinfo() const; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   bNodeSocket *bsocket() const; | 
					
						
							|  |  |  |   bNode *bnode() const; | 
					
						
							|  |  |  |   bNodeTree *btree() const; | 
					
						
							| 
									
										
										
										
											2021-03-04 18:15:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   bool is_available() const; | 
					
						
							| 
									
										
										
										
											2021-06-11 14:54:44 +02:00
										 |  |  |   bool is_undefined() const; | 
					
						
							| 
									
										
										
										
											2021-03-19 20:35:48 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   void *default_value() const; | 
					
						
							|  |  |  |   template<typename T> T *default_value() const; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class InputSocketRef final : public SocketRef { | 
					
						
							|  |  |  |  public: | 
					
						
							| 
									
										
										
										
											2021-04-21 16:21:54 +02:00
										 |  |  |   friend NodeTreeRef; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-19 21:10:55 +01:00
										 |  |  |   Span<const OutputSocketRef *> logically_linked_sockets() const; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  |   Span<const OutputSocketRef *> directly_linked_sockets() const; | 
					
						
							| 
									
										
										
										
											2021-03-04 18:15:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   bool is_multi_input_socket() const; | 
					
						
							| 
									
										
										
										
											2021-04-01 13:10:22 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-21 16:21:54 +02:00
										 |  |  |  private: | 
					
						
							| 
									
										
										
										
											2021-04-01 13:10:22 +02:00
										 |  |  |   void foreach_logical_origin(FunctionRef<void(const OutputSocketRef &)> origin_fn, | 
					
						
							|  |  |  |                               FunctionRef<void(const SocketRef &)> skipped_fn, | 
					
						
							| 
									
										
										
										
											2021-04-21 16:21:54 +02:00
										 |  |  |                               bool only_follow_first_input_link, | 
					
						
							| 
									
										
										
										
											2021-06-24 15:45:43 +02:00
										 |  |  |                               Vector<const InputSocketRef *> &seen_sockets_stack) const; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class OutputSocketRef final : public SocketRef { | 
					
						
							|  |  |  |  public: | 
					
						
							| 
									
										
										
										
											2021-04-21 16:21:54 +02:00
										 |  |  |   friend NodeTreeRef; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-19 21:10:55 +01:00
										 |  |  |   Span<const InputSocketRef *> logically_linked_sockets() const; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  |   Span<const InputSocketRef *> directly_linked_sockets() const; | 
					
						
							| 
									
										
										
										
											2021-04-01 13:10:22 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-21 16:21:54 +02:00
										 |  |  |  private: | 
					
						
							| 
									
										
										
										
											2021-04-01 13:10:22 +02:00
										 |  |  |   void foreach_logical_target(FunctionRef<void(const InputSocketRef &)> target_fn, | 
					
						
							| 
									
										
										
										
											2021-04-21 16:21:54 +02:00
										 |  |  |                               FunctionRef<void(const SocketRef &)> skipped_fn, | 
					
						
							| 
									
										
										
										
											2021-06-24 15:45:43 +02:00
										 |  |  |                               Vector<const OutputSocketRef *> &seen_sockets_stack) const; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-30 10:35:50 +02:00
										 |  |  | class NodeRef : NonCopyable, NonMovable { | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  |  private: | 
					
						
							| 
									
										
										
										
											2020-07-03 14:15:05 +02:00
										 |  |  |   NodeTreeRef *tree_; | 
					
						
							|  |  |  |   bNode *bnode_; | 
					
						
							|  |  |  |   PointerRNA rna_; | 
					
						
							| 
									
										
										
										
											2020-07-20 12:16:20 +02:00
										 |  |  |   int id_; | 
					
						
							| 
									
										
										
										
											2020-07-03 14:15:05 +02:00
										 |  |  |   Vector<InputSocketRef *> inputs_; | 
					
						
							|  |  |  |   Vector<OutputSocketRef *> outputs_; | 
					
						
							| 
									
										
										
										
											2021-03-04 18:15:22 +01:00
										 |  |  |   Vector<InternalLinkRef *> internal_links_; | 
					
						
							| 
									
										
										
										
											2021-06-11 16:21:08 +02:00
										 |  |  |   SocketIndexByIdentifierMap *input_index_by_identifier_; | 
					
						
							|  |  |  |   SocketIndexByIdentifierMap *output_index_by_identifier_; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   friend NodeTreeRef; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  public: | 
					
						
							|  |  |  |   const NodeTreeRef &tree() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Span<const InputSocketRef *> inputs() const; | 
					
						
							|  |  |  |   Span<const OutputSocketRef *> outputs() const; | 
					
						
							| 
									
										
										
										
											2021-03-04 18:15:22 +01:00
										 |  |  |   Span<const InternalLinkRef *> internal_links() const; | 
					
						
							| 
									
										
										
										
											2021-09-23 15:21:31 -05:00
										 |  |  |   Span<const SocketRef *> sockets(eNodeSocketInOut in_out) const; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-20 12:16:20 +02:00
										 |  |  |   const InputSocketRef &input(int index) const; | 
					
						
							|  |  |  |   const OutputSocketRef &output(int index) const; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-11 16:21:08 +02:00
										 |  |  |   const InputSocketRef &input_by_identifier(StringRef identifier) const; | 
					
						
							|  |  |  |   const OutputSocketRef &output_by_identifier(StringRef identifier) const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-23 15:21:31 -05:00
										 |  |  |   bool any_input_is_directly_linked() const; | 
					
						
							|  |  |  |   bool any_output_is_directly_linked() const; | 
					
						
							|  |  |  |   bool any_socket_is_directly_linked(eNodeSocketInOut in_out) const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  |   bNode *bnode() const; | 
					
						
							|  |  |  |   bNodeTree *btree() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   PointerRNA *rna() const; | 
					
						
							|  |  |  |   StringRefNull idname() const; | 
					
						
							|  |  |  |   StringRefNull name() const; | 
					
						
							| 
									
										
										
										
											2021-10-26 15:32:01 +02:00
										 |  |  |   StringRefNull label() const; | 
					
						
							|  |  |  |   StringRefNull label_or_name() const; | 
					
						
							| 
									
										
										
										
											2021-03-04 18:15:22 +01:00
										 |  |  |   bNodeType *typeinfo() const; | 
					
						
							| 
									
										
										
										
											2021-09-23 15:21:31 -05:00
										 |  |  |   const NodeDeclaration *declaration() const; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-20 12:16:20 +02:00
										 |  |  |   int id() const; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   bool is_reroute_node() const; | 
					
						
							|  |  |  |   bool is_group_node() const; | 
					
						
							|  |  |  |   bool is_group_input_node() const; | 
					
						
							|  |  |  |   bool is_group_output_node() const; | 
					
						
							| 
									
										
										
										
											2020-11-27 19:38:14 +01:00
										 |  |  |   bool is_muted() const; | 
					
						
							| 
									
										
										
										
											2021-03-19 22:33:43 +01:00
										 |  |  |   bool is_frame() const; | 
					
						
							| 
									
										
										
										
											2021-06-11 14:54:44 +02:00
										 |  |  |   bool is_undefined() const; | 
					
						
							| 
									
										
										
										
											2021-03-19 20:35:48 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   void *storage() const; | 
					
						
							|  |  |  |   template<typename T> T *storage() const; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-03 07:59:07 +01:00
										 |  |  | 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; | 
					
						
							| 
									
										
										
										
											2021-03-17 16:43:06 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   bool is_muted() const; | 
					
						
							| 
									
										
										
										
											2021-03-03 07:59:07 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-04 18:15:22 +01:00
										 |  |  | 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; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-30 10:35:50 +02:00
										 |  |  | class NodeTreeRef : NonCopyable, NonMovable { | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  |  private: | 
					
						
							| 
									
										
										
										
											2020-07-03 14:15:05 +02:00
										 |  |  |   LinearAllocator<> allocator_; | 
					
						
							|  |  |  |   bNodeTree *btree_; | 
					
						
							|  |  |  |   Vector<NodeRef *> nodes_by_id_; | 
					
						
							|  |  |  |   Vector<SocketRef *> sockets_by_id_; | 
					
						
							|  |  |  |   Vector<InputSocketRef *> input_sockets_; | 
					
						
							|  |  |  |   Vector<OutputSocketRef *> output_sockets_; | 
					
						
							| 
									
										
										
										
											2021-03-03 07:59:07 +01:00
										 |  |  |   Vector<LinkRef *> links_; | 
					
						
							| 
									
										
										
										
											2020-07-24 12:15:13 +02:00
										 |  |  |   MultiValueMap<const bNodeType *, NodeRef *> nodes_by_type_; | 
					
						
							| 
									
										
										
										
											2021-06-11 16:21:08 +02:00
										 |  |  |   Vector<std::unique_ptr<SocketIndexByIdentifierMap>> owned_identifier_maps_; | 
					
						
							| 
									
										
										
										
											2021-12-24 12:34:04 +01:00
										 |  |  |   const NodeRef *group_output_node_ = nullptr; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |  public: | 
					
						
							|  |  |  |   NodeTreeRef(bNodeTree *btree); | 
					
						
							|  |  |  |   ~NodeTreeRef(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   Span<const NodeRef *> nodes() const; | 
					
						
							| 
									
										
										
										
											2020-06-30 13:35:38 +02:00
										 |  |  |   Span<const NodeRef *> nodes_by_type(StringRefNull idname) const; | 
					
						
							|  |  |  |   Span<const NodeRef *> nodes_by_type(const bNodeType *nodetype) const; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   Span<const SocketRef *> sockets() const; | 
					
						
							|  |  |  |   Span<const InputSocketRef *> input_sockets() const; | 
					
						
							|  |  |  |   Span<const OutputSocketRef *> output_sockets() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-03 07:59:07 +01:00
										 |  |  |   Span<const LinkRef *> links() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-21 15:38:41 +02:00
										 |  |  |   const NodeRef *find_node(const bNode &bnode) const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-24 12:34:04 +01:00
										 |  |  |   /**
 | 
					
						
							|  |  |  |    * This is the active group output node if there are multiple. | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   const NodeRef *group_output_node() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-10 21:40:30 +11:00
										 |  |  |   /**
 | 
					
						
							|  |  |  |    * \return True when there is a link cycle. Unavailable sockets are ignored. | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2020-12-02 13:25:25 +01:00
										 |  |  |   bool has_link_cycles() const; | 
					
						
							| 
									
										
										
										
											2021-06-11 14:54:44 +02:00
										 |  |  |   bool has_undefined_nodes_or_sockets() const; | 
					
						
							| 
									
										
										
										
											2020-12-02 13:25:25 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-23 15:21:31 -05:00
										 |  |  |   enum class ToposortDirection { | 
					
						
							|  |  |  |     LeftToRight, | 
					
						
							|  |  |  |     RightToLeft, | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-27 12:29:46 +02:00
										 |  |  |   struct ToposortResult { | 
					
						
							|  |  |  |     Vector<const NodeRef *> sorted_nodes; | 
					
						
							|  |  |  |     /**
 | 
					
						
							| 
									
										
										
										
											2021-11-01 14:00:58 +11:00
										 |  |  |      * There can't be a correct topological sort of the nodes when there is a cycle. The nodes will | 
					
						
							| 
									
										
										
										
											2021-10-27 12:29:46 +02:00
										 |  |  |      * still be sorted to some degree. The caller has to decide whether it can handle non-perfect | 
					
						
							|  |  |  |      * sorts or not. | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     bool has_cycle = false; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-10 21:40:30 +11:00
										 |  |  |   /**
 | 
					
						
							|  |  |  |    * Sort nodes topologically from left to right or right to left. | 
					
						
							|  |  |  |    * In the future the result if this could be cached on #NodeTreeRef. | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2021-10-27 12:29:46 +02:00
										 |  |  |   ToposortResult toposort(ToposortDirection direction) const; | 
					
						
							| 
									
										
										
										
											2021-09-23 15:21:31 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  |   bNodeTree *btree() const; | 
					
						
							| 
									
										
										
										
											2021-03-19 22:33:43 +01:00
										 |  |  |   StringRefNull name() const; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   std::string to_dot() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  private: | 
					
						
							|  |  |  |   /* Utility functions used during construction. */ | 
					
						
							|  |  |  |   InputSocketRef &find_input_socket(Map<bNode *, NodeRef *> &node_mapping, | 
					
						
							|  |  |  |                                     bNode *bnode, | 
					
						
							|  |  |  |                                     bNodeSocket *bsocket); | 
					
						
							|  |  |  |   OutputSocketRef &find_output_socket(Map<bNode *, NodeRef *> &node_mapping, | 
					
						
							|  |  |  |                                       bNode *bnode, | 
					
						
							|  |  |  |                                       bNodeSocket *bsocket); | 
					
						
							| 
									
										
										
										
											2021-03-17 16:43:06 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   void create_linked_socket_caches(); | 
					
						
							| 
									
										
										
										
											2021-06-11 16:21:08 +02:00
										 |  |  |   void create_socket_identifier_maps(); | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-04 18:15:22 +01:00
										 |  |  | 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
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-05 11:10:25 +11:00
										 |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name #SocketRef Inline Methods
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-19 21:10:55 +01:00
										 |  |  | inline Span<const SocketRef *> SocketRef::logically_linked_sockets() const | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-03-19 21:10:55 +01:00
										 |  |  |   return logically_linked_sockets_; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-01 13:10:22 +02:00
										 |  |  | inline Span<const SocketRef *> SocketRef::logically_linked_skipped_sockets() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return logically_linked_skipped_sockets_; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | inline Span<const SocketRef *> SocketRef::directly_linked_sockets() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-08 22:29:10 +02:00
										 |  |  |   return directly_linked_sockets_; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-03 07:59:07 +01:00
										 |  |  | inline Span<const LinkRef *> SocketRef::directly_linked_links() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return directly_linked_links_; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-19 21:10:55 +01:00
										 |  |  | inline bool SocketRef::is_directly_linked() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return directly_linked_sockets_.size() > 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline bool SocketRef::is_logically_linked() const | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-03-19 21:10:55 +01:00
										 |  |  |   return logically_linked_sockets_.size() > 0; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline const NodeRef &SocketRef::node() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-03 14:15:05 +02:00
										 |  |  |   return *node_; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline const NodeTreeRef &SocketRef::tree() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-03 14:15:05 +02:00
										 |  |  |   return node_->tree(); | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-20 12:16:20 +02:00
										 |  |  | inline int SocketRef::id() const | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-03 14:15:05 +02:00
										 |  |  |   return id_; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-20 12:16:20 +02:00
										 |  |  | inline int SocketRef::index() const | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-03 14:15:05 +02:00
										 |  |  |   return index_; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline bool SocketRef::is_input() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-03 14:15:05 +02:00
										 |  |  |   return is_input_; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline bool SocketRef::is_output() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-03 14:15:05 +02:00
										 |  |  |   return !is_input_; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline const SocketRef &SocketRef::as_base() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return *this; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline const InputSocketRef &SocketRef::as_input() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   BLI_assert(this->is_input()); | 
					
						
							| 
									
										
										
										
											2020-08-07 18:24:59 +02:00
										 |  |  |   return static_cast<const InputSocketRef &>(*this); | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline const OutputSocketRef &SocketRef::as_output() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   BLI_assert(this->is_output()); | 
					
						
							| 
									
										
										
										
											2020-08-07 18:24:59 +02:00
										 |  |  |   return static_cast<const OutputSocketRef &>(*this); | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline PointerRNA *SocketRef::rna() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-03 14:15:05 +02:00
										 |  |  |   return const_cast<PointerRNA *>(&rna_); | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline StringRefNull SocketRef::idname() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-03 14:15:05 +02:00
										 |  |  |   return bsocket_->idname; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline StringRefNull SocketRef::name() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-03 14:15:05 +02:00
										 |  |  |   return bsocket_->name; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-02 13:25:25 +01:00
										 |  |  | inline StringRefNull SocketRef::identifier() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return bsocket_->identifier; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-04 18:15:22 +01:00
										 |  |  | inline bNodeSocketType *SocketRef::typeinfo() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return bsocket_->typeinfo; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | inline bNodeSocket *SocketRef::bsocket() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-03 14:15:05 +02:00
										 |  |  |   return bsocket_; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline bNode *SocketRef::bnode() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-03 14:15:05 +02:00
										 |  |  |   return node_->bnode(); | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline bNodeTree *SocketRef::btree() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-03 14:15:05 +02:00
										 |  |  |   return node_->btree(); | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-04 18:15:22 +01:00
										 |  |  | inline bool SocketRef::is_available() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return (bsocket_->flag & SOCK_UNAVAIL) == 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-11 14:54:44 +02:00
										 |  |  | inline bool SocketRef::is_undefined() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return bsocket_->typeinfo == &NodeSocketTypeUndefined; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-19 20:35:48 +01:00
										 |  |  | inline void *SocketRef::default_value() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return bsocket_->default_value; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<typename T> inline T *SocketRef::default_value() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return (T *)bsocket_->default_value; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-05 11:10:25 +11:00
										 |  |  | /** \} */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name #InputSocketRef Inline Methods
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-19 21:10:55 +01:00
										 |  |  | inline Span<const OutputSocketRef *> InputSocketRef::logically_linked_sockets() const | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-03-19 21:10:55 +01:00
										 |  |  |   return logically_linked_sockets_.as_span().cast<const OutputSocketRef *>(); | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline Span<const OutputSocketRef *> InputSocketRef::directly_linked_sockets() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-03-17 16:43:06 +01:00
										 |  |  |   return directly_linked_sockets_.cast<const OutputSocketRef *>(); | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-04 18:15:22 +01:00
										 |  |  | inline bool InputSocketRef::is_multi_input_socket() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return bsocket_->flag & SOCK_MULTI_INPUT; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-05 11:10:25 +11:00
										 |  |  | /** \} */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name #OutputSocketRef Inline Methods
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-19 21:10:55 +01:00
										 |  |  | inline Span<const InputSocketRef *> OutputSocketRef::logically_linked_sockets() const | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2021-03-19 21:10:55 +01:00
										 |  |  |   return logically_linked_sockets_.as_span().cast<const InputSocketRef *>(); | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline Span<const InputSocketRef *> OutputSocketRef::directly_linked_sockets() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-03-17 16:43:06 +01:00
										 |  |  |   return directly_linked_sockets_.cast<const InputSocketRef *>(); | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-05 11:10:25 +11:00
										 |  |  | /** \} */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name #NodeRef Inline Methods
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | inline const NodeTreeRef &NodeRef::tree() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-03 14:15:05 +02:00
										 |  |  |   return *tree_; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline Span<const InputSocketRef *> NodeRef::inputs() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-08 22:29:10 +02:00
										 |  |  |   return inputs_; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline Span<const OutputSocketRef *> NodeRef::outputs() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-08 22:29:10 +02:00
										 |  |  |   return outputs_; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-23 15:21:31 -05:00
										 |  |  | inline Span<const SocketRef *> NodeRef::sockets(const eNodeSocketInOut in_out) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return in_out == SOCK_IN ? inputs_.as_span().cast<const SocketRef *>() : | 
					
						
							|  |  |  |                              outputs_.as_span().cast<const SocketRef *>(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-04 18:15:22 +01:00
										 |  |  | inline Span<const InternalLinkRef *> NodeRef::internal_links() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return internal_links_; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-20 12:16:20 +02:00
										 |  |  | inline const InputSocketRef &NodeRef::input(int index) const | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-03 14:15:05 +02:00
										 |  |  |   return *inputs_[index]; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-20 12:16:20 +02:00
										 |  |  | inline const OutputSocketRef &NodeRef::output(int index) const | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-03 14:15:05 +02:00
										 |  |  |   return *outputs_[index]; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-11 16:21:08 +02:00
										 |  |  | inline const InputSocketRef &NodeRef::input_by_identifier(StringRef identifier) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   const int index = input_index_by_identifier_->lookup_as(identifier); | 
					
						
							|  |  |  |   return this->input(index); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline const OutputSocketRef &NodeRef::output_by_identifier(StringRef identifier) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   const int index = output_index_by_identifier_->lookup_as(identifier); | 
					
						
							|  |  |  |   return this->output(index); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | inline bNode *NodeRef::bnode() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-03 14:15:05 +02:00
										 |  |  |   return bnode_; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline bNodeTree *NodeRef::btree() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-03 14:15:05 +02:00
										 |  |  |   return tree_->btree(); | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline PointerRNA *NodeRef::rna() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-03 14:15:05 +02:00
										 |  |  |   return const_cast<PointerRNA *>(&rna_); | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline StringRefNull NodeRef::idname() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-03 14:15:05 +02:00
										 |  |  |   return bnode_->idname; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline StringRefNull NodeRef::name() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-03 14:15:05 +02:00
										 |  |  |   return bnode_->name; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-26 15:32:01 +02:00
										 |  |  | inline StringRefNull NodeRef::label() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return bnode_->label; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline StringRefNull NodeRef::label_or_name() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   const StringRefNull label = this->label(); | 
					
						
							|  |  |  |   if (!label.is_empty()) { | 
					
						
							|  |  |  |     return label; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return this->name(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-04 18:15:22 +01:00
										 |  |  | inline bNodeType *NodeRef::typeinfo() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return bnode_->typeinfo; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-23 15:21:31 -05:00
										 |  |  | /* Returns a pointer because not all nodes have declarations currently. */ | 
					
						
							|  |  |  | inline const NodeDeclaration *NodeRef::declaration() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   nodeDeclarationEnsure(this->tree().btree(), bnode_); | 
					
						
							|  |  |  |   return bnode_->declaration; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-20 12:16:20 +02:00
										 |  |  | inline int NodeRef::id() const | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-03 14:15:05 +02:00
										 |  |  |   return id_; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline bool NodeRef::is_reroute_node() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-03 14:15:05 +02:00
										 |  |  |   return bnode_->type == NODE_REROUTE; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline bool NodeRef::is_group_node() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2021-04-08 16:25:09 -06:00
										 |  |  |   return bnode_->type == NODE_GROUP || bnode_->type == NODE_CUSTOM_GROUP; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline bool NodeRef::is_group_input_node() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-03 14:15:05 +02:00
										 |  |  |   return bnode_->type == NODE_GROUP_INPUT; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline bool NodeRef::is_group_output_node() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-03 14:15:05 +02:00
										 |  |  |   return bnode_->type == NODE_GROUP_OUTPUT; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-19 22:33:43 +01:00
										 |  |  | inline bool NodeRef::is_frame() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return bnode_->type == NODE_FRAME; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-11 14:54:44 +02:00
										 |  |  | inline bool NodeRef::is_undefined() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return bnode_->typeinfo == &NodeTypeUndefined; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-27 19:38:14 +01:00
										 |  |  | inline bool NodeRef::is_muted() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return (bnode_->flag & NODE_MUTED) != 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-19 20:35:48 +01:00
										 |  |  | inline void *NodeRef::storage() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return bnode_->storage; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<typename T> inline T *NodeRef::storage() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return (T *)bnode_->storage; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-05 11:10:25 +11:00
										 |  |  | /** \} */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name #LinkRef Inline Methods
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							| 
									
										
										
										
											2021-03-03 07:59:07 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | inline const OutputSocketRef &LinkRef::from() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return *from_; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline const InputSocketRef &LinkRef::to() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return *to_; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline bNodeLink *LinkRef::blink() const | 
					
						
							| 
									
										
										
										
											2021-03-04 18:15:22 +01:00
										 |  |  | { | 
					
						
							|  |  |  |   return blink_; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-17 16:43:06 +01:00
										 |  |  | inline bool LinkRef::is_muted() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return blink_->flag & NODE_LINK_MUTED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-05 11:10:25 +11:00
										 |  |  | /** \} */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name #InternalLinkRef Inline Methods
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							| 
									
										
										
										
											2021-03-04 18:15:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | inline const InputSocketRef &InternalLinkRef::from() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return *from_; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline const OutputSocketRef &InternalLinkRef::to() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return *to_; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline bNodeLink *InternalLinkRef::blink() const | 
					
						
							| 
									
										
										
										
											2021-03-03 07:59:07 +01:00
										 |  |  | { | 
					
						
							|  |  |  |   return blink_; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-05 11:10:25 +11:00
										 |  |  | /** \} */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /** \name #NodeTreeRef Inline Methods
 | 
					
						
							|  |  |  |  * \{ */ | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | inline Span<const NodeRef *> NodeTreeRef::nodes() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-08 22:29:10 +02:00
										 |  |  |   return nodes_by_id_; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-30 13:35:38 +02:00
										 |  |  | inline Span<const NodeRef *> NodeTreeRef::nodes_by_type(StringRefNull idname) const | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-17 12:38:15 +02:00
										 |  |  |   const bNodeType *nodetype = nodeTypeFind(idname.c_str()); | 
					
						
							| 
									
										
										
										
											2020-06-30 13:35:38 +02:00
										 |  |  |   return this->nodes_by_type(nodetype); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline Span<const NodeRef *> NodeTreeRef::nodes_by_type(const bNodeType *nodetype) const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-24 12:15:13 +02:00
										 |  |  |   return nodes_by_type_.lookup(nodetype); | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline Span<const SocketRef *> NodeTreeRef::sockets() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-08 22:29:10 +02:00
										 |  |  |   return sockets_by_id_; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline Span<const InputSocketRef *> NodeTreeRef::input_sockets() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-08 22:29:10 +02:00
										 |  |  |   return input_sockets_; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline Span<const OutputSocketRef *> NodeTreeRef::output_sockets() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-08 22:29:10 +02:00
										 |  |  |   return output_sockets_; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-03 07:59:07 +01:00
										 |  |  | inline Span<const LinkRef *> NodeTreeRef::links() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return links_; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-24 12:34:04 +01:00
										 |  |  | inline const NodeRef *NodeTreeRef::group_output_node() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return group_output_node_; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | inline bNodeTree *NodeTreeRef::btree() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-03 14:15:05 +02:00
										 |  |  |   return btree_; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-19 22:33:43 +01:00
										 |  |  | inline StringRefNull NodeTreeRef::name() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return btree_->id.name + 2; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-05 11:10:25 +11:00
										 |  |  | /** \} */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-17 11:36:59 +02:00
										 |  |  | }  // namespace blender::nodes
 |