Blender V5.3
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
8
9#include <fmt/format.h>
10
11#include "DNA_node_types.h"
12#include "DNA_space_types.h"
14
15#include "RNA_access.hh"
16#include "RNA_define.hh"
17
18#include "WM_api.hh"
19
20#include "BKE_context.hh"
22#include "BKE_node_runtime.hh"
24
25#include "BLT_translation.hh"
26
27#include "ED_node.hh"
28#include "ED_screen.hh"
29
30#include "NOD_sync_sockets.hh"
31
32#include "node_intern.hh"
33
35
37{
38 SpaceNode &snode = *CTX_wm_space_node(&C);
39 if (!snode.edittree) {
40 return {};
41 }
42
43 std::optional<std::string> node_name;
44 PropertyRNA *node_name_prop = RNA_struct_find_property(ptr, "node_name");
45 if (RNA_property_is_set(ptr, node_name_prop)) {
46 node_name = RNA_property_string_get(ptr, node_name_prop);
47 }
48
49 Vector<bNode *> nodes_to_sync;
50 bNodeTree &tree = *snode.edittree;
51 for (bNode *node : tree.all_nodes()) {
52 if (node_name.has_value()) {
53 if (node->name != node_name) {
54 continue;
55 }
56 }
57 else {
58 if (!node->is_selected()) {
59 continue;
60 }
61 }
62 nodes_to_sync.append(node);
63 }
64 return nodes_to_sync;
65}
66
68{
69 Main &bmain = *CTX_data_main(C);
70 SpaceNode &snode = *CTX_wm_space_node(C);
71 if (!snode.edittree) {
72 return OPERATOR_CANCELLED;
73 }
74 Vector<bNode *> nodes_to_sync = get_nodes_to_sync(*C, op->ptr);
75 if (nodes_to_sync.is_empty()) {
76 return OPERATOR_CANCELLED;
77 }
78 for (bNode *node : nodes_to_sync) {
80 }
82 return OPERATOR_FINISHED;
83}
84
86{
87 Vector<bNode *> nodes_to_sync = get_nodes_to_sync(*C, ptr);
88 if (nodes_to_sync.size() != 1) {
89 return TIP_(ot->description);
90 }
91 const bNode &node = *nodes_to_sync.first();
92 std::string description = nodes::sync_node_description_get(*C, node);
93 if (description.empty()) {
94 return TIP_(ot->description);
95 }
96 return description;
97}
98
100{
101 ot->name = "Sync Sockets";
102 ot->idname = "NODE_OT_sockets_sync";
103 ot->description = "Update sockets to match what is actually used";
105
108
110
111 PropertyRNA *prop;
112 prop = RNA_def_string(ot->srna, "node_name", nullptr, 0, "Node Name", nullptr);
114}
115
120
121} // namespace blender::ed::space_node
#define TIP_(msgid)
#define C
Definition RandGen.cpp:29
int64_t size() const
void append(const T &value)
bool is_empty() const
const T & first() const
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_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
bool ED_operator_node_editable(bContext *C)
std::string RNA_property_string_get(PointerRNA *ptr, PropertyRNA *prop)
void BKE_main_ensure_invariants(Main &bmain, std::optional< Span< ID * > > modified_ids=std::nullopt)
SpaceNode * CTX_wm_space_node(const bContext *C)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
Main * CTX_data_main(const bContext *C)
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
struct bNodeTree * edittree
ed::space_node::SpaceNode_Runtime * runtime
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
std::string(*) get_description(bContext *C, wmOperatorType *ot, PointerRNA *ptr)
Definition WM_types.hh:1197
struct ReportList * reports