Make edge slide a proper operator
authorMartin Poirier <theeth@yahoo.com>
Tue, 22 Sep 2009 20:16:56 +0000 (20:16 +0000)
committerMartin Poirier <theeth@yahoo.com>
Tue, 22 Sep 2009 20:16:56 +0000 (20:16 +0000)
Clean up a couple of things in transform (PET settings, custom data, ...)

source/blender/editors/mesh/mesh_ops.c
source/blender/editors/transform/transform.c
source/blender/editors/transform/transform.h
source/blender/editors/transform/transform_conversions.c
source/blender/editors/transform/transform_generics.c
source/blender/editors/transform/transform_ops.c

index 3f1bbbb9097e6070ba76b1f0a0b2beef9f1d4520..a79b42dcbb80b286d6e08e483a343002651ba164 100644 (file)
@@ -113,7 +113,7 @@ static int edge_specials_invoke(bContext *C, wmOperator *op, wmEvent *event)
        uiItemEnumO(layout, "Rotate Edge CCW", 0, "MESH_OT_edge_rotate", "direction", 2);
        //uiItemO(layout, "Loopcut", 0, "MESH_OT_loop_cut"); // CutEdgeloop(em, 1);
        //uiItemO(layout, "Edge Slide", 0, "MESH_OT_edge_slide"); // EdgeSlide(em, 0,0.0);
-       uiItemEnumO(layout, "Edge Slide", 0, "TFM_OT_transform", "mode", TFM_EDGE_SLIDE);
+       uiItemO(layout, "Edge Slide", 0, "TFM_OT_edge_slide");
        uiItemO(layout, "Edge Loop", 0, "MESH_OT_loop_multi_select");
        uiItemBooleanO(layout, "Edge Ring", 0, "MESH_OT_loop_multi_select", "ring", 1);
        uiItemO(layout, NULL, 0, "MESH_OT_loop_to_region");
