2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-12-13 18:09:49 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2008-12-13 18:09:49 +00:00
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2008 Blender Foundation.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* Contributor(s): Blender Foundation
|
|
|
|
|
*
|
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
|
*/
|
|
|
|
|
|
2011-02-27 20:29:51 +00:00
|
|
|
/** \file blender/editors/space_node/node_header.c
|
|
|
|
|
* \ingroup spnode
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2008-12-13 18:09:49 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
#include "DNA_space_types.h"
|
2008-12-24 10:33:10 +00:00
|
|
|
#include "DNA_node_types.h"
|
2008-12-13 18:09:49 +00:00
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
|
#include "DNA_screen_types.h"
|
|
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2008-12-13 18:09:49 +00:00
|
|
|
|
2011-09-20 07:39:25 +00:00
|
|
|
#include "BLF_translation.h"
|
2011-07-13 14:41:12 +00:00
|
|
|
|
2008-12-18 02:56:48 +00:00
|
|
|
#include "BKE_context.h"
|
2011-09-05 21:01:50 +00:00
|
|
|
#include "BKE_global.h"
|
2008-12-25 18:29:56 +00:00
|
|
|
#include "BKE_main.h"
|
2011-11-02 19:24:30 +00:00
|
|
|
#include "BKE_node.h"
|
|
|
|
|
#include "BKE_scene.h"
|
|
|
|
|
#include "BKE_screen.h"
|
2008-12-13 18:09:49 +00:00
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
#include "RNA_access.h"
|
|
|
|
|
|
2008-12-13 18:09:49 +00:00
|
|
|
#include "WM_api.h"
|
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
|
|
|
|
|
#include "UI_interface.h"
|
2011-02-27 18:03:19 +00:00
|
|
|
#include "UI_interface_icons.h"
|
2011-09-05 21:01:50 +00:00
|
|
|
#include "UI_resources.h"
|
2010-09-23 20:16:45 +00:00
|
|
|
#include "UI_view2d.h"
|
2008-12-13 18:09:49 +00:00
|
|
|
|
|
|
|
|
#include "node_intern.h"
|
|
|
|
|
|
2009-08-19 00:55:30 +00:00
|
|
|
/* ************************ add menu *********************** */
|
2008-12-13 18:09:49 +00:00
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
static void do_node_add(bContext *C, bNodeTemplate *ntemp)
|
2008-12-13 18:09:49 +00:00
|
|
|
{
|
2011-08-12 18:27:48 +00:00
|
|
|
Main *bmain= CTX_data_main(C);
|
|
|
|
|
Scene *scene= CTX_data_scene(C);
|
2009-07-28 16:33:02 +00:00
|
|
|
SpaceNode *snode= CTX_wm_space_node(C);
|
2011-01-03 14:36:44 +00:00
|
|
|
ScrArea *sa= CTX_wm_area(C);
|
|
|
|
|
ARegion *ar;
|
2008-12-25 18:29:56 +00:00
|
|
|
bNode *node;
|
|
|
|
|
|
2011-01-03 14:36:44 +00:00
|
|
|
/* 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->mx, &snode->my);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-25 18:29:56 +00:00
|
|
|
/* 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;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-22 14:42:29 +00:00
|
|
|
/* node= */ node_add_node(snode, bmain, scene, ntemp, snode->mx, snode->my);
|
2008-12-25 18:29:56 +00:00
|
|
|
|
2010-01-05 06:49:29 +00:00
|
|
|
/* 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;
|
|
|
|
|
}
|
2008-12-25 18:29:56 +00:00
|
|
|
|
2010-01-21 01:42:28 +00:00
|
|
|
snode_notify(C, snode);
|
2011-05-02 12:31:09 +00:00
|
|
|
snode_dag_update(C, snode);
|
2008-12-25 18:29:56 +00:00
|
|
|
}
|
|
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
static void do_node_add_static(bContext *C, void *UNUSED(arg), int event)
|
|
|
|
|
{
|
Adds a new node type for saving multiple image files from a single node.
Unlike the existing file output node this node has an arbitrary number of
possible input slots. It has a base path string that can be set to a general
base folder. Every input socket then uses its name as an extension of the base
path for file organization. This can include further subfolders on top of the
base path. Example:
Base path: '/home/user/myproject'
Input 1: 'Compo'
Input 2: 'Diffuse/'
Input 3: 'details/Normals'
would create output files
in /home/user/myproject: Compo0001.png, Compo0002.png, ...
in /home/user/myproject/Diffuse: 0001.png, 0002.png, ... (no filename base
given)
in /home/user/myproject/details: Normals0001.png, Normals0002.png, ...
Most settings for the node can be found in the sidebar (NKEY). New input sockets
can be added with the "Add Input" button. There is a list of input sockets and
below that the details for each socket can be changed, including the sub-path
and filename. Sockets can be removed here as well. By default each socket uses
the render settings file output format, but each can use its own format if
necessary.
To my knowledge this is the first node making use of such dynamic sockets in
trunk. So this is also a design test, other nodes might use this in the future.
Adding operator buttons on top of a node is a bit unwieldy atm, because all node
operators generally work on selected and/or active node(s). The operator button
would therefore either have to make sure the node is activated before the
operator is called (block callback maybe?) OR it has to store the node name
(risky, weak reference). For now it is only used in the sidebar, where only the
active node's buttons are displayed.
Also adds a new struct_type value to bNodeSocket, in order to distinguish
different socket types with the same data type (file inputs are SOCK_RGBA color
sockets). Would be nicer to use data type only for actual data evaluation, but
used in too many places, this works ok for now.
2012-02-22 12:24:04 +00:00
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
2011-09-05 21:01:50 +00:00
|
|
|
bNodeTemplate ntemp;
|
Adds a new node type for saving multiple image files from a single node.
Unlike the existing file output node this node has an arbitrary number of
possible input slots. It has a base path string that can be set to a general
base folder. Every input socket then uses its name as an extension of the base
path for file organization. This can include further subfolders on top of the
base path. Example:
Base path: '/home/user/myproject'
Input 1: 'Compo'
Input 2: 'Diffuse/'
Input 3: 'details/Normals'
would create output files
in /home/user/myproject: Compo0001.png, Compo0002.png, ...
in /home/user/myproject/Diffuse: 0001.png, 0002.png, ... (no filename base
given)
in /home/user/myproject/details: Normals0001.png, Normals0002.png, ...
Most settings for the node can be found in the sidebar (NKEY). New input sockets
can be added with the "Add Input" button. There is a list of input sockets and
below that the details for each socket can be changed, including the sub-path
and filename. Sockets can be removed here as well. By default each socket uses
the render settings file output format, but each can use its own format if
necessary.
To my knowledge this is the first node making use of such dynamic sockets in
trunk. So this is also a design test, other nodes might use this in the future.
Adding operator buttons on top of a node is a bit unwieldy atm, because all node
operators generally work on selected and/or active node(s). The operator button
would therefore either have to make sure the node is activated before the
operator is called (block callback maybe?) OR it has to store the node name
(risky, weak reference). For now it is only used in the sidebar, where only the
active node's buttons are displayed.
Also adds a new struct_type value to bNodeSocket, in order to distinguish
different socket types with the same data type (file inputs are SOCK_RGBA color
sockets). Would be nicer to use data type only for actual data evaluation, but
used in too many places, this works ok for now.
2012-02-22 12:24:04 +00:00
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
ntemp.type = event;
|
Adds a new node type for saving multiple image files from a single node.
Unlike the existing file output node this node has an arbitrary number of
possible input slots. It has a base path string that can be set to a general
base folder. Every input socket then uses its name as an extension of the base
path for file organization. This can include further subfolders on top of the
base path. Example:
Base path: '/home/user/myproject'
Input 1: 'Compo'
Input 2: 'Diffuse/'
Input 3: 'details/Normals'
would create output files
in /home/user/myproject: Compo0001.png, Compo0002.png, ...
in /home/user/myproject/Diffuse: 0001.png, 0002.png, ... (no filename base
given)
in /home/user/myproject/details: Normals0001.png, Normals0002.png, ...
Most settings for the node can be found in the sidebar (NKEY). New input sockets
can be added with the "Add Input" button. There is a list of input sockets and
below that the details for each socket can be changed, including the sub-path
and filename. Sockets can be removed here as well. By default each socket uses
the render settings file output format, but each can use its own format if
necessary.
To my knowledge this is the first node making use of such dynamic sockets in
trunk. So this is also a design test, other nodes might use this in the future.
Adding operator buttons on top of a node is a bit unwieldy atm, because all node
operators generally work on selected and/or active node(s). The operator button
would therefore either have to make sure the node is activated before the
operator is called (block callback maybe?) OR it has to store the node name
(risky, weak reference). For now it is only used in the sidebar, where only the
active node's buttons are displayed.
Also adds a new struct_type value to bNodeSocket, in order to distinguish
different socket types with the same data type (file inputs are SOCK_RGBA color
sockets). Would be nicer to use data type only for actual data evaluation, but
used in too many places, this works ok for now.
2012-02-22 12:24:04 +00:00
|
|
|
ntemp.main = bmain;
|
|
|
|
|
ntemp.scene = scene;
|
|
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
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);
|
Adds a new node type for saving multiple image files from a single node.
Unlike the existing file output node this node has an arbitrary number of
possible input slots. It has a base path string that can be set to a general
base folder. Every input socket then uses its name as an extension of the base
path for file organization. This can include further subfolders on top of the
base path. Example:
Base path: '/home/user/myproject'
Input 1: 'Compo'
Input 2: 'Diffuse/'
Input 3: 'details/Normals'
would create output files
in /home/user/myproject: Compo0001.png, Compo0002.png, ...
in /home/user/myproject/Diffuse: 0001.png, 0002.png, ... (no filename base
given)
in /home/user/myproject/details: Normals0001.png, Normals0002.png, ...
Most settings for the node can be found in the sidebar (NKEY). New input sockets
can be added with the "Add Input" button. There is a list of input sockets and
below that the details for each socket can be changed, including the sub-path
and filename. Sockets can be removed here as well. By default each socket uses
the render settings file output format, but each can use its own format if
necessary.
To my knowledge this is the first node making use of such dynamic sockets in
trunk. So this is also a design test, other nodes might use this in the future.
Adding operator buttons on top of a node is a bit unwieldy atm, because all node
operators generally work on selected and/or active node(s). The operator button
would therefore either have to make sure the node is activated before the
operator is called (block callback maybe?) OR it has to store the node name
(risky, weak reference). For now it is only used in the sidebar, where only the
active node's buttons are displayed.
Also adds a new struct_type value to bNodeSocket, in order to distinguish
different socket types with the same data type (file inputs are SOCK_RGBA color
sockets). Would be nicer to use data type only for actual data evaluation, but
used in too many places, this works ok for now.
2012-02-22 12:24:04 +00:00
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
2011-09-05 21:01:50 +00:00
|
|
|
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("Group", snode->treetype, ntemp.type);
|
|
|
|
|
break;
|
|
|
|
|
case NODE_FORLOOP:
|
|
|
|
|
ntemp.ngroup = ntreeAddTree("For Loop", snode->treetype, ntemp.type);
|
|
|
|
|
break;
|
|
|
|
|
case NODE_WHILELOOP:
|
|
|
|
|
ntemp.ngroup = ntreeAddTree("While Loop", snode->treetype, ntemp.type);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
ntemp.ngroup = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!ntemp.ngroup)
|
|
|
|
|
return;
|
|
|
|
|
|
Adds a new node type for saving multiple image files from a single node.
Unlike the existing file output node this node has an arbitrary number of
possible input slots. It has a base path string that can be set to a general
base folder. Every input socket then uses its name as an extension of the base
path for file organization. This can include further subfolders on top of the
base path. Example:
Base path: '/home/user/myproject'
Input 1: 'Compo'
Input 2: 'Diffuse/'
Input 3: 'details/Normals'
would create output files
in /home/user/myproject: Compo0001.png, Compo0002.png, ...
in /home/user/myproject/Diffuse: 0001.png, 0002.png, ... (no filename base
given)
in /home/user/myproject/details: Normals0001.png, Normals0002.png, ...
Most settings for the node can be found in the sidebar (NKEY). New input sockets
can be added with the "Add Input" button. There is a list of input sockets and
below that the details for each socket can be changed, including the sub-path
and filename. Sockets can be removed here as well. By default each socket uses
the render settings file output format, but each can use its own format if
necessary.
To my knowledge this is the first node making use of such dynamic sockets in
trunk. So this is also a design test, other nodes might use this in the future.
Adding operator buttons on top of a node is a bit unwieldy atm, because all node
operators generally work on selected and/or active node(s). The operator button
would therefore either have to make sure the node is activated before the
operator is called (block callback maybe?) OR it has to store the node name
(risky, weak reference). For now it is only used in the sidebar, where only the
active node's buttons are displayed.
Also adds a new struct_type value to bNodeSocket, in order to distinguish
different socket types with the same data type (file inputs are SOCK_RGBA color
sockets). Would be nicer to use data type only for actual data evaluation, but
used in too many places, this works ok for now.
2012-02-22 12:24:04 +00:00
|
|
|
ntemp.main = bmain;
|
|
|
|
|
ntemp.scene = scene;
|
|
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
do_node_add(C, &ntemp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if 0 /* disabled */
|
|
|
|
|
static void do_node_add_dynamic(bContext *C, void *UNUSED(arg), int event)
|
|
|
|
|
{
|
Adds a new node type for saving multiple image files from a single node.
Unlike the existing file output node this node has an arbitrary number of
possible input slots. It has a base path string that can be set to a general
base folder. Every input socket then uses its name as an extension of the base
path for file organization. This can include further subfolders on top of the
base path. Example:
Base path: '/home/user/myproject'
Input 1: 'Compo'
Input 2: 'Diffuse/'
Input 3: 'details/Normals'
would create output files
in /home/user/myproject: Compo0001.png, Compo0002.png, ...
in /home/user/myproject/Diffuse: 0001.png, 0002.png, ... (no filename base
given)
in /home/user/myproject/details: Normals0001.png, Normals0002.png, ...
Most settings for the node can be found in the sidebar (NKEY). New input sockets
can be added with the "Add Input" button. There is a list of input sockets and
below that the details for each socket can be changed, including the sub-path
and filename. Sockets can be removed here as well. By default each socket uses
the render settings file output format, but each can use its own format if
necessary.
To my knowledge this is the first node making use of such dynamic sockets in
trunk. So this is also a design test, other nodes might use this in the future.
Adding operator buttons on top of a node is a bit unwieldy atm, because all node
operators generally work on selected and/or active node(s). The operator button
would therefore either have to make sure the node is activated before the
operator is called (block callback maybe?) OR it has to store the node name
(risky, weak reference). For now it is only used in the sidebar, where only the
active node's buttons are displayed.
Also adds a new struct_type value to bNodeSocket, in order to distinguish
different socket types with the same data type (file inputs are SOCK_RGBA color
sockets). Would be nicer to use data type only for actual data evaluation, but
used in too many places, this works ok for now.
2012-02-22 12:24:04 +00:00
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
2011-09-05 21:01:50 +00:00
|
|
|
bNodeTemplate ntemp;
|
Adds a new node type for saving multiple image files from a single node.
Unlike the existing file output node this node has an arbitrary number of
possible input slots. It has a base path string that can be set to a general
base folder. Every input socket then uses its name as an extension of the base
path for file organization. This can include further subfolders on top of the
base path. Example:
Base path: '/home/user/myproject'
Input 1: 'Compo'
Input 2: 'Diffuse/'
Input 3: 'details/Normals'
would create output files
in /home/user/myproject: Compo0001.png, Compo0002.png, ...
in /home/user/myproject/Diffuse: 0001.png, 0002.png, ... (no filename base
given)
in /home/user/myproject/details: Normals0001.png, Normals0002.png, ...
Most settings for the node can be found in the sidebar (NKEY). New input sockets
can be added with the "Add Input" button. There is a list of input sockets and
below that the details for each socket can be changed, including the sub-path
and filename. Sockets can be removed here as well. By default each socket uses
the render settings file output format, but each can use its own format if
necessary.
To my knowledge this is the first node making use of such dynamic sockets in
trunk. So this is also a design test, other nodes might use this in the future.
Adding operator buttons on top of a node is a bit unwieldy atm, because all node
operators generally work on selected and/or active node(s). The operator button
would therefore either have to make sure the node is activated before the
operator is called (block callback maybe?) OR it has to store the node name
(risky, weak reference). For now it is only used in the sidebar, where only the
active node's buttons are displayed.
Also adds a new struct_type value to bNodeSocket, in order to distinguish
different socket types with the same data type (file inputs are SOCK_RGBA color
sockets). Would be nicer to use data type only for actual data evaluation, but
used in too many places, this works ok for now.
2012-02-22 12:24:04 +00:00
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
ntemp.type = NODE_DYNAMIC;
|
Adds a new node type for saving multiple image files from a single node.
Unlike the existing file output node this node has an arbitrary number of
possible input slots. It has a base path string that can be set to a general
base folder. Every input socket then uses its name as an extension of the base
path for file organization. This can include further subfolders on top of the
base path. Example:
Base path: '/home/user/myproject'
Input 1: 'Compo'
Input 2: 'Diffuse/'
Input 3: 'details/Normals'
would create output files
in /home/user/myproject: Compo0001.png, Compo0002.png, ...
in /home/user/myproject/Diffuse: 0001.png, 0002.png, ... (no filename base
given)
in /home/user/myproject/details: Normals0001.png, Normals0002.png, ...
Most settings for the node can be found in the sidebar (NKEY). New input sockets
can be added with the "Add Input" button. There is a list of input sockets and
below that the details for each socket can be changed, including the sub-path
and filename. Sockets can be removed here as well. By default each socket uses
the render settings file output format, but each can use its own format if
necessary.
To my knowledge this is the first node making use of such dynamic sockets in
trunk. So this is also a design test, other nodes might use this in the future.
Adding operator buttons on top of a node is a bit unwieldy atm, because all node
operators generally work on selected and/or active node(s). The operator button
would therefore either have to make sure the node is activated before the
operator is called (block callback maybe?) OR it has to store the node name
(risky, weak reference). For now it is only used in the sidebar, where only the
active node's buttons are displayed.
Also adds a new struct_type value to bNodeSocket, in order to distinguish
different socket types with the same data type (file inputs are SOCK_RGBA color
sockets). Would be nicer to use data type only for actual data evaluation, but
used in too many places, this works ok for now.
2012-02-22 12:24:04 +00:00
|
|
|
|
|
|
|
|
ntemp.main = bmain;
|
|
|
|
|
ntemp.scene = scene;
|
|
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
do_node_add(C, &ntemp);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
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)
|
2008-12-25 18:29:56 +00:00
|
|
|
{
|
|
|
|
|
Main *bmain= CTX_data_main(C);
|
2011-11-02 19:24:30 +00:00
|
|
|
Scene *scene= CTX_data_scene(C);
|
2009-07-28 16:33:02 +00:00
|
|
|
SpaceNode *snode= CTX_wm_space_node(C);
|
2008-12-25 18:29:56 +00:00
|
|
|
bNodeTree *ntree;
|
2009-08-19 00:55:30 +00:00
|
|
|
int nodeclass= GET_INT_FROM_POINTER(arg_nodeclass);
|
2011-11-02 19:24:30 +00:00
|
|
|
int event, compatibility= 0;
|
2008-12-25 18:29:56 +00:00
|
|
|
|
|
|
|
|
ntree = snode->nodetree;
|
2011-09-05 21:01:50 +00:00
|
|
|
|
2009-08-19 00:55:30 +00:00
|
|
|
if(!ntree) {
|
|
|
|
|
uiItemS(layout);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-11-02 19:24:30 +00:00
|
|
|
|
|
|
|
|
if(ntree->type == NTREE_SHADER) {
|
|
|
|
|
if(scene_use_new_shading_nodes(scene))
|
|
|
|
|
compatibility= NODE_NEW_SHADING;
|
|
|
|
|
else
|
|
|
|
|
compatibility= NODE_OLD_SHADING;
|
|
|
|
|
}
|
2009-08-19 00:55:30 +00:00
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
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, "New Group", 0, -NODE_GROUP);
|
|
|
|
|
if (node_tree_has_type(ntree->type, NODE_FORLOOP))
|
|
|
|
|
uiItemV(layout, "New For Loop", 0, -NODE_FORLOOP);
|
|
|
|
|
if (node_tree_has_type(ntree->type, NODE_WHILELOOP))
|
|
|
|
|
uiItemV(layout, "New While Loop", 0, -NODE_WHILELOOP);
|
2009-08-19 00:55:30 +00:00
|
|
|
uiItemS(layout);
|
2011-09-05 21:01:50 +00:00
|
|
|
|
|
|
|
|
for(ngroup=bmain->nodetree.first, event=0; ngroup; ngroup= ngroup->id.next, ++event) {
|
|
|
|
|
/* only use group trees */
|
|
|
|
|
if (ngroup->type==ntree->type && ELEM3(ngroup->nodetype, NODE_GROUP, NODE_FORLOOP, NODE_WHILELOOP)) {
|
|
|
|
|
uiItemV(layout, ngroup->id.name+2, 0, event);
|
2008-12-25 18:29:56 +00:00
|
|
|
}
|
|
|
|
|
}
|
2009-08-19 00:55:30 +00:00
|
|
|
}
|
2011-09-05 21:01:50 +00:00
|
|
|
else if (nodeclass==NODE_DYNAMIC) {
|
|
|
|
|
/* disabled */
|
|
|
|
|
}
|
2009-08-19 00:55:30 +00:00
|
|
|
else {
|
2011-09-05 21:01:50 +00:00
|
|
|
bNodeType *ntype;
|
|
|
|
|
|
|
|
|
|
uiLayoutSetFunc(layout, do_node_add_static, NULL);
|
|
|
|
|
|
|
|
|
|
for (ntype=ntreeGetType(ntree->type)->node_types.first; ntype; ntype=ntype->next) {
|
2011-11-02 19:24:30 +00:00
|
|
|
if (ntype->nclass==nodeclass && ntype->name)
|
|
|
|
|
if (!compatibility || (ntype->compatibility & compatibility))
|
|
|
|
|
uiItemV(layout, ntype->name, 0, ntype->type);
|
2008-12-25 18:29:56 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-07 22:14:48 +00:00
|
|
|
static void node_menu_add_foreach_cb(void *calldata, int nclass, const char *name)
|
|
|
|
|
{
|
|
|
|
|
uiLayout *layout= calldata;
|
2011-11-08 11:02:57 +00:00
|
|
|
uiItemMenuF(layout, name, 0, node_add_menu, SET_INT_IN_POINTER(nclass));
|
2011-11-07 22:14:48 +00:00
|
|
|
}
|
|
|
|
|
|
2009-08-19 00:55:30 +00:00
|
|
|
static void node_menu_add(const bContext *C, Menu *menu)
|
2008-12-25 18:29:56 +00:00
|
|
|
{
|
2011-11-02 19:24:30 +00:00
|
|
|
Scene *scene= CTX_data_scene(C);
|
2009-08-19 00:55:30 +00:00
|
|
|
SpaceNode *snode= CTX_wm_space_node(C);
|
2011-01-03 14:36:44 +00:00
|
|
|
uiLayout *layout= menu->layout;
|
2011-11-07 22:14:48 +00:00
|
|
|
bNodeTreeType *ntreetype= ntreeGetType(snode->treetype);
|
2008-12-25 18:29:56 +00:00
|
|
|
|
2009-08-19 00:55:30 +00:00
|
|
|
if(!snode->nodetree)
|
|
|
|
|
uiLayoutSetActive(layout, 0);
|
2011-11-07 22:14:48 +00:00
|
|
|
|
|
|
|
|
if(ntreetype && ntreetype->foreach_nodeclass)
|
|
|
|
|
ntreetype->foreach_nodeclass(scene, layout, node_menu_add_foreach_cb);
|
2008-12-25 18:29:56 +00:00
|
|
|
}
|
|
|
|
|
|
2010-10-15 09:07:19 +00:00
|
|
|
void node_menus_register(void)
|
2009-08-19 00:55:30 +00:00
|
|
|
{
|
|
|
|
|
MenuType *mt;
|
|
|
|
|
|
|
|
|
|
mt= MEM_callocN(sizeof(MenuType), "spacetype node menu add");
|
|
|
|
|
strcpy(mt->idname, "NODE_MT_add");
|
2011-09-15 13:20:18 +00:00
|
|
|
strcpy(mt->label, "Add");
|
2009-08-19 00:55:30 +00:00
|
|
|
mt->draw= node_menu_add;
|
2009-10-08 19:06:32 +00:00
|
|
|
WM_menutype_add(mt);
|
2009-08-19 00:55:30 +00:00
|
|
|
}
|
|
|
|
|
|