1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
|
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The Original Code is Copyright (C) 2009 Blender Foundation.
* All rights reserved.
*/
/** \file
* \ingroup spnode
*/
#include "MEM_guardedalloc.h"
#include "DNA_node_types.h"
#include "BLI_blenlib.h"
#include "BLI_math.h"
#include "BLT_translation.h"
#include "BKE_context.h"
#include "BKE_global.h"
#include "BKE_node.h"
#include "BKE_screen.h"
#include "WM_api.h"
#include "WM_types.h"
#include "RNA_access.h"
#include "ED_gpencil.h"
#include "ED_screen.h"
#include "UI_resources.h"
#include "node_intern.h" /* own include */
/* ******************* node space & buttons ************** */
#if 0
/* poll for active nodetree */
static bool active_nodetree_poll(const bContext *C, PanelType *UNUSED(pt))
{
SpaceNode *snode = CTX_wm_space_node(C);
return (snode && snode->nodetree);
}
#endif
static bool node_sockets_poll(const bContext *C, PanelType *UNUSED(pt))
{
SpaceNode *snode = CTX_wm_space_node(C);
return (snode && snode->nodetree && G.debug_value == 777);
}
static void node_sockets_panel(const bContext *C, Panel *panel)
{
SpaceNode *snode = CTX_wm_space_node(C);
bNodeTree *ntree = (snode) ? snode->edittree : NULL;
bNode *node = (ntree) ? nodeGetActive(ntree) : NULL;
bNodeSocket *sock;
uiLayout *layout = panel->layout, *split;
char name[UI_MAX_NAME_STR];
if (ELEM(NULL, ntree, node)) {
return;
}
for (sock = node->inputs.first; sock; sock = sock->next) {
BLI_snprintf(name, sizeof(name), "%s:", sock->name);
split = uiLayoutSplit(layout, 0.35f, false);
uiItemL(split, name, ICON_NONE);
uiTemplateNodeLink(split, (bContext *)C, ntree, node, sock);
}
}
static bool node_tree_interface_poll(const bContext *C, PanelType *UNUSED(pt))
{
SpaceNode *snode = CTX_wm_space_node(C);
return (snode && snode->edittree &&
(snode->edittree->inputs.first || snode->edittree->outputs.first));
}
static bool node_tree_find_active_socket(bNodeTree *ntree, bNodeSocket **r_sock, int *r_in_out)
{
bNodeSocket *sock;
for (sock = ntree->inputs.first; sock; sock = sock->next) {
if (sock->flag & SELECT) {
*r_sock = sock;
*r_in_out = SOCK_IN;
return true;
}
}
for (sock = ntree->outputs.first; sock; sock = sock->next) {
if (sock->flag & SELECT) {
*r_sock = sock;
*r_in_out = SOCK_OUT;
return true;
}
}
*r_sock = NULL;
*r_in_out = 0;
return false;
}
static void node_tree_interface_panel(const bContext *C, Panel *panel)
{
SpaceNode *snode = CTX_wm_space_node(C);
bNodeTree *ntree = (snode) ? snode->edittree : NULL;
bNodeSocket *sock;
int in_out;
uiLayout *layout = panel->layout, *row, *split, *col;
PointerRNA ptr, sockptr, opptr;
wmOperatorType *ot;
if (!ntree) {
return;
}
RNA_id_pointer_create((ID *)ntree, &ptr);
node_tree_find_active_socket(ntree, &sock, &in_out);
RNA_pointer_create((ID *)ntree, &RNA_NodeSocketInterface, sock, &sockptr);
row = uiLayoutRow(layout, false);
split = uiLayoutRow(row, true);
col = uiLayoutColumn(split, true);
ot = WM_operatortype_find("NODE_OT_tree_socket_add", false);
uiItemL(col, IFACE_("Inputs:"), ICON_NONE);
uiTemplateList(col,
(bContext *)C,
"NODE_UL_interface_sockets",
"inputs",
&ptr,
"inputs",
&ptr,
"active_input",
NULL,
0,
0,
0,
0,
false,
false);
uiItemFullO_ptr(col, ot, "", ICON_PLUS, NULL, WM_OP_EXEC_DEFAULT, 0, &opptr);
RNA_enum_set(&opptr, "in_out", SOCK_IN);
col = uiLayoutColumn(split, true);
uiItemL(col, IFACE_("Outputs:"), ICON_NONE);
uiTemplateList(col,
(bContext *)C,
"NODE_UL_interface_sockets",
"outputs",
&ptr,
"outputs",
&ptr,
"active_output",
NULL,
0,
0,
0,
0,
false,
false);
uiItemFullO_ptr(col, ot, "", ICON_PLUS, NULL, WM_OP_EXEC_DEFAULT, 0, &opptr);
RNA_enum_set(&opptr, "in_out", SOCK_OUT);
ot = WM_operatortype_find("NODE_OT_tree_socket_move", false);
col = uiLayoutColumn(row, true);
uiItemFullO_ptr(col, ot, "", ICON_TRIA_UP, NULL, WM_OP_EXEC_DEFAULT, 0, &opptr);
RNA_enum_set(&opptr, "direction", 1);
uiItemFullO_ptr(col, ot, "", ICON_TRIA_DOWN, NULL, WM_OP_EXEC_DEFAULT, 0, &opptr);
RNA_enum_set(&opptr, "direction", 2);
if (sock) {
row = uiLayoutRow(layout, true);
uiItemR(row, &sockptr, "name", 0, NULL, ICON_NONE);
uiItemO(row, "", ICON_X, "NODE_OT_tree_socket_remove");
if (sock->typeinfo->interface_draw) {
uiItemS(layout);
sock->typeinfo->interface_draw((bContext *)C, layout, &sockptr);
}
}
}
/* ******************* node buttons registration ************** */
void node_buttons_register(ARegionType *art)
{
PanelType *pt;
pt = MEM_callocN(sizeof(PanelType), "spacetype node panel node sockets");
strcpy(pt->idname, "NODE_PT_sockets");
strcpy(pt->category, N_("Node"));
strcpy(pt->label, N_("Sockets"));
strcpy(pt->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA);
pt->draw = node_sockets_panel;
pt->poll = node_sockets_poll;
pt->flag |= PANEL_TYPE_DEFAULT_CLOSED;
BLI_addtail(&art->paneltypes, pt);
pt = MEM_callocN(sizeof(PanelType), "spacetype node panel tree interface");
strcpy(pt->idname, "NODE_PT_node_tree_interface");
strcpy(pt->category, N_("Node"));
strcpy(pt->label, N_("Interface"));
strcpy(pt->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA);
pt->draw = node_tree_interface_panel;
pt->poll = node_tree_interface_poll;
BLI_addtail(&art->paneltypes, pt);
}
|