doxygen: prevent GPL license block from being parsed as doxygen comment.
[blender.git] / source / blender / editors / space_view3d / view3d_buttons.c
index 0352996..0e4e1ad 100644 (file)
@@ -1,4 +1,4 @@
-/**
+/*
  * $Id$
  *
  * ***** BEGIN GPL LICENSE BLOCK *****
@@ -45,6 +45,7 @@
 #include "BLI_blenlib.h"
 #include "BLI_editVert.h"
 #include "BLI_rand.h"
+#include "BLI_utildefines.h"
 
 #include "BKE_action.h"
 #include "BKE_context.h"
@@ -56,7 +57,6 @@
 #include "BKE_screen.h"
 #include "BKE_deform.h"
 
-
 #include "WM_api.h"
 #include "WM_types.h"
 
@@ -282,12 +282,7 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
        
        if(block) {     // buttons
                uiBut *but;
-               int but_y;
-               if((ob->parent) && (ob->partype == PARBONE))    but_y = 135;
-               else                                                                                    but_y = 150;
-               
-               
-               
+
                memcpy(tfp->ve_median, median, sizeof(tfp->ve_median));
                
                uiBlockBeginAlign(block);
@@ -303,15 +298,15 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
                        uiButSetUnitType(but, PROP_UNIT_LENGTH);
 
                        if(totw==1) {
-                               uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "W:",        0, 50, 200, 20, &(tfp->ve_median[3]), 0.01, 100.0, 10, 3, "");
+                               uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "W:",        0, 50, 200, 20, &(tfp->ve_median[3]), 0.01, 100.0, 1, 3, "");
                                uiBlockBeginAlign(block);
                                uiDefButBitS(block, TOG, V3D_GLOBAL_STATS, B_REDR, "Global",            0, 25, 100, 20, &v3d->flag, 0, 0, 0, 0, "Displays global values");
                                uiDefButBitS(block, TOGN, V3D_GLOBAL_STATS, B_REDR, "Local",            100, 25, 100, 20, &v3d->flag, 0, 0, 0, 0, "Displays local values");
                                uiBlockEndAlign(block);
                                if(totweight)
-                                       uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Weight:",   0, 0, 200, 20, &(tfp->ve_median[4]), 0.0, 1.0, 10, 3, "");
+                                       uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Weight:",   0, 0, 200, 20, &(tfp->ve_median[4]), 0.0, 1.0, 1, 3, "");
                                if(totradius)
-                                       uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Radius:",   0, 0, 200, 20, &(tfp->ve_median[5]), 0.0, 100.0, 10, 3, "Radius of curve CPs");
+                                       uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Radius:",   0, 0, 200, 20, &(tfp->ve_median[5]), 0.0, 100.0, 1, 3, "Radius of curve CPs");
                                }
                        else {
                                uiBlockBeginAlign(block);
@@ -334,7 +329,7 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
                        but= uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Z:",           0, 70, 200, 20, &(tfp->ve_median[2]), -lim, lim, 10, 3, "");
                        uiButSetUnitType(but, PROP_UNIT_LENGTH);
                        if(totw==tot) {
-                               uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "W:",        0, 50, 200, 20, &(tfp->ve_median[3]), 0.01, 100.0, 10, 3, "");
+                               uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "W:",        0, 50, 200, 20, &(tfp->ve_median[3]), 0.01, 100.0, 1, 3, "");
                                uiBlockEndAlign(block);
                                uiBlockBeginAlign(block);
                                uiDefButBitS(block, TOG, V3D_GLOBAL_STATS, B_REDR, "Global",            0, 25, 100, 20, &v3d->flag, 0, 0, 0, 0, "Displays global values");
@@ -352,17 +347,17 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
                                uiDefButBitS(block, TOGN, V3D_GLOBAL_STATS, B_REDR, "Local",            100, 45, 100, 20, &v3d->flag, 0, 0, 0, 0, "Displays local values");
                                uiBlockEndAlign(block);
                                if(totweight)
-                                       uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Weight:",   0, 20, 200, 20, &(tfp->ve_median[4]), 0.0, 1.0, 10, 3, "Weight is used for SoftBody Goal");
+                                       uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Weight:",   0, 20, 200, 20, &(tfp->ve_median[4]), 0.0, 1.0, 1, 3, "Weight is used for SoftBody Goal");
                                if(totradius)
-                                       uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Radius:",   0, 0, 200, 20, &(tfp->ve_median[5]), 0.0, 100.0, 10, 3, "Radius of curve CPs");
+                                       uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Radius:",   0, 0, 200, 20, &(tfp->ve_median[5]), 0.0, 100.0, 1, 3, "Radius of curve CPs");
                                uiBlockEndAlign(block);
                        }
                }
                                
                if(totedge==1)
-                       uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Crease:",   0, 20, 200, 20, &(tfp->ve_median[3]), 0.0, 1.0, 10, 3, "");
+                       uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Crease:",   0, 20, 200, 20, &(tfp->ve_median[3]), 0.0, 1.0, 1, 3, "");
                else if(totedge>1)
-                       uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Mean Crease:",      0, 20, 200, 20, &(tfp->ve_median[3]), 0.0, 1.0, 10, 3, "");
+                       uiDefButF(block, NUM, B_OBJECTPANELMEDIAN, "Mean Crease:",      0, 20, 200, 20, &(tfp->ve_median[3]), 0.0, 1.0, 1, 3, "");
                
        }
        else {  // apply
@@ -381,30 +376,66 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
                if(ob->type==OB_MESH) {
                        Mesh *me= ob->data;
                        EditMesh *em = BKE_mesh_get_editmesh(me);
-                       EditVert *eve;
-                       EditEdge *eed;
-                       
-                       eve= em->verts.first;
-                       while(eve) {
-                               if(eve->f & SELECT) {
-                                       add_v3_v3(eve->co, median);
+
+                       /* allow for some rounding error becasue of matrix transform */
+                       if(len_v3(median) > 0.000001) {
+                               EditVert *eve;
+
+                               for(eve= em->verts.first; eve; eve= eve->next) {
+                                       if(eve->f & SELECT) {
+                                               add_v3_v3(eve->co, median);
+                                       }
                                }
-                               eve= eve->next;
+
+                               recalc_editnormals(em);
                        }
