diff options
author | Martin Poirier <theeth@yahoo.com> | 2009-11-26 22:47:55 +0300 |
---|---|---|
committer | Martin Poirier <theeth@yahoo.com> | 2009-11-26 22:47:55 +0300 |
commit | 74715d00cc466ccb45ed525c12cfd1c7ed29243f (patch) | |
tree | 9c22674e455a5dfc2fdc13f3cb4a8e7a1ad572d2 /source/blender/editors | |
parent | 6ca1c913d3acee63a275259f9a708a1389c23b81 (diff) |
First changes to implement the 2.5 snapping proposal (discussed back in May and recently on IRC).
http://wiki.blender.org/index.php/User:Theeth/Snapping
The new widget isn't there yet, but the rest works, including:
Increment (gears) is now a snap mode
Ctrl click to toggle snap on or off (in transform and 3d view)
Shift+Ctrl click to select snap mode (3d view only)
Snap status (on/off) is persisted in tool settings, no need to always turn it back on when entering transform.
It's still possible to have something resembling the old system by editing the transform modal keymap to snap on on ctrl press and snap off on key release.
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/object/object_ops.c | 4 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_header.c | 64 | ||||
-rw-r--r-- | source/blender/editors/transform/transform.c | 52 | ||||
-rw-r--r-- | source/blender/editors/transform/transform.h | 17 | ||||
-rw-r--r-- | source/blender/editors/transform/transform_constraints.c | 4 | ||||
-rw-r--r-- | source/blender/editors/transform/transform_generics.c | 4 | ||||
-rw-r--r-- | source/blender/editors/transform/transform_ops.c | 44 | ||||
-rw-r--r-- | source/blender/editors/transform/transform_snap.c | 62 |
8 files changed, 145 insertions, 106 deletions
diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c index 522ca45dc3d..c9a0b3f0614 100644 --- a/source/blender/editors/object/object_ops.c +++ b/source/blender/editors/object/object_ops.c @@ -340,10 +340,6 @@ void ED_object_generic_keymap(struct wmKeyConfig *keyconf, struct wmKeyMap *keym { wmKeyMapItem *km; - /* snap */ - km = WM_keymap_add_item(keymap, "WM_OT_context_toggle", TABKEY, KM_PRESS, KM_SHIFT, 0); - RNA_string_set(km->ptr, "path", "scene.tool_settings.snap"); - /* used by mesh, curve & lattice only */ if(do_pet) { /* context ops */ diff --git a/source/blender/editors/space_view3d/view3d_header.c b/source/blender/editors/space_view3d/view3d_header.c index 0ec151046d6..84e54abc20c 100644 --- a/source/blender/editors/space_view3d/view3d_header.c +++ b/source/blender/editors/space_view3d/view3d_header.c @@ -1693,10 +1693,11 @@ static char *snapmode_pup(void) char *str = string; str += sprintf(str, "%s", "Snap Element: %t"); - str += sprintf(str, "%s", "|Vertex%x0"); - str += sprintf(str, "%s", "|Edge%x1"); - str += sprintf(str, "%s", "|Face%x2"); - str += sprintf(str, "%s", "|Volume%x3"); + str += sprintf(str, "%s", "|Increments%x0"); + str += sprintf(str, "%s", "|Vertex%x1"); + str += sprintf(str, "%s", "|Edge%x2"); + str += sprintf(str, "%s", "|Face%x3"); + str += sprintf(str, "%s", "|Volume%x4"); return string; } @@ -2172,36 +2173,37 @@ void uiTemplateHeader3D(uiLayout *layout, struct bContext *C) } /* Snap */ - if (BIF_snappingSupported(obedit)) { - uiBlockBeginAlign(block); + uiBlockBeginAlign(block); - if (ts->snap_flag & SCE_SNAP) { - uiDefIconButBitS(block, TOG, SCE_SNAP, B_REDR, ICON_SNAP_GEO,xco,yco,XIC,YIC, &ts->snap_flag, 0, 0, 0, 0, "Snap with Ctrl during transform (Shift Tab)"); - xco+= XIC; - if(v3d->modeselect == OB_MODE_OBJECT) { - uiDefIconButBitS(block, TOG, SCE_SNAP_ROTATE, B_REDR, ICON_SNAP_NORMAL,xco,yco,XIC,YIC, &ts->snap_flag, 0, 0, 0, 0, "Align rotation with the snapping target"); - xco+= XIC; - } - if (ts->snap_mode == SCE_SNAP_MODE_VOLUME) { - uiDefIconButBitS(block, TOG, SCE_SNAP_PEEL_OBJECT, B_REDR, ICON_SNAP_PEEL_OBJECT,xco,yco,XIC,YIC, &ts->snap_flag, 0, 0, 0, 0, "Consider objects as whole when finding volume center"); - xco+= XIC; - } - if (ts->snap_mode == SCE_SNAP_MODE_FACE) { - uiDefIconButBitS(block, TOG, SCE_SNAP_PROJECT, B_REDR, ICON_RETOPO,xco,yco,XIC,YIC, &ts->snap_flag, 0, 0, 0, 0, "Project elements instead of snapping them"); - xco+= XIC; - } - uiDefIconTextButS(block, ICONTEXTROW,B_REDR, ICON_SNAP_VERTEX, snapmode_pup(), xco,yco,XIC+10,YIC, &(ts->snap_mode), 0.0, 0.0, 0, 0, "Snapping mode"); - xco+= XIC + 10; - uiDefButS(block, MENU, B_NOP, "Snap Mode%t|Closest%x0|Center%x1|Median%x2|Active%x3",xco,yco,70,YIC, &ts->snap_target, 0, 0, 0, 0, "Snap Target Mode"); - xco+= 70; - } else { - uiDefIconButBitS(block, TOG, SCE_SNAP, B_REDR, ICON_SNAP_GEAR,xco,yco,XIC,YIC, &ts->snap_flag, 0, 0, 0, 0, "Snap while Ctrl is held during transform (Shift Tab)"); - xco+= XIC; - } + if (ts->snap_flag & SCE_SNAP) { + uiDefIconButBitS(block, TOG, SCE_SNAP, B_REDR, ICON_SNAP_ON,xco,yco,XIC,YIC, &ts->snap_flag, 0, 0, 0, 0, "Snap during transform (Ctrl)"); + } else { + uiDefIconButBitS(block, TOG, SCE_SNAP, B_REDR, ICON_SNAP_OFF,xco,yco,XIC,YIC, &ts->snap_flag, 0, 0, 0, 0, "Snap during transform (Ctrl)"); + } + xco+= XIC; - uiBlockEndAlign(block); - header_xco_step(ar, &xco, &yco, &maxco, 10); + if(v3d->modeselect == OB_MODE_OBJECT && ts->snap_mode != SCE_SNAP_MODE_INCREMENT) { + uiDefIconButBitS(block, TOG, SCE_SNAP_ROTATE, B_REDR, ICON_SNAP_NORMAL,xco,yco,XIC,YIC, &ts->snap_flag, 0, 0, 0, 0, "Align rotation with the snapping target"); + xco+= XIC; } + if (ts->snap_mode == SCE_SNAP_MODE_VOLUME) { + uiDefIconButBitS(block, TOG, SCE_SNAP_PEEL_OBJECT, B_REDR, ICON_SNAP_PEEL_OBJECT,xco,yco,XIC,YIC, &ts->snap_flag, 0, 0, 0, 0, "Consider objects as whole when finding volume center"); + xco+= XIC; + } + if (ts->snap_mode == SCE_SNAP_MODE_FACE) { + uiDefIconButBitS(block, TOG, SCE_SNAP_PROJECT, B_REDR, ICON_RETOPO,xco,yco,XIC,YIC, &ts->snap_flag, 0, 0, 0, 0, "Project elements instead of snapping them"); + xco+= XIC; + } + uiDefIconTextButS(block, ICONTEXTROW,B_REDR, ICON_SNAP_INCREMENT, snapmode_pup(), xco,yco,XIC+10,YIC, &(ts->snap_mode), 0.0, 0.0, 0, 0, "Snapping mode"); + xco+= XIC + 10; + if(ts->snap_mode != SCE_SNAP_MODE_INCREMENT) { + uiDefButS(block, MENU, B_NOP, "Snap Mode%t|Closest%x0|Center%x1|Median%x2|Active%x3",xco,yco,70,YIC, &ts->snap_target, 0, 0, 0, 0, "Snap Target Mode"); + xco+= 70; + } + + uiBlockEndAlign(block); + header_xco_step(ar, &xco, &yco, &maxco, 10); + /* selection modus */ if(obedit && (obedit->type == OB_MESH)) { diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 775e33e542c..cd267f51601 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -507,9 +507,9 @@ static char *transform_to_undostr(TransInfo *t) #define TFM_MODAL_TRANSLATE 3 #define TFM_MODAL_ROTATE 4 #define TFM_MODAL_RESIZE 5 -#define TFM_MODAL_SNAP_GEARS 6 -#define TFM_MODAL_SNAP_GEARS_OFF 7 -#define TFM_MODAL_SNAP_GEARS_TOGGLE 8 +#define TFM_MODAL_SNAP_ON 6 +#define TFM_MODAL_SNAP_OFF 7 +#define TFM_MODAL_SNAP_TOGGLE 8 /* called in transform_ops.c, on each regeneration of keymaps */ void transform_modal_keymap(wmKeyConfig *keyconf) @@ -520,9 +520,9 @@ void transform_modal_keymap(wmKeyConfig *keyconf) {TFM_MODAL_TRANSLATE, "TRANSLATE", 0, "Translate", ""}, {TFM_MODAL_ROTATE, "ROTATE", 0, "Rotate", ""}, {TFM_MODAL_RESIZE, "RESIZE", 0, "Resize", ""}, - {TFM_MODAL_SNAP_GEARS, "SNAP_GEARS", 0, "Snap On", ""}, - {TFM_MODAL_SNAP_GEARS_OFF, "SNAP_GEARS_OFF", 0, "Snap Off", ""}, - {TFM_MODAL_SNAP_GEARS_TOGGLE, "SNAP_GEARS_TOGGLE", 0, "Snap Toggle", ""}, + {TFM_MODAL_SNAP_ON, "SNAP_ON", 0, "Snap On", ""}, + {TFM_MODAL_SNAP_OFF, "SNAP_OFF", 0, "Snap Off", ""}, + {TFM_MODAL_SNAP_TOGGLE, "SNAP_TOGGLE", 0, "Snap Toggle", ""}, {0, NULL, 0, NULL, NULL}}; wmKeyMap *keymap= WM_modalkeymap_get(keyconf, "Transform Modal Map"); @@ -542,7 +542,7 @@ void transform_modal_keymap(wmKeyConfig *keyconf) WM_modalkeymap_add_item(keymap, RKEY, KM_PRESS, 0, 0, TFM_MODAL_ROTATE); WM_modalkeymap_add_item(keymap, SKEY, KM_PRESS, 0, 0, TFM_MODAL_RESIZE); - WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_PRESS, KM_ANY, 0, TFM_MODAL_SNAP_GEARS_TOGGLE); + WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_CLICK, KM_ANY, 0, TFM_MODAL_SNAP_TOGGLE); /* assign map to operators */ WM_modalkeymap_assign(keymap, "TFM_OT_transform"); @@ -629,16 +629,16 @@ void transformEvent(TransInfo *t, wmEvent *event) } break; - case TFM_MODAL_SNAP_GEARS: - t->modifiers |= MOD_SNAP_GEARS; + case TFM_MODAL_SNAP_ON: + t->modifiers |= MOD_SNAP; t->redraw = 1; break; - case TFM_MODAL_SNAP_GEARS_OFF: - t->modifiers &= ~MOD_SNAP_GEARS; + case TFM_MODAL_SNAP_OFF: + t->modifiers &= ~MOD_SNAP; t->redraw = 1; break; - case TFM_MODAL_SNAP_GEARS_TOGGLE: - t->modifiers ^= MOD_SNAP_GEARS; + case TFM_MODAL_SNAP_TOGGLE: + t->modifiers ^= MOD_SNAP; t->redraw = 1; break; } @@ -1280,28 +1280,30 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op) } // If modal, save settings back in scene if not set as operator argument - if (t->flag & T_MODAL) - { + if (t->flag & T_MODAL) { + /* save settings if not set in operator */ - if (RNA_struct_find_property(op->ptr, "proportional") && !RNA_property_is_set(op->ptr, "proportional")) - { + if (RNA_struct_find_property(op->ptr, "proportional") && !RNA_property_is_set(op->ptr, "proportional")) { ts->proportional = proportional; } - if (RNA_struct_find_property(op->ptr, "proportional_size") && !RNA_property_is_set(op->ptr, "proportional_size")) - { + if (RNA_struct_find_property(op->ptr, "proportional_size") && !RNA_property_is_set(op->ptr, "proportional_size")) { ts->proportional_size = t->prop_size; } - if (RNA_struct_find_property(op->ptr, "proportional_editing_falloff") && !RNA_property_is_set(op->ptr, "proportional_editing_falloff")) - { + if (RNA_struct_find_property(op->ptr, "proportional_editing_falloff") && !RNA_property_is_set(op->ptr, "proportional_editing_falloff")) { ts->prop_mode = t->prop_mode; } - if(t->spacetype == SPACE_VIEW3D) - { - if (RNA_struct_find_property(op->ptr, "constraint_orientation") && !RNA_property_is_set(op->ptr, "constraint_orientation")) - { + /* do we check for parameter? */ + if (t->modifiers & MOD_SNAP) { + ts->snap_flag |= SCE_SNAP; + } else { + ts->snap_flag &= ~SCE_SNAP; + } + + if(t->spacetype == SPACE_VIEW3D) { + if (RNA_struct_find_property(op->ptr, "constraint_orientation") && !RNA_property_is_set(op->ptr, "constraint_orientation")) { View3D *v3d = t->view; v3d->twmode = t->current_orientation; diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h index b8ef50507d3..1d284d2cc5b 100644 --- a/source/blender/editors/transform/transform.h +++ b/source/blender/editors/transform/transform.h @@ -83,11 +83,13 @@ typedef struct NumInput { */ typedef struct TransSnap { + short mode; short modePoint; short modeTarget; - short mode; + short modeSelect; short align; short project; + short peel; short status; float snapPoint[3]; /* snapping from this point */ float snapTarget[3]; /* to this point */ @@ -371,7 +373,7 @@ typedef struct TransInfo { /* TransInfo->modifiers */ #define MOD_CONSTRAINT_SELECT 0x01 #define MOD_PRECISION 0x02 -#define MOD_SNAP_GEARS 0x04 +#define MOD_SNAP 0x04 #define MOD_CONSTRAINT_PLANE 0x08 @@ -412,14 +414,9 @@ typedef struct TransInfo { #define TD_MIRROR_EDGE (1 << 16) /* For editmode mirror, clamp to x = 0 */ /* transsnap->status */ -#define SNAP_ON 1 -#define SNAP_FORCED 2 -#define TARGET_INIT 4 -#define POINT_INIT 8 - -/* transsnap->modePoint */ -#define SNAP_GRID 0 -#define SNAP_GEO 1 +#define SNAP_FORCED 1 +#define TARGET_INIT 2 +#define POINT_INIT 4 /* transsnap->modeTarget */ #define SNAP_CLOSEST 0 diff --git a/source/blender/editors/transform/transform_constraints.c b/source/blender/editors/transform/transform_constraints.c index da8f0c4d0e9..f59803924d5 100644 --- a/source/blender/editors/transform/transform_constraints.c +++ b/source/blender/editors/transform/transform_constraints.c @@ -290,7 +290,7 @@ static void applyAxisConstraintVec(TransInfo *t, TransData *td, float in[3], flo mul_m3_v3(t->con.pmtx, out); // With snap, a projection is alright, no need to correct for view alignment - if ((t->tsnap.status & SNAP_ON) == 0) { + if (!(t->tsnap.mode != SCE_SNAP_MODE_INCREMENT && t->modifiers & MOD_SNAP)) { if (getConstraintSpaceDimension(t) == 2) { if (out[0] != 0.0f || out[1] != 0.0f || out[2] != 0.0f) { planeProjection(t, in, out); @@ -316,7 +316,7 @@ static void applyAxisConstraintVec(TransInfo *t, TransData *td, float in[3], flo } /* - * Generic callback for object based spacial constraints applied to linear motion + * Generic callback for object based spatial constraints applied to linear motion * * At first, the following is applied to the first data in the array * The IN vector in projected into the constrained space and then further diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c index d3c0e91e57c..7fa4f8b0ffc 100644 --- a/source/blender/editors/transform/transform_generics.c +++ b/source/blender/editors/transform/transform_generics.c @@ -1048,6 +1048,10 @@ int initTransInfo (bContext *C, TransInfo *t, wmOperator *op, wmEvent *event) t->options |= CTX_NO_PET; } + /* Snapping */ + if (ts->snap_flag & SCE_SNAP) { + t->modifiers |= MOD_SNAP; + } setTransformViewMatrices(t); initNumInput(&t->num); diff --git a/source/blender/editors/transform/transform_ops.c b/source/blender/editors/transform/transform_ops.c index 67b7f60e728..e01f4373516 100644 --- a/source/blender/editors/transform/transform_ops.c +++ b/source/blender/editors/transform/transform_ops.c @@ -84,6 +84,38 @@ TransformModeItem transform_modes[] = {NULL, 0} }; +static int snap_type_exec(bContext *C, wmOperator *op) +{ + ToolSettings *ts= CTX_data_tool_settings(C); + + ts->snap_mode = RNA_enum_get(op->ptr,"type"); + + WM_event_add_notifier(C, NC_SCENE|ND_MODE, NULL); /* header redraw */ + + return OPERATOR_FINISHED; +} + +void TFM_OT_snap_type(wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Snap Type"; + ot->description= "Set the snap element type."; + ot->idname= "TFM_OT_snap_type"; + + /* api callbacks */ + ot->invoke= WM_menu_invoke; + ot->exec= snap_type_exec; + + ot->poll= ED_operator_areaactive; + + /* flags */ + ot->flag= OPTYPE_UNDO; + + /* props */ + RNA_def_enum(ot->srna, "type", snap_element_items, 0, "Type", "Set the snap element type"); + +} + static int select_orientation_exec(bContext *C, wmOperator *op) { int orientation = RNA_enum_get(op->ptr, "orientation"); @@ -344,7 +376,7 @@ void Properties_Proportional(struct wmOperatorType *ot) void Properties_Snapping(struct wmOperatorType *ot, short align) { RNA_def_boolean(ot->srna, "snap", 0, "Snap to Point", ""); - RNA_def_enum(ot->srna, "snap_mode", snap_mode_items, 0, "Mode", ""); + RNA_def_enum(ot->srna, "snap_target", snap_target_items, 0, "Target", ""); RNA_def_float_vector(ot->srna, "snap_point", 3, NULL, -FLT_MAX, FLT_MAX, "Point", "", -FLT_MAX, FLT_MAX); if (align) @@ -700,6 +732,8 @@ void transform_operatortypes(void) WM_operatortype_append(TFM_OT_select_orientation); WM_operatortype_append(TFM_OT_create_orientation); WM_operatortype_append(TFM_OT_delete_orientation); + + WM_operatortype_append(TFM_OT_snap_type); } void transform_keymap_for_space(struct wmKeyConfig *keyconf, struct wmKeyMap *keymap, int spaceid) @@ -737,6 +771,11 @@ void transform_keymap_for_space(struct wmKeyConfig *keyconf, struct wmKeyMap *ke km = WM_keymap_add_item(keymap, "TFM_OT_mirror", MKEY, KM_PRESS, KM_CTRL, 0); + km = WM_keymap_add_item(keymap, "WM_OT_context_toggle", LEFTCTRLKEY, KM_CLICK, 0, 0); + RNA_string_set(km->ptr, "path", "scene.tool_settings.snap"); + + km = WM_keymap_add_item(keymap, "TFM_OT_snap_type", LEFTCTRLKEY, KM_CLICK, KM_SHIFT, 0); + break; case SPACE_ACTION: km= WM_keymap_add_item(keymap, "TFM_OT_transform", GKEY, KM_PRESS, 0, 0); @@ -808,6 +847,9 @@ void transform_keymap_for_space(struct wmKeyConfig *keyconf, struct wmKeyMap *ke km = WM_keymap_add_item(keymap, "TFM_OT_resize", SKEY, KM_PRESS, 0, 0); km = WM_keymap_add_item(keymap, "TFM_OT_mirror", MKEY, KM_PRESS, KM_CTRL, 0); + + km = WM_keymap_add_item(keymap, "WM_OT_context_toggle", LEFTCTRLKEY, KM_CLICK, 0, 0); + RNA_string_set(km->ptr, "path", "scene.tool_settings.snap"); break; default: break; diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c index be3d3579344..bbea9d4ba25 100644 --- a/source/blender/editors/transform/transform_snap.c +++ b/source/blender/editors/transform/transform_snap.c @@ -125,8 +125,8 @@ int BIF_snappingSupported(Object *obedit) void drawSnapping(const struct bContext *C, TransInfo *t) { - if ((t->tsnap.status & (SNAP_ON|POINT_INIT|TARGET_INIT)) == (SNAP_ON|POINT_INIT|TARGET_INIT) && - (t->modifiers & MOD_SNAP_GEARS)) + if ((t->tsnap.status & (POINT_INIT|TARGET_INIT)) == (POINT_INIT|TARGET_INIT) && + (t->modifiers & MOD_SNAP)) { char col[4] = {1, 0, 1}; @@ -205,7 +205,8 @@ void drawSnapping(const struct bContext *C, TransInfo *t) int handleSnapping(TransInfo *t, wmEvent *event) { int status = 0; - + +#if 0 // XXX need a proper selector for all snap mode if (BIF_snappingSupported(t->obedit) && event->type == TABKEY && event->shift) { /* toggle snap and reinit */ @@ -213,6 +214,7 @@ int handleSnapping(TransInfo *t, wmEvent *event) initSnapping(t, NULL); status = 1; } +#endif return status; } @@ -220,7 +222,7 @@ int handleSnapping(TransInfo *t, wmEvent *event) void applyProject(TransInfo *t) { /* XXX FLICKER IN OBJECT MODE */ - if ((t->tsnap.project) && (t->tsnap.status & SNAP_ON) && (t->modifiers & MOD_SNAP_GEARS)) + if ((t->tsnap.project) && (t->modifiers & MOD_SNAP) && (t->modifiers & MOD_SNAP)) { TransData *td = t->data; float tvec[3]; @@ -256,7 +258,7 @@ void applyProject(TransInfo *t) project_float(t->ar, iloc, mval); - if (snapObjectsTransform(t, mval, &dist, loc, no, t->tsnap.mode)) + if (snapObjectsTransform(t, mval, &dist, loc, no, t->tsnap.modeTarget)) { // if(t->flag & (T_EDIT|T_POSE)) { // mul_m4_v3(imat, loc); @@ -286,8 +288,8 @@ void applySnapping(TransInfo *t, float *vec) t->tsnap.applySnap(t, vec); } - else if ((t->tsnap.status & SNAP_ON) && - (t->modifiers & MOD_SNAP_GEARS)) + else if ((t->tsnap.mode != SCE_SNAP_MODE_INCREMENT) && + (t->modifiers & MOD_SNAP)) { double current = PIL_check_seconds_timer(); @@ -310,9 +312,9 @@ void applySnapping(TransInfo *t, float *vec) void resetSnapping(TransInfo *t) { t->tsnap.status = 0; - t->tsnap.mode = 0; t->tsnap.align = 0; - t->tsnap.modePoint = 0; + t->tsnap.mode = 0; + t->tsnap.modeSelect = 0; t->tsnap.modeTarget = 0; t->tsnap.last = 0; t->tsnap.applySnap = NULL; @@ -346,7 +348,7 @@ void initSnapping(TransInfo *t, wmOperator *op) Object *obedit = t->obedit; Scene *scene = t->scene; int snapping = 0; - short snap_mode = t->settings->snap_target; + short snap_target = t->settings->snap_target; resetSnapping(t); @@ -355,7 +357,7 @@ void initSnapping(TransInfo *t, wmOperator *op) if (RNA_boolean_get(op->ptr, "snap")) { snapping = 1; - snap_mode = RNA_enum_get(op->ptr, "snap_mode"); + snap_target = RNA_enum_get(op->ptr, "snap_target"); t->tsnap.status |= SNAP_FORCED|POINT_INIT; RNA_float_get_array(op->ptr, "snap_point", t->tsnap.snapPoint); @@ -379,6 +381,7 @@ void initSnapping(TransInfo *t, wmOperator *op) snapping = ((ts->snap_flag & SCE_SNAP) == SCE_SNAP); t->tsnap.align = ((t->settings->snap_flag & SCE_SNAP_ROTATE) == SCE_SNAP_ROTATE); t->tsnap.project = ((t->settings->snap_flag & SCE_SNAP_PROJECT) == SCE_SNAP_PROJECT); + t->tsnap.peel = ((t->settings->snap_flag & SCE_SNAP_PROJECT) == SCE_SNAP_PROJECT); } /* force project off when not supported */ @@ -387,25 +390,23 @@ void initSnapping(TransInfo *t, wmOperator *op) t->tsnap.project = 0; } + t->tsnap.mode = ts->snap_mode; + if ((t->spacetype == SPACE_VIEW3D || t->spacetype == SPACE_IMAGE) && // Only 3D view or UV - (t->flag & T_CAMERA) == 0) { // Not with camera selected - setSnappingCallback(t, snap_mode); + (t->flag & T_CAMERA) == 0) { // Not with camera selected in camera view + setSnappingCallback(t, snap_target); /* Edit mode */ if (t->tsnap.applySnap != NULL && // A snapping function actually exist - (snapping) && // Only if the snap flag is on (obedit != NULL && ELEM3(obedit->type, OB_MESH, OB_ARMATURE, OB_CURVE)) ) // Temporary limited to edit mode meshes, armature, curves { - t->tsnap.status |= SNAP_ON; - t->tsnap.modePoint = SNAP_GEO; - if (t->flag & T_PROP_EDIT) { - t->tsnap.mode = SNAP_NOT_OBEDIT; + t->tsnap.modeSelect = SNAP_NOT_OBEDIT; } else { - t->tsnap.mode = SNAP_ALL; + t->tsnap.modeSelect = SNAP_ALL; } } /* Particles edit mode*/ @@ -413,29 +414,24 @@ void initSnapping(TransInfo *t, wmOperator *op) (snapping) && // Only if the snap flag is on (obedit == NULL && BASACT->object && BASACT->object->mode & OB_MODE_PARTICLE_EDIT )) { - t->tsnap.status |= SNAP_ON; - t->tsnap.modePoint = SNAP_GEO; - t->tsnap.mode = SNAP_ALL; + t->tsnap.modeSelect = SNAP_ALL; } /* Object mode */ else if (t->tsnap.applySnap != NULL && // A snapping function actually exist - (snapping) && // Only if the snap flag is on (obedit == NULL) ) // Object Mode { - t->tsnap.status |= SNAP_ON; - t->tsnap.modePoint = SNAP_GEO; - t->tsnap.mode = SNAP_NOT_SELECTED; + t->tsnap.modeSelect = SNAP_NOT_SELECTED; } else { /* Grid if snap is not possible */ - t->tsnap.modePoint = SNAP_GRID; + t->tsnap.mode = SCE_SNAP_MODE_INCREMENT; } } else { /* Always grid outside of 3D view */ - t->tsnap.modePoint = SNAP_GRID; + t->tsnap.mode = SCE_SNAP_MODE_INCREMENT; } } @@ -627,7 +623,7 @@ void CalcSnapGeometry(TransInfo *t, float *vec) mval[0] = t->mval[0]; mval[1] = t->mval[1]; - if (t->settings->snap_mode == SCE_SNAP_MODE_VOLUME) + if (t->tsnap.mode == SCE_SNAP_MODE_VOLUME) { ListBase depth_peels; DepthPeel *p1, *p2; @@ -720,7 +716,7 @@ void CalcSnapGeometry(TransInfo *t, float *vec) } else { - found = snapObjectsTransform(t, mval, &dist, loc, no, t->tsnap.mode); + found = snapObjectsTransform(t, mval, &dist, loc, no, t->tsnap.modeSelect); } if (found == 1) @@ -1828,7 +1824,7 @@ void snapGrid(TransInfo *t, float *val) { GearsType action; // Only do something if using Snap to Grid - if (t->tsnap.modePoint != SNAP_GRID) + if (t->tsnap.mode != SCE_SNAP_MODE_INCREMENT) return; if(t->mode==TFM_ROTATION || t->mode==TFM_WARP || t->mode==TFM_TILT || t->mode==TFM_TRACKBALL || t->mode==TFM_BONE_ROLL) @@ -1839,10 +1835,10 @@ void snapGrid(TransInfo *t, float *val) { invert = U.flag & USER_AUTOGRABGRID; if(invert) { - action = (t->modifiers & MOD_SNAP_GEARS) ? NO_GEARS: BIG_GEARS; + action = (t->modifiers & MOD_SNAP) ? NO_GEARS: BIG_GEARS; } else { - action = (t->modifiers & MOD_SNAP_GEARS) ? BIG_GEARS : NO_GEARS; + action = (t->modifiers & MOD_SNAP) ? BIG_GEARS : NO_GEARS; } if (action == BIG_GEARS && (t->modifiers & MOD_PRECISION)) { |