merging back to a version that works...
[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         ntemp.scene = CTX_data_scene(C);
270         ntemp.main = CTX_data_main(C);
271
272         if (event == UI_NODE_LINK_DISCONNECT)
273                 node_socket_disconnect(bmain, ntree, node_to, sock_to);
274         else if (event == UI_NODE_LINK_REMOVE)
275                 node_socket_remove(bmain, ntree, node_to, sock_to);
276         else
277                 node_socket_add_replace(bmain, ntree, node_to, sock_to, &ntemp, arg->output);
278         
279         ED_undo_push(C, "Node input modify");
280 }
281
282 static void ui_node_sock_name(bNodeSocket *sock, char name[UI_MAX_NAME_STR])
283 {
284         if (sock->link && sock->link->fromnode) {
285                 bNode *node = sock->link->fromnode;
286                 char node_name[UI_MAX_NAME_STR];
287
288                 if (node->type == NODE_GROUP) {
289                         if (node->id)
290                                 BLI_strncpy(node_name, node->id->name+2, UI_MAX_NAME_STR);
291                         else
292                                 BLI_strncpy(node_name, "Group", UI_MAX_NAME_STR);
293                 }
294                 else
295                         BLI_strncpy(node_name, node->typeinfo->name, UI_MAX_NAME_STR);
296
297                 if (node->inputs.first == NULL &&
298                    node->outputs.first != node->outputs.last &&
299                    !(node->typeinfo->flag & NODE_OPTIONS))
300                         BLI_snprintf(name, UI_MAX_NAME_STR, "%s | %s", node_name, sock->link->fromsock->name);
301                 else
302                         BLI_strncpy(name, node_name, UI_MAX_NAME_STR);
303         }
304         else if (sock->type == SOCK_SHADER)
305                 BLI_strncpy(name, "None", UI_MAX_NAME_STR);
306         else
307                 BLI_strncpy(name, "Default", UI_MAX_NAME_STR);
308 }
309
310 static int ui_compatible_sockets(int typeA, int typeB)
311 {
312         return (typeA == typeB);
313 }
314
315 static void ui_node_menu_column(NodeLinkArg *arg, int nclass, const char *cname)
316 {
317         Main *bmain = arg->bmain;
318         bNodeTree *ntree = arg->ntree;
319         bNodeSocket *sock = arg->sock;
320         uiLayout *layout = arg->layout;
321         uiLayout *column = NULL;
322         uiBlock *block = uiLayoutGetBlock(layout);
323         uiBut *but;
324         bNodeType *ntype;
325         bNodeTree *ngroup;
326         NodeLinkArg *argN;
327         int first = 1;
328         int compatibility= 0;
329
330         if (ntree->type == NTREE_SHADER) {
331                 if (scene_use_new_shading_nodes(arg->scene))
332                         compatibility= NODE_NEW_SHADING;
333                 else
334                         compatibility= NODE_OLD_SHADING;
335         }
336
337         if (nclass == NODE_CLASS_GROUP) {
338                 for (ngroup=bmain->nodetree.first; ngroup; ngroup=ngroup->id.next) {
339                         bNodeSocket *gsock;
340                         char name[UI_MAX_NAME_STR];
341                         int i, j, num = 0;
342
343                         if (ngroup->type != ntree->type)
344                                 continue;
345
346                         for (gsock=ngroup->inputs.first; gsock; gsock=gsock->next)
347                                 if (ui_compatible_sockets(gsock->type, sock->type))
348                                         num++;
349
350                         for (i=0, j=0, gsock=ngroup->outputs.first; gsock; gsock=gsock->next, i++) {
351                                 if (!ui_compatible_sockets(gsock->type, sock->type))
352                                         continue;
353
354                                 if (first) {
355                                         column= uiLayoutColumn(layout, 0);
356                                         uiBlockSetCurLayout(block, column);
357
358                                         uiItemL(column, cname, ICON_NODE);
359                                         but= block->buttons.last;
360                                         but->flag= UI_TEXT_LEFT;
361
362                                         first = 0;
363                                 }
364
365                                 if (num > 1) {
366                                         if (j == 0) {
367                                                 uiItemL(column, ngroup->id.name+2, ICON_NODE);
368                                                 but= block->buttons.last;
369                                                 but->flag= UI_TEXT_LEFT;
370                                         }
371
372                                         BLI_snprintf(name, UI_MAX_NAME_STR, "  %s", gsock->name);
373                                         j++;
374                                 }
375                                 else
376                                         BLI_strncpy(name, ngroup->id.name+2, UI_MAX_NAME_STR);
377
378                                 but = uiDefBut(block, BUT, 0, ngroup->id.name+2, 0, 0, UI_UNIT_X*4, UI_UNIT_Y,
379                                         NULL, 0.0, 0.0, 0.0, 0.0, "Add node to input");
380
381                                 argN = MEM_dupallocN(arg);
382                                 argN->type = NODE_GROUP;
383                                 argN->ngroup = ngroup;
384                                 argN->output = i;
385                                 uiButSetNFunc(but, ui_node_link, argN, NULL);
386                         }
387                 }
388         }
389         else {
390                 bNodeTreeType *ttype= ntreeGetType(ntree->type);
391
392                 for (ntype=ttype->node_types.first; ntype; ntype=ntype->next) {
393                         bNodeSocketTemplate *stemp;
394                         char name[UI_MAX_NAME_STR];
395                         int i, j, num = 0;
396
397                         if (compatibility && !(ntype->compatibility & compatibility))
398                                 continue;
399
400                         if (ntype->nclass != nclass)
401                                 continue;
402
403                         for (i=0, stemp=ntype->outputs; stemp && stemp->type != -1; stemp++, i++)
404                                 if (ui_compatible_sockets(stemp->type, sock->type))
405                                         num++;
406
407                         for (i=0, j=0, stemp=ntype->outputs; stemp && stemp->type != -1; stemp++, i++) {
408                                 if (!ui_compatible_sockets(stemp->type, sock->type))
409                                         continue;
410
411                                 if (first) {
412                                         column= uiLayoutColumn(layout, 0);
413                                         uiBlockSetCurLayout(block, column);
414
415                                         uiItemL(column, cname, ICON_NODE);
416                                         but= block->buttons.last;
417                                         but->flag= UI_TEXT_LEFT;
418
419                                         first = 0;
420                                 }
421
422                                 if (num > 1) {
423                                         if (j == 0) {
424                                                 uiItemL(column, ntype->name, ICON_NODE);
425                                                 but= block->buttons.last;
426                                                 but->flag= UI_TEXT_LEFT;
427                                         }
428
429                                         BLI_snprintf(name, UI_MAX_NAME_STR, "  %s", stemp->name);
430                                         j++;
431                                 }
432                                 else
433                                         BLI_strncpy(name, ntype->name, UI_MAX_NAME_STR);
434
435                                 but = uiDefBut(block, BUT, 0, name, 0, 0, UI_UNIT_X*4, UI_UNIT_Y,
436                                         NULL, 0.0, 0.0, 0.0, 0.0, "Add node to input");
437
438                                 argN = MEM_dupallocN(arg);
439                                 argN->type = ntype->type;
440                                 argN->output = i;
441                                 uiButSetNFunc(but, ui_node_link, argN, NULL);
442                         }
443                 }
444         }
445 }
446
447 static void node_menu_column_foreach_cb(void *calldata, int nclass, const char *name)
448 {
449         NodeLinkArg *arg = (NodeLinkArg*)calldata;
450
451         if (!ELEM(nclass, NODE_CLASS_GROUP, NODE_CLASS_LAYOUT))
452                 ui_node_menu_column(arg, nclass, name);
453 }
454
455 static void ui_template_node_link_menu(bContext *C, uiLayout *layout, void *but_p)
456 {
457         Main *bmain= CTX_data_main(C);
458         Scene *scene= CTX_data_scene(C);
459         uiBlock *block = uiLayoutGetBlock(layout);
460         uiBut *but = (uiBut*)but_p;
461         uiLayout *split, *column;
462         NodeLinkArg *arg = (NodeLinkArg*)but->func_argN;
463         bNodeSocket *sock = arg->sock;
464         bNodeTreeType *ntreetype= ntreeGetType(arg->ntree->type);
465
466         uiBlockSetCurLayout(block, layout);
467         split= uiLayoutSplit(layout, 0, 0);
468
469         arg->bmain= bmain;
470         arg->scene= scene;
471         arg->layout= split;
472         
473         if (ntreetype && ntreetype->foreach_nodeclass)
474                 ntreetype->foreach_nodeclass(scene, arg, node_menu_column_foreach_cb);
475
476         column= uiLayoutColumn(split, 0);
477         uiBlockSetCurLayout(block, column);
478
479         if (sock->link) {
480                 uiItemL(column, "Link", ICON_NONE);
481                 but= block->buttons.last;
482                 but->flag= UI_TEXT_LEFT;
483
484                 but = uiDefBut(block, BUT, 0, "Remove", 0, 0, UI_UNIT_X*4, UI_UNIT_Y,
485                         NULL, 0.0, 0.0, 0.0, 0.0, "Remove nodes connected to the input");
486                 uiButSetNFunc(but, ui_node_link, MEM_dupallocN(arg), SET_INT_IN_POINTER(UI_NODE_LINK_REMOVE));
487
488                 but = uiDefBut(block, BUT, 0, "Disconnect", 0, 0, UI_UNIT_X*4, UI_UNIT_Y,
489                         NULL, 0.0, 0.0, 0.0, 0.0, "Disconnect nodes connected to the input");
490                 uiButSetNFunc(but, ui_node_link, MEM_dupallocN(arg), SET_INT_IN_POINTER(UI_NODE_LINK_DISCONNECT));
491         }
492
493         ui_node_menu_column(arg, NODE_CLASS_GROUP, IFACE_("Group"));
494 }
495
496 void uiTemplateNodeLink(uiLayout *layout, bNodeTree *ntree, bNode *node, bNodeSocket *sock)
497 {
498         uiBlock *block = uiLayoutGetBlock(layout);
499         NodeLinkArg *arg;
500         uiBut *but;
501
502         arg = MEM_callocN(sizeof(NodeLinkArg), "NodeLinkArg");
503         arg->ntree = ntree;
504         arg->node = node;
505         arg->sock = sock;
506         arg->type = 0;
507         arg->output = 0;
508
509         uiBlockSetCurLayout(block, layout);
510
511         if (sock->link || sock->type == SOCK_SHADER || (sock->flag & SOCK_HIDE_VALUE)) {
512                 char name[UI_MAX_NAME_STR];
513                 ui_node_sock_name(sock, name);
514                 but = uiDefMenuBut(block, ui_template_node_link_menu, NULL, name, 0, 0, UI_UNIT_X*4, UI_UNIT_Y, "");
515         }
516         else
517                 but = uiDefIconMenuBut(block, ui_template_node_link_menu, NULL, ICON_NONE, 0, 0, UI_UNIT_X, UI_UNIT_Y, "");
518
519         but->type= MENU;
520         but->flag |= UI_TEXT_LEFT|UI_BUT_NODE_LINK;
521         but->poin= (char*)but;
522         but->func_argN = arg;
523
524         if (sock->link && sock->link->fromnode)
525                 if (sock->link->fromnode->flag & NODE_ACTIVE_TEXTURE)
526                         but->flag |= UI_BUT_NODE_ACTIVE;
527 }
528
529 /**************************** Node Tree Layout *******************************/
530
531 static void ui_node_draw_input(uiLayout *layout, bContext *C,
532         bNodeTree *ntree, bNode *node, bNodeSocket *input, int depth);
533
534 static void ui_node_draw_node(uiLayout *layout, bContext *C, bNodeTree *ntree, bNode *node, int depth)
535 {
536         bNodeSocket *input;
537         uiLayout *col, *split;
538         PointerRNA nodeptr;
539
540         RNA_pointer_create(&ntree->id, &RNA_Node, node, &nodeptr);
541
542         if (node->typeinfo->uifunc) {
543                 if (node->type != NODE_GROUP) {
544                         split = uiLayoutSplit(layout, 0.35f, 0);
545                         col = uiLayoutColumn(split, 0);
546                         col = uiLayoutColumn(split, 0);
547
548                         node->typeinfo->uifunc(col, C, &nodeptr);
549                 }
550         }
551
552         for (input=node->inputs.first; input; input=input->next)
553                 ui_node_draw_input(layout, C, ntree, node, input, depth+1);
554 }
555
556 static void ui_node_draw_input(uiLayout *layout, bContext *C, bNodeTree *ntree, bNode *node, bNodeSocket *input, int depth)
557 {
558         PointerRNA inputptr;
559         uiBlock *block = uiLayoutGetBlock(layout);
560         uiBut *bt;
561         uiLayout *split, *row, *col;
562         bNode *lnode;
563         char label[UI_MAX_NAME_STR];
564         int indent = (depth > 1)? 2*(depth - 1): 0;
565         int dependency_loop;
566
567         if (input->flag & SOCK_UNAVAIL)
568                 return;
569
570         /* to avoid eternal loops on cyclic dependencies */
571         node->flag |= NODE_TEST;
572         lnode = (input->link)? input->link->fromnode: NULL;
573
574         dependency_loop = (lnode && (lnode->flag & NODE_TEST));
575         if (dependency_loop)
576                 lnode = NULL;
577
578         /* socket RNA pointer */
579         RNA_pointer_create(&ntree->id, &RNA_NodeSocket, input, &inputptr);
580
581         /* indented label */
582         memset(label, ' ', indent);
583         label[indent] = '\0';
584         BLI_snprintf(label, UI_MAX_NAME_STR, "%s%s:", label, input->name);
585
586         /* split in label and value */
587         split = uiLayoutSplit(layout, 0.35f, 0);
588
589         row = uiLayoutRow(split, 1);
590
591         if (depth > 0) {
592                 uiBlockSetEmboss(block, UI_EMBOSSN);
593
594                 if (lnode && (lnode->inputs.first || (lnode->typeinfo->uifunc && lnode->type != NODE_GROUP))) {
595                         int icon = (input->flag & SOCK_COLLAPSED)? ICON_DISCLOSURE_TRI_RIGHT: ICON_DISCLOSURE_TRI_DOWN;
596                         uiItemR(row, &inputptr, "show_expanded", UI_ITEM_R_ICON_ONLY, "", icon);
597                 }
598                 else
599                         uiItemL(row, "", ICON_BLANK1);
600
601                 bt = block->buttons.last;
602                 bt->x2 = UI_UNIT_X/2;
603
604                 uiBlockSetEmboss(block, UI_EMBOSS);
605         }
606
607         uiItemL(row, label, ICON_NONE);
608         bt= block->buttons.last;
609         bt->flag= UI_TEXT_LEFT;
610
611         if (dependency_loop) {
612                 row = uiLayoutRow(split, 0);
613                 uiItemL(row, "Dependency Loop", ICON_ERROR);
614         }
615         else if (lnode) {
616                 /* input linked to a node */
617                 uiTemplateNodeLink(split, ntree, node, input);
618
619                 if (!(input->flag & SOCK_COLLAPSED)) {
620                         if (depth == 0)
621                                 uiItemS(layout);
622
623                         ui_node_draw_node(layout, C, ntree, lnode, depth);
624                 }
625         }
626         else {
627                 /* input not linked, show value */
628                 if (input->type != SOCK_SHADER && !(input->flag & SOCK_HIDE_VALUE)) {
629                         if (input->type == SOCK_VECTOR) {
630                                 row = uiLayoutRow(split, 0);
631                                 col = uiLayoutColumn(row, 0);
632
633                                 uiItemR(col, &inputptr, "default_value", 0, "", 0);
634                         }
635                         else {
636                                 row = uiLayoutRow(split, 1);
637                                 uiItemR(row, &inputptr, "default_value", 0, "", 0);
638                         }
639                 }
640                 else
641                         row = uiLayoutRow(split, 0);
642
643                 uiTemplateNodeLink(row, ntree, node, input);
644         }
645
646         /* clear */
647         node->flag &= ~NODE_TEST;
648 }
649
650 void uiTemplateNodeView(uiLayout *layout, bContext *C, bNodeTree *ntree, bNode *node, bNodeSocket *input)
651 {
652         bNode *tnode;
653
654         if (!ntree)
655                 return;
656
657         /* clear for cycle check */
658         for (tnode=ntree->nodes.first; tnode; tnode=tnode->next)
659                 tnode->flag &= ~NODE_TEST;
660
661         if (input)
662                 ui_node_draw_input(layout, C, ntree, node, input, 0);
663         else
664                 ui_node_draw_node(layout, C, ntree, node, 0);
665 }
666