Blender V5.3
DNA_node_tree_interface_types.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2005 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include "BLI_color_types.hh"
12#include "BLI_enum_flags.hh"
13#include "BLI_function_ref.hh"
14#include "BLI_span.hh"
15#include "BLI_string_ref.hh"
16#include "BLI_sys_types.hh"
17
18namespace blender {
19
20namespace bke {
22struct bNodeSocketType;
23} // namespace bke
24
25struct bNodeSocket;
29struct ID;
30struct IDProperty;
32struct BlendWriter;
33struct BlendDataReader;
34
36enum class NodeTreeInterfaceItemType : char {
37 Panel = 0,
38 Socket = 1,
39};
40
44 char _pad[7] = {};
45
46#ifdef __cplusplus
47 void set_selected(bool select);
48#endif
49};
50
51/* Socket interface flags */
58 /* To be deprecated when structure types are moved out of experimental. */
61 /* INSPECT is used by Connect to Output operator to ensure socket that exits from node group. */
63 /* Socket is used in the panel header as a toggle. */
65 /* Menu socket should be drawn expanded instead of as drop-down menu. */
72 /* Whether the socket is selected in the node group interface tree view. */
74};
76
85
86// TODO: Move out of DNA.
87#ifdef __cplusplus
88namespace nodes {
89enum class StructureType : int8_t {
95};
96}
97#endif
98
99/* Panel interface flags */
101 /* Panel starts closed on new node instances. */
103 /* In the past, not all panels allowed child panels. Now all allow them. */
105 /* Allow adding sockets after panels. */
107 /* Whether the panel is collapsed in the node group interface tree view. */
109 /* Whether the panel is selected in the node group interface tree view. */
111};
113
127
130
131 /* UI name of the socket. */
132 char *name_ = nullptr;
133 char *description_ = nullptr;
134 /* Type idname of the socket to generate, e.g. "NodeSocketFloat". */
135 char *socket_type = nullptr;
137
138 /* AttrDomain */
141 char *default_attribute_name = nullptr;
142
143 /* Unique identifier for generated sockets. */
144 char *identifier = nullptr;
145 /* Socket default value and associated data, e.g. bNodeSocketValueFloat. */
146 void *socket_data = nullptr;
147
148 struct IDProperty *properties = nullptr;
149
151
152 /* Needed to ensure forward compatibility of PROP_PIXEL socket subtype. */
154
155 char _pad[6] = {};
156
157#ifdef __cplusplus
158 StringRefNull name() const;
159 StringRefNull description() const;
160
161 bke::bNodeSocketType *socket_typeinfo() const;
162 ColorGeometry4f socket_color() const;
163
168 bool set_socket_type(StringRef new_socket_type);
177 void update_socket_type();
178
183 void init_from_socket_instance(const bNodeSocket *socket);
184#endif
185};
186
189
190 /* UI name of the panel. */
191 char *name_ = nullptr;
192 char *description_ = nullptr;
194 char _pad[4] = {};
195
197 int items_num = 0;
198
199 /* Internal unique identifier for validating panel states. */
200 int identifier = 0;
201
202#ifdef __cplusplus
203 StringRefNull name() const;
204 StringRefNull description() const;
205
206 IndexRange items_range() const;
209
213 bool contains(const bNodeTreeInterfaceItem &item) const;
218 bool contains_recursive(const bNodeTreeInterfaceItem &item) const;
224 int item_position(const bNodeTreeInterfaceItem &item) const;
229 int item_index(const bNodeTreeInterfaceItem &item) const;
233 const bNodeTreeInterfaceItem *item_at_index(int index) const;
238 bNodeTreeInterfacePanel *find_parent_recursive(const bNodeTreeInterfaceItem &item);
239
241 void clear(bool do_id_user);
242
247 void add_item(bNodeTreeInterfaceItem &item);
252 void insert_item(bNodeTreeInterfaceItem &item, int position);
258 bool remove_item(bNodeTreeInterfaceItem &item, bool free);
263 bool move_item(bNodeTreeInterfaceItem &item, int new_position);
264
272 void foreach_item(FunctionRef<bool(bNodeTreeInterfaceItem &item)> fn, bool include_self = false);
274 void foreach_item(FunctionRef<bool(const bNodeTreeInterfaceItem &item)> fn,
275 bool include_self = false) const;
276
278 const bNodeTreeInterfaceSocket *header_toggle_socket() const;
279 bNodeTreeInterfaceSocket *header_toggle_socket();
280
281 private:
283 int find_valid_insert_position_for_item(const bNodeTreeInterfaceItem &item,
284 int initial_position) const;
285#endif
286};
287
290
291 /* Global index of the active item. */
293 int next_uid = 0;
294
296
297#ifdef __cplusplus
298
300 void init_data();
304 void copy_data(const bNodeTreeInterface &src, int flag);
308 void free_data();
309
311 void write(BlendWriter *writer);
312 void read_data(BlendDataReader *reader);
313
314 bNodeTreeInterfaceItem *active_item();
315 const bNodeTreeInterfaceItem *active_item() const;
316 void active_item_set(bNodeTreeInterfaceItem *item, bool deselect_original = true);
317
322 int find_item_position(const bNodeTreeInterfaceItem &item) const
323 {
324 /* const_cast to avoid a const version of #find_parent_recursive. */
325 const bNodeTreeInterfacePanel *parent =
326 const_cast<bNodeTreeInterfacePanel &>(root_panel).find_parent_recursive(item);
327 if (parent == nullptr || parent == &root_panel) {
328 /* Panel is the root panel. */
329 return root_panel.item_position(item);
330 }
331 return parent->item_position(item);
332 }
337 int find_item_index(const bNodeTreeInterfaceItem &item) const
338 {
339 return root_panel.item_index(item);
340 }
345 bool find_item(const bNodeTreeInterfaceItem &item) const
346 {
347 return root_panel.contains_recursive(item);
348 }
352 const bNodeTreeInterfaceItem *get_item_at_index(int index) const
353 {
354 return root_panel.item_at_index(index);
355 }
362 bNodeTreeInterfacePanel *find_item_parent(const bNodeTreeInterfaceItem &item,
363 bool include_root = false)
364 {
365 bNodeTreeInterfacePanel *parent = root_panel.find_parent_recursive(item);
366 /* Return nullptr instead the root panel. */
367 if (!include_root && parent == &root_panel) {
368 return nullptr;
369 }
370 return parent;
371 }
372
378 bNodeTreeInterfaceSocket *add_socket(StringRef name,
379 StringRef description,
380 StringRef socket_type,
382 bNodeTreeInterfacePanel *parent);
389 bNodeTreeInterfaceSocket *insert_socket(StringRef name,
390 StringRef description,
391 StringRef socket_type,
393 bNodeTreeInterfacePanel *parent,
394 int position);
395
401 bNodeTreeInterfacePanel *add_panel(StringRef name,
402 StringRef description,
404 bNodeTreeInterfacePanel *parent);
411 bNodeTreeInterfacePanel *insert_panel(StringRef name,
412 StringRef description,
414 bNodeTreeInterfacePanel *parent,
415 int position);
416
422 bNodeTreeInterfaceItem *add_item_copy(const bNodeTreeInterfaceItem &item,
423 bNodeTreeInterfacePanel *parent);
430 bNodeTreeInterfaceItem *insert_item_copy(const bNodeTreeInterfaceItem &item,
431 bNodeTreeInterfacePanel *parent,
432 int position);
433
440 bool remove_item(bNodeTreeInterfaceItem &item, bool move_content_to_parent = true);
441 void clear_items();
442
447 bool move_item(bNodeTreeInterfaceItem &item, int new_position);
454 bool move_item_to_parent(bNodeTreeInterfaceItem &item,
455 bNodeTreeInterfacePanel *new_parent,
456 int new_position);
457
465 void foreach_item(FunctionRef<bool(bNodeTreeInterfaceItem &item)> fn, bool include_root = false)
466 {
467 root_panel.foreach_item(fn, /*include_self=*/include_root);
468 }
476 void foreach_item(FunctionRef<bool(const bNodeTreeInterfaceItem &item)> fn,
477 bool include_root = false) const
478 {
479 root_panel.foreach_item(fn, /*include_self=*/include_root);
480 }
481
483 void foreach_id(LibraryForeachIDData *cb);
484
486 bool items_cache_is_available() const;
487
489 void ensure_items_cache() const;
490
492 int input_index_by_identifier(StringRef identifier) const;
494 int output_index_by_identifier(StringRef identifier) const;
495
497 bool requires_dependent_tree_updates() const;
498
500 void tag_items_changed();
502 void tag_items_changed_generic();
504 void tag_item_property_changed();
505
510 void reset_interface_changed();
511
512 private:
514 void tag_interface_changed();
516 void tag_missing_runtime_data();
517
518#endif
519};
520
521} // namespace blender
#define position
ENUM_OPERATORS(Layer::Flags)
void free(Subdiv *subdiv)
Definition subdiv.cc:192
BMesh Iterators.
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
signed char int8_t
Definition BKE_text.h:76
signed short int16_t
Definition BKE_text.h:77
NodeSocketInterfaceStructureType structure_type
bke::bNodeTreeInterfaceRuntime * runtime
Defines a socket type.
Definition BKE_node.hh:163