-                       
-                       for(eed= em->edges.first; eed; eed= eed->next) {
-                               if(eed->f & SELECT) {
-                                       /* ensure the median can be set to zero or one */
-                                       if(ve_median[3]==0.0f) eed->crease= 0.0f;
-                                       else if(ve_median[3]==1.0f) eed->crease= 1.0f;
+
+                       if(median[3] != 0.0f) {
+                               EditEdge *eed;
+                               const float fixed_crease= (ve_median[3] <= 0.0f ? 0.0 : (ve_median[3] >= 1.0f ? 1.0 : FLT_MAX));
+                               
+                               if(fixed_crease != FLT_MAX) {
+                                       /* simple case */
+
+                                       for(eed= em->edges.first; eed; eed= eed->next) {
+                                               if(eed->f & SELECT) {
+                                                       eed->crease= fixed_crease;
+                                               }
+                                       }
+                               }
+                               else {
+                                       /* scale crease to target median */
+                                       float median_new= ve_median[3];
+                                       float median_orig= ve_median[3] - median[3]; /* previous median value */
+
+                                       /* incase of floating point error */
+                                       CLAMP(median_orig, 0.0, 1.0);
+                                       CLAMP(median_new, 0.0, 1.0);
+
+                                       if(median_new < median_orig) {
+                                               /* scale down */
+                                               const float sca= median_new / median_orig;
+                                               
+                                               for(eed= em->edges.first; eed; eed= eed->next) {
+                                                       if(eed->f & SELECT) {
+                                                               eed->crease *= sca;
+                                                               CLAMP(eed->crease, 0.0, 1.0);
+                                                       }
+                                               }
+                                       }
                                        else {
-                                               eed->crease+= median[3];
-                                               CLAMP(eed->crease, 0.0, 1.0);
+                                               /* scale up */
+                                               const float sca= (1.0f - median_new) / (1.0f - median_orig);
+
+                                               for(eed= em->edges.first; eed; eed= eed->next) {
+                                                       if(eed->f & SELECT) {
+                                                               eed->crease = 1.0f - ((1.0f - eed->crease) * sca);
+                                                               CLAMP(eed->crease, 0.0, 1.0);
+                                                       }
+                                               }
                                        }
                                }
                        }
-                       
-                       recalc_editnormals(em);
 
                        BKE_mesh_end_editmesh(me, em);
                }
@@ -678,7 +709,7 @@ static void do_view3d_vgroup_buttons(bContext *C, void *UNUSED(arg), int event)
        WM_event_add_notifier(C, NC_GEOM|ND_DATA, ob->data);
 }
 
