Cleanup: reduce variable scopes
This commit is contained in:
parent
89ffdad0f3
commit
00ee3960e0
|
@ -138,12 +138,11 @@ static int node_group_edit_exec(bContext *C, wmOperator *op)
|
|||
{
|
||||
SpaceNode *snode = CTX_wm_space_node(C);
|
||||
const char *node_idname = group_node_idname(C);
|
||||
bNode *gnode;
|
||||
const bool exit = RNA_boolean_get(op->ptr, "exit");
|
||||
|
||||
ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
|
||||
|
||||
gnode = node_group_get_active(C, node_idname);
|
||||
bNode *gnode = node_group_get_active(C, node_idname);
|
||||
|
||||
if (gnode && !exit) {
|
||||
bNodeTree *ngroup = (bNodeTree *)gnode->id;
|
||||
|
@ -203,30 +202,24 @@ static void animation_basepath_change_free(AnimationBasePathChange *basepath_cha
|
|||
/* returns 1 if its OK */
|
||||
static int node_group_ungroup(Main *bmain, bNodeTree *ntree, bNode *gnode)
|
||||
{
|
||||
bNodeLink *link, *linkn, *tlink;
|
||||
bNode *node, *nextnode;
|
||||
bNodeTree *ngroup, *wgroup;
|
||||
ListBase anim_basepaths = {NULL, NULL};
|
||||
LinkNode *nodes_delayed_free = NULL;
|
||||
|
||||
ngroup = (bNodeTree *)gnode->id;
|
||||
|
||||
/* clear new pointers, set in copytree */
|
||||
for (node = ntree->nodes.first; node; node = node->next) {
|
||||
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
|
||||
node->new_node = NULL;
|
||||
}
|
||||
|
||||
ListBase anim_basepaths = {NULL, NULL};
|
||||
LinkNode *nodes_delayed_free = NULL;
|
||||
bNodeTree *ngroup = (bNodeTree *)gnode->id;
|
||||
|
||||
/* wgroup is a temporary copy of the NodeTree we're merging in
|
||||
* - all of wgroup's nodes are copied across to their new home
|
||||
* - ngroup (i.e. the source NodeTree) is left unscathed
|
||||
* - temp copy. do change ID usercount for the copies
|
||||
*/
|
||||
wgroup = ntreeCopyTree_ex_new_pointers(ngroup, bmain, true);
|
||||
bNodeTree *wgroup = ntreeCopyTree_ex_new_pointers(ngroup, bmain, true);
|
||||
|
||||
/* Add the nodes into the ntree */
|
||||
for (node = wgroup->nodes.first; node; node = nextnode) {
|
||||
nextnode = node->next;
|
||||
|
||||
LISTBASE_FOREACH_MUTABLE (bNode *, node, &wgroup->nodes) {
|
||||
/* Remove interface nodes.
|
||||
* This also removes remaining links to and from interface nodes.
|
||||
*/
|
||||
|
@ -271,8 +264,7 @@ static int node_group_ungroup(Main *bmain, bNodeTree *ntree, bNode *gnode)
|
|||
bNodeLink *glinks_first = ntree->links.last;
|
||||
|
||||
/* Add internal links to the ntree */
|
||||
for (link = wgroup->links.first; link; link = linkn) {
|
||||
linkn = link->next;
|
||||
LISTBASE_FOREACH_MUTABLE (bNodeLink *, link, &wgroup->links) {
|
||||
BLI_remlink(&wgroup->links, link);
|
||||
BLI_addtail(&ntree->links, link);
|
||||
}
|
||||
|
@ -310,13 +302,14 @@ static int node_group_ungroup(Main *bmain, bNodeTree *ntree, bNode *gnode)
|
|||
|
||||
/* input links */
|
||||
if (glinks_first != NULL) {
|
||||
for (link = glinks_first->next; link != glinks_last->next; link = link->next) {
|
||||
for (bNodeLink *link = glinks_first->next; link != glinks_last->next; link = link->next) {
|
||||
if (link->fromnode->type == NODE_GROUP_INPUT) {
|
||||
const char *identifier = link->fromsock->identifier;
|
||||
int num_external_links = 0;
|
||||
|
||||
/* find external links to this input */
|
||||
for (tlink = ntree->links.first; tlink != glinks_first->next; tlink = tlink->next) {
|
||||
for (bNodeLink *tlink = ntree->links.first; tlink != glinks_first->next;
|
||||
tlink = tlink->next) {
|
||||
if (tlink->tonode == gnode && STREQ(tlink->tosock->identifier, identifier)) {
|
||||
nodeAddLink(ntree, tlink->fromnode, tlink->fromsock, link->tonode, link->tosock);
|
||||
num_external_links++;
|
||||
|
@ -342,13 +335,14 @@ static int node_group_ungroup(Main *bmain, bNodeTree *ntree, bNode *gnode)
|
|||
glinks_last = ntree->links.last;
|
||||
|
||||
/* output links */
|
||||
for (link = ntree->links.first; link != glinks_first->next; link = link->next) {
|
||||
for (bNodeLink *link = ntree->links.first; link != glinks_first->next; link = link->next) {
|
||||
if (link->fromnode == gnode) {
|
||||
const char *identifier = link->fromsock->identifier;
|
||||
int num_internal_links = 0;
|
||||
|
||||
/* find internal links to this output */
|
||||
for (tlink = glinks_first->next; tlink != glinks_last->next; tlink = tlink->next) {
|
||||
for (bNodeLink *tlink = glinks_first->next; tlink != glinks_last->next;
|
||||
tlink = tlink->next) {
|
||||
/* only use active output node */
|
||||
if (tlink->tonode->type == NODE_GROUP_OUTPUT && (tlink->tonode->flag & NODE_DO_OUTPUT)) {
|
||||
if (STREQ(tlink->tosock->identifier, identifier)) {
|
||||
|
@ -374,7 +368,7 @@ static int node_group_ungroup(Main *bmain, bNodeTree *ntree, bNode *gnode)
|
|||
}
|
||||
|
||||
while (nodes_delayed_free) {
|
||||
node = BLI_linklist_pop(&nodes_delayed_free);
|
||||
bNode *node = BLI_linklist_pop(&nodes_delayed_free);
|
||||
nodeRemoveNode(bmain, ntree, node, false);
|
||||
}
|
||||
|
||||
|
@ -391,11 +385,10 @@ static int node_group_ungroup_exec(bContext *C, wmOperator *op)
|
|||
Main *bmain = CTX_data_main(C);
|
||||
SpaceNode *snode = CTX_wm_space_node(C);
|
||||
const char *node_idname = group_node_idname(C);
|
||||
bNode *gnode;
|
||||
|
||||
ED_preview_kill_jobs(CTX_wm_manager(C), bmain);
|
||||
|
||||
gnode = node_group_get_active(C, node_idname);
|
||||
bNode *gnode = node_group_get_active(C, node_idname);
|
||||
if (!gnode) {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
@ -435,23 +428,20 @@ void NODE_OT_group_ungroup(wmOperatorType *ot)
|
|||
static int node_group_separate_selected(
|
||||
Main *bmain, bNodeTree *ntree, bNodeTree *ngroup, float offx, float offy, int make_copy)
|
||||
{
|
||||
bNodeLink *link, *link_next;
|
||||
bNode *node, *node_next, *newnode;
|
||||
ListBase anim_basepaths = {NULL, NULL};
|
||||
|
||||
/* deselect all nodes in the target tree */
|
||||
for (node = ntree->nodes.first; node; node = node->next) {
|
||||
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
|
||||
nodeSetSelected(node, false);
|
||||
}
|
||||
|
||||
/* clear new pointers, set in BKE_node_copy_ex(). */
|
||||
for (node = ngroup->nodes.first; node; node = node->next) {
|
||||
LISTBASE_FOREACH (bNode *, node, &ngroup->nodes) {
|
||||
node->new_node = NULL;
|
||||
}
|
||||
|
||||
ListBase anim_basepaths = {NULL, NULL};
|
||||
|
||||
/* add selected nodes into the ntree */
|
||||
for (node = ngroup->nodes.first; node; node = node_next) {
|
||||
node_next = node->next;
|
||||
LISTBASE_FOREACH_MUTABLE (bNode *, node, &ngroup->nodes) {
|
||||
if (!(node->flag & NODE_SELECT)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -462,6 +452,7 @@ static int node_group_separate_selected(
|
|||
continue;
|
||||
}
|
||||
|
||||
bNode *newnode;
|
||||
if (make_copy) {
|
||||
/* make a copy */
|
||||
newnode = BKE_node_copy_store_new_pointers(ngroup, node, LIB_ID_COPY_DEFAULT);
|
||||
|
@ -505,10 +496,9 @@ static int node_group_separate_selected(
|
|||
}
|
||||
|
||||
/* add internal links to the ntree */
|
||||
for (link = ngroup->links.first; link; link = link_next) {
|
||||
LISTBASE_FOREACH_MUTABLE (bNodeLink *, link, &ngroup->links) {
|
||||
const bool fromselect = (link->fromnode && (link->fromnode->flag & NODE_SELECT));
|
||||
const bool toselect = (link->tonode && (link->tonode->flag & NODE_SELECT));
|
||||
link_next = link->next;
|
||||
|
||||
if (make_copy) {
|
||||
/* make a copy of internal links */
|
||||
|
@ -568,20 +558,19 @@ static int node_group_separate_exec(bContext *C, wmOperator *op)
|
|||
{
|
||||
Main *bmain = CTX_data_main(C);
|
||||
SpaceNode *snode = CTX_wm_space_node(C);
|
||||
bNodeTree *ngroup, *nparent;
|
||||
int type = RNA_enum_get(op->ptr, "type");
|
||||
float offx, offy;
|
||||
|
||||
ED_preview_kill_jobs(CTX_wm_manager(C), bmain);
|
||||
|
||||
/* are we inside of a group? */
|
||||
ngroup = snode->edittree;
|
||||
nparent = ED_node_tree_get(snode, 1);
|
||||
bNodeTree *ngroup = snode->edittree;
|
||||
bNodeTree *nparent = ED_node_tree_get(snode, 1);
|
||||
if (!nparent) {
|
||||
BKE_report(op->reports, RPT_WARNING, "Not inside node group");
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
/* get node tree offset */
|
||||
float offx, offy;
|
||||
space_node_group_offset(snode, &offx, &offy);
|
||||
|
||||
switch (type) {
|
||||
|
@ -658,16 +647,13 @@ static bool node_group_make_test_selected(bNodeTree *ntree,
|
|||
const char *ntree_idname,
|
||||
struct ReportList *reports)
|
||||
{
|
||||
bNodeTree *ngroup;
|
||||
bNode *node;
|
||||
bNodeLink *link;
|
||||
int ok = true;
|
||||
|
||||
/* make a local pseudo node tree to pass to the node poll functions */
|
||||
ngroup = ntreeAddTree(NULL, "Pseudo Node Group", ntree_idname);
|
||||
bNodeTree *ngroup = ntreeAddTree(NULL, "Pseudo Node Group", ntree_idname);
|
||||
|
||||
/* check poll functions for selected nodes */
|
||||
for (node = ntree->nodes.first; node; node = node->next) {
|
||||
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
|
||||
if (node_group_make_use_node(node, gnode)) {
|
||||
if (node->typeinfo->poll_instance && !node->typeinfo->poll_instance(node, ngroup)) {
|
||||
BKE_reportf(reports, RPT_WARNING, "Can not add node '%s' in a group", node->name);
|
||||
|
@ -688,7 +674,7 @@ static bool node_group_make_test_selected(bNodeTree *ntree,
|
|||
|
||||
/* check if all connections are OK, no unselected node has both
|
||||
* inputs and outputs to a selection */
|
||||
for (link = ntree->links.first; link; link = link->next) {
|
||||
LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) {
|
||||
if (node_group_make_use_node(link->fromnode, gnode)) {
|
||||
link->tonode->done |= 1;
|
||||
}
|
||||
|
@ -696,7 +682,7 @@ static bool node_group_make_test_selected(bNodeTree *ntree,
|
|||
link->fromnode->done |= 2;
|
||||
}
|
||||
}
|
||||
for (node = ntree->nodes.first; node; node = node->next) {
|
||||
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
|
||||
if (!(node->flag & NODE_SELECT) && node != gnode && node->done == 3) {
|
||||
return false;
|
||||
}
|
||||
|
@ -707,13 +693,12 @@ static bool node_group_make_test_selected(bNodeTree *ntree,
|
|||
static int node_get_selected_minmax(
|
||||
bNodeTree *ntree, bNode *gnode, float *min, float *max, bool use_size)
|
||||
{
|
||||
bNode *node;
|
||||
float loc[2];
|
||||
int totselect = 0;
|
||||
|
||||
INIT_MINMAX2(min, max);
|
||||
for (node = ntree->nodes.first; node; node = node->next) {
|
||||
LISTBASE_FOREACH (bNode *, node, &ntree->nodes) {
|
||||
if (node_group_make_use_node(node, gnode)) {
|
||||
float loc[2];
|
||||
nodeToView(node, 0.0f, 0.0f, &loc[0], &loc[1]);
|
||||
minmax_v2v2_v2(min, max, loc);
|
||||
if (use_size) {
|
||||
|
@ -737,28 +722,23 @@ static void node_group_make_insert_selected(const bContext *C, bNodeTree *ntree,
|
|||
{
|
||||
Main *bmain = CTX_data_main(C);
|
||||
bNodeTree *ngroup = (bNodeTree *)gnode->id;
|
||||
bNodeLink *link, *linkn;
|
||||
bNode *node, *nextn, *link_node;
|
||||
bNodeSocket *sock, *link_sock;
|
||||
ListBase anim_basepaths = {NULL, NULL};
|
||||
float min[2], max[2], real_min[2], real_max[2], center[2];
|
||||
int totselect;
|
||||
bool expose_visible = false;
|
||||
bNode *input_node, *output_node;
|
||||
|
||||
/* XXX rough guess, not nice but we don't have access to UI constants here ... */
|
||||
static const float offsetx = 200;
|
||||
static const float offsety = 0.0f;
|
||||
|
||||
/* deselect all nodes in the target tree */
|
||||
for (node = ngroup->nodes.first; node; node = node->next) {
|
||||
LISTBASE_FOREACH (bNode *, node, &ngroup->nodes) {
|
||||
nodeSetSelected(node, false);
|
||||
}
|
||||
|
||||
totselect = node_get_selected_minmax(ntree, gnode, min, max, false);
|
||||
float center[2], min[2], max[2];
|
||||
const int totselect = node_get_selected_minmax(ntree, gnode, min, max, false);
|
||||
add_v2_v2v2(center, min, max);
|
||||
mul_v2_fl(center, 0.5f);
|
||||
|
||||
float real_min[2], real_max[2];
|
||||
node_get_selected_minmax(ntree, gnode, real_min, real_max, true);
|
||||
|
||||
/* auto-add interface for "solo" nodes */
|
||||
|
@ -766,9 +746,10 @@ static void node_group_make_insert_selected(const bContext *C, bNodeTree *ntree,
|
|||
expose_visible = true;
|
||||
}
|
||||
|
||||
ListBase anim_basepaths = {NULL, NULL};
|
||||
|
||||
/* move nodes over */
|
||||
for (node = ntree->nodes.first; node; node = nextn) {
|
||||
nextn = node->next;
|
||||
LISTBASE_FOREACH_MUTABLE (bNode *, node, &ntree->nodes) {
|
||||
if (node_group_make_use_node(node, gnode)) {
|
||||
/* 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
|
||||
|
@ -813,22 +794,20 @@ static void node_group_make_insert_selected(const bContext *C, bNodeTree *ntree,
|
|||
ntreeFreeCache(ngroup);
|
||||
|
||||
/* create input node */
|
||||
input_node = nodeAddStaticNode(C, ngroup, NODE_GROUP_INPUT);
|
||||
bNode *input_node = nodeAddStaticNode(C, ngroup, NODE_GROUP_INPUT);
|
||||
input_node->locx = real_min[0] - center[0] - offsetx;
|
||||
input_node->locy = -offsety;
|
||||
|
||||
/* create output node */
|
||||
output_node = nodeAddStaticNode(C, ngroup, NODE_GROUP_OUTPUT);
|
||||
bNode *output_node = nodeAddStaticNode(C, ngroup, NODE_GROUP_OUTPUT);
|
||||
output_node->locx = real_max[0] - center[0] + offsetx * 0.25f;
|
||||
output_node->locy = -offsety;
|
||||
|
||||
/* relink external sockets */
|
||||
for (link = ntree->links.first; link; link = linkn) {
|
||||
LISTBASE_FOREACH_MUTABLE (bNodeLink *, link, &ntree->links) {
|
||||
int fromselect = node_group_make_use_node(link->fromnode, gnode);
|
||||
int toselect = node_group_make_use_node(link->tonode, gnode);
|
||||
|
||||
linkn = link->next;
|
||||
|
||||
if ((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.
|
||||
|
@ -836,9 +815,10 @@ static void node_group_make_insert_selected(const bContext *C, bNodeTree *ntree,
|
|||
nodeRemLink(ntree, link);
|
||||
}
|
||||
else if (toselect && !fromselect) {
|
||||
bNodeSocket *link_sock;
|
||||
bNode *link_node;
|
||||
node_socket_skip_reroutes(&ntree->links, link->tonode, link->tosock, &link_node, &link_sock);
|
||||
bNodeSocket *iosock = ntreeAddSocketInterfaceFromSocket(ngroup, link_node, link_sock);
|
||||
bNodeSocket *input_sock;
|
||||
|
||||
/* update the group node and interface node sockets,
|
||||
* so the new interface socket can be linked.
|
||||
|
@ -847,7 +827,7 @@ static void node_group_make_insert_selected(const bContext *C, bNodeTree *ntree,
|
|||
node_group_input_update(ngroup, input_node);
|
||||
|
||||
/* create new internal link */
|
||||
input_sock = node_group_input_find_socket(input_node, iosock->identifier);
|
||||
bNodeSocket *input_sock = node_group_input_find_socket(input_node, iosock->identifier);
|
||||
nodeAddLink(ngroup, input_node, input_sock, link->tonode, link->tosock);
|
||||
|
||||
/* redirect external link */
|
||||
|
@ -858,8 +838,7 @@ static void node_group_make_insert_selected(const bContext *C, bNodeTree *ntree,
|
|||
/* First check whether the source of this link is already connected to an output.
|
||||
* If yes, reuse that output instead of duplicating it. */
|
||||
bool connected = false;
|
||||
bNodeLink *olink;
|
||||
for (olink = ngroup->links.first; olink; olink = olink->next) {
|
||||
LISTBASE_FOREACH (bNodeLink *, olink, &ngroup->links) {
|
||||
if (olink->fromsock == link->fromsock && olink->tonode == output_node) {
|
||||
bNodeSocket *output_sock = node_group_find_output_socket(gnode,
|
||||
olink->tosock->identifier);
|
||||
|
@ -870,10 +849,11 @@ static void node_group_make_insert_selected(const bContext *C, bNodeTree *ntree,
|
|||
}
|
||||
|
||||
if (!connected) {
|
||||
bNodeSocket *link_sock;
|
||||
bNode *link_node;
|
||||
node_socket_skip_reroutes(
|
||||
&ntree->links, link->fromnode, link->fromsock, &link_node, &link_sock);
|
||||
bNodeSocket *iosock = ntreeAddSocketInterfaceFromSocket(ngroup, link_node, link_sock);
|
||||
bNodeSocket *output_sock;
|
||||
|
||||
/* update the group node and interface node sockets,
|
||||
* so the new interface socket can be linked.
|
||||
|
@ -882,7 +862,7 @@ static void node_group_make_insert_selected(const bContext *C, bNodeTree *ntree,
|
|||
node_group_output_update(ngroup, output_node);
|
||||
|
||||
/* create new internal link */
|
||||
output_sock = node_group_output_find_socket(output_node, iosock->identifier);
|
||||
bNodeSocket *output_sock = node_group_output_find_socket(output_node, iosock->identifier);
|
||||
nodeAddLink(ngroup, link->fromnode, link->fromsock, output_node, output_sock);
|
||||
|
||||
/* redirect external link */
|
||||
|
@ -893,12 +873,10 @@ static void node_group_make_insert_selected(const bContext *C, bNodeTree *ntree,
|
|||
}
|
||||
|
||||
/* move internal links */
|
||||
for (link = ntree->links.first; link; link = linkn) {
|
||||
LISTBASE_FOREACH_MUTABLE (bNodeLink *, link, &ntree->links) {
|
||||
int fromselect = node_group_make_use_node(link->fromnode, gnode);
|
||||
int toselect = node_group_make_use_node(link->tonode, gnode);
|
||||
|
||||
linkn = link->next;
|
||||
|
||||
if (fromselect && toselect) {
|
||||
BLI_remlink(&ntree->links, link);
|
||||
BLI_addtail(&ngroup->links, link);
|
||||
|
@ -906,7 +884,7 @@ static void node_group_make_insert_selected(const bContext *C, bNodeTree *ntree,
|
|||
}
|
||||
|
||||
/* move nodes in the group to the center */
|
||||
for (node = ngroup->nodes.first; node; node = node->next) {
|
||||
LISTBASE_FOREACH (bNode *, node, &ngroup->nodes) {
|
||||
if (node_group_make_use_node(node, gnode) && !node->parent) {
|
||||
node->locx -= center[0];
|
||||
node->locy -= center[1];
|
||||
|
@ -915,12 +893,11 @@ static void node_group_make_insert_selected(const bContext *C, bNodeTree *ntree,
|
|||
|
||||
/* expose all unlinked sockets too but only the visible ones*/
|
||||
if (expose_visible) {
|
||||
for (node = ngroup->nodes.first; node; node = node->next) {
|
||||
LISTBASE_FOREACH (bNode *, node, &ngroup->nodes) {
|
||||
if (node_group_make_use_node(node, gnode)) {
|
||||
for (sock = node->inputs.first; sock; sock = sock->next) {
|
||||
bNodeSocket *iosock, *input_sock;
|
||||
LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) {
|
||||
bool skip = false;
|
||||
for (link = ngroup->links.first; link; link = link->next) {
|
||||
LISTBASE_FOREACH (bNodeLink *, link, &ngroup->links) {
|
||||
if (link->tosock == sock) {
|
||||
skip = true;
|
||||
break;
|
||||
|
@ -933,19 +910,18 @@ static void node_group_make_insert_selected(const bContext *C, bNodeTree *ntree,
|
|||
continue;
|
||||
}
|
||||
|
||||
iosock = ntreeAddSocketInterfaceFromSocket(ngroup, node, sock);
|
||||
bNodeSocket *iosock = ntreeAddSocketInterfaceFromSocket(ngroup, node, sock);
|
||||
|
||||
node_group_input_update(ngroup, input_node);
|
||||
|
||||
/* create new internal link */
|
||||
input_sock = node_group_input_find_socket(input_node, iosock->identifier);
|
||||
bNodeSocket *input_sock = node_group_input_find_socket(input_node, iosock->identifier);
|
||||
nodeAddLink(ngroup, input_node, input_sock, node, sock);
|
||||
}
|
||||
|
||||
for (sock = node->outputs.first; sock; sock = sock->next) {
|
||||
bNodeSocket *iosock, *output_sock;
|
||||
LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) {
|
||||
bool skip = false;
|
||||
for (link = ngroup->links.first; link; link = link->next) {
|
||||
LISTBASE_FOREACH (bNodeLink *, link, &ngroup->links) {
|
||||
if (link->fromsock == sock) {
|
||||
skip = true;
|
||||
}
|
||||
|
@ -957,12 +933,13 @@ static void node_group_make_insert_selected(const bContext *C, bNodeTree *ntree,
|
|||
continue;
|
||||
}
|
||||
|
||||
iosock = ntreeAddSocketInterfaceFromSocket(ngroup, node, sock);
|
||||
bNodeSocket *iosock = ntreeAddSocketInterfaceFromSocket(ngroup, node, sock);
|
||||
|
||||
node_group_output_update(ngroup, output_node);
|
||||
|
||||
/* create new internal link */
|
||||
output_sock = node_group_output_find_socket(output_node, iosock->identifier);
|
||||
bNodeSocket *output_sock = node_group_output_find_socket(output_node,
|
||||
iosock->identifier);
|
||||
nodeAddLink(ngroup, node, sock, output_node, output_sock);
|
||||
}
|
||||
}
|
||||
|
@ -981,22 +958,19 @@ static bNode *node_group_make_from_selected(const bContext *C,
|
|||
const char *ntreetype)
|
||||
{
|
||||
Main *bmain = CTX_data_main(C);
|
||||
bNode *gnode;
|
||||
bNodeTree *ngroup;
|
||||
float min[2], max[2];
|
||||
int totselect;
|
||||
|
||||
totselect = node_get_selected_minmax(ntree, NULL, min, max, false);
|
||||
float min[2], max[2];
|
||||
const int totselect = node_get_selected_minmax(ntree, NULL, min, max, false);
|
||||
/* don't make empty group */
|
||||
if (totselect == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* new nodetree */
|
||||
ngroup = ntreeAddTree(bmain, "NodeGroup", ntreetype);
|
||||
bNodeTree *ngroup = ntreeAddTree(bmain, "NodeGroup", ntreetype);
|
||||
|
||||
/* make group node */
|
||||
gnode = nodeAddNode(C, ntree, ntype);
|
||||
bNode *gnode = nodeAddNode(C, ntree, ntype);
|
||||
gnode->id = (ID *)ngroup;
|
||||
|
||||
gnode->locx = 0.5f * (min[0] + max[0]);
|
||||
|
@ -1016,8 +990,6 @@ static int node_group_make_exec(bContext *C, wmOperator *op)
|
|||
bNodeTree *ntree = snode->edittree;
|
||||
const char *ntree_idname = group_ntree_idname(C);
|
||||
const char *node_idname = group_node_idname(C);
|
||||
bNodeTree *ngroup;
|
||||
bNode *gnode;
|
||||
Main *bmain = CTX_data_main(C);
|
||||
|
||||
ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
|
||||
|
@ -1026,10 +998,10 @@ static int node_group_make_exec(bContext *C, wmOperator *op)
|
|||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
gnode = node_group_make_from_selected(C, ntree, node_idname, ntree_idname);
|
||||
bNode *gnode = node_group_make_from_selected(C, ntree, node_idname, ntree_idname);
|
||||
|
||||
if (gnode) {
|
||||
ngroup = (bNodeTree *)gnode->id;
|
||||
bNodeTree *ngroup = (bNodeTree *)gnode->id;
|
||||
|
||||
nodeSetActive(ntree, gnode);
|
||||
if (ngroup) {
|
||||
|
@ -1070,20 +1042,18 @@ static int node_group_insert_exec(bContext *C, wmOperator *op)
|
|||
{
|
||||
SpaceNode *snode = CTX_wm_space_node(C);
|
||||
bNodeTree *ntree = snode->edittree;
|
||||
bNodeTree *ngroup;
|
||||
const char *node_idname = group_node_idname(C);
|
||||
bNode *gnode;
|
||||
Main *bmain = CTX_data_main(C);
|
||||
|
||||
ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C));
|
||||
|
||||
gnode = node_group_get_active(C, node_idname);
|
||||
bNode *gnode = node_group_get_active(C, node_idname);
|
||||
|
||||
if (!gnode || !gnode->id) {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
ngroup = (bNodeTree *)gnode->id;
|
||||
bNodeTree *ngroup = (bNodeTree *)gnode->id;
|
||||
if (!node_group_make_test_selected(ntree, gnode, ngroup->idname, op->reports)) {
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue