Blender V5.0
node_sync_sockets.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include <fmt/format.h>
6
7#include "DNA_node_types.h"
8#include "DNA_space_types.h"
10
11#include "RNA_access.hh"
12#include "RNA_define.hh"
13
14#include "WM_api.hh"
15
16#include "BKE_context.hh"
18#include "BKE_node_runtime.hh"
20
21#include "BLT_translation.hh"
22
23#include "ED_node.hh"
24#include "ED_screen.hh"
25
26#include "NOD_sync_sockets.hh"
27
28#include "node_intern.hh"
29
31
33{
34 SpaceNode &snode = *CTX_wm_space_node(&C);
35 if (!snode.edittree) {
36 return {};
37 }
38
39 std::optional<std::string> node_name;
40 PropertyRNA *node_name_prop = RNA_struct_find_property(ptr, "node_name");
41 if (RNA_property_is_set(ptr, node_name_prop)) {
42 node_name = RNA_property_string_get(ptr, node_name_prop);
43 }
44
45 Vector<bNode *> nodes_to_sync;
46 bNodeTree &tree = *snode.edittree;
47 for (bNode *node : tree.all_nodes()) {
48 if (node_name.has_value()) {
49 if (node->name != node_name) {
50 continue;
51 }
52 }
53 else {
54 if (!(node->flag & NODE_SELECT)) {
55 continue;
56 }
57 }
58 nodes_to_sync.append(node);
59 }
60 return nodes_to_sync;
61}
62
64{
65 Main &bmain = *CTX_data_main(C);
66 SpaceNode &snode = *CTX_wm_space_node(C);
67 if (!snode.edittree) {
68 return OPERATOR_CANCELLED;
69 }
70 Vector<bNode *> nodes_to_sync = get_nodes_to_sync(*C, op->ptr);
71 if (nodes_to_sync.is_empty()) {
72 return OPERATOR_CANCELLED;
73 }
74 for (bNode *node : nodes_to_sync) {
75 nodes::sync_node(*C, *node, op->reports);
76 }
78 return OPERATOR_FINISHED;
79}
80
82{
83 Vector<bNode *> nodes_to_sync = get_nodes_to_sync(*C, ptr);
84 if (nodes_to_sync.size() != 1) {
85 return TIP_(ot->description);
86 }
87 const bNode &node = *nodes_to_sync.first();
88 std::string description = nodes::sync_node_description_get(*C, node);
89 if (description.empty()) {
90 return TIP_(ot->description);
91 }
92 return description;
93}
94
96{
97 ot->name = "Sync Sockets";
98 ot->idname = "NODE_OT_sockets_sync";
99 ot->description = "Update sockets to match what is actually used";
100 ot->get_description = sockets_sync_get_description;
101
103 ot->exec = sockets_sync_exec;
104
106
107 PropertyRNA *prop;
108 prop = RNA_def_string(ot->srna, "node_name", nullptr, 0, "Node Name", nullptr);
110}
111
116
117} // namespace blender::ed::space_node
SpaceNode * CTX_wm_space_node(const bContext *C)
Main * CTX_data_main(const bContext *C)
void BKE_main_ensure_invariants(Main &bmain, std::optional< blender::Span< ID * > > modified_ids=std::nullopt)
#define TIP_(msgid)
@ NODE_SELECT
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
bool ED_operator_node_editable(bContext *C)
@ PROP_SKIP_SAVE
Definition RNA_types.hh:344
#define C
Definition RandGen.cpp:29
@ OPTYPE_UNDO
Definition WM_types.hh:182
@ OPTYPE_REGISTER
Definition WM_types.hh:180
int64_t size() const
void append(const T &value)
bool is_empty() const
const T & first() const
KDTree_3d * tree
static std::string sockets_sync_get_description(bContext *C, wmOperatorType *ot, PointerRNA *ptr)
static Vector< bNode * > get_nodes_to_sync(bContext &C, PointerRNA *ptr)
void NODE_OT_sockets_sync(wmOperatorType *ot)
Map< int, bool > & node_can_sync_cache_get(SpaceNode &snode)
static wmOperatorStatus sockets_sync_exec(bContext *C, wmOperator *op)
void sync_node(bContext &C, bNode &node, ReportList *reports)
std::string sync_node_description_get(const bContext &C, const bNode &node)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
std::string RNA_property_string_get(PointerRNA *ptr, PropertyRNA *prop)
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
SpaceNode_Runtime * runtime
struct bNodeTree * edittree
struct ReportList * reports
struct PointerRNA * ptr
PointerRNA * ptr
Definition wm_files.cc:4238
wmOperatorType * ot
Definition wm_files.cc:4237