-int view3d_panel_vgroup_poll(const bContext *C, PanelType *UNUSED(pt))
+static int view3d_panel_vgroup_poll(const bContext *C, PanelType *UNUSED(pt))
 {
        Scene *scene= CTX_data_scene(C);
        Object *ob= OBACT;
@@ -748,57 +779,57 @@ static void v3d_transform_butsR(uiLayout *layout, PointerRNA *ptr)
                uiLayoutSetActive(split, !(bone->parent && bone->flag & BONE_CONNECTED));
        }
        colsub = uiLayoutColumn(split, 1);
-       uiItemR(colsub, ptr, "location", 0, "Location", 0);
+       uiItemR(colsub, ptr, "location", 0, "Location", ICON_NULL);
        colsub = uiLayoutColumn(split, 1);
-       uiItemL(colsub, "", 0);
-       uiItemR(colsub, ptr, "lock_location", UI_ITEM_R_TOGGLE+UI_ITEM_R_ICON_ONLY, "", 0);
+       uiItemL(colsub, "", ICON_NULL);
+       uiItemR(colsub, ptr, "lock_location", UI_ITEM_R_TOGGLE+UI_ITEM_R_ICON_ONLY, "", ICON_NULL);
        
        split = uiLayoutSplit(layout, 0.8, 0);
        
        switch(RNA_enum_get(ptr, "rotation_mode")) {
                case ROT_MODE_QUAT: /* quaternion */
                        colsub = uiLayoutColumn(split, 1);
-                       uiItemR(colsub, ptr, "rotation_quaternion", 0, "Rotation", 0);
+                       uiItemR(colsub, ptr, "rotation_quaternion", 0, "Rotation", ICON_NULL);
                        colsub = uiLayoutColumn(split, 1);
-                       uiItemR(colsub, ptr, "lock_rotations_4d", UI_ITEM_R_TOGGLE, "4L", 0);
+                       uiItemR(colsub, ptr, "lock_rotations_4d", UI_ITEM_R_TOGGLE, "4L", ICON_NULL);
                        if (RNA_boolean_get(ptr, "lock_rotations_4d"))
-                               uiItemR(colsub, ptr, "lock_rotation_w", UI_ITEM_R_TOGGLE+UI_ITEM_R_ICON_ONLY, "", 0);
+                               uiItemR(colsub, ptr, "lock_rotation_w", UI_ITEM_R_TOGGLE+UI_ITEM_R_ICON_ONLY, "", ICON_NULL);
                        else
-                               uiItemL(colsub, "", 0);
-                       uiItemR(colsub, ptr, "lock_rotation", UI_ITEM_R_TOGGLE+UI_ITEM_R_ICON_ONLY, "", 0);
+                               uiItemL(colsub, "", ICON_NULL);
+                       uiItemR(colsub, ptr, "lock_rotation", UI_ITEM_R_TOGGLE+UI_ITEM_R_ICON_ONLY, "", ICON_NULL);
                        break;
                case ROT_MODE_AXISANGLE: /* axis angle */
                        colsub = uiLayoutColumn(split, 1);
-                       uiItemR(colsub, ptr, "rotation_axis_angle", 0, "Rotation", 0);
+                       uiItemR(colsub, ptr, "rotation_axis_angle", 0, "Rotation", ICON_NULL);
                        colsub = uiLayoutColumn(split, 1);
-                       uiItemR(colsub, ptr, "lock_rotations_4d", UI_ITEM_R_TOGGLE, "4L", 0);
+                       uiItemR(colsub, ptr, "lock_rotations_4d", UI_ITEM_R_TOGGLE, "4L", ICON_NULL);
                        if (RNA_boolean_get(ptr, "lock_rotations_4d"))
-                               uiItemR(colsub, ptr, "lock_rotation_w", UI_ITEM_R_TOGGLE+UI_ITEM_R_ICON_ONLY, "", 0);
+                               uiItemR(colsub, ptr, "lock_rotation_w", UI_ITEM_R_TOGGLE+UI_ITEM_R_ICON_ONLY, "", ICON_NULL);
                        else
-                               uiItemL(colsub, "", 0);
-                       uiItemR(colsub, ptr, "lock_rotation", UI_ITEM_R_TOGGLE+UI_ITEM_R_ICON_ONLY, "", 0);
+                               uiItemL(colsub, "", ICON_NULL);
+                       uiItemR(colsub, ptr, "lock_rotation", UI_ITEM_R_TOGGLE+UI_ITEM_R_ICON_ONLY, "", ICON_NULL);
                        break;
                default: /* euler rotations */
                        colsub = uiLayoutColumn(split, 1);
-                       uiItemR(colsub, ptr, "rotation_euler", 0, "Rotation", 0);
+                       uiItemR(colsub, ptr, "rotation_euler", 0, "Rotation", ICON_NULL);
                        colsub = uiLayoutColumn(split, 1);
-                       uiItemL(colsub, "", 0);
-                       uiItemR(colsub, ptr, "lock_rotation", UI_ITEM_R_TOGGLE+UI_ITEM_R_ICON_ONLY, "", 0);
+                       uiItemL(colsub, "", ICON_NULL);
+                       uiItemR(colsub, ptr, "lock_rotation", UI_ITEM_R_TOGGLE+UI_ITEM_R_ICON_ONLY, "", ICON_NULL);
                        break;
        }
