Welcome to mirror list, hosted at ThFree Co, Russian Federation.

BKE_virtual_node_tree.h « blenkernel « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 86d96e569f68bfef4792fa9cd75f2b0c1771bf05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
#ifndef __BKE_VIRTUAL_NODE_TREE_H__
#define __BKE_VIRTUAL_NODE_TREE_H__

#include "BLI_vector.h"
#include "BLI_utility_mixins.h"
#include "BLI_array_cxx.h"
#include "BLI_string_ref.h"
#include "BLI_string_map.h"
#include "BLI_resource_collector.h"
#include "BLI_string_multi_map.h"
#include "BLI_linear_allocated_vector.h"

#include "DNA_node_types.h"

#include "RNA_access.h"

namespace BKE {

using BLI::Array;
using BLI::ArrayRef;
using BLI::LinearAllocatedVector;
using BLI::ResourceCollector;
using BLI::StringMap;
using BLI::StringMultiMap;
using BLI::StringRef;
using BLI::StringRefNull;
using BLI::Vector;

class VSocket;
class VInputSocket;
class VOutputSocket;
class VNode;
class VirtualNodeTree;

/* Virtual Node Tree declarations
 ******************************************/

class VSocket : BLI::NonCopyable, BLI::NonMovable {
 protected:
  LinearAllocatedVector<VSocket *> m_linked_sockets;
  LinearAllocatedVector<VSocket *> m_directly_linked_sockets;
  VNode *m_node;
  bool m_is_input;
  bNodeSocket *m_bsocket;
  uint m_id;
  PointerRNA m_rna;
  uint m_index;

  friend VirtualNodeTree;

 public:
  ArrayRef<const VSocket *> linked_sockets() const;
  ArrayRef<const VSocket *> directly_linked_sockets() const;

  const VNode &node() const;
  const VirtualNodeTree &tree() const;
  uint id() const;

  uint index() const;

  bool is_input() const;
  bool is_output() const;

  const VSocket &as_base() const;
  const VInputSocket &as_input() const;
  const VOutputSocket &as_output() const;

  PointerRNA *rna() const;

  StringRefNull idname() const;
  StringRefNull name() const;

  bool is_linked() const;

  bNodeSocket *bsocket() const;
  bNodeTree *btree() const;
};

class VInputSocket final : public VSocket {
 public:
  ArrayRef<const VOutputSocket *> linked_sockets() const;
  ArrayRef<const VOutputSocket *> directly_linked_sockets() const;
};

class VOutputSocket final : public VSocket {
 public:
  ArrayRef<const VInputSocket *> linked_sockets() const;
  ArrayRef<const VInputSocket *> directly_linked_sockets() const;
};

class VNode : BLI::NonCopyable, BLI::NonMovable {
 private:
  VirtualNodeTree *m_vtree;
  LinearAllocatedVector<VInputSocket *> m_inputs;
  LinearAllocatedVector<VOutputSocket *> m_outputs;
  bNode *m_bnode;
  uint m_id;
  PointerRNA m_rna;

  friend VirtualNodeTree;

 public:
  const VirtualNodeTree &tree() const;

  ArrayRef<const VInputSocket *> inputs() const;
  ArrayRef<const VOutputSocket *> outputs() const;

  PointerRNA *rna() const;
  StringRefNull idname() const;
  StringRefNull name() const;

  const VInputSocket &input(uint index) const;
  const VOutputSocket &output(uint index) const;

  const VInputSocket &input(uint index, StringRef expected_name) const;
  const VOutputSocket &output(uint index, StringRef expected_name) const;

  bNode *bnode() const;
  bNodeTree *btree() const;

  uint id() const;
};

class VirtualNodeTree : BLI::NonCopyable, BLI::NonMovable {
 private:
  BLI::LinearAllocator<> m_allocator;
  bNodeTree *m_btree;
  Vector<VNode *> m_nodes_by_id;
  Vector<VSocket *> m_sockets_by_id;
  Vector<VInputSocket *> m_input_sockets;
  Vector<VOutputSocket *> m_output_sockets;
  StringMultiMap<VNode *> m_nodes_by_idname;

 public:
  VirtualNodeTree(bNodeTree *btree);
  ~VirtualNodeTree();

  ArrayRef<const VNode *> nodes() const;
  ArrayRef<const VNode *> nodes_with_idname(StringRef idname) const;
  uint socket_count() const;

  ArrayRef<const VSocket *> all_sockets() const;
  ArrayRef<const VInputSocket *> all_input_sockets() const;
  ArrayRef<const VOutputSocket *> all_output_sockets() const;

  const VSocket &socket_by_id(uint id) const;

  bNodeTree *btree() const;

