Nodes: Allow skipping node attachment after dragging

This patch allows skipping the automatic insertion of nodes on top of
links when the transform operator ends. When putting nodes into small
spaces this often gets in the way and wastes time. Now, when holding
`alt`, this is turned off.

The header text is also improved to add this shortcut and to remove
the Dx and Dy values and improve the formatting a bit.

Making this functionality optional might allow us to use it in more
places in the future, like for the nodes added by link-drag-search.

Differential Revision: https://developer.blender.org/D16230
This commit is contained in:
Hans Goudey 2022-12-15 14:03:28 -06:00
parent 7608ebe44a
commit ae886596a0
Notes: blender-bot 2023-02-14 02:22:07 +01:00
Referenced by commit 6b9825e6f7, Fix T103463: Repeat last crashes in node editor
Referenced by issue #94917, Alt modifier key to disable node auto-connection
6 changed files with 101 additions and 45 deletions

View File

@ -5779,6 +5779,8 @@ def km_transform_modal_map(_params):
("AUTOIK_CHAIN_LEN_UP", {"type": 'WHEELDOWNMOUSE', "value": 'PRESS', "shift": True}, None),
("AUTOIK_CHAIN_LEN_DOWN", {"type": 'WHEELUPMOUSE', "value": 'PRESS', "shift": True}, None),
("INSERTOFS_TOGGLE_DIR", {"type": 'T', "value": 'PRESS'}, None),
("NODE_ATTACH_ON", {"type": 'LEFT_ALT', "value": 'RELEASE', "any": True}, None),
("NODE_ATTACH_OFF", {"type": 'LEFT_ALT', "value": 'PRESS', "any": True}, None),
("AUTOCONSTRAIN", {"type": 'MIDDLEMOUSE', "value": 'ANY'}, None),
("AUTOCONSTRAINPLANE", {"type": 'MIDDLEMOUSE', "value": 'ANY', "shift": True}, None),
("PRECISION", {"type": 'LEFT_SHIFT', "value": 'ANY', "any": True}, None),

View File

@ -3996,6 +3996,8 @@ def km_transform_modal_map(_params):
("AUTOIK_CHAIN_LEN_UP", {"type": 'WHEELDOWNMOUSE', "value": 'PRESS', "shift": True}, None),
("AUTOIK_CHAIN_LEN_DOWN", {"type": 'WHEELUPMOUSE', "value": 'PRESS', "shift": True}, None),
("INSERTOFS_TOGGLE_DIR", {"type": 'T', "value": 'PRESS'}, None),
("NODE_ATTACH_ON", {"type": 'LEFT_ALT', "value": 'RELEASE', "any": True}, None),
("NODE_ATTACH_OFF", {"type": 'LEFT_ALT', "value": 'PRESS', "any": True}, None),
("AUTOCONSTRAIN", {"type": 'MIDDLEMOUSE', "value": 'ANY'}, None),
("AUTOCONSTRAINPLANE", {"type": 'MIDDLEMOUSE', "value": 'ANY', "shift": True}, None),
("PRECISION", {"type": 'LEFT_SHIFT', "value": 'ANY', "any": True}, None),

View File

