Node Editor - More Cleanups (Reshuffling):

- removing duplicate chunks of code -> hide unused sockets now works
- moving some functions to the files that they get called from -> view all/home
- made duplicate a macro operator like the other places that work like this, eliminating the unnecessary transform-related property there still
- removed a few chunks of unused code
This commit is contained in:
2009-11-20 21:04:41 +00:00
parent acf0fbbf70
commit 03cfcc6007
9 changed files with 136 additions and 269 deletions

View File

@@ -111,7 +111,7 @@ class NODE_MT_node(bpy.types.Menu):
layout.itemS()
layout.itemO("node.duplicate")
layout.itemO("node.duplicate_move", text="Duplicate")
layout.itemO("node.delete")
layout.itemS()

View File

@@ -44,7 +44,10 @@ void ED_node_changed_update(struct ID *id, struct bNode *node);
/* node_edit.c */
void ED_node_shader_default(struct Material *ma);
void ED_node_composit_default(struct Scene *sce);
void ED_node_texture_default(struct Tex *tex);;
void ED_node_texture_default(struct Tex *tex);
/* node ops.c */
void ED_operatormacros_node(void);
#endif /* ED_NODE_H */

View File

@@ -45,6 +45,7 @@
#include "ED_gpencil.h"
#include "ED_markers.h"
#include "ED_mesh.h"
#include "ED_node.h"
#include "ED_object.h"
#include "ED_physics.h"
#include "ED_render.h"
@@ -111,6 +112,7 @@ void ED_spacetypes_init(void)
* maybe we'll need to have them go after python operators too? */
ED_operatormacros_armature();
ED_operatormacros_mesh();
ED_operatormacros_node();
ED_operatormacros_object();
}

View File

