Blender V4.5
node_tree_interface.cc
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#include <queue>
6
7#include "BKE_idprop.hh"
8#include "BKE_lib_id.hh"
9#include "BKE_lib_query.hh"
10#include "BKE_node.hh"
11#include "BKE_node_enum.hh"
12#include "BKE_node_runtime.hh"
14
15#include "BLI_math_vector.h"
16#include "BLI_stack.hh"
17#include "BLI_string.h"
18
19#include "BLO_read_write.hh"
20
22#include "DNA_material_types.h"
24#include "DNA_node_types.h"
25
27
29
31
32namespace socket_types {
33
34/* Try to get a supported socket type from some final type.
35 * Built-in socket can have multiple registered RNA types for the base type, e.g.
36 * `NodeSocketFloatUnsigned`, `NodeSocketFloatFactor`. Only the "base type" (`NodeSocketFloat`)
37 * is considered valid for interface sockets.
38 */
39static std::optional<StringRef> try_get_supported_socket_type(const StringRef socket_type)
40{
41 const blender::bke::bNodeSocketType *typeinfo = bke::node_socket_type_find(socket_type);
42 if (typeinfo == nullptr) {
43 return std::nullopt;
44 }
45 /* For builtin socket types only the base type is supported. */
46 if (node_is_static_socket_type(*typeinfo)) {
47 if (const std::optional<StringRefNull> type_name = bke::node_static_socket_type(typeinfo->type,
48 PROP_NONE))
49 {
50 return *type_name;
51 }
52 return std::nullopt;
53 }
54 return typeinfo->idname;
55}
56
57/* -------------------------------------------------------------------- */
60
61template<typename T> void socket_data_id_user_increment(T & /*data*/) {}
63{
64 id_us_plus(reinterpret_cast<ID *>(data.value));
65}
67{
68 id_us_plus(reinterpret_cast<ID *>(data.value));
69}
71{
72 id_us_plus(reinterpret_cast<ID *>(data.value));
73}
75{
76 id_us_plus(reinterpret_cast<ID *>(data.value));
77}
79{
80 id_us_plus(reinterpret_cast<ID *>(data.value));
81}
82
84
85/* -------------------------------------------------------------------- */
88
89template<typename T> void socket_data_id_user_decrement(T & /*data*/) {}
91{
92 id_us_min(reinterpret_cast<ID *>(data.value));
93}
95{
96 id_us_min(reinterpret_cast<ID *>(data.value));
97}
99{
100 id_us_min(reinterpret_cast<ID *>(data.value));
101}
103{
104 id_us_min(reinterpret_cast<ID *>(data.value));
105}
107{
108 id_us_min(reinterpret_cast<ID *>(data.value));
109}
110
112
113/* -------------------------------------------------------------------- */
116
117template<typename T> void socket_data_init_impl(T & /*data*/) {}
119{
120 data.subtype = PROP_NONE;
121 data.value = 0.0f;
122 data.min = -FLT_MAX;
123 data.max = FLT_MAX;
124}
126{
127 data.subtype = PROP_NONE;
128 data.value = 0;
129 data.min = INT_MIN;
130 data.max = INT_MAX;
131}
133{
134 data.value = false;
135}
138{
139 static float default_value[] = {0.0f, 0.0f, 0.0f};
140 data.subtype = PROP_NONE;
141 data.dimensions = 3;
142 copy_v3_v3(data.value, default_value);
143 data.min = -FLT_MAX;
144 data.max = FLT_MAX;
145}
147{
148 static float default_value[] = {0.0f, 0.0f, 0.0f, 1.0f};
149 copy_v4_v4(data.value, default_value);
150}
152{
153 data.subtype = PROP_NONE;
154 data.value[0] = '\0';
155}
157{
158 data.value = nullptr;
159}
161{
162 data.value = nullptr;
163}
165{
166 data.value = nullptr;
167}
169{
170 data.value = nullptr;
171}
173{
174 data.value = nullptr;
175}
177{
178 data.value = -1;
179 data.enum_items = nullptr;
180 data.runtime_flag = 0;
181}
182
183static void *make_socket_data(const StringRef socket_type)
184{
185 void *socket_data = nullptr;
186 socket_data_to_static_type_tag(socket_type, [&socket_data](auto type_tag) {
187 using SocketDataType = typename decltype(type_tag)::type;
188 SocketDataType *new_socket_data = MEM_callocN<SocketDataType>(__func__);
189 socket_data_init_impl(*new_socket_data);
190 socket_data = new_socket_data;
191 });
192 return socket_data;
193}
194
196
197/* -------------------------------------------------------------------- */
200
201template<typename T> void socket_data_free_impl(T & /*data*/, const bool /*do_id_user*/) {}
202template<> void socket_data_free_impl(bNodeSocketValueMenu &dst, const bool /*do_id_user*/)
203{
204 if (dst.enum_items) {
205 /* Release shared data pointer. */
206 dst.enum_items->remove_user_and_delete_if_last();
207 }
208}
209
210static void socket_data_free(bNodeTreeInterfaceSocket &socket, const bool do_id_user)
211{
212 socket_data_to_static_type_tag(socket.socket_type, [&](auto type_tag) {
213 using SocketDataType = typename decltype(type_tag)::type;
214 if (do_id_user) {
215 socket_data_id_user_decrement(get_socket_data_as<SocketDataType>(socket));
216 }
218 });
219}
220
222
223/* -------------------------------------------------------------------- */
226
227template<typename T> void socket_data_copy_impl(T & /*dst*/, const T & /*src*/) {}
228template<>
230{
231 /* Copy of shared data pointer. */
232 if (dst.enum_items) {
233 dst.enum_items->add_user();
234 }
235}
236
238 const bNodeTreeInterfaceSocket &src,
239 int flag)
240{
241 socket_data_to_static_type_tag(dst.socket_type, [&](auto type_tag) {
242 using SocketDataType = typename decltype(type_tag)::type;
243 dst.socket_data = MEM_dupallocN(src.socket_data);
244 socket_data_copy_impl(get_socket_data_as<SocketDataType>(dst),
245 get_socket_data_as<SocketDataType>(src));
246 if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
247 socket_data_id_user_increment(get_socket_data_as<SocketDataType>(dst));
248 }
249 });
250}
251
252/* Copy socket data from a raw pointer, e.g. from a #bNodeSocket. */
254 const void *src_socket_data,
255 int flag)
256{
257 socket_data_to_static_type_tag(dst.socket_type, [&](auto type_tag) {
258 using SocketDataType = typename decltype(type_tag)::type;
259
260 if (dst.socket_data != nullptr) {
261 socket_data_free(dst, true);
262 MEM_SAFE_FREE(dst.socket_data);
263 }
264
265 dst.socket_data = MEM_dupallocN(src_socket_data);
267 *static_cast<const SocketDataType *>(src_socket_data));
268 if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
270 }
271 });
272}
273
275
276/* -------------------------------------------------------------------- */
279
280/* NOTE: no default implementation, every used type must write at least the base struct. */
281
334
336{
337 socket_data_to_static_type_tag(socket.socket_type, [&](auto type_tag) {
338 using SocketDataType = typename decltype(type_tag)::type;
339 socket_data_write_impl(writer, get_socket_data_as<SocketDataType>(socket));
340 });
341}
342
344
345/* -------------------------------------------------------------------- */
348
349template<typename T> void socket_data_read_data_impl(BlendDataReader *reader, T **data)
350{
351 /* FIXME Avoid using low-level untyped read function here. Cannot use the BLO_read_struct
352 * currently (macro expansion would process `T` instead of the actual type). */
354}
356{
357 /* FIXME Avoid using low-level untyped read function here. No type info available here currently.
358 */
360 /* Clear runtime data. */
361 (*data)->enum_items = nullptr;
362 (*data)->runtime_flag = 0;
363}
364
366{
367 bool data_read = false;
368 socket_data_to_static_type_tag(socket.socket_type, [&](auto type_tag) {
369 using SocketDataType = typename decltype(type_tag)::type;
370 socket_data_read_data_impl(reader, reinterpret_cast<SocketDataType **>(&socket.socket_data));
371 data_read = true;
372 });
373 if (!data_read && socket.socket_data) {
374 /* Not sure how this can happen exactly, but it did happen in #127855. */
375 socket.socket_data = nullptr;
376 }
377}
378
380
381/* -------------------------------------------------------------------- */
384
385template<typename T>
387{
388}
397template<>
402template<>
407template<>
412
414{
415 socket_data_to_static_type_tag(socket.socket_type, [&](auto type_tag) {
416 using SocketDataType = typename decltype(type_tag)::type;
417 socket_data_foreach_id_impl(data, get_socket_data_as<SocketDataType>(socket));
418 });
419}
420
422
423} // namespace socket_types
424
425namespace item_types {
426
428
429static void item_copy(bNodeTreeInterfaceItem &dst,
430 const bNodeTreeInterfaceItem &src,
431 int flag,
432 UidGeneratorFn generate_uid);
433
441 const int flag,
442 UidGeneratorFn generate_uid)
443{
444 panel.items_num = items_src.size();
446
447 /* Copy buffers. */
448 for (const int i : items_src.index_range()) {
449 const bNodeTreeInterfaceItem *item_src = items_src[i];
450 panel.items_array[i] = static_cast<bNodeTreeInterfaceItem *>(MEM_dupallocN(item_src));
451 item_types::item_copy(*panel.items_array[i], *item_src, flag, generate_uid);
452 }
453}
454
461 const bNodeTreeInterfaceItem &src,
462 const int flag,
463 UidGeneratorFn generate_uid)
464{
467 bNodeTreeInterfaceSocket &dst_socket = reinterpret_cast<bNodeTreeInterfaceSocket &>(dst);
468 const bNodeTreeInterfaceSocket &src_socket =
469 reinterpret_cast<const bNodeTreeInterfaceSocket &>(src);
470 BLI_assert(src_socket.socket_type != nullptr);
471
472 dst_socket.name = BLI_strdup_null(src_socket.name);
473 dst_socket.description = BLI_strdup_null(src_socket.description);
474 dst_socket.socket_type = BLI_strdup(src_socket.socket_type);
476 dst_socket.identifier = generate_uid ? BLI_sprintfN("Socket_%d", generate_uid()) :
477 BLI_strdup(src_socket.identifier);
478 if (src_socket.properties) {
479 dst_socket.properties = IDP_CopyProperty_ex(src_socket.properties, flag);
480 }
481 if (src_socket.socket_data != nullptr) {
482 socket_types::socket_data_copy(dst_socket, src_socket, flag);
483 }
484 break;
485 }
487 bNodeTreeInterfacePanel &dst_panel = reinterpret_cast<bNodeTreeInterfacePanel &>(dst);
488 const bNodeTreeInterfacePanel &src_panel = reinterpret_cast<const bNodeTreeInterfacePanel &>(
489 src);
490
491 dst_panel.name = BLI_strdup_null(src_panel.name);
492 dst_panel.description = BLI_strdup_null(src_panel.description);
493 dst_panel.identifier = generate_uid ? generate_uid() : src_panel.identifier;
494
495 panel_init(dst_panel, src_panel.items(), flag, generate_uid);
496 break;
497 }
498 }
499}
500
501static void item_free(bNodeTreeInterfaceItem &item, const bool do_id_user)
502{
503 switch (NodeTreeInterfaceItemType(item.item_type)) {
505 bNodeTreeInterfaceSocket &socket = reinterpret_cast<bNodeTreeInterfaceSocket &>(item);
506
507 if (socket.socket_data != nullptr) {
508 socket_types::socket_data_free(socket, do_id_user);
510 }
511
512 MEM_SAFE_FREE(socket.name);
517 if (socket.properties) {
518 IDP_FreePropertyContent_ex(socket.properties, do_id_user);
519 MEM_freeN(socket.properties);
520 }
521 break;
522 }
524 bNodeTreeInterfacePanel &panel = reinterpret_cast<bNodeTreeInterfacePanel &>(item);
525
526 panel.clear(do_id_user);
527 MEM_SAFE_FREE(panel.name);
529 break;
530 }
531 }
532
533 MEM_freeN(&item);
534}
535
537
539{
540 switch (NodeTreeInterfaceItemType(item.item_type)) {
542 bNodeTreeInterfaceSocket &socket = reinterpret_cast<bNodeTreeInterfaceSocket &>(item);
543 BLO_write_string(writer, socket.name);
544 BLO_write_string(writer, socket.identifier);
545 BLO_write_string(writer, socket.description);
546 BLO_write_string(writer, socket.socket_type);
548 if (socket.properties) {
549 IDP_BlendWrite(writer, socket.properties);
550 }
551
552 socket_types::socket_data_write(writer, socket);
553 break;
554 }
556 bNodeTreeInterfacePanel &panel = reinterpret_cast<bNodeTreeInterfacePanel &>(item);
557 BLO_write_string(writer, panel.name);
558 BLO_write_string(writer, panel.description);
559 BLO_write_pointer_array(writer, panel.items_num, panel.items_array);
560 for (bNodeTreeInterfaceItem *child_item : panel.items()) {
561 item_write_struct(writer, *child_item);
562 }
563 break;
564 }
565 }
566}
567
569{
570 switch (NodeTreeInterfaceItemType(item.item_type)) {
572 /* Forward compatible writing of older single value only flag. To be removed in 5.0. */
577
579 break;
580 }
583 break;
584 }
585 }
586
587 item_write_data(writer, item);
588}
589
590static size_t item_struct_size(const bNodeTreeInterfaceItem &item)
591{
592 switch (NodeTreeInterfaceItemType(item.item_type)) {
594 return sizeof(bNodeTreeInterfaceSocket);
596 return sizeof(bNodeTreeInterfacePanel);
597 }
598 return sizeof(bNodeTreeInterfaceItem);
599}
600
602{
603 switch (NodeTreeInterfaceItemType(item.item_type)) {
605 bNodeTreeInterfaceSocket &socket = reinterpret_cast<bNodeTreeInterfaceSocket &>(item);
606 BLO_read_string(reader, &socket.name);
607 BLO_read_string(reader, &socket.description);
608 BLO_read_string(reader, &socket.socket_type);
610 BLO_read_string(reader, &socket.identifier);
611 BLO_read_struct(reader, IDProperty, &socket.properties);
612 IDP_BlendDataRead(reader, &socket.properties);
613
614 /* Improve forward compatibility for unknown default input types. */
615 const bNodeSocketType *stype = socket.socket_typeinfo();
617 *stype, NodeDefaultInputType(socket.default_input)))
618 {
620 }
621
623 break;
624 }
626 bNodeTreeInterfacePanel &panel = reinterpret_cast<bNodeTreeInterfacePanel &>(item);
627 BLO_read_string(reader, &panel.name);
628 BLO_read_string(reader, &panel.description);
630 reader, panel.items_num, reinterpret_cast<void **>(&panel.items_array));
631
632 /* Read the direct-data for each interface item if possible. The pointer becomes null if the
633 * struct type is not known, or the data is too small for its type. */
634 for (const int i : blender::IndexRange(panel.items_num)) {
636 reader, &panel.items_array[i], item_struct_size);
637 }
638 /* Forward compatibility: Discard unknown tree interface item types that may be introduced in
639 * the future. Their pointer is set to null above. */
640 panel.items_num = std::remove_if(
641 panel.items_array,
642 panel.items_array + panel.items_num,
643 [&](const bNodeTreeInterfaceItem *item) { return item == nullptr; }) -
644 panel.items_array;
645 /* Now read the actual data if the known interface items. */
646 for (const int i : blender::IndexRange(panel.items_num)) {
647 item_read_data(reader, *panel.items_array[i]);
648 }
649 break;
650 }
651 }
652}
653
655{
656 switch (NodeTreeInterfaceItemType(item.item_type)) {
658 bNodeTreeInterfaceSocket &socket = reinterpret_cast<bNodeTreeInterfaceSocket &>(item);
659
662 BKE_lib_query_idpropertiesForeachIDLink_callback(prop, data);
663 }));
664
666 break;
667 }
669 bNodeTreeInterfacePanel &panel = reinterpret_cast<bNodeTreeInterfacePanel &>(item);
670 for (bNodeTreeInterfaceItem *item : panel.items()) {
671 item_foreach_id(data, *item);
672 }
673 break;
674 }
675 }
676}
677
678/* Move all child items to the new parent. */
680{
681 switch (NodeTreeInterfaceItemType(item.item_type)) {
683 return {};
684 }
686 bNodeTreeInterfacePanel &panel = reinterpret_cast<bNodeTreeInterfacePanel &>(item);
687 return panel.items();
688 }
689 }
690 return {};
691}
692
693} // namespace item_types
694
695} // namespace blender::bke::node_interface
696
697using namespace blender::bke::node_interface;
698
699blender::bke::bNodeSocketType *bNodeTreeInterfaceSocket::socket_typeinfo() const
700{
702}
703
704blender::ColorGeometry4f bNodeTreeInterfaceSocket::socket_color() const
705{
706 blender::bke::bNodeSocketType *typeinfo = this->socket_typeinfo();
707 if (typeinfo && typeinfo->draw_color_simple) {
708 float color[4];
709 typeinfo->draw_color_simple(typeinfo, color);
711 }
712 return blender::ColorGeometry4f(1.0f, 0.0f, 1.0f, 1.0f);
713}
714
715bool bNodeTreeInterfaceSocket::set_socket_type(const StringRef new_socket_type)
716{
717 const std::optional<StringRef> idname = socket_types::try_get_supported_socket_type(
718 new_socket_type);
719 if (!idname) {
720 return false;
721 }
722
723 if (this->socket_data != nullptr) {
726 }
728
729 this->socket_type = BLI_strdupn(new_socket_type.data(), new_socket_type.size());
730 this->socket_data = socket_types::make_socket_data(new_socket_type);
731
732 blender::bke::bNodeSocketType *stype = this->socket_typeinfo();
734 *stype, NodeDefaultInputType(this->default_input)))
735 {
737 }
738
739 return true;
740}
741
742void bNodeTreeInterfaceSocket::init_from_socket_instance(const bNodeSocket *socket)
743{
744 const std::optional<StringRef> idname = socket_types::try_get_supported_socket_type(
745 socket->idname);
746 BLI_assert(idname.has_value());
747
748 if (this->socket_data != nullptr) {
751 }
753 if (socket->flag & SOCK_HIDE_VALUE) {
755 }
756
757 this->socket_type = BLI_strdupn(idname->data(), idname->size());
760}
761
762blender::IndexRange bNodeTreeInterfacePanel::items_range() const
763{
764 return blender::IndexRange(items_num);
765}
766
767blender::Span<const bNodeTreeInterfaceItem *> bNodeTreeInterfacePanel::items() const
768{
769 return blender::Span(items_array, items_num);
770}
771
772blender::MutableSpan<bNodeTreeInterfaceItem *> bNodeTreeInterfacePanel::items()
773{
774 return blender::MutableSpan(items_array, items_num);
775}
776
777bool bNodeTreeInterfacePanel::contains(const bNodeTreeInterfaceItem &item) const
778{
779 return items().contains(&item);
780}
781
782bool bNodeTreeInterfacePanel::contains_recursive(const bNodeTreeInterfaceItem &item) const
783{
784 bool is_child = false;
785 /* Have to capture item address here instead of just a reference,
786 * otherwise pointer comparison will not work. */
787 this->foreach_item(
788 [&](const bNodeTreeInterfaceItem &titem) {
789 if (&titem == &item) {
790 is_child = true;
791 return false;
792 }
793 return true;
794 },
795 true);
796 return is_child;
797}
798
799int bNodeTreeInterfacePanel::item_position(const bNodeTreeInterfaceItem &item) const
800{
801 return items().first_index_try(&item);
802}
803
804int bNodeTreeInterfacePanel::item_index(const bNodeTreeInterfaceItem &item) const
805{
806 int index = 0;
807 bool found = false;
808 /* Have to capture item address here instead of just a reference,
809 * otherwise pointer comparison will not work. */
810 this->foreach_item([&](const bNodeTreeInterfaceItem &titem) {
811 if (&titem == &item) {
812 found = true;
813 return false;
814 }
815 ++index;
816 return true;
817 });
818 return found ? index : -1;
819}
820
821const bNodeTreeInterfaceItem *bNodeTreeInterfacePanel::item_at_index(int index) const
822{
823 int i = 0;
824 const bNodeTreeInterfaceItem *result = nullptr;
825 this->foreach_item([&](const bNodeTreeInterfaceItem &item) {
826 if (i == index) {
827 result = &item;
828 return false;
829 }
830 ++i;
831 return true;
832 });
833 return result;
834}
835
836bNodeTreeInterfacePanel *bNodeTreeInterfacePanel::find_parent_recursive(
837 const bNodeTreeInterfaceItem &item)
838{
839 std::queue<bNodeTreeInterfacePanel *> queue;
840
841 if (this->contains(item)) {
842 return this;
843 }
844 queue.push(this);
845
846 while (!queue.empty()) {
847 bNodeTreeInterfacePanel *parent = queue.front();
848 queue.pop();
849
850 for (bNodeTreeInterfaceItem *titem : parent->items()) {
851 if (titem->item_type != NODE_INTERFACE_PANEL) {
852 continue;
853 }
854
856 if (tpanel->contains(item)) {
857 return tpanel;
858 }
859 queue.push(tpanel);
860 }
861 }
862
863 return nullptr;
864}
865
866int bNodeTreeInterfacePanel::find_valid_insert_position_for_item(
867 const bNodeTreeInterfaceItem &item, const int initial_pos) const
868{
869 const bool sockets_above_panels = !(this->flag &
871 const blender::Span<const bNodeTreeInterfaceItem *> items = this->items();
872
873 /* True if item a should be above item b. */
874 auto must_be_before = [sockets_above_panels](const bNodeTreeInterfaceItem &a,
875 const bNodeTreeInterfaceItem &b) -> bool {
876 /* Keep sockets above panels. */
877 if (sockets_above_panels) {
878 if (a.item_type == NODE_INTERFACE_SOCKET && b.item_type == NODE_INTERFACE_PANEL) {
879 return true;
880 }
881 }
882 /* Keep outputs above inputs. */
883 if (a.item_type == NODE_INTERFACE_SOCKET && b.item_type == NODE_INTERFACE_SOCKET) {
884 const auto &sa = reinterpret_cast<const bNodeTreeInterfaceSocket &>(a);
885 const auto &sb = reinterpret_cast<const bNodeTreeInterfaceSocket &>(b);
886 const bool is_output_a = sa.flag & NODE_INTERFACE_SOCKET_OUTPUT;
887 const bool is_output_b = sb.flag & NODE_INTERFACE_SOCKET_OUTPUT;
888 if ((sa.flag & NODE_INTERFACE_SOCKET_PANEL_TOGGLE) ||
890 {
891 /* Panel toggle inputs are allowed to be above outputs. */
892 return false;
893 }
894 if (is_output_a && !is_output_b) {
895 return true;
896 }
897 }
898 return false;
899 };
900
901 int min_pos = 0;
902 for (const int i : items.index_range()) {
903 if (must_be_before(*items[i], item)) {
904 min_pos = i + 1;
905 }
906 }
907 int max_pos = items.size();
908 for (const int i : items.index_range()) {
909 if (must_be_before(item, *items[i])) {
910 max_pos = i;
911 break;
912 }
913 }
914 BLI_assert(min_pos <= max_pos);
915 return std::clamp(initial_pos, min_pos, max_pos);
916}
917
918void bNodeTreeInterfacePanel::add_item(bNodeTreeInterfaceItem &item)
919{
920 /* Same as inserting at the end. */
921 insert_item(item, this->items_num);
922}
923
924void bNodeTreeInterfacePanel::insert_item(bNodeTreeInterfaceItem &item, int position)
925{
926 /* Apply any constraints on the item positions. */
927 position = find_valid_insert_position_for_item(item, position);
928 position = std::min(std::max(position, 0), items_num);
929
930 blender::MutableSpan<bNodeTreeInterfaceItem *> old_items = this->items();
931 items_num++;
933 this->items().take_front(position).copy_from(old_items.take_front(position));
934 this->items().drop_front(position + 1).copy_from(old_items.drop_front(position));
935 this->items()[position] = &item;
936
937 if (old_items.data()) {
938 MEM_freeN(old_items.data());
939 }
940}
941
942bool bNodeTreeInterfacePanel::remove_item(bNodeTreeInterfaceItem &item, const bool free)
943{
944 const int position = this->item_position(item);
945 if (!this->items().index_range().contains(position)) {
946 return false;
947 }
948
949 blender::MutableSpan<bNodeTreeInterfaceItem *> old_items = this->items();
950 items_num--;
952 this->items().take_front(position).copy_from(old_items.take_front(position));
953 this->items().drop_front(position).copy_from(old_items.drop_front(position + 1));
954
955 /* Guaranteed not empty, contains at least the removed item */
956 MEM_freeN(old_items.data());
957
958 if (free) {
960 }
961
962 return true;
963}
964
965void bNodeTreeInterfacePanel::clear(bool do_id_user)
966{
967 for (bNodeTreeInterfaceItem *item : this->items()) {
968 item_types::item_free(*item, do_id_user);
969 }
971 items_array = nullptr;
972 items_num = 0;
973}
974
975bool bNodeTreeInterfacePanel::move_item(bNodeTreeInterfaceItem &item, int new_position)
976{
977 const int old_position = this->item_position(item);
978 if (!this->items().index_range().contains(old_position)) {
979 return false;
980 }
981 if (old_position == new_position) {
982 /* Nothing changes. */
983 return true;
984 }
985
986 new_position = find_valid_insert_position_for_item(item, new_position);
987 new_position = std::min(std::max(new_position, 0), items_num);
988
989 if (old_position < new_position) {
990 /* Actual target position and all existing items shifted by 1. */
991 const blender::Span<bNodeTreeInterfaceItem *> moved_items = this->items().slice(
992 old_position + 1, new_position - old_position - 1);
993 bNodeTreeInterfaceItem *tmp = this->items()[old_position];
994 std::copy(
995 moved_items.begin(), moved_items.end(), this->items().drop_front(old_position).data());
996 this->items()[new_position - 1] = tmp;
997 }
998 else /* old_position > new_position */ {
999 const blender::Span<bNodeTreeInterfaceItem *> moved_items = this->items().slice(
1000 new_position, old_position - new_position);
1001 bNodeTreeInterfaceItem *tmp = this->items()[old_position];
1002 std::copy_backward(
1003 moved_items.begin(), moved_items.end(), this->items().drop_front(old_position + 1).data());
1004 this->items()[new_position] = tmp;
1005 }
1006
1007 return true;
1008}
1009
1010void bNodeTreeInterfacePanel::foreach_item(
1011 blender::FunctionRef<bool(bNodeTreeInterfaceItem &item)> fn, bool include_self)
1012{
1013 using ItemSpan = blender::Span<bNodeTreeInterfaceItem *>;
1014 blender::Stack<ItemSpan> stack;
1015
1016 if (include_self && fn(this->item) == false) {
1017 return;
1018 }
1019 stack.push(this->items());
1020
1021 while (!stack.is_empty()) {
1022 const ItemSpan current_items = stack.pop();
1023
1024 for (const int index : current_items.index_range()) {
1025 bNodeTreeInterfaceItem *item = current_items[index];
1026 if (fn(*item) == false) {
1027 return;
1028 }
1029
1031 bNodeTreeInterfacePanel *panel = reinterpret_cast<bNodeTreeInterfacePanel *>(item);
1032 /* Reinsert remaining items. */
1033 if (index < current_items.size() - 1) {
1034 const ItemSpan remaining_items = current_items.drop_front(index + 1);
1035 stack.push(remaining_items);
1036 }
1037 /* Handle child items first before continuing with current span. */
1038 stack.push(panel->items());
1039 break;
1040 }
1041 }
1042 }
1043}
1044
1045void bNodeTreeInterfacePanel::foreach_item(
1046 blender::FunctionRef<bool(const bNodeTreeInterfaceItem &item)> fn, bool include_self) const
1047{
1048 using ItemSpan = blender::Span<const bNodeTreeInterfaceItem *>;
1049 blender::Stack<ItemSpan> stack;
1050
1051 if (include_self && fn(this->item) == false) {
1052 return;
1053 }
1054 stack.push(this->items());
1055
1056 while (!stack.is_empty()) {
1057 const ItemSpan current_items = stack.pop();
1058
1059 for (const int index : current_items.index_range()) {
1060 const bNodeTreeInterfaceItem *item = current_items[index];
1061 if (fn(*item) == false) {
1062 return;
1063 }
1064
1066 const bNodeTreeInterfacePanel *panel = reinterpret_cast<const bNodeTreeInterfacePanel *>(
1067 item);
1068 /* Reinsert remaining items. */
1069 if (index < current_items.size() - 1) {
1070 const ItemSpan remaining_items = current_items.drop_front(index + 1);
1071 stack.push(remaining_items);
1072 }
1073 /* Handle child items first before continuing with current span. */
1074 stack.push(panel->items());
1075 break;
1076 }
1077 }
1078 }
1079}
1080
1081const bNodeTreeInterfaceSocket *bNodeTreeInterfacePanel::header_toggle_socket() const
1082{
1083 if (this->items().is_empty()) {
1084 return nullptr;
1085 }
1086 const bNodeTreeInterfaceItem *first_item = this->items().first();
1087 if (first_item->item_type != NODE_INTERFACE_SOCKET) {
1088 return nullptr;
1089 }
1090 const auto &socket = *reinterpret_cast<const bNodeTreeInterfaceSocket *>(first_item);
1091 if (!(socket.flag & NODE_INTERFACE_SOCKET_INPUT) ||
1093 {
1094 return nullptr;
1095 }
1096 const blender::bke::bNodeSocketType *typeinfo = socket.socket_typeinfo();
1097 if (!typeinfo || typeinfo->type != SOCK_BOOLEAN) {
1098 return nullptr;
1099 }
1100 return &socket;
1101}
1102bNodeTreeInterfaceSocket *bNodeTreeInterfacePanel::header_toggle_socket()
1103{
1104 return const_cast<bNodeTreeInterfaceSocket *>(
1105 const_cast<const bNodeTreeInterfacePanel *>(this)->header_toggle_socket());
1106}
1107
1109
1111 const StringRef name,
1112 const StringRef description,
1113 const StringRef socket_type,
1114 const NodeTreeInterfaceSocketFlag flag)
1115{
1116 BLI_assert(!socket_type.is_empty());
1117
1118 const std::optional<StringRef> idname = socket_types::try_get_supported_socket_type(socket_type);
1119 if (!idname) {
1120 return nullptr;
1121 }
1122
1124 BLI_assert(new_socket);
1125
1126 /* Init common socket properties. */
1127 new_socket->identifier = BLI_sprintfN("Socket_%d", uid);
1128 new_socket->item.item_type = NODE_INTERFACE_SOCKET;
1129 new_socket->name = BLI_strdupn(name.data(), name.size());
1130 new_socket->description = description.is_empty() ?
1131 nullptr :
1132 BLI_strdupn(description.data(), description.size());
1133 new_socket->socket_type = BLI_strdupn(socket_type.data(), socket_type.size());
1134 new_socket->flag = flag;
1135
1136 new_socket->socket_data = socket_types::make_socket_data(socket_type);
1137
1138 return new_socket;
1139}
1140
1142 const bNode &from_node,
1143 const bNodeSocket &from_sock,
1144 const StringRef socket_type,
1145 const StringRef name)
1146{
1147 ntree.ensure_topology_cache();
1148 bNodeTreeInterfaceSocket *iosock = nullptr;
1149 if (from_node.is_group()) {
1150 if (const bNodeTree *group = reinterpret_cast<const bNodeTree *>(from_node.id)) {
1151 /* Copy interface socket directly from source group to avoid loosing data in the process. */
1152 group->ensure_interface_cache();
1153 const bNodeTreeInterfaceSocket &src_io_socket =
1154 from_sock.is_input() ? *group->interface_inputs()[from_sock.index()] :
1155 *group->interface_outputs()[from_sock.index()];
1156 iosock = reinterpret_cast<bNodeTreeInterfaceSocket *>(
1157 ntree.tree_interface.add_item_copy(src_io_socket.item, nullptr));
1158 }
1159 }
1160 if (!iosock) {
1164
1165 const nodes::SocketDeclaration *decl = from_sock.runtime->declaration;
1166 StringRef description = from_sock.description;
1167 if (decl) {
1168 if (!decl->description.empty()) {
1169 description = decl->description;
1170 }
1171 }
1172
1173 iosock = ntree.tree_interface.add_socket(name, description, socket_type, flag, nullptr);
1174
1175 if (iosock) {
1176 if (decl) {
1177 iosock->default_input = decl->default_input_type;
1178 }
1179 }
1180 }
1181 if (iosock == nullptr) {
1182 return nullptr;
1183 }
1184 const blender::bke::bNodeSocketType *typeinfo = iosock->socket_typeinfo();
1185 if (typeinfo->interface_from_socket) {
1186 typeinfo->interface_from_socket(&ntree.id, iosock, &from_node, &from_sock);
1187 }
1188 return iosock;
1189}
1190
1192 const blender::StringRef name,
1193 const blender::StringRef description,
1194 const NodeTreeInterfacePanelFlag flag)
1195{
1196 BLI_assert(!name.is_empty());
1197
1199 new_panel->item.item_type = NODE_INTERFACE_PANEL;
1200 new_panel->name = BLI_strdupn(name.data(), name.size());
1201 new_panel->description = description.is_empty() ?
1202 nullptr :
1203 BLI_strdupn(description.data(), description.size());
1204 new_panel->identifier = uid;
1205 new_panel->flag = flag;
1206 return new_panel;
1207}
1208
1209} // namespace blender::bke::node_interface
1210
1211void bNodeTreeInterface::init_data()
1212{
1213 this->runtime = MEM_new<blender::bke::bNodeTreeInterfaceRuntime>(__func__);
1214 this->tag_missing_runtime_data();
1215}
1216
1217void bNodeTreeInterface::copy_data(const bNodeTreeInterface &src, int flag)
1218{
1219 item_types::panel_init(this->root_panel, src.root_panel.items(), flag, nullptr);
1220 this->active_index = src.active_index;
1221
1222 this->runtime = MEM_new<blender::bke::bNodeTreeInterfaceRuntime>(__func__);
1223 this->tag_missing_runtime_data();
1224}
1225
1226void bNodeTreeInterface::free_data()
1227{
1228 MEM_delete(this->runtime);
1229
1230 /* Called when freeing the main database, don't do user refcount here. */
1231 this->root_panel.clear(false);
1232}
1233
1234void bNodeTreeInterface::write(BlendWriter *writer)
1235{
1236 /* Don't write the root panel struct itself, it's nested in the interface struct. */
1238}
1239
1240void bNodeTreeInterface::read_data(BlendDataReader *reader)
1241{
1242 /* Root item must be a panel, not checked elsewhere because it is embedded. */
1244 BLO_read_data_invalidate(reader, "Corrupt .blend file, invalid node tree interface.");
1246 }
1248
1249 this->runtime = MEM_new<blender::bke::bNodeTreeInterfaceRuntime>(__func__);
1250 this->tag_missing_runtime_data();
1251}
1252
1253bNodeTreeInterfaceItem *bNodeTreeInterface::active_item()
1254{
1255 bNodeTreeInterfaceItem *active = nullptr;
1256 int count = this->active_index;
1257 this->foreach_item([&](bNodeTreeInterfaceItem &item) {
1258 if (count == 0) {
1259 active = &item;
1260 return false;
1261 }
1262 --count;
1263 return true;
1264 });
1265 return active;
1266}
1267
1268const bNodeTreeInterfaceItem *bNodeTreeInterface::active_item() const
1269{
1270 const bNodeTreeInterfaceItem *active = nullptr;
1271 int count = this->active_index;
1272 this->foreach_item([&](const bNodeTreeInterfaceItem &item) {
1273 if (count == 0) {
1274 active = &item;
1275 return false;
1276 }
1277 --count;
1278 return true;
1279 });
1280 return active;
1281}
1282
1283void bNodeTreeInterface::active_item_set(bNodeTreeInterfaceItem *item)
1284{
1285 this->active_index = 0;
1286 int count = 0;
1287 this->foreach_item([&](bNodeTreeInterfaceItem &titem) {
1288 if (&titem == item) {
1289 this->active_index = count;
1290 return false;
1291 }
1292 ++count;
1293 return true;
1294 });
1295}
1296
1297bNodeTreeInterfaceSocket *bNodeTreeInterface::add_socket(const blender::StringRef name,
1298 const blender::StringRef description,
1299 const blender::StringRef socket_type,
1300 const NodeTreeInterfaceSocketFlag flag,
1302{
1303 /* Check that each interface socket is either an input or an output. Technically, it can be both
1304 * at the same time, but we don't want that for the time being. */
1307 if (parent == nullptr) {
1308 parent = &root_panel;
1309 }
1310 BLI_assert(this->find_item(parent->item));
1311
1313 this->next_uid++, name, description, socket_type, flag);
1314 if (new_socket) {
1315 parent->add_item(new_socket->item);
1316 }
1317
1318 this->tag_items_changed();
1319 return new_socket;
1320}
1321
1322bNodeTreeInterfaceSocket *bNodeTreeInterface::insert_socket(const blender::StringRef name,
1323 const blender::StringRef description,
1324 const blender::StringRef socket_type,
1325 const NodeTreeInterfaceSocketFlag flag,
1327 const int position)
1328{
1329 if (parent == nullptr) {
1330 parent = &root_panel;
1331 }
1332 BLI_assert(this->find_item(parent->item));
1333
1335 this->next_uid++, name, description, socket_type, flag);
1336 if (new_socket) {
1337 parent->insert_item(new_socket->item, position);
1338 }
1339
1340 this->tag_items_changed();
1341 return new_socket;
1342}
1343
1344bNodeTreeInterfacePanel *bNodeTreeInterface::add_panel(const blender::StringRef name,
1345 const blender::StringRef description,
1346 const NodeTreeInterfacePanelFlag flag,
1348{
1349 if (parent == nullptr) {
1350 parent = &root_panel;
1351 }
1352 BLI_assert(this->find_item(parent->item));
1353
1354 bNodeTreeInterfacePanel *new_panel = make_panel(this->next_uid++, name, description, flag);
1355 if (new_panel) {
1356 parent->add_item(new_panel->item);
1357 }
1358
1359 this->tag_items_changed();
1360 return new_panel;
1361}
1362
1363bNodeTreeInterfacePanel *bNodeTreeInterface::insert_panel(const blender::StringRef name,
1364 const blender::StringRef description,
1365 const NodeTreeInterfacePanelFlag flag,
1367 const int position)
1368{
1369 if (parent == nullptr) {
1370 parent = &root_panel;
1371 }
1372 BLI_assert(this->find_item(parent->item));
1373
1374 bNodeTreeInterfacePanel *new_panel = make_panel(this->next_uid++, name, description, flag);
1375 if (new_panel) {
1376 parent->insert_item(new_panel->item, position);
1377 }
1378
1379 this->tag_items_changed();
1380 return new_panel;
1381}
1382
1383bNodeTreeInterfaceItem *bNodeTreeInterface::add_item_copy(const bNodeTreeInterfaceItem &item,
1385{
1386 if (parent == nullptr) {
1387 parent = &root_panel;
1388 }
1389 BLI_assert(this->find_item(parent->item));
1390
1391 bNodeTreeInterfaceItem *citem = static_cast<bNodeTreeInterfaceItem *>(MEM_dupallocN(&item));
1392 item_types::item_copy(*citem, item, 0, [&]() { return this->next_uid++; });
1393 parent->add_item(*citem);
1394
1395 this->tag_items_changed();
1396 return citem;
1397}
1398
1399bNodeTreeInterfaceItem *bNodeTreeInterface::insert_item_copy(const bNodeTreeInterfaceItem &item,
1401 int position)
1402{
1403 if (parent == nullptr) {
1404 parent = &root_panel;
1405 }
1406 BLI_assert(this->find_item(item));
1407 BLI_assert(this->find_item(parent->item));
1408
1409 bNodeTreeInterfaceItem *citem = static_cast<bNodeTreeInterfaceItem *>(MEM_dupallocN(&item));
1410 item_types::item_copy(*citem, item, 0, [&]() { return this->next_uid++; });
1411 parent->insert_item(*citem, position);
1412
1413 this->tag_items_changed();
1414 return citem;
1415}
1416
1417bool bNodeTreeInterface::remove_item(bNodeTreeInterfaceItem &item, bool move_content_to_parent)
1418{
1419 bNodeTreeInterfacePanel *parent = this->find_item_parent(item, true);
1420 if (parent == nullptr) {
1421 return false;
1422 }
1423 if (move_content_to_parent) {
1424 int position = parent->item_position(item);
1425 /* Cache children to avoid invalidating the iterator. */
1426 blender::Array<bNodeTreeInterfaceItem *> children(item_types::item_children(item));
1427 for (bNodeTreeInterfaceItem *child : children) {
1428 this->move_item_to_parent(*child, parent, position++);
1429 }
1430 }
1431 if (parent->remove_item(item, true)) {
1432 this->tag_items_changed();
1433 return true;
1434 }
1435
1436 return false;
1437}
1438
1439void bNodeTreeInterface::clear_items()
1440{
1441 root_panel.clear(true);
1442 this->tag_items_changed();
1443}
1444
1445bool bNodeTreeInterface::move_item(bNodeTreeInterfaceItem &item, const int new_position)
1446{
1447 bNodeTreeInterfacePanel *parent = this->find_item_parent(item, true);
1448 if (parent == nullptr) {
1449 return false;
1450 }
1451
1452 if (parent->move_item(item, new_position)) {
1453 this->tag_items_changed();
1454 return true;
1455 }
1456 return false;
1457}
1458
1459bool bNodeTreeInterface::move_item_to_parent(bNodeTreeInterfaceItem &item,
1460 bNodeTreeInterfacePanel *new_parent,
1461 int new_position)
1462{
1463 if (new_parent == nullptr) {
1464 new_parent = &this->root_panel;
1465 }
1466
1467 if (item.item_type == NODE_INTERFACE_PANEL) {
1468 bNodeTreeInterfacePanel &src_item = reinterpret_cast<bNodeTreeInterfacePanel &>(item);
1469 if (src_item.contains_recursive(new_parent->item)) {
1470 return false;
1471 }
1472 }
1473
1474 bNodeTreeInterfacePanel *parent = this->find_item_parent(item, true);
1475 if (parent == nullptr) {
1476 return false;
1477 }
1478
1479 if (parent == new_parent) {
1480 if (parent->move_item(item, new_position)) {
1481 this->tag_items_changed();
1482 return true;
1483 }
1484 }
1485 else {
1486 /* NOTE: only remove and reinsert when parents different, otherwise removing the item can
1487 * change the desired target position! */
1488 if (parent->remove_item(item, false)) {
1489 new_parent->insert_item(item, new_position);
1490 this->tag_items_changed();
1491 return true;
1492 }
1493 }
1494 return false;
1495}
1496
1497void bNodeTreeInterface::foreach_id(LibraryForeachIDData *cb)
1498{
1500}
1501
1502bool bNodeTreeInterface::items_cache_is_available() const
1503{
1504 return !this->runtime->items_cache_mutex_.is_dirty();
1505}
1506
1507void bNodeTreeInterface::ensure_items_cache() const
1508{
1509 blender::bke::bNodeTreeInterfaceRuntime &runtime = *this->runtime;
1510
1511 runtime.items_cache_mutex_.ensure([&]() {
1512 /* Rebuild draw-order list of interface items for linear access. */
1513 runtime.items_.clear();
1514 runtime.inputs_.clear();
1515 runtime.outputs_.clear();
1516
1517 /* Items in the cache are mutable pointers, but node tree update considers ID data to be
1518 * immutable when caching. DNA ListBase pointers can be mutable even if their container is
1519 * const, but the items returned by #foreach_item inherit qualifiers from the container. */
1520 bNodeTreeInterface &mutable_self = const_cast<bNodeTreeInterface &>(*this);
1521
1522 mutable_self.foreach_item([&](bNodeTreeInterfaceItem &item) {
1523 runtime.items_.add_new(&item);
1525 if (socket->flag & NODE_INTERFACE_SOCKET_INPUT) {
1526 runtime.inputs_.add_new(socket);
1527 }
1528 if (socket->flag & NODE_INTERFACE_SOCKET_OUTPUT) {
1529 runtime.outputs_.add_new(socket);
1530 }
1531 }
1532 return true;
1533 });
1534 });
1535}
1536
1537void bNodeTreeInterface::tag_interface_changed()
1538{
1539 this->runtime->interface_changed_.store(true);
1540}
1541
1542bool bNodeTreeInterface::requires_dependent_tree_updates() const
1543{
1544 return this->runtime->interface_changed_.load(std::memory_order_relaxed);
1545}
1546
1547void bNodeTreeInterface::tag_items_changed()
1548{
1549 this->tag_interface_changed();
1550 this->runtime->items_cache_mutex_.tag_dirty();
1551}
1552
1553void bNodeTreeInterface::tag_items_changed_generic()
1554{
1555 /* Perform a full update since we don't know what changed exactly. */
1556 this->tag_items_changed();
1557}
1558
1559void bNodeTreeInterface::tag_item_property_changed()
1560{
1561 this->tag_interface_changed();
1562}
1563
1564void bNodeTreeInterface::tag_missing_runtime_data()
1565{
1566 this->tag_items_changed();
1567}
1568
1569void bNodeTreeInterface::reset_interface_changed()
1570{
1571 this->runtime->interface_changed_.store(false);
1572}
void IDP_foreach_property(IDProperty *id_property_root, int type_filter, blender::FunctionRef< void(IDProperty *id_property)> callback)
#define IDP_BlendDataRead(reader, prop)
void IDP_FreePropertyContent_ex(IDProperty *prop, bool do_id_user)
Definition idprop.cc:1205
IDProperty * IDP_CopyProperty_ex(const IDProperty *prop, int flag) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:855
void IDP_BlendWrite(BlendWriter *writer, const IDProperty *prop)
Definition idprop.cc:1453
void id_us_plus(ID *id)
Definition lib_id.cc:353
void id_us_min(ID *id)
Definition lib_id.cc:361
@ LIB_ID_CREATE_NO_USER_REFCOUNT
#define BKE_LIB_FOREACHID_PROCESS_FUNCTION_CALL(data_, func_call_)
#define BKE_LIB_FOREACHID_PROCESS_IDSUPER(data_, id_super_, cb_flag_)
@ IDWALK_CB_USER
#define BLI_assert(a)
Definition BLI_assert.h:46
void BLI_kdtree_nd_ free(KDTree *tree)
MINLINE void copy_v4_v4(float r[4], const float a[4])
MINLINE void copy_v3_v3(float r[3], const float a[3])
char * BLI_sprintfN(const char *__restrict format,...) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_PRINTF_FORMAT(1
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
Definition string.cc:41
char * BLI_strdupn(const char *str, size_t len) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition string.cc:30
char * BLI_strdup_null(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_MALLOC
Definition string.cc:46
#define SET_FLAG_FROM_TEST(value, test, flag)
#define BLO_read_data_address(reader, ptr_p)
void BLO_read_data_invalidate(BlendDataReader *reader, const char *message)
Definition readfile.cc:5937
#define BLO_write_struct(writer, struct_name, data_ptr)
void BLO_read_string(BlendDataReader *reader, char **ptr_p)
Definition readfile.cc:5783
void BLO_write_string(BlendWriter *writer, const char *data_ptr)
void BLO_read_struct_with_type_size(BlendDataReader *reader, T **ptr_p, blender::FunctionRef< size_t(const T &data)> type_size_fn)
#define BLO_read_struct(reader, struct_name, ptr_p)
void BLO_write_pointer_array(BlendWriter *writer, int64_t num, const void *data_ptr)
void BLO_read_pointer_array(BlendDataReader *reader, int64_t array_size, void **ptr_p)
Definition readfile.cc:5834
@ IDP_TYPE_FILTER_ID
Object groups, one object can be in many groups at once.
@ NODE_INTERFACE_PANEL_ALLOW_SOCKETS_AFTER_PANELS
@ NODE_INTERFACE_SOCKET_SINGLE_VALUE_ONLY_LEGACY
@ NODE_INTERFACE_SOCKET_PANEL_TOGGLE
@ NODE_INTERFACE_SOCKET_HIDE_VALUE
struct bNodeTreeInterface bNodeTreeInterface
struct bNodeTreeInterfaceSocket bNodeTreeInterfaceSocket
struct bNodeTreeInterfacePanel bNodeTreeInterfacePanel
@ NODE_INTERFACE_SOCKET_STRUCTURE_TYPE_SINGLE
struct bNodeTreeInterfaceItem bNodeTreeInterfaceItem
@ SOCK_OUT
@ SOCK_IN
@ SOCK_HIDE_VALUE
@ SOCK_BOOLEAN
@ PROP_NONE
Definition RNA_types.hh:221
BMesh const char void * data
void add_new(const Key &key)
void ensure(FunctionRef< void()> compute_cache)
constexpr T * data() const
Definition BLI_span.hh:539
constexpr MutableSpan drop_front(const int64_t n) const
Definition BLI_span.hh:607
constexpr MutableSpan take_front(const int64_t n) const
Definition BLI_span.hh:629
constexpr Span drop_front(int64_t n) const
Definition BLI_span.hh:171
constexpr Span slice(int64_t start, int64_t size) const
Definition BLI_span.hh:137
constexpr const T & first() const
Definition BLI_span.hh:315
constexpr int64_t size() const
Definition BLI_span.hh:252
constexpr const T * end() const
Definition BLI_span.hh:224
constexpr IndexRange index_range() const
Definition BLI_span.hh:401
constexpr const T * begin() const
Definition BLI_span.hh:220
constexpr Span take_front(int64_t n) const
Definition BLI_span.hh:193
bool is_empty() const
Definition BLI_stack.hh:308
void push(const T &value)
Definition BLI_stack.hh:213
constexpr bool is_empty() const
constexpr int64_t size() const
constexpr const char * data() const
#define active
#define this
#define MEM_SAFE_FREE(v)
void * MEM_calloc_arrayN(size_t len, size_t size, const char *str)
Definition mallocn.cc:123
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void * MEM_dupallocN(const void *vmemh)
Definition mallocn.cc:143
void MEM_freeN(void *vmemh)
Definition mallocn.cc:113
void item_write_struct(BlendWriter *writer, bNodeTreeInterfaceItem &item)
static void item_copy(bNodeTreeInterfaceItem &dst, const bNodeTreeInterfaceItem &src, int flag, UidGeneratorFn generate_uid)
static size_t item_struct_size(const bNodeTreeInterfaceItem &item)
static void item_free(bNodeTreeInterfaceItem &item, const bool do_id_user)
static void item_write_data(BlendWriter *writer, bNodeTreeInterfaceItem &item)
static Span< bNodeTreeInterfaceItem * > item_children(bNodeTreeInterfaceItem &item)
static void item_read_data(BlendDataReader *reader, bNodeTreeInterfaceItem &item)
static void item_foreach_id(LibraryForeachIDData *data, bNodeTreeInterfaceItem &item)
static void panel_init(bNodeTreeInterfacePanel &panel, const Span< const bNodeTreeInterfaceItem * > items_src, const int flag, UidGeneratorFn generate_uid)
static std::optional< StringRef > try_get_supported_socket_type(const StringRef socket_type)
static void socket_data_read_data(BlendDataReader *reader, bNodeTreeInterfaceSocket &socket)
void socket_data_foreach_id_impl(LibraryForeachIDData *, T &)
static void * make_socket_data(const StringRef socket_type)
static void socket_data_free(bNodeTreeInterfaceSocket &socket, const bool do_id_user)
void socket_data_to_static_type_tag(const StringRef socket_type, const Fn &fn)
static void socket_data_write(BlendWriter *writer, bNodeTreeInterfaceSocket &socket)
static void socket_data_foreach_id(LibraryForeachIDData *data, bNodeTreeInterfaceSocket &socket)
static void socket_data_copy(bNodeTreeInterfaceSocket &dst, const bNodeTreeInterfaceSocket &src, int flag)
static void socket_data_copy_ptr(bNodeTreeInterfaceSocket &dst, const void *src_socket_data, int flag)
void socket_data_write_impl(BlendWriter *writer, bNodeSocketValueFloat &data)
void socket_data_read_data_impl(BlendDataReader *reader, T **data)
T & get_item_as(bNodeTreeInterfaceItem &item)
static bNodeTreeInterfaceSocket * make_socket(const int uid, const StringRef name, const StringRef description, const StringRef socket_type, const NodeTreeInterfaceSocketFlag flag)
bNodeTreeInterfaceSocket * add_interface_socket_from_node(bNodeTree &ntree, const bNode &from_node, const bNodeSocket &from_sock, StringRef socket_type, StringRef name)
static bNodeTreeInterfacePanel * make_panel(const int uid, const blender::StringRef name, const blender::StringRef description, const NodeTreeInterfacePanelFlag flag)
T & get_socket_data_as(bNodeTreeInterfaceSocket &item)
bNodeSocketType * node_socket_type_find(StringRef idname)
Definition node.cc:2794
std::optional< StringRefNull > node_static_socket_type(int type, int subtype, std::optional< int > dimensions=std::nullopt)
Definition node.cc:3167
bool node_is_static_socket_type(const bNodeSocketType &stype)
Definition node.cc:3158
bool socket_type_supports_default_input_type(const bke::bNodeSocketType &socket_type, const NodeDefaultInputType input_type)
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
Definition BLI_color.hh:342
#define FLT_MAX
Definition stdcycles.h:14
Definition DNA_ID.h:404
const RuntimeNodeEnumItemsHandle * enum_items
bNodeSocketRuntimeHandle * runtime
char description[64]
void * default_value
char idname[64]
bNodeTreeInterfaceItem ** items_array
bNodeTreeInterfacePanel root_panel
bNodeTreeInterfaceRuntimeHandle * runtime
bNodeTreeInterface tree_interface
struct ID * id
Defines a socket type.
Definition BKE_node.hh:152
eNodeSocketDatatype type
Definition BKE_node.hh:187
void(*) draw_color_simple(const bNodeSocketType *socket_type, float *r_color)
Definition BKE_node.hh:166
void(*) interface_from_socket(ID *id, bNodeTreeInterfaceSocket *interface_socket, const bNode *node, const bNodeSocket *socket)
Definition BKE_node.hh:177
i
Definition text_draw.cc:230