Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/space_node/node_templates.c')
-rw-r--r--source/blender/editors/space_node/node_templates.c228
1 files changed, 92 insertions, 136 deletions
diff --git a/source/blender/editors/space_node/node_templates.c b/source/blender/editors/space_node/node_templates.c
index 23f4e948794..527defb1f07 100644
--- a/source/blender/editors/space_node/node_templates.c
+++ b/source/blender/editors/space_node/node_templates.c
@@ -30,6 +30,7 @@
#include "DNA_node_types.h"
#include "DNA_screen_types.h"
+#include "DNA_space_types.h"
#include "BLI_listbase.h"
#include "BLI_string.h"
@@ -52,6 +53,8 @@
#include "ED_util.h"
+#include "node_intern.h"
+
/************************* Node Socket Manipulation **************************/
static void node_tag_recursive(bNode *node)
@@ -127,7 +130,7 @@ static void node_socket_disconnect(Main *bmain, bNodeTree *ntree, bNode *node_to
nodeUpdate(ntree, node_to);
ntreeUpdateTree(ntree);
- ED_node_generic_update(bmain, ntree, node_to);
+ ED_node_tag_update_nodetree(bmain, ntree);
}
/* remove all nodes connected to this socket, if they aren't connected to other nodes */
@@ -142,11 +145,11 @@ static void node_socket_remove(Main *bmain, bNodeTree *ntree, bNode *node_to, bN
nodeUpdate(ntree, node_to);
ntreeUpdateTree(ntree);
- ED_node_generic_update(bmain, ntree, node_to);
+ ED_node_tag_update_nodetree(bmain, ntree);
}
/* add new node connected to this socket, or replace an existing one */
-static void node_socket_add_replace(Main *bmain, bNodeTree *ntree, bNode *node_to, bNodeSocket *sock_to, bNodeTemplate *ntemp, int sock_num)
+static void node_socket_add_replace(const bContext *C, bNodeTree *ntree, bNode *node_to, bNodeSocket *sock_to, int type, bNodeTree *ngroup, int sock_num)
{
bNode *node_from;
bNodeSocket *sock_from_tmp;
@@ -160,24 +163,30 @@ static void node_socket_add_replace(Main *bmain, bNodeTree *ntree, bNode *node_t
/* find existing node that we can use */
for (node_from = ntree->nodes.first; node_from; node_from = node_from->next)
- if (node_from->type == ntemp->type)
+ if (node_from->type == type)
break;
if (node_from)
if (!(node_from->inputs.first == NULL && !(node_from->typeinfo->flag & NODE_OPTIONS)))
node_from = NULL;
- if (node_prev && node_prev->type == ntemp->type &&
- (ntemp->type != NODE_GROUP || node_prev->id == &ntemp->ngroup->id))
+ /* XXX how can this be done nicely? bNodeTemplate is removed, it doesn't work for generic custom nodes */
+ if (node_prev && node_prev->type == type &&
+ (type != NODE_GROUP || node_prev->id == &ngroup->id))
{
/* keep the previous node if it's the same type */
node_from = node_prev;
}
else if (!node_from) {
- node_from = nodeAddNode(ntree, ntemp);
+ node_from = nodeAddStaticNode(C, ntree, type);
node_from->locx = node_to->locx - (node_from->typeinfo->width + 50);
node_from->locy = node_to->locy;
-
+
+ /* XXX bad, should be dispatched to generic operator or something ... */
+ if (type == NODE_GROUP) {
+ node_from->id = (ID *)ngroup;
+ }
+
if (node_from->id)
id_us_plus(node_from->id);
}
@@ -198,7 +207,7 @@ static void node_socket_add_replace(Main *bmain, bNodeTree *ntree, bNode *node_t
if (nodeCountSocketLinks(ntree, sock_from) >= sock_from->limit)
continue;
- if (strcmp(sock_prev->name, sock_from->name) == 0 && sock_prev->type == sock_from->type) {
+ if (STREQ(sock_prev->name, sock_from->name) && sock_prev->type == sock_from->type) {
bNodeLink *link = sock_prev->link;
if (link && link->fromnode) {
@@ -206,9 +215,11 @@ static void node_socket_add_replace(Main *bmain, bNodeTree *ntree, bNode *node_t
nodeRemLink(ntree, link);
}
- node_socket_free_default_value(sock_from->type, sock_from->default_value);
- sock_from->default_value = node_socket_make_default_value(sock_from->type);
- node_socket_copy_default_value(sock_from->type, sock_from->default_value, sock_prev->default_value);
+#if 0 /* XXX TODO */
+ node_socket_free_default_value(sock_from->typeinfo, sock_from->default_value);
+ sock_from->default_value = node_socket_make_default_value(sock_from->typeinfo);
+ node_socket_copy_default_value(sock_from->typeinfo, sock_from->default_value, sock_prev->default_value);
+#endif
}
}
}
@@ -228,7 +239,7 @@ static void node_socket_add_replace(Main *bmain, bNodeTree *ntree, bNode *node_t
nodeUpdate(ntree, node_to);
ntreeUpdateTree(ntree);
- ED_node_generic_update(bmain, ntree, node_to);
+ ED_node_tag_update_nodetree(CTX_data_main(C), ntree);
}
/****************************** Node Link Menu *******************************/
@@ -259,19 +270,13 @@ static void ui_node_link(bContext *C, void *arg_p, void *event_p)
bNodeSocket *sock_to = arg->sock;
bNodeTree *ntree = arg->ntree;
int event = GET_INT_FROM_POINTER(event_p);
- bNodeTemplate ntemp;
-
- ntemp.type = arg->type;
- ntemp.ngroup = arg->ngroup;
- ntemp.scene = CTX_data_scene(C);
- ntemp.main = CTX_data_main(C);
if (event == UI_NODE_LINK_DISCONNECT)
node_socket_disconnect(bmain, ntree, node_to, sock_to);
else if (event == UI_NODE_LINK_REMOVE)
node_socket_remove(bmain, ntree, node_to, sock_to);
else
- node_socket_add_replace(bmain, ntree, node_to, sock_to, &ntemp, arg->output);
+ node_socket_add_replace(C, ntree, node_to, sock_to, arg->type, arg->ngroup, arg->output);
ED_undo_push(C, "Node input modify");
}
@@ -286,10 +291,10 @@ static void ui_node_sock_name(bNodeSocket *sock, char name[UI_MAX_NAME_STR])
if (node->id)
BLI_strncpy(node_name, node->id->name + 2, UI_MAX_NAME_STR);
else
- BLI_strncpy(node_name, N_("Group"), UI_MAX_NAME_STR);
+ BLI_strncpy(node_name, N_(node->typeinfo->ui_name), UI_MAX_NAME_STR);
}
else
- BLI_strncpy(node_name, node->typeinfo->name, UI_MAX_NAME_STR);
+ BLI_strncpy(node_name, node->typeinfo->ui_name, UI_MAX_NAME_STR);
if (node->inputs.first == NULL &&
node->outputs.first != node->outputs.last)
@@ -313,19 +318,16 @@ static int ui_compatible_sockets(int typeA, int typeB)
static void ui_node_menu_column(NodeLinkArg *arg, int nclass, const char *cname)
{
- Main *bmain = arg->bmain;
bNodeTree *ntree = arg->ntree;
bNodeSocket *sock = arg->sock;
uiLayout *layout = arg->layout;
uiLayout *column = NULL;
uiBlock *block = uiLayoutGetBlock(layout);
uiBut *but;
- bNodeType *ntype;
- bNodeTree *ngroup;
NodeLinkArg *argN;
int first = 1;
int compatibility = 0;
-
+
if (ntree->type == NTREE_SHADER) {
if (BKE_scene_use_new_shading_nodes(arg->scene))
compatibility = NODE_NEW_SHADING;
@@ -333,114 +335,58 @@ static void ui_node_menu_column(NodeLinkArg *arg, int nclass, const char *cname)
compatibility = NODE_OLD_SHADING;
}
- if (nclass == NODE_CLASS_GROUP) {
- for (ngroup = bmain->nodetree.first; ngroup; ngroup = ngroup->id.next) {
- bNodeSocket *gsock;
- char name[UI_MAX_NAME_STR];
- int i, j, num = 0;
-
- if (ngroup->type != ntree->type)
+ NODE_TYPES_BEGIN(ntype)
+ bNodeSocketTemplate *stemp;
+ char name[UI_MAX_NAME_STR];
+ int i, j, num = 0;
+
+ if (compatibility && !(ntype->compatibility & compatibility))
+ continue;
+
+ if (ntype->nclass != nclass)
+ continue;
+
+ for (i = 0, stemp = ntype->outputs; stemp && stemp->type != -1; stemp++, i++)
+ if (ui_compatible_sockets(stemp->type, sock->type))
+ num++;
+
+ for (i = 0, j = 0, stemp = ntype->outputs; stemp && stemp->type != -1; stemp++, i++) {
+ if (!ui_compatible_sockets(stemp->type, sock->type))
continue;
-
- for (gsock = ngroup->inputs.first; gsock; gsock = gsock->next)
- if (ui_compatible_sockets(gsock->type, sock->type))
- num++;
-
- for (i = 0, j = 0, gsock = ngroup->outputs.first; gsock; gsock = gsock->next, i++) {
- if (!ui_compatible_sockets(gsock->type, sock->type))
- continue;
-
- if (first) {
- column = uiLayoutColumn(layout, FALSE);
- uiBlockSetCurLayout(block, column);
-
- uiItemL(column, IFACE_(cname), ICON_NODE);
- but = block->buttons.last;
- but->flag = UI_TEXT_LEFT;
-
- first = 0;
- }
-
- if (num > 1) {
- if (j == 0) {
- uiItemL(column, ngroup->id.name + 2, ICON_NODE);
- but = block->buttons.last;
- but->flag = UI_TEXT_LEFT;
- }
-
- BLI_snprintf(name, UI_MAX_NAME_STR, " %s", gsock->name);
- j++;
- }
- else
- BLI_strncpy(name, ngroup->id.name + 2, UI_MAX_NAME_STR);
-
- but = uiDefBut(block, BUT, 0, ngroup->id.name + 2, 0, 0, UI_UNIT_X * 4, UI_UNIT_Y,
- NULL, 0.0, 0.0, 0.0, 0.0, TIP_("Add node to input"));
-
- argN = MEM_dupallocN(arg);
- argN->type = NODE_GROUP;
- argN->ngroup = ngroup;
- argN->output = i;
- uiButSetNFunc(but, ui_node_link, argN, NULL);
+
+ if (first) {
+ column = uiLayoutColumn(layout, 0);
+ uiBlockSetCurLayout(block, column);
+
+ uiItemL(column, IFACE_(cname), ICON_NODE);
+ but = block->buttons.last;
+ but->flag = UI_TEXT_LEFT;
+
+ first = 0;
}
- }
- }
- else {
- bNodeTreeType *ttype = ntreeGetType(ntree->type);
-
- for (ntype = ttype->node_types.first; ntype; ntype = ntype->next) {
- bNodeSocketTemplate *stemp;
- char name[UI_MAX_NAME_STR];
- int i, j, num = 0;
-
- if (compatibility && !(ntype->compatibility & compatibility))
- continue;
-
- if (ntype->nclass != nclass)
- continue;
-
- for (i = 0, stemp = ntype->outputs; stemp && stemp->type != -1; stemp++, i++)
- if (ui_compatible_sockets(stemp->type, sock->type))
- num++;
-
- for (i = 0, j = 0, stemp = ntype->outputs; stemp && stemp->type != -1; stemp++, i++) {
- if (!ui_compatible_sockets(stemp->type, sock->type))
- continue;
-
- if (first) {
- column = uiLayoutColumn(layout, FALSE);
- uiBlockSetCurLayout(block, column);
-
- uiItemL(column, IFACE_(cname), ICON_NODE);
+
+ if (num > 1) {
+ if (j == 0) {
+ uiItemL(column, IFACE_(ntype->ui_name), ICON_NODE);
but = block->buttons.last;
but->flag = UI_TEXT_LEFT;
-
- first = 0;
}
-
- if (num > 1) {
- if (j == 0) {
- uiItemL(column, IFACE_(ntype->name), ICON_NODE);
- but = block->buttons.last;
- but->flag = UI_TEXT_LEFT;
- }
-
- BLI_snprintf(name, UI_MAX_NAME_STR, " %s", IFACE_(stemp->name));
- j++;
- }
- else
- BLI_strncpy(name, IFACE_(ntype->name), UI_MAX_NAME_STR);
-
- but = uiDefBut(block, BUT, 0, name, 0, 0, UI_UNIT_X * 4, UI_UNIT_Y,
- NULL, 0.0, 0.0, 0.0, 0.0, TIP_("Add node to input"));
-
- argN = MEM_dupallocN(arg);
- argN->type = ntype->type;
- argN->output = i;
- uiButSetNFunc(but, ui_node_link, argN, NULL);
+
+ BLI_snprintf(name, UI_MAX_NAME_STR, " %s", IFACE_(stemp->name));
+ j++;
}
+ else
+ BLI_strncpy(name, IFACE_(ntype->ui_name), UI_MAX_NAME_STR);
+
+ but = uiDefBut(block, BUT, 0, name, 0, 0, UI_UNIT_X * 4, UI_UNIT_Y,
+ NULL, 0.0, 0.0, 0.0, 0.0, TIP_("Add node to input"));
+
+ argN = MEM_dupallocN(arg);
+ argN->type = ntype->type;
+ argN->output = i;
+ uiButSetNFunc(but, ui_node_link, argN, NULL);
}
- }
+ NODE_TYPES_END
}
static void node_menu_column_foreach_cb(void *calldata, int nclass, const char *name)
@@ -460,7 +406,7 @@ static void ui_template_node_link_menu(bContext *C, uiLayout *layout, void *but_
uiLayout *split, *column;
NodeLinkArg *arg = (NodeLinkArg *)but->func_argN;
bNodeSocket *sock = arg->sock;
- bNodeTreeType *ntreetype = ntreeGetType(arg->ntree->type);
+ bNodeTreeType *ntreetype = arg->ntree->typeinfo;
uiBlockSetCurLayout(block, layout);
split = uiLayoutSplit(layout, 0.0f, FALSE);
@@ -554,7 +500,7 @@ static void ui_node_draw_node(uiLayout *layout, bContext *C, bNodeTree *ntree, b
static void ui_node_draw_input(uiLayout *layout, bContext *C, bNodeTree *ntree, bNode *node, bNodeSocket *input, int depth)
{
- PointerRNA inputptr;
+ PointerRNA inputptr, nodeptr;
uiBlock *block = uiLayoutGetBlock(layout);
uiBut *bt;
uiLayout *split, *row, *col;
@@ -576,6 +522,7 @@ static void ui_node_draw_input(uiLayout *layout, bContext *C, bNodeTree *ntree,
/* socket RNA pointer */
RNA_pointer_create(&ntree->id, &RNA_NodeSocket, input, &inputptr);
+ RNA_pointer_create(&ntree->id, &RNA_Node, node, &nodeptr);
/* indented label */
memset(label, ' ', indent);
@@ -624,16 +571,25 @@ static void ui_node_draw_input(uiLayout *layout, bContext *C, bNodeTree *ntree,
}
else {
/* input not linked, show value */
- if (input->type != SOCK_SHADER && !(input->flag & SOCK_HIDE_VALUE)) {
- if (input->type == SOCK_VECTOR) {
+ if (!(input->flag & SOCK_HIDE_VALUE)) {
+ switch (input->type) {
+ case SOCK_FLOAT:
+ case SOCK_INT:
+ case SOCK_BOOLEAN:
+ case SOCK_RGBA:
+ case SOCK_STRING:
+ row = uiLayoutRow(split, TRUE);
+ uiItemR(row, &inputptr, "default_value", 0, "", ICON_NONE);
+ break;
+ case SOCK_VECTOR:
row = uiLayoutRow(split, FALSE);
col = uiLayoutColumn(row, FALSE);
-
uiItemR(col, &inputptr, "default_value", 0, "", ICON_NONE);
- }
- else {
- row = uiLayoutRow(split, TRUE);
- uiItemR(row, &inputptr, "default_value", 0, "", ICON_NONE);
+ break;
+
+ default:
+ row = uiLayoutRow(split, FALSE);
+ break;
}
}
else