@ -599,7 +599,9 @@ static bool transform_modal_item_poll(const wmOperator *op, int value)
}
break;
}
case TFM_MODAL_INSERTOFS_TOGGLE_DIR: {
case TFM_MODAL_INSERTOFS_TOGGLE_DIR:
case TFM_MODAL_NODE_ATTACH_ON:
case TFM_MODAL_NODE_ATTACH_OFF: {
if (t->spacetype != SPACE_NODE) {
return false;
}
@ -661,6 +663,8 @@ wmKeyMap *transform_modal_keymap(wmKeyConfig *keyconf)
0,
"Toggle Direction for Node Auto-Offset",
""},
{TFM_MODAL_NODE_ATTACH_ON, "NODE_ATTACH_ON", 0, "Node Attachment", ""},
{TFM_MODAL_NODE_ATTACH_OFF, "NODE_ATTACH_OFF", 0, "Node Attachment (Off)", ""},
{TFM_MODAL_TRANSLATE, "TRANSLATE", 0, "Move", ""},
{TFM_MODAL_ROTATE, "ROTATE", 0, "Rotate", ""},
{TFM_MODAL_RESIZE, "RESIZE", 0, "Resize", ""},
@ -1112,6 +1116,17 @@ int transformEvent(TransInfo *t, const wmEvent *event)
t->redraw |= TREDRAW_SOFT;
}
break;
case TFM_MODAL_NODE_ATTACH_ON:
t->modifiers |= MOD_NODE_ATTACH;
t->redraw |= TREDRAW_HARD;
handled = true;
break;
case TFM_MODAL_NODE_ATTACH_OFF:
t->modifiers &= ~MOD_NODE_ATTACH;
t->redraw |= TREDRAW_HARD;
handled = true;
break;
case TFM_MODAL_AUTOCONSTRAINT:
case TFM_MODAL_AUTOCONSTRAINTPLANE:
if ((t->flag & T_RELEASE_CONFIRM) && (event->prev_val == KM_RELEASE) &&
@ -1857,6 +1872,27 @@ bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
}
}
}
if (t->data_type == &TransConvertType_Node) {
/* Set the initial auto-attach flag based on whether the chosen keymap key is pressed at the
* start of the operator. */
t->modifiers |= MOD_NODE_ATTACH;
LISTBASE_FOREACH (const wmKeyMapItem *, kmi, &t->keymap->items) {
if (kmi->flag & KMI_INACTIVE) {
continue;
}
if (kmi->propvalue == TFM_MODAL_NODE_ATTACH_OFF && kmi->val == KM_PRESS) {
if ((ELEM(kmi->type, EVT_LEFTCTRLKEY, EVT_RIGHTCTRLKEY) && (event->modifier & KM_CTRL)) ||
(ELEM(kmi->type, EVT_LEFTSHIFTKEY, EVT_RIGHTSHIFTKEY) &&
(event->modifier & KM_SHIFT)) ||
(ELEM(kmi->type, EVT_LEFTALTKEY, EVT_RIGHTALTKEY) && (event->modifier & KM_ALT)) ||
((kmi->type == EVT_OSKEY) && (event->modifier & KM_OSKEY))) {
t->modifiers &= ~MOD_NODE_ATTACH;
}
break;
}
}
}
initSnapping(t, op); /* Initialize snapping data AFTER mode flags */

View File

@ -152,8 +152,9 @@ typedef enum {
MOD_SNAP = 1 << 2,
MOD_SNAP_INVERT = 1 << 3,
MOD_CONSTRAINT_SELECT_PLANE = 1 << 4,
MOD_NODE_ATTACH = 1 << 5,
} eTModifier;
ENUM_OPERATORS(eTModifier, MOD_CONSTRAINT_SELECT_PLANE)
ENUM_OPERATORS(eTModifier, MOD_NODE_ATTACH)
/** #TransSnap.status */
typedef enum eTSnap {
@ -244,8 +245,8 @@ enum {
TFM_MODAL_AUTOIK_LEN_INC = 22,
TFM_MODAL_AUTOIK_LEN_DEC = 23,
// TFM_MODAL_UNUSED_1 = 24,
// TFM_MODAL_UNUSED_2 = 25,
TFM_MODAL_NODE_ATTACH_ON = 24,
TFM_MODAL_NODE_ATTACH_OFF = 25,
/** For analog input, like track-pad. */
TFM_MODAL_PROPSIZE = 26,

View File

@ -116,6 +116,13 @@ static void createTransNodeData(bContext * /*C*/, TransInfo *t)
NODE_EDGE_PAN_ZOOM_INFLUENCE);
customdata->viewrect_prev = customdata->edgepan_data.initial_rect;
if (t->modifiers & MOD_NODE_ATTACH) {
space_node::node_insert_on_link_flags_set(*snode, *t->region);
}
else {
space_node::node_insert_on_link_flags_clear(*snode->edittree);
}
t->custom.type.data = customdata;
t->custom.type.use_free = true;
@ -245,7 +252,12 @@ static void flushTransNodes(TransInfo *t)
/* handle intersection with noodles */
if (tc->data_len == 1) {
space_node::node_insert_on_link_flags_set(*snode, *t->region);
if (t->modifiers & MOD_NODE_ATTACH) {
space_node::node_insert_on_link_flags_set(*snode, *t->region);
}
else {
space_node::node_insert_on_link_flags_clear(*snode->edittree);
}
}
}
}
@ -279,7 +291,9 @@ static void special_aftertrans_update__node(bContext *C, TransInfo *t)
if (!canceled) {
ED_node_post_apply_transform(C, snode->edittree);
space_node::node_insert_on_link_flags(*bmain, *snode);
if (t->modifiers & MOD_NODE_ATTACH) {
space_node::node_insert_on_link_flags(*bmain, *snode);
}
}
space_node::node_insert_on_link_flags_clear(*ntree);

