minor cleanup to node pasting.
This commit is contained in:
@@ -1516,7 +1516,7 @@ int BKE_node_clipboard_validate(void)
|
||||
if (BLI_findindex(lb, node_info->id) == -1) {
|
||||
/* may assign NULL */
|
||||
node->id = BLI_findstring(lb, node_info->id_name + 2, offsetof(ID, name) + 2);
|
||||
printf("%s %p\n", node_info->id_name, node->id);
|
||||
|
||||
if (node->id == NULL) {
|
||||
ok = FALSE;
|
||||
}
|
||||
|
||||
@@ -2018,46 +2018,55 @@ static int node_clipboard_paste_exec(bContext *C, wmOperator *op)
|
||||
SpaceNode *snode = CTX_wm_space_node(C);
|
||||
bNodeTree *ntree = snode->edittree;
|
||||
bNode *gnode = node_tree_get_editgroup(snode->nodetree);
|
||||
float gnode_x = 0.0f, gnode_y = 0.0f;
|
||||
float gnode_center[2];
|
||||
const ListBase *clipboard_nodes_lb;
|
||||
const ListBase *clipboard_links_lb;
|
||||
bNode *node;
|
||||
bNodeLink *link;
|
||||
int num_nodes;
|
||||
float centerx, centery;
|
||||
float center[2];
|
||||
int is_clipboard_valid;
|
||||
|
||||
/* validate pointers in the clipboard */
|
||||
is_clipboard_valid = BKE_node_clipboard_validate();
|
||||
clipboard_nodes_lb = BKE_node_clipboard_get_nodes();
|
||||
clipboard_links_lb = BKE_node_clipboard_get_links();
|
||||
|
||||
if (clipboard_nodes_lb->first == NULL) {
|
||||
BKE_report(op->reports, RPT_ERROR, "Clipboard is empty");
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
if (BKE_node_clipboard_get_type() != ntree->type) {
|
||||
BKE_report(op->reports, RPT_ERROR, "Clipboard nodes are an incompatible type");
|
||||
return OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
/* only warn */
|
||||
if (is_clipboard_valid == FALSE) {
|
||||
BKE_report(op->reports, RPT_WARNING, "Some nodes references could not be restored, will be left empty");
|
||||
}
|
||||
|
||||
ED_preview_kill_jobs(C);
|
||||
|
||||
/* deselect old nodes */
|
||||
node_deselect_all(snode);
|
||||
|
||||
/* get group node offset */
|
||||
if (gnode)
|
||||
nodeToView(gnode, 0.0f, 0.0f, &gnode_x, &gnode_y);
|
||||
|
||||
|
||||
/* validate pointers in the clipboard */
|
||||
is_clipboard_valid = BKE_node_clipboard_validate();
|
||||
|
||||
clipboard_nodes_lb = BKE_node_clipboard_get_nodes();
|
||||
clipboard_links_lb = BKE_node_clipboard_get_links();
|
||||
if (gnode) {
|
||||
nodeToView(gnode, 0.0f, 0.0f, &gnode_center[0], &gnode_center[1]);
|
||||
}
|
||||
else {
|
||||
zero_v2(gnode_center);
|
||||
}
|
||||
|
||||
/* calculate "barycenter" for placing on mouse cursor */
|
||||
num_nodes = 0;
|
||||
centerx = centery = 0.0f;
|
||||
for (node = clipboard_nodes_lb->first; node; node = node->next) {
|
||||
++num_nodes;
|
||||
centerx += 0.5f * (node->totr.xmin + node->totr.xmax);
|
||||
centery += 0.5f * (node->totr.ymin + node->totr.ymax);
|
||||
zero_v2(center);
|
||||
for (node = clipboard_nodes_lb->first, num_nodes = 0; node; node = node->next, num_nodes++) {
|
||||
center[0] += 0.5f * (node->totr.xmin + node->totr.xmax);
|
||||
center[1] += 0.5f * (node->totr.ymin + node->totr.ymax);
|
||||
}
|
||||
centerx /= num_nodes;
|
||||
centery /= num_nodes;
|
||||
mul_v2_fl(center, 1.0 / num_nodes);
|
||||
|
||||
/* copy nodes from clipboard */
|
||||
for (node = clipboard_nodes_lb->first; node; node = node->next) {
|
||||
@@ -2079,8 +2088,8 @@ static int node_clipboard_paste_exec(bContext *C, wmOperator *op)
|
||||
|
||||
/* place nodes around the mouse cursor. child nodes locations are relative to parent */
|
||||
if (!new_node->parent) {
|
||||
new_node->locx += snode->cursor[0] - centerx - gnode_x;
|
||||
new_node->locy += snode->cursor[1] - centery - gnode_y;
|
||||
new_node->locx += snode->cursor[0] - center[0] - gnode_center[0];
|
||||
new_node->locy += snode->cursor[1] - center[1] - gnode_center[1];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2094,10 +2103,6 @@ static int node_clipboard_paste_exec(bContext *C, wmOperator *op)
|
||||
snode_notify(C, snode);
|
||||
snode_dag_update(C, snode);
|
||||
|
||||
if (is_clipboard_valid == FALSE) {
|
||||
BKE_report(op->reports, RPT_ERROR, "Some nodes ID references could not be found");
|
||||
}
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user