-       uiItemR(layout, ptr, "rotation_mode", 0, "", 0);
+       uiItemR(layout, ptr, "rotation_mode", 0, "", ICON_NULL);
        
        split = uiLayoutSplit(layout, 0.8, 0);
        colsub = uiLayoutColumn(split, 1);
-       uiItemR(colsub, ptr, "scale", 0, "Scale", 0);
+       uiItemR(colsub, ptr, "scale", 0, "Scale", ICON_NULL);
        colsub = uiLayoutColumn(split, 1);
-       uiItemL(colsub, "", 0);
-       uiItemR(colsub, ptr, "lock_scale", UI_ITEM_R_TOGGLE+UI_ITEM_R_ICON_ONLY, "", 0);
+       uiItemL(colsub, "", ICON_NULL);
+       uiItemR(colsub, ptr, "lock_scale", UI_ITEM_R_TOGGLE+UI_ITEM_R_ICON_ONLY, "", ICON_NULL);
        
        if (ptr->type == &RNA_Object) {
                Object *ob = ptr->data;
                if (ELEM5(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL))
-                       uiItemR(layout, ptr, "dimensions", 0, "Dimensions", 0);
+                       uiItemR(layout, ptr, "dimensions", 0, "Dimensions", ICON_NULL);
        }
 }
 
@@ -818,7 +849,7 @@ static void v3d_posearmature_buts(uiLayout *layout, Object *ob)
 //     row= uiLayoutRow(layout, 0);
        
        if (!pchan)     {
-               uiItemL(layout, "No Bone Active", 0);
+               uiItemL(layout, "No Bone Active", ICON_NULL);
                return; 
        }
 