View File

@ -296,47 +296,48 @@ static void headerTranslation(TransInfo *t, const float vec[3], char str[UI_MAX_
}
}
else {
if (t->flag & T_2D_EDIT) {
ofs += BLI_snprintf_rlen(str + ofs,
UI_MAX_DRAW_STR - ofs,
"Dx: %s Dy: %s (%s)%s",
dvec_str[0],
dvec_str[1],
dist_str,
t->con.text);
if (t->spacetype == SPACE_NODE) {
SpaceNode *snode = (SpaceNode *)t->area->spacedata.first;
if ((snode->flag & SNODE_SKIP_INSOFFSET) == 0) {
const char *str_dir = (snode->insert_ofs_dir == SNODE_INSERTOFS_DIR_RIGHT) ?
TIP_("right") :
TIP_("left");
char str_dir_km[64];
WM_modalkeymap_items_to_string(
t->keymap, TFM_MODAL_INSERTOFS_TOGGLE_DIR, true, str_dir_km, sizeof(str_dir_km));
ofs += BLI_snprintf_rlen(str,
UI_MAX_DRAW_STR,
TIP_("%s: Toggle auto-offset direction (%s)"),
str_dir_km,
str_dir);
}
char str_attach_km[64];
WM_modalkeymap_items_to_string(
t->keymap, TFM_MODAL_NODE_ATTACH_OFF, true, str_attach_km, sizeof(str_attach_km));
ofs += BLI_snprintf_rlen(
str + ofs, UI_MAX_DRAW_STR - ofs, TIP_(", %s: Toggle auto-attach"), str_attach_km);
}
else {
ofs += BLI_snprintf_rlen(str + ofs,
UI_MAX_DRAW_STR - ofs,
"Dx: %s Dy: %s Dz: %s (%s)%s",
dvec_str[0],
dvec_str[1],
dvec_str[2],
dist_str,
t->con.text);
}
}
if (t->spacetype == SPACE_NODE) {
SpaceNode *snode = (SpaceNode *)t->area->spacedata.first;
if ((snode->flag & SNODE_SKIP_INSOFFSET) == 0) {
const char *str_old = BLI_strdup(str);
const char *str_dir = (snode->insert_ofs_dir == SNODE_INSERTOFS_DIR_RIGHT) ? TIP_("right") :
TIP_("left");
char str_km[64];
WM_modalkeymap_items_to_string(
t->keymap, TFM_MODAL_INSERTOFS_TOGGLE_DIR, true, str_km, sizeof(str_km));
ofs += BLI_snprintf_rlen(str,
UI_MAX_DRAW_STR,
TIP_("Auto-offset set to %s - press %s to toggle direction | %s"),
str_dir,
str_km,
str_old);
MEM_freeN((void *)str_old);
if (t->flag & T_2D_EDIT) {
ofs += BLI_snprintf_rlen(str + ofs,
UI_MAX_DRAW_STR - ofs,
"Dx: %s Dy: %s (%s)%s",
dvec_str[0],
dvec_str[1],
dist_str,
t->con.text);
}
else {
ofs += BLI_snprintf_rlen(str + ofs,
UI_MAX_DRAW_STR - ofs,
"Dx: %s Dy: %s Dz: %s (%s)%s",
dvec_str[0],
dvec_str[1],
dvec_str[2],
dist_str,
t->con.text);
}
}
}
}