index 6dec51945ce80140603eb6f5811c9f1e23a0925f..ca9981bc5903fa133c5dc6035d109bc28baf314b 100644 (file)
@@ -1321,7 +1321,12 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
        if (t->flag & T_MODAL)
        {
                ts->prop_mode = t->prop_mode;
-               ts->proportional = proportional;
+               
+               /* only save back if it wasn't automatically disabled */
+               if ((t->options & CTX_NO_PET) == 0)
+               {
+                       ts->proportional = proportional;
+               }
 
                if(t->spacetype == SPACE_VIEW3D)
                {
@@ -4500,19 +4505,52 @@ static int createSlideVerts(TransInfo *t)
        return 1;
 }
 
+void freeSlideVerts(TransInfo *t)
+{
+       TransDataSlideUv *suv;
+       SlideData *sld = t->customData;
+       int uvlay_idx;
+
+       //BLI_ghash_free(edgesgh, freeGHash, NULL);
+       BLI_ghash_free(sld->vhash, NULL, (GHashValFreeFP)MEM_freeN);
+       BLI_linklist_free(sld->vertlist, NULL);
+       BLI_linklist_free(sld->edgelist, NULL);
+
+       if (sld->uvlay_tot) {
+               for (uvlay_idx=0; uvlay_idx<sld->uvlay_tot; uvlay_idx++) {
+                       BLI_ghash_free(sld->uvhash[uvlay_idx], NULL, NULL);
+               }
+               MEM_freeN(sld->slideuv);
+               MEM_freeN(sld->uvhash);
+
+               suv = sld->suv_last-1;
+               while (suv >= sld->slideuv) {
+                       if (suv->fuv_list) {
+                               BLI_linklist_free(suv->fuv_list,NULL);
+                       }
+                       suv--;
+               }
+       }
+
+       MEM_freeN(sld);
+       t->customData = NULL;
+}
+
 void initEdgeSlide(TransInfo *t)
 {
        SlideData *sld;
 
        t->mode = TFM_EDGE_SLIDE;
        t->transform = EdgeSlide;
-
+       
        createSlideVerts(t);
        sld = t->customData;
 
        if (!sld)
                return;
 
+       t->customFree = freeSlideVerts;
+
        initMouseInputMode(t, &t->mouse, INPUT_CUSTOM_RATIO);
        setCustomPoints(t, &t->mouse, sld->end, sld->start);
        
@@ -4639,36 +4677,6 @@ int doEdgeSlide(TransInfo *t, float perc)
        return 1;
 }
 
-void freeSlideVerts(TransInfo *t)
-{
-       TransDataSlideUv *suv;
-       SlideData *sld = t->customData;
-       int uvlay_idx;
-
-       //BLI_ghash_free(edgesgh, freeGHash, NULL);
-       BLI_ghash_free(sld->vhash, NULL, (GHashValFreeFP)MEM_freeN);
-       BLI_linklist_free(sld->vertlist, NULL);
-       BLI_linklist_free(sld->edgelist, NULL);
-
-       if (sld->uvlay_tot) {
-               for (uvlay_idx=0; uvlay_idx<sld->uvlay_tot; uvlay_idx++) {
-                       BLI_ghash_free(sld->uvhash[uvlay_idx], NULL, NULL);
-               }
-               MEM_freeN(sld->slideuv);
-               MEM_freeN(sld->uvhash);
-
-               suv = sld->suv_last-1;
-               while (suv >= sld->slideuv) {
-                       if (suv->fuv_list) {
-                               BLI_linklist_free(suv->fuv_list,NULL);
-                       }
-                       suv--;
-               }
-       }
-
-       MEM_freeN(sld);
-}
-
 int EdgeSlide(TransInfo *t, short mval[2])
 {
        TransData *td = t->data;
index 404257a55ff59c0f1fdb8a61e5fa950eff6a23c2..66d5ecd4d66769866e2b30ad614d36830e3f7c61 100644 (file)
@@ -291,6 +291,7 @@ typedef struct TransInfo {
        struct Object *poseobj;         /* if t->flag & T_POSE, this denotes pose object */
 
        void       *customData;         /* Per Transform custom data */
+       void      (*customFree)(struct TransInfo *); /* if a special free function is needed */
 
        /*************** NEW STUFF *********************/
 
index 64151918a47971983c33ecbab6fb529d43306edc..543bbf13fcc1d2f2b43474038cad05c4d1b15f3d 100644 (file)
@@ -5312,6 +5312,8 @@ void createTransData(bContext *C, TransInfo *t)
        }
        else {
                t->flag &= ~T_PROP_EDIT; /* no proportional edit in object mode */
+               t->options |= CTX_NO_PET;
+               
                createTransObject(C, t);
                t->flag |= T_OBJECT;
 
index 59429d65e7bdc8daa6e8acf9e3a48533f13c4632..ea5653dc1305f1661ee6f24e76ac880f4165cf0d 100644 (file)
@@ -978,51 +978,60 @@ int initTransInfo (bContext *C, TransInfo *t, wmOperator *op, wmEvent *event)
                }
        }
 
-       /* setting PET flag */
-       if (op && RNA_struct_find_property(op->ptr, "proportional") && RNA_property_is_set(op->ptr, "proportional"))
+       /* setting PET flag only if property exist in operator. Otherwise, assume it's not supported */
+       if (op && RNA_struct_find_property(op->ptr, "proportional"))
        {
-               switch(RNA_enum_get(op->ptr, "proportional"))
+               if (RNA_property_is_set(op->ptr, "proportional"))
                {
-               case 2: /* XXX connected constant */
-                       t->flag |= T_PROP_CONNECTED;
-               case 1: /* XXX prop on constant */
-                       t->flag |= T_PROP_EDIT;
-                       break;
+                       switch(RNA_enum_get(op->ptr, "proportional"))
+                       {
+                       case 2: /* XXX connected constant */
+                               t->flag |= T_PROP_CONNECTED;
+                       case 1: /* XXX prop on constant */
+                               t->flag |= T_PROP_EDIT;
+                               break;
+                       }
                }
-       }
-       else
-       {
-               if ((t->options & CTX_NO_PET) == 0 && (ts->proportional)) {
-                       t->flag |= T_PROP_EDIT;
+               else
+               {
+                       if ((t->options & CTX_NO_PET) == 0 && (ts->proportional)) {
+                               t->flag |= T_PROP_EDIT;
 
-                       if(ts->proportional == 2)
-                               t->flag |= T_PROP_CONNECTED;    // yes i know, has to become define
+                               if(ts->proportional == 2)
+                                       t->flag |= T_PROP_CONNECTED;    // yes i know, has to become define
+                       }
                }
-       }
 
-       if (op && RNA_struct_find_property(op->ptr, "proportional_size") && RNA_property_is_set(op->ptr, "proportional_size"))
-       {
-               t->prop_size = RNA_float_get(op->ptr, "proportional_size");
-       }
-       else
-       {
-               t->prop_size = ts->proportional_size;
-       }
+               if (op && RNA_struct_find_property(op->ptr, "proportional_size") && RNA_property_is_set(op->ptr, "proportional_size"))
+               {
+                       t->prop_size = RNA_float_get(op->ptr, "proportional_size");
+               }
+               else
+               {
+                       t->prop_size = ts->proportional_size;
+               }
 
-       if (op && RNA_struct_find_property(op->ptr, "proportional_editing_falloff") && RNA_property_is_set(op->ptr, "proportional_editing_falloff"))
-       {
-               t->prop_mode = RNA_enum_get(op->ptr, "proportional_editing_falloff");
+
+               /* TRANSFORM_FIX_ME rna restrictions */
+               if (t->prop_size <= 0)
+               {
+                       t->prop_size = 1.0f;
+               }
+               
+               if (op && RNA_struct_find_property(op->ptr, "proportional_editing_falloff") && RNA_property_is_set(op->ptr, "proportional_editing_falloff"))
+               {
+                       t->prop_mode = RNA_enum_get(op->ptr, "proportional_editing_falloff");
+               }
+               else
+               {
+                       t->prop_mode = ts->prop_mode;
+               }
        }
-       else
+       else /* add not pet option to context when not available */
        {
-               t->prop_mode = ts->prop_mode;
+               t->options |= CTX_NO_PET;
        }
 
-       /* TRANSFORM_FIX_ME rna restrictions */
-       if (t->prop_size <= 0)
-       {
-               t->prop_size = 1.0f;
-       }
 
        setTransformViewMatrices(t);
        initNumInput(&t->num);
@@ -1065,8 +1074,6 @@ void postTrans (TransInfo *t)
                        ED_uvedit_live_unwrap_end(t->state == TRANS_CANCEL);
        }
        else if(ELEM(t->spacetype, SPACE_ACTION, SPACE_NLA)) {
-               if (t->customData)
-                       MEM_freeN(t->customData);
        }
 
        if (t->mouse.data)
@@ -1074,8 +1081,11 @@ void postTrans (TransInfo *t)
                MEM_freeN(t->mouse.data);
        }
 
