style cleanup: follow style guide for formatting of if/for/while loops, and else...
[blender.git] / source / blender / editors / space_node / node_templates.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * Contributor(s): Blender Foundation 2009.
19  *
20  * ***** END GPL LICENSE BLOCK *****
21  */
22
23 /** \file blender/editors/space_node/node_templates.c
24  *  \ingroup edinterface
25  */
26
27 #include <stdlib.h>
28 #include <stddef.h>
29 #include <string.h>
30
31 #include "MEM_guardedalloc.h"
32
33 #include "DNA_node_types.h"
34 #include "DNA_scene_types.h"
35 #include "DNA_screen_types.h"
36
37 #include "BLI_listbase.h"
38 #include "BLI_string.h"
39 #include "BLI_utildefines.h"
40
41 #include "BLF_translation.h"
42
43 #include "BKE_context.h"
44 #include "BKE_depsgraph.h"
45 #include "BKE_library.h"
46 #include "BKE_main.h"
47 #include "BKE_node.h"
48 #include "BKE_scene.h"
49
50 #include "RNA_access.h"
51
52 #include "NOD_socket.h"
53
54 #include "WM_api.h"
55 #include "WM_types.h"
56
57 #include "UI_interface.h"
58 #include "UI_resources.h"
59 #include "../interface/interface_intern.h"
60
61 #include "ED_node.h"
62 #include "ED_util.h"
63
64 /************************* Node Socket Manipulation **************************/
65
66 static void node_tag_recursive(bNode *node)
67 {
68         bNodeSocket *input;
69
70         if (!node || (node->flag & NODE_TEST))
71                 return; /* in case of cycles */
72         
73         node->flag |= NODE_TEST;
74
75         for (input=node->inputs.first; input; input=input->next)
76                 if (input->link)
77                         node_tag_recursive(input->link->fromnode);
78 }
79
80 static void node_clear_recursive(bNode *node)
81 {
82         bNodeSocket *input;
83
84         if (!node || !(node->flag & NODE_TEST))
85                 return; /* in case of cycles */
86         
87         node->flag &= ~NODE_TEST;
88
89         for (input=node->inputs.first; input; input=input->next)
90                 if (input->link)
91                         node_clear_recursive(input->link->fromnode);
92 }
93
94 static void node_remove_linked(bNodeTree *ntree, bNode *rem_node)
95 {
96         bNode *node, *next;
97         bNodeSocket *sock;
98
99         if (!rem_node)
100                 return;
101
102         /* tag linked nodes to be removed */
103         for (node=ntree->nodes.first; node; node=node->next)
104                 node->flag &= ~NODE_TEST;
105         
106         node_tag_recursive(rem_node);
107
108         /* clear tags on nodes that are still used by other nodes */
109         for (node=ntree->nodes.first; node; node=node->next)
110                 if (!(node->flag & NODE_TEST))
111                         for (sock=node->inputs.first; sock; sock=sock->next)
112                                 if (sock->link && sock->link->fromnode != rem_node)
113                                         node_clear_recursive(sock->link->fromnode);
114
115         /* remove nodes */
116         for (node=ntree->nodes.first; node; node=next) {
117                 next = node->next;
118
119                 if (node->flag & NODE_TEST) {
120                         if (node->id)
121                                 node->id->us--;
122                         nodeFreeNode(ntree, node);
123                 }
124         }
125 }
126
127 /* disconnect socket from the node it is connected to */
128 static void node_socket_disconnect(Main *bmain, bNodeTree *ntree, bNode *node_to, bNodeSocket *sock_to)
129 {
130         if (!sock_to->link)
131                 return;
132
133         nodeRemLink(ntree, sock_to->link);
134
135         nodeUpdate(ntree, node_to);
136         ntreeUpdateTree(ntree);
137
138         ED_node_generic_update(bmain, ntree, node_to);
139 }
140
141 /* remove all nodes connected to this socket, if they aren't connected to other nodes */
142 static void node_socket_remove(Main *bmain, bNodeTree *ntree, bNode *node_to, bNodeSocket *sock_to)
143 {
144         if (!sock_to->link)
145                 return;
146
147         node_remove_linked(ntree, sock_to->link->fromnode);
148
149         nodeUpdate(ntree, node_to);
150         ntreeUpdateTree(ntree);
151
152         ED_node_generic_update(bmain, ntree, node_to);
153 }
154
155 /* add new node connected to this socket, or replace an existing one */
156 static void node_socket_add_replace(Main *bmain, bNodeTree *ntree, bNode *node_to, bNodeSocket *sock_to, bNodeTemplate *ntemp, int sock_num)
157 {
158         bNode *node_from;
159         bNodeSocket *sock_from;
160         bNode *node_prev = NULL;
161
162         /* unlink existing node */
163         if (sock_to->link) {
164                 node_prev = sock_to->link->fromnode;
165                 nodeRemLink(ntree, sock_to->link);
166         }
167
168         /* find existing node that we can use */
169         for (node_from=ntree->nodes.first; node_from; node_from=node_from->next)
170                 if (node_from->type == ntemp->type)
171                         break;
172
173         if (node_from)
174                 if (!(node_from->inputs.first == NULL && !(node_from->typeinfo->flag & NODE_OPTIONS)))
175                         node_from = NULL;
176
177         if (node_prev && node_prev->type == ntemp->type &&
178                 (ntemp->type != NODE_GROUP || node_prev->id == &ntemp->ngroup->id)) {
179                 /* keep the previous node if it's the same type */
180                 node_from = node_prev;
181         }
182         else if (!node_from) {
183                 node_from= nodeAddNode(ntree, ntemp);
184                 node_from->locx = node_to->locx - (node_from->typeinfo->width + 50);
185                 node_from->locy = node_to->locy;
186
187                 if (node_from->id)
188                         id_us_plus(node_from->id);
189         }
190
191         nodeSetActive(ntree, node_from);
192
193         /* add link */
194         sock_from = BLI_findlink(&node_from->outputs, sock_num);
195         nodeAddLink(ntree, node_from, sock_from, node_to, sock_to);
196
197         /* copy input sockets from previous node */
198         if (node_prev && node_from != node_prev) {
199                 bNodeSocket *sock_prev, *sock_from;
200
201                 for (sock_prev=node_prev->inputs.first; sock_prev; sock_prev=sock_prev->next) {
202                         for (sock_from=node_from->inputs.first; sock_from; sock_from=sock_from->next) {
203                                 if (nodeCountSocketLinks(ntree, sock_from) >= sock_from->limit)
204                                         continue;
205                                 
206                                 if (strcmp(sock_prev->name, sock_from->name) == 0 && sock_prev->type == sock_from->type) {
207                                         bNodeLink *link = sock_prev->link;
208
209                                         if (link && link->fromnode) {
210                                                 nodeAddLink(ntree, link->fromnode, link->fromsock, node_from, sock_from);
211                                                 nodeRemLink(ntree, link);
212                                         }
213
214                                         node_socket_free_default_value(sock_from->type, sock_from->default_value);
215                                         sock_from->default_value = node_socket_make_default_value(sock_from->type);
216                                         node_socket_copy_default_value(sock_from->type, sock_from->default_value, sock_prev->default_value);
217                                 }
218                         }
219                 }
220
221                 /* also preserve mapping for texture nodes */
222                 if (node_from->typeinfo->nclass == NODE_CLASS_TEXTURE &&
223                    node_prev->typeinfo->nclass == NODE_CLASS_TEXTURE)
224                         memcpy(node_from->storage, node_prev->storage, sizeof(NodeTexBase));
225
226                 /* remove node */
227                 node_remove_linked(ntree, node_prev);
228         }
229
230         nodeUpdate(ntree, node_from);
231         nodeUpdate(ntree, node_to);
232         ntreeUpdateTree(ntree);
233
234         ED_node_generic_update(bmain, ntree, node_to);
235 }
236
237 /****************************** Node Link Menu *******************************/
238
239 #define UI_NODE_LINK_ADD                0
240 #define UI_NODE_LINK_DISCONNECT -1
241 #define UI_NODE_LINK_REMOVE             -2
242
243 typedef struct NodeLinkArg {
244         Main *bmain;
245         Scene *scene;
246         bNodeTree *ntree;
247         bNode *node;
248         bNodeSocket *sock;
249
250         bNodeTree *ngroup;
251         int type;
252         int output;
253
254         uiLayout *layout;
255 } NodeLinkArg;
256
257 static void ui_node_link(bContext *C, void *arg_p, void *event_p)
258 {
259         NodeLinkArg *arg = (NodeLinkArg*)arg_p;
260         Main *bmain = arg->bmain;
261         bNode *node_to = arg->node;
262         bNodeSocket *sock_to = arg->sock;
263         bNodeTree *ntree = arg->ntree;
264         int event = GET_INT_FROM_POINTER(event_p);
265         bNodeTemplate ntemp;
266
267         ntemp.type = arg->type;
268         ntemp.ngroup = arg->ngroup;
269
270         if (event == UI_NODE_LINK_DISCONNECT)
271                 node_socket_disconnect(bmain, ntree, node_to, sock_to);
272         else if (event == UI_NODE_LINK_REMOVE)
273                 node_socket_remove(bmain, ntree, node_to, sock_to);
274         else
275                 node_socket_add_replace(bmain, ntree, node_to, sock_to, &ntemp, arg->output);
276         
277         ED_undo_push(C, "Node input modify");
278 }
279
280 static void ui_node_sock_name(bNodeSocket *sock, char name[UI_MAX_NAME_STR])
281 {
282         if (sock->link && sock->link->fromnode) {
283                 bNode *node = sock->link->fromnode;
284                 char node_name[UI_MAX_NAME_STR];
285
286                 if (node->type == NODE_GROUP) {
287                         if (node->id)
288                                 BLI_strncpy(node_name, node->id->name+2, UI_MAX_NAME_STR);
289                         else
290                                 BLI_strncpy(node_name, "Group", UI_MAX_NAME_STR);
291                 }
292                 else
293                         BLI_strncpy(node_name, node->typeinfo->name, UI_MAX_NAME_STR);
294
295                 if (node->inputs.first == NULL &&
296                    node->outputs.first != node->outputs.last &&
297                    !(node->typeinfo->flag & NODE_OPTIONS))
298                         BLI_snprintf(name, UI_MAX_NAME_STR, "%s | %s", node_name, sock->link->fromsock->name);
299                 else
300                         BLI_strncpy(name, node_name, UI_MAX_NAME_STR);
301         }
302         else if (sock->type == SOCK_SHADER)
303                 BLI_strncpy(name, "None", UI_MAX_NAME_STR);
304         else
305                 BLI_strncpy(name, "Default", UI_MAX_NAME_STR);
306 }
307
308 static int ui_compatible_sockets(int typeA, int typeB)
309 {
310         return (typeA == typeB);
311 }
312
313 static void ui_node_menu_column(NodeLinkArg *arg, int nclass, const char *cname)
314 {
315         Main *bmain = arg->bmain;
316         bNodeTree *ntree = arg->ntree;
317         bNodeSocket *sock = arg->sock;
318         uiLayout *layout = arg->layout;
319         uiLayout *column = NULL;
320         uiBlock *block = uiLayoutGetBlock(layout);
321         uiBut *but;
322         bNodeType *ntype;
323         bNodeTree *ngroup;
324         NodeLinkArg *argN;
325         int first = 1;
326         int compatibility= 0;
327
328         if (ntree->type == NTREE_SHADER) {
329                 if (scene_use_new_shading_nodes(arg->scene))
330                         compatibility= NODE_NEW_SHADING;
331                 else
332                         compatibility= NODE_OLD_SHADING;
333         }
334
335         if (nclass == NODE_CLASS_GROUP) {
336                 for (ngroup=bmain->nodetree.first; ngroup; ngroup=ngroup->id.next) {
337                         bNodeSocket *gsock;
338                         char name[UI_MAX_NAME_STR];
339                         int i, j, num = 0;
340
341                         if (ngroup->type != ntree->type)
342                                 continue;
343
344                         for (gsock=ngroup->inputs.first; gsock; gsock=gsock->next)
345                                 if (ui_compatible_sockets(gsock->type, sock->type))
346                                         num++;
347
348                         for (i=0, j=0, gsock=ngroup->outputs.first; gsock; gsock=gsock->next, i++) {
349                                 if (!ui_compatible_sockets(gsock->type, sock->type))
350                                         continue;
351
352                                 if (first) {
353                                         column= uiLayoutColumn(layout, 0);
354                                         uiBlockSetCurLayout(block, column);
355
356                                         uiItemL(column, cname, ICON_NODE);
357                                         but= block->buttons.last;
358                                         but->flag= UI_TEXT_LEFT;
359
360                                         first = 0;
361                                 }
362
363                                 if (num > 1) {
364                                         if (j == 0) {
365                                                 uiItemL(column, ngroup->id.name+2, ICON_NODE);
366                                                 but= block->buttons.last;
367                                                 but->flag= UI_TEXT_LEFT;
368                                         }
369
370                                         BLI_snprintf(name, UI_MAX_NAME_STR, "  %s", gsock->name);
371                                         j++;
372                                 }
373                                 else
374                                         BLI_strncpy(name, ngroup->id.name+2, UI_MAX_NAME_STR);
375
376                                 but = uiDefBut(block, BUT, 0, ngroup->id.name+2, 0, 0, UI_UNIT_X*4, UI_UNIT_Y,
377                                         NULL, 0.0, 0.0, 0.0, 0.0, "Add node to input");
378
379                                 argN = MEM_dupallocN(arg);
380                                 argN->type = NODE_GROUP;
381                                 argN->ngroup = ngroup;
382                                 argN->output = i;
383                                 uiButSetNFunc(but, ui_node_link, argN, NULL);
384                         }
385                 }
386         }
387         else {
388                 bNodeTreeType *ttype= ntreeGetType(ntree->type);
389
390                 for (ntype=ttype->node_types.first; ntype; ntype=ntype->next) {
391                         bNodeSocketTemplate *stemp;
392                         char name[UI_MAX_NAME_STR];
393                         int i, j, num = 0;
394
395                         if (compatibility && !(ntype->compatibility & compatibility))
396                                 continue;
397
398                         if (ntype->nclass != nclass)
399                                 continue;
400
401                         for (i=0, stemp=ntype->outputs; stemp && stemp->type != -1; stemp++, i++)
402                                 if (ui_compatible_sockets(stemp->type, sock->type))
403                                         num++;
404
405                         for (i=0, j=0, stemp=ntype->outputs; stemp && stemp->type != -1; stemp++, i++) {
406                                 if (!ui_compatible_sockets(stemp->type, sock->type))
407                                         continue;
408
409                                 if (first) {
410                                         column= uiLayoutColumn(layout, 0);
411                                         uiBlockSetCurLayout(block, column);
412
413                                         uiItemL(column, cname, ICON_NODE);
414                                         but= block->buttons.last;
415                                         but->flag= UI_TEXT_LEFT;
416
417                                         first = 0;
418                                 }
419
420                                 if (num > 1) {
421                                         if (j == 0) {
422                                                 uiItemL(column, ntype->name, ICON_NODE);
423                                                 but= block->buttons.last;
424                                                 but->flag= UI_TEXT_LEFT;
425                                         }
426
427                                         BLI_snprintf(name, UI_MAX_NAME_STR, "  %s", stemp->name);
428                                         j++;
429                                 }
430                                 else
431                                         BLI_strncpy(name, ntype->name, UI_MAX_NAME_STR);
432
433                                 but = uiDefBut(block, BUT, 0, name, 0, 0, UI_UNIT_X*4, UI_UNIT_Y,
434                                         NULL, 0.0, 0.0, 0.0, 0.0, "Add node to input");
435
436                                 argN = MEM_dupallocN(arg);
437                                 argN->type = ntype->type;
438                                 argN->output = i;
439                                 uiButSetNFunc(but, ui_node_link, argN, NULL);
440                         }
441                 }
442         }
443 }
444
445 static void node_menu_column_foreach_cb(void *calldata, int nclass, const char *name)
446 {
447         NodeLinkArg *arg = (NodeLinkArg*)calldata;
448
449         if (!ELEM(nclass, NODE_CLASS_GROUP, NODE_CLASS_LAYOUT))
450                 ui_node_menu_column(arg, nclass, name);
451 }
452
453 static void ui_template_node_link_menu(bContext *C, uiLayout *layout, void *but_p)
454 {
455         Main *bmain= CTX_data_main(C);
456         Scene *scene= CTX_data_scene(C);
457         uiBlock *block = uiLayoutGetBlock(layout);
458         uiBut *but = (uiBut*)but_p;
459         uiLayout *split, *column;
460         NodeLinkArg *arg = (NodeLinkArg*)but->func_argN;
461         bNodeSocket *sock = arg->sock;
462         bNodeTreeType *ntreetype= ntreeGetType(arg->ntree->type);
463
464         uiBlockSetCurLayout(block, layout);
465         split= uiLayoutSplit(layout, 0, 0);
466
467         arg->bmain= bmain;
468         arg->scene= scene;
469         arg->layout= split;
470         
471         if (ntreetype && ntreetype->foreach_nodeclass)
472                 ntreetype->foreach_nodeclass(scene, arg, node_menu_column_foreach_cb);
473
474         column= uiLayoutColumn(split, 0);
475         uiBlockSetCurLayout(block, column);
476
477         if (sock->link) {
478                 uiItemL(column, "Link", ICON_NONE);
479                 but= block->buttons.last;
480                 but->flag= UI_TEXT_LEFT;
481
482                 but = uiDefBut(block, BUT, 0, "Remove", 0, 0, UI_UNIT_X*4, UI_UNIT_Y,
483                         NULL, 0.0, 0.0, 0.0, 0.0, "Remove nodes connected to the input");
484                 uiButSetNFunc(but, ui_node_link, MEM_dupallocN(arg), SET_INT_IN_POINTER(UI_NODE_LINK_REMOVE));
485
486                 but = uiDefBut(block, BUT, 0, "Disconnect", 0, 0, UI_UNIT_X*4, UI_UNIT_Y,
487                         NULL, 0.0, 0.0, 0.0, 0.0, "Disconnect nodes connected to the input");
488                 uiButSetNFunc(but, ui_node_link, MEM_dupallocN(arg), SET_INT_IN_POINTER(UI_NODE_LINK_DISCONNECT));
489         }
490
491         ui_node_menu_column(arg, NODE_CLASS_GROUP, IFACE_("Group"));
492 }
493
494 void uiTemplateNodeLink(uiLayout *layout, bNodeTree *ntree, bNode *node, bNodeSocket *sock)
495 {
496         uiBlock *block = uiLayoutGetBlock(layout);
497         NodeLinkArg *arg;
498         uiBut *but;
499
500         arg = MEM_callocN(sizeof(NodeLinkArg), "NodeLinkArg");
501         arg->ntree = ntree;
502         arg->node = node;
503         arg->sock = sock;
504         arg->type = 0;
505         arg->output = 0;
506
507         uiBlockSetCurLayout(block, layout);
508
509         if (sock->link || sock->type == SOCK_SHADER || (sock->flag & SOCK_HIDE_VALUE)) {
510                 char name[UI_MAX_NAME_STR];
511                 ui_node_sock_name(sock, name);
512                 but = uiDefMenuBut(block, ui_template_node_link_menu, NULL, name, 0, 0, UI_UNIT_X*4, UI_UNIT_Y, "");
513         }
514         else
515                 but = uiDefIconMenuBut(block, ui_template_node_link_menu, NULL, ICON_NONE, 0, 0, UI_UNIT_X, UI_UNIT_Y, "");
516
517         but->type= MENU;
518         but->flag |= UI_TEXT_LEFT|UI_BUT_NODE_LINK;
519         but->poin= (char*)but;
520         but->func_argN = arg;
521
522         if (sock->link && sock->link->fromnode)
523                 if (sock->link->fromnode->flag & NODE_ACTIVE_TEXTURE)
524                         but->flag |= UI_BUT_NODE_ACTIVE;
525 }
526
527 /**************************** Node Tree Layout *******************************/
528
529 static void ui_node_draw_input(uiLayout *layout, bContext *C,
530         bNodeTree *ntree, bNode *node, bNodeSocket *input, int depth);
531
532 static void ui_node_draw_node(uiLayout *layout, bContext *C, bNodeTree *ntree, bNode *node, int depth)
533 {
534         bNodeSocket *input;
535         uiLayout *col, *split;
536         PointerRNA nodeptr;
537
538         RNA_pointer_create(&ntree->id, &RNA_Node, node, &nodeptr);
539
540         if (node->typeinfo->uifunc) {
541                 if (node->type != NODE_GROUP) {
542                         split = uiLayoutSplit(layout, 0.35f, 0);
543                         col = uiLayoutColumn(split, 0);
544                         col = uiLayoutColumn(split, 0);
545
546                         node->typeinfo->uifunc(col, C, &nodeptr);
547                 }
548         }
549
550         for (input=node->inputs.first; input; input=input->next)
551                 ui_node_draw_input(layout, C, ntree, node, input, depth+1);
552 }
553
554 static void ui_node_draw_input(uiLayout *layout, bContext *C, bNodeTree *ntree, bNode *node, bNodeSocket *input, int depth)
555 {
556         PointerRNA inputptr;
557         uiBlock *block = uiLayoutGetBlock(layout);
558         uiBut *bt;
559         uiLayout *split, *row, *col;
560         bNode *lnode;
561         char label[UI_MAX_NAME_STR];
562         int indent = (depth > 1)? 2*(depth - 1): 0;
563         int dependency_loop;
564
565         if (input->flag & SOCK_UNAVAIL)
566                 return;
567
568         /* to avoid eternal loops on cyclic dependencies */
569         node->flag |= NODE_TEST;
570         lnode = (input->link)? input->link->fromnode: NULL;
571
572         dependency_loop = (lnode && (lnode->flag & NODE_TEST));
573         if (dependency_loop)
574                 lnode = NULL;
575
576         /* socket RNA pointer */
577         RNA_pointer_create(&ntree->id, &RNA_NodeSocket, input, &inputptr);
578
579         /* indented label */
580         memset(label, ' ', indent);
581         label[indent] = '\0';
582         BLI_snprintf(label, UI_MAX_NAME_STR, "%s%s:", label, input->name);
583
584         /* split in label and value */
585         split = uiLayoutSplit(layout, 0.35f, 0);
586
587         row = uiLayoutRow(split, 1);
588
589         if (depth > 0) {
590                 uiBlockSetEmboss(block, UI_EMBOSSN);
591
592                 if (lnode && (lnode->inputs.first || (lnode->typeinfo->uifunc && lnode->type != NODE_GROUP))) {
593                         int icon = (input->flag & SOCK_COLLAPSED)? ICON_DISCLOSURE_TRI_RIGHT: ICON_DISCLOSURE_TRI_DOWN;
594                         uiItemR(row, &inputptr, "show_expanded", UI_ITEM_R_ICON_ONLY, "", icon);
595                 }
596                 else
597                         uiItemL(row, "", ICON_BLANK1);
598
599                 bt = block->buttons.last;
600                 bt->x2 = UI_UNIT_X/2;
601
602                 uiBlockSetEmboss(block, UI_EMBOSS);
603         }
604
605         uiItemL(row, label, ICON_NONE);
606         bt= block->buttons.last;
607         bt->flag= UI_TEXT_LEFT;
608
609         if (dependency_loop) {
610                 row = uiLayoutRow(split, 0);
611                 uiItemL(row, "Dependency Loop", ICON_ERROR);
612         }
613         else if (lnode) {
614                 /* input linked to a node */
615                 uiTemplateNodeLink(split, ntree, node, input);
616
617                 if (!(input->flag & SOCK_COLLAPSED)) {
618                         if (depth == 0)
619                                 uiItemS(layout);
620
621                         ui_node_draw_node(layout, C, ntree, lnode, depth);
622                 }
623         }
624         else {
625                 /* input not linked, show value */
626                 if (input->type != SOCK_SHADER && !(input->flag & SOCK_HIDE_VALUE)) {
627                         if (input->type == SOCK_VECTOR) {
628                                 row = uiLayoutRow(split, 0);
629                                 col = uiLayoutColumn(row, 0);
630
631                                 uiItemR(col, &inputptr, "default_value", 0, "", 0);
632                         }
633                         else {
634                                 row = uiLayoutRow(split, 1);
635                                 uiItemR(row, &inputptr, "default_value", 0, "", 0);
636                         }
637                 }
638                 else
639                         row = uiLayoutRow(split, 0);
640
641                 uiTemplateNodeLink(row, ntree, node, input);
642         }
643
644         /* clear */
645         node->flag &= ~NODE_TEST;
646 }
647
648 void uiTemplateNodeView(uiLayout *layout, bContext *C, bNodeTree *ntree, bNode *node, bNodeSocket *input)
649 {
650         bNode *tnode;
651
652         if (!ntree)
653                 return;
654
655         /* clear for cycle check */
656         for (tnode=ntree->nodes.first; tnode; tnode=tnode->next)
657                 tnode->flag &= ~NODE_TEST;
658
659         if (input)
660                 ui_node_draw_input(layout, C, ntree, node, input, 0);
661         else
662                 ui_node_draw_node(layout, C, ntree, node, 0);
663 }
664