Add missing snap properties to transform operator.
authorMartin Poirier <theeth@yahoo.com>
Fri, 27 Nov 2009 16:15:34 +0000 (16:15 +0000)
committerMartin Poirier <theeth@yahoo.com>
Fri, 27 Nov 2009 16:15:34 +0000 (16:15 +0000)
This is used to force snap on and off when needed.

Also, when transform is not run modal, it will use default values for PET and snap properties (False) instead of scene settings. No need to force them off when calling transform with Exec.

release/scripts/op/wm.py
source/blender/editors/include/ED_transform.h
source/blender/editors/transform/transform_generics.c
source/blender/editors/transform/transform_ops.c
source/blender/editors/transform/transform_snap.c

index f4cb136693ffbbe9b533079ace02c770add089c1..f93c0d47e28e29fd7d8331654df921df80c43cd1 100644 (file)
@@ -30,14 +30,10 @@ class MESH_OT_delete_edgeloop(bpy.types.Operator):
     bl_label = "Delete Edge Loop"
 
     def execute(self, context):
-        snap = bpy.context.scene.tool_settings.snap
-        bpy.context.scene.tool_settings.snap = False
-        
         bpy.ops.tfm.edge_slide(value=1.0)
         bpy.ops.mesh.select_more()
         bpy.ops.mesh.remove_doubles()
         
-        bpy.context.scene.tool_settings.snap = snap
         return ('FINISHED',)
 
 rna_path_prop = StringProperty(name="Context Attributes",
index 0f17599daae2df587613f7702faf4d564030cf71..065867a3bb36d3f1af453198d59b86bd9fea856e 100644 (file)
@@ -135,7 +135,7 @@ void BIF_selectOrientation(void);
 /* to be able to add operator properties to other operators */
 
 void Properties_Proportional(struct wmOperatorType *ot);
-void Properties_Snapping(struct wmOperatorType *ot, short align);
+void Properties_Snapping(struct wmOperatorType *ot, short fullsnap, short align);
 void Properties_Constraints(struct wmOperatorType *ot);
 
 /* view3d manipulators */
index 7fa4f8b0ffc9e26d7a46b62f96409d61abc48aa0..8b7c4b7503b7f5a1c7b84f451306ddfd6644daf6 100644 (file)
@@ -930,6 +930,11 @@ int initTransInfo (bContext *C, TransInfo *t, wmOperator *op, wmEvent *event)
        
        unit_m3(t->mat);
        
+       /* if there's an event, we're modal */
+       if (event) {
+               t->flag |= T_MODAL;
+       }
+
        t->spacetype = sa->spacetype;
        if(t->spacetype == SPACE_VIEW3D)
        {
@@ -1010,11 +1015,15 @@ int initTransInfo (bContext *C, TransInfo *t, wmOperator *op, wmEvent *event)
                }
                else
                {
-                       if ((t->options & CTX_NO_PET) == 0 && (ts->proportional != PROP_EDIT_OFF)) {
-                               t->flag |= T_PROP_EDIT;
-                               
-                               if(ts->proportional == PROP_EDIT_CONNECTED)
-                                       t->flag |= T_PROP_CONNECTED;
+                       /* use settings from scene only if modal */
+                       if (t->flag & T_MODAL)
+                       {
+                               if ((t->options & CTX_NO_PET) == 0 && (ts->proportional != PROP_EDIT_OFF)) {
+                                       t->flag |= T_PROP_EDIT;
+
+                                       if(ts->proportional == PROP_EDIT_CONNECTED)
+                                               t->flag |= T_PROP_CONNECTED;
+                               }
                        }
                }
                
@@ -1048,11 +1057,6 @@ 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);
        initNDofInput(&t->ndof);
index e01f437351682edcc6f54d3377c5b6c324176a4b..0c54b5273e3e807c680f976eccad6c0b07de5dd1 100644 (file)
@@ -354,13 +354,9 @@ static int transform_invoke(bContext *C, wmOperator *op, wmEvent *event)
                return transform_exec(C, op);
        }
        else {
-               TransInfo *t = op->customdata;
-
                /* add temp handler */
                WM_event_add_modal_handler(C, op);
 
-               t->flag |= T_MODAL; // XXX meh maybe somewhere else
-
                op->flag |= OP_GRAB_POINTER; // XXX maybe we want this with the manipulator only?
                return OPERATOR_RUNNING_MODAL;
        }
@@ -373,16 +369,18 @@ void Properties_Proportional(struct wmOperatorType *ot)
        RNA_def_float(ot->srna, "proportional_size", 1, 0, FLT_MAX, "Proportional Size", "", 0, 100);
 }
 
-void Properties_Snapping(struct wmOperatorType *ot, short align)
+void Properties_Snapping(struct wmOperatorType *ot, short fullsnap, short align)
 {
-       RNA_def_boolean(ot->srna, "snap", 0, "Snap to Point", "");
-       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);
+       RNA_def_boolean(ot->srna, "snap", 0, "Use Snapping Options", "");
 
-       if (align)
-       {
-               RNA_def_boolean(ot->srna, "snap_align", 0, "Align with Point Normal", "");
-               RNA_def_float_vector(ot->srna, "snap_normal", 3, NULL, -FLT_MAX, FLT_MAX, "Normal", "", -FLT_MAX, FLT_MAX);
+       if (fullsnap) {
+               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) {
+                       RNA_def_boolean(ot->srna, "snap_align", 0, "Align with Point Normal", "");
+                       RNA_def_float_vector(ot->srna, "snap_normal", 3, NULL, -FLT_MAX, FLT_MAX, "Normal", "", -FLT_MAX, FLT_MAX);
+               }
        }
 }
 
