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:
authorLukas Toenne <lukas.toenne@googlemail.com>2013-03-18 20:34:57 +0400
committerLukas Toenne <lukas.toenne@googlemail.com>2013-03-18 20:34:57 +0400
commit4638e5f99a9ba59ad0b8a1fd52b12e876480b9e8 (patch)
tree2444f12b4612440f44cf02835cdf5951b6564e92 /source/blender/editors/space_node/node_header.c
parent7bfef29f2f2a1b262d28abdc6e30fcd9c1f1caad (diff)
Merge of the PyNodes branch (aka "custom nodes") into trunk.
PyNodes opens up the node system in Blender to scripters and adds a number of UI-level improvements. === Dynamic node type registration === Node types can now be added at runtime, using the RNA registration mechanism from python. This enables addons such as render engines to create a complete user interface with nodes. Examples of how such nodes can be defined can be found in my personal wiki docs atm [1] and as a script template in release/scripts/templates_py/custom_nodes.py [2]. === Node group improvements === Each node editor now has a tree history of edited node groups, which allows opening and editing nested node groups. The node editor also supports pinning now, so that different spaces can be used to edit different node groups simultaneously. For more ramblings and rationale see (really old) blog post on code.blender.org [3]. The interface of node groups has been overhauled. Sockets of a node group are no longer displayed in columns on either side, but instead special input/output nodes are used to mirror group sockets inside a node tree. This solves the problem of long node lines in groups and allows more adaptable node layout. Internal sockets can be exposed from a group by either connecting to the extension sockets in input/output nodes (shown as empty circle) or by adding sockets from the node property bar in the "Interface" panel. Further details such as the socket name can also be changed there. [1] http://wiki.blender.org/index.php/User:Phonybone/Python_Nodes [2] http://projects.blender.org/scm/viewvc.php/trunk/blender/release/scripts/templates_py/custom_nodes.py?view=markup&root=bf-blender [3] http://code.blender.org/index.php/2012/01/improving-node-group-interface-editing/
Diffstat (limited to 'source/blender/editors/space_node/node_header.c')
-rw-r--r--source/blender/editors/space_node/node_header.c177
1 files changed, 6 insertions, 171 deletions
diff --git a/source/blender/editors/space_node/node_header.c b/source/blender/editors/space_node/node_header.c
index f26b6ff0f54..175bbce756e 100644
--- a/source/blender/editors/space_node/node_header.c
+++ b/source/blender/editors/space_node/node_header.c
@@ -58,186 +58,21 @@
/* ************************ add menu *********************** */
-static void do_node_add(bContext *C, bNodeTemplate *ntemp)
-{
- Main *bmain = CTX_data_main(C);
- Scene *scene = CTX_data_scene(C);
- SpaceNode *snode = CTX_wm_space_node(C);
- ScrArea *sa = CTX_wm_area(C);
- ARegion *ar;
- bNode *node, *node_new;
-
- /* get location to add node at mouse */
- for (ar = sa->regionbase.first; ar; ar = ar->next) {
- if (ar->regiontype == RGN_TYPE_WINDOW) {
- wmWindow *win = CTX_wm_window(C);
- int x = win->eventstate->x - ar->winrct.xmin;
- int y = win->eventstate->y - ar->winrct.ymin;
-
- if (y < 60) y += 60;
- UI_view2d_region_to_view(&ar->v2d, x, y, &snode->cursor[0], &snode->cursor[1]);
- }
- }
-
- /* store selection in temp test flag */
- for (node = snode->edittree->nodes.first; node; node = node->next) {
- if (node->flag & NODE_SELECT) node->flag |= NODE_TEST;
- else node->flag &= ~NODE_TEST;
- }
-
- node_new = node_add_node(snode, bmain, scene, ntemp, snode->cursor[0], snode->cursor[1]);
-
- /* select previous selection before autoconnect */
- for (node = snode->edittree->nodes.first; node; node = node->next) {
- if (node->flag & NODE_TEST) node->flag |= NODE_SELECT;
- }
-
- /* deselect after autoconnection */
- for (node = snode->edittree->nodes.first; node; node = node->next) {
- if (node->flag & NODE_TEST) node->flag &= ~NODE_SELECT;
- }
-
- /* once this is called from an operator, this should be removed */
- if (node_new) {
- char undostr[BKE_UNDO_STR_MAX];
- BLI_snprintf(undostr, sizeof(undostr), "Add Node %s", nodeLabel(node_new));
- BKE_write_undo(C, undostr);
- }
-
- snode_notify(C, snode);
- snode_dag_update(C, snode);
-}
-
-static void do_node_add_static(bContext *C, void *UNUSED(arg), int event)
-{
- Main *bmain = CTX_data_main(C);
- Scene *scene = CTX_data_scene(C);
- bNodeTemplate ntemp;
-
- ntemp.type = event;
- ntemp.main = bmain;
- ntemp.scene = scene;
-
- do_node_add(C, &ntemp);
-}
-
-static void do_node_add_group(bContext *C, void *UNUSED(arg), int event)
-{
- SpaceNode *snode = CTX_wm_space_node(C);
- Main *bmain = CTX_data_main(C);
- Scene *scene = CTX_data_scene(C);
- bNodeTemplate ntemp;
-
- if (event >= 0) {
- ntemp.ngroup = BLI_findlink(&G.main->nodetree, event);
- ntemp.type = ntemp.ngroup->nodetype;
- }
- else {
- ntemp.type = -event;
- switch (ntemp.type) {
- case NODE_GROUP:
- ntemp.ngroup = ntreeAddTree(bmain, "Group", snode->treetype, ntemp.type);
- break;
- default:
- ntemp.ngroup = NULL;
- }
- }
- if (!ntemp.ngroup)
- return;
-
- ntemp.main = bmain;
- ntemp.scene = scene;
-
- do_node_add(C, &ntemp);
-}
-
-static int node_tree_has_type(int treetype, int nodetype)
-{
- bNodeTreeType *ttype = ntreeGetType(treetype);
- bNodeType *ntype;
- for (ntype = ttype->node_types.first; ntype; ntype = ntype->next) {
- if (ntype->type == nodetype)
- return 1;
- }
- return 0;
-}
-
-static void node_add_menu(bContext *C, uiLayout *layout, void *arg_nodeclass)
-{
- Main *bmain = CTX_data_main(C);
- Scene *scene = CTX_data_scene(C);
- SpaceNode *snode = CTX_wm_space_node(C);
- bNodeTree *ntree;
- int nodeclass = GET_INT_FROM_POINTER(arg_nodeclass);
- int event, compatibility = 0;
-
- ntree = snode->nodetree;
-
- if (!ntree) {
- uiItemS(layout);
- return;
- }
-
- if (ntree->type == NTREE_SHADER) {
- if (BKE_scene_use_new_shading_nodes(scene))
- compatibility = NODE_NEW_SHADING;
- else
- compatibility = NODE_OLD_SHADING;
- }
-
- if (nodeclass == NODE_CLASS_GROUP) {
- bNodeTree *ngroup;
-
- uiLayoutSetFunc(layout, do_node_add_group, NULL);
-
- /* XXX hack: negative numbers used for empty group types */
- if (node_tree_has_type(ntree->type, NODE_GROUP))
- uiItemV(layout, IFACE_("New Group"), 0, -NODE_GROUP);
- uiItemS(layout);
-
- for (ngroup = bmain->nodetree.first, event = 0; ngroup; ngroup = ngroup->id.next, ++event) {
- /* only use group trees */
- if (ngroup->type == ntree->type && ngroup->nodetype == NODE_GROUP) {
- uiItemV(layout, ngroup->id.name + 2, 0, event);
- }
- }
- }
- else {
- bNodeType *ntype;
-
- uiLayoutSetFunc(layout, do_node_add_static, NULL);
-
- for (ntype = ntreeGetType(ntree->type)->node_types.first; ntype; ntype = ntype->next) {
- if (ntype->nclass == nodeclass && ntype->name) {
- if (!compatibility || (ntype->compatibility & compatibility)) {
- uiItemV(layout, IFACE_(ntype->name), 0, ntype->type);
- }
- }
- }
- }
-}
-
-static void node_menu_add_foreach_cb(void *calldata, int nclass, const char *name)
-{
- uiLayout *layout = calldata;
- uiItemMenuF(layout, IFACE_(name), 0, node_add_menu, SET_INT_IN_POINTER(nclass));
-}
-
static void node_menu_add(const bContext *C, Menu *menu)
{
- Scene *scene = CTX_data_scene(C);
SpaceNode *snode = CTX_wm_space_node(C);
uiLayout *layout = menu->layout;
- bNodeTreeType *ntreetype = ntreeGetType(snode->treetype);
+ bNodeTree *ntree = snode->edittree;
- if (!snode->nodetree)
+ if (!ntree || !ntree->typeinfo || !ntree->typeinfo->draw_add_menu) {
uiLayoutSetActive(layout, FALSE);
-
+ return;
+ }
+
uiLayoutSetOperatorContext(layout, WM_OP_INVOKE_DEFAULT);
uiItemO(layout, CTX_IFACE_(BLF_I18NCONTEXT_OPERATOR_DEFAULT, "Search ..."), 0, "NODE_OT_add_search");
- if (ntreetype && ntreetype->foreach_nodeclass)
- ntreetype->foreach_nodeclass(scene, layout, node_menu_add_foreach_cb);
+ ntree->typeinfo->draw_add_menu(C, layout, ntree);
}
void node_menus_register(void)