-       if (t->mode == TFM_EDGE_SLIDE) {
-               freeSlideVerts(t);
+       if (t->customFree) {
+               t->customFree(t);
+       }
+       else if (t->customData) {
+               MEM_freeN(t->customData);
        }
 }
 
index 69819da8cc2c569dd0b8ec9bc7a35b9ff24a2e7b..b6f8d2c8c2218724f9cf44954bd9ffd989e41e30 100644 (file)
@@ -99,6 +99,7 @@ char OP_SHRINK_FATTEN[] = "TFM_OT_shrink_fatten";
 char OP_TILT[] = "TFM_OT_tilt";
 char OP_TRACKBALL[] = "TFM_OT_trackball";
 char OP_MIRROR[] = "TFM_OT_mirror";
+char OP_EDGE_SLIDE[] = "TFM_OT_edge_slide";
 
 
 TransformModeItem transform_modes[] =
@@ -113,6 +114,7 @@ TransformModeItem transform_modes[] =
        {OP_TILT, TFM_TILT},
        {OP_TRACKBALL, TFM_TRACKBALL},
        {OP_MIRROR, TFM_MIRROR},
+       {OP_EDGE_SLIDE, TFM_EDGE_SLIDE},
        {NULL, 0}
 };
 
@@ -549,6 +551,26 @@ void TFM_OT_mirror(struct wmOperatorType *ot)
        Properties_Constraints(ot);
 }
 
+void TFM_OT_edge_slide(struct wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name   = "Tilt";
+       ot->description= "Tilt selected control vertices of 3d curve."; 
+       ot->idname = OP_EDGE_SLIDE;
+       ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO|OPTYPE_BLOCKING;
+
+       /* api callbacks */
+       ot->invoke = transform_invoke;
+       ot->exec   = transform_exec;
+       ot->modal  = transform_modal;
+       ot->cancel  = transform_cancel;
+       ot->poll   = ED_operator_editmesh;
+
+       RNA_def_float_factor(ot->srna, "value", 0, 0, 1, "Factor", "", 0, 1);
+
+       RNA_def_boolean(ot->srna, "mirror", 0, "Mirror Editing", "");
+}
+
 void TFM_OT_transform(struct wmOperatorType *ot)
 {
        static EnumPropertyItem transform_mode_types[] = {
@@ -618,6 +640,7 @@ void transform_operatortypes(void)
        WM_operatortype_append(TFM_OT_tilt);
        WM_operatortype_append(TFM_OT_trackball);
        WM_operatortype_append(TFM_OT_mirror);
+       WM_operatortype_append(TFM_OT_edge_slide);
 
        WM_operatortype_append(TFM_OT_select_orientation);
 }