@@ -894,7 +925,8 @@ static void v3d_posearmature_buts(uiLayout *layout, Object *ob)
 }
 
 /* assumes armature editmode */
-void validate_editbonebutton_cb(bContext *C, void *bonev, void *namev)
+#if 0
+static void validate_editbonebutton_cb(bContext *C, void *bonev, void *namev)
 {
        EditBone *eBone= bonev;
        char oldname[sizeof(eBone->name)], newname[sizeof(eBone->name)];
@@ -908,6 +940,7 @@ void validate_editbonebutton_cb(bContext *C, void *bonev, void *namev)
        ED_armature_bone_rename(CTX_data_edit_object(C)->data, oldname, newname); // editarmature.c
        WM_event_add_notifier(C, NC_OBJECT|ND_BONE_SELECT, CTX_data_edit_object(C)); // XXX fix
 }
+#endif
 
 static void v3d_editarmature_buts(uiLayout *layout, Object *ob)
 {
@@ -929,18 +962,18 @@ static void v3d_editarmature_buts(uiLayout *layout, Object *ob)
 
 
        col= uiLayoutColumn(layout, 0);
-       uiItemR(col, &eboneptr, "head", 0, "Head", 0);
+       uiItemR(col, &eboneptr, "head", 0, "Head", ICON_NULL);
        if (ebone->parent && ebone->flag & BONE_CONNECTED ) {
                PointerRNA parptr = RNA_pointer_get(&eboneptr, "parent");
-               uiItemR(col, &parptr, "tail_radius", 0, "Radius (Parent)", 0);
+               uiItemR(col, &parptr, "tail_radius", 0, "Radius (Parent)", ICON_NULL);
        } else {
-               uiItemR(col, &eboneptr, "head_radius", 0, "Radius", 0);
+               uiItemR(col, &eboneptr, "head_radius", 0, "Radius", ICON_NULL);
        }
        
-       uiItemR(col, &eboneptr, "tail", 0, "Tail", 0);
-       uiItemR(col, &eboneptr, "tail_radius", 0, "Radius", 0);
+       uiItemR(col, &eboneptr, "tail", 0, "Tail", ICON_NULL);
+       uiItemR(col, &eboneptr, "tail_radius", 0, "Radius", ICON_NULL);
        
-       uiItemR(col, &eboneptr, "roll", 0, "Roll", 0);
+       uiItemR(col, &eboneptr, "roll", 0, "Roll", ICON_NULL);
 }
 
 static void v3d_editmetaball_buts(uiLayout *layout, Object *ob)
@@ -959,37 +992,37 @@ static void v3d_editmetaball_buts(uiLayout *layout, Object *ob)
        RNA_pointer_create(&mball->id, &RNA_MetaElement, mball->lastelem, &ptr);
        
        col= uiLayoutColumn(layout, 0);
-       uiItemR(col, &ptr, "co", 0, "Location", 0);
+       uiItemR(col, &ptr, "co", 0, "Location", ICON_NULL);
        
-       uiItemR(col, &ptr, "radius", 0, "Radius", 0);
-       uiItemR(col, &ptr, "stiffness", 0, "Stiffness", 0);
+       uiItemR(col, &ptr, "radius", 0, "Radius", ICON_NULL);
+       uiItemR(col, &ptr, "stiffness", 0, "Stiffness", ICON_NULL);
        