@@ -1031,6 +1031,7 @@ static void node_draw_group(const bContext *C, ARegion *ar, SpaceNode *snode, bN
else
strcpy(showname, ngroup->id.name+2);
// XXX this shows some scaling artifacts
UI_DrawString(rect.xmin+8.0f, rect.ymax+5.0f, showname);
/* links from groupsockets to the internal nodes */

View File

@@ -762,6 +762,19 @@ void node_set_active(SpaceNode *snode, bNode *node)
}
}
/* when links in groups change, inputs/outputs change, nodes added/deleted... */
void node_tree_verify_groups(bNodeTree *nodetree)
{
bNode *gnode;
gnode= node_tree_get_editgroup(nodetree);
/* does all materials */
if(gnode)
nodeVerifyGroup((bNodeTree *)gnode->id);
}
/* ***************** Edit Group operator ************* */
void snode_make_group_editable(SpaceNode *snode, bNode *gnode)
@@ -892,81 +905,6 @@ void NODE_OT_group_ungroup(wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
}
/* when links in groups change, inputs/outputs change, nodes added/deleted... */
static void node_tree_verify_groups(bNodeTree *nodetree)
{
bNode *gnode;
gnode= node_tree_get_editgroup(nodetree);
/* does all materials */
if(gnode)
nodeVerifyGroup((bNodeTree *)gnode->id);
}
#if 0
static void node_addgroup(SpaceNode *snode)
{
bNodeTree *ngroup;
int tot= 0, offs, val;
char *strp;
if(snode->edittree!=snode->nodetree) {
error("Can not add a Group in a Group");
return;
}
/* construct menu with choices */
for(ngroup= G.main->nodetree.first; ngroup; ngroup= ngroup->id.next) {
if(ngroup->type==snode->treetype)
tot++;
}
if(tot==0) {
error("No groups available in database");
return;
}
strp= MEM_mallocN(32*tot+32, "menu");
strcpy(strp, "Add Group %t");
offs= strlen(strp);
for(tot=0, ngroup= G.main->nodetree.first; ngroup; ngroup= ngroup->id.next, tot++) {
if(ngroup->type==snode->treetype)
offs+= sprintf(strp+offs, "|%s %%x%d", ngroup->id.name+2, tot);
}
val= pupmenu(strp);
if(val>=0) {
ngroup= BLI_findlink(&G.main->nodetree, val);
if(ngroup) {
bNode *node= nodeAddNodeType(snode->edittree, NODE_GROUP, ngroup, NULL);
/* generics */
if(node) {
float locx, locy;
short mval[2];
node_deselectall(snode, 0);
getmouseco_areawin(mval);
areamouseco_to_ipoco(G.v2d, mval, &locx, &locy);
node->locx= locx;
node->locy= locy + 60.0f; // arbitrary.. so its visible
node->flag |= SELECT;
id_us_plus(node->id);
node_set_active(snode, node);
}
}
}
MEM_freeN(strp);
}
#endif /* 0 */
/* ************************** Node generic ************** */
/* allows to walk the list in order of visibility */
@@ -1035,56 +973,6 @@ static bNode *visible_node(SpaceNode *snode, rctf *rct)
return tnode;
}
void snode_home(ScrArea *sa, ARegion *ar, SpaceNode* snode)
{
bNode *node;
rctf *cur, *tot;
float oldwidth, oldheight, width, height;
int first= 1;
cur= &ar->v2d.cur;
tot= &ar->v2d.tot;
oldwidth= cur->xmax - cur->xmin;
oldheight= cur->ymax - cur->ymin;
cur->xmin= cur->ymin= 0.0f;
cur->xmax=ar->winx;
cur->xmax= ar->winy;
if(snode->edittree) {
for(node= snode->edittree->nodes.first; node; node= node->next) {
if(first) {
first= 0;
ar->v2d.cur= node->totr;
}
else {
BLI_union_rctf(cur, &node->totr);
}
}
}
snode->xof= 0;
snode->yof= 0;
width= cur->xmax - cur->xmin;
height= cur->ymax- cur->ymin;
if(width > height) {
float newheight;
newheight= oldheight * width/oldwidth;
cur->ymin= cur->ymin - newheight/4;
cur->ymax= cur->ymin + newheight;
}
else {
float newwidth;
newwidth= oldwidth * height/oldheight;
cur->xmin= cur->xmin - newwidth/4;
cur->xmax= cur->xmin + newwidth;
}
ar->v2d.tot= ar->v2d.cur;
UI_view2d_curRect_validate(&ar->v2d);
}
#if 0
static void snode_bg_viewmove(SpaceNode *snode)
{
@@ -1324,127 +1212,6 @@ int node_has_hidden_sockets(bNode *node)
return 0;
}
static void node_hide_unhide_sockets(SpaceNode *snode, bNode *node)
{
bNodeSocket *sock;
/* unhide all */
if( node_has_hidden_sockets(node) ) {
for(sock= node->inputs.first; sock; sock= sock->next)
sock->flag &= ~SOCK_HIDDEN;
for(sock= node->outputs.first; sock; sock= sock->next)
sock->flag &= ~SOCK_HIDDEN;
}
else {
bNode *gnode= node_tree_get_editgroup(snode->nodetree);
/* hiding inside group should not break links in other group users */
if(gnode) {
nodeGroupSocketUseFlags((bNodeTree *)gnode->id);
for(sock= node->inputs.first; sock; sock= sock->next)
if(!(sock->flag & SOCK_IN_USE))
if(sock->link==NULL)
sock->flag |= SOCK_HIDDEN;
for(sock= node->outputs.first; sock; sock= sock->next)
if(!(sock->flag & SOCK_IN_USE))
if(nodeCountSocketLinks(snode->edittree, sock)==0)
sock->flag |= SOCK_HIDDEN;
}
else {
/* hide unused sockets */
for(sock= node->inputs.first; sock; sock= sock->next) {
if(sock->link==NULL)
sock->flag |= SOCK_HIDDEN;
}
for(sock= node->outputs.first; sock; sock= sock->next) {
if(nodeCountSocketLinks(snode->edittree, sock)==0)
sock->flag |= SOCK_HIDDEN;
}
}
}
// allqueue(REDRAWNODE, 1);
node_tree_verify_groups(snode->nodetree);
}
// XXX duplicate function
/*static*/ int do_header_node(SpaceNode *snode, bNode *node, float mx, float my)
{
rctf totr= node->totr;
totr.ymin= totr.ymax-20.0f;
totr.xmax= totr.xmin+15.0f;
if(BLI_in_rctf(&totr, mx, my)) {
node->flag |= NODE_HIDDEN;
// allqueue(REDRAWNODE, 0);
return 1;
}
totr.xmax= node->totr.xmax;
totr.xmin= totr.xmax-18.0f;
if(node->typeinfo->flag & NODE_PREVIEW) {
if(BLI_in_rctf(&totr, mx, my)) {
node->flag ^= NODE_PREVIEW;
// allqueue(REDRAWNODE, 0);
return 1;
}
totr.xmin-=18.0f;
}
if(node->type == NODE_GROUP) {
if(BLI_in_rctf(&totr, mx, my)) {
snode_make_group_editable(snode, node);
return 1;
}
totr.xmin-=18.0f;
}
if(node->typeinfo->flag & NODE_OPTIONS) {
if(BLI_in_rctf(&totr, mx, my)) {
node->flag ^= NODE_OPTIONS;
// allqueue(REDRAWNODE, 0);
return 1;
}
totr.xmin-=18.0f;
}
/* hide unused sockets */
if(BLI_in_rctf(&totr, mx, my)) {
node_hide_unhide_sockets(snode, node);
}
totr= node->totr;
totr.xmin= totr.xmax-10.0f;
totr.ymax= totr.ymin+10.0f;
if(BLI_in_rctf(&totr, mx, my)) {
// scale_node(snode, node);
return 1;
}
return 0;
}
// XXX duplicate function
/*static*/ int do_header_hidden_node(SpaceNode *snode, bNode *node, float mx, float my)
{
rctf totr= node->totr;
totr.xmax= totr.xmin+15.0f;
if(BLI_in_rctf(&totr, mx, my)) {
node->flag &= ~NODE_HIDDEN;
// allqueue(REDRAWNODE, 0);
return 1;
}
totr.xmax= node->totr.xmax;
totr.xmin= node->totr.xmax-15.0f;
if(BLI_in_rctf(&totr, mx, my)) {
// scale_node(snode, node);
return 1;
}
return 0;
}
static void node_link_viewer(SpaceNode *snode, bNode *tonode)
{
bNode *node;
@@ -1738,17 +1505,6 @@ static int node_duplicate_exec(bContext *C, wmOperator *op)
return OPERATOR_FINISHED;
}
static int node_duplicate_invoke(bContext *C, wmOperator *op, wmEvent *event)
{
node_duplicate_exec(C, op);
// todo... remove this - this is for a modal op instead!
RNA_int_set(op->ptr, "mode", TFM_TRANSLATION);
WM_operator_name_call(C, "TFM_OT_transform", WM_OP_INVOKE_REGION_WIN, op->ptr);
return OPERATOR_FINISHED;
}
void NODE_OT_duplicate(wmOperatorType *ot)
{
/* identifiers */
@@ -1757,16 +1513,11 @@ void NODE_OT_duplicate(wmOperatorType *ot)
ot->idname= "NODE_OT_duplicate";
/* api callbacks */
ot->invoke= node_duplicate_invoke;
ot->exec= node_duplicate_exec;
ot->poll= ED_operator_node_active;
/* flags */
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
/* to give to transform */
RNA_def_int(ot->srna, "mode", TFM_TRANSLATION, 0, INT_MAX, "Mode", "", 0, INT_MAX);
}
/* *************************** add link op ******************** */

