Blender V5.3
FN_lazy_function_graph.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
19
21
22#include "FN_lazy_function.hh"
23
24namespace blender {
25
26namespace dot_export {
27class DirectedEdge;
28}
29
30namespace fn::lazy_function {
31
32class Socket;
33class InputSocket;
34class OutputSocket;
35class Node;
36class Graph;
37
43 protected:
51 const CPPType *type_;
64
65 friend Graph;
66
67 public:
68 bool is_input() const;
69 bool is_output() const;
70
71 int index() const;
72 int index_in_graph() const;
73
76 const InputSocket &as_input() const;
77 const OutputSocket &as_output() const;
78
79 const Node &node() const;
80 Node &node();
81
82 const CPPType &type() const;
83
84 std::string name() const;
85 std::string detailed_name() const;
86};
87
88class InputSocket : public Socket {
89 private:
95 OutputSocket *origin_;
104 const void *default_value_ = nullptr;
105
106 friend Graph;
107
108 public:
110 const OutputSocket *origin() const;
111
112 const void *default_value() const;
113 void set_default_value(const void *value);
114};
115
116class OutputSocket : public Socket {
117 private:
121 Vector<InputSocket *> targets_;
122
123 friend Graph;
124
125 public:
128};
129
134 protected:
139 const LazyFunction *fn_ = nullptr;
155
156 friend Graph;
157
158 public:
159 bool is_interface() const;
160 bool is_function() const;
161 int index_in_graph() const;
162
167
168 const InputSocket &input(int index) const;
169 const OutputSocket &output(int index) const;
170 InputSocket &input(int index);
172
173 std::string name() const;
174};
175
179class FunctionNode final : public Node {
180 public:
181 const LazyFunction &function() const;
182};
183
188class InterfaceNode final : public Node {
189 private:
190 friend Node;
191 friend Socket;
192 friend Graph;
193
194 Vector<std::string> socket_names_;
195};
196
203
208 private:
212 LinearAllocator<> allocator_;
216 StringRefNull name_;
221 Vector<Node *> nodes_;
222
223 InterfaceNode *graph_input_node_ = nullptr;
224 InterfaceNode *graph_output_node_ = nullptr;
225
226 Vector<GraphInputSocket *> graph_inputs_;
227 Vector<GraphOutputSocket *> graph_outputs_;
228
233 int socket_num_ = 0;
234
235 public:
236 Graph(StringRef name = "unknown");
237 ~Graph();
238
239 StringRefNull name() const;
240
246
249
252
255
260
264 GraphInputSocket &add_input(const CPPType &type, std::string name = "");
265 GraphOutputSocket &add_output(const CPPType &type, std::string name = "");
266
271 void add_link(OutputSocket &from, InputSocket &to);
272
276 void clear_origin(InputSocket &socket);
277
281 void update_node_indices();
286
290 int socket_num() const;
291
295 bool node_indices_are_valid() const;
296
302 public:
303 virtual std::string socket_name(const Socket &socket) const;
304 virtual std::optional<std::string> socket_font_color(const Socket &socket) const;
305 virtual void add_edge_attributes(const OutputSocket &from,
306 const InputSocket &to,
307 dot_export::DirectedEdge &dot_edge) const;
308 };
309
313 std::string to_dot(const ToDotOptions &options = {}) const;
314};
315
316/* -------------------------------------------------------------------- */
319
320inline bool Socket::is_input() const
321{
322 return is_input_;
323}
324
325inline bool Socket::is_output() const
326{
327 return !is_input_;
328}
329
330inline int Socket::index() const
331{
332 return index_in_node_;
333}
334
335inline int Socket::index_in_graph() const
336{
337 return index_in_graph_;
338}
339
341{
342 BLI_assert(this->is_input());
343 return *static_cast<InputSocket *>(this);
344}
345
347{
348 BLI_assert(this->is_output());
349 return *static_cast<OutputSocket *>(this);
350}
351
352inline const InputSocket &Socket::as_input() const
353{
354 BLI_assert(this->is_input());
355 return *static_cast<const InputSocket *>(this);
356}
357
358inline const OutputSocket &Socket::as_output() const
359{
360 BLI_assert(this->is_output());
361 return *static_cast<const OutputSocket *>(this);
362}
363
364inline const Node &Socket::node() const
365{
366 return *node_;
367}
368
370{
371 return *node_;
372}
373
374inline const CPPType &Socket::type() const
375{
376 return *type_;
377}
378
380
381/* -------------------------------------------------------------------- */
384
386{
387 return origin_;
388}
389
391{
392 return origin_;
393}
394
395inline const void *InputSocket::default_value() const
396{
397 return default_value_;
398}
399
400inline void InputSocket::set_default_value(const void *value)
401{
402 default_value_ = value;
403}
404
406
407/* -------------------------------------------------------------------- */
410
412{
413 return targets_;
414}
415
417{
418 return targets_;
419}
420
422
423/* -------------------------------------------------------------------- */
426
427inline bool Node::is_interface() const
428{
429 return fn_ == nullptr;
430}
431
432inline bool Node::is_function() const
433{
434 return fn_ != nullptr;
435}
436
437inline int Node::index_in_graph() const
438{
439 return index_in_graph_;
440}
441
443{
444 return inputs_;
445}
446
448{
449 return outputs_;
450}
451
453{
454 return inputs_;
455}
456
458{
459 return outputs_;
460}
461
462inline const InputSocket &Node::input(const int index) const
463{
464 return *inputs_[index];
465}
466
467inline const OutputSocket &Node::output(const int index) const
468{
469 return *outputs_[index];
470}
471
472inline InputSocket &Node::input(const int index)
473{
474 return *inputs_[index];
475}
476
478{
479 return *outputs_[index];
480}
481
483
484/* -------------------------------------------------------------------- */
487
489{
490 BLI_assert(fn_ != nullptr);
491 return *fn_;
492}
493
495
496/* -------------------------------------------------------------------- */
499
501{
502 return name_;
503}
504
506{
507 return nodes_;
508}
509
511{
512 return nodes_;
513}
514
516{
517 return nodes_.as_span().drop_front(2).cast<const FunctionNode *>();
518}
519
521{
522 return nodes_.as_span().drop_front(2).cast<FunctionNode *>();
523}
524
526{
527 return graph_inputs_;
528}
529
531{
532 return graph_outputs_;
533}
534
536{
537 return graph_inputs_;
538}
539
541{
542 return graph_outputs_;
543}
544
545inline int Graph::socket_num() const
546{
547 return socket_num_;
548}
549
551
552} // namespace fn::lazy_function
553
554} // namespace blender
#define final(a, b, c)
Definition BLI_hash_c.hh:21
constexpr Span drop_front(int64_t n) const
Definition BLI_span.hh:175
Span< NewT > constexpr cast() const
Definition BLI_span.hh:422
NonCopyable(const NonCopyable &other)=delete
NonMovable(NonMovable &&other)=delete
virtual std::string socket_name(const Socket &socket) const
virtual void add_edge_attributes(const OutputSocket &from, const InputSocket &to, dot_export::DirectedEdge &dot_edge) const
virtual std::optional< std::string > socket_font_color(const Socket &socket) const
Span< GraphInputSocket * > graph_inputs()
Span< const FunctionNode * > function_nodes() const
FunctionNode & add_function(const LazyFunction &fn)
void add_link(OutputSocket &from, InputSocket &to)
Span< GraphOutputSocket * > graph_outputs()
GraphOutputSocket & add_output(const CPPType &type, std::string name="")
void clear_origin(InputSocket &socket)
std::string to_dot(const ToDotOptions &options={}) const
GraphInputSocket & add_input(const CPPType &type, std::string name="")
Span< const InputSocket * > inputs() const
Span< const OutputSocket * > outputs() const
const InputSocket & input(int index) const
const OutputSocket & output(int index) const
CCL_NAMESPACE_BEGIN struct Options options
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)