2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-12-24 10:33:10 +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-24 10:33:10 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2005 Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
2009-01-01 16:27:02 +00:00
|
|
|
* Contributor(s): David Millan Escriva, Juho Vepsäläinen, Nathan Letwory
|
2008-12-24 10:33:10 +00:00
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2011-02-27 20:29:51 +00:00
|
|
|
/** \file blender/editors/space_node/node_edit.c
|
|
|
|
* \ingroup spnode
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2008-12-24 10:33:10 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <string.h>
|
2010-07-03 17:47:06 +00:00
|
|
|
#include <errno.h>
|
2008-12-24 10:33:10 +00:00
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
#include "DNA_ID.h"
|
2011-11-02 18:55:32 +00:00
|
|
|
#include "DNA_lamp_types.h"
|
2008-12-24 10:33:10 +00:00
|
|
|
#include "DNA_material_types.h"
|
|
|
|
#include "DNA_node_types.h"
|
2011-11-02 18:55:32 +00:00
|
|
|
#include "DNA_object_types.h"
|
2011-09-05 21:01:50 +00:00
|
|
|
#include "DNA_particle_types.h"
|
2008-12-24 10:33:10 +00:00
|
|
|
#include "DNA_scene_types.h"
|
2011-11-02 18:55:32 +00:00
|
|
|
#include "DNA_world_types.h"
|
2012-06-12 08:44:46 +00:00
|
|
|
#include "DNA_action_types.h"
|
|
|
|
#include "DNA_anim_types.h"
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_math.h"
|
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
2012-06-12 08:44:46 +00:00
|
|
|
#include "BKE_action.h"
|
|
|
|
#include "BKE_animsys.h"
|
2008-12-24 10:33:10 +00:00
|
|
|
#include "BKE_context.h"
|
2011-05-02 12:31:09 +00:00
|
|
|
#include "BKE_depsgraph.h"
|
2008-12-24 10:33:10 +00:00
|
|
|
#include "BKE_global.h"
|
|
|
|
#include "BKE_image.h"
|
|
|
|
#include "BKE_library.h"
|
|
|
|
#include "BKE_main.h"
|
|
|
|
#include "BKE_node.h"
|
|
|
|
#include "BKE_material.h"
|
2011-09-05 21:01:50 +00:00
|
|
|
#include "BKE_modifier.h"
|
2009-08-16 19:50:00 +00:00
|
|
|
#include "BKE_paint.h"
|
2011-11-08 11:38:16 +00:00
|
|
|
#include "BKE_scene.h"
|
2011-01-31 14:42:55 +00:00
|
|
|
#include "BKE_screen.h"
|
2008-12-24 10:33:10 +00:00
|
|
|
#include "BKE_texture.h"
|
2009-09-15 11:35:10 +00:00
|
|
|
#include "BKE_report.h"
|
2008-12-24 10:33:10 +00:00
|
|
|
|
|
|
|
#include "RE_pipeline.h"
|
|
|
|
|
2010-04-07 17:06:22 +00:00
|
|
|
#include "IMB_imbuf_types.h"
|
2008-12-28 00:08:34 +00:00
|
|
|
|
2009-10-07 22:05:30 +00:00
|
|
|
#include "ED_node.h"
|
2012-01-12 05:46:45 +00:00
|
|
|
#include "ED_image.h"
|
2009-01-12 00:14:37 +00:00
|
|
|
#include "ED_screen.h"
|
2011-01-31 14:42:55 +00:00
|
|
|
#include "ED_space_api.h"
|
2010-07-04 19:58:52 +00:00
|
|
|
#include "ED_render.h"
|
2009-01-12 00:14:37 +00:00
|
|
|
|
|
|
|
#include "RNA_access.h"
|
|
|
|
#include "RNA_define.h"
|
2011-09-05 21:01:50 +00:00
|
|
|
#include "RNA_enum_types.h"
|
2009-01-12 00:14:37 +00:00
|
|
|
|
|
|
|
#include "WM_api.h"
|
2008-12-28 00:08:34 +00:00
|
|
|
#include "WM_types.h"
|
|
|
|
|
2009-09-15 11:35:10 +00:00
|
|
|
#include "UI_interface.h"
|
2011-09-05 21:01:50 +00:00
|
|
|
#include "UI_resources.h"
|
2009-01-01 16:27:02 +00:00
|
|
|
#include "UI_view2d.h"
|
2010-04-07 17:06:22 +00:00
|
|
|
|
2011-01-31 14:42:55 +00:00
|
|
|
#include "IMB_imbuf.h"
|
|
|
|
|
2011-02-21 13:47:49 +00:00
|
|
|
#include "RNA_enum_types.h"
|
|
|
|
|
2011-11-08 13:07:16 +00:00
|
|
|
#include "GPU_material.h"
|
|
|
|
|
2009-01-12 00:14:37 +00:00
|
|
|
#include "node_intern.h"
|
2012-06-12 08:44:46 +00:00
|
|
|
#include "NOD_socket.h"
|
2009-01-01 16:27:02 +00:00
|
|
|
|
2011-02-21 13:47:49 +00:00
|
|
|
static EnumPropertyItem socket_in_out_items[] = {
|
2011-09-05 21:01:50 +00:00
|
|
|
{ SOCK_IN, "SOCK_IN", 0, "Input", "" },
|
|
|
|
{ SOCK_OUT, "SOCK_OUT", 0, "Output", "" },
|
|
|
|
{ 0, NULL, 0, NULL, NULL },
|
2011-02-21 13:47:49 +00:00
|
|
|
};
|
2008-12-28 00:08:34 +00:00
|
|
|
|
2009-01-27 17:12:40 +00:00
|
|
|
/* ***************** composite job manager ********************** */
|
|
|
|
|
|
|
|
typedef struct CompoJob {
|
|
|
|
Scene *scene;
|
|
|
|
bNodeTree *ntree;
|
|
|
|
bNodeTree *localtree;
|
|
|
|
short *stop;
|
|
|
|
short *do_update;
|
2010-05-27 08:22:16 +00:00
|
|
|
float *progress;
|
2009-01-27 17:12:40 +00:00
|
|
|
} CompoJob;
|
|
|
|
|
|
|
|
/* called by compo, only to check job 'stop' value */
|
|
|
|
static int compo_breakjob(void *cjv)
|
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
CompoJob *cj = cjv;
|
2009-01-27 17:12:40 +00:00
|
|
|
|
|
|
|
return *(cj->stop);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* called by compo, wmJob sends notifier */
|
2010-10-15 04:27:09 +00:00
|
|
|
static void compo_redrawjob(void *cjv, char *UNUSED(str))
|
2009-01-27 17:12:40 +00:00
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
CompoJob *cj = cjv;
|
2009-01-27 17:12:40 +00:00
|
|
|
|
2012-05-19 13:28:19 +00:00
|
|
|
*(cj->do_update) = TRUE;
|
2009-01-27 17:12:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void compo_freejob(void *cjv)
|
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
CompoJob *cj = cjv;
|
2009-01-27 17:12:40 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (cj->localtree) {
|
2009-01-27 17:12:40 +00:00
|
|
|
ntreeLocalMerge(cj->localtree, cj->ntree);
|
|
|
|
}
|
|
|
|
MEM_freeN(cj);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* only now we copy the nodetree, so adding many jobs while
|
2012-03-03 16:31:46 +00:00
|
|
|
* sliding buttons doesn't frustrate */
|
2009-01-27 17:12:40 +00:00
|
|
|
static void compo_initjob(void *cjv)
|
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
CompoJob *cj = cjv;
|
2009-01-27 17:12:40 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
cj->localtree = ntreeLocalize(cj->ntree);
|
2009-01-27 17:12:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* called before redraw notifiers, it moves finished previews over */
|
|
|
|
static void compo_updatejob(void *cjv)
|
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
CompoJob *cj = cjv;
|
2009-01-27 17:12:40 +00:00
|
|
|
|
|
|
|
ntreeLocalSync(cj->localtree, cj->ntree);
|
|
|
|
}
|
|
|
|
|
2010-05-27 08:22:16 +00:00
|
|
|
static void compo_progressjob(void *cjv, float progress)
|
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
CompoJob *cj = cjv;
|
2010-05-27 08:22:16 +00:00
|
|
|
|
|
|
|
*(cj->progress) = progress;
|
|
|
|
}
|
|
|
|
|
2009-01-27 17:12:40 +00:00
|
|
|
|
|
|
|
/* only this runs inside thread */
|
2010-05-27 08:22:16 +00:00
|
|
|
static void compo_startjob(void *cjv, short *stop, short *do_update, float *progress)
|
2009-01-27 17:12:40 +00:00
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
CompoJob *cj = cjv;
|
|
|
|
bNodeTree *ntree = cj->localtree;
|
2009-09-30 18:18:32 +00:00
|
|
|
|
2012-05-19 13:28:19 +00:00
|
|
|
if (cj->scene->use_nodes == FALSE)
|
2009-01-27 17:12:40 +00:00
|
|
|
return;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
cj->stop = stop;
|
|
|
|
cj->do_update = do_update;
|
|
|
|
cj->progress = progress;
|
|
|
|
|
|
|
|
ntree->test_break = compo_breakjob;
|
|
|
|
ntree->tbh = cj;
|
|
|
|
ntree->stats_draw = compo_redrawjob;
|
|
|
|
ntree->sdh = cj;
|
|
|
|
ntree->progress = compo_progressjob;
|
|
|
|
ntree->prh = cj;
|
2009-01-27 17:12:40 +00:00
|
|
|
|
|
|
|
// XXX BIF_store_spare();
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
ntreeCompositExecTree(ntree, &cj->scene->r, 0, 1); /* 1 is do_previews */
|
____
`````|````` | | | ..''''
| | | |______ .''
| | | | ..'
| | |_______ |___________ ....''
merge to TRUNK!
* The old compositor is still available (Debug Menu: 200)
This commit was brought to you by:
Developers:
* Monique Dewanchand
* Jeroen Bakker
* Dalai Felinto
* Lukas Tönne
Review:
* Brecht van Lommel
Testers:
* Nate Wiebe
* Wolfgang Faehnle
* Carlo Andreacchio
* Daniel Salazar
* Artur Mag
* Christian Krupa
* Francesco Siddi
* Dan McGrath
* Bassam Kurdali
But mostly by the community:
Gold:
Joshua Faulkner
Michael Tiemann
Francesco Paglia
Blender Guru
Blender Developers Fund
Silver:
Pablo Vazquez
Joel Heethaar
Amrein Olivier
Ilias Karasavvidis
Thomas Kumlehn
Sebastian Koenig
Hannu Hoffrén
Benjamin Dansie
Fred M'ule
Michel Vilain
Bradley Cathey
Gianmichele Mariani
Gottfried Hofmann
Bjørnar Frøyse
Valentijn Bruning
Paul Holmes
Clemens Rudolph
Juris Graphix
David Strebel
Ronan Zeegers
François Tarlier
Felipe Andres Esquivel Reed
Olaf Beckman
Jesus Alberto Olmos Linares
Kajimba
Maria Figueiredo
Alexandr Galperin
Francesco Siddi
Julio Iglesias Lopez
Kjartan Tysdal
Thomas Torfs
Film Works
Teruyuki Nakamura
Roger Luethi
Benoit Bolsee
Stefan Abrahamsen
Andreas Mattijat
Xavier Bouchoux
Blender 3D Graphics and Animation
Henk Vostermans
Daniel Blanco Delgado
BlenderDay/2011
Bradley Cathey
Matthieu Dupont de Dinechin
Gianmichele Mariani
Jérôme Scaillet
Bronze (Ivo Grigull, Dylan Urquidi, Philippe Derungs, Phil Beauchamp, Bruce Parrott, Mathieu Quiblier, Daniel Martinez, Leandro Inocencio, Lluc Romaní Brasó,
Jonathan Williamson, Michael Ehlen, Karlis Stigis, Dreamsteep, Martin Lindelöf, Filippo Saracino, Douwe van der Veen, Olli Äkräs, Bruno D'Arcangeli,
Francisco Sedrez Warmling, Watchmike.ca, peter lener, Matteo Novellino, Martin Kirsch, Austars Schnore, KC Elliott, Massimiliano Puliero, Karl Stein,
Wood Design Studios, Omer Khan, Jyrki Kanto, Michał Krupa, Lars Brubaker, Neil Richmond, Adam Kalisz, Robert Garlington, Ian Wilson, Carlo Andreacchio,
Jeremias Boos, Robert Holcomb, Gabriel Zöller, Robert Cude, Natibel de Leon, Nathan Turnage, Nicolas Vergnes, Philipp Kleinhenz, Norman Hartig, Louis Kreusel,
Christopher Taylor, Giovanni Remondini, Daniel Rentzsch, Nico Partipilo, Thomas Ventresco, Johannes Schwarz, Александр Коротеев, Brendon Harvey,
Marcelo G. Malheiros, Marius Giurgi, Richard Burns, Perttu Iso-Metsälä, Steve Bazin, Radoslav Borisov, Yoshiyuki Shida, Julien Guigner, Andrew Hunter,
Philipp Oeser, Daniel Thul, Thobias Johansson, Mauro Bonecchi, Georg Piorczynski, Sebastian Michailidis, L M Weedy, Gen X, Stefan Hinze, Nicolò Zubbini,
Erik Pusch, Rob Scott, Florian Koch, Charles Razack, Adrian Baker, Oliver Villar Diz, David Revoy, Julio Iglesias Lopez, Coen Spoor, Carlos Folch,
Joseph Christie, Victor Hernández García, David Mcsween, James Finnerty, Cory Kruckenberg, Giacomo Graziosi, Olivier Saraja, Lars Brubaker, Eric Hudson,
Johannes Schwarz, David Elguea, Marcus Schulderinsky, Karel De Bruijn, Lucas van Wijngaarden, Stefano Ciarrocchi, Mehmet Eribol, Thomas Berglund, Zuofei Song,
Dylan Urquidi )
2012-05-17 12:49:33 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
ntree->test_break = NULL;
|
|
|
|
ntree->stats_draw = NULL;
|
|
|
|
ntree->progress = NULL;
|
2009-01-27 17:12:40 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void snode_composite_job(const bContext *C, ScrArea *sa)
|
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = sa->spacedata.first;
|
2009-09-30 18:18:32 +00:00
|
|
|
wmJob *steve;
|
|
|
|
CompoJob *cj;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
steve = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), sa, "Compositing", WM_JOB_EXCL_RENDER | WM_JOB_PROGRESS);
|
|
|
|
cj = MEM_callocN(sizeof(CompoJob), "compo job");
|
2009-01-27 17:12:40 +00:00
|
|
|
|
|
|
|
/* customdata for preview thread */
|
2012-06-21 13:19:19 +00:00
|
|
|
cj->scene = CTX_data_scene(C);
|
|
|
|
cj->ntree = snode->nodetree;
|
2009-01-27 17:12:40 +00:00
|
|
|
|
|
|
|
/* setup job */
|
|
|
|
WM_jobs_customdata(steve, cj, compo_freejob);
|
2012-06-21 13:19:19 +00:00
|
|
|
WM_jobs_timer(steve, 0.1, NC_SCENE, NC_SCENE | ND_COMPO_RESULT);
|
2010-04-15 10:28:32 +00:00
|
|
|
WM_jobs_callbacks(steve, compo_startjob, compo_initjob, compo_updatejob, NULL);
|
2009-01-27 17:12:40 +00:00
|
|
|
|
2009-06-07 11:12:35 +00:00
|
|
|
WM_jobs_start(CTX_wm_manager(C), steve);
|
2009-01-27 17:12:40 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ***************************************** */
|
|
|
|
|
2011-01-17 18:38:44 +00:00
|
|
|
/* operator poll callback */
|
|
|
|
static int composite_node_active(bContext *C)
|
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
if (ED_operator_node_active(C)) {
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
if (snode->treetype == NTREE_COMPOSIT)
|
2011-01-17 18:38:44 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-06 18:38:10 +00:00
|
|
|
/* also checks for edited groups */
|
2011-02-14 17:55:27 +00:00
|
|
|
static bNode *editnode_get_active(bNodeTree *ntree)
|
2009-02-06 18:38:10 +00:00
|
|
|
{
|
|
|
|
bNode *node;
|
|
|
|
|
|
|
|
/* check for edited group */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = ntree->nodes.first; node; node = node->next)
|
2012-03-24 06:38:07 +00:00
|
|
|
if (nodeGroupEditGet(node))
|
2009-02-06 18:38:10 +00:00
|
|
|
break;
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node)
|
2009-02-06 18:38:10 +00:00
|
|
|
return nodeGetActive((bNodeTree *)node->id);
|
|
|
|
else
|
|
|
|
return nodeGetActive(ntree);
|
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-05-05 19:44:28 +00:00
|
|
|
static int has_nodetree(bNodeTree *ntree, bNodeTree *lookup)
|
|
|
|
{
|
|
|
|
bNode *node;
|
|
|
|
|
|
|
|
if (ntree == lookup)
|
|
|
|
return 1;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = ntree->nodes.first; node; node = node->next)
|
2012-05-05 19:44:28 +00:00
|
|
|
if (node->type == NODE_GROUP && node->id)
|
2012-06-21 13:19:19 +00:00
|
|
|
if (has_nodetree((bNodeTree *)node->id, lookup))
|
2012-05-05 19:44:28 +00:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void snode_dag_update_group(void *calldata, ID *owner_id, bNodeTree *ntree)
|
|
|
|
{
|
|
|
|
if (has_nodetree(ntree, calldata))
|
|
|
|
DAG_id_tag_update(owner_id, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void snode_dag_update(bContext *C, SpaceNode *snode)
|
2011-05-02 12:31:09 +00:00
|
|
|
{
|
2012-05-05 19:44:28 +00:00
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
|
|
|
|
/* for groups, update all ID's using this */
|
2012-06-21 13:19:19 +00:00
|
|
|
if (snode->edittree != snode->nodetree) {
|
|
|
|
bNodeTreeType *tti = ntreeGetType(snode->edittree->type);
|
2012-05-05 19:44:28 +00:00
|
|
|
tti->foreach_nodetree(bmain, snode->edittree, snode_dag_update_group);
|
|
|
|
}
|
|
|
|
|
2011-05-02 12:31:09 +00:00
|
|
|
DAG_id_tag_update(snode->id, 0);
|
|
|
|
}
|
|
|
|
|
2010-01-21 01:42:28 +00:00
|
|
|
void snode_notify(bContext *C, SpaceNode *snode)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
WM_event_add_notifier(C, NC_NODE | NA_EDITED, NULL);
|
2011-01-03 14:36:44 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
if (snode->treetype == NTREE_SHADER)
|
|
|
|
WM_event_add_notifier(C, NC_MATERIAL | ND_NODES, snode->id);
|
|
|
|
else if (snode->treetype == NTREE_COMPOSIT)
|
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_NODES, snode->id);
|
|
|
|
else if (snode->treetype == NTREE_TEXTURE)
|
|
|
|
WM_event_add_notifier(C, NC_TEXTURE | ND_NODES, snode->id);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
2009-09-15 11:35:10 +00:00
|
|
|
bNode *node_tree_get_editgroup(bNodeTree *nodetree)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
|
|
|
bNode *gnode;
|
|
|
|
|
|
|
|
/* get the groupnode */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (gnode = nodetree->nodes.first; gnode; gnode = gnode->next)
|
2012-03-24 06:38:07 +00:00
|
|
|
if (nodeGroupEditGet(gnode))
|
2008-12-24 10:33:10 +00:00
|
|
|
break;
|
|
|
|
return gnode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* assumes nothing being done in ntree yet, sets the default in/out node */
|
|
|
|
/* called from shading buttons or header */
|
2011-11-08 11:38:16 +00:00
|
|
|
void ED_node_shader_default(Scene *scene, ID *id)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
|
|
|
bNode *in, *out;
|
2011-11-08 11:38:16 +00:00
|
|
|
bNodeSocket *fromsock, *tosock, *sock;
|
2011-11-02 18:55:32 +00:00
|
|
|
bNodeTree *ntree;
|
2011-09-05 21:01:50 +00:00
|
|
|
bNodeTemplate ntemp;
|
2011-11-02 18:55:32 +00:00
|
|
|
int output_type, shader_type;
|
2011-11-08 11:38:16 +00:00
|
|
|
float color[3], strength = 1.0f;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
ntree = ntreeAddTree("Shader Nodetree", NTREE_SHADER, 0);
|
2011-11-02 18:55:32 +00:00
|
|
|
|
2012-04-28 06:31:57 +00:00
|
|
|
switch (GS(id->name)) {
|
2011-11-02 18:55:32 +00:00
|
|
|
case ID_MA: {
|
2012-06-21 13:19:19 +00:00
|
|
|
Material *ma = (Material *)id;
|
2011-11-02 18:55:32 +00:00
|
|
|
ma->nodetree = ntree;
|
|
|
|
|
2012-05-05 14:33:36 +00:00
|
|
|
if (BKE_scene_use_new_shading_nodes(scene)) {
|
2011-11-08 11:38:16 +00:00
|
|
|
output_type = SH_NODE_OUTPUT_MATERIAL;
|
|
|
|
shader_type = SH_NODE_BSDF_DIFFUSE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
output_type = SH_NODE_OUTPUT;
|
|
|
|
shader_type = SH_NODE_MATERIAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
copy_v3_v3(color, &ma->r);
|
2012-06-21 13:19:19 +00:00
|
|
|
strength = 0.0f;
|
2011-11-02 18:55:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ID_WO: {
|
2012-06-21 13:19:19 +00:00
|
|
|
World *wo = (World *)id;
|
2011-11-02 18:55:32 +00:00
|
|
|
wo->nodetree = ntree;
|
|
|
|
|
2011-11-08 11:38:16 +00:00
|
|
|
output_type = SH_NODE_OUTPUT_WORLD;
|
|
|
|
shader_type = SH_NODE_BACKGROUND;
|
|
|
|
|
|
|
|
copy_v3_v3(color, &wo->horr);
|
2012-06-21 13:19:19 +00:00
|
|
|
strength = 1.0f;
|
2011-11-02 18:55:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ID_LA: {
|
2012-06-21 13:19:19 +00:00
|
|
|
Lamp *la = (Lamp *)id;
|
2011-11-02 18:55:32 +00:00
|
|
|
la->nodetree = ntree;
|
|
|
|
|
2011-11-08 11:38:16 +00:00
|
|
|
output_type = SH_NODE_OUTPUT_LAMP;
|
|
|
|
shader_type = SH_NODE_EMISSION;
|
|
|
|
|
|
|
|
copy_v3_v3(color, &la->r);
|
2012-03-24 06:38:07 +00:00
|
|
|
if (la->type == LA_LOCAL || la->type == LA_SPOT || la->type == LA_AREA)
|
2012-06-21 13:19:19 +00:00
|
|
|
strength = 100.0f;
|
2011-11-08 11:38:16 +00:00
|
|
|
else
|
2012-06-21 13:19:19 +00:00
|
|
|
strength = 1.0f;
|
2011-11-02 18:55:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
printf("ED_node_shader_default called on wrong ID type.\n");
|
|
|
|
return;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
2011-11-02 18:55:32 +00:00
|
|
|
ntemp.type = output_type;
|
2012-06-21 13:19:19 +00:00
|
|
|
out = nodeAddNode(ntree, &ntemp);
|
|
|
|
out->locx = 300.0f; out->locy = 300.0f;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2011-11-02 18:55:32 +00:00
|
|
|
ntemp.type = shader_type;
|
2012-06-21 13:19:19 +00:00
|
|
|
in = nodeAddNode(ntree, &ntemp);
|
|
|
|
in->locx = 10.0f; in->locy = 300.0f;
|
2011-11-02 18:55:32 +00:00
|
|
|
nodeSetActive(ntree, in);
|
2008-12-24 10:33:10 +00:00
|
|
|
|
|
|
|
/* only a link from color to color */
|
2012-06-21 13:19:19 +00:00
|
|
|
fromsock = in->outputs.first;
|
|
|
|
tosock = out->inputs.first;
|
2011-11-02 18:55:32 +00:00
|
|
|
nodeAddLink(ntree, in, fromsock, out, tosock);
|
2011-11-08 11:38:16 +00:00
|
|
|
|
|
|
|
/* default values */
|
2012-05-05 14:33:36 +00:00
|
|
|
if (BKE_scene_use_new_shading_nodes(scene)) {
|
2012-06-21 13:19:19 +00:00
|
|
|
sock = in->inputs.first;
|
|
|
|
copy_v3_v3(((bNodeSocketValueRGBA *)sock->default_value)->value, color);
|
2011-11-08 11:38:16 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (strength != 0.0f) {
|
2012-06-21 13:19:19 +00:00
|
|
|
sock = in->inputs.last;
|
|
|
|
((bNodeSocketValueFloat *)sock->default_value)->value = strength;
|
2011-11-08 11:38:16 +00:00
|
|
|
}
|
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2011-11-02 18:55:32 +00:00
|
|
|
ntreeUpdateTree(ntree);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* assumes nothing being done in ntree yet, sets the default in/out node */
|
|
|
|
/* called from shading buttons or header */
|
2009-08-19 00:55:30 +00:00
|
|
|
void ED_node_composit_default(Scene *sce)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
|
|
|
bNode *in, *out;
|
|
|
|
bNodeSocket *fromsock, *tosock;
|
2011-09-05 21:01:50 +00:00
|
|
|
bNodeTemplate ntemp;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
|
|
|
/* but lets check it anyway */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (sce->nodetree) {
|
2012-03-31 00:59:17 +00:00
|
|
|
if (G.debug & G_DEBUG)
|
2010-01-22 06:48:29 +00:00
|
|
|
printf("error in composite initialize\n");
|
2008-12-24 10:33:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
sce->nodetree = ntreeAddTree("Compositing Nodetree", NTREE_COMPOSIT, 0);
|
____
`````|````` | | | ..''''
| | | |______ .''
| | | | ..'
| | |_______ |___________ ....''
merge to TRUNK!
* The old compositor is still available (Debug Menu: 200)
This commit was brought to you by:
Developers:
* Monique Dewanchand
* Jeroen Bakker
* Dalai Felinto
* Lukas Tönne
Review:
* Brecht van Lommel
Testers:
* Nate Wiebe
* Wolfgang Faehnle
* Carlo Andreacchio
* Daniel Salazar
* Artur Mag
* Christian Krupa
* Francesco Siddi
* Dan McGrath
* Bassam Kurdali
But mostly by the community:
Gold:
Joshua Faulkner
Michael Tiemann
Francesco Paglia
Blender Guru
Blender Developers Fund
Silver:
Pablo Vazquez
Joel Heethaar
Amrein Olivier
Ilias Karasavvidis
Thomas Kumlehn
Sebastian Koenig
Hannu Hoffrén
Benjamin Dansie
Fred M'ule
Michel Vilain
Bradley Cathey
Gianmichele Mariani
Gottfried Hofmann
Bjørnar Frøyse
Valentijn Bruning
Paul Holmes
Clemens Rudolph
Juris Graphix
David Strebel
Ronan Zeegers
François Tarlier
Felipe Andres Esquivel Reed
Olaf Beckman
Jesus Alberto Olmos Linares
Kajimba
Maria Figueiredo
Alexandr Galperin
Francesco Siddi
Julio Iglesias Lopez
Kjartan Tysdal
Thomas Torfs
Film Works
Teruyuki Nakamura
Roger Luethi
Benoit Bolsee
Stefan Abrahamsen
Andreas Mattijat
Xavier Bouchoux
Blender 3D Graphics and Animation
Henk Vostermans
Daniel Blanco Delgado
BlenderDay/2011
Bradley Cathey
Matthieu Dupont de Dinechin
Gianmichele Mariani
Jérôme Scaillet
Bronze (Ivo Grigull, Dylan Urquidi, Philippe Derungs, Phil Beauchamp, Bruce Parrott, Mathieu Quiblier, Daniel Martinez, Leandro Inocencio, Lluc Romaní Brasó,
Jonathan Williamson, Michael Ehlen, Karlis Stigis, Dreamsteep, Martin Lindelöf, Filippo Saracino, Douwe van der Veen, Olli Äkräs, Bruno D'Arcangeli,
Francisco Sedrez Warmling, Watchmike.ca, peter lener, Matteo Novellino, Martin Kirsch, Austars Schnore, KC Elliott, Massimiliano Puliero, Karl Stein,
Wood Design Studios, Omer Khan, Jyrki Kanto, Michał Krupa, Lars Brubaker, Neil Richmond, Adam Kalisz, Robert Garlington, Ian Wilson, Carlo Andreacchio,
Jeremias Boos, Robert Holcomb, Gabriel Zöller, Robert Cude, Natibel de Leon, Nathan Turnage, Nicolas Vergnes, Philipp Kleinhenz, Norman Hartig, Louis Kreusel,
Christopher Taylor, Giovanni Remondini, Daniel Rentzsch, Nico Partipilo, Thomas Ventresco, Johannes Schwarz, Александр Коротеев, Brendon Harvey,
Marcelo G. Malheiros, Marius Giurgi, Richard Burns, Perttu Iso-Metsälä, Steve Bazin, Radoslav Borisov, Yoshiyuki Shida, Julien Guigner, Andrew Hunter,
Philipp Oeser, Daniel Thul, Thobias Johansson, Mauro Bonecchi, Georg Piorczynski, Sebastian Michailidis, L M Weedy, Gen X, Stefan Hinze, Nicolò Zubbini,
Erik Pusch, Rob Scott, Florian Koch, Charles Razack, Adrian Baker, Oliver Villar Diz, David Revoy, Julio Iglesias Lopez, Coen Spoor, Carlos Folch,
Joseph Christie, Victor Hernández García, David Mcsween, James Finnerty, Cory Kruckenberg, Giacomo Graziosi, Olivier Saraja, Lars Brubaker, Eric Hudson,
Johannes Schwarz, David Elguea, Marcus Schulderinsky, Karel De Bruijn, Lucas van Wijngaarden, Stefano Ciarrocchi, Mehmet Eribol, Thomas Berglund, Zuofei Song,
Dylan Urquidi )
2012-05-17 12:49:33 +00:00
|
|
|
|
|
|
|
sce->nodetree->chunksize = 256;
|
|
|
|
sce->nodetree->edit_quality = NTREE_QUALITY_HIGH;
|
|
|
|
sce->nodetree->render_quality = NTREE_QUALITY_HIGH;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
ntemp.type = CMP_NODE_COMPOSITE;
|
2012-06-21 13:19:19 +00:00
|
|
|
out = nodeAddNode(sce->nodetree, &ntemp);
|
|
|
|
out->locx = 300.0f; out->locy = 400.0f;
|
|
|
|
out->id = &sce->id;
|
2010-12-01 08:49:08 +00:00
|
|
|
id_us_plus(out->id);
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
ntemp.type = CMP_NODE_R_LAYERS;
|
2012-06-21 13:19:19 +00:00
|
|
|
in = nodeAddNode(sce->nodetree, &ntemp);
|
|
|
|
in->locx = 10.0f; in->locy = 400.0f;
|
|
|
|
in->id = &sce->id;
|
2010-12-01 08:49:08 +00:00
|
|
|
id_us_plus(in->id);
|
2008-12-24 10:33:10 +00:00
|
|
|
nodeSetActive(sce->nodetree, in);
|
|
|
|
|
|
|
|
/* links from color to color */
|
2012-06-21 13:19:19 +00:00
|
|
|
fromsock = in->outputs.first;
|
|
|
|
tosock = out->inputs.first;
|
2008-12-24 10:33:10 +00:00
|
|
|
nodeAddLink(sce->nodetree, in, fromsock, out, tosock);
|
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
ntreeUpdateTree(sce->nodetree);
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2009-01-12 01:02:52 +00:00
|
|
|
// XXX ntreeCompositForceHidden(sce->nodetree);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* assumes nothing being done in ntree yet, sets the default in/out node */
|
|
|
|
/* called from shading buttons or header */
|
2009-08-19 00:55:30 +00:00
|
|
|
void ED_node_texture_default(Tex *tx)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
|
|
|
bNode *in, *out;
|
|
|
|
bNodeSocket *fromsock, *tosock;
|
2011-09-05 21:01:50 +00:00
|
|
|
bNodeTemplate ntemp;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
|
|
|
/* but lets check it anyway */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (tx->nodetree) {
|
2012-03-31 00:59:17 +00:00
|
|
|
if (G.debug & G_DEBUG)
|
2010-01-22 06:48:29 +00:00
|
|
|
printf("error in texture initialize\n");
|
2008-12-24 10:33:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
tx->nodetree = ntreeAddTree("Texture Nodetree", NTREE_TEXTURE, 0);
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
ntemp.type = TEX_NODE_OUTPUT;
|
2012-06-21 13:19:19 +00:00
|
|
|
out = nodeAddNode(tx->nodetree, &ntemp);
|
|
|
|
out->locx = 300.0f; out->locy = 300.0f;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
ntemp.type = TEX_NODE_CHECKER;
|
2012-06-21 13:19:19 +00:00
|
|
|
in = nodeAddNode(tx->nodetree, &ntemp);
|
|
|
|
in->locx = 10.0f; in->locy = 300.0f;
|
2008-12-24 10:33:10 +00:00
|
|
|
nodeSetActive(tx->nodetree, in);
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
fromsock = in->outputs.first;
|
|
|
|
tosock = out->inputs.first;
|
2008-12-24 10:33:10 +00:00
|
|
|
nodeAddLink(tx->nodetree, in, fromsock, out, tosock);
|
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
ntreeUpdateTree(tx->nodetree);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
2011-01-08 19:12:42 +00:00
|
|
|
/* id is supposed to contain a node tree */
|
2009-10-07 22:05:30 +00:00
|
|
|
void node_tree_from_ID(ID *id, bNodeTree **ntree, bNodeTree **edittree, int *treetype)
|
|
|
|
{
|
2011-09-05 21:01:50 +00:00
|
|
|
if (id) {
|
2012-06-21 13:19:19 +00:00
|
|
|
bNode *node = NULL;
|
|
|
|
short idtype = GS(id->name);
|
2011-09-05 21:01:50 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (idtype == ID_NT) {
|
2012-06-21 13:19:19 +00:00
|
|
|
*ntree = (bNodeTree *)id;
|
|
|
|
if (treetype) *treetype = (*ntree)->type;
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (idtype == ID_MA) {
|
2012-06-21 13:19:19 +00:00
|
|
|
*ntree = ((Material *)id)->nodetree;
|
|
|
|
if (treetype) *treetype = NTREE_SHADER;
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (idtype == ID_LA) {
|
2012-06-21 13:19:19 +00:00
|
|
|
*ntree = ((Lamp *)id)->nodetree;
|
|
|
|
if (treetype) *treetype = NTREE_SHADER;
|
2011-11-02 18:55:32 +00:00
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (idtype == ID_WO) {
|
2012-06-21 13:19:19 +00:00
|
|
|
*ntree = ((World *)id)->nodetree;
|
|
|
|
if (treetype) *treetype = NTREE_SHADER;
|
2011-11-02 18:55:32 +00:00
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (idtype == ID_SCE) {
|
2012-06-21 13:19:19 +00:00
|
|
|
*ntree = ((Scene *)id)->nodetree;
|
|
|
|
if (treetype) *treetype = NTREE_COMPOSIT;
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (idtype == ID_TE) {
|
2012-06-21 13:19:19 +00:00
|
|
|
*ntree = ((Tex *)id)->nodetree;
|
|
|
|
if (treetype) *treetype = NTREE_TEXTURE;
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-06-21 13:19:19 +00:00
|
|
|
if (treetype) *treetype = 0;
|
2011-09-05 21:01:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find editable group */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (edittree) {
|
|
|
|
if (*ntree)
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = (*ntree)->nodes.first; node; node = node->next)
|
2012-03-24 06:38:07 +00:00
|
|
|
if (nodeGroupEditGet(node))
|
2011-09-05 21:01:50 +00:00
|
|
|
break;
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node && node->id)
|
2012-06-21 13:19:19 +00:00
|
|
|
*edittree = (bNodeTree *)node->id;
|
2011-09-05 21:01:50 +00:00
|
|
|
else
|
2012-06-21 13:19:19 +00:00
|
|
|
*edittree = *ntree;
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
2009-10-07 22:05:30 +00:00
|
|
|
}
|
2011-01-08 19:12:42 +00:00
|
|
|
else {
|
2012-06-21 13:19:19 +00:00
|
|
|
*ntree = NULL;
|
|
|
|
*edittree = NULL;
|
|
|
|
if (treetype) *treetype = 0;
|
2009-10-07 22:05:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-24 10:33:10 +00:00
|
|
|
/* Here we set the active tree(s), even called for each redraw now, so keep it fast :) */
|
|
|
|
void snode_set_context(SpaceNode *snode, Scene *scene)
|
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
Object *ob = OBACT;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
snode->id = snode->from = NULL;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
if (snode->treetype == NTREE_SHADER) {
|
2008-12-24 10:33:10 +00:00
|
|
|
/* need active object, or we allow pinning... */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (snode->shaderfrom == SNODE_SHADER_OBJECT) {
|
|
|
|
if (ob) {
|
|
|
|
if (ob->type == OB_LAMP) {
|
2012-06-21 13:19:19 +00:00
|
|
|
snode->from = &ob->id;
|
|
|
|
snode->id = ob->data;
|
2011-11-02 18:55:32 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-06-21 13:19:19 +00:00
|
|
|
Material *ma = give_current_material(ob, ob->actcol);
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ma) {
|
2012-06-21 13:19:19 +00:00
|
|
|
snode->from = &ob->id;
|
|
|
|
snode->id = &ma->id;
|
2011-11-02 18:55:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { /* SNODE_SHADER_WORLD */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (scene->world) {
|
2012-06-21 13:19:19 +00:00
|
|
|
snode->from = NULL;
|
|
|
|
snode->id = &scene->world->id;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-06-21 13:19:19 +00:00
|
|
|
else if (snode->treetype == NTREE_COMPOSIT) {
|
|
|
|
snode->id = &scene->id;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2011-09-07 13:30:16 +00:00
|
|
|
/* update output sockets based on available layers */
|
|
|
|
ntreeCompositForceHidden(scene->nodetree, scene);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2012-06-21 13:19:19 +00:00
|
|
|
else if (snode->treetype == NTREE_TEXTURE) {
|
|
|
|
Tex *tx = NULL;
|
2009-06-08 20:08:19 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
if (snode->texfrom == SNODE_TEX_OBJECT) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ob) {
|
2012-06-21 13:19:19 +00:00
|
|
|
tx = give_current_object_texture(ob);
|
2009-08-19 00:55:30 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ob->type == OB_LAMP)
|
2012-06-21 13:19:19 +00:00
|
|
|
snode->from = (ID *)ob->data;
|
2009-08-19 00:55:30 +00:00
|
|
|
else
|
2012-06-21 13:19:19 +00:00
|
|
|
snode->from = (ID *)give_current_material(ob, ob->actcol);
|
2009-08-19 00:55:30 +00:00
|
|
|
|
|
|
|
/* from is not set fully for material nodes, should be ID + Node then */
|
2012-06-21 13:19:19 +00:00
|
|
|
snode->id = &tx->id;
|
2009-06-08 20:08:19 +00:00
|
|
|
}
|
|
|
|
}
|
2012-06-21 13:19:19 +00:00
|
|
|
else if (snode->texfrom == SNODE_TEX_WORLD) {
|
|
|
|
tx = give_current_world_texture(scene->world);
|
|
|
|
snode->from = (ID *)scene->world;
|
|
|
|
snode->id = &tx->id;
|
2009-06-08 20:08:19 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-06-21 13:19:19 +00:00
|
|
|
struct Brush *brush = NULL;
|
2009-06-08 20:08:19 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ob && (ob->mode & OB_MODE_SCULPT))
|
2012-06-21 13:19:19 +00:00
|
|
|
brush = paint_brush(&scene->toolsettings->sculpt->paint);
|
2009-08-17 04:40:59 +00:00
|
|
|
else
|
2012-06-21 13:19:19 +00:00
|
|
|
brush = paint_brush(&scene->toolsettings->imapaint.paint);
|
2009-08-17 04:40:59 +00:00
|
|
|
|
2010-03-17 22:54:55 +00:00
|
|
|
if (brush) {
|
2012-06-21 13:19:19 +00:00
|
|
|
snode->from = (ID *)brush;
|
|
|
|
tx = give_current_brush_texture(brush);
|
|
|
|
snode->id = &tx->id;
|
2010-03-17 22:54:55 +00:00
|
|
|
}
|
2008-11-12 19:03:50 +00:00
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2011-09-05 21:01:50 +00:00
|
|
|
else {
|
|
|
|
if (snode->nodetree && snode->nodetree->type == snode->treetype)
|
|
|
|
snode->id = &snode->nodetree->id;
|
|
|
|
else
|
|
|
|
snode->id = NULL;
|
|
|
|
}
|
2009-10-07 22:05:30 +00:00
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
node_tree_from_ID(snode->id, &snode->nodetree, &snode->edittree, NULL);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
2011-10-19 17:08:35 +00:00
|
|
|
static void snode_update(SpaceNode *snode, bNode *node)
|
2011-04-19 15:15:50 +00:00
|
|
|
{
|
|
|
|
bNode *gnode;
|
|
|
|
|
|
|
|
if (node)
|
2011-10-19 17:08:35 +00:00
|
|
|
nodeUpdate(snode->edittree, node);
|
2011-04-19 15:15:50 +00:00
|
|
|
|
|
|
|
/* if inside group, tag entire group */
|
2012-06-21 13:19:19 +00:00
|
|
|
gnode = node_tree_get_editgroup(snode->nodetree);
|
2012-03-24 06:38:07 +00:00
|
|
|
if (gnode)
|
2011-10-19 17:08:35 +00:00
|
|
|
nodeUpdateID(snode->nodetree, gnode->id);
|
2011-04-19 15:15:50 +00:00
|
|
|
}
|
|
|
|
|
2011-08-12 18:27:48 +00:00
|
|
|
void ED_node_set_active(Main *bmain, bNodeTree *ntree, bNode *node)
|
|
|
|
{
|
2011-11-08 13:07:16 +00:00
|
|
|
int was_active_texture = (node->flag & NODE_ACTIVE_TEXTURE);
|
|
|
|
|
2011-08-12 18:27:48 +00:00
|
|
|
nodeSetActive(ntree, node);
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
if (node->type != NODE_GROUP) {
|
|
|
|
int was_output = (node->flag & NODE_DO_OUTPUT);
|
2010-12-20 11:08:29 +00:00
|
|
|
|
2008-12-24 10:33:10 +00:00
|
|
|
/* tree specific activate calls */
|
2012-06-21 13:19:19 +00:00
|
|
|
if (ntree->type == NTREE_SHADER) {
|
2008-12-24 10:33:10 +00:00
|
|
|
/* when we select a material, active texture is cleared, for buttons */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->id && ELEM3(GS(node->id->name), ID_MA, ID_LA, ID_WO))
|
2011-08-12 18:27:48 +00:00
|
|
|
nodeClearActiveID(ntree, ID_TE);
|
2010-12-20 11:08:29 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
if (node->type == SH_NODE_OUTPUT) {
|
2010-12-20 11:08:29 +00:00
|
|
|
bNode *tnode;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (tnode = ntree->nodes.first; tnode; tnode = tnode->next)
|
|
|
|
if (tnode->type == SH_NODE_OUTPUT)
|
2010-12-20 11:08:29 +00:00
|
|
|
tnode->flag &= ~NODE_DO_OUTPUT;
|
|
|
|
|
|
|
|
node->flag |= NODE_DO_OUTPUT;
|
2012-06-21 13:19:19 +00:00
|
|
|
if (was_output == 0)
|
2011-08-12 18:27:48 +00:00
|
|
|
ED_node_generic_update(bmain, ntree, node);
|
2010-12-20 11:08:29 +00:00
|
|
|
}
|
2010-01-29 16:32:06 +00:00
|
|
|
|
2011-11-08 13:07:16 +00:00
|
|
|
/* if active texture changed, free glsl materials */
|
2012-03-24 06:38:07 +00:00
|
|
|
if ((node->flag & NODE_ACTIVE_TEXTURE) && !was_active_texture) {
|
2011-11-08 13:07:16 +00:00
|
|
|
Material *ma;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (ma = bmain->mat.first; ma; ma = ma->id.next)
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ma->nodetree && ma->use_nodes && has_nodetree(ma->nodetree, ntree))
|
2011-11-08 13:07:16 +00:00
|
|
|
GPU_material_free(ma);
|
2012-04-13 09:31:37 +00:00
|
|
|
|
|
|
|
WM_main_add_notifier(NC_IMAGE, NULL);
|
2011-11-08 13:07:16 +00:00
|
|
|
}
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
WM_main_add_notifier(NC_MATERIAL | ND_NODES, node->id);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2012-06-21 13:19:19 +00:00
|
|
|
else if (ntree->type == NTREE_COMPOSIT) {
|
2008-12-24 10:33:10 +00:00
|
|
|
/* make active viewer, currently only 1 supported... */
|
2012-06-21 13:19:19 +00:00
|
|
|
if (ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) {
|
2008-12-24 10:33:10 +00:00
|
|
|
bNode *tnode;
|
2010-12-20 11:08:29 +00:00
|
|
|
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (tnode = ntree->nodes.first; tnode; tnode = tnode->next)
|
|
|
|
if (ELEM(tnode->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER))
|
2008-12-24 10:33:10 +00:00
|
|
|
tnode->flag &= ~NODE_DO_OUTPUT;
|
|
|
|
|
|
|
|
node->flag |= NODE_DO_OUTPUT;
|
2012-06-21 13:19:19 +00:00
|
|
|
if (was_output == 0)
|
2011-08-12 18:27:48 +00:00
|
|
|
ED_node_generic_update(bmain, ntree, node);
|
2008-12-24 10:33:10 +00:00
|
|
|
|
|
|
|
/* addnode() doesnt link this yet... */
|
2012-06-21 13:19:19 +00:00
|
|
|
node->id = (ID *)BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2012-06-21 13:19:19 +00:00
|
|
|
else if (node->type == CMP_NODE_R_LAYERS) {
|
2011-08-12 18:27:48 +00:00
|
|
|
Scene *scene;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (scene = bmain->scene.first; scene; scene = scene->id.next) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (scene->nodetree && scene->use_nodes && has_nodetree(scene->nodetree, ntree)) {
|
2012-06-21 13:19:19 +00:00
|
|
|
if (node->id == NULL || node->id == (ID *)scene) {
|
|
|
|
scene->r.actlay = node->custom1;
|
2011-08-12 18:27:48 +00:00
|
|
|
}
|
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
}
|
2012-06-21 13:19:19 +00:00
|
|
|
else if (node->type == CMP_NODE_COMPOSITE) {
|
|
|
|
if (was_output == 0) {
|
2011-08-21 13:25:19 +00:00
|
|
|
bNode *tnode;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (tnode = ntree->nodes.first; tnode; tnode = tnode->next)
|
|
|
|
if (tnode->type == CMP_NODE_COMPOSITE)
|
2011-08-21 13:25:19 +00:00
|
|
|
tnode->flag &= ~NODE_DO_OUTPUT;
|
|
|
|
|
|
|
|
node->flag |= NODE_DO_OUTPUT;
|
|
|
|
ED_node_generic_update(bmain, ntree, node);
|
|
|
|
}
|
2010-12-19 15:03:27 +00:00
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2012-06-21 13:19:19 +00:00
|
|
|
else if (ntree->type == NTREE_TEXTURE) {
|
2009-10-07 22:05:30 +00:00
|
|
|
// XXX
|
|
|
|
#if 0
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->id)
|
2012-06-21 13:19:19 +00:00
|
|
|
; // XXX BIF_preview_changed(-1);
|
2008-12-24 10:33:10 +00:00
|
|
|
// allqueue(REDRAWBUTSSHADING, 1);
|
|
|
|
// allqueue(REDRAWIPO, 0);
|
2009-10-07 22:05:30 +00:00
|
|
|
#endif
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-22 14:13:33 +00:00
|
|
|
void ED_node_post_apply_transform(bContext *UNUSED(C), bNodeTree *UNUSED(ntree))
|
2011-09-05 21:01:50 +00:00
|
|
|
{
|
|
|
|
/* XXX This does not work due to layout functions relying on node->block,
|
|
|
|
* which only exists during actual drawing. Can we rely on valid totr rects?
|
|
|
|
*/
|
|
|
|
/* make sure nodes have correct bounding boxes after transform */
|
2012-05-22 14:13:33 +00:00
|
|
|
/* node_update_nodetree(C, ntree, 0.0f, 0.0f); */
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ***************** generic operator functions for nodes ***************** */
|
|
|
|
|
2011-09-20 08:48:48 +00:00
|
|
|
#if 0 /* UNUSED */
|
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
static int edit_node_poll(bContext *C)
|
|
|
|
{
|
|
|
|
return ED_operator_node_active(C);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void edit_node_properties(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* XXX could node be a context pointer? */
|
2012-01-11 08:51:06 +00:00
|
|
|
RNA_def_string(ot->srna, "node", "", MAX_NAME, "Node", "");
|
2011-09-05 21:01:50 +00:00
|
|
|
RNA_def_int(ot->srna, "socket", 0, 0, MAX_SOCKET, "Socket", "", 0, MAX_SOCKET);
|
|
|
|
RNA_def_enum(ot->srna, "in_out", socket_in_out_items, SOCK_IN, "Socket Side", "");
|
|
|
|
}
|
|
|
|
|
|
|
|
static int edit_node_invoke_properties(bContext *C, wmOperator *op)
|
|
|
|
{
|
2012-01-11 16:32:12 +00:00
|
|
|
if (!RNA_struct_property_is_set(op->ptr, "node")) {
|
2012-06-21 13:19:19 +00:00
|
|
|
bNode *node = CTX_data_pointer_get_type(C, "node", &RNA_Node).data;
|
2011-09-05 21:01:50 +00:00
|
|
|
if (!node)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
RNA_string_set(op->ptr, "node", node->name);
|
|
|
|
}
|
|
|
|
|
2012-01-11 16:32:12 +00:00
|
|
|
if (!RNA_struct_property_is_set(op->ptr, "in_out"))
|
2011-09-05 21:01:50 +00:00
|
|
|
RNA_enum_set(op->ptr, "in_out", SOCK_IN);
|
|
|
|
|
2012-01-11 16:32:12 +00:00
|
|
|
if (!RNA_struct_property_is_set(op->ptr, "socket"))
|
2011-09-05 21:01:50 +00:00
|
|
|
RNA_int_set(op->ptr, "socket", 0);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void edit_node_properties_get(wmOperator *op, bNodeTree *ntree, bNode **rnode, bNodeSocket **rsock, int *rin_out)
|
|
|
|
{
|
|
|
|
bNode *node;
|
2012-06-21 13:19:19 +00:00
|
|
|
bNodeSocket *sock = NULL;
|
2012-01-11 08:51:06 +00:00
|
|
|
char nodename[MAX_NAME];
|
2011-09-05 21:01:50 +00:00
|
|
|
int sockindex;
|
|
|
|
int in_out;
|
|
|
|
|
|
|
|
RNA_string_get(op->ptr, "node", nodename);
|
|
|
|
node = nodeFindNodebyName(ntree, nodename);
|
|
|
|
|
|
|
|
in_out = RNA_enum_get(op->ptr, "in_out");
|
|
|
|
|
|
|
|
sockindex = RNA_int_get(op->ptr, "socket");
|
|
|
|
switch (in_out) {
|
2012-06-21 13:19:19 +00:00
|
|
|
case SOCK_IN: sock = BLI_findlink(&node->inputs, sockindex); break;
|
|
|
|
case SOCK_OUT: sock = BLI_findlink(&node->outputs, sockindex); break;
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (rnode)
|
|
|
|
*rnode = node;
|
|
|
|
if (rsock)
|
|
|
|
*rsock = sock;
|
|
|
|
if (rin_out)
|
|
|
|
*rin_out = in_out;
|
2009-11-20 21:04:41 +00:00
|
|
|
}
|
2011-09-20 08:48:48 +00:00
|
|
|
#endif
|
2009-11-20 21:04:41 +00:00
|
|
|
|
2009-09-15 11:35:10 +00:00
|
|
|
/* ***************** Edit Group operator ************* */
|
|
|
|
|
2008-12-24 10:33:10 +00:00
|
|
|
void snode_make_group_editable(SpaceNode *snode, bNode *gnode)
|
|
|
|
{
|
|
|
|
bNode *node;
|
|
|
|
|
|
|
|
/* make sure nothing has group editing on */
|
2012-07-24 12:35:41 +00:00
|
|
|
for (node = snode->nodetree->nodes.first; node; node = node->next) {
|
2011-09-05 21:01:50 +00:00
|
|
|
nodeGroupEditClear(node);
|
2012-07-24 12:35:41 +00:00
|
|
|
|
|
|
|
/* while we're here, clear texture active */
|
|
|
|
if (node->typeinfo->nclass == NODE_CLASS_TEXTURE) {
|
|
|
|
/* this is not 100% sure to be reliable, see comment on the flag */
|
|
|
|
node->flag &= ~NODE_ACTIVE_TEXTURE;
|
|
|
|
}
|
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
if (gnode == NULL) {
|
2008-12-24 10:33:10 +00:00
|
|
|
/* with NULL argument we do a toggle */
|
2012-06-21 13:19:19 +00:00
|
|
|
if (snode->edittree == snode->nodetree)
|
|
|
|
gnode = nodeGetActive(snode->nodetree);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
if (gnode) {
|
|
|
|
snode->edittree = nodeGroupEditSet(gnode, 1);
|
2008-12-24 10:33:10 +00:00
|
|
|
|
|
|
|
/* deselect all other nodes, so we can also do grabbing of entire subtree */
|
2012-07-24 12:35:41 +00:00
|
|
|
for (node = snode->nodetree->nodes.first; node; node = node->next) {
|
2012-03-14 18:10:57 +00:00
|
|
|
node_deselect(node);
|
2012-07-24 12:35:41 +00:00
|
|
|
|
|
|
|
if (node->typeinfo->nclass == NODE_CLASS_TEXTURE) {
|
|
|
|
/* this is not 100% sure to be reliable, see comment on the flag */
|
|
|
|
node->flag &= ~NODE_ACTIVE_TEXTURE;
|
|
|
|
}
|
|
|
|
}
|
2012-03-14 18:10:57 +00:00
|
|
|
node_select(gnode);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
else
|
2012-06-21 13:19:19 +00:00
|
|
|
snode->edittree = snode->nodetree;
|
2009-09-15 11:35:10 +00:00
|
|
|
}
|
|
|
|
|
2010-10-15 01:36:14 +00:00
|
|
|
static int node_group_edit_exec(bContext *C, wmOperator *UNUSED(op))
|
2009-09-15 11:35:10 +00:00
|
|
|
{
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
|
2010-07-04 19:58:52 +00:00
|
|
|
ED_preview_kill_jobs(C);
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
if (snode->nodetree == snode->edittree) {
|
2011-12-18 12:51:50 +00:00
|
|
|
bNode *gnode = nodeGetActive(snode->edittree);
|
2011-09-05 21:01:50 +00:00
|
|
|
snode_make_group_editable(snode, gnode);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
snode_make_group_editable(snode, NULL);
|
2009-09-15 11:35:10 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_NODES, NULL);
|
2009-09-15 11:35:10 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
2010-10-15 01:36:14 +00:00
|
|
|
static int node_group_edit_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
|
2009-09-15 11:35:10 +00:00
|
|
|
{
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
bNode *gnode;
|
2011-12-18 12:51:50 +00:00
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
/* XXX callback? */
|
2012-06-21 13:19:19 +00:00
|
|
|
if (snode->nodetree == snode->edittree) {
|
2012-01-30 09:00:54 +00:00
|
|
|
gnode = nodeGetActive(snode->edittree);
|
2012-06-21 13:19:19 +00:00
|
|
|
if (gnode && gnode->id && GS(gnode->id->name) == ID_NT && gnode->id->lib) {
|
2012-01-30 09:00:54 +00:00
|
|
|
uiPupMenuOkee(C, op->type->idname, "Make group local?");
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
2009-09-15 11:35:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return node_group_edit_exec(C, op);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NODE_OT_group_edit(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Edit Group";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description = "Edit node group";
|
2009-09-15 11:35:10 +00:00
|
|
|
ot->idname = "NODE_OT_group_edit";
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2009-09-15 11:35:10 +00:00
|
|
|
/* api callbacks */
|
|
|
|
ot->invoke = node_group_edit_invoke;
|
|
|
|
ot->exec = node_group_edit_exec;
|
|
|
|
ot->poll = ED_operator_node_active;
|
|
|
|
|
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
2011-02-21 13:47:49 +00:00
|
|
|
/* ***************** Add Group Socket operator ************* */
|
|
|
|
|
|
|
|
static int node_group_socket_add_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2012-06-21 13:19:19 +00:00
|
|
|
int in_out = -1;
|
|
|
|
char name[MAX_NAME] = "";
|
|
|
|
int type = SOCK_FLOAT;
|
|
|
|
bNodeTree *ngroup = snode->edittree;
|
2011-09-20 08:48:48 +00:00
|
|
|
/* bNodeSocket *sock; */ /* UNUSED */
|
2011-02-21 13:47:49 +00:00
|
|
|
|
|
|
|
ED_preview_kill_jobs(C);
|
|
|
|
|
2012-01-11 16:32:12 +00:00
|
|
|
if (RNA_struct_property_is_set(op->ptr, "name"))
|
2011-02-21 13:47:49 +00:00
|
|
|
RNA_string_get(op->ptr, "name", name);
|
|
|
|
|
2012-01-11 16:32:12 +00:00
|
|
|
if (RNA_struct_property_is_set(op->ptr, "type"))
|
2011-02-21 13:47:49 +00:00
|
|
|
type = RNA_enum_get(op->ptr, "type");
|
|
|
|
|
2012-01-11 16:32:12 +00:00
|
|
|
if (RNA_struct_property_is_set(op->ptr, "in_out"))
|
2011-02-21 13:47:49 +00:00
|
|
|
in_out = RNA_enum_get(op->ptr, "in_out");
|
|
|
|
else
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
/* using placeholder subtype first */
|
2011-09-20 08:48:48 +00:00
|
|
|
/* sock = */ /* UNUSED */ node_group_add_socket(ngroup, name, type, in_out);
|
2011-02-21 13:47:49 +00:00
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
ntreeUpdateTree(ngroup);
|
2011-02-21 13:47:49 +00:00
|
|
|
|
|
|
|
snode_notify(C, snode);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NODE_OT_group_socket_add(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Add Group Socket";
|
|
|
|
ot->description = "Add node group socket";
|
|
|
|
ot->idname = "NODE_OT_group_socket_add";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = node_group_socket_add_exec;
|
|
|
|
ot->poll = ED_operator_node_active;
|
|
|
|
|
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2011-02-21 13:47:49 +00:00
|
|
|
|
|
|
|
RNA_def_enum(ot->srna, "in_out", socket_in_out_items, SOCK_IN, "Socket Type", "Input or Output");
|
2012-01-11 08:51:06 +00:00
|
|
|
RNA_def_string(ot->srna, "name", "", MAX_NAME, "Name", "Group socket name");
|
2011-09-05 21:01:50 +00:00
|
|
|
RNA_def_enum(ot->srna, "type", node_socket_type_items, SOCK_FLOAT, "Type", "Type of the group socket");
|
2011-02-21 13:47:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ***************** Remove Group Socket operator ************* */
|
|
|
|
|
|
|
|
static int node_group_socket_remove_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2012-06-21 13:19:19 +00:00
|
|
|
int index = -1;
|
|
|
|
int in_out = -1;
|
|
|
|
bNodeTree *ngroup = snode->edittree;
|
2011-02-21 13:47:49 +00:00
|
|
|
bNodeSocket *sock;
|
|
|
|
|
|
|
|
ED_preview_kill_jobs(C);
|
|
|
|
|
2012-01-11 16:32:12 +00:00
|
|
|
if (RNA_struct_property_is_set(op->ptr, "index"))
|
2011-02-21 13:47:49 +00:00
|
|
|
index = RNA_int_get(op->ptr, "index");
|
|
|
|
else
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
2012-01-11 16:32:12 +00:00
|
|
|
if (RNA_struct_property_is_set(op->ptr, "in_out"))
|
2011-02-21 13:47:49 +00:00
|
|
|
in_out = RNA_enum_get(op->ptr, "in_out");
|
|
|
|
else
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
sock = (bNodeSocket *)BLI_findlink(in_out == SOCK_IN ? &ngroup->inputs : &ngroup->outputs, index);
|
2011-02-21 13:47:49 +00:00
|
|
|
if (sock) {
|
2011-09-05 21:01:50 +00:00
|
|
|
node_group_remove_socket(ngroup, sock, in_out);
|
|
|
|
ntreeUpdateTree(ngroup);
|
2011-02-21 13:47:49 +00:00
|
|
|
|
|
|
|
snode_notify(C, snode);
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NODE_OT_group_socket_remove(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Remove Group Socket";
|
2011-09-19 12:26:20 +00:00
|
|
|
ot->description = "Remove a node group socket";
|
2011-02-21 13:47:49 +00:00
|
|
|
ot->idname = "NODE_OT_group_socket_remove";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = node_group_socket_remove_exec;
|
|
|
|
ot->poll = ED_operator_node_active;
|
|
|
|
|
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2011-02-21 13:47:49 +00:00
|
|
|
|
|
|
|
RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "", 0, INT_MAX);
|
|
|
|
RNA_def_enum(ot->srna, "in_out", socket_in_out_items, SOCK_IN, "Socket Type", "Input or Output");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ***************** Move Group Socket Up operator ************* */
|
|
|
|
|
|
|
|
static int node_group_socket_move_up_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2012-06-21 13:19:19 +00:00
|
|
|
int index = -1;
|
|
|
|
int in_out = -1;
|
|
|
|
bNodeTree *ngroup = snode->edittree;
|
2011-02-21 13:47:49 +00:00
|
|
|
bNodeSocket *sock, *prev;
|
|
|
|
|
|
|
|
ED_preview_kill_jobs(C);
|
|
|
|
|
2012-01-11 16:32:12 +00:00
|
|
|
if (RNA_struct_property_is_set(op->ptr, "index"))
|
2011-02-21 13:47:49 +00:00
|
|
|
index = RNA_int_get(op->ptr, "index");
|
|
|
|
else
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
2012-01-11 16:32:12 +00:00
|
|
|
if (RNA_struct_property_is_set(op->ptr, "in_out"))
|
2011-02-21 13:47:49 +00:00
|
|
|
in_out = RNA_enum_get(op->ptr, "in_out");
|
|
|
|
else
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
|
|
|
/* swap */
|
2012-06-21 13:19:19 +00:00
|
|
|
if (in_out == SOCK_IN) {
|
|
|
|
sock = (bNodeSocket *)BLI_findlink(&ngroup->inputs, index);
|
2011-02-21 13:47:49 +00:00
|
|
|
prev = sock->prev;
|
|
|
|
/* can't move up the first socket */
|
|
|
|
if (!prev)
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
BLI_remlink(&ngroup->inputs, sock);
|
|
|
|
BLI_insertlinkbefore(&ngroup->inputs, prev, sock);
|
2011-09-05 21:01:50 +00:00
|
|
|
|
|
|
|
ngroup->update |= NTREE_UPDATE_GROUP_IN;
|
2011-02-21 13:47:49 +00:00
|
|
|
}
|
2012-06-21 13:19:19 +00:00
|
|
|
else if (in_out == SOCK_OUT) {
|
|
|
|
sock = (bNodeSocket *)BLI_findlink(&ngroup->outputs, index);
|
2011-02-21 13:47:49 +00:00
|
|
|
prev = sock->prev;
|
|
|
|
/* can't move up the first socket */
|
|
|
|
if (!prev)
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
BLI_remlink(&ngroup->outputs, sock);
|
|
|
|
BLI_insertlinkbefore(&ngroup->outputs, prev, sock);
|
2011-09-05 21:01:50 +00:00
|
|
|
|
|
|
|
ngroup->update |= NTREE_UPDATE_GROUP_OUT;
|
2011-02-21 13:47:49 +00:00
|
|
|
}
|
2011-09-05 21:01:50 +00:00
|
|
|
ntreeUpdateTree(ngroup);
|
2011-02-21 13:47:49 +00:00
|
|
|
|
|
|
|
snode_notify(C, snode);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NODE_OT_group_socket_move_up(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Move Group Socket Up";
|
|
|
|
ot->description = "Move up node group socket";
|
|
|
|
ot->idname = "NODE_OT_group_socket_move_up";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = node_group_socket_move_up_exec;
|
|
|
|
ot->poll = ED_operator_node_active;
|
|
|
|
|
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2011-02-21 13:47:49 +00:00
|
|
|
|
|
|
|
RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "", 0, INT_MAX);
|
|
|
|
RNA_def_enum(ot->srna, "in_out", socket_in_out_items, SOCK_IN, "Socket Type", "Input or Output");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ***************** Move Group Socket Up operator ************* */
|
|
|
|
|
|
|
|
static int node_group_socket_move_down_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2012-06-21 13:19:19 +00:00
|
|
|
int index = -1;
|
|
|
|
int in_out = -1;
|
|
|
|
bNodeTree *ngroup = snode->edittree;
|
2011-02-21 13:47:49 +00:00
|
|
|
bNodeSocket *sock, *next;
|
|
|
|
|
|
|
|
ED_preview_kill_jobs(C);
|
|
|
|
|
2012-01-11 16:32:12 +00:00
|
|
|
if (RNA_struct_property_is_set(op->ptr, "index"))
|
2011-02-21 13:47:49 +00:00
|
|
|
index = RNA_int_get(op->ptr, "index");
|
|
|
|
else
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
2012-01-11 16:32:12 +00:00
|
|
|
if (RNA_struct_property_is_set(op->ptr, "in_out"))
|
2011-02-21 13:47:49 +00:00
|
|
|
in_out = RNA_enum_get(op->ptr, "in_out");
|
|
|
|
else
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
|
|
|
/* swap */
|
2012-06-21 13:19:19 +00:00
|
|
|
if (in_out == SOCK_IN) {
|
|
|
|
sock = (bNodeSocket *)BLI_findlink(&ngroup->inputs, index);
|
2011-02-21 13:47:49 +00:00
|
|
|
next = sock->next;
|
|
|
|
/* can't move down the last socket */
|
|
|
|
if (!next)
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
BLI_remlink(&ngroup->inputs, sock);
|
|
|
|
BLI_insertlinkafter(&ngroup->inputs, next, sock);
|
2011-09-05 21:01:50 +00:00
|
|
|
|
|
|
|
ngroup->update |= NTREE_UPDATE_GROUP_IN;
|
2011-02-21 13:47:49 +00:00
|
|
|
}
|
2012-06-21 13:19:19 +00:00
|
|
|
else if (in_out == SOCK_OUT) {
|
|
|
|
sock = (bNodeSocket *)BLI_findlink(&ngroup->outputs, index);
|
2011-02-21 13:47:49 +00:00
|
|
|
next = sock->next;
|
|
|
|
/* can't move down the last socket */
|
|
|
|
if (!next)
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
BLI_remlink(&ngroup->outputs, sock);
|
|
|
|
BLI_insertlinkafter(&ngroup->outputs, next, sock);
|
2011-09-05 21:01:50 +00:00
|
|
|
|
|
|
|
ngroup->update |= NTREE_UPDATE_GROUP_OUT;
|
2011-02-21 13:47:49 +00:00
|
|
|
}
|
2011-09-05 21:01:50 +00:00
|
|
|
ntreeUpdateTree(ngroup);
|
2011-02-21 13:47:49 +00:00
|
|
|
|
|
|
|
snode_notify(C, snode);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NODE_OT_group_socket_move_down(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Move Group Socket Down";
|
|
|
|
ot->description = "Move down node group socket";
|
|
|
|
ot->idname = "NODE_OT_group_socket_move_down";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = node_group_socket_move_down_exec;
|
|
|
|
ot->poll = ED_operator_node_active;
|
|
|
|
|
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2011-02-21 13:47:49 +00:00
|
|
|
|
|
|
|
RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "", 0, INT_MAX);
|
|
|
|
RNA_def_enum(ot->srna, "in_out", socket_in_out_items, SOCK_IN, "Socket Type", "Input or Output");
|
|
|
|
}
|
|
|
|
|
2009-09-15 11:35:10 +00:00
|
|
|
/* ******************** Ungroup operator ********************** */
|
2008-12-28 00:08:34 +00:00
|
|
|
|
2012-06-12 08:44:46 +00:00
|
|
|
/* returns 1 if its OK */
|
|
|
|
static int node_group_ungroup(bNodeTree *ntree, bNode *gnode)
|
|
|
|
{
|
|
|
|
bNodeLink *link, *linkn;
|
|
|
|
bNode *node, *nextn;
|
|
|
|
bNodeTree *ngroup, *wgroup;
|
|
|
|
ListBase anim_basepaths = {NULL, NULL};
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
ngroup = (bNodeTree *)gnode->id;
|
|
|
|
if (ngroup == NULL) return 0;
|
2012-06-12 08:44:46 +00:00
|
|
|
|
|
|
|
/* clear new pointers, set in copytree */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = ntree->nodes.first; node; node = node->next)
|
|
|
|
node->new_node = NULL;
|
2012-06-12 08:44:46 +00:00
|
|
|
|
|
|
|
/* wgroup is a temporary copy of the NodeTree we're merging in
|
|
|
|
* - all of wgroup's nodes are transferred across to their new home
|
|
|
|
* - ngroup (i.e. the source NodeTree) is left unscathed
|
|
|
|
*/
|
2012-06-21 13:19:19 +00:00
|
|
|
wgroup = ntreeCopyTree(ngroup);
|
2012-06-12 08:44:46 +00:00
|
|
|
|
|
|
|
/* add the nodes into the ntree */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = wgroup->nodes.first; node; node = nextn) {
|
|
|
|
nextn = node->next;
|
2012-06-12 08:44:46 +00:00
|
|
|
|
|
|
|
/* keep track of this node's RNA "base" path (the part of the path identifying the node)
|
|
|
|
* if the old nodetree has animation data which potentially covers this node
|
|
|
|
*/
|
|
|
|
if (wgroup->adt) {
|
|
|
|
PointerRNA ptr;
|
|
|
|
char *path;
|
|
|
|
|
|
|
|
RNA_pointer_create(&wgroup->id, &RNA_Node, node, &ptr);
|
|
|
|
path = RNA_path_from_ID_to_struct(&ptr);
|
|
|
|
|
|
|
|
if (path)
|
|
|
|
BLI_addtail(&anim_basepaths, BLI_genericNodeN(path));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* migrate node */
|
|
|
|
BLI_remlink(&wgroup->nodes, node);
|
|
|
|
BLI_addtail(&ntree->nodes, node);
|
|
|
|
|
2012-07-10 09:31:08 +00:00
|
|
|
/* ensure unique node name in the nodee tree */
|
|
|
|
nodeUniqueName(ntree, node);
|
|
|
|
|
2012-06-12 08:44:46 +00:00
|
|
|
node->locx += gnode->locx;
|
|
|
|
node->locy += gnode->locy;
|
|
|
|
|
|
|
|
node->flag |= NODE_SELECT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* restore external links to and from the gnode */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (link = ntree->links.first; link; link = link->next) {
|
|
|
|
if (link->fromnode == gnode) {
|
2012-06-12 08:44:46 +00:00
|
|
|
if (link->fromsock->groupsock) {
|
2012-06-21 13:19:19 +00:00
|
|
|
bNodeSocket *gsock = link->fromsock->groupsock;
|
2012-06-12 08:44:46 +00:00
|
|
|
if (gsock->link) {
|
|
|
|
if (gsock->link->fromnode) {
|
|
|
|
/* NB: using the new internal copies here! the groupsock pointer still maps to the old tree */
|
|
|
|
link->fromnode = (gsock->link->fromnode ? gsock->link->fromnode->new_node : NULL);
|
|
|
|
link->fromsock = gsock->link->fromsock->new_sock;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* group output directly maps to group input */
|
2012-06-21 13:19:19 +00:00
|
|
|
bNodeSocket *insock = node_group_find_input(gnode, gsock->link->fromsock);
|
2012-06-12 08:44:46 +00:00
|
|
|
if (insock->link) {
|
|
|
|
link->fromnode = insock->link->fromnode;
|
|
|
|
link->fromsock = insock->link->fromsock;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* copy the default input value from the group socket default to the external socket */
|
|
|
|
node_socket_convert_default_value(link->tosock->type, link->tosock->default_value, gsock->type, gsock->default_value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* remove internal output links, these are not used anymore */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (link = wgroup->links.first; link; link = linkn) {
|
2012-06-12 08:44:46 +00:00
|
|
|
linkn = link->next;
|
|
|
|
if (!link->tonode)
|
|
|
|
nodeRemLink(wgroup, link);
|
|
|
|
}
|
|
|
|
/* restore links from internal nodes */
|
2012-07-12 15:14:50 +00:00
|
|
|
for (link = wgroup->links.first; link; link = linkn) {
|
|
|
|
linkn = link->next;
|
2012-06-12 08:44:46 +00:00
|
|
|
/* indicates link to group input */
|
|
|
|
if (!link->fromnode) {
|
|
|
|
/* NB: can't use find_group_node_input here,
|
|
|
|
* because gnode sockets still point to the old tree!
|
|
|
|
*/
|
|
|
|
bNodeSocket *insock;
|
2012-06-21 13:19:19 +00:00
|
|
|
for (insock = gnode->inputs.first; insock; insock = insock->next)
|
2012-06-12 08:44:46 +00:00
|
|
|
if (insock->groupsock->new_sock == link->fromsock)
|
|
|
|
break;
|
|
|
|
if (insock->link) {
|
|
|
|
link->fromnode = insock->link->fromnode;
|
|
|
|
link->fromsock = insock->link->fromsock;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* copy the default input value from the group node socket default to the internal socket */
|
|
|
|
node_socket_convert_default_value(link->tosock->type, link->tosock->default_value, insock->type, insock->default_value);
|
|
|
|
nodeRemLink(wgroup, link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add internal links to the ntree */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (link = wgroup->links.first; link; link = linkn) {
|
|
|
|
linkn = link->next;
|
2012-06-12 08:44:46 +00:00
|
|
|
BLI_remlink(&wgroup->links, link);
|
|
|
|
BLI_addtail(&ntree->links, link);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* and copy across the animation,
|
|
|
|
* note that the animation data's action can be NULL here */
|
|
|
|
if (wgroup->adt) {
|
2012-06-21 13:19:19 +00:00
|
|
|
LinkData *ld, *ldn = NULL;
|
2012-06-12 08:44:46 +00:00
|
|
|
bAction *waction;
|
|
|
|
|
|
|
|
/* firstly, wgroup needs to temporary dummy action that can be destroyed, as it shares copies */
|
|
|
|
waction = wgroup->adt->action = BKE_action_copy(wgroup->adt->action);
|
|
|
|
|
|
|
|
/* now perform the moving */
|
|
|
|
BKE_animdata_separate_by_basepath(&wgroup->id, &ntree->id, &anim_basepaths);
|
|
|
|
|
|
|
|
/* paths + their wrappers need to be freed */
|
|
|
|
for (ld = anim_basepaths.first; ld; ld = ldn) {
|
|
|
|
ldn = ld->next;
|
|
|
|
|
|
|
|
MEM_freeN(ld->data);
|
|
|
|
BLI_freelinkN(&anim_basepaths, ld);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* free temp action too */
|
|
|
|
if (waction) {
|
|
|
|
BKE_libblock_free(&G.main->action, waction);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* delete the group instance. this also removes old input links! */
|
|
|
|
nodeFreeNode(ntree, gnode);
|
|
|
|
|
|
|
|
/* free the group tree (takes care of user count) */
|
|
|
|
BKE_libblock_free(&G.main->nodetree, wgroup);
|
|
|
|
|
|
|
|
ntree->update |= NTREE_UPDATE_NODES | NTREE_UPDATE_LINKS;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-09-15 11:35:10 +00:00
|
|
|
static int node_group_ungroup_exec(bContext *C, wmOperator *op)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2009-09-15 11:35:10 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2008-12-24 10:33:10 +00:00
|
|
|
bNode *gnode;
|
|
|
|
|
2010-07-04 19:58:52 +00:00
|
|
|
ED_preview_kill_jobs(C);
|
|
|
|
|
2008-12-24 10:33:10 +00:00
|
|
|
/* are we inside of a group? */
|
2012-06-21 13:19:19 +00:00
|
|
|
gnode = node_tree_get_editgroup(snode->nodetree);
|
2012-03-24 06:38:07 +00:00
|
|
|
if (gnode)
|
2008-12-24 10:33:10 +00:00
|
|
|
snode_make_group_editable(snode, NULL);
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
gnode = nodeGetActive(snode->edittree);
|
|
|
|
if (gnode == NULL)
|
2009-09-15 11:35:10 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
if (gnode->type != NODE_GROUP) {
|
2010-12-21 15:10:09 +00:00
|
|
|
BKE_report(op->reports, RPT_WARNING, "Not a group");
|
2009-09-15 11:35:10 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
2012-06-12 08:44:46 +00:00
|
|
|
else if (node_group_ungroup(snode->nodetree, gnode)) {
|
|
|
|
ntreeUpdateTree(snode->nodetree);
|
|
|
|
}
|
|
|
|
else {
|
2010-12-21 15:10:09 +00:00
|
|
|
BKE_report(op->reports, RPT_WARNING, "Can't ungroup");
|
2009-09-15 11:35:10 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2009-09-15 11:35:10 +00:00
|
|
|
|
2011-05-02 12:31:09 +00:00
|
|
|
snode_notify(C, snode);
|
|
|
|
snode_dag_update(C, snode);
|
2009-09-15 11:35:10 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NODE_OT_group_ungroup(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Ungroup";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description = "Ungroup selected nodes";
|
2009-09-15 11:35:10 +00:00
|
|
|
ot->idname = "NODE_OT_group_ungroup";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = node_group_ungroup_exec;
|
|
|
|
ot->poll = ED_operator_node_active;
|
|
|
|
|
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
2012-06-12 08:44:46 +00:00
|
|
|
/* ******************** Separate operator ********************** */
|
|
|
|
|
|
|
|
/* returns 1 if its OK */
|
|
|
|
static int node_group_separate_selected(bNodeTree *ntree, bNode *gnode, int make_copy)
|
|
|
|
{
|
|
|
|
bNodeLink *link, *link_next;
|
|
|
|
bNode *node, *node_next, *newnode;
|
|
|
|
bNodeTree *ngroup;
|
|
|
|
ListBase anim_basepaths = {NULL, NULL};
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
ngroup = (bNodeTree *)gnode->id;
|
|
|
|
if (ngroup == NULL) return 0;
|
2012-06-12 08:44:46 +00:00
|
|
|
|
|
|
|
/* deselect all nodes in the target tree */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = ntree->nodes.first; node; node = node->next)
|
2012-06-12 08:44:46 +00:00
|
|
|
node_deselect(node);
|
|
|
|
|
|
|
|
/* clear new pointers, set in nodeCopyNode */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = ngroup->nodes.first; node; node = node->next)
|
|
|
|
node->new_node = NULL;
|
2012-06-12 08:44:46 +00:00
|
|
|
|
|
|
|
/* add selected nodes into the ntree */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = ngroup->nodes.first; node; node = node_next) {
|
2012-06-12 08:44:46 +00:00
|
|
|
node_next = node->next;
|
|
|
|
if (!(node->flag & NODE_SELECT))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (make_copy) {
|
|
|
|
/* make a copy */
|
|
|
|
newnode = nodeCopyNode(ngroup, node);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* use the existing node */
|
|
|
|
newnode = node;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* keep track of this node's RNA "base" path (the part of the path identifying the node)
|
|
|
|
* if the old nodetree has animation data which potentially covers this node
|
|
|
|
*/
|
|
|
|
if (ngroup->adt) {
|
|
|
|
PointerRNA ptr;
|
|
|
|
char *path;
|
|
|
|
|
|
|
|
RNA_pointer_create(&ngroup->id, &RNA_Node, newnode, &ptr);
|
|
|
|
path = RNA_path_from_ID_to_struct(&ptr);
|
|
|
|
|
|
|
|
if (path)
|
|
|
|
BLI_addtail(&anim_basepaths, BLI_genericNodeN(path));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ensure valid parent pointers, detach if parent stays inside the group */
|
|
|
|
if (newnode->parent && !(newnode->parent->flag & NODE_SELECT))
|
|
|
|
nodeDetachNode(newnode);
|
|
|
|
|
|
|
|
/* migrate node */
|
|
|
|
BLI_remlink(&ngroup->nodes, newnode);
|
|
|
|
BLI_addtail(&ntree->nodes, newnode);
|
|
|
|
|
2012-07-10 09:31:08 +00:00
|
|
|
/* ensure unique node name in the node tree */
|
|
|
|
nodeUniqueName(ntree, newnode);
|
|
|
|
|
2012-06-12 08:44:46 +00:00
|
|
|
newnode->locx += gnode->locx;
|
|
|
|
newnode->locy += gnode->locy;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add internal links to the ntree */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (link = ngroup->links.first; link; link = link_next) {
|
2012-06-12 08:44:46 +00:00
|
|
|
int fromselect = (link->fromnode && (link->fromnode->flag & NODE_SELECT));
|
|
|
|
int toselect = (link->tonode && (link->tonode->flag & NODE_SELECT));
|
|
|
|
link_next = link->next;
|
|
|
|
|
|
|
|
if (make_copy) {
|
|
|
|
/* make a copy of internal links */
|
|
|
|
if (fromselect && toselect)
|
|
|
|
nodeAddLink(ntree, link->fromnode->new_node, link->fromsock->new_sock, link->tonode->new_node, link->tosock->new_sock);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* move valid links over, delete broken links */
|
|
|
|
if (fromselect && toselect) {
|
|
|
|
BLI_remlink(&ngroup->links, link);
|
|
|
|
BLI_addtail(&ntree->links, link);
|
|
|
|
}
|
|
|
|
else if (fromselect || toselect) {
|
|
|
|
nodeRemLink(ngroup, link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* and copy across the animation,
|
|
|
|
* note that the animation data's action can be NULL here */
|
|
|
|
if (ngroup->adt) {
|
2012-06-21 13:19:19 +00:00
|
|
|
LinkData *ld, *ldn = NULL;
|
2012-06-12 08:44:46 +00:00
|
|
|
|
|
|
|
/* now perform the moving */
|
|
|
|
BKE_animdata_separate_by_basepath(&ngroup->id, &ntree->id, &anim_basepaths);
|
|
|
|
|
|
|
|
/* paths + their wrappers need to be freed */
|
|
|
|
for (ld = anim_basepaths.first; ld; ld = ldn) {
|
|
|
|
ldn = ld->next;
|
|
|
|
|
|
|
|
MEM_freeN(ld->data);
|
|
|
|
BLI_freelinkN(&anim_basepaths, ld);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ntree->update |= NTREE_UPDATE_NODES | NTREE_UPDATE_LINKS;
|
|
|
|
if (!make_copy)
|
|
|
|
ngroup->update |= NTREE_UPDATE_NODES | NTREE_UPDATE_LINKS;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef enum eNodeGroupSeparateType {
|
|
|
|
NODE_GS_COPY,
|
|
|
|
NODE_GS_MOVE
|
|
|
|
} eNodeGroupSeparateType;
|
|
|
|
|
|
|
|
/* Operator Property */
|
|
|
|
EnumPropertyItem node_group_separate_types[] = {
|
2012-06-21 13:19:19 +00:00
|
|
|
{NODE_GS_COPY, "COPY", 0, "Copy", "Copy to parent node tree, keep group intact"},
|
2012-06-12 08:44:46 +00:00
|
|
|
{NODE_GS_MOVE, "MOVE", 0, "Move", "Move to parent node tree, remove from group"},
|
|
|
|
{0, NULL, 0, NULL, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static int node_group_separate_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
bNode *gnode;
|
|
|
|
int type = RNA_enum_get(op->ptr, "type");
|
|
|
|
|
|
|
|
ED_preview_kill_jobs(C);
|
|
|
|
|
|
|
|
/* are we inside of a group? */
|
2012-06-21 13:19:19 +00:00
|
|
|
gnode = node_tree_get_editgroup(snode->nodetree);
|
2012-06-12 08:44:46 +00:00
|
|
|
if (!gnode) {
|
|
|
|
BKE_report(op->reports, RPT_WARNING, "Not inside node group");
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (type) {
|
2012-06-21 13:19:19 +00:00
|
|
|
case NODE_GS_COPY:
|
|
|
|
if (!node_group_separate_selected(snode->nodetree, gnode, 1)) {
|
|
|
|
BKE_report(op->reports, RPT_WARNING, "Can't separate nodes");
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NODE_GS_MOVE:
|
|
|
|
if (!node_group_separate_selected(snode->nodetree, gnode, 0)) {
|
|
|
|
BKE_report(op->reports, RPT_WARNING, "Can't separate nodes");
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
break;
|
2012-06-12 08:44:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* switch to parent tree */
|
|
|
|
snode_make_group_editable(snode, NULL);
|
|
|
|
|
|
|
|
ntreeUpdateTree(snode->nodetree);
|
|
|
|
|
|
|
|
snode_notify(C, snode);
|
|
|
|
snode_dag_update(C, snode);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int node_group_separate_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *UNUSED(event))
|
|
|
|
{
|
|
|
|
uiPopupMenu *pup = uiPupMenuBegin(C, "Separate", ICON_NONE);
|
|
|
|
uiLayout *layout = uiPupMenuLayout(pup);
|
|
|
|
|
|
|
|
uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT);
|
|
|
|
uiItemEnumO(layout, "NODE_OT_group_separate", NULL, 0, "type", NODE_GS_COPY);
|
|
|
|
uiItemEnumO(layout, "NODE_OT_group_separate", NULL, 0, "type", NODE_GS_MOVE);
|
|
|
|
|
|
|
|
uiPupMenuEnd(C, pup);
|
|
|
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NODE_OT_group_separate(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Separate";
|
|
|
|
ot->description = "Separate selected nodes from the node group";
|
|
|
|
ot->idname = "NODE_OT_group_separate";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->invoke = node_group_separate_invoke;
|
|
|
|
ot->exec = node_group_separate_exec;
|
|
|
|
ot->poll = ED_operator_node_active;
|
|
|
|
|
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2012-06-12 08:44:46 +00:00
|
|
|
|
|
|
|
RNA_def_enum(ot->srna, "type", node_group_separate_types, NODE_GS_COPY, "Type", "");
|
|
|
|
}
|
|
|
|
|
2008-12-24 10:33:10 +00:00
|
|
|
/* ************************** Node generic ************** */
|
|
|
|
|
|
|
|
/* is rct in visible part of node? */
|
|
|
|
static bNode *visible_node(SpaceNode *snode, rctf *rct)
|
|
|
|
{
|
2011-09-05 21:01:50 +00:00
|
|
|
bNode *node;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = snode->edittree->nodes.last; node; node = node->prev) {
|
2012-07-15 00:29:56 +00:00
|
|
|
if (BLI_rctf_isect(&node->totr, rct, NULL))
|
2008-12-24 10:33:10 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-09-05 21:01:50 +00:00
|
|
|
return node;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
2010-04-07 17:06:22 +00:00
|
|
|
/* **************************** */
|
|
|
|
|
|
|
|
typedef struct NodeViewMove {
|
2011-05-12 16:47:36 +00:00
|
|
|
int mvalo[2];
|
2010-04-07 17:06:22 +00:00
|
|
|
int xmin, ymin, xmax, ymax;
|
|
|
|
} NodeViewMove;
|
|
|
|
|
|
|
|
static int snode_bg_viewmove_modal(bContext *C, wmOperator *op, wmEvent *event)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
|
|
|
NodeViewMove *nvm = op->customdata;
|
2010-04-07 17:06:22 +00:00
|
|
|
|
|
|
|
switch (event->type) {
|
|
|
|
case MOUSEMOVE:
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
snode->xof -= (nvm->mvalo[0] - event->mval[0]);
|
|
|
|
snode->yof -= (nvm->mvalo[1] - event->mval[1]);
|
|
|
|
nvm->mvalo[0] = event->mval[0];
|
|
|
|
nvm->mvalo[1] = event->mval[1];
|
2010-04-07 17:06:22 +00:00
|
|
|
|
|
|
|
/* prevent dragging image outside of the window and losing it! */
|
|
|
|
CLAMP(snode->xof, nvm->xmin, nvm->xmax);
|
|
|
|
CLAMP(snode->yof, nvm->ymin, nvm->ymax);
|
|
|
|
|
|
|
|
ED_region_tag_redraw(ar);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LEFTMOUSE:
|
|
|
|
case MIDDLEMOUSE:
|
|
|
|
case RIGHTMOUSE:
|
|
|
|
|
|
|
|
MEM_freeN(nvm);
|
2012-06-21 13:19:19 +00:00
|
|
|
op->customdata = NULL;
|
2010-04-07 17:06:22 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int snode_bg_viewmove_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
|
|
|
{
|
2012-07-15 11:33:13 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2012-06-21 13:19:19 +00:00
|
|
|
ARegion *ar = CTX_wm_region(C);
|
2010-04-07 17:06:22 +00:00
|
|
|
NodeViewMove *nvm;
|
2008-12-24 10:33:10 +00:00
|
|
|
Image *ima;
|
|
|
|
ImBuf *ibuf;
|
2012-07-15 11:33:13 +00:00
|
|
|
const float pad = 32.0f; /* better be bigger then scrollbars */
|
|
|
|
|
2010-09-29 22:13:24 +00:00
|
|
|
void *lock;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
ima = BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
|
|
|
|
ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ibuf == NULL) {
|
2010-09-29 22:13:24 +00:00
|
|
|
BKE_image_release_ibuf(ima, lock);
|
2010-04-07 17:06:22 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2010-09-29 22:13:24 +00:00
|
|
|
}
|
2010-04-07 17:06:22 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
nvm = MEM_callocN(sizeof(NodeViewMove), "NodeViewMove struct");
|
|
|
|
op->customdata = nvm;
|
|
|
|
nvm->mvalo[0] = event->mval[0];
|
|
|
|
nvm->mvalo[1] = event->mval[1];
|
2010-04-07 17:06:22 +00:00
|
|
|
|
2012-07-15 11:33:13 +00:00
|
|
|
nvm->xmin = -(ar->winx / 2) - (ibuf->x * (0.5f * snode->zoom)) + pad;
|
|
|
|
nvm->xmax = (ar->winx / 2) + (ibuf->x * (0.5f * snode->zoom)) - pad;
|
|
|
|
nvm->ymin = -(ar->winy / 2) - (ibuf->y * (0.5f * snode->zoom)) + pad;
|
|
|
|
nvm->ymax = (ar->winy / 2) + (ibuf->y * (0.5f * snode->zoom)) - pad;
|
2010-09-29 22:13:24 +00:00
|
|
|
|
|
|
|
BKE_image_release_ibuf(ima, lock);
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2010-04-07 17:06:22 +00:00
|
|
|
/* add modal handler */
|
|
|
|
WM_event_add_modal_handler(C, op);
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2010-04-07 17:06:22 +00:00
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
}
|
|
|
|
|
2011-06-06 11:04:54 +00:00
|
|
|
static int snode_bg_viewmove_cancel(bContext *UNUSED(C), wmOperator *op)
|
|
|
|
{
|
|
|
|
MEM_freeN(op->customdata);
|
2012-06-21 13:19:19 +00:00
|
|
|
op->customdata = NULL;
|
2011-06-06 11:04:54 +00:00
|
|
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
2010-04-07 17:06:22 +00:00
|
|
|
|
|
|
|
void NODE_OT_backimage_move(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Background Image Move";
|
2011-01-31 16:16:15 +00:00
|
|
|
ot->description = "Move Node backdrop";
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->idname = "NODE_OT_backimage_move";
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2010-04-07 17:06:22 +00:00
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->invoke = snode_bg_viewmove_invoke;
|
|
|
|
ot->modal = snode_bg_viewmove_modal;
|
|
|
|
ot->poll = composite_node_active;
|
|
|
|
ot->cancel = snode_bg_viewmove_cancel;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2010-04-07 17:06:22 +00:00
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_BLOCKING | OPTYPE_GRAB_POINTER;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2010-04-07 17:06:22 +00:00
|
|
|
|
2010-04-08 16:36:50 +00:00
|
|
|
static int backimage_zoom(bContext *C, wmOperator *op)
|
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
|
|
|
float fac = RNA_float_get(op->ptr, "factor");
|
2010-04-08 16:36:50 +00:00
|
|
|
|
|
|
|
snode->zoom *= fac;
|
|
|
|
ED_region_tag_redraw(ar);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NODE_OT_backimage_zoom(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Background Image Zoom";
|
|
|
|
ot->idname = "NODE_OT_backimage_zoom";
|
2012-07-04 15:04:38 +00:00
|
|
|
ot->description = "Zoom in/out the background image";
|
2010-04-08 16:36:50 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = backimage_zoom;
|
|
|
|
ot->poll = composite_node_active;
|
2010-04-08 16:36:50 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->flag = OPTYPE_BLOCKING;
|
2010-04-08 16:36:50 +00:00
|
|
|
|
|
|
|
/* internal */
|
|
|
|
RNA_def_float(ot->srna, "factor", 1.2f, 0.0f, 10.0f, "Factor", "", 0.0f, 10.0f);
|
|
|
|
}
|
|
|
|
|
2011-01-31 14:42:55 +00:00
|
|
|
/******************** sample backdrop operator ********************/
|
|
|
|
|
|
|
|
typedef struct ImageSampleInfo {
|
|
|
|
ARegionType *art;
|
|
|
|
void *draw_handle;
|
|
|
|
int x, y;
|
|
|
|
int channels;
|
|
|
|
int color_manage;
|
|
|
|
|
2012-01-20 14:33:03 +00:00
|
|
|
unsigned char col[4];
|
2011-01-31 14:42:55 +00:00
|
|
|
float colf[4];
|
|
|
|
|
|
|
|
int draw;
|
|
|
|
} ImageSampleInfo;
|
|
|
|
|
2011-04-23 08:30:28 +00:00
|
|
|
static void sample_draw(const bContext *C, ARegion *ar, void *arg_info)
|
2011-01-31 14:42:55 +00:00
|
|
|
{
|
2012-02-06 22:17:41 +00:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
2012-06-21 13:19:19 +00:00
|
|
|
ImageSampleInfo *info = arg_info;
|
2011-01-31 14:42:55 +00:00
|
|
|
|
2012-06-21 14:37:56 +00:00
|
|
|
if (info->draw) {
|
|
|
|
ED_image_draw_info(ar, (scene->r.color_mgt_flag & R_COLOR_MANAGEMENT), info->channels,
|
|
|
|
info->x, info->y, info->col, info->colf,
|
|
|
|
NULL, NULL /* zbuf - unused for nodes */
|
|
|
|
);
|
|
|
|
}
|
2011-01-31 14:42:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sample_apply(bContext *C, wmOperator *op, wmEvent *event)
|
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
|
|
|
ImageSampleInfo *info = op->customdata;
|
2011-01-31 14:42:55 +00:00
|
|
|
void *lock;
|
|
|
|
Image *ima;
|
|
|
|
ImBuf *ibuf;
|
|
|
|
float fx, fy, bufx, bufy;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
ima = BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
|
|
|
|
ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
|
2012-06-21 14:37:56 +00:00
|
|
|
if (!ibuf) {
|
|
|
|
info->draw = 0;
|
2011-01-31 14:42:55 +00:00
|
|
|
return;
|
2012-06-21 14:37:56 +00:00
|
|
|
}
|
2011-01-31 14:42:55 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!ibuf->rect) {
|
|
|
|
if (info->color_manage)
|
2011-01-31 14:42:55 +00:00
|
|
|
ibuf->profile = IB_PROFILE_LINEAR_RGB;
|
|
|
|
else
|
|
|
|
ibuf->profile = IB_PROFILE_NONE;
|
|
|
|
IMB_rect_from_float(ibuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* map the mouse coords to the backdrop image space */
|
|
|
|
bufx = ibuf->x * snode->zoom;
|
|
|
|
bufy = ibuf->y * snode->zoom;
|
2012-06-21 13:19:19 +00:00
|
|
|
fx = (bufx > 0.0f ? ((float)event->mval[0] - 0.5f * ar->winx - snode->xof) / bufx + 0.5f : 0.0f);
|
|
|
|
fy = (bufy > 0.0f ? ((float)event->mval[1] - 0.5f * ar->winy - snode->yof) / bufy + 0.5f : 0.0f);
|
2011-01-31 14:42:55 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
if (fx >= 0.0f && fy >= 0.0f && fx < 1.0f && fy < 1.0f) {
|
2011-01-31 14:42:55 +00:00
|
|
|
float *fp;
|
|
|
|
char *cp;
|
2012-06-21 13:19:19 +00:00
|
|
|
int x = (int)(fx * ibuf->x), y = (int)(fy * ibuf->y);
|
2011-01-31 14:42:55 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
CLAMP(x, 0, ibuf->x - 1);
|
|
|
|
CLAMP(y, 0, ibuf->y - 1);
|
2011-01-31 14:42:55 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
info->x = x;
|
|
|
|
info->y = y;
|
|
|
|
info->draw = 1;
|
|
|
|
info->channels = ibuf->channels;
|
2011-01-31 14:42:55 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ibuf->rect) {
|
2012-06-21 13:19:19 +00:00
|
|
|
cp = (char *)(ibuf->rect + y * ibuf->x + x);
|
2011-01-31 14:42:55 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
info->col[0] = cp[0];
|
|
|
|
info->col[1] = cp[1];
|
|
|
|
info->col[2] = cp[2];
|
|
|
|
info->col[3] = cp[3];
|
2011-01-31 14:42:55 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
info->colf[0] = (float)cp[0] / 255.0f;
|
|
|
|
info->colf[1] = (float)cp[1] / 255.0f;
|
|
|
|
info->colf[2] = (float)cp[2] / 255.0f;
|
|
|
|
info->colf[3] = (float)cp[3] / 255.0f;
|
2011-01-31 14:42:55 +00:00
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ibuf->rect_float) {
|
2012-06-21 13:19:19 +00:00
|
|
|
fp = (ibuf->rect_float + (ibuf->channels) * (y * ibuf->x + x));
|
2011-01-31 14:42:55 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
info->colf[0] = fp[0];
|
|
|
|
info->colf[1] = fp[1];
|
|
|
|
info->colf[2] = fp[2];
|
|
|
|
info->colf[3] = fp[3];
|
2011-01-31 14:42:55 +00:00
|
|
|
}
|
2012-06-21 14:12:14 +00:00
|
|
|
|
|
|
|
ED_node_sample_set(info->colf);
|
2011-01-31 14:42:55 +00:00
|
|
|
}
|
2012-06-21 14:12:14 +00:00
|
|
|
else {
|
2012-06-21 13:19:19 +00:00
|
|
|
info->draw = 0;
|
2012-06-21 14:12:14 +00:00
|
|
|
ED_node_sample_set(NULL);
|
|
|
|
}
|
2011-01-31 14:42:55 +00:00
|
|
|
|
|
|
|
BKE_image_release_ibuf(ima, lock);
|
|
|
|
|
|
|
|
ED_area_tag_redraw(CTX_wm_area(C));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sample_exit(bContext *C, wmOperator *op)
|
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
ImageSampleInfo *info = op->customdata;
|
2011-01-31 14:42:55 +00:00
|
|
|
|
2012-06-21 14:12:14 +00:00
|
|
|
ED_node_sample_set(NULL);
|
2011-01-31 14:42:55 +00:00
|
|
|
ED_region_draw_cb_exit(info->art, info->draw_handle);
|
|
|
|
ED_area_tag_redraw(CTX_wm_area(C));
|
|
|
|
MEM_freeN(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sample_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
2011-01-31 14:42:55 +00:00
|
|
|
ImageSampleInfo *info;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
if (snode->treetype != NTREE_COMPOSIT || !(snode->flag & SNODE_BACKDRAW))
|
2011-01-31 14:42:55 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
info = MEM_callocN(sizeof(ImageSampleInfo), "ImageSampleInfo");
|
|
|
|
info->art = ar->type;
|
2011-01-31 14:42:55 +00:00
|
|
|
info->draw_handle = ED_region_draw_cb_activate(ar->type, sample_draw, info, REGION_DRAW_POST_PIXEL);
|
2012-06-21 13:19:19 +00:00
|
|
|
op->customdata = info;
|
2011-01-31 14:42:55 +00:00
|
|
|
|
|
|
|
sample_apply(C, op, event);
|
|
|
|
|
|
|
|
WM_event_add_modal_handler(C, op);
|
|
|
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sample_modal(bContext *C, wmOperator *op, wmEvent *event)
|
|
|
|
{
|
2012-04-28 06:31:57 +00:00
|
|
|
switch (event->type) {
|
2011-01-31 14:42:55 +00:00
|
|
|
case LEFTMOUSE:
|
|
|
|
case RIGHTMOUSE: // XXX hardcoded
|
|
|
|
sample_exit(C, op);
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
case MOUSEMOVE:
|
|
|
|
sample_apply(C, op, event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sample_cancel(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
sample_exit(C, op);
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NODE_OT_backimage_sample(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Backimage Sample";
|
|
|
|
ot->idname = "NODE_OT_backimage_sample";
|
2012-05-05 17:10:51 +00:00
|
|
|
ot->description = "Use mouse to sample background image";
|
2011-01-31 14:42:55 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->invoke = sample_invoke;
|
|
|
|
ot->modal = sample_modal;
|
|
|
|
ot->cancel = sample_cancel;
|
|
|
|
ot->poll = ED_operator_node_active;
|
2011-01-31 14:42:55 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->flag = OPTYPE_BLOCKING;
|
2011-01-31 14:42:55 +00:00
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2009-02-06 18:38:10 +00:00
|
|
|
/* ********************** size widget operator ******************** */
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2009-02-06 18:38:10 +00:00
|
|
|
typedef struct NodeSizeWidget {
|
2011-09-05 21:01:50 +00:00
|
|
|
float mxstart, mystart;
|
2012-05-22 14:13:33 +00:00
|
|
|
float oldlocx, oldlocy;
|
|
|
|
float oldoffsetx, oldoffsety;
|
2011-09-05 21:01:50 +00:00
|
|
|
float oldwidth, oldheight;
|
|
|
|
float oldminiwidth;
|
2012-05-22 14:13:33 +00:00
|
|
|
int directions;
|
2009-02-06 18:38:10 +00:00
|
|
|
} NodeSizeWidget;
|
|
|
|
|
2012-05-22 14:13:33 +00:00
|
|
|
static void node_resize_init(bContext *C, wmOperator *op, wmEvent *UNUSED(event), bNode *node, int dir)
|
|
|
|
{
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
NodeSizeWidget *nsw = MEM_callocN(sizeof(NodeSizeWidget), "size widget op data");
|
2012-05-22 14:13:33 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
op->customdata = nsw;
|
|
|
|
nsw->mxstart = snode->mx;
|
|
|
|
nsw->mystart = snode->my;
|
2012-05-22 14:13:33 +00:00
|
|
|
|
|
|
|
/* store old */
|
2012-06-21 13:19:19 +00:00
|
|
|
nsw->oldlocx = node->locx;
|
|
|
|
nsw->oldlocy = node->locy;
|
|
|
|
nsw->oldoffsetx = node->offsetx;
|
|
|
|
nsw->oldoffsety = node->offsety;
|
|
|
|
nsw->oldwidth = node->width;
|
|
|
|
nsw->oldheight = node->height;
|
|
|
|
nsw->oldminiwidth = node->miniwidth;
|
2012-05-22 14:13:33 +00:00
|
|
|
nsw->directions = dir;
|
|
|
|
|
|
|
|
WM_cursor_modal(CTX_wm_window(C), node_get_resize_cursor(dir));
|
|
|
|
/* add modal handler */
|
|
|
|
WM_event_add_modal_handler(C, op);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void node_resize_exit(bContext *C, wmOperator *op, int UNUSED(cancel))
|
|
|
|
{
|
|
|
|
WM_cursor_restore(CTX_wm_window(C));
|
|
|
|
|
|
|
|
MEM_freeN(op->customdata);
|
2012-06-21 13:19:19 +00:00
|
|
|
op->customdata = NULL;
|
2012-05-22 14:13:33 +00:00
|
|
|
}
|
|
|
|
|
2009-04-15 15:40:31 +00:00
|
|
|
static int node_resize_modal(bContext *C, wmOperator *op, wmEvent *event)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
|
|
|
bNode *node = editnode_get_active(snode->edittree);
|
|
|
|
NodeSizeWidget *nsw = op->customdata;
|
2012-05-22 14:13:33 +00:00
|
|
|
float mx, my, dx, dy;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2009-02-06 18:38:10 +00:00
|
|
|
switch (event->type) {
|
|
|
|
case MOUSEMOVE:
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-05-22 14:13:33 +00:00
|
|
|
UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &mx, &my);
|
|
|
|
dx = mx - nsw->mxstart;
|
|
|
|
dy = my - nsw->mystart;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2009-11-15 11:32:29 +00:00
|
|
|
if (node) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->flag & NODE_HIDDEN) {
|
2012-05-22 14:13:33 +00:00
|
|
|
float widthmin = 0.0f;
|
|
|
|
float widthmax = 100.0f;
|
|
|
|
if (nsw->directions & NODE_RESIZE_RIGHT) {
|
2012-06-21 13:19:19 +00:00
|
|
|
node->miniwidth = nsw->oldminiwidth + dx;
|
2012-05-22 14:13:33 +00:00
|
|
|
CLAMP(node->miniwidth, widthmin, widthmax);
|
|
|
|
}
|
|
|
|
if (nsw->directions & NODE_RESIZE_LEFT) {
|
|
|
|
float locmax = nsw->oldlocx + nsw->oldminiwidth;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
node->locx = nsw->oldlocx + dx;
|
2012-05-22 14:13:33 +00:00
|
|
|
CLAMP(node->locx, locmax - widthmax, locmax - widthmin);
|
2012-06-21 13:19:19 +00:00
|
|
|
node->miniwidth = locmax - node->locx;
|
2012-05-22 14:13:33 +00:00
|
|
|
}
|
2009-11-15 11:32:29 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-06-21 13:19:19 +00:00
|
|
|
float widthmin = UI_DPI_FAC * node->typeinfo->minwidth;
|
|
|
|
float widthmax = UI_DPI_FAC * node->typeinfo->maxwidth;
|
2012-05-22 14:13:33 +00:00
|
|
|
if (nsw->directions & NODE_RESIZE_RIGHT) {
|
2012-06-21 13:19:19 +00:00
|
|
|
node->width = nsw->oldwidth + dx;
|
2012-05-22 14:13:33 +00:00
|
|
|
CLAMP(node->width, widthmin, widthmax);
|
|
|
|
}
|
|
|
|
if (nsw->directions & NODE_RESIZE_LEFT) {
|
|
|
|
float locmax = nsw->oldlocx + nsw->oldwidth;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
node->locx = nsw->oldlocx + dx;
|
2012-05-22 14:13:33 +00:00
|
|
|
CLAMP(node->locx, locmax - widthmax, locmax - widthmin);
|
2012-06-21 13:19:19 +00:00
|
|
|
node->width = locmax - node->locx;
|
2012-05-22 14:13:33 +00:00
|
|
|
}
|
2009-11-15 11:32:29 +00:00
|
|
|
}
|
2012-05-22 14:13:33 +00:00
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
/* height works the other way round ... */
|
2012-05-22 14:13:33 +00:00
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
float heightmin = UI_DPI_FAC * node->typeinfo->minheight;
|
|
|
|
float heightmax = UI_DPI_FAC * node->typeinfo->maxheight;
|
2012-05-22 14:13:33 +00:00
|
|
|
if (nsw->directions & NODE_RESIZE_TOP) {
|
|
|
|
float locmin = nsw->oldlocy - nsw->oldheight;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
node->locy = nsw->oldlocy + dy;
|
2012-05-22 14:13:33 +00:00
|
|
|
CLAMP(node->locy, locmin + heightmin, locmin + heightmax);
|
2012-06-21 13:19:19 +00:00
|
|
|
node->height = node->locy - locmin;
|
2012-05-22 14:13:33 +00:00
|
|
|
}
|
|
|
|
if (nsw->directions & NODE_RESIZE_BOTTOM) {
|
2012-06-21 13:19:19 +00:00
|
|
|
node->height = nsw->oldheight - dy;
|
2012-05-22 14:13:33 +00:00
|
|
|
CLAMP(node->height, heightmin, heightmax);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX make callback? */
|
|
|
|
if (node->type == NODE_FRAME) {
|
|
|
|
/* keep the offset symmetric around center point */
|
|
|
|
if (nsw->directions & NODE_RESIZE_LEFT) {
|
2012-06-21 13:19:19 +00:00
|
|
|
node->locx = nsw->oldlocx + 0.5f * dx;
|
|
|
|
node->offsetx = nsw->oldoffsetx + 0.5f * dx;
|
2012-05-22 14:13:33 +00:00
|
|
|
}
|
|
|
|
if (nsw->directions & NODE_RESIZE_RIGHT) {
|
2012-06-21 13:19:19 +00:00
|
|
|
node->locx = nsw->oldlocx + 0.5f * dx;
|
|
|
|
node->offsetx = nsw->oldoffsetx - 0.5f * dx;
|
2012-05-22 14:13:33 +00:00
|
|
|
}
|
|
|
|
if (nsw->directions & NODE_RESIZE_TOP) {
|
2012-06-21 13:19:19 +00:00
|
|
|
node->locy = nsw->oldlocy + 0.5f * dy;
|
|
|
|
node->offsety = nsw->oldoffsety + 0.5f * dy;
|
2012-05-22 14:13:33 +00:00
|
|
|
}
|
|
|
|
if (nsw->directions & NODE_RESIZE_BOTTOM) {
|
2012-06-21 13:19:19 +00:00
|
|
|
node->locy = nsw->oldlocy + 0.5f * dy;
|
|
|
|
node->offsety = nsw->oldoffsety - 0.5f * dy;
|
2012-05-22 14:13:33 +00:00
|
|
|
}
|
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2009-02-06 18:38:10 +00:00
|
|
|
|
|
|
|
ED_region_tag_redraw(ar);
|
|
|
|
|
|
|
|
break;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2009-02-06 18:38:10 +00:00
|
|
|
case LEFTMOUSE:
|
|
|
|
case MIDDLEMOUSE:
|
|
|
|
case RIGHTMOUSE:
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-05-22 14:13:33 +00:00
|
|
|
node_resize_exit(C, op, 0);
|
|
|
|
ED_node_post_apply_transform(C, snode->edittree);
|
2011-09-05 21:01:50 +00:00
|
|
|
|
2009-02-06 18:38:10 +00:00
|
|
|
return OPERATOR_FINISHED;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
2009-02-06 18:38:10 +00:00
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
}
|
|
|
|
|
2009-04-15 15:40:31 +00:00
|
|
|
static int node_resize_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
2009-02-06 18:38:10 +00:00
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
|
|
|
bNode *node = editnode_get_active(snode->edittree);
|
2012-05-22 14:13:33 +00:00
|
|
|
int dir;
|
2009-02-06 18:38:10 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node) {
|
2009-11-20 04:19:57 +00:00
|
|
|
/* convert mouse coordinates to v2d space */
|
2011-05-20 07:40:05 +00:00
|
|
|
UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1],
|
2012-05-22 14:13:33 +00:00
|
|
|
&snode->mx, &snode->my);
|
|
|
|
dir = node->typeinfo->resize_area_func(node, snode->mx, snode->my);
|
|
|
|
if (dir != 0) {
|
|
|
|
node_resize_init(C, op, event, node, dir);
|
2009-02-06 18:38:10 +00:00
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2012-06-21 13:19:19 +00:00
|
|
|
return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH;
|
2009-02-06 18:38:10 +00:00
|
|
|
}
|
|
|
|
|
2012-05-22 14:13:33 +00:00
|
|
|
static int node_resize_cancel(bContext *C, wmOperator *op)
|
2011-06-06 11:04:54 +00:00
|
|
|
{
|
2012-05-22 14:13:33 +00:00
|
|
|
node_resize_exit(C, op, 1);
|
2011-06-06 11:04:54 +00:00
|
|
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
2009-04-15 15:40:31 +00:00
|
|
|
void NODE_OT_resize(wmOperatorType *ot)
|
2009-02-06 18:38:10 +00:00
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Resize Node";
|
|
|
|
ot->idname = "NODE_OT_resize";
|
2012-05-05 17:10:51 +00:00
|
|
|
ot->description = "Resize a node";
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2009-02-06 18:38:10 +00:00
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->invoke = node_resize_invoke;
|
|
|
|
ot->modal = node_resize_modal;
|
|
|
|
ot->poll = ED_operator_node_active;
|
|
|
|
ot->cancel = node_resize_cancel;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2009-02-06 18:38:10 +00:00
|
|
|
/* flags */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->flag = OPTYPE_BLOCKING;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-18 12:51:50 +00:00
|
|
|
/* ********************** hidden sockets ******************** */
|
2010-05-12 13:55:09 +00:00
|
|
|
|
2012-04-16 10:50:57 +00:00
|
|
|
int node_has_hidden_sockets(bNode *node)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
|
|
|
bNodeSocket *sock;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (sock = node->inputs.first; sock; sock = sock->next)
|
2012-04-16 10:50:57 +00:00
|
|
|
if (sock->flag & SOCK_HIDDEN)
|
2008-12-24 10:33:10 +00:00
|
|
|
return 1;
|
2012-06-21 13:19:19 +00:00
|
|
|
for (sock = node->outputs.first; sock; sock = sock->next)
|
2012-04-16 10:50:57 +00:00
|
|
|
if (sock->flag & SOCK_HIDDEN)
|
2008-12-24 10:33:10 +00:00
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-04-16 10:50:57 +00:00
|
|
|
void node_set_hidden_sockets(SpaceNode *snode, bNode *node, int set)
|
2012-06-01 12:38:03 +00:00
|
|
|
{
|
2011-12-18 12:51:50 +00:00
|
|
|
bNodeSocket *sock;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
if (set == 0) {
|
|
|
|
for (sock = node->inputs.first; sock; sock = sock->next)
|
2012-04-16 10:50:57 +00:00
|
|
|
sock->flag &= ~SOCK_HIDDEN;
|
2012-06-21 13:19:19 +00:00
|
|
|
for (sock = node->outputs.first; sock; sock = sock->next)
|
2012-04-16 10:50:57 +00:00
|
|
|
sock->flag &= ~SOCK_HIDDEN;
|
2011-12-18 12:51:50 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* hide unused sockets */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (sock = node->inputs.first; sock; sock = sock->next) {
|
|
|
|
if (sock->link == NULL)
|
2012-04-16 10:50:57 +00:00
|
|
|
sock->flag |= SOCK_HIDDEN;
|
2011-12-18 12:51:50 +00:00
|
|
|
}
|
2012-06-21 13:19:19 +00:00
|
|
|
for (sock = node->outputs.first; sock; sock = sock->next) {
|
|
|
|
if (nodeCountSocketLinks(snode->edittree, sock) == 0)
|
2012-04-16 10:50:57 +00:00
|
|
|
sock->flag |= SOCK_HIDDEN;
|
2011-12-18 12:51:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-04 10:49:13 +00:00
|
|
|
static int node_link_viewer(const bContext *C, bNode *tonode)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2012-03-04 10:49:13 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2008-12-24 10:33:10 +00:00
|
|
|
bNode *node;
|
2012-03-04 10:49:13 +00:00
|
|
|
bNodeLink *link;
|
|
|
|
bNodeSocket *sock;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
|
|
|
/* context check */
|
2012-06-21 13:19:19 +00:00
|
|
|
if (tonode == NULL || tonode->outputs.first == NULL)
|
2012-03-04 10:49:13 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2012-06-21 13:19:19 +00:00
|
|
|
if (ELEM(tonode->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER))
|
2012-03-04 10:49:13 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
|
|
|
/* get viewer */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = snode->edittree->nodes.first; node; node = node->next)
|
|
|
|
if (ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER))
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->flag & NODE_DO_OUTPUT)
|
2008-12-24 10:33:10 +00:00
|
|
|
break;
|
2010-04-14 17:32:28 +00:00
|
|
|
/* no viewer, we make one active */
|
2012-06-21 13:19:19 +00:00
|
|
|
if (node == NULL) {
|
|
|
|
for (node = snode->edittree->nodes.first; node; node = node->next) {
|
|
|
|
if (ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) {
|
2010-04-14 17:32:28 +00:00
|
|
|
node->flag |= NODE_DO_OUTPUT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-04 10:49:13 +00:00
|
|
|
|
|
|
|
sock = NULL;
|
|
|
|
|
|
|
|
/* try to find an already connected socket to cycle to the next */
|
|
|
|
if (node) {
|
|
|
|
link = NULL;
|
2012-06-21 13:19:19 +00:00
|
|
|
for (link = snode->edittree->links.first; link; link = link->next)
|
|
|
|
if (link->tonode == node && link->fromnode == tonode)
|
|
|
|
if (link->tosock == node->inputs.first)
|
2010-06-05 15:59:48 +00:00
|
|
|
break;
|
2012-03-24 06:38:07 +00:00
|
|
|
if (link) {
|
2010-06-05 15:59:48 +00:00
|
|
|
/* unlink existing connection */
|
2012-06-21 13:19:19 +00:00
|
|
|
sock = link->fromsock;
|
2010-06-05 15:59:48 +00:00
|
|
|
nodeRemLink(snode->edittree, link);
|
2012-03-04 10:49:13 +00:00
|
|
|
|
2010-06-05 15:59:48 +00:00
|
|
|
/* find a socket after the previously connected socket */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (sock = sock->next; sock; sock = sock->next)
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!nodeSocketIsHidden(sock))
|
2010-06-05 15:59:48 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-03-04 10:49:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* find a socket starting from the first socket */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!sock) {
|
2012-06-21 13:19:19 +00:00
|
|
|
for (sock = tonode->outputs.first; sock; sock = sock->next)
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!nodeSocketIsHidden(sock))
|
2012-03-04 10:49:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (sock) {
|
2012-03-04 10:49:13 +00:00
|
|
|
/* add a new viewer if none exists yet */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!node) {
|
2012-03-04 10:49:13 +00:00
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
bNodeTemplate ntemp;
|
|
|
|
|
|
|
|
ntemp.type = CMP_NODE_VIEWER;
|
|
|
|
/* XXX location is a quick hack, just place it next to the linked socket */
|
|
|
|
node = node_add_node(snode, bmain, scene, &ntemp, sock->locx + 100, sock->locy);
|
|
|
|
if (!node)
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
|
|
|
link = NULL;
|
2010-06-05 15:59:48 +00:00
|
|
|
}
|
2012-03-04 10:49:13 +00:00
|
|
|
else {
|
2010-05-12 17:27:25 +00:00
|
|
|
/* get link to viewer */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (link = snode->edittree->links.first; link; link = link->next)
|
|
|
|
if (link->tonode == node && link->tosock == node->inputs.first)
|
2010-05-12 17:27:25 +00:00
|
|
|
break;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2012-03-04 10:49:13 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
if (link == NULL) {
|
2012-03-04 10:49:13 +00:00
|
|
|
nodeAddLink(snode->edittree, tonode, sock, node, node->inputs.first);
|
|
|
|
}
|
|
|
|
else {
|
2012-06-21 13:19:19 +00:00
|
|
|
link->fromnode = tonode;
|
|
|
|
link->fromsock = sock;
|
2012-05-30 14:42:40 +00:00
|
|
|
/* make sure the dependency sorting is updated */
|
|
|
|
snode->edittree->update |= NTREE_UPDATE_LINKS;
|
2012-03-04 10:49:13 +00:00
|
|
|
}
|
|
|
|
ntreeUpdateTree(snode->edittree);
|
|
|
|
snode_update(snode, node);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2012-03-04 10:49:13 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-15 01:36:14 +00:00
|
|
|
static int node_active_link_viewer(bContext *C, wmOperator *UNUSED(op))
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2010-04-05 18:34:18 +00:00
|
|
|
bNode *node;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
node = editnode_get_active(snode->edittree);
|
2010-04-05 18:34:18 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!node)
|
2010-07-04 19:58:52 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
|
|
|
ED_preview_kill_jobs(C);
|
|
|
|
|
2012-03-04 10:49:13 +00:00
|
|
|
if (node_link_viewer(C, node) == OPERATOR_CANCELLED)
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
2010-07-04 19:58:52 +00:00
|
|
|
snode_notify(C, snode);
|
|
|
|
|
2010-04-05 18:34:18 +00:00
|
|
|
return OPERATOR_FINISHED;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
2010-04-05 18:34:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
void NODE_OT_link_viewer(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Link to Viewer Node";
|
2011-09-22 15:35:25 +00:00
|
|
|
ot->description = "Link to viewer node";
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->idname = "NODE_OT_link_viewer";
|
2010-04-05 18:34:18 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = node_active_link_viewer;
|
|
|
|
ot->poll = composite_node_active;
|
2010-04-05 18:34:18 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2010-04-05 18:34:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-12-24 10:33:10 +00:00
|
|
|
/* return 0, nothing done */
|
2012-06-21 13:19:19 +00:00
|
|
|
static int UNUSED_FUNCTION(node_mouse_groupheader) (SpaceNode * snode)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
|
|
|
bNode *gnode;
|
2012-06-21 13:19:19 +00:00
|
|
|
float mx = 0, my = 0;
|
2011-05-12 16:47:36 +00:00
|
|
|
// XXX int mval[2];
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
gnode = node_tree_get_editgroup(snode->nodetree);
|
|
|
|
if (gnode == NULL) return 0;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2009-02-06 16:34:05 +00:00
|
|
|
// XXX getmouseco_areawin(mval);
|
|
|
|
// XXX areamouseco_to_ipoco(G.v2d, mval, &mx, &my);
|
2008-12-24 10:33:10 +00:00
|
|
|
|
|
|
|
/* click in header or outside? */
|
2012-06-21 13:19:19 +00:00
|
|
|
if (BLI_in_rctf(&gnode->totr, mx, my) == 0) {
|
|
|
|
rctf rect = gnode->totr;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
|
|
|
rect.ymax += NODE_DY;
|
2012-06-21 13:19:19 +00:00
|
|
|
if (BLI_in_rctf(&rect, mx, my) == 0)
|
|
|
|
snode_make_group_editable(snode, NULL); /* toggles, so exits editmode */
|
2009-02-06 16:34:05 +00:00
|
|
|
// else
|
|
|
|
// XXX transform_nodes(snode->nodetree, 'g', "Move group");
|
2008-12-24 10:33:10 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-06 16:34:05 +00:00
|
|
|
/* checks snode->mouse position, and returns found node/socket */
|
|
|
|
/* type is SOCK_IN and/or SOCK_OUT */
|
2012-03-09 10:16:41 +00:00
|
|
|
int node_find_indicated_socket(SpaceNode *snode, bNode **nodep, bNodeSocket **sockp, int in_out)
|
2009-02-06 16:34:05 +00:00
|
|
|
{
|
|
|
|
bNode *node;
|
|
|
|
bNodeSocket *sock;
|
|
|
|
rctf rect;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
*nodep = NULL;
|
|
|
|
*sockp = NULL;
|
2012-03-09 10:16:41 +00:00
|
|
|
|
2009-02-06 16:34:05 +00:00
|
|
|
/* check if we click in a socket */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = snode->edittree->nodes.first; node; node = node->next) {
|
2009-02-06 16:34:05 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
rect.xmin = snode->mx - (NODE_SOCKSIZE + 4);
|
|
|
|
rect.ymin = snode->my - (NODE_SOCKSIZE + 4);
|
|
|
|
rect.xmax = snode->mx + (NODE_SOCKSIZE + 4);
|
|
|
|
rect.ymax = snode->my + (NODE_SOCKSIZE + 4);
|
2009-02-06 16:34:05 +00:00
|
|
|
|
|
|
|
if (!(node->flag & NODE_HIDDEN)) {
|
|
|
|
/* extra padding inside and out - allow dragging on the text areas too */
|
|
|
|
if (in_out == SOCK_IN) {
|
|
|
|
rect.xmax += NODE_SOCKSIZE;
|
2012-06-21 13:19:19 +00:00
|
|
|
rect.xmin -= NODE_SOCKSIZE * 4;
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else if (in_out == SOCK_OUT) {
|
2012-06-21 13:19:19 +00:00
|
|
|
rect.xmax += NODE_SOCKSIZE * 4;
|
2009-02-06 16:34:05 +00:00
|
|
|
rect.xmin -= NODE_SOCKSIZE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (in_out & SOCK_IN) {
|
2012-06-21 13:19:19 +00:00
|
|
|
for (sock = node->inputs.first; sock; sock = sock->next) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!nodeSocketIsHidden(sock)) {
|
|
|
|
if (BLI_in_rctf(&rect, sock->locx, sock->locy)) {
|
|
|
|
if (node == visible_node(snode, &rect)) {
|
2012-06-21 13:19:19 +00:00
|
|
|
*nodep = node;
|
|
|
|
*sockp = sock;
|
2009-02-06 16:34:05 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
if (in_out & SOCK_OUT) {
|
2012-06-21 13:19:19 +00:00
|
|
|
for (sock = node->outputs.first; sock; sock = sock->next) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!nodeSocketIsHidden(sock)) {
|
|
|
|
if (BLI_in_rctf(&rect, sock->locx, sock->locy)) {
|
|
|
|
if (node == visible_node(snode, &rect)) {
|
2012-06-21 13:19:19 +00:00
|
|
|
*nodep = node;
|
|
|
|
*sockp = sock;
|
2009-02-06 16:34:05 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-02-21 13:47:49 +00:00
|
|
|
|
|
|
|
/* check group sockets
|
|
|
|
* NB: using ngroup->outputs as input sockets and vice versa here!
|
|
|
|
*/
|
2012-03-24 06:38:07 +00:00
|
|
|
if (in_out & SOCK_IN) {
|
2012-06-21 13:19:19 +00:00
|
|
|
for (sock = snode->edittree->outputs.first; sock; sock = sock->next) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!nodeSocketIsHidden(sock)) {
|
|
|
|
if (BLI_in_rctf(&rect, sock->locx, sock->locy)) {
|
2012-06-21 13:19:19 +00:00
|
|
|
*nodep = NULL; /* NULL node pointer indicates group socket */
|
|
|
|
*sockp = sock;
|
2011-02-21 13:47:49 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
if (in_out & SOCK_OUT) {
|
2012-06-21 13:19:19 +00:00
|
|
|
for (sock = snode->edittree->inputs.first; sock; sock = sock->next) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!nodeSocketIsHidden(sock)) {
|
|
|
|
if (BLI_in_rctf(&rect, sock->locx, sock->locy)) {
|
2012-06-21 13:19:19 +00:00
|
|
|
*nodep = NULL; /* NULL node pointer indicates group socket */
|
|
|
|
*sockp = sock;
|
2011-02-21 13:47:49 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-06 16:34:05 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-02-21 13:47:49 +00:00
|
|
|
static int outside_group_rect(SpaceNode *snode)
|
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
bNode *gnode = node_tree_get_editgroup(snode->nodetree);
|
2011-02-21 13:47:49 +00:00
|
|
|
if (gnode) {
|
2012-04-21 15:11:03 +00:00
|
|
|
return (snode->mx < gnode->totr.xmin ||
|
|
|
|
snode->mx >= gnode->totr.xmax ||
|
|
|
|
snode->my < gnode->totr.ymin ||
|
|
|
|
snode->my >= gnode->totr.ymax);
|
2011-02-21 13:47:49 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-12-24 10:33:10 +00:00
|
|
|
/* ****************** Add *********************** */
|
|
|
|
|
2010-01-05 06:49:29 +00:00
|
|
|
|
|
|
|
typedef struct bNodeListItem {
|
|
|
|
struct bNodeListItem *next, *prev;
|
|
|
|
struct bNode *node;
|
|
|
|
} bNodeListItem;
|
|
|
|
|
2011-02-14 17:55:27 +00:00
|
|
|
static int sort_nodes_locx(void *a, void *b)
|
2010-01-04 04:26:28 +00:00
|
|
|
{
|
2010-01-05 06:49:29 +00:00
|
|
|
bNodeListItem *nli1 = (bNodeListItem *)a;
|
|
|
|
bNodeListItem *nli2 = (bNodeListItem *)b;
|
|
|
|
bNode *node1 = nli1->node;
|
|
|
|
bNode *node2 = nli2->node;
|
2010-01-04 04:26:28 +00:00
|
|
|
|
2010-01-05 06:49:29 +00:00
|
|
|
if (node1->locx > node2->locx)
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-01-09 09:30:51 +00:00
|
|
|
static int socket_is_available(bNodeTree *UNUSED(ntree), bNodeSocket *sock, int allow_used)
|
2010-01-05 06:49:29 +00:00
|
|
|
{
|
2012-01-08 10:23:19 +00:00
|
|
|
if (nodeSocketIsHidden(sock))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!allow_used && (sock->flag & SOCK_IN_USE))
|
2010-01-05 06:49:29 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bNodeSocket *best_socket_output(bNodeTree *ntree, bNode *node, bNodeSocket *sock_target, int allow_multiple)
|
|
|
|
{
|
|
|
|
bNodeSocket *sock;
|
|
|
|
|
2012-03-09 10:16:41 +00:00
|
|
|
/* first look for selected output */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (sock = node->outputs.first; sock; sock = sock->next) {
|
2012-03-09 10:16:41 +00:00
|
|
|
if (!socket_is_available(ntree, sock, allow_multiple))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (sock->flag & SELECT)
|
|
|
|
return sock;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* try to find a socket with a matching name */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (sock = node->outputs.first; sock; sock = sock->next) {
|
2010-01-05 06:49:29 +00:00
|
|
|
if (!socket_is_available(ntree, sock, allow_multiple))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* check for same types */
|
|
|
|
if (sock->type == sock_target->type) {
|
2012-06-21 13:19:19 +00:00
|
|
|
if (strcmp(sock->name, sock_target->name) == 0)
|
2010-01-05 06:49:29 +00:00
|
|
|
return sock;
|
2010-01-04 04:26:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* otherwise settle for the first available socket of the right type */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (sock = node->outputs.first; sock; sock = sock->next) {
|
2010-01-05 06:49:29 +00:00
|
|
|
|
|
|
|
if (!socket_is_available(ntree, sock, allow_multiple))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* check for same types */
|
|
|
|
if (sock->type == sock_target->type) {
|
|
|
|
return sock;
|
2010-01-04 04:26:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-03-04 04:35:12 +00:00
|
|
|
/* this is a bit complicated, but designed to prioritize finding
|
2010-01-05 06:49:29 +00:00
|
|
|
* sockets of higher types, such as image, first */
|
|
|
|
static bNodeSocket *best_socket_input(bNodeTree *ntree, bNode *node, int num, int replace)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2010-01-05 06:49:29 +00:00
|
|
|
bNodeSocket *sock;
|
2012-06-21 13:19:19 +00:00
|
|
|
int socktype, maxtype = 0;
|
2010-01-19 20:30:04 +00:00
|
|
|
int a = 0;
|
2010-01-05 06:49:29 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (sock = node->inputs.first; sock; sock = sock->next) {
|
2010-01-05 06:49:29 +00:00
|
|
|
maxtype = MAX2(sock->type, maxtype);
|
2010-01-04 04:26:28 +00:00
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2010-01-05 06:49:29 +00:00
|
|
|
/* find sockets of higher 'types' first (i.e. image) */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (socktype = maxtype; socktype >= 0; socktype--) {
|
|
|
|
for (sock = node->inputs.first; sock; sock = sock->next) {
|
2010-01-05 06:49:29 +00:00
|
|
|
|
|
|
|
if (!socket_is_available(ntree, sock, replace)) {
|
|
|
|
a++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sock->type == socktype) {
|
|
|
|
/* increment to make sure we don't keep finding
|
|
|
|
* the same socket on every attempt running this function */
|
|
|
|
a++;
|
|
|
|
if (a > num)
|
|
|
|
return sock;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-01-05 06:49:29 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-03-09 10:16:41 +00:00
|
|
|
static int snode_autoconnect_input(SpaceNode *snode, bNode *node_fr, bNodeSocket *sock_fr, bNode *node_to, bNodeSocket *sock_to, int replace)
|
|
|
|
{
|
|
|
|
bNodeTree *ntree = snode->edittree;
|
|
|
|
bNodeLink *link;
|
|
|
|
|
|
|
|
/* then we can connect */
|
|
|
|
if (replace)
|
|
|
|
nodeRemSocketLinks(ntree, sock_to);
|
|
|
|
|
|
|
|
link = nodeAddLink(ntree, node_fr, sock_fr, node_to, sock_to);
|
|
|
|
/* validate the new link */
|
|
|
|
ntreeUpdateTree(ntree);
|
|
|
|
if (!(link->flag & NODE_LINK_VALID)) {
|
|
|
|
nodeRemLink(ntree, link);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
snode_update(snode, node_to);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-01-05 06:49:29 +00:00
|
|
|
void snode_autoconnect(SpaceNode *snode, int allow_multiple, int replace)
|
|
|
|
{
|
2012-03-09 10:16:41 +00:00
|
|
|
bNodeTree *ntree = snode->edittree;
|
2010-01-05 06:49:29 +00:00
|
|
|
ListBase *nodelist = MEM_callocN(sizeof(ListBase), "items_list");
|
|
|
|
bNodeListItem *nli;
|
|
|
|
bNode *node;
|
2012-06-21 13:19:19 +00:00
|
|
|
int i, numlinks = 0;
|
2010-01-05 06:49:29 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->flag & NODE_SELECT) {
|
2010-01-05 06:49:29 +00:00
|
|
|
nli = MEM_mallocN(sizeof(bNodeListItem), "temporary node list item");
|
|
|
|
nli->node = node;
|
|
|
|
BLI_addtail(nodelist, nli);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* sort nodes left to right */
|
|
|
|
BLI_sortlist(nodelist, sort_nodes_locx);
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (nli = nodelist->first; nli; nli = nli->next) {
|
2010-01-05 06:49:29 +00:00
|
|
|
bNode *node_fr, *node_to;
|
|
|
|
bNodeSocket *sock_fr, *sock_to;
|
2012-03-09 10:16:41 +00:00
|
|
|
int has_selected_inputs = 0;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2010-01-05 06:49:29 +00:00
|
|
|
if (nli->next == NULL) break;
|
2010-01-04 04:26:28 +00:00
|
|
|
|
2010-01-05 06:49:29 +00:00
|
|
|
node_fr = nli->node;
|
|
|
|
node_to = nli->next->node;
|
2010-01-04 04:26:28 +00:00
|
|
|
|
2012-03-09 10:16:41 +00:00
|
|
|
/* if there are selected sockets, connect those */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (sock_to = node_to->inputs.first; sock_to; sock_to = sock_to->next) {
|
2012-03-09 10:16:41 +00:00
|
|
|
if (sock_to->flag & SELECT) {
|
|
|
|
has_selected_inputs = 1;
|
|
|
|
|
|
|
|
if (!socket_is_available(ntree, sock_to, replace))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* check for an appropriate output socket to connect from */
|
|
|
|
sock_fr = best_socket_output(ntree, node_fr, sock_to, allow_multiple);
|
|
|
|
if (!sock_fr)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (snode_autoconnect_input(snode, node_fr, sock_fr, node_to, sock_to, replace))
|
|
|
|
++numlinks;
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
2012-03-09 10:16:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!has_selected_inputs) {
|
|
|
|
/* no selected inputs, connect by finding suitable match */
|
|
|
|
int num_inputs = BLI_countlist(&node_to->inputs);
|
2011-09-05 21:01:50 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (i = 0; i < num_inputs; i++) {
|
2012-03-09 10:16:41 +00:00
|
|
|
|
|
|
|
/* find the best guess input socket */
|
|
|
|
sock_to = best_socket_input(ntree, node_to, i, replace);
|
|
|
|
if (!sock_to)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* check for an appropriate output socket to connect from */
|
|
|
|
sock_fr = best_socket_output(ntree, node_fr, sock_to, allow_multiple);
|
|
|
|
if (!sock_fr)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (snode_autoconnect_input(snode, node_fr, sock_fr, node_to, sock_to, replace)) {
|
|
|
|
++numlinks;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-18 14:49:06 +00:00
|
|
|
if (numlinks > 0) {
|
2012-03-09 10:16:41 +00:00
|
|
|
ntreeUpdateTree(ntree);
|
2011-01-18 14:49:06 +00:00
|
|
|
}
|
2010-01-05 06:49:29 +00:00
|
|
|
|
|
|
|
BLI_freelistN(nodelist);
|
|
|
|
MEM_freeN(nodelist);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* can be called from menus too, but they should do own undopush and redraws */
|
2011-09-05 21:01:50 +00:00
|
|
|
bNode *node_add_node(SpaceNode *snode, Main *bmain, Scene *scene, bNodeTemplate *ntemp, float locx, float locy)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
bNode *node = NULL, *gnode;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2011-12-18 12:51:50 +00:00
|
|
|
node_deselect_all(snode);
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
node = nodeAddNode(snode->edittree, ntemp);
|
2008-12-24 10:33:10 +00:00
|
|
|
|
|
|
|
/* generics */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node) {
|
2012-03-14 18:10:57 +00:00
|
|
|
node_select(node);
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
gnode = node_tree_get_editgroup(snode->nodetree);
|
2012-07-20 15:07:06 +00:00
|
|
|
// arbitrary y offset of 60 so its visible
|
2012-03-24 06:38:07 +00:00
|
|
|
if (gnode) {
|
2012-07-20 15:07:06 +00:00
|
|
|
nodeFromView(gnode, locx, locy + 60.0f, &node->locx, &node->locy);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
node->locx = locx;
|
|
|
|
node->locy = locy + 60.0f;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
ntreeUpdateTree(snode->edittree);
|
2011-08-12 18:27:48 +00:00
|
|
|
ED_node_set_active(bmain, snode->edittree, node);
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
if (snode->nodetree->type == NTREE_COMPOSIT) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (ELEM4(node->type, CMP_NODE_R_LAYERS, CMP_NODE_COMPOSITE, CMP_NODE_DEFOCUS, CMP_NODE_OUTPUT_FILE)) {
|
2009-02-06 16:34:05 +00:00
|
|
|
node->id = &scene->id;
|
2011-11-07 12:56:05 +00:00
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (ELEM3(node->type, CMP_NODE_MOVIECLIP, CMP_NODE_MOVIEDISTORTION, CMP_NODE_STABILIZE2D)) {
|
2011-11-08 06:11:23 +00:00
|
|
|
node->id = (ID *)scene->clip;
|
2011-11-07 12:56:05 +00:00
|
|
|
}
|
2009-02-06 16:34:05 +00:00
|
|
|
|
|
|
|
ntreeCompositForceHidden(snode->edittree, scene);
|
|
|
|
}
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->id)
|
2008-12-24 10:33:10 +00:00
|
|
|
id_us_plus(node->id);
|
2009-02-06 16:34:05 +00:00
|
|
|
|
2011-10-19 17:08:35 +00:00
|
|
|
snode_update(snode, node);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
if (snode->nodetree->type == NTREE_TEXTURE) {
|
2008-12-24 10:33:10 +00:00
|
|
|
ntreeTexCheckCyclics(snode->edittree);
|
|
|
|
}
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2009-11-20 06:31:49 +00:00
|
|
|
/* ****************** Duplicate *********************** */
|
2009-01-12 00:00:59 +00:00
|
|
|
|
2012-05-22 14:13:33 +00:00
|
|
|
static void node_duplicate_reparent_recursive(bNode *node)
|
|
|
|
{
|
|
|
|
bNode *parent;
|
|
|
|
|
|
|
|
node->flag |= NODE_TEST;
|
|
|
|
|
|
|
|
/* find first selected parent */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (parent = node->parent; parent; parent = parent->parent) {
|
2012-05-22 14:13:33 +00:00
|
|
|
if (parent->flag & SELECT) {
|
|
|
|
if (!(parent->flag & NODE_TEST))
|
|
|
|
node_duplicate_reparent_recursive(parent);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* reparent node copy to parent copy */
|
|
|
|
if (parent) {
|
|
|
|
nodeDetachNode(node->new_node);
|
|
|
|
nodeAttachNode(node->new_node, parent->new_node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-17 18:04:28 +00:00
|
|
|
static int node_duplicate_exec(bContext *C, wmOperator *op)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
bNodeTree *ntree = snode->edittree;
|
2011-06-30 12:37:59 +00:00
|
|
|
bNode *node, *newnode, *lastnode;
|
|
|
|
bNodeLink *link, *newlink, *lastlink;
|
2011-07-17 18:04:28 +00:00
|
|
|
int keep_inputs = RNA_boolean_get(op->ptr, "keep_inputs");
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2010-07-04 19:58:52 +00:00
|
|
|
ED_preview_kill_jobs(C);
|
2011-02-11 09:37:58 +00:00
|
|
|
|
2011-06-30 12:37:59 +00:00
|
|
|
lastnode = ntree->nodes.last;
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->flag & SELECT) {
|
2011-02-21 13:47:49 +00:00
|
|
|
newnode = nodeCopyNode(ntree, node);
|
2011-02-11 09:37:58 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (newnode->id) {
|
2012-03-18 07:38:51 +00:00
|
|
|
/* simple id user adjustment, node internal functions don't touch this
|
2011-02-11 09:37:58 +00:00
|
|
|
* but operators and readfile.c do. */
|
|
|
|
id_us_plus(newnode->id);
|
|
|
|
/* to ensure redraws or rerenders happen */
|
|
|
|
ED_node_changed_update(snode->id, newnode);
|
|
|
|
}
|
2010-10-15 04:27:09 +00:00
|
|
|
}
|
2011-02-11 09:37:58 +00:00
|
|
|
|
|
|
|
/* make sure we don't copy new nodes again! */
|
2012-06-21 13:19:19 +00:00
|
|
|
if (node == lastnode)
|
2011-06-30 12:37:59 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy links between selected nodes
|
|
|
|
* NB: this depends on correct node->new_node and sock->new_sock pointers from above copy!
|
|
|
|
*/
|
|
|
|
lastlink = ntree->links.last;
|
2012-06-21 13:19:19 +00:00
|
|
|
for (link = ntree->links.first; link; link = link->next) {
|
2011-07-17 18:04:28 +00:00
|
|
|
/* This creates new links between copied nodes.
|
|
|
|
* If keep_inputs is set, also copies input links from unselected (when fromnode==NULL)!
|
2011-06-30 12:37:59 +00:00
|
|
|
*/
|
2012-04-21 15:11:03 +00:00
|
|
|
if (link->tonode && (link->tonode->flag & NODE_SELECT) &&
|
|
|
|
(keep_inputs || (link->fromnode && (link->fromnode->flag & NODE_SELECT))))
|
|
|
|
{
|
2011-06-30 12:37:59 +00:00
|
|
|
newlink = MEM_callocN(sizeof(bNodeLink), "bNodeLink");
|
|
|
|
newlink->flag = link->flag;
|
|
|
|
newlink->tonode = link->tonode->new_node;
|
|
|
|
newlink->tosock = link->tosock->new_sock;
|
|
|
|
if (link->fromnode && (link->fromnode->flag & NODE_SELECT)) {
|
|
|
|
newlink->fromnode = link->fromnode->new_node;
|
|
|
|
newlink->fromsock = link->fromsock->new_sock;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* input node not copied, this keeps the original input linked */
|
|
|
|
newlink->fromnode = link->fromnode;
|
|
|
|
newlink->fromsock = link->fromsock;
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_addtail(&ntree->links, newlink);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make sure we don't copy new links again! */
|
2012-06-21 13:19:19 +00:00
|
|
|
if (link == lastlink)
|
2011-06-30 12:37:59 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-05-22 14:13:33 +00:00
|
|
|
/* clear flags for recursive depth-first iteration */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = ntree->nodes.first; node; node = node->next)
|
2012-05-22 14:13:33 +00:00
|
|
|
node->flag &= ~NODE_TEST;
|
|
|
|
/* reparent copied nodes */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
2012-05-22 14:13:33 +00:00
|
|
|
if ((node->flag & SELECT) && !(node->flag & NODE_TEST))
|
|
|
|
node_duplicate_reparent_recursive(node);
|
|
|
|
|
|
|
|
/* only has to check old nodes */
|
2012-06-21 13:19:19 +00:00
|
|
|
if (node == lastnode)
|
2012-05-22 14:13:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-06-30 12:37:59 +00:00
|
|
|
/* deselect old nodes, select the copies instead */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->flag & SELECT) {
|
2011-06-30 12:37:59 +00:00
|
|
|
/* has been set during copy above */
|
|
|
|
newnode = node->new_node;
|
|
|
|
|
2012-03-14 18:10:57 +00:00
|
|
|
node_deselect(node);
|
|
|
|
node->flag &= ~NODE_ACTIVE;
|
|
|
|
node_select(newnode);
|
2011-06-30 12:37:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* make sure we don't copy new nodes again! */
|
2012-06-21 13:19:19 +00:00
|
|
|
if (node == lastnode)
|
2011-02-11 09:37:58 +00:00
|
|
|
break;
|
2010-10-15 04:27:09 +00:00
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
ntreeUpdateTree(snode->edittree);
|
2011-01-03 14:36:44 +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-24 10:33:10 +00:00
|
|
|
|
2009-07-07 17:30:39 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
2009-07-08 21:41:35 +00:00
|
|
|
void NODE_OT_duplicate(wmOperatorType *ot)
|
2009-07-07 17:30:39 +00:00
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Duplicate Nodes";
|
2011-09-22 15:35:25 +00:00
|
|
|
ot->description = "Duplicate selected nodes";
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->idname = "NODE_OT_duplicate";
|
2009-07-07 17:30:39 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = node_duplicate_exec;
|
|
|
|
ot->poll = ED_operator_node_active;
|
2009-07-07 17:30:39 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2011-07-17 18:04:28 +00:00
|
|
|
|
|
|
|
RNA_def_boolean(ot->srna, "keep_inputs", 0, "Keep Inputs", "Keep the input links to duplicated nodes");
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
2009-02-06 16:34:05 +00:00
|
|
|
/* *************************** add link op ******************** */
|
|
|
|
|
2008-12-24 10:33:10 +00:00
|
|
|
static void node_remove_extra_links(SpaceNode *snode, bNodeSocket *tsock, bNodeLink *link)
|
|
|
|
{
|
|
|
|
bNodeLink *tlink;
|
|
|
|
bNodeSocket *sock;
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (tsock && nodeCountSocketLinks(snode->edittree, link->tosock) > tsock->limit) {
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (tlink = snode->edittree->links.first; tlink; tlink = tlink->next) {
|
|
|
|
if (link != tlink && tlink->tosock == link->tosock)
|
2008-12-24 10:33:10 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
if (tlink) {
|
2011-02-21 13:47:49 +00:00
|
|
|
/* try to move the existing link to the next available socket */
|
|
|
|
if (tlink->tonode) {
|
2011-07-17 19:43:14 +00:00
|
|
|
/* is there a free input socket with the target type? */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (sock = tlink->tonode->inputs.first; sock; sock = sock->next) {
|
|
|
|
if (sock->type == tlink->tosock->type)
|
2012-03-24 06:38:07 +00:00
|
|
|
if (nodeCountSocketLinks(snode->edittree, sock) < sock->limit)
|
2011-02-21 13:47:49 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
if (sock) {
|
2012-06-21 13:19:19 +00:00
|
|
|
tlink->tosock = sock;
|
2012-04-16 10:50:57 +00:00
|
|
|
sock->flag &= ~SOCK_HIDDEN;
|
2011-02-21 13:47:49 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
nodeRemLink(snode->edittree, tlink);
|
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2011-02-21 13:47:49 +00:00
|
|
|
else
|
2008-12-24 10:33:10 +00:00
|
|
|
nodeRemLink(snode->edittree, tlink);
|
2012-03-01 07:56:15 +00:00
|
|
|
|
|
|
|
snode->edittree->update |= NTREE_UPDATE_LINKS;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* loop that adds a nodelink, called by function below */
|
|
|
|
/* in_out = starting socket */
|
2009-02-06 16:34:05 +00:00
|
|
|
static int node_link_modal(bContext *C, wmOperator *op, wmEvent *event)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
|
|
|
bNodeLinkDrag *nldrag = op->customdata;
|
2012-05-28 14:39:55 +00:00
|
|
|
bNodeTree *ntree = snode->edittree;
|
2012-05-15 12:40:43 +00:00
|
|
|
bNode *tnode;
|
2012-06-21 13:19:19 +00:00
|
|
|
bNodeSocket *tsock = NULL;
|
2009-02-06 16:34:05 +00:00
|
|
|
bNodeLink *link;
|
2012-05-15 12:40:43 +00:00
|
|
|
LinkData *linkdata;
|
2009-02-06 16:34:05 +00:00
|
|
|
int in_out;
|
|
|
|
|
2012-05-15 12:40:43 +00:00
|
|
|
in_out = nldrag->in_out;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2011-05-20 07:40:05 +00:00
|
|
|
UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1],
|
2012-06-21 13:19:19 +00:00
|
|
|
&snode->mx, &snode->my);
|
2009-02-06 16:34:05 +00:00
|
|
|
|
|
|
|
switch (event->type) {
|
|
|
|
case MOUSEMOVE:
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
if (in_out == SOCK_OUT) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node_find_indicated_socket(snode, &tnode, &tsock, SOCK_IN)) {
|
2012-06-21 13:19:19 +00:00
|
|
|
for (linkdata = nldrag->links.first; linkdata; linkdata = linkdata->next) {
|
2012-05-15 12:40:43 +00:00
|
|
|
link = linkdata->data;
|
|
|
|
|
|
|
|
/* skip if this is already the target socket */
|
|
|
|
if (link->tosock == tsock)
|
|
|
|
continue;
|
|
|
|
/* skip if socket is on the same node as the fromsock */
|
|
|
|
if (tnode && link->fromnode == tnode)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* attach links to the socket */
|
|
|
|
link->tonode = tnode;
|
|
|
|
link->tosock = tsock;
|
|
|
|
/* add it to the node tree temporarily */
|
2012-05-28 14:39:55 +00:00
|
|
|
if (BLI_findindex(&ntree->links, link) < 0)
|
|
|
|
BLI_addtail(&ntree->links, link);
|
2012-05-15 12:40:43 +00:00
|
|
|
|
2012-05-28 14:39:55 +00:00
|
|
|
ntree->update |= NTREE_UPDATE_LINKS;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2012-05-28 14:39:55 +00:00
|
|
|
ntreeUpdateTree(ntree);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-05-19 13:28:19 +00:00
|
|
|
int do_update = FALSE;
|
2012-06-21 13:19:19 +00:00
|
|
|
for (linkdata = nldrag->links.first; linkdata; linkdata = linkdata->next) {
|
2012-05-15 12:40:43 +00:00
|
|
|
link = linkdata->data;
|
2011-09-05 21:01:50 +00:00
|
|
|
|
2012-05-15 12:40:43 +00:00
|
|
|
if (link->tonode || link->tosock) {
|
2012-05-28 14:39:55 +00:00
|
|
|
BLI_remlink(&ntree->links, link);
|
2012-05-15 12:40:43 +00:00
|
|
|
link->prev = link->next = NULL;
|
2012-06-21 13:19:19 +00:00
|
|
|
link->tonode = NULL;
|
|
|
|
link->tosock = NULL;
|
2012-05-15 12:40:43 +00:00
|
|
|
|
2012-05-28 14:39:55 +00:00
|
|
|
ntree->update |= NTREE_UPDATE_LINKS;
|
2012-05-19 13:28:19 +00:00
|
|
|
do_update = TRUE;
|
2012-05-15 12:40:43 +00:00
|
|
|
}
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
2012-05-19 13:28:19 +00:00
|
|
|
if (do_update) {
|
2012-05-28 14:39:55 +00:00
|
|
|
ntreeUpdateTree(ntree);
|
2012-05-19 13:28:19 +00:00
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node_find_indicated_socket(snode, &tnode, &tsock, SOCK_OUT)) {
|
2012-06-21 13:19:19 +00:00
|
|
|
for (linkdata = nldrag->links.first; linkdata; linkdata = linkdata->next) {
|
2012-05-15 12:40:43 +00:00
|
|
|
link = linkdata->data;
|
|
|
|
|
|
|
|
/* skip if this is already the target socket */
|
|
|
|
if (link->fromsock == tsock)
|
|
|
|
continue;
|
|
|
|
/* skip if socket is on the same node as the fromsock */
|
|
|
|
if (tnode && link->tonode == tnode)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* attach links to the socket */
|
|
|
|
link->fromnode = tnode;
|
|
|
|
link->fromsock = tsock;
|
|
|
|
/* add it to the node tree temporarily */
|
2012-05-28 14:39:55 +00:00
|
|
|
if (BLI_findindex(&ntree->links, link) < 0)
|
|
|
|
BLI_addtail(&ntree->links, link);
|
2012-05-15 12:40:43 +00:00
|
|
|
|
2012-05-28 14:39:55 +00:00
|
|
|
ntree->update |= NTREE_UPDATE_LINKS;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2012-05-28 14:39:55 +00:00
|
|
|
ntreeUpdateTree(ntree);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-05-19 13:28:19 +00:00
|
|
|
int do_update = FALSE;
|
2012-06-21 13:19:19 +00:00
|
|
|
for (linkdata = nldrag->links.first; linkdata; linkdata = linkdata->next) {
|
2012-05-15 12:40:43 +00:00
|
|
|
link = linkdata->data;
|
|
|
|
|
|
|
|
if (link->fromnode || link->fromsock) {
|
2012-05-28 14:39:55 +00:00
|
|
|
BLI_remlink(&ntree->links, link);
|
2012-05-15 12:40:43 +00:00
|
|
|
link->prev = link->next = NULL;
|
2012-06-21 13:19:19 +00:00
|
|
|
link->fromnode = NULL;
|
|
|
|
link->fromsock = NULL;
|
2012-05-15 12:40:43 +00:00
|
|
|
|
2012-05-28 14:39:55 +00:00
|
|
|
ntree->update |= NTREE_UPDATE_LINKS;
|
2012-05-19 13:28:19 +00:00
|
|
|
do_update = TRUE;
|
2012-05-15 12:40:43 +00:00
|
|
|
}
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
2012-05-19 13:28:19 +00:00
|
|
|
if (do_update) {
|
2012-05-28 14:39:55 +00:00
|
|
|
ntreeUpdateTree(ntree);
|
2012-05-19 13:28:19 +00:00
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-09 10:16:41 +00:00
|
|
|
|
2009-02-06 16:34:05 +00:00
|
|
|
ED_region_tag_redraw(ar);
|
|
|
|
break;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2009-02-06 16:34:05 +00:00
|
|
|
case LEFTMOUSE:
|
|
|
|
case RIGHTMOUSE:
|
2012-05-15 12:40:43 +00:00
|
|
|
case MIDDLEMOUSE: {
|
2012-06-21 13:19:19 +00:00
|
|
|
for (linkdata = nldrag->links.first; linkdata; linkdata = linkdata->next) {
|
2012-05-15 12:40:43 +00:00
|
|
|
link = linkdata->data;
|
2011-07-29 07:14:03 +00:00
|
|
|
|
2012-05-15 12:40:43 +00:00
|
|
|
if (link->tosock && link->fromsock) {
|
|
|
|
/* send changed events for original tonode and new */
|
|
|
|
if (link->tonode)
|
|
|
|
snode_update(snode, link->tonode);
|
|
|
|
|
|
|
|
/* we might need to remove a link */
|
2012-06-21 13:19:19 +00:00
|
|
|
if (in_out == SOCK_OUT)
|
2012-05-15 12:40:43 +00:00
|
|
|
node_remove_extra_links(snode, link->tosock, link);
|
|
|
|
|
|
|
|
/* when linking to group outputs, update the socket type */
|
|
|
|
/* XXX this should all be part of a generic update system */
|
|
|
|
if (!link->tonode) {
|
2012-05-22 22:03:41 +00:00
|
|
|
if (link->tosock->type != link->fromsock->type)
|
2012-05-15 12:40:43 +00:00
|
|
|
nodeSocketSetType(link->tosock, link->fromsock->type);
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
2011-02-21 13:47:49 +00:00
|
|
|
}
|
2012-05-15 12:40:43 +00:00
|
|
|
else if (outside_group_rect(snode) && (link->tonode || link->fromnode)) {
|
|
|
|
/* automatically add new group socket */
|
|
|
|
if (link->tonode && link->tosock) {
|
2012-05-28 14:39:55 +00:00
|
|
|
link->fromsock = node_group_expose_socket(ntree, link->tosock, SOCK_IN);
|
2012-05-15 12:40:43 +00:00
|
|
|
link->fromnode = NULL;
|
2012-05-28 14:39:55 +00:00
|
|
|
if (BLI_findindex(&ntree->links, link) < 0)
|
|
|
|
BLI_addtail(&ntree->links, link);
|
2012-05-15 12:40:43 +00:00
|
|
|
|
2012-05-28 14:39:55 +00:00
|
|
|
ntree->update |= NTREE_UPDATE_GROUP_IN | NTREE_UPDATE_LINKS;
|
2012-05-15 12:40:43 +00:00
|
|
|
}
|
|
|
|
else if (link->fromnode && link->fromsock) {
|
2012-05-28 14:39:55 +00:00
|
|
|
link->tosock = node_group_expose_socket(ntree, link->fromsock, SOCK_OUT);
|
2012-05-15 12:40:43 +00:00
|
|
|
link->tonode = NULL;
|
2012-05-28 14:39:55 +00:00
|
|
|
if (BLI_findindex(&ntree->links, link) < 0)
|
|
|
|
BLI_addtail(&ntree->links, link);
|
2012-05-15 12:40:43 +00:00
|
|
|
|
2012-05-28 14:39:55 +00:00
|
|
|
ntree->update |= NTREE_UPDATE_GROUP_OUT | NTREE_UPDATE_LINKS;
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
2011-02-21 13:47:49 +00:00
|
|
|
}
|
2012-05-15 12:40:43 +00:00
|
|
|
else
|
2012-05-28 14:39:55 +00:00
|
|
|
nodeRemLink(ntree, link);
|
2011-02-21 13:47:49 +00:00
|
|
|
}
|
2009-02-06 16:34:05 +00:00
|
|
|
|
2012-05-28 14:39:55 +00:00
|
|
|
ntreeUpdateTree(ntree);
|
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);
|
2009-02-06 16:34:05 +00:00
|
|
|
|
2011-03-13 22:07:55 +00:00
|
|
|
BLI_remlink(&snode->linkdrag, nldrag);
|
2012-05-15 12:40:43 +00:00
|
|
|
/* links->data pointers are either held by the tree or freed already */
|
|
|
|
BLI_freelistN(&nldrag->links);
|
2011-03-13 22:07:55 +00:00
|
|
|
MEM_freeN(nldrag);
|
2009-02-06 16:34:05 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
2012-05-15 12:40:43 +00:00
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
2009-02-06 16:34:05 +00:00
|
|
|
return OPERATOR_RUNNING_MODAL;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* return 1 when socket clicked */
|
2012-05-15 12:40:43 +00:00
|
|
|
static bNodeLinkDrag *node_link_init(SpaceNode *snode, int detach)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2012-05-15 12:40:43 +00:00
|
|
|
bNode *node;
|
|
|
|
bNodeSocket *sock;
|
|
|
|
bNodeLink *link, *link_next, *oplink;
|
|
|
|
bNodeLinkDrag *nldrag = NULL;
|
|
|
|
LinkData *linkdata;
|
|
|
|
int num_links;
|
|
|
|
|
2008-12-24 10:33:10 +00:00
|
|
|
/* output indicated? */
|
2012-05-15 12:40:43 +00:00
|
|
|
if (node_find_indicated_socket(snode, &node, &sock, SOCK_OUT)) {
|
2012-06-21 13:19:19 +00:00
|
|
|
nldrag = MEM_callocN(sizeof(bNodeLinkDrag), "drag link op customdata");
|
2012-05-15 12:40:43 +00:00
|
|
|
|
|
|
|
num_links = nodeCountSocketLinks(snode->edittree, sock);
|
|
|
|
if (num_links > 0 && (num_links >= sock->limit || detach)) {
|
|
|
|
/* dragged links are fixed on input side */
|
|
|
|
nldrag->in_out = SOCK_IN;
|
|
|
|
/* detach current links and store them in the operator data */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (link = snode->edittree->links.first; link; link = link_next) {
|
2012-05-15 12:40:43 +00:00
|
|
|
link_next = link->next;
|
2012-06-21 13:19:19 +00:00
|
|
|
if (link->fromsock == sock) {
|
2012-05-15 12:40:43 +00:00
|
|
|
linkdata = MEM_callocN(sizeof(LinkData), "drag link op link data");
|
|
|
|
linkdata->data = oplink = MEM_callocN(sizeof(bNodeLink), "drag link op link");
|
|
|
|
*oplink = *link;
|
2012-05-28 14:39:55 +00:00
|
|
|
oplink->next = oplink->prev = NULL;
|
2012-05-15 12:40:43 +00:00
|
|
|
BLI_addtail(&nldrag->links, linkdata);
|
|
|
|
nodeRemLink(snode->edittree, link);
|
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
}
|
2012-05-15 12:40:43 +00:00
|
|
|
else {
|
|
|
|
/* dragged links are fixed on output side */
|
|
|
|
nldrag->in_out = SOCK_OUT;
|
|
|
|
/* create a new link */
|
|
|
|
linkdata = MEM_callocN(sizeof(LinkData), "drag link op link data");
|
|
|
|
linkdata->data = oplink = MEM_callocN(sizeof(bNodeLink), "drag link op link");
|
|
|
|
oplink->fromnode = node;
|
|
|
|
oplink->fromsock = sock;
|
|
|
|
BLI_addtail(&nldrag->links, linkdata);
|
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
/* or an input? */
|
2012-05-15 12:40:43 +00:00
|
|
|
else if (node_find_indicated_socket(snode, &node, &sock, SOCK_IN)) {
|
2012-06-21 13:19:19 +00:00
|
|
|
nldrag = MEM_callocN(sizeof(bNodeLinkDrag), "drag link op customdata");
|
2012-05-15 12:40:43 +00:00
|
|
|
|
|
|
|
num_links = nodeCountSocketLinks(snode->edittree, sock);
|
|
|
|
if (num_links > 0 && (num_links >= sock->limit || detach)) {
|
|
|
|
/* dragged links are fixed on output side */
|
|
|
|
nldrag->in_out = SOCK_OUT;
|
|
|
|
/* detach current links and store them in the operator data */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (link = snode->edittree->links.first; link; link = link_next) {
|
2012-05-15 12:40:43 +00:00
|
|
|
link_next = link->next;
|
2012-06-21 13:19:19 +00:00
|
|
|
if (link->tosock == sock) {
|
2012-05-15 12:40:43 +00:00
|
|
|
linkdata = MEM_callocN(sizeof(LinkData), "drag link op link data");
|
|
|
|
linkdata->data = oplink = MEM_callocN(sizeof(bNodeLink), "drag link op link");
|
|
|
|
*oplink = *link;
|
2012-05-28 14:39:55 +00:00
|
|
|
oplink->next = oplink->prev = NULL;
|
2012-05-15 12:40:43 +00:00
|
|
|
BLI_addtail(&nldrag->links, linkdata);
|
|
|
|
nodeRemLink(snode->edittree, link);
|
|
|
|
|
|
|
|
/* send changed event to original link->tonode */
|
|
|
|
if (node)
|
|
|
|
snode_update(snode, node);
|
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
}
|
2012-05-15 12:40:43 +00:00
|
|
|
else {
|
|
|
|
/* dragged links are fixed on input side */
|
|
|
|
nldrag->in_out = SOCK_IN;
|
|
|
|
/* create a new link */
|
|
|
|
linkdata = MEM_callocN(sizeof(LinkData), "drag link op link data");
|
|
|
|
linkdata->data = oplink = MEM_callocN(sizeof(bNodeLink), "drag link op link");
|
|
|
|
oplink->tonode = node;
|
|
|
|
oplink->tosock = sock;
|
|
|
|
BLI_addtail(&nldrag->links, linkdata);
|
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
2012-05-15 12:40:43 +00:00
|
|
|
return nldrag;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
2009-02-06 16:34:05 +00:00
|
|
|
static int node_link_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
2012-05-15 12:40:43 +00:00
|
|
|
bNodeLinkDrag *nldrag;
|
|
|
|
int detach = RNA_boolean_get(op->ptr, "detach");
|
2009-02-06 16:34:05 +00:00
|
|
|
|
2011-05-20 07:40:05 +00:00
|
|
|
UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1],
|
2012-06-21 13:19:19 +00:00
|
|
|
&snode->mx, &snode->my);
|
2009-02-06 16:34:05 +00:00
|
|
|
|
2010-07-04 19:58:52 +00:00
|
|
|
ED_preview_kill_jobs(C);
|
|
|
|
|
2012-05-15 12:40:43 +00:00
|
|
|
nldrag = node_link_init(snode, detach);
|
2011-09-05 21:01:50 +00:00
|
|
|
|
2012-05-15 12:40:43 +00:00
|
|
|
if (nldrag) {
|
2012-06-21 13:19:19 +00:00
|
|
|
op->customdata = nldrag;
|
2011-03-13 22:07:55 +00:00
|
|
|
BLI_addtail(&snode->linkdrag, nldrag);
|
2009-02-06 16:34:05 +00:00
|
|
|
|
|
|
|
/* add modal handler */
|
2009-09-18 12:43:36 +00:00
|
|
|
WM_event_add_modal_handler(C, op);
|
2009-02-06 16:34:05 +00:00
|
|
|
|
|
|
|
return OPERATOR_RUNNING_MODAL;
|
|
|
|
}
|
2012-05-15 12:40:43 +00:00
|
|
|
else
|
2012-06-21 13:19:19 +00:00
|
|
|
return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH;
|
2009-02-06 16:34:05 +00:00
|
|
|
}
|
|
|
|
|
2011-06-06 11:04:54 +00:00
|
|
|
static int node_link_cancel(bContext *C, wmOperator *op)
|
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
bNodeLinkDrag *nldrag = op->customdata;
|
2012-05-15 12:40:43 +00:00
|
|
|
|
2011-06-06 11:04:54 +00:00
|
|
|
BLI_remlink(&snode->linkdrag, nldrag);
|
2012-05-15 12:40:43 +00:00
|
|
|
|
|
|
|
BLI_freelistN(&nldrag->links);
|
2011-06-06 11:04:54 +00:00
|
|
|
MEM_freeN(nldrag);
|
2012-05-15 12:40:43 +00:00
|
|
|
|
2011-06-06 11:04:54 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
2009-02-06 16:34:05 +00:00
|
|
|
void NODE_OT_link(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Link Nodes";
|
|
|
|
ot->idname = "NODE_OT_link";
|
2012-05-05 17:10:51 +00:00
|
|
|
ot->description = "Use the mouse to create a link between two nodes";
|
2009-02-06 16:34:05 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->invoke = node_link_invoke;
|
|
|
|
ot->modal = node_link_modal;
|
|
|
|
// ot->exec = node_link_exec;
|
|
|
|
ot->poll = ED_operator_node_active;
|
|
|
|
ot->cancel = node_link_cancel;
|
2009-02-06 16:34:05 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
|
2012-05-15 12:40:43 +00:00
|
|
|
|
|
|
|
RNA_def_boolean(ot->srna, "detach", FALSE, "Detach", "Detach and redirect existing links");
|
2009-02-06 16:34:05 +00:00
|
|
|
}
|
|
|
|
|
2009-11-20 06:31:49 +00:00
|
|
|
/* ********************** Make Link operator ***************** */
|
2009-01-12 00:14:37 +00:00
|
|
|
|
2008-12-24 10:33:10 +00:00
|
|
|
/* makes a link between selected output and input sockets */
|
2009-11-20 06:31:49 +00:00
|
|
|
static int node_make_link_exec(bContext *C, wmOperator *op)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2010-01-04 04:26:28 +00:00
|
|
|
int replace = RNA_boolean_get(op->ptr, "replace");
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2010-07-04 19:58:52 +00:00
|
|
|
ED_preview_kill_jobs(C);
|
|
|
|
|
2010-09-25 19:35:59 +00:00
|
|
|
snode_autoconnect(snode, 1, replace);
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-03-09 10:16:41 +00:00
|
|
|
/* deselect sockets after linking */
|
|
|
|
node_deselect_all_input_sockets(snode, 0);
|
|
|
|
node_deselect_all_output_sockets(snode, 0);
|
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
ntreeUpdateTree(snode->edittree);
|
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);
|
2009-11-20 06:31:49 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2009-11-20 06:31:49 +00:00
|
|
|
void NODE_OT_link_make(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Make Links";
|
|
|
|
ot->description = "Makes a link between selected output in input sockets";
|
|
|
|
ot->idname = "NODE_OT_link_make";
|
2009-11-20 06:31:49 +00:00
|
|
|
|
|
|
|
/* callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = node_make_link_exec;
|
|
|
|
ot->poll = ED_operator_node_active; // XXX we need a special poll which checks that there are selected input/output sockets
|
2009-11-20 06:31:49 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2010-01-04 04:26:28 +00:00
|
|
|
|
|
|
|
RNA_def_boolean(ot->srna, "replace", 0, "Replace", "Replace socket connections with the new links");
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
2012-06-01 12:38:03 +00:00
|
|
|
/* ********************** Add reroute operator ***************** */
|
2009-02-07 14:03:34 +00:00
|
|
|
#define LINK_RESOL 12
|
2012-06-01 12:38:03 +00:00
|
|
|
static int add_reroute_intersect_check(bNodeLink *link, float mcoords[][2], int tot, float result[2])
|
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
float coord_array[LINK_RESOL + 1][2];
|
2012-06-01 12:38:03 +00:00
|
|
|
int i, b;
|
|
|
|
|
2012-06-04 20:11:09 +00:00
|
|
|
if (node_link_bezier_points(NULL, NULL, link, coord_array, LINK_RESOL)) {
|
2012-06-01 12:38:03 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (i = 0; i < tot - 1; i++)
|
|
|
|
for (b = 0; b < LINK_RESOL; b++)
|
|
|
|
if (isect_line_line_v2(mcoords[i], mcoords[i + 1], coord_array[b], coord_array[b + 1]) > 0) {
|
|
|
|
result[0] = (mcoords[i][0] + mcoords[i + 1][0]) / 2.0f;
|
|
|
|
result[1] = (mcoords[i][1] + mcoords[i + 1][1]) / 2.0f;
|
2012-06-01 12:38:03 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int add_reroute_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
2012-07-19 08:23:56 +00:00
|
|
|
bNode *gnode = node_tree_get_editgroup(snode->nodetree);
|
2012-06-01 12:38:03 +00:00
|
|
|
float mcoords[256][2];
|
2012-06-21 13:19:19 +00:00
|
|
|
int i = 0;
|
2012-06-01 12:38:03 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
RNA_BEGIN(op->ptr, itemptr, "path")
|
|
|
|
{
|
2012-06-01 12:38:03 +00:00
|
|
|
float loc[2];
|
|
|
|
|
|
|
|
RNA_float_get_array(&itemptr, "loc", loc);
|
|
|
|
UI_view2d_region_to_view(&ar->v2d, (short)loc[0], (short)loc[1],
|
2012-06-21 13:19:19 +00:00
|
|
|
&mcoords[i][0], &mcoords[i][1]);
|
2012-06-01 12:38:03 +00:00
|
|
|
i++;
|
2012-06-21 13:19:19 +00:00
|
|
|
if (i >= 256) break;
|
2012-06-01 12:38:03 +00:00
|
|
|
}
|
|
|
|
RNA_END;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
if (i > 1) {
|
2012-06-01 12:38:03 +00:00
|
|
|
bNodeLink *link;
|
|
|
|
float insertPoint[2];
|
|
|
|
|
|
|
|
ED_preview_kill_jobs(C);
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (link = snode->edittree->links.first; link; link = link->next) {
|
2012-06-04 20:11:09 +00:00
|
|
|
if (add_reroute_intersect_check(link, mcoords, i, insertPoint)) {
|
2012-06-01 12:38:03 +00:00
|
|
|
bNodeTemplate ntemp;
|
|
|
|
bNode *rerouteNode;
|
|
|
|
|
|
|
|
node_deselect_all(snode);
|
|
|
|
|
|
|
|
ntemp.type = NODE_REROUTE;
|
|
|
|
rerouteNode = nodeAddNode(snode->edittree, &ntemp);
|
2012-07-19 08:23:56 +00:00
|
|
|
if (gnode) {
|
2012-07-20 15:07:06 +00:00
|
|
|
nodeFromView(gnode, insertPoint[0], insertPoint[1], &rerouteNode->locx, &rerouteNode->locy);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rerouteNode->locx = insertPoint[0];
|
|
|
|
rerouteNode->locy = insertPoint[1];
|
2012-07-19 08:23:56 +00:00
|
|
|
}
|
2012-06-01 12:38:03 +00:00
|
|
|
|
|
|
|
nodeAddLink(snode->edittree, link->fromnode, link->fromsock, rerouteNode, rerouteNode->inputs.first);
|
|
|
|
link->fromnode = rerouteNode;
|
|
|
|
link->fromsock = rerouteNode->outputs.first;
|
|
|
|
|
|
|
|
break; // add one reroute at the time.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ntreeUpdateTree(snode->edittree);
|
|
|
|
snode_notify(C, snode);
|
|
|
|
snode_dag_update(C, snode);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH;
|
2012-06-01 12:38:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void NODE_OT_add_reroute(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
PropertyRNA *prop;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->name = "Add reroute";
|
|
|
|
ot->idname = "NODE_OT_add_reroute";
|
2012-06-01 12:38:03 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->invoke = WM_gesture_lines_invoke;
|
|
|
|
ot->modal = WM_gesture_lines_modal;
|
|
|
|
ot->exec = add_reroute_exec;
|
|
|
|
ot->cancel = WM_gesture_lines_cancel;
|
2012-06-01 12:38:03 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->poll = ED_operator_node_active;
|
2012-06-01 12:38:03 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2012-06-01 12:38:03 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
prop = RNA_def_property(ot->srna, "path", PROP_COLLECTION, PROP_NONE);
|
2012-06-01 12:38:03 +00:00
|
|
|
RNA_def_property_struct_runtime(prop, &RNA_OperatorMousePath);
|
|
|
|
/* internal */
|
|
|
|
RNA_def_int(ot->srna, "cursor", BC_CROSSCURSOR, 0, INT_MAX, "Cursor", "", 0, INT_MAX);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ********************** Cut Link operator ***************** */
|
2009-02-07 14:03:34 +00:00
|
|
|
static int cut_links_intersect(bNodeLink *link, float mcoords[][2], int tot)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
float coord_array[LINK_RESOL + 1][2];
|
2009-02-07 14:03:34 +00:00
|
|
|
int i, b;
|
2012-06-01 12:38:03 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node_link_bezier_points(NULL, NULL, link, coord_array, LINK_RESOL)) {
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (i = 0; i < tot - 1; i++)
|
|
|
|
for (b = 0; b < LINK_RESOL; b++)
|
|
|
|
if (isect_line_line_v2(mcoords[i], mcoords[i + 1], coord_array[b], coord_array[b + 1]) > 0)
|
2009-02-07 14:03:34 +00:00
|
|
|
return 1;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2009-02-07 14:03:34 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cut_links_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
ARegion *ar = CTX_wm_region(C);
|
2009-02-07 14:03:34 +00:00
|
|
|
float mcoords[256][2];
|
2012-06-21 13:19:19 +00:00
|
|
|
int i = 0;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
RNA_BEGIN(op->ptr, itemptr, "path")
|
2012-04-30 16:22:40 +00:00
|
|
|
{
|
2009-02-07 14:03:34 +00:00
|
|
|
float loc[2];
|
|
|
|
|
|
|
|
RNA_float_get_array(&itemptr, "loc", loc);
|
2012-05-14 13:54:00 +00:00
|
|
|
UI_view2d_region_to_view(&ar->v2d, (int)loc[0], (int)loc[1],
|
2012-06-21 13:19:19 +00:00
|
|
|
&mcoords[i][0], &mcoords[i][1]);
|
2009-02-07 14:03:34 +00:00
|
|
|
i++;
|
2012-06-21 13:19:19 +00:00
|
|
|
if (i >= 256) break;
|
2009-02-07 14:03:34 +00:00
|
|
|
}
|
|
|
|
RNA_END;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
if (i > 1) {
|
2009-02-07 14:03:34 +00:00
|
|
|
bNodeLink *link, *next;
|
2010-07-04 19:58:52 +00:00
|
|
|
|
|
|
|
ED_preview_kill_jobs(C);
|
2009-02-07 14:03:34 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (link = snode->edittree->links.first; link; link = next) {
|
|
|
|
next = link->next;
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (cut_links_intersect(link, mcoords, i)) {
|
2011-10-19 17:08:35 +00:00
|
|
|
snode_update(snode, link->tonode);
|
2009-02-07 14:03:34 +00:00
|
|
|
nodeRemLink(snode->edittree, link);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
}
|
2009-11-20 06:31:49 +00:00
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
ntreeUpdateTree(snode->edittree);
|
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);
|
2009-02-07 14:03:34 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
2009-02-07 14:03:34 +00:00
|
|
|
void NODE_OT_links_cut(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
PropertyRNA *prop;
|
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Cut links";
|
|
|
|
ot->idname = "NODE_OT_links_cut";
|
2012-05-05 17:10:51 +00:00
|
|
|
ot->description = "Use the mouse to cut (remove) some links";
|
2009-02-07 14:03:34 +00:00
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->invoke = WM_gesture_lines_invoke;
|
|
|
|
ot->modal = WM_gesture_lines_modal;
|
|
|
|
ot->exec = cut_links_exec;
|
|
|
|
ot->cancel = WM_gesture_lines_cancel;
|
2009-02-07 14:03:34 +00:00
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->poll = ED_operator_node_active;
|
2009-02-07 14:03:34 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2009-02-07 14:03:34 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
prop = RNA_def_property(ot->srna, "path", PROP_COLLECTION, PROP_NONE);
|
2009-02-07 14:03:34 +00:00
|
|
|
RNA_def_property_struct_runtime(prop, &RNA_OperatorMousePath);
|
|
|
|
/* internal */
|
|
|
|
RNA_def_int(ot->srna, "cursor", BC_KNIFECURSOR, 0, INT_MAX, "Cursor", "", 0, INT_MAX);
|
|
|
|
}
|
|
|
|
|
2012-02-27 17:38:16 +00:00
|
|
|
/* ********************** Detach links operator ***************** */
|
|
|
|
|
2012-02-27 18:20:58 +00:00
|
|
|
static int detach_links_exec(bContext *C, wmOperator *UNUSED(op))
|
2012-02-27 17:38:16 +00:00
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
bNodeTree *ntree = snode->edittree;
|
2012-02-27 17:38:16 +00:00
|
|
|
bNode *node;
|
|
|
|
|
|
|
|
ED_preview_kill_jobs(C);
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->flag & SELECT) {
|
2012-02-27 17:38:16 +00:00
|
|
|
nodeInternalRelink(ntree, node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ntreeUpdateTree(ntree);
|
|
|
|
|
|
|
|
snode_notify(C, snode);
|
|
|
|
snode_dag_update(C, snode);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NODE_OT_links_detach(wmOperatorType *ot)
|
|
|
|
{
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Detach Links";
|
|
|
|
ot->idname = "NODE_OT_links_detach";
|
2012-05-05 17:10:51 +00:00
|
|
|
ot->description = "Remove all links to selected nodes, and try to connect neighbor nodes together";
|
2012-02-27 17:38:16 +00:00
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = detach_links_exec;
|
|
|
|
ot->poll = ED_operator_node_active;
|
2012-02-27 17:38:16 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2012-02-27 17:38:16 +00:00
|
|
|
}
|
|
|
|
|
2011-07-22 15:28:50 +00:00
|
|
|
/* ********************* automatic node insert on dragging ******************* */
|
|
|
|
|
2011-07-22 16:39:06 +00:00
|
|
|
/* assumes sockets in list */
|
2012-03-08 12:04:06 +00:00
|
|
|
static bNodeSocket *socket_best_match(ListBase *sockets)
|
2011-07-22 15:28:50 +00:00
|
|
|
{
|
|
|
|
bNodeSocket *sock;
|
2012-06-21 13:19:19 +00:00
|
|
|
int type, maxtype = 0;
|
2011-07-22 15:28:50 +00:00
|
|
|
|
2012-03-08 12:04:06 +00:00
|
|
|
/* find type range */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (sock = sockets->first; sock; sock = sock->next)
|
2012-03-08 12:04:06 +00:00
|
|
|
maxtype = MAX2(sock->type, maxtype);
|
2011-07-22 16:39:06 +00:00
|
|
|
|
2012-03-08 12:04:06 +00:00
|
|
|
/* try all types, starting from 'highest' (i.e. colors, vectors, values) */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (type = maxtype; type >= 0; --type) {
|
|
|
|
for (sock = sockets->first; sock; sock = sock->next) {
|
|
|
|
if (!nodeSocketIsHidden(sock) && type == sock->type) {
|
2012-03-08 12:04:06 +00:00
|
|
|
return sock;
|
|
|
|
}
|
2011-07-22 16:39:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-08 12:04:06 +00:00
|
|
|
/* no visible sockets, unhide first of highest type */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (type = maxtype; type >= 0; --type) {
|
|
|
|
for (sock = sockets->first; sock; sock = sock->next) {
|
|
|
|
if (type == sock->type) {
|
2012-04-16 10:50:57 +00:00
|
|
|
sock->flag &= ~SOCK_HIDDEN;
|
2012-03-08 12:04:06 +00:00
|
|
|
return sock;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-07-22 15:28:50 +00:00
|
|
|
|
2012-03-08 12:04:06 +00:00
|
|
|
return NULL;
|
2011-07-22 15:28:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* prevent duplicate testing code below */
|
|
|
|
static SpaceNode *ed_node_link_conditions(ScrArea *sa, bNode **select)
|
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = sa ? sa->spacedata.first : NULL;
|
2011-07-22 15:28:50 +00:00
|
|
|
bNode *node;
|
|
|
|
bNodeLink *link;
|
|
|
|
|
|
|
|
/* no unlucky accidents */
|
2012-06-21 13:19:19 +00:00
|
|
|
if (sa == NULL || sa->spacetype != SPACE_NODE) return NULL;
|
2011-07-22 15:28:50 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
*select = NULL;
|
2011-07-22 15:28:50 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = snode->edittree->nodes.first; node; node = node->next) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->flag & SELECT) {
|
|
|
|
if (*select)
|
2011-07-22 15:28:50 +00:00
|
|
|
break;
|
|
|
|
else
|
2012-06-21 13:19:19 +00:00
|
|
|
*select = node;
|
2011-07-22 15:28:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* only one selected */
|
2012-06-21 13:19:19 +00:00
|
|
|
if (node || *select == NULL) return NULL;
|
2011-07-22 15:28:50 +00:00
|
|
|
|
|
|
|
/* correct node */
|
2012-06-21 13:19:19 +00:00
|
|
|
if ((*select)->inputs.first == NULL || (*select)->outputs.first == NULL) return NULL;
|
2011-07-22 15:28:50 +00:00
|
|
|
|
|
|
|
/* test node for links */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (link = snode->edittree->links.first; link; link = link->next) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (link->tonode == *select || link->fromnode == *select)
|
2011-07-22 15:28:50 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return snode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* assumes link with NODE_LINKFLAG_HILITE set */
|
|
|
|
void ED_node_link_insert(ScrArea *sa)
|
|
|
|
{
|
|
|
|
bNode *node, *select;
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = ed_node_link_conditions(sa, &select);
|
2011-07-22 15:28:50 +00:00
|
|
|
bNodeLink *link;
|
|
|
|
bNodeSocket *sockto;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
if (snode == NULL) return;
|
2011-07-22 15:28:50 +00:00
|
|
|
|
|
|
|
/* get the link */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (link = snode->edittree->links.first; link; link = link->next)
|
2012-03-24 06:38:07 +00:00
|
|
|
if (link->flag & NODE_LINKFLAG_HILITE)
|
2011-07-22 15:28:50 +00:00
|
|
|
break;
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (link) {
|
2012-06-21 13:19:19 +00:00
|
|
|
node = link->tonode;
|
|
|
|
sockto = link->tosock;
|
2011-07-22 15:28:50 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
link->tonode = select;
|
|
|
|
link->tosock = socket_best_match(&select->inputs);
|
2011-07-22 15:28:50 +00:00
|
|
|
link->flag &= ~NODE_LINKFLAG_HILITE;
|
|
|
|
|
2012-03-08 12:04:06 +00:00
|
|
|
nodeAddLink(snode->edittree, select, socket_best_match(&select->outputs), node, sockto);
|
2012-06-21 13:19:19 +00:00
|
|
|
ntreeUpdateTree(snode->edittree); /* needed for pointers */
|
2011-10-19 17:08:35 +00:00
|
|
|
snode_update(snode, select);
|
2011-07-22 15:28:50 +00:00
|
|
|
ED_node_changed_update(snode->id, select);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* test == 0, clear all intersect flags */
|
|
|
|
void ED_node_link_intersect_test(ScrArea *sa, int test)
|
|
|
|
{
|
|
|
|
bNode *select;
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = ed_node_link_conditions(sa, &select);
|
|
|
|
bNodeLink *link, *selink = NULL;
|
2011-07-22 16:39:06 +00:00
|
|
|
float mcoords[6][2];
|
2011-07-22 15:28:50 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
if (snode == NULL) return;
|
2011-07-22 15:28:50 +00:00
|
|
|
|
|
|
|
/* clear flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (link = snode->edittree->links.first; link; link = link->next)
|
2011-07-22 15:28:50 +00:00
|
|
|
link->flag &= ~NODE_LINKFLAG_HILITE;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
if (test == 0) return;
|
2011-07-22 15:28:50 +00:00
|
|
|
|
|
|
|
/* okay, there's 1 node, without links, now intersect */
|
2012-06-21 13:19:19 +00:00
|
|
|
mcoords[0][0] = select->totr.xmin;
|
|
|
|
mcoords[0][1] = select->totr.ymin;
|
|
|
|
mcoords[1][0] = select->totr.xmax;
|
|
|
|
mcoords[1][1] = select->totr.ymin;
|
|
|
|
mcoords[2][0] = select->totr.xmax;
|
|
|
|
mcoords[2][1] = select->totr.ymax;
|
|
|
|
mcoords[3][0] = select->totr.xmin;
|
|
|
|
mcoords[3][1] = select->totr.ymax;
|
|
|
|
mcoords[4][0] = select->totr.xmin;
|
|
|
|
mcoords[4][1] = select->totr.ymin;
|
|
|
|
mcoords[5][0] = select->totr.xmax;
|
|
|
|
mcoords[5][1] = select->totr.ymax;
|
2011-07-22 15:28:50 +00:00
|
|
|
|
|
|
|
/* we only tag a single link for intersect now */
|
|
|
|
/* idea; use header dist when more? */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (link = snode->edittree->links.first; link; link = link->next) {
|
2011-07-22 15:28:50 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (cut_links_intersect(link, mcoords, 5)) { /* intersect code wants edges */
|
|
|
|
if (selink)
|
2011-07-22 15:28:50 +00:00
|
|
|
break;
|
2012-06-21 13:19:19 +00:00
|
|
|
selink = link;
|
2011-07-22 15:28:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
if (link == NULL && selink)
|
2011-07-22 15:28:50 +00:00
|
|
|
selink->flag |= NODE_LINKFLAG_HILITE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-07 14:03:34 +00:00
|
|
|
/* ******************************** */
|
2009-11-20 06:31:49 +00:00
|
|
|
// XXX some code needing updating to operators...
|
2009-02-07 14:03:34 +00:00
|
|
|
|
2011-01-17 18:38:44 +00:00
|
|
|
|
2010-04-06 17:47:21 +00:00
|
|
|
/* goes over all scenes, reads render layers */
|
2010-10-15 01:36:14 +00:00
|
|
|
static int node_read_renderlayers_exec(bContext *C, wmOperator *UNUSED(op))
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
Scene *curscene = CTX_data_scene(C), *scene;
|
2008-12-24 10:33:10 +00:00
|
|
|
bNode *node;
|
|
|
|
|
2010-07-04 19:58:52 +00:00
|
|
|
ED_preview_kill_jobs(C);
|
|
|
|
|
2008-12-24 10:33:10 +00:00
|
|
|
/* first tag scenes unread */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (scene = bmain->scene.first; scene; scene = scene->id.next)
|
2008-12-24 10:33:10 +00:00
|
|
|
scene->id.flag |= LIB_DOIT;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = snode->edittree->nodes.first; node; node = node->next) {
|
|
|
|
if (node->type == CMP_NODE_R_LAYERS) {
|
|
|
|
ID *id = node->id;
|
2012-03-24 06:38:07 +00:00
|
|
|
if (id->flag & LIB_DOIT) {
|
2009-02-07 14:03:34 +00:00
|
|
|
RE_ReadRenderResult(curscene, (Scene *)id);
|
2008-12-24 10:33:10 +00:00
|
|
|
ntreeCompositTagRender((Scene *)id);
|
|
|
|
id->flag &= ~LIB_DOIT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-06 17:47:21 +00:00
|
|
|
snode_notify(C, snode);
|
2011-05-02 12:31:09 +00:00
|
|
|
snode_dag_update(C, snode);
|
|
|
|
|
2010-04-06 17:47:21 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NODE_OT_read_renderlayers(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Read Render Layers";
|
|
|
|
ot->idname = "NODE_OT_read_renderlayers";
|
2012-05-05 17:10:51 +00:00
|
|
|
ot->description = "Read all render layers of all used scenes";
|
2010-04-06 17:47:21 +00:00
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = node_read_renderlayers_exec;
|
2010-04-06 17:47:21 +00:00
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->poll = composite_node_active;
|
2010-04-06 17:47:21 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->flag = 0;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
2010-10-15 01:36:14 +00:00
|
|
|
static int node_read_fullsamplelayers_exec(bContext *C, wmOperator *UNUSED(op))
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
Scene *curscene = CTX_data_scene(C);
|
|
|
|
Render *re = RE_NewRender(curscene->id.name);
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2010-12-28 10:39:27 +00:00
|
|
|
WM_cursor_wait(1);
|
2010-10-31 11:51:10 +00:00
|
|
|
RE_MergeFullSample(re, bmain, curscene, snode->nodetree);
|
2010-12-28 10:39:27 +00:00
|
|
|
WM_cursor_wait(0);
|
2011-09-22 12:45:25 +00:00
|
|
|
|
|
|
|
/* note we are careful to send the right notifier, as otherwise the
|
2012-03-03 16:31:46 +00:00
|
|
|
* compositor would reexecute and overwrite the full sample result */
|
2012-06-21 13:19:19 +00:00
|
|
|
WM_event_add_notifier(C, NC_SCENE | ND_COMPO_RESULT, NULL);
|
2011-09-22 12:45:25 +00:00
|
|
|
|
2010-04-06 17:47:21 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void NODE_OT_read_fullsamplelayers(wmOperatorType *ot)
|
|
|
|
{
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Read Full Sample Layers";
|
|
|
|
ot->idname = "NODE_OT_read_fullsamplelayers";
|
2012-05-05 17:10:51 +00:00
|
|
|
ot->description = "Read all render layers of current scene, in full sample";
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = node_read_fullsamplelayers_exec;
|
2010-04-06 17:47:21 +00:00
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->poll = composite_node_active;
|
2010-04-06 17:47:21 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->flag = 0;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
2011-02-07 16:41:57 +00:00
|
|
|
int node_render_changed_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
Scene *sce = CTX_data_scene(C);
|
2011-02-07 16:41:57 +00:00
|
|
|
bNode *node;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = sce->nodetree->nodes.first; node; node = node->next) {
|
|
|
|
if (node->id == (ID *)sce && node->need_exec) {
|
2011-02-07 16:41:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node) {
|
2012-06-21 13:19:19 +00:00
|
|
|
SceneRenderLayer *srl = BLI_findlink(&sce->r.layers, node->custom1);
|
2011-02-07 16:41:57 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (srl) {
|
2011-02-07 16:41:57 +00:00
|
|
|
PointerRNA op_ptr;
|
|
|
|
|
|
|
|
WM_operator_properties_create(&op_ptr, "RENDER_OT_render");
|
|
|
|
RNA_string_set(&op_ptr, "layer", srl->name);
|
2012-06-21 13:19:19 +00:00
|
|
|
RNA_string_set(&op_ptr, "scene", sce->id.name + 2);
|
2011-02-07 16:41:57 +00:00
|
|
|
|
2011-02-07 18:09:27 +00:00
|
|
|
/* to keep keypositions */
|
|
|
|
sce->r.scemode |= R_NO_FRAME_UPDATE;
|
|
|
|
|
2011-02-07 16:41:57 +00:00
|
|
|
WM_operator_name_call(C, "RENDER_OT_render", WM_OP_INVOKE_DEFAULT, &op_ptr);
|
|
|
|
|
|
|
|
WM_operator_properties_free(&op_ptr);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NODE_OT_render_changed(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Render Changed Layer";
|
|
|
|
ot->idname = "NODE_OT_render_changed";
|
2012-05-05 17:10:51 +00:00
|
|
|
ot->description = "Render current scene, when input node's layer has been changed";
|
2011-02-07 16:41:57 +00:00
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = node_render_changed_exec;
|
2011-02-07 16:41:57 +00:00
|
|
|
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->poll = composite_node_active;
|
2011-02-07 16:41:57 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->flag = 0;
|
2011-02-07 16:41:57 +00:00
|
|
|
}
|
|
|
|
|
2010-04-06 17:47:21 +00:00
|
|
|
|
2009-09-15 11:35:10 +00:00
|
|
|
/* ****************** Make Group operator ******************* */
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-06-12 08:44:46 +00:00
|
|
|
static int node_group_make_test(bNodeTree *ntree, bNode *gnode)
|
|
|
|
{
|
|
|
|
bNode *node;
|
|
|
|
bNodeLink *link;
|
|
|
|
int totnode = 0;
|
|
|
|
|
|
|
|
/* is there something to group? also do some clearing */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
2012-06-12 08:44:46 +00:00
|
|
|
if (node == gnode)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (node->flag & NODE_SELECT) {
|
|
|
|
/* no groups in groups */
|
2012-06-21 13:19:19 +00:00
|
|
|
if (node->type == NODE_GROUP)
|
2012-06-12 08:44:46 +00:00
|
|
|
return 0;
|
|
|
|
totnode++;
|
|
|
|
}
|
|
|
|
|
|
|
|
node->done = 0;
|
|
|
|
}
|
2012-06-21 13:19:19 +00:00
|
|
|
if (totnode == 0) return 0;
|
2012-06-12 08:44:46 +00:00
|
|
|
|
|
|
|
/* check if all connections are OK, no unselected node has both
|
|
|
|
* inputs and outputs to a selection */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (link = ntree->links.first; link; link = link->next) {
|
2012-06-12 08:44:46 +00:00
|
|
|
if (link->fromnode && link->tonode && link->fromnode->flag & NODE_SELECT && link->fromnode != gnode)
|
|
|
|
link->tonode->done |= 1;
|
|
|
|
if (link->fromnode && link->tonode && link->tonode->flag & NODE_SELECT && link->tonode != gnode)
|
|
|
|
link->fromnode->done |= 2;
|
|
|
|
}
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
2012-06-12 08:44:46 +00:00
|
|
|
if (node == gnode)
|
|
|
|
continue;
|
2012-06-21 13:19:19 +00:00
|
|
|
if ((node->flag & NODE_SELECT) == 0)
|
|
|
|
if (node->done == 3)
|
2012-06-12 08:44:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (node)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void node_get_selected_minmax(bNodeTree *ntree, bNode *gnode, float *min, float *max)
|
|
|
|
{
|
|
|
|
bNode *node;
|
|
|
|
INIT_MINMAX2(min, max);
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
2012-06-12 08:44:46 +00:00
|
|
|
if (node == gnode)
|
|
|
|
continue;
|
|
|
|
if (node->flag & NODE_SELECT) {
|
|
|
|
DO_MINMAX2((&node->locx), min, max);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int node_group_make_insert_selected(bNodeTree *ntree, bNode *gnode)
|
|
|
|
{
|
|
|
|
bNodeTree *ngroup = (bNodeTree *)gnode->id;
|
|
|
|
bNodeLink *link, *linkn;
|
|
|
|
bNode *node, *nextn;
|
|
|
|
bNodeSocket *gsock;
|
|
|
|
ListBase anim_basepaths = {NULL, NULL};
|
|
|
|
float min[2], max[2];
|
|
|
|
|
|
|
|
/* deselect all nodes in the target tree */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = ngroup->nodes.first; node; node = node->next)
|
2012-06-12 08:44:46 +00:00
|
|
|
node_deselect(node);
|
|
|
|
|
|
|
|
node_get_selected_minmax(ntree, gnode, min, max);
|
|
|
|
|
|
|
|
/* move nodes over */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = ntree->nodes.first; node; node = nextn) {
|
|
|
|
nextn = node->next;
|
2012-06-12 08:44:46 +00:00
|
|
|
if (node == gnode)
|
|
|
|
continue;
|
|
|
|
if (node->flag & NODE_SELECT) {
|
|
|
|
/* keep track of this node's RNA "base" path (the part of the pat identifying the node)
|
|
|
|
* if the old nodetree has animation data which potentially covers this node
|
|
|
|
*/
|
|
|
|
if (ntree->adt) {
|
|
|
|
PointerRNA ptr;
|
|
|
|
char *path;
|
|
|
|
|
|
|
|
RNA_pointer_create(&ntree->id, &RNA_Node, node, &ptr);
|
|
|
|
path = RNA_path_from_ID_to_struct(&ptr);
|
|
|
|
|
|
|
|
if (path)
|
|
|
|
BLI_addtail(&anim_basepaths, BLI_genericNodeN(path));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ensure valid parent pointers, detach if parent stays outside the group */
|
|
|
|
if (node->parent && !(node->parent->flag & NODE_SELECT))
|
|
|
|
nodeDetachNode(node);
|
|
|
|
|
|
|
|
/* change node-collection membership */
|
|
|
|
BLI_remlink(&ntree->nodes, node);
|
|
|
|
BLI_addtail(&ngroup->nodes, node);
|
|
|
|
|
2012-07-10 09:31:08 +00:00
|
|
|
/* ensure unique node name in the ngroup */
|
|
|
|
nodeUniqueName(ngroup, node);
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
node->locx -= 0.5f * (min[0] + max[0]);
|
|
|
|
node->locy -= 0.5f * (min[1] + max[1]);
|
2012-06-12 08:44:46 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-10 09:31:08 +00:00
|
|
|
|
2012-06-12 08:44:46 +00:00
|
|
|
/* move animation data over */
|
|
|
|
if (ntree->adt) {
|
2012-06-21 13:19:19 +00:00
|
|
|
LinkData *ld, *ldn = NULL;
|
2012-06-12 08:44:46 +00:00
|
|
|
|
|
|
|
BKE_animdata_separate_by_basepath(&ntree->id, &ngroup->id, &anim_basepaths);
|
|
|
|
|
|
|
|
/* paths + their wrappers need to be freed */
|
|
|
|
for (ld = anim_basepaths.first; ld; ld = ldn) {
|
|
|
|
ldn = ld->next;
|
|
|
|
|
|
|
|
MEM_freeN(ld->data);
|
|
|
|
BLI_freelinkN(&anim_basepaths, ld);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* node groups don't use internal cached data */
|
|
|
|
ntreeFreeCache(ngroup);
|
|
|
|
|
|
|
|
/* relink external sockets */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (link = ntree->links.first; link; link = linkn) {
|
2012-06-12 08:44:46 +00:00
|
|
|
int fromselect = (link->fromnode && (link->fromnode->flag & NODE_SELECT) && link->fromnode != gnode);
|
|
|
|
int toselect = (link->tonode && (link->tonode->flag & NODE_SELECT) && link->tonode != gnode);
|
2012-06-21 13:19:19 +00:00
|
|
|
linkn = link->next;
|
2012-06-12 08:44:46 +00:00
|
|
|
|
|
|
|
if (gnode && ((fromselect && link->tonode == gnode) || (toselect && link->fromnode == gnode))) {
|
|
|
|
/* remove all links to/from the gnode.
|
|
|
|
* this can remove link information, but there's no general way to preserve it.
|
|
|
|
*/
|
|
|
|
nodeRemLink(ntree, link);
|
|
|
|
}
|
|
|
|
else if (fromselect && toselect) {
|
|
|
|
BLI_remlink(&ntree->links, link);
|
|
|
|
BLI_addtail(&ngroup->links, link);
|
|
|
|
}
|
|
|
|
else if (toselect) {
|
|
|
|
gsock = node_group_expose_socket(ngroup, link->tosock, SOCK_IN);
|
|
|
|
link->tosock->link = nodeAddLink(ngroup, NULL, gsock, link->tonode, link->tosock);
|
|
|
|
link->tosock = node_group_add_extern_socket(ntree, &gnode->inputs, SOCK_IN, gsock);
|
|
|
|
link->tonode = gnode;
|
|
|
|
}
|
|
|
|
else if (fromselect) {
|
|
|
|
/* search for existing group node socket */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (gsock = ngroup->outputs.first; gsock; gsock = gsock->next)
|
|
|
|
if (gsock->link && gsock->link->fromsock == link->fromsock)
|
2012-06-12 08:44:46 +00:00
|
|
|
break;
|
|
|
|
if (!gsock) {
|
|
|
|
gsock = node_group_expose_socket(ngroup, link->fromsock, SOCK_OUT);
|
|
|
|
gsock->link = nodeAddLink(ngroup, link->fromnode, link->fromsock, NULL, gsock);
|
|
|
|
link->fromsock = node_group_add_extern_socket(ntree, &gnode->outputs, SOCK_OUT, gsock);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
link->fromsock = node_group_find_output(gnode, gsock);
|
|
|
|
link->fromnode = gnode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* update of the group tree */
|
|
|
|
ngroup->update |= NTREE_UPDATE;
|
|
|
|
/* update of the tree containing the group instance node */
|
|
|
|
ntree->update |= NTREE_UPDATE_NODES | NTREE_UPDATE_LINKS;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bNode *node_group_make_from_selected(bNodeTree *ntree)
|
|
|
|
{
|
|
|
|
bNode *gnode;
|
|
|
|
bNodeTree *ngroup;
|
|
|
|
float min[2], max[2];
|
|
|
|
bNodeTemplate ntemp;
|
|
|
|
|
|
|
|
node_get_selected_minmax(ntree, NULL, min, max);
|
|
|
|
|
|
|
|
/* new nodetree */
|
2012-06-21 13:19:19 +00:00
|
|
|
ngroup = ntreeAddTree("NodeGroup", ntree->type, NODE_GROUP);
|
2012-06-12 08:44:46 +00:00
|
|
|
|
|
|
|
/* make group node */
|
|
|
|
ntemp.type = NODE_GROUP;
|
|
|
|
ntemp.ngroup = ngroup;
|
2012-06-21 13:19:19 +00:00
|
|
|
gnode = nodeAddNode(ntree, &ntemp);
|
|
|
|
gnode->locx = 0.5f * (min[0] + max[0]);
|
|
|
|
gnode->locy = 0.5f * (min[1] + max[1]);
|
2012-06-12 08:44:46 +00:00
|
|
|
|
|
|
|
node_group_make_insert_selected(ntree, gnode);
|
|
|
|
|
|
|
|
/* update of the tree containing the group instance node */
|
|
|
|
ntree->update |= NTREE_UPDATE_NODES;
|
|
|
|
|
|
|
|
return gnode;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef enum eNodeGroupMakeType {
|
|
|
|
NODE_GM_NEW,
|
|
|
|
NODE_GM_INSERT
|
|
|
|
} eNodeGroupMakeType;
|
|
|
|
|
|
|
|
/* Operator Property */
|
|
|
|
EnumPropertyItem node_group_make_types[] = {
|
|
|
|
{NODE_GM_NEW, "NEW", 0, "New", "Create a new node group from selected nodes"},
|
|
|
|
{NODE_GM_INSERT, "INSERT", 0, "Insert", "Insert into active node group"},
|
|
|
|
{0, NULL, 0, NULL, NULL}
|
|
|
|
};
|
|
|
|
|
2009-09-15 11:35:10 +00:00
|
|
|
static int node_group_make_exec(bContext *C, wmOperator *op)
|
2008-12-24 10:33:10 +00:00
|
|
|
{
|
2009-09-15 11:35:10 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2008-12-24 10:33:10 +00:00
|
|
|
bNode *gnode;
|
2012-06-12 08:44:46 +00:00
|
|
|
int type = RNA_enum_get(op->ptr, "type");
|
2008-12-24 10:33:10 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
if (snode->edittree != snode->nodetree) {
|
2010-12-21 15:10:09 +00:00
|
|
|
BKE_report(op->reports, RPT_WARNING, "Can not add a new Group in a Group");
|
2009-09-15 11:35:10 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* for time being... is too complex to handle */
|
2012-06-21 13:19:19 +00:00
|
|
|
if (snode->treetype == NTREE_COMPOSIT) {
|
|
|
|
for (gnode = snode->nodetree->nodes.first; gnode; gnode = gnode->next) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (gnode->flag & SELECT)
|
2012-06-21 13:19:19 +00:00
|
|
|
if (gnode->type == CMP_NODE_R_LAYERS)
|
2008-12-24 10:33:10 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-11-20 06:31:49 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (gnode) {
|
2010-12-21 15:10:09 +00:00
|
|
|
BKE_report(op->reports, RPT_WARNING, "Can not add RenderLayer in a Group");
|
2009-09-15 11:35:10 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-12 08:44:46 +00:00
|
|
|
ED_preview_kill_jobs(C);
|
|
|
|
|
|
|
|
switch (type) {
|
2012-06-21 13:19:19 +00:00
|
|
|
case NODE_GM_NEW:
|
|
|
|
if (node_group_make_test(snode->nodetree, NULL)) {
|
|
|
|
gnode = node_group_make_from_selected(snode->nodetree);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BKE_report(op->reports, RPT_WARNING, "Can not make Group");
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NODE_GM_INSERT:
|
|
|
|
gnode = nodeGetActive(snode->nodetree);
|
|
|
|
if (!gnode || gnode->type != NODE_GROUP) {
|
|
|
|
BKE_report(op->reports, RPT_WARNING, "No active Group node");
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
if (node_group_make_test(snode->nodetree, gnode)) {
|
|
|
|
node_group_make_insert_selected(snode->nodetree, gnode);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BKE_report(op->reports, RPT_WARNING, "Can not insert into Group");
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
break;
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2012-06-12 08:44:46 +00:00
|
|
|
|
|
|
|
if (gnode) {
|
2008-12-24 10:33:10 +00:00
|
|
|
nodeSetActive(snode->nodetree, gnode);
|
2012-06-12 08:44:46 +00:00
|
|
|
snode_make_group_editable(snode, gnode);
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
2009-11-20 04:19:57 +00:00
|
|
|
|
2012-06-12 08:44:46 +00:00
|
|
|
if (gnode)
|
|
|
|
ntreeUpdateTree((bNodeTree *)gnode->id);
|
|
|
|
ntreeUpdateTree(snode->nodetree);
|
|
|
|
|
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);
|
2009-11-20 06:31:49 +00:00
|
|
|
|
2009-09-15 11:35:10 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
2012-06-12 08:44:46 +00:00
|
|
|
static int node_group_make_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *UNUSED(event))
|
|
|
|
{
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
bNode *act = nodeGetActive(snode->edittree);
|
|
|
|
uiPopupMenu *pup = uiPupMenuBegin(C, "Make Group", ICON_NONE);
|
|
|
|
uiLayout *layout = uiPupMenuLayout(pup);
|
|
|
|
|
|
|
|
uiLayoutSetOperatorContext(layout, WM_OP_EXEC_DEFAULT);
|
|
|
|
uiItemEnumO(layout, "NODE_OT_group_make", NULL, 0, "type", NODE_GM_NEW);
|
|
|
|
|
|
|
|
/* if active node is a group, add insert option */
|
|
|
|
if (act && act->type == NODE_GROUP) {
|
|
|
|
uiItemEnumO(layout, "NODE_OT_group_make", NULL, 0, "type", NODE_GM_INSERT);
|
|
|
|
}
|
|
|
|
|
|
|
|
uiPupMenuEnd(C, pup);
|
|
|
|
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
2009-09-15 11:35:10 +00:00
|
|
|
void NODE_OT_group_make(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Group";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description = "Make group from selected nodes";
|
2009-09-15 11:35:10 +00:00
|
|
|
ot->idname = "NODE_OT_group_make";
|
|
|
|
|
|
|
|
/* api callbacks */
|
2012-06-12 08:44:46 +00:00
|
|
|
ot->invoke = node_group_make_invoke;
|
2009-09-15 11:35:10 +00:00
|
|
|
ot->exec = node_group_make_exec;
|
|
|
|
ot->poll = ED_operator_node_active;
|
|
|
|
|
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2012-06-12 08:44:46 +00:00
|
|
|
|
|
|
|
RNA_def_enum(ot->srna, "type", node_group_make_types, NODE_GM_NEW, "Type", "");
|
2008-12-24 10:33:10 +00:00
|
|
|
}
|
|
|
|
|
2009-11-20 06:31:49 +00:00
|
|
|
/* ****************** Hide operator *********************** */
|
|
|
|
|
2010-06-07 20:03:40 +00:00
|
|
|
static void node_flag_toggle_exec(SpaceNode *snode, int toggle_flag)
|
2009-11-20 06:31:49 +00:00
|
|
|
{
|
|
|
|
bNode *node;
|
2012-06-21 13:19:19 +00:00
|
|
|
int tot_eq = 0, tot_neq = 0;
|
2010-06-07 20:03:40 +00:00
|
|
|
|
2011-12-18 12:51:50 +00:00
|
|
|
/* Toggles the flag on all selected nodes.
|
|
|
|
* If the flag is set on all nodes it is unset.
|
|
|
|
* If the flag is not set on all nodes, it is set.
|
|
|
|
*/
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = snode->edittree->nodes.first; node; node = node->next) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->flag & SELECT) {
|
2011-12-18 12:51:50 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
if (toggle_flag == NODE_PREVIEW && (node->typeinfo->flag & NODE_PREVIEW) == 0)
|
2010-06-09 14:17:22 +00:00
|
|
|
continue;
|
2012-06-21 13:19:19 +00:00
|
|
|
if (toggle_flag == NODE_OPTIONS && (node->typeinfo->flag & NODE_OPTIONS) == 0)
|
2011-12-18 12:51:50 +00:00
|
|
|
continue;
|
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->flag & toggle_flag)
|
2010-06-07 20:03:40 +00:00
|
|
|
tot_eq++;
|
2009-11-20 06:31:49 +00:00
|
|
|
else
|
2010-06-07 20:03:40 +00:00
|
|
|
tot_neq++;
|
2009-11-20 06:31:49 +00:00
|
|
|
}
|
|
|
|
}
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = snode->edittree->nodes.first; node; node = node->next) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->flag & SELECT) {
|
2011-12-18 12:51:50 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
if (toggle_flag == NODE_PREVIEW && (node->typeinfo->flag & NODE_PREVIEW) == 0)
|
2010-06-09 14:17:22 +00:00
|
|
|
continue;
|
2012-06-21 13:19:19 +00:00
|
|
|
if (toggle_flag == NODE_OPTIONS && (node->typeinfo->flag & NODE_OPTIONS) == 0)
|
2011-12-18 12:51:50 +00:00
|
|
|
continue;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
if ( (tot_eq && tot_neq) || tot_eq == 0)
|
2010-06-07 20:03:40 +00:00
|
|
|
node->flag |= toggle_flag;
|
2012-04-16 10:50:57 +00:00
|
|
|
else
|
2010-06-07 20:03:40 +00:00
|
|
|
node->flag &= ~toggle_flag;
|
2009-11-20 06:31:49 +00:00
|
|
|
}
|
|
|
|
}
|
2010-06-07 20:03:40 +00:00
|
|
|
}
|
|
|
|
|
2011-12-18 12:51:50 +00:00
|
|
|
static int node_hide_toggle_exec(bContext *C, wmOperator *UNUSED(op))
|
2010-06-07 20:03:40 +00:00
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2010-06-07 20:03:40 +00:00
|
|
|
|
|
|
|
/* sanity checking (poll callback checks this already) */
|
2012-03-24 06:38:07 +00:00
|
|
|
if ((snode == NULL) || (snode->edittree == NULL))
|
2010-06-07 20:03:40 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
|
|
|
node_flag_toggle_exec(snode, NODE_HIDDEN);
|
2012-07-16 16:16:05 +00:00
|
|
|
|
|
|
|
WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL);
|
|
|
|
|
2009-11-20 06:31:49 +00:00
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
2010-06-07 20:03:40 +00:00
|
|
|
void NODE_OT_hide_toggle(wmOperatorType *ot)
|
2009-11-20 06:31:49 +00:00
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Hide";
|
|
|
|
ot->description = "Toggle hiding of selected nodes";
|
|
|
|
ot->idname = "NODE_OT_hide_toggle";
|
2009-11-20 06:31:49 +00:00
|
|
|
|
|
|
|
/* callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = node_hide_toggle_exec;
|
|
|
|
ot->poll = ED_operator_node_active;
|
2010-06-07 20:03:40 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2010-06-07 20:03:40 +00:00
|
|
|
}
|
|
|
|
|
2011-12-18 12:51:50 +00:00
|
|
|
static int node_preview_toggle_exec(bContext *C, wmOperator *UNUSED(op))
|
2010-06-07 20:03:40 +00:00
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2010-06-07 20:03:40 +00:00
|
|
|
|
|
|
|
/* sanity checking (poll callback checks this already) */
|
2012-03-24 06:38:07 +00:00
|
|
|
if ((snode == NULL) || (snode->edittree == NULL))
|
2010-06-07 20:03:40 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
2010-07-04 19:58:52 +00:00
|
|
|
ED_preview_kill_jobs(C);
|
|
|
|
|
2010-06-07 20:03:40 +00:00
|
|
|
node_flag_toggle_exec(snode, NODE_PREVIEW);
|
|
|
|
|
|
|
|
snode_notify(C, snode);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NODE_OT_preview_toggle(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Toggle Node Preview";
|
|
|
|
ot->description = "Toggle preview display for selected nodes";
|
|
|
|
ot->idname = "NODE_OT_preview_toggle";
|
2010-06-07 20:03:40 +00:00
|
|
|
|
|
|
|
/* callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = node_preview_toggle_exec;
|
|
|
|
ot->poll = ED_operator_node_active;
|
2011-12-18 12:51:50 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2011-12-18 12:51:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int node_options_toggle_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2011-12-18 12:51:50 +00:00
|
|
|
|
|
|
|
/* sanity checking (poll callback checks this already) */
|
2012-03-24 06:38:07 +00:00
|
|
|
if ((snode == NULL) || (snode->edittree == NULL))
|
2011-12-18 12:51:50 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
|
|
|
node_flag_toggle_exec(snode, NODE_OPTIONS);
|
|
|
|
|
2012-07-16 16:16:05 +00:00
|
|
|
WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL);
|
2011-12-18 12:51:50 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NODE_OT_options_toggle(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Toggle Node Options";
|
|
|
|
ot->description = "Toggle option buttons display for selected nodes";
|
|
|
|
ot->idname = "NODE_OT_options_toggle";
|
2011-12-18 12:51:50 +00:00
|
|
|
|
|
|
|
/* callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = node_options_toggle_exec;
|
|
|
|
ot->poll = ED_operator_node_active;
|
2010-06-07 20:03:40 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2010-06-07 20:03:40 +00:00
|
|
|
}
|
|
|
|
|
2010-10-15 01:36:14 +00:00
|
|
|
static int node_socket_toggle_exec(bContext *C, wmOperator *UNUSED(op))
|
2010-06-07 20:03:40 +00:00
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2010-06-07 20:03:40 +00:00
|
|
|
bNode *node;
|
2011-12-18 12:51:50 +00:00
|
|
|
int hidden;
|
2010-06-07 20:03:40 +00:00
|
|
|
|
|
|
|
/* sanity checking (poll callback checks this already) */
|
2012-03-24 06:38:07 +00:00
|
|
|
if ((snode == NULL) || (snode->edittree == NULL))
|
2010-06-07 20:03:40 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
2010-07-04 19:58:52 +00:00
|
|
|
ED_preview_kill_jobs(C);
|
|
|
|
|
2011-12-18 12:51:50 +00:00
|
|
|
/* Toggle for all selected nodes */
|
|
|
|
hidden = 0;
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = snode->edittree->nodes.first; node; node = node->next) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->flag & SELECT) {
|
2012-04-16 10:50:57 +00:00
|
|
|
if (node_has_hidden_sockets(node)) {
|
2012-06-21 13:19:19 +00:00
|
|
|
hidden = 1;
|
2010-06-07 20:03:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-12-18 12:51:50 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = snode->edittree->nodes.first; node; node = node->next) {
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->flag & SELECT) {
|
2012-04-16 10:50:57 +00:00
|
|
|
node_set_hidden_sockets(snode, node, !hidden);
|
2010-06-07 20:03:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
ntreeUpdateTree(snode->edittree);
|
2010-06-07 20:03:40 +00:00
|
|
|
|
2012-07-16 16:16:05 +00:00
|
|
|
WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL);
|
2010-06-07 20:03:40 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NODE_OT_hide_socket_toggle(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Toggle Hidden Node Sockets";
|
|
|
|
ot->description = "Toggle unused node socket display";
|
|
|
|
ot->idname = "NODE_OT_hide_socket_toggle";
|
2010-06-07 20:03:40 +00:00
|
|
|
|
|
|
|
/* callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = node_socket_toggle_exec;
|
|
|
|
ot->poll = ED_operator_node_active;
|
2010-06-07 20:03:40 +00:00
|
|
|
|
2009-11-20 06:31:49 +00:00
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2009-11-20 06:31:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ****************** Mute operator *********************** */
|
|
|
|
|
2010-10-15 01:36:14 +00:00
|
|
|
static int node_mute_exec(bContext *C, wmOperator *UNUSED(op))
|
2009-11-20 06:31:49 +00:00
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2009-11-20 06:31:49 +00:00
|
|
|
bNode *node;
|
|
|
|
|
2010-07-04 19:58:52 +00:00
|
|
|
ED_preview_kill_jobs(C);
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = snode->edittree->nodes.first; node; node = node->next) {
|
2011-11-20 16:38:23 +00:00
|
|
|
/* Only allow muting of nodes having a mute func! */
|
2012-02-27 17:38:16 +00:00
|
|
|
if ((node->flag & SELECT) && node->typeinfo->internal_connect) {
|
|
|
|
node->flag ^= NODE_MUTED;
|
|
|
|
snode_update(snode, node);
|
2009-11-20 06:31:49 +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);
|
2009-11-20 06:31:49 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
2010-06-07 20:03:40 +00:00
|
|
|
void NODE_OT_mute_toggle(wmOperatorType *ot)
|
2009-11-20 06:31:49 +00:00
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Toggle Node Mute";
|
|
|
|
ot->description = "Toggle muting of the nodes";
|
|
|
|
ot->idname = "NODE_OT_mute_toggle";
|
2009-11-20 06:31:49 +00:00
|
|
|
|
|
|
|
/* callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = node_mute_exec;
|
|
|
|
ot->poll = ED_operator_node_active;
|
2009-11-20 06:31:49 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2009-11-20 06:31:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ****************** Delete operator ******************* */
|
|
|
|
|
2010-10-15 01:36:14 +00:00
|
|
|
static int node_delete_exec(bContext *C, wmOperator *UNUSED(op))
|
2009-11-20 06:31:49 +00:00
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2009-11-20 06:31:49 +00:00
|
|
|
bNode *node, *next;
|
|
|
|
|
2010-07-04 19:58:52 +00:00
|
|
|
ED_preview_kill_jobs(C);
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = snode->edittree->nodes.first; node; node = next) {
|
|
|
|
next = node->next;
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->flag & SELECT) {
|
2009-11-20 06:31:49 +00:00
|
|
|
/* check id user here, nodeFreeNode is called for free dbase too */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->id)
|
2009-11-20 06:31:49 +00:00
|
|
|
node->id->us--;
|
|
|
|
nodeFreeNode(snode->edittree, node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
ntreeUpdateTree(snode->edittree);
|
2009-11-20 06:31:49 +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);
|
2009-11-20 06:31:49 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NODE_OT_delete(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Delete";
|
2010-02-10 21:15:44 +00:00
|
|
|
ot->description = "Delete selected nodes";
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->idname = "NODE_OT_delete";
|
2009-11-20 06:31:49 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = node_delete_exec;
|
|
|
|
ot->poll = ED_operator_node_active;
|
2009-11-20 06:31:49 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2009-11-20 06:31:49 +00:00
|
|
|
}
|
|
|
|
|
2011-07-12 18:59:54 +00:00
|
|
|
/* ****************** Delete with reconnect ******************* */
|
|
|
|
static int node_delete_reconnect_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2011-07-12 18:59:54 +00:00
|
|
|
bNode *node, *next;
|
|
|
|
|
|
|
|
ED_preview_kill_jobs(C);
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = snode->edittree->nodes.first; node; node = next) {
|
|
|
|
next = node->next;
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->flag & SELECT) {
|
2012-02-27 17:38:16 +00:00
|
|
|
nodeInternalRelink(snode->edittree, node);
|
|
|
|
|
|
|
|
/* check id user here, nodeFreeNode is called for free dbase too */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->id)
|
2012-02-27 17:38:16 +00:00
|
|
|
node->id->us--;
|
|
|
|
nodeFreeNode(snode->edittree, node);
|
2011-07-12 18:59:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
ntreeUpdateTree(snode->edittree);
|
2011-07-12 18:59:54 +00:00
|
|
|
|
|
|
|
snode_notify(C, snode);
|
|
|
|
snode_dag_update(C, snode);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NODE_OT_delete_reconnect(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Delete with reconnect";
|
2011-07-12 18:59:54 +00:00
|
|
|
ot->description = "Delete nodes; will reconnect nodes as if deletion was muted";
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->idname = "NODE_OT_delete_reconnect";
|
2011-07-12 18:59:54 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = node_delete_reconnect_exec;
|
|
|
|
ot->poll = ED_operator_node_active;
|
2011-07-12 18:59:54 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2011-07-12 18:59:54 +00:00
|
|
|
}
|
|
|
|
|
2009-11-20 21:17:17 +00:00
|
|
|
/* ****************** Show Cyclic Dependencies Operator ******************* */
|
|
|
|
|
2010-10-15 01:36:14 +00:00
|
|
|
static int node_show_cycles_exec(bContext *C, wmOperator *UNUSED(op))
|
2009-11-20 21:17:17 +00:00
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2009-11-20 21:17:17 +00:00
|
|
|
|
|
|
|
/* this is just a wrapper around this call... */
|
2011-09-05 21:01:50 +00:00
|
|
|
ntreeUpdateTree(snode->nodetree);
|
2010-01-21 01:42:28 +00:00
|
|
|
snode_notify(C, snode);
|
2009-11-20 21:17:17 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NODE_OT_show_cyclic_dependencies(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Show Cyclic Dependencies";
|
|
|
|
ot->description = "Sort the nodes and show the cyclic dependencies between the nodes";
|
|
|
|
ot->idname = "NODE_OT_show_cyclic_dependencies";
|
2009-11-20 21:17:17 +00:00
|
|
|
|
|
|
|
/* callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = node_show_cycles_exec;
|
|
|
|
ot->poll = ED_operator_node_active;
|
2009-11-20 21:17:17 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2009-11-20 21:17:17 +00:00
|
|
|
}
|
2009-11-20 06:31:49 +00:00
|
|
|
|
2010-05-12 04:25:33 +00:00
|
|
|
/* ****************** Add File Node Operator ******************* */
|
|
|
|
|
|
|
|
static int node_add_file_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2010-05-12 04:25:33 +00:00
|
|
|
bNode *node;
|
2012-06-21 13:19:19 +00:00
|
|
|
Image *ima = NULL;
|
2011-09-05 21:01:50 +00:00
|
|
|
bNodeTemplate ntemp;
|
|
|
|
|
2010-05-12 04:25:33 +00:00
|
|
|
/* check input variables */
|
2012-03-06 18:40:15 +00:00
|
|
|
if (RNA_struct_property_is_set(op->ptr, "filepath")) {
|
2010-05-12 04:25:33 +00:00
|
|
|
char path[FILE_MAX];
|
2010-06-14 03:52:10 +00:00
|
|
|
RNA_string_get(op->ptr, "filepath", path);
|
2010-07-03 17:47:06 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
errno = 0;
|
2010-07-03 17:47:06 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
ima = BKE_image_load_exists(path);
|
2010-07-03 17:47:06 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!ima) {
|
2012-07-27 13:57:03 +00:00
|
|
|
BKE_reportf(op->reports, RPT_ERROR, "Can't read image: \"%s\", %s", path, errno ? strerror(errno) : "Unsupported format");
|
2010-07-03 17:47:06 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
2010-05-12 04:25:33 +00:00
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (RNA_struct_property_is_set(op->ptr, "name")) {
|
2012-06-21 13:19:19 +00:00
|
|
|
char name[MAX_ID_NAME - 2];
|
2010-05-12 04:25:33 +00:00
|
|
|
RNA_string_get(op->ptr, "name", name);
|
2012-06-21 13:19:19 +00:00
|
|
|
ima = (Image *)BKE_libblock_find_name(ID_IM, name);
|
2010-07-03 17:47:06 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!ima) {
|
2011-09-19 12:26:20 +00:00
|
|
|
BKE_reportf(op->reports, RPT_ERROR, "Image named \"%s\", not found", name);
|
2010-07-03 17:47:06 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
2010-05-12 04:25:33 +00:00
|
|
|
}
|
|
|
|
|
2011-12-18 12:51:50 +00:00
|
|
|
node_deselect_all(snode);
|
2010-05-12 04:25:33 +00:00
|
|
|
|
2012-03-18 15:12:11 +00:00
|
|
|
switch (snode->nodetree->type) {
|
|
|
|
case NTREE_SHADER:
|
|
|
|
ntemp.type = SH_NODE_TEX_IMAGE;
|
|
|
|
break;
|
|
|
|
case NTREE_TEXTURE:
|
|
|
|
ntemp.type = TEX_NODE_IMAGE;
|
|
|
|
break;
|
|
|
|
case NTREE_COMPOSIT:
|
|
|
|
ntemp.type = CMP_NODE_IMAGE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
2010-07-04 19:58:52 +00:00
|
|
|
ED_preview_kill_jobs(C);
|
2010-05-12 04:25:33 +00:00
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
node = node_add_node(snode, bmain, scene, &ntemp, snode->mx, snode->my);
|
2010-05-12 04:25:33 +00:00
|
|
|
|
|
|
|
if (!node) {
|
2011-09-19 12:26:20 +00:00
|
|
|
BKE_report(op->reports, RPT_WARNING, "Could not add an image node");
|
2010-05-12 04:25:33 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
node->id = (ID *)ima;
|
2012-07-27 13:57:03 +00:00
|
|
|
id_us_plus(node->id);
|
2010-05-12 04:25:33 +00:00
|
|
|
|
|
|
|
snode_notify(C, snode);
|
2011-05-02 12:31:09 +00:00
|
|
|
snode_dag_update(C, snode);
|
2010-05-12 04:25:33 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int node_add_file_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
ARegion *ar = CTX_wm_region(C);
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2010-05-12 04:25:33 +00:00
|
|
|
|
|
|
|
/* convert mouse coordinates to v2d space */
|
2011-05-20 07:40:05 +00:00
|
|
|
UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1],
|
2012-06-21 13:19:19 +00:00
|
|
|
&snode->mx, &snode->my);
|
2010-05-12 04:25:33 +00:00
|
|
|
|
2012-01-11 16:32:12 +00:00
|
|
|
if (RNA_struct_property_is_set(op->ptr, "filepath") || RNA_struct_property_is_set(op->ptr, "name"))
|
2010-05-12 04:25:33 +00:00
|
|
|
return node_add_file_exec(C, op);
|
|
|
|
else
|
|
|
|
return WM_operator_filesel(C, op, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NODE_OT_add_file(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Add File Node";
|
|
|
|
ot->description = "Add a file node to the current node editor";
|
|
|
|
ot->idname = "NODE_OT_add_file";
|
2010-05-12 04:25:33 +00:00
|
|
|
|
|
|
|
/* callbacks */
|
2012-03-24 07:36:32 +00:00
|
|
|
ot->exec = node_add_file_exec;
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->invoke = node_add_file_invoke;
|
2012-03-24 07:36:32 +00:00
|
|
|
ot->poll = ED_operator_node_active;
|
2010-05-12 04:25:33 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2010-05-12 04:25:33 +00:00
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
WM_operator_properties_filesel(ot, FOLDERFILE | IMAGEFILE, FILE_SPECIAL, FILE_OPENFILE, WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY); //XXX TODO, relative_path
|
|
|
|
RNA_def_string(ot->srna, "name", "Image", MAX_ID_NAME - 2, "Name", "Datablock name to assign");
|
2010-05-12 04:25:33 +00:00
|
|
|
}
|
2009-01-12 00:14:37 +00:00
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
/********************** New node tree operator *********************/
|
2011-07-22 15:28:50 +00:00
|
|
|
|
2011-09-05 21:01:50 +00:00
|
|
|
static int new_node_tree_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
|
|
|
SpaceNode *snode;
|
|
|
|
bNodeTree *ntree;
|
|
|
|
PointerRNA ptr, idptr;
|
|
|
|
PropertyRNA *prop;
|
|
|
|
int treetype;
|
2012-06-21 13:19:19 +00:00
|
|
|
char treename[MAX_ID_NAME - 2] = "NodeTree";
|
2011-09-05 21:01:50 +00:00
|
|
|
|
|
|
|
/* retrieve state */
|
2012-06-21 13:19:19 +00:00
|
|
|
snode = CTX_wm_space_node(C);
|
2011-09-05 21:01:50 +00:00
|
|
|
|
2012-01-11 16:32:12 +00:00
|
|
|
if (RNA_struct_property_is_set(op->ptr, "type"))
|
2011-09-05 21:01:50 +00:00
|
|
|
treetype = RNA_enum_get(op->ptr, "type");
|
|
|
|
else
|
|
|
|
treetype = snode->treetype;
|
|
|
|
|
2012-01-11 16:32:12 +00:00
|
|
|
if (RNA_struct_property_is_set(op->ptr, "name"))
|
2011-09-05 21:01:50 +00:00
|
|
|
RNA_string_get(op->ptr, "name", treename);
|
|
|
|
|
|
|
|
ntree = ntreeAddTree(treename, treetype, 0);
|
2012-03-24 06:38:07 +00:00
|
|
|
if (!ntree)
|
2011-09-05 21:01:50 +00:00
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
|
|
|
/* hook into UI */
|
|
|
|
uiIDContextProperty(C, &ptr, &prop);
|
2011-07-22 15:28:50 +00:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (prop) {
|
2011-09-05 21:01:50 +00:00
|
|
|
RNA_id_pointer_create(&ntree->id, &idptr);
|
|
|
|
RNA_property_pointer_set(&ptr, prop, idptr);
|
|
|
|
/* RNA_property_pointer_set increases the user count,
|
|
|
|
* fixed here as the editor is the initial user.
|
|
|
|
*/
|
|
|
|
--ntree->id.us;
|
|
|
|
RNA_property_update(C, &ptr, prop);
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (snode) {
|
2012-06-21 13:19:19 +00:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
2011-09-05 21:01:50 +00:00
|
|
|
snode->nodetree = ntree;
|
|
|
|
|
|
|
|
ED_node_tree_update(snode, scene);
|
|
|
|
}
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NODE_OT_new_node_tree(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-05-05 17:10:51 +00:00
|
|
|
ot->name = "New Node Tree";
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->idname = "NODE_OT_new_node_tree";
|
2012-05-05 17:10:51 +00:00
|
|
|
ot->description = "Create a new node tree";
|
2011-09-05 21:01:50 +00:00
|
|
|
|
|
|
|
/* api callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = new_node_tree_exec;
|
|
|
|
ot->poll = ED_operator_node_active;
|
2011-09-05 21:01:50 +00:00
|
|
|
|
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2011-09-05 21:01:50 +00:00
|
|
|
|
|
|
|
RNA_def_enum(ot->srna, "type", nodetree_type_items, NTREE_COMPOSIT, "Tree Type", "");
|
2012-06-21 13:19:19 +00:00
|
|
|
RNA_def_string(ot->srna, "name", "NodeTree", MAX_ID_NAME - 2, "Name", "");
|
2011-09-05 21:01:50 +00:00
|
|
|
}
|
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
|
|
|
|
2012-03-01 07:56:15 +00:00
|
|
|
/* ****************** File Output Add Socket ******************* */
|
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
|
|
|
|
2012-03-01 07:56:15 +00:00
|
|
|
static int node_output_file_add_socket_exec(bContext *C, wmOperator *op)
|
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
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2012-05-02 07:18:51 +00:00
|
|
|
PointerRNA ptr;
|
|
|
|
bNodeTree *ntree;
|
|
|
|
bNode *node;
|
2012-03-01 07:56:15 +00:00
|
|
|
char file_path[MAX_NAME];
|
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
|
|
|
|
2012-05-02 07:18:51 +00:00
|
|
|
ptr = CTX_data_pointer_get(C, "node");
|
|
|
|
if (!ptr.data)
|
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
|
|
|
return OPERATOR_CANCELLED;
|
2012-05-02 07:18:51 +00:00
|
|
|
node = ptr.data;
|
|
|
|
ntree = ptr.id.data;
|
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
|
|
|
|
2012-03-01 07:56:15 +00:00
|
|
|
RNA_string_get(op->ptr, "file_path", file_path);
|
|
|
|
ntreeCompositOutputFileAddSocket(ntree, node, file_path, &scene->r.im_format);
|
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
|
|
|
|
|
|
|
snode_notify(C, snode);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
2012-03-01 07:56:15 +00:00
|
|
|
void NODE_OT_output_file_add_socket(wmOperatorType *ot)
|
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
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Add File Node Socket";
|
|
|
|
ot->description = "Add a new input to a file output node";
|
|
|
|
ot->idname = "NODE_OT_output_file_add_socket";
|
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
|
|
|
|
|
|
|
/* callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = node_output_file_add_socket_exec;
|
|
|
|
ot->poll = composite_node_active;
|
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
|
|
|
|
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2012-03-01 07:56:15 +00:00
|
|
|
|
|
|
|
RNA_def_string(ot->srna, "file_path", "Image", MAX_NAME, "File Path", "Sub-path of the output file");
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/* ****************** Multi File Output Remove Socket ******************* */
|
|
|
|
|
2012-03-01 07:56:15 +00:00
|
|
|
static int node_output_file_remove_active_socket_exec(bContext *C, wmOperator *UNUSED(op))
|
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
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2012-05-02 07:18:51 +00:00
|
|
|
PointerRNA ptr = CTX_data_pointer_get(C, "node");
|
|
|
|
bNodeTree *ntree;
|
|
|
|
bNode *node;
|
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
|
|
|
|
2012-05-02 07:18:51 +00:00
|
|
|
if (!ptr.data)
|
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
|
|
|
return OPERATOR_CANCELLED;
|
2012-05-02 07:18:51 +00:00
|
|
|
node = ptr.data;
|
|
|
|
ntree = ptr.id.data;
|
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
|
|
|
|
2012-03-01 07:56:15 +00:00
|
|
|
if (!ntreeCompositOutputFileRemoveActiveSocket(ntree, node))
|
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
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
|
|
|
snode_notify(C, snode);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
2012-03-01 07:56:15 +00:00
|
|
|
void NODE_OT_output_file_remove_active_socket(wmOperatorType *ot)
|
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
|
|
|
{
|
|
|
|
/* identifiers */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->name = "Remove File Node Socket";
|
|
|
|
ot->description = "Remove active input from a file output node";
|
|
|
|
ot->idname = "NODE_OT_output_file_remove_active_socket";
|
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
|
|
|
|
|
|
|
/* callbacks */
|
2012-03-22 07:26:09 +00:00
|
|
|
ot->exec = node_output_file_remove_active_socket_exec;
|
|
|
|
ot->poll = composite_node_active;
|
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
|
|
|
|
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
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
|
|
|
}
|
2012-05-02 07:18:51 +00:00
|
|
|
|
|
|
|
/* ****************** Multi File Output Move Socket ******************* */
|
|
|
|
|
|
|
|
static int node_output_file_move_active_socket_exec(bContext *C, wmOperator *op)
|
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2012-05-02 07:18:51 +00:00
|
|
|
PointerRNA ptr = CTX_data_pointer_get(C, "node");
|
|
|
|
bNode *node;
|
|
|
|
NodeImageMultiFile *nimf;
|
|
|
|
bNodeSocket *sock;
|
|
|
|
int direction;
|
|
|
|
|
|
|
|
if (!ptr.data)
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
node = ptr.data;
|
|
|
|
nimf = node->storage;
|
|
|
|
|
|
|
|
sock = BLI_findlink(&node->inputs, nimf->active_input);
|
|
|
|
if (!sock)
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
|
|
|
direction = RNA_enum_get(op->ptr, "direction");
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
if (direction == 1) {
|
2012-05-02 07:18:51 +00:00
|
|
|
bNodeSocket *before = sock->prev;
|
|
|
|
if (!before)
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
BLI_remlink(&node->inputs, sock);
|
|
|
|
BLI_insertlinkbefore(&node->inputs, before, sock);
|
|
|
|
--nimf->active_input;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bNodeSocket *after = sock->next;
|
|
|
|
if (!after)
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
BLI_remlink(&node->inputs, sock);
|
|
|
|
BLI_insertlinkafter(&node->inputs, after, sock);
|
|
|
|
++nimf->active_input;
|
|
|
|
}
|
|
|
|
|
|
|
|
snode_notify(C, snode);
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NODE_OT_output_file_move_active_socket(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
static EnumPropertyItem direction_items[] = {
|
|
|
|
{1, "UP", 0, "Up", ""},
|
2012-05-03 06:57:30 +00:00
|
|
|
{2, "DOWN", 0, "Down", ""},
|
2012-06-21 13:19:19 +00:00
|
|
|
{ 0, NULL, 0, NULL, NULL }
|
|
|
|
};
|
2012-05-02 07:18:51 +00:00
|
|
|
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Move File Node Socket";
|
|
|
|
ot->description = "Move the active input of a file output node up or down the list";
|
|
|
|
ot->idname = "NODE_OT_output_file_move_active_socket";
|
|
|
|
|
|
|
|
/* callbacks */
|
|
|
|
ot->exec = node_output_file_move_active_socket_exec;
|
|
|
|
ot->poll = composite_node_active;
|
|
|
|
|
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2012-05-02 07:18:51 +00:00
|
|
|
|
|
|
|
RNA_def_enum(ot->srna, "direction", direction_items, 2, "Direction", "");
|
|
|
|
}
|
2012-05-22 14:13:33 +00:00
|
|
|
|
|
|
|
/* ****************** Copy Node Color ******************* */
|
|
|
|
|
|
|
|
static int node_copy_color_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
bNodeTree *ntree = snode->edittree;
|
|
|
|
bNode *node, *tnode;
|
|
|
|
|
|
|
|
if (!ntree)
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
node = nodeGetActive(ntree);
|
|
|
|
if (!node)
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (tnode = ntree->nodes.first; tnode; tnode = tnode->next) {
|
2012-05-22 14:13:33 +00:00
|
|
|
if (tnode->flag & NODE_SELECT && tnode != node) {
|
|
|
|
if (node->flag & NODE_CUSTOM_COLOR) {
|
|
|
|
tnode->flag |= NODE_CUSTOM_COLOR;
|
|
|
|
copy_v3_v3(tnode->color, node->color);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
tnode->flag &= ~NODE_CUSTOM_COLOR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ED_node_sort(ntree);
|
2012-06-21 13:19:19 +00:00
|
|
|
WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL);
|
2012-05-22 14:13:33 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NODE_OT_node_copy_color(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Copy Color";
|
|
|
|
ot->description = "Copy color to all selected nodes";
|
|
|
|
ot->idname = "NODE_OT_node_copy_color";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = node_copy_color_exec;
|
|
|
|
ot->poll = ED_operator_node_active;
|
|
|
|
|
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2012-05-22 14:13:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ****************** Set Parent ******************* */
|
|
|
|
|
|
|
|
static int node_parent_set_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
bNodeTree *ntree = snode->edittree;
|
|
|
|
bNode *frame = nodeGetActive(ntree), *node;
|
|
|
|
if (!frame || frame->type != NODE_FRAME)
|
|
|
|
return OPERATOR_CANCELLED;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
2012-05-22 14:13:33 +00:00
|
|
|
if (node == frame)
|
|
|
|
continue;
|
|
|
|
if (node->flag & NODE_SELECT) {
|
|
|
|
nodeDetachNode(node);
|
|
|
|
nodeAttachNode(node, frame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ED_node_sort(ntree);
|
2012-06-21 13:19:19 +00:00
|
|
|
WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL);
|
2012-05-22 14:13:33 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NODE_OT_parent_set(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Make Parent";
|
|
|
|
ot->description = "Attach selected nodes";
|
|
|
|
ot->idname = "NODE_OT_parent_set";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = node_parent_set_exec;
|
|
|
|
ot->poll = ED_operator_node_active;
|
|
|
|
|
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2012-05-22 14:13:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ****************** Clear Parent ******************* */
|
|
|
|
|
|
|
|
static int node_parent_clear_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
bNodeTree *ntree = snode->edittree;
|
|
|
|
bNode *node;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
2012-05-22 14:13:33 +00:00
|
|
|
if (node->flag & NODE_SELECT) {
|
|
|
|
nodeDetachNode(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL);
|
2012-05-22 14:13:33 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NODE_OT_parent_clear(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Clear Parent";
|
|
|
|
ot->description = "Detach selected nodes";
|
|
|
|
ot->idname = "NODE_OT_parent_clear";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = node_parent_clear_exec;
|
|
|
|
ot->poll = ED_operator_node_active;
|
|
|
|
|
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2012-05-22 14:13:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ****************** Join Nodes ******************* */
|
|
|
|
|
|
|
|
/* tags for depth-first search */
|
2012-06-21 13:19:19 +00:00
|
|
|
#define NODE_JOIN_DONE 1
|
|
|
|
#define NODE_JOIN_IS_DESCENDANT 2
|
2012-05-22 14:13:33 +00:00
|
|
|
|
|
|
|
static void node_join_attach_recursive(bNode *node, bNode *frame)
|
|
|
|
{
|
|
|
|
node->done |= NODE_JOIN_DONE;
|
|
|
|
|
|
|
|
if (node == frame) {
|
|
|
|
node->done |= NODE_JOIN_IS_DESCENDANT;
|
|
|
|
}
|
|
|
|
else if (node->parent) {
|
|
|
|
/* call recursively */
|
|
|
|
if (!(node->parent->done & NODE_JOIN_DONE))
|
|
|
|
node_join_attach_recursive(node->parent, frame);
|
|
|
|
|
|
|
|
/* in any case: if the parent is a descendant, so is the child */
|
|
|
|
if (node->parent->done & NODE_JOIN_IS_DESCENDANT)
|
|
|
|
node->done |= NODE_JOIN_IS_DESCENDANT;
|
|
|
|
else if (node->flag & NODE_TEST) {
|
|
|
|
/* if parent is not an decendant of the frame, reattach the node */
|
|
|
|
nodeDetachNode(node);
|
|
|
|
nodeAttachNode(node, frame);
|
|
|
|
node->done |= NODE_JOIN_IS_DESCENDANT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (node->flag & NODE_TEST) {
|
|
|
|
nodeAttachNode(node, frame);
|
|
|
|
node->done |= NODE_JOIN_IS_DESCENDANT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int node_join_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
bNodeTree *ntree = snode->edittree;
|
|
|
|
bNode *node, *frame;
|
|
|
|
bNodeTemplate ntemp;
|
|
|
|
|
|
|
|
/* XXX save selection: node_add_node call below sets the new frame as single active+selected node */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
2012-05-22 14:13:33 +00:00
|
|
|
if (node->flag & NODE_SELECT)
|
|
|
|
node->flag |= NODE_TEST;
|
|
|
|
else
|
|
|
|
node->flag &= ~NODE_TEST;
|
|
|
|
}
|
|
|
|
|
|
|
|
ntemp.main = bmain;
|
|
|
|
ntemp.scene = scene;
|
|
|
|
ntemp.type = NODE_FRAME;
|
|
|
|
frame = node_add_node(snode, bmain, scene, &ntemp, 0.0f, 0.0f);
|
|
|
|
|
|
|
|
/* reset tags */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = ntree->nodes.first; node; node = node->next)
|
2012-05-22 14:13:33 +00:00
|
|
|
node->done = 0;
|
|
|
|
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
2012-05-22 14:13:33 +00:00
|
|
|
if (!(node->done & NODE_JOIN_DONE))
|
|
|
|
node_join_attach_recursive(node, frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* restore selection */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
2012-05-22 14:13:33 +00:00
|
|
|
if (node->flag & NODE_TEST)
|
|
|
|
node->flag |= NODE_SELECT;
|
|
|
|
}
|
|
|
|
|
|
|
|
ED_node_sort(ntree);
|
2012-06-21 13:19:19 +00:00
|
|
|
WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL);
|
2012-05-22 14:13:33 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NODE_OT_join(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Join Nodes";
|
2012-05-28 14:01:42 +00:00
|
|
|
ot->description = "Attach selected nodes to a new common frame";
|
2012-05-22 14:13:33 +00:00
|
|
|
ot->idname = "NODE_OT_join";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = node_join_exec;
|
|
|
|
ot->poll = ED_operator_node_active;
|
|
|
|
|
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2012-05-22 14:13:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ****************** Attach ******************* */
|
|
|
|
|
|
|
|
static int node_attach_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
bNodeTree *ntree = snode->edittree;
|
|
|
|
bNode *frame;
|
|
|
|
|
|
|
|
/* check nodes front to back */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (frame = ntree->nodes.last; frame; frame = frame->prev) {
|
2012-05-22 14:13:33 +00:00
|
|
|
/* skip selected, those are the nodes we want to attach */
|
|
|
|
if ((frame->type != NODE_FRAME) || (frame->flag & NODE_SELECT))
|
|
|
|
continue;
|
|
|
|
if (BLI_in_rctf(&frame->totr, snode->mx, snode->my))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (frame) {
|
|
|
|
bNode *node, *parent;
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = ntree->nodes.last; node; node = node->prev) {
|
2012-05-22 14:13:33 +00:00
|
|
|
if (node->flag & NODE_SELECT) {
|
|
|
|
if (node->parent == NULL) {
|
|
|
|
/* attach all unparented nodes */
|
|
|
|
nodeAttachNode(node, frame);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* attach nodes which share parent with the frame */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (parent = frame->parent; parent; parent = parent->parent)
|
2012-05-22 14:13:33 +00:00
|
|
|
if (parent == node->parent)
|
|
|
|
break;
|
|
|
|
if (parent) {
|
|
|
|
nodeDetachNode(node);
|
|
|
|
nodeAttachNode(node, frame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ED_node_sort(ntree);
|
2012-06-21 13:19:19 +00:00
|
|
|
WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL);
|
2012-05-22 14:13:33 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int node_attach_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
|
|
|
{
|
2012-06-21 13:19:19 +00:00
|
|
|
ARegion *ar = CTX_wm_region(C);
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
2012-05-22 14:13:33 +00:00
|
|
|
|
|
|
|
/* convert mouse coordinates to v2d space */
|
|
|
|
UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &snode->mx, &snode->my);
|
|
|
|
|
|
|
|
return node_attach_exec(C, op);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NODE_OT_attach(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Attach Nodes";
|
2012-05-28 14:01:42 +00:00
|
|
|
ot->description = "Attach active node to a frame";
|
2012-05-22 14:13:33 +00:00
|
|
|
ot->idname = "NODE_OT_attach";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = node_attach_exec;
|
|
|
|
ot->invoke = node_attach_invoke;
|
|
|
|
ot->poll = ED_operator_node_active;
|
|
|
|
|
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2012-05-22 14:13:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ****************** Detach ******************* */
|
|
|
|
|
|
|
|
/* tags for depth-first search */
|
2012-06-21 13:19:19 +00:00
|
|
|
#define NODE_DETACH_DONE 1
|
|
|
|
#define NODE_DETACH_IS_DESCENDANT 2
|
2012-05-22 14:13:33 +00:00
|
|
|
|
|
|
|
static void node_detach_recursive(bNode *node)
|
|
|
|
{
|
|
|
|
node->done |= NODE_DETACH_DONE;
|
|
|
|
|
|
|
|
if (node->parent) {
|
|
|
|
/* call recursively */
|
|
|
|
if (!(node->parent->done & NODE_DETACH_DONE))
|
|
|
|
node_detach_recursive(node->parent);
|
|
|
|
|
|
|
|
/* in any case: if the parent is a descendant, so is the child */
|
|
|
|
if (node->parent->done & NODE_DETACH_IS_DESCENDANT)
|
|
|
|
node->done |= NODE_DETACH_IS_DESCENDANT;
|
|
|
|
else if (node->flag & NODE_SELECT) {
|
|
|
|
/* if parent is not a decendant of a selected node, detach */
|
|
|
|
nodeDetachNode(node);
|
|
|
|
node->done |= NODE_DETACH_IS_DESCENDANT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (node->flag & NODE_SELECT) {
|
|
|
|
node->done |= NODE_DETACH_IS_DESCENDANT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* detach the root nodes in the current selection */
|
|
|
|
static int node_detach_exec(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
{
|
|
|
|
SpaceNode *snode = CTX_wm_space_node(C);
|
|
|
|
bNodeTree *ntree = snode->edittree;
|
|
|
|
bNode *node;
|
|
|
|
|
|
|
|
/* reset tags */
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = ntree->nodes.first; node; node = node->next)
|
2012-05-22 14:13:33 +00:00
|
|
|
node->done = 0;
|
|
|
|
/* detach nodes recursively
|
|
|
|
* relative order is preserved here!
|
|
|
|
*/
|
2012-06-21 13:19:19 +00:00
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
2012-05-22 14:13:33 +00:00
|
|
|
if (!(node->done & NODE_DETACH_DONE))
|
|
|
|
node_detach_recursive(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
ED_node_sort(ntree);
|
2012-06-21 13:19:19 +00:00
|
|
|
WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, NULL);
|
2012-05-22 14:13:33 +00:00
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NODE_OT_detach(wmOperatorType *ot)
|
|
|
|
{
|
|
|
|
/* identifiers */
|
|
|
|
ot->name = "Detach Nodes";
|
2012-05-28 14:01:42 +00:00
|
|
|
ot->description = "Detach selected nodes from parents";
|
2012-05-22 14:13:33 +00:00
|
|
|
ot->idname = "NODE_OT_detach";
|
|
|
|
|
|
|
|
/* api callbacks */
|
|
|
|
ot->exec = node_detach_exec;
|
|
|
|
ot->poll = ED_operator_node_active;
|
|
|
|
|
|
|
|
/* flags */
|
2012-06-21 13:19:19 +00:00
|
|
|
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
2012-05-22 14:13:33 +00:00
|
|
|
}
|