View File

@@ -76,11 +76,11 @@ bNode *next_node(bNodeTree *ntree);
bNode *node_add_node(SpaceNode *snode, Scene *scene, int type, float locx, float locy);
void snode_set_context(SpaceNode *snode, Scene *scene);
void snode_make_group_editable(SpaceNode *snode, bNode *gnode);
void snode_home(ScrArea *sa, ARegion *ar, SpaceNode *snode);
void node_set_active(SpaceNode *snode, bNode *node);
void node_deselectall(SpaceNode *snode);
void snode_composite_job(const struct bContext *C, ScrArea *sa);
bNode *node_tree_get_editgroup(bNodeTree *ntree);
void node_tree_verify_groups(bNodeTree *nodetree);
void snode_autoconnect(SpaceNode *snode, bNode *node_to, int flag);
void NODE_OT_duplicate(struct wmOperatorType *ot);

View File

@@ -75,6 +75,17 @@ void node_operatortypes(void)
WM_operatortype_append(NODE_OT_group_edit);
}
void ED_operatormacros_node(void)
{
wmOperatorType *ot;
wmOperatorTypeMacro *otmacro;
ot= WM_operatortype_append_macro("NODE_OT_duplicate_move", "Add Duplicate", OPTYPE_UNDO|OPTYPE_REGISTER);
WM_operatortype_macro_define(ot, "NODE_OT_duplicate");
otmacro= WM_operatortype_macro_define(ot, "TFM_OT_translate");
RNA_enum_set(otmacro->ptr, "proportional", 0);
}
void node_keymap(struct wmKeyConfig *keyconf)
{
wmKeyMap *keymap;
@@ -107,7 +118,7 @@ void node_keymap(struct wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "NODE_OT_link_make", FKEY, KM_PRESS, 0, 0);
WM_keymap_add_menu(keymap, "NODE_MT_add", AKEY, KM_PRESS, KM_SHIFT, 0);
WM_keymap_add_item(keymap, "NODE_OT_duplicate", DKEY, KM_PRESS, KM_SHIFT, 0);
WM_keymap_add_item(keymap, "NODE_OT_duplicate_move", DKEY, KM_PRESS, KM_SHIFT, 0);
WM_keymap_add_item(keymap, "NODE_OT_hide", HKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "NODE_OT_mute", MKEY, KM_PRESS, 0, 0);

View File

@@ -56,6 +56,8 @@
#include "node_intern.h"
/* ****** Click Select ****** */
static bNode *node_mouse_select(SpaceNode *snode, ARegion *ar, short *mval, short extend)
{
bNode *node;

View File

@@ -55,7 +55,50 @@
#include "node_intern.h"
// XXX duplicate function
/* **************** Node Header Buttons ************** */
static void node_hide_unhide_sockets(SpaceNode *snode, bNode *node)
{
bNodeSocket *sock;
/* unhide all */
if( node_has_hidden_sockets(node) ) {
for(sock= node->inputs.first; sock; sock= sock->next)
sock->flag &= ~SOCK_HIDDEN;
for(sock= node->outputs.first; sock; sock= sock->next)
sock->flag &= ~SOCK_HIDDEN;
}
else {
bNode *gnode= node_tree_get_editgroup(snode->nodetree);
/* hiding inside group should not break links in other group users */
if(gnode) {
nodeGroupSocketUseFlags((bNodeTree *)gnode->id);
for(sock= node->inputs.first; sock; sock= sock->next)
if(!(sock->flag & SOCK_IN_USE))
if(sock->link==NULL)
sock->flag |= SOCK_HIDDEN;
for(sock= node->outputs.first; sock; sock= sock->next)
if(!(sock->flag & SOCK_IN_USE))
if(nodeCountSocketLinks(snode->edittree, sock)==0)
sock->flag |= SOCK_HIDDEN;
}
else {
/* hide unused sockets */
for(sock= node->inputs.first; sock; sock= sock->next) {
if(sock->link==NULL)
sock->flag |= SOCK_HIDDEN;
}
for(sock= node->outputs.first; sock; sock= sock->next) {
if(nodeCountSocketLinks(snode->edittree, sock)==0)
sock->flag |= SOCK_HIDDEN;
}
}
}
node_tree_verify_groups(snode->nodetree);
}
static int do_header_node(SpaceNode *snode, bNode *node, float mx, float my)
{
rctf totr= node->totr;
@@ -93,13 +136,12 @@ static int do_header_node(SpaceNode *snode, bNode *node, float mx, float my)
}
/* hide unused sockets */
if(BLI_in_rctf(&totr, mx, my)) {
// XXX node_hide_unhide_sockets(snode, node);
node_hide_unhide_sockets(snode, node);
}
return 0;
}
// XXX duplicate function
static int do_header_hidden_node(SpaceNode *snode, bNode *node, float mx, float my)
{
rctf totr= node->totr;
@@ -172,6 +214,7 @@ void NODE_OT_visibility_toggle(wmOperatorType *ot)
/* identifiers */
ot->name= "Toggle Visibility";
ot->idname= "NODE_OT_visibility_toggle";
ot->description= "Handle clicks on node header buttons.";
/* api callbacks */
ot->invoke= node_toggle_visibility_invoke;
@@ -184,13 +227,67 @@ void NODE_OT_visibility_toggle(wmOperatorType *ot)
RNA_def_int(ot->srna, "mouse_y", 0, INT_MIN, INT_MAX, "Mouse Y", "", INT_MIN, INT_MAX);
}
/* **************** View All Operator ************** */
static void snode_home(ScrArea *sa, ARegion *ar, SpaceNode* snode)
{
bNode *node;
rctf *cur, *tot;
float oldwidth, oldheight, width, height;
int first= 1;
cur= &ar->v2d.cur;
tot= &ar->v2d.tot;
oldwidth= cur->xmax - cur->xmin;
oldheight= cur->ymax - cur->ymin;
cur->xmin= cur->ymin= 0.0f;
cur->xmax=ar->winx;
cur->xmax= ar->winy;
if(snode->edittree) {
for(node= snode->edittree->nodes.first; node; node= node->next) {
if(first) {
first= 0;
ar->v2d.cur= node->totr;
}
else {
BLI_union_rctf(cur, &node->totr);
}
}
}
snode->xof= 0;
snode->yof= 0;
width= cur->xmax - cur->xmin;
height= cur->ymax- cur->ymin;
if(width > height) {
float newheight;
newheight= oldheight * width/oldwidth;
cur->ymin= cur->ymin - newheight/4;
cur->ymax= cur->ymin + newheight;
}
else {
float newwidth;
newwidth= oldwidth * height/oldheight;
cur->xmin= cur->xmin - newwidth/4;
cur->xmax= cur->xmin + newwidth;
}
ar->v2d.tot= ar->v2d.cur;
UI_view2d_curRect_validate(&ar->v2d);
}
static int node_view_all_exec(bContext *C, wmOperator *op)
{
ScrArea *sa= CTX_wm_area(C);
ARegion *ar= CTX_wm_region(C);
SpaceNode *snode= CTX_wm_space_node(C);
snode_home(sa, ar, snode);
ED_region_tag_redraw(ar);
return OPERATOR_FINISHED;
}