wrong button.
Works by adding a flag to transform operators "remove_on_cancel". This is currently only used for node transforms, the idea is that if set, the operator will remove the transformed elements when it is
cancelled. It's not possible to do that in the original NODE_OT_add_node operator, because transform is modal and there is no way of reacting to a cancel outside of the transform itself (previous attempt
used a macro operator, but that also doesn't work because subsequent operators don't get executed if the previous transform cancels).
Adding a new node in Node Editor failed for "High DPI" (Only Mac retina now).
- Py script for adding nodes was doing dpi magic, which it shouldn't. It has
been replaced with a (temporary) API call to set the correct cursor location.
(Thanks to Lukas T for helping here)
- The SpaceNode->cursor[2] property now is *only* storing the coordinate
in "adding new node space". Use of this has been removed from the code where
possible, with as only exception the code to draw noodles while adding them.
Special coder note: Nodes should respect the DPI value, and draw larger with
larger buttons if you increase this size. The hack here is that this can only
work nice if also the node positions are scaled accordingly.
A better fix could be to check on scaling the node view itself for it. That
then would also remove this Python API call that was added in this commit.
However, that again might fight with how buttons layout code works now...
needs some careful checking.
Workaround for an issue with python: strings generated by py scripts should also exist in python as long as they are used in C. Else C code may access freed memory.
Simply store the generated list of items in the class, for now. :/
As some people have already noticed, the "Add" menu for nodes is a bit messy since pynodes merge. The reason for this is that the order of nodes in submenus (categories) was previously defined by the order in which all nodes are registered (at the bottom of blenkernel/intern/node.c). For the dynamic registration of node types now possible this system of defining node order along with registration is no longer viable: while it would still sort of work for C nodes, it is completely meaningless for dynamic (python) nodes, which are basically registered automatically in whatever order modules and addons are loaded, with the added complexity of unloading and reloading.
To fix this problem and add a bunch of desirable features this commit replaces the C menu with a python implementation. The new menu does not rely on any particular order of types in the node registry, but instead uses a simple explicit list of all the available nodes, grouped by categories (in scripts/nodeitems_builtins.py).
There are a number of additional features that become possible with this implementation:
1) Node Toolbar can be populated!
The list of nodes is used to create 2 UI items for each node: 1 entry in a submenu of "Add" menu and 1 item in a node toolbar panel with basically the same functionality. Clicking a button in the toolbar will add a new node of this type, just like selecting an item in the menu. The toolbar has the advantage of having collapsible panels for each category, so users can decide if they don't need certain nodes categories and have the rest more easily accessible.
2) Each node item is a true operator call.
The old Add menu is a pretty old piece of C code which doesn't even use proper operator buttons. Now there is a generic node_add operator which can be used very flexibly for adding any of the available nodes.
3) Node Items support additional settings.
Each "NodeItem" consists of the basic node type plus an optional list of initial settings that shall be applied to a new instance. This gives additional flexibility for creating variants of the same node or for defining preferred initial settings. E.g. it has been requested to disable previews for all nodes except inputs, this would be simple change in the py code and much less intrusive than in C.
4) Node items can be generated with a function.
A callback can be used in any category instead of the fixed list, which generates a set of items based on the context (much like dynamic enum items in bpy.props). Originally this was implemented for group nodes, because these nodes only make sense when linked to a node tree from the library data. This principle could come in handy for a number of other nodes, e.g. Image nodes could provide a similar list of node variants based on images in the library - no need to first add node, then select an image.
WARNING: pynodes scripters will have to rework their "draw_add_menu" callback in node tree types, this has been removed now! It was already pretty redundant, since one can add draw functions to the Add menu just like for any other menu. In the future i'd like to improve the categories system further so scripters can use it for custom node systems too, for now just make a draw callback and attach it to the Add menu.
- "Add node" was showing on wrong location when used via pulldown menus.
Now this option will put the nodes in center of the view.
- The Curves widget was making itself smaller/bigger based on width of region.
That messes up the layout engine now - especially the code that checks if
there's a scroller needed or not (it went into an eternal feedback loop).
Now this widget has fixed height (like the other larger widgets).
Better would be to allow such large widgets to be scaled vertically individually.
That's for the todo!
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/
The node_add_move operator is an extended variant which starts the (modal) transform operator right after adding a node, as a quicker way of inserting nodes in a tree.
The 'Add' menu in the node editor now has an option 'Search' at the top, which opens a separate popup for searching node types by name.
The operator for this is implemented completely in Python (this could also be done for the regular menu-based Add options in the future). There are a few necessary extensions to the RNA as well:
* The View2D struct in regions is now exposed. Currently only contains converter functions for coordinates from the region to the view (i.e. scrolled and zoomed view space). Used for converting mouse location to node space.
* The SpaceNode exposes the existing 'cursor_location' for operators to store mouse position beyond invoke calls. Not used for anything else (transforms) so far.
* The edit_tree in SpaceNode is also exposed, this is needed for operators to work correctly inside node groups.