| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							|  |  |  |  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  |  *  - 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"
 | 
					
						
							|  |  |  | #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; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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_; | 
					
						
							|  |  |  |   Vector<SocketRef *> linked_sockets_; | 
					
						
							|  |  |  |   Vector<SocketRef *> directly_linked_sockets_; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   friend NodeTreeRef; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  public: | 
					
						
							|  |  |  |   Span<const SocketRef *> linked_sockets() const; | 
					
						
							|  |  |  |   Span<const SocketRef *> directly_linked_sockets() const; | 
					
						
							|  |  |  |   bool is_linked() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   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; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   bNodeSocket *bsocket() const; | 
					
						
							|  |  |  |   bNode *bnode() const; | 
					
						
							|  |  |  |   bNodeTree *btree() const; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class InputSocketRef final : public SocketRef { | 
					
						
							|  |  |  |  public: | 
					
						
							|  |  |  |   Span<const OutputSocketRef *> linked_sockets() const; | 
					
						
							|  |  |  |   Span<const OutputSocketRef *> directly_linked_sockets() const; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class OutputSocketRef final : public SocketRef { | 
					
						
							|  |  |  |  public: | 
					
						
							|  |  |  |   Span<const InputSocketRef *> linked_sockets() const; | 
					
						
							|  |  |  |   Span<const InputSocketRef *> directly_linked_sockets() const; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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_; | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							|  |  |  |   bNode *bnode() const; | 
					
						
							|  |  |  |   bNodeTree *btree() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   PointerRNA *rna() const; | 
					
						
							|  |  |  |   StringRefNull idname() const; | 
					
						
							|  |  |  |   StringRefNull name() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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_; | 
					
						
							| 
									
										
										
										
											2020-07-24 12:15:13 +02:00
										 |  |  |   MultiValueMap<const bNodeType *, NodeRef *> nodes_by_type_; | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-02 13:25:25 +01:00
										 |  |  |   bool has_link_cycles() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  |   bNodeTree *btree() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   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); | 
					
						
							|  |  |  |   void find_targets_skipping_reroutes(OutputSocketRef &socket_ref, Vector<SocketRef *> &r_targets); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* --------------------------------------------------------------------
 | 
					
						
							|  |  |  |  * SocketRef inline methods. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline Span<const SocketRef *> SocketRef::linked_sockets() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-08 22:29:10 +02:00
										 |  |  |   return linked_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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline bool SocketRef::is_linked() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-03 14:15:05 +02:00
										 |  |  |   return 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; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* --------------------------------------------------------------------
 | 
					
						
							|  |  |  |  * InputSocketRef inline methods. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline Span<const OutputSocketRef *> InputSocketRef::linked_sockets() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-03 14:15:05 +02:00
										 |  |  |   return linked_sockets_.as_span().cast<const OutputSocketRef *>(); | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline Span<const OutputSocketRef *> InputSocketRef::directly_linked_sockets() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-03 14:15:05 +02:00
										 |  |  |   return directly_linked_sockets_.as_span().cast<const OutputSocketRef *>(); | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* --------------------------------------------------------------------
 | 
					
						
							|  |  |  |  * OutputSocketRef inline methods. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline Span<const InputSocketRef *> OutputSocketRef::linked_sockets() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-03 14:15:05 +02:00
										 |  |  |   return linked_sockets_.as_span().cast<const InputSocketRef *>(); | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline Span<const InputSocketRef *> OutputSocketRef::directly_linked_sockets() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-03 14:15:05 +02:00
										 |  |  |   return directly_linked_sockets_.as_span().cast<const InputSocketRef *>(); | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* --------------------------------------------------------------------
 | 
					
						
							|  |  |  |  * NodeRef inline methods. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-03 14:15:05 +02:00
										 |  |  |   return bnode_->type == NODE_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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-27 19:38:14 +01:00
										 |  |  | inline bool NodeRef::is_muted() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return (bnode_->flag & NODE_MUTED) != 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | /* --------------------------------------------------------------------
 | 
					
						
							|  |  |  |  * NodeRef inline methods. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | inline bNodeTree *NodeTreeRef::btree() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-07-03 14:15:05 +02:00
										 |  |  |   return btree_; | 
					
						
							| 
									
										
										
										
											2020-06-09 17:08:41 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-17 11:36:59 +02:00
										 |  |  | }  // namespace blender::nodes
 |