 private:
  void find_targets_skipping_reroutes(VOutputSocket &vsocket,
                                      LinearAllocatedVector<VSocket *> &r_targets);
};

/* Virtual Node Tree inline functions
 ****************************************************/

inline ArrayRef<const VSocket *> VSocket::linked_sockets() const
{
  return m_linked_sockets.as_ref();
}

inline ArrayRef<const VSocket *> VSocket::directly_linked_sockets() const
{
  return m_directly_linked_sockets.as_ref();
}

inline const VirtualNodeTree &VSocket::tree() const
{
  return m_node->tree();
}

inline const VNode &VSocket::node() const
{
  return *m_node;
}

inline uint VSocket::id() const
{
  return m_id;
}

inline uint VSocket::index() const
{
  return m_index;
}

inline bool VSocket::is_input() const
{
  return m_is_input;
}

inline bool VSocket::is_output() const
{
  return !m_is_input;
}

inline bool VSocket::is_linked() const
{
  return m_linked_sockets.size() > 0;
}

inline const VSocket &VSocket::as_base() const
{
  return *this;
}

inline const VInputSocket &VSocket::as_input() const
{
  BLI_assert(this->is_input());
  return *(const VInputSocket *)this;
}

inline const VOutputSocket &VSocket::as_output() const
{
  BLI_assert(this->is_output());
  return *(const VOutputSocket *)this;
}

inline PointerRNA *VSocket::rna() const
{
  return const_cast<PointerRNA *>(&m_rna);
}

inline StringRefNull VSocket::idname() const
{
  return m_bsocket->idname;
}

inline StringRefNull VSocket::name() const
{
  return m_bsocket->name;
}

inline bNodeSocket *VSocket::bsocket() const
{
  return m_bsocket;
}

inline ArrayRef<const VOutputSocket *> VInputSocket::linked_sockets() const
{
  return m_linked_sockets.as_ref().cast<const VOutputSocket *>();
  ;
}

inline ArrayRef<const VOutputSocket *> VInputSocket::directly_linked_sockets() const
{
  return m_directly_linked_sockets.as_ref().cast<const VOutputSocket *>();
}

inline ArrayRef<const VInputSocket *> VOutputSocket::linked_sockets() const
{
  return m_linked_sockets.as_ref().cast<const VInputSocket *>();
}

inline ArrayRef<const VInputSocket *> VOutputSocket::directly_linked_sockets() const
{
  return m_directly_linked_sockets.as_ref().cast<const VInputSocket *>();
}

inline ArrayRef<const VInputSocket *> VNode::inputs() const
{
  return m_inputs.as_ref();
}

inline ArrayRef<const VOutputSocket *> VNode::outputs() const
{
  return m_outputs.as_ref();
}

inline const VirtualNodeTree &VNode::tree() const
{
  return *m_vtree;
}

inline PointerRNA *VNode::rna() const
{
  return const_cast<PointerRNA *>(&m_rna);
}

inline StringRefNull VNode::idname() const
{
  return m_bnode->idname;
}

inline StringRefNull VNode::name() const
{
  return m_bnode->name;
}

inline const VInputSocket &VNode::input(uint index) const
{
  return *m_inputs[index];
}

inline const VOutputSocket &VNode::output(uint index) const
{
  return *m_outputs[index];
}

inline const VInputSocket &VNode::input(uint index, StringRef expected_name) const
{
  BLI_assert(m_inputs[index]->name() == expected_name);
  UNUSED_VARS_NDEBUG(expected_name);
  return *m_inputs[index];
}

inline const VOutputSocket &VNode::output(uint index, StringRef expected_name) const
{
  BLI_assert(m_outputs[index]->name() == expected_name);
  UNUSED_VARS_NDEBUG(expected_name);
  return *m_outputs[index];
}

inline bNode *VNode::bnode() const
{
  return m_bnode;
}

inline uint VNode::id() const
{
  return m_id;
}

inline bNodeTree *VirtualNodeTree::btree() const
{
  return m_btree;
}

inline ArrayRef<const VNode *> VirtualNodeTree::nodes() const
{
  return m_nodes_by_id.as_ref();
}

inline ArrayRef<const VNode *> VirtualNodeTree::nodes_with_idname(StringRef idname) const
{
  return m_nodes_by_idname.lookup_default(idname);
}

inline uint VirtualNodeTree::socket_count() const
{
  return m_sockets_by_id.size();
}

inline ArrayRef<const VSocket *> VirtualNodeTree::all_sockets() const
{
  return m_sockets_by_id.as_ref();
}

inline ArrayRef<const VInputSocket *> VirtualNodeTree::all_input_sockets() const
{
  return m_input_sockets.as_ref();
}

inline ArrayRef<const VOutputSocket *> VirtualNodeTree::all_output_sockets() const
{
  return m_output_sockets.as_ref();
}

inline const VSocket &VirtualNodeTree::socket_by_id(uint id) const
{
  return *m_sockets_by_id[id];
}

}  // namespace BKE

#endif /* __BKE_VIRTUAL_NODE_TREE_H__ */