Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Toenne <lukas.toenne@googlemail.com>2012-08-03 14:51:29 +0400
committerLukas Toenne <lukas.toenne@googlemail.com>2012-08-03 14:51:29 +0400
commit771a7241b9b2267007ed0f990a1987eca442e0c4 (patch)
treede69834712097b41dec4f21e95207cd828d06094
parent854e122e5d07baaef6f221ad7bcc436d8f3c077f (diff)
Fix for node placement when copying to/pasting from clipboard. Child node location is always relative to parent nodes (if the parent is also copied) and must not be offset. Also takes the offset of the edited node group in the editor into account now.
-rw-r--r--source/blender/editors/space_node/node_edit.c42
1 files changed, 32 insertions, 10 deletions
diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c
index 16760ca9897..d32303b27d1 100644
--- a/source/blender/editors/space_node/node_edit.c
+++ b/source/blender/editors/space_node/node_edit.c
@@ -1904,7 +1904,9 @@ static int node_clipboard_copy_exec(bContext *C, wmOperator *UNUSED(op))
{
SpaceNode *snode = CTX_wm_space_node(C);
bNodeTree *ntree = snode->edittree;
- bNode *node, *newnode;
+ bNode *gnode = node_tree_get_editgroup(snode->nodetree);
+ float gnode_x = 0.0f, gnode_y = 0.0f;
+ bNode *node, *new_node;
bNodeLink *link, *newlink;
ED_preview_kill_jobs(C);
@@ -1912,17 +1914,22 @@ static int node_clipboard_copy_exec(bContext *C, wmOperator *UNUSED(op))
/* clear current clipboard */
nodeClipboardClear();
+ /* get group node offset */
+ if (gnode)
+ nodeToView(gnode, 0.0f, 0.0f, &gnode_x, &gnode_y);
+
for (node = ntree->nodes.first; node; node = node->next) {
if (node->flag & SELECT) {
- newnode = nodeCopyNode(NULL, node);
- nodeClipboardAddNode(newnode);
+ new_node = nodeCopyNode(NULL, node);
+ nodeClipboardAddNode(new_node);
}
}
- /* ensure valid pointers */
for (node = ntree->nodes.first; node; node = node->next) {
if (node->flag & SELECT) {
bNode *new_node = node->new_node;
+
+ /* ensure valid pointers */
if (new_node->parent) {
/* parent pointer must be redirected to new node or detached if parent is not copied */
if (new_node->parent->flag & NODE_SELECT) {
@@ -1932,6 +1939,12 @@ static int node_clipboard_copy_exec(bContext *C, wmOperator *UNUSED(op))
nodeDetachNode(new_node);
}
}
+
+ /* transform to basic view space. child node location is relative to parent */
+ if (!new_node->parent) {
+ new_node->locx += gnode_x;
+ new_node->locy += gnode_y;
+ }
}
}
@@ -1978,6 +1991,8 @@ static int node_clipboard_paste_exec(bContext *C, wmOperator *UNUSED(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;
bNode *node;
bNodeLink *link;
int num_nodes;
@@ -1988,13 +2003,17 @@ static int node_clipboard_paste_exec(bContext *C, wmOperator *UNUSED(op))
/* deselect old nodes */
node_deselect_all(snode);
+ /* get group node offset */
+ if (gnode)
+ nodeToView(gnode, 0.0f, 0.0f, &gnode_x, &gnode_y);
+
/* calculate "barycenter" for placing on mouse cursor */
num_nodes = 0;
centerx = centery = 0.0f;
for (node = nodeClipboardGetNodes()->first; node; node = node->next) {
++num_nodes;
- centerx += node->locx + 0.5f * node->width;
- centery += node->locy - 0.5f * node->height;
+ centerx += 0.5f * (node->totr.xmin + node->totr.xmax);
+ centery += 0.5f * (node->totr.ymin + node->totr.ymax);
}
centerx /= num_nodes;
centery /= num_nodes;
@@ -2005,10 +2024,6 @@ static int node_clipboard_paste_exec(bContext *C, wmOperator *UNUSED(op))
/* pasted nodes are selected */
node_select(new_node);
-
- /* place nodes around the mouse cursor */
- new_node->locx += snode->mx - centerx;
- new_node->locy += snode->my - centery;
}
/* reparent copied nodes */
@@ -2016,6 +2031,13 @@ static int node_clipboard_paste_exec(bContext *C, wmOperator *UNUSED(op))
bNode *new_node = node->new_node;
if (new_node->parent)
new_node->parent = new_node->parent->new_node;
+
+
+ /* place nodes around the mouse cursor. child nodes locations are relative to parent */
+ if (!new_node->parent) {
+ new_node->locx += snode->mx - centerx - gnode_x;
+ new_node->locy += snode->my - centery - gnode_y;
+ }
}
for (link = nodeClipboardGetLinks()->first; link; link = link->next) {