diff options
Diffstat (limited to 'source/blender/editors/space_node/node_group.cc')
-rw-r--r-- | source/blender/editors/space_node/node_group.cc | 89 |
1 files changed, 34 insertions, 55 deletions
diff --git a/source/blender/editors/space_node/node_group.cc b/source/blender/editors/space_node/node_group.cc index 704ffe1e478..f6802e64049 100644 --- a/source/blender/editors/space_node/node_group.cc +++ b/source/blender/editors/space_node/node_group.cc @@ -32,6 +32,7 @@ #include "BLI_linklist.h" #include "BLI_listbase.h" #include "BLI_string.h" +#include "BLI_vector.hh" #include "BLT_translation.h" @@ -40,6 +41,7 @@ #include "BKE_context.h" #include "BKE_lib_id.h" #include "BKE_main.h" +#include "BKE_node_tree_update.h" #include "BKE_report.h" #include "DEG_depsgraph_build.h" @@ -61,6 +63,8 @@ #include "node_intern.hh" /* own include */ using blender::float2; +using blender::Map; +using blender::Vector; /* -------------------------------------------------------------------- */ /** \name Local Utilities @@ -216,24 +220,21 @@ static void animation_basepath_change_free(AnimationBasePathChange *basepath_cha MEM_freeN(basepath_change); } -/* returns 1 if its OK */ -static int node_group_ungroup(Main *bmain, bNodeTree *ntree, bNode *gnode) +/** + * \return True if successful. + */ +static bool node_group_ungroup(Main *bmain, bNodeTree *ntree, bNode *gnode) { - /* Clear new pointers, set in #ntreeCopyTree_ex_new_pointers. */ - LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { - node->new_node = nullptr; - } - ListBase anim_basepaths = {nullptr, nullptr}; - LinkNode *nodes_delayed_free = nullptr; - bNodeTree *ngroup = (bNodeTree *)gnode->id; + Vector<bNode *> nodes_delayed_free; + const bNodeTree *ngroup = reinterpret_cast<const 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 */ - bNodeTree *wgroup = ntreeCopyTree_ex_new_pointers(ngroup, bmain, true); + bNodeTree *wgroup = ntreeCopyTree(bmain, ngroup); /* Add the nodes into the ntree */ LISTBASE_FOREACH_MUTABLE (bNode *, node, &wgroup->nodes) { @@ -242,7 +243,7 @@ static int node_group_ungroup(Main *bmain, bNodeTree *ntree, bNode *gnode) */ if (ELEM(node->type, NODE_GROUP_INPUT, NODE_GROUP_OUTPUT)) { /* We must delay removal since sockets will reference this node. see: T52092 */ - BLI_linklist_prepend(&nodes_delayed_free, node); + nodes_delayed_free.append(node); } /* keep track of this node's RNA "base" path (the part of the path identifying the node) @@ -258,6 +259,7 @@ static int node_group_ungroup(Main *bmain, bNodeTree *ntree, bNode *gnode) /* migrate node */ BLI_remlink(&wgroup->nodes, node); BLI_addtail(&ntree->nodes, node); + BKE_ntree_update_tag_node_new(ntree, node); /* ensure unique node name in the node tree */ nodeUniqueName(ntree, node); @@ -284,6 +286,7 @@ static int node_group_ungroup(Main *bmain, bNodeTree *ntree, bNode *gnode) LISTBASE_FOREACH_MUTABLE (bNodeLink *, link, &wgroup->links) { BLI_remlink(&wgroup->links, link); BLI_addtail(&ntree->links, link); + BKE_ntree_update_tag_link_added(ntree, link); } bNodeLink *glinks_last = (bNodeLink *)ntree->links.last; @@ -385,17 +388,14 @@ static int node_group_ungroup(Main *bmain, bNodeTree *ntree, bNode *gnode) } } - while (nodes_delayed_free) { - bNode *node = (bNode *)BLI_linklist_pop(&nodes_delayed_free); + for (bNode *node : nodes_delayed_free) { nodeRemoveNode(bmain, ntree, node, false); } /* delete the group instance and dereference group tree */ nodeRemoveNode(bmain, ntree, gnode, true); - ntree->update |= NTREE_UPDATE_NODES | NTREE_UPDATE_LINKS; - - return 1; + return true; } static int node_group_ungroup_exec(bContext *C, wmOperator *op) @@ -412,16 +412,13 @@ static int node_group_ungroup_exec(bContext *C, wmOperator *op) } if (gnode->id && node_group_ungroup(bmain, snode->edittree, gnode)) { - ntreeUpdateTree(bmain, snode->nodetree); + ED_node_tree_propagate_change(C, CTX_data_main(C), nullptr); } else { BKE_report(op->reports, RPT_WARNING, "Cannot ungroup"); return OPERATOR_CANCELLED; } - snode_notify(*C, *snode); - snode_dag_update(*C, *snode); - return OPERATOR_FINISHED; } @@ -457,13 +454,11 @@ static bool node_group_separate_selected( nodeSetSelected(node, false); } - /* clear new pointers, set in BKE_node_copy_ex(). */ - LISTBASE_FOREACH (bNode *, node, &ngroup.nodes) { - node->new_node = nullptr; - } - ListBase anim_basepaths = {nullptr, nullptr}; + Map<const bNode *, bNode *> node_map; + Map<const bNodeSocket *, bNodeSocket *> socket_map; + /* add selected nodes into the ntree */ LISTBASE_FOREACH_MUTABLE (bNode *, node, &ngroup.nodes) { if (!(node->flag & NODE_SELECT)) { @@ -479,7 +474,9 @@ static bool node_group_separate_selected( bNode *newnode; if (make_copy) { /* make a copy */ - newnode = BKE_node_copy_store_new_pointers(&ngroup, node, LIB_ID_COPY_DEFAULT); + newnode = blender::bke::node_copy_with_mapping( + &ngroup, *node, LIB_ID_COPY_DEFAULT, true, socket_map); + node_map.add_new(node, newnode); } else { /* use the existing node */ @@ -528,10 +525,10 @@ static bool node_group_separate_selected( /* 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); + node_map.lookup(link->fromnode), + socket_map.lookup(link->fromsock), + node_map.lookup(link->tonode), + socket_map.lookup(link->tosock)); } } else { @@ -558,9 +555,9 @@ static bool node_group_separate_selected( } } - ntree.update |= NTREE_UPDATE_NODES | NTREE_UPDATE_LINKS; + BKE_ntree_update_tag_all(&ntree); if (!make_copy) { - ngroup.update |= NTREE_UPDATE_NODES | NTREE_UPDATE_LINKS; + BKE_ntree_update_tag_all(&ngroup); } return true; @@ -614,10 +611,7 @@ static int node_group_separate_exec(bContext *C, wmOperator *op) /* switch to parent tree */ ED_node_tree_pop(snode); - ntreeUpdateTree(CTX_data_main(C), snode->nodetree); - - snode_notify(*C, *snode); - snode_dag_update(*C, *snode); + ED_node_tree_propagate_change(C, CTX_data_main(C), nullptr); return OPERATOR_FINISHED; } @@ -812,6 +806,8 @@ static void node_group_make_insert_selected(const bContext &C, bNodeTree &ntree, /* change node-collection membership */ BLI_remlink(&ntree.nodes, node); BLI_addtail(&ngroup->nodes, node); + BKE_ntree_update_tag_node_removed(&ntree); + BKE_ntree_update_tag_node_new(ngroup, node); /* ensure unique node name in the ngroup */ nodeUniqueName(ngroup, node); @@ -983,11 +979,6 @@ static void node_group_make_insert_selected(const bContext &C, bNodeTree &ntree, } } } - - /* update of the group tree */ - ngroup->update |= NTREE_UPDATE | NTREE_UPDATE_LINKS; - /* update of the tree containing the group instance node */ - ntree.update |= NTREE_UPDATE_NODES | NTREE_UPDATE_LINKS; } static bNode *node_group_make_from_selected(const bContext &C, @@ -1016,9 +1007,6 @@ static bNode *node_group_make_from_selected(const bContext &C, node_group_make_insert_selected(C, ntree, gnode); - /* update of the tree containing the group instance node */ - ntree.update |= NTREE_UPDATE_NODES; - return gnode; } @@ -1047,14 +1035,10 @@ static int node_group_make_exec(bContext *C, wmOperator *op) LISTBASE_FOREACH (bNode *, node, &ngroup->nodes) { sort_multi_input_socket_links(snode, *node, nullptr, nullptr); } - ntreeUpdateTree(bmain, ngroup); } } - ntreeUpdateTree(bmain, &ntree); - - snode_notify(*C, snode); - snode_dag_update(*C, snode); + ED_node_tree_propagate_change(C, bmain, nullptr); /* We broke relations in node tree, need to rebuild them in the graphs. */ DEG_relations_tag_update(bmain); @@ -1107,12 +1091,7 @@ static int node_group_insert_exec(bContext *C, wmOperator *op) nodeSetActive(ntree, gnode); ED_node_tree_push(snode, ngroup, gnode); - ntreeUpdateTree(bmain, ngroup); - - ntreeUpdateTree(bmain, ntree); - - snode_notify(*C, *snode); - snode_dag_update(*C, *snode); + ED_node_tree_propagate_change(C, bmain, nullptr); return OPERATOR_FINISHED; } |