-       uiItemR(col, &ptr, "type", 0, "Type", 0);
+       uiItemR(col, &ptr, "type", 0, "Type", ICON_NULL);
        
        col= uiLayoutColumn(layout, 1);
        switch (RNA_enum_get(&ptr, "type")) {
                case MB_BALL:
                        break;
                case MB_CUBE:
-                       uiItemL(col, "Size:", 0);
-                       uiItemR(col, &ptr, "size_x", 0, "X", 0);
-                       uiItemR(col, &ptr, "size_y", 0, "Y", 0);
-                       uiItemR(col, &ptr, "size_z", 0, "Z", 0);
+                       uiItemL(col, "Size:", ICON_NULL);
+                       uiItemR(col, &ptr, "size_x", 0, "X", ICON_NULL);
+                       uiItemR(col, &ptr, "size_y", 0, "Y", ICON_NULL);
+                       uiItemR(col, &ptr, "size_z", 0, "Z", ICON_NULL);
                        break;
                case MB_TUBE:
-                       uiItemL(col, "Size:", 0);
-                       uiItemR(col, &ptr, "size_x", 0, "X", 0);
+                       uiItemL(col, "Size:", ICON_NULL);
+                       uiItemR(col, &ptr, "size_x", 0, "X", ICON_NULL);
                        break;
                case MB_PLANE:
-                       uiItemL(col, "Size:", 0);
-                       uiItemR(col, &ptr, "size_x", 0, "X", 0);
-                       uiItemR(col, &ptr, "size_y", 0, "Y", 0);
+                       uiItemL(col, "Size:", ICON_NULL);
+                       uiItemR(col, &ptr, "size_x", 0, "X", ICON_NULL);
+                       uiItemR(col, &ptr, "size_y", 0, "Y", ICON_NULL);
                        break;
                case MB_ELIPSOID:
-                       uiItemL(col, "Size:", 0);
-                       uiItemR(col, &ptr, "size_x", 0, "X", 0);
-                       uiItemR(col, &ptr, "size_y", 0, "Y", 0);
-                       uiItemR(col, &ptr, "size_z", 0, "Z", 0);
+                       uiItemL(col, "Size:", ICON_NULL);
+                       uiItemR(col, &ptr, "size_x", 0, "X", ICON_NULL);
+                       uiItemR(col, &ptr, "size_y", 0, "Y", ICON_NULL);
+                       uiItemR(col, &ptr, "size_z", 0, "Z", ICON_NULL);
                        break;             
        }       
 }
@@ -1168,16 +1201,6 @@ static void do_view3d_region_buttons(bContext *C, void *UNUSED(index), int event
        WM_event_add_notifier(C, NC_SPACE|ND_SPACE_VIEW3D, ob);
 }
 
-void removeTransformOrientation_func(bContext *C, void *target, void *UNUSED(arg))
-{
-       BIF_removeTransformOrientation(C, (TransformOrientation *) target);
-}
-
-void selectTransformOrientation_func(bContext *C, void *target, void *UNUSED(arg))
-{
-       BIF_selectTransformOrientation(C, (TransformOrientation *) target);
-}
-
 static void view3d_panel_object(const bContext *C, Panel *pa)
 {
        uiBlock *block;
@@ -1392,33 +1415,6 @@ static void view3d_panel_bonesketch_spaces(const bContext *C, Panel *pa)
        uiBlockEndAlign(block);
 }
 
-static void view3d_panel_operator_redo(const bContext *C, Panel *pa)
-{
-       wmWindowManager *wm= CTX_wm_manager(C);
-       wmOperator *op;
-       PointerRNA ptr;
-       uiBlock *block;
-       
-       block= uiLayoutGetBlock(pa->layout);
-
-       /* only for operators that are registered and did an undo push */
-       for(op= wm->operators.last; op; op= op->prev)
-               if((op->type->flag & OPTYPE_REGISTER) && (op->type->flag & OPTYPE_UNDO))
-                       break;
-       
-       if(op==NULL)
-               return;
-       
-       uiBlockSetFunc(block, ED_undo_operator_repeat_cb, op, NULL);
-       
-       if(!op->properties) {
-               IDPropertyTemplate val = {0};
-               op->properties= IDP_New(IDP_GROUP, val, "wmOperatorProperties");
-       }
-       
-       RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
-       uiDefAutoButsRNA(pa->layout, &ptr, 2);
-}
 #endif // XXX not used
 
 void view3d_buttons_register(ARegionType *art)