@@ -419,7 +417,7 @@ void TFM_OT_translate(struct wmOperatorType *ot)
 
        Properties_Constraints(ot);
 
-       Properties_Snapping(ot, 1);
+       Properties_Snapping(ot, 1, 1);
 }
 
 void TFM_OT_resize(struct wmOperatorType *ot)
@@ -445,7 +443,7 @@ void TFM_OT_resize(struct wmOperatorType *ot)
 
        Properties_Constraints(ot);
 
-       Properties_Snapping(ot, 0);
+       Properties_Snapping(ot, 1, 0);
 }
 
 
@@ -469,6 +467,8 @@ void TFM_OT_trackball(struct wmOperatorType *ot)
        Properties_Proportional(ot);
 
        RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
+
+       Properties_Snapping(ot, 0, 0);
 }
 
 void TFM_OT_rotate(struct wmOperatorType *ot)
@@ -494,7 +494,7 @@ void TFM_OT_rotate(struct wmOperatorType *ot)
 
        Properties_Constraints(ot);
 
-       Properties_Snapping(ot, 0);
+       Properties_Snapping(ot, 1, 0);
 }
 
 void TFM_OT_tilt(struct wmOperatorType *ot)
@@ -522,6 +522,8 @@ void TFM_OT_tilt(struct wmOperatorType *ot)
        RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
 
        Properties_Constraints(ot);
+
+       Properties_Snapping(ot, 0, 0);
 }
 
 void TFM_OT_warp(struct wmOperatorType *ot)
@@ -545,7 +547,9 @@ void TFM_OT_warp(struct wmOperatorType *ot)
 
        RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
 
-       // XXX Shear axis?
+       Properties_Snapping(ot, 0, 0);
+
+       // XXX Warp axis?
 //     Properties_Constraints(ot);
 }
 
@@ -570,6 +574,8 @@ void TFM_OT_shear(struct wmOperatorType *ot)
 
        RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
 
+       Properties_Snapping(ot, 0, 0);
+
        // XXX Shear axis?
 //     Properties_Constraints(ot);
 }
@@ -594,6 +600,8 @@ void TFM_OT_shrink_fatten(struct wmOperatorType *ot)
        Properties_Proportional(ot);
 
        RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
+
+       Properties_Snapping(ot, 0, 0);
 }
 
 void TFM_OT_tosphere(struct wmOperatorType *ot)
@@ -617,6 +625,8 @@ void TFM_OT_tosphere(struct wmOperatorType *ot)
        Properties_Proportional(ot);
 
        RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
+
+       Properties_Snapping(ot, 0, 0);
 }
 
 void TFM_OT_mirror(struct wmOperatorType *ot)
@@ -656,6 +666,8 @@ void TFM_OT_edge_slide(struct wmOperatorType *ot)
        RNA_def_float_factor(ot->srna, "value", 0, -1.0f, 1.0f, "Factor", "", -1.0f, 1.0f);
 
        RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
+
+       Properties_Snapping(ot, 0, 0);
 }
 
 void TFM_OT_transform(struct wmOperatorType *ot)
index bbea9d4ba25e8989a1f8a01b193b433b62b864b1..d36b7c9b903454bffa0f7dcaa14f75d00f7b3c82 100644 (file)
@@ -347,20 +347,27 @@ void initSnapping(TransInfo *t, wmOperator *op)
        ToolSettings *ts = t->settings;
        Object *obedit = t->obedit;
        Scene *scene = t->scene;
-       int snapping = 0;
        short snap_target = t->settings->snap_target;
        
        resetSnapping(t);
        
+       /* if snap property exists */
        if (op && RNA_struct_find_property(op->ptr, "snap") && RNA_property_is_set(op->ptr, "snap"))
        {
                if (RNA_boolean_get(op->ptr, "snap"))
                {
-                       snapping = 1;
-                       snap_target = RNA_enum_get(op->ptr, "snap_target");
+                       t->modifiers |= MOD_SNAP;
+
+                       if (RNA_property_is_set(op->ptr, "snap_target"))
+                       {
+                               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);
+                       if (RNA_property_is_set(op->ptr, "snap_point"))
+                       {
+                               RNA_float_get_array(op->ptr, "snap_point", t->tsnap.snapPoint);
+                               t->tsnap.status |= SNAP_FORCED|POINT_INIT;
+                       }
                        
                        /* snap align only defined in specific cases */
                        if (RNA_struct_find_property(op->ptr, "snap_align"))
@@ -376,9 +383,13 @@ void initSnapping(TransInfo *t, wmOperator *op)
                        }
                }
        }
-       else
+       /* use scene defaults only when transform is modal */
+       else if (t->flag & T_MODAL)
        {
-               snapping = ((ts->snap_flag & SCE_SNAP) == SCE_SNAP);
+               if (ts->snap_flag & SCE_SNAP) {
+                       t->modifiers |= MOD_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);
@@ -411,7 +422,6 @@ void initSnapping(TransInfo *t, wmOperator *op)
                }
                /* Particles edit mode*/
                else if (t->tsnap.applySnap != NULL && // A snapping function actually exist
-                       (snapping) && // Only if the snap flag is on
                        (obedit == NULL && BASACT->object && BASACT->object->mode & OB_MODE_PARTICLE_EDIT ))
                {
                        t->tsnap.modeSelect = SNAP_ALL;