Fix T54771: Can't change multiple dimensions at once
authorCampbell Barton <ideasman42@gmail.com>
Fri, 4 Jan 2019 08:52:13 +0000 (19:52 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 4 Jan 2019 08:52:13 +0000 (19:52 +1100)
- Use non-rna button for adjusting dimensions.
- Make Object.dimensions RNA read-only since it never worked well.
  This is mainly a UI editing feature.

source/blender/blenkernel/BKE_object.h
source/blender/blenkernel/intern/object.c
source/blender/editors/space_view3d/view3d_buttons.c
source/blender/makesrna/intern/rna_object.c

index 8a3bf81911d1745f244cf6a3197af69211223224..329be17463287efa8b0a1f75b7d2c053dc2f0514 100644 (file)
@@ -184,7 +184,7 @@ void BKE_boundbox_minmax(const struct BoundBox *bb, float obmat[4][4], float r_m
 
 struct BoundBox *BKE_object_boundbox_get(struct Object *ob);
 void BKE_object_dimensions_get(struct Object *ob, float vec[3]);
-void BKE_object_dimensions_set(struct Object *ob, const float value[3]);
+void BKE_object_dimensions_set(struct Object *ob, const float value[3], int axis_mask);
 void BKE_object_empty_draw_type_set(struct Object *ob, const int value);
 void BKE_object_boundbox_flag(struct Object *ob, int flag, const bool set);
 void BKE_object_boundbox_calc_from_mesh(struct Object *ob, struct Mesh *me_eval);
index 8ab3962d930a86c6b4adb0048026b2b43bc17d7e..80a59216f609ecba714bcbdb8c5b3dfed9b9d381 100644 (file)
@@ -2548,7 +2548,7 @@ void BKE_object_dimensions_get(Object *ob, float vec[3])
        }
 }
 
-void BKE_object_dimensions_set(Object *ob, const float value[3])
+void BKE_object_dimensions_set(Object *ob, const float value[3], int axis_mask)
 {
        BoundBox *bb = NULL;
 
@@ -2560,9 +2560,13 @@ void BKE_object_dimensions_set(Object *ob, const float value[3])
                len[1] = bb->vec[2][1] - bb->vec[0][1];
                len[2] = bb->vec[1][2] - bb->vec[0][2];
 
-               if (len[0] > 0.f) ob->size[0] = value[0] / len[0];
-               if (len[1] > 0.f) ob->size[1] = value[1] / len[1];
-               if (len[2] > 0.f) ob->size[2] = value[2] / len[2];
+               for (int i = 0; i < 3; i++) {
+                       if (((1 << i) & axis_mask) == 0) {
+                               if (len[i] > 0.0f) {
+                                       ob->size[i] = value[i] / len[i];
+                               }
+                       }
+               }
        }
 }
 
index 277d0f6a2a082b141b9071e34158b66257b14faa..cc6b51518b7ae6eac482bdb7e8f1a46936602b9c 100644 (file)
@@ -83,6 +83,7 @@
 /* ******************* view3d space & buttons ************** */
 #define B_REDR              2
 #define B_OBJECTPANELMEDIAN 1008
+#define B_OBJECTPANEL_DIMS  1009
 
 #define NBR_TRANSFORM_PROPERTIES 8
 
@@ -90,6 +91,7 @@
 typedef struct {
        float ob_eul[4];   /* used for quat too... */
        float ob_scale[3]; /* need temp space due to linked values */
+       float ob_dims_orig[3];
        float ob_dims[3];
        short link_scale;
        float ve_median[NBR_TRANSFORM_PROPERTIES];
@@ -170,6 +172,14 @@ static void apply_scale_factor_clamp(float *val, const int tot, const float ve_m
        }
 }
 
+static TransformProperties *v3d_transform_props_ensure(View3D *v3d)
+{
+       if (v3d->properties_storage == NULL) {
+               v3d->properties_storage = MEM_callocN(sizeof(TransformProperties), "TransformProperties");
+       }
+       return v3d->properties_storage;
+}
+
 /* is used for both read and write... */
 static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float lim)
 {
@@ -195,7 +205,7 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
 #define L_WEIGHT     4
 
        uiBlock *block = (layout) ? uiLayoutAbsoluteBlock(layout) : NULL;
-       TransformProperties *tfp;
+       TransformProperties *tfp = v3d_transform_props_ensure(v3d);
        float median[NBR_TRANSFORM_PROPERTIES], ve_median[NBR_TRANSFORM_PROPERTIES];
        int tot, totedgedata, totcurvedata, totlattdata, totcurvebweight;
        bool has_meshdata = false;
@@ -205,11 +215,6 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
        copy_vn_fl(median, NBR_TRANSFORM_PROPERTIES, 0.0f);
        tot = totedgedata = totcurvedata = totlattdata = totcurvebweight = 0;
 
-       /* make sure we got storage */
-       if (v3d->properties_storage == NULL)
-               v3d->properties_storage = MEM_callocN(sizeof(TransformProperties), "TransformProperties");
-       tfp = v3d->properties_storage;
-
        if (ob->type == OB_MESH) {
                Mesh *me = ob->data;
                BMEditMesh *em = me->edit_btmesh;
@@ -770,6 +775,47 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
 }
 #undef NBR_TRANSFORM_PROPERTIES
 
+static void v3d_object_dimension_buts(bContext *C, uiLayout *layout, View3D *v3d, Object *ob)
+{
+       uiBlock *block = (layout) ? uiLayoutAbsoluteBlock(layout) : NULL;
+       TransformProperties *tfp = v3d_transform_props_ensure(v3d);
+
+       if (block) {
+               BLI_assert(C == NULL);
+               uiBut *but;
+               int yi = 200;
+               const int butw = 200;
+               const int buth = 20 * UI_DPI_FAC;
+
+               BKE_object_dimensions_get(ob, tfp->ob_dims);
+               copy_v3_v3(tfp->ob_dims_orig, tfp->ob_dims);
+
+               uiDefBut(block, UI_BTYPE_LABEL, 0, IFACE_("Dimensions:"), 0, yi -= buth, butw, buth, NULL, 0, 0, 0, 0, "");
+               UI_block_align_begin(block);
+               const float lim = 10000;
+               for (int i = 0; i < 3; i++) {
+                       char text[3] = {'X' + i, ':', '\0'};
+                       uiDefButF(block, UI_BTYPE_NUM, B_OBJECTPANEL_DIMS, text, 0, yi -= buth, butw, buth,
+                                 &(tfp->ob_dims[i]), 0.0f, lim, 10, 3, "");
+               }
+               UI_block_align_end(block);
+       }
+       else {  /* apply */
+               int axis_mask = 0;
+               for (int i = 0; i < 3; i++) {
+                       if (tfp->ob_dims[i] == tfp->ob_dims_orig[i]) {
+                               axis_mask |= (1 << i);
+                       }
+               }
+               BKE_object_dimensions_set(ob, tfp->ob_dims, axis_mask);
+
+               PointerRNA obptr;
+               RNA_id_pointer_create(&ob->id, &obptr);
+               PropertyRNA *prop = RNA_struct_find_property(&obptr, "scale");
+               RNA_property_update(C, &obptr, prop);
+       }
+}
+
 #define B_VGRP_PNL_EDIT_SINGLE 8       /* or greater */
 
 static void do_view3d_vgroup_buttons(bContext *C, void *UNUSED(arg), int event)
@@ -987,14 +1033,6 @@ static void v3d_transform_butsR(uiLayout *layout, PointerRNA *ptr)
        uiLayoutSetEmboss(colsub, UI_EMBOSS_NONE);
        uiItemL(colsub, "", ICON_NONE);
        uiItemR(colsub, ptr, "lock_scale", UI_ITEM_R_TOGGLE | UI_ITEM_R_ICON_ONLY, "", ICON_DECORATE_UNLOCKED);
-
-       if (ptr->type == &RNA_Object) {
-               Object *ob = ptr->data;
-               /* dimensions and editmode just happen to be the same checks */
-               if (OB_TYPE_SUPPORT_EDITMODE(ob->type)) {
-                       uiItemR(layout, ptr, "dimensions", 0, NULL, ICON_NONE);
-               }
-       }
 }
 
 static void v3d_posearmature_buts(uiLayout *layout, Object *ob)
@@ -1120,6 +1158,11 @@ static void do_view3d_region_buttons(bContext *C, void *UNUSED(index), int event
                                DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY);
                        }
                        break;
+               case B_OBJECTPANEL_DIMS:
+                       if (ob) {
+                               v3d_object_dimension_buts(C, NULL, v3d, ob);
+                       }
+                       break;
        }
 
        /* default for now */
@@ -1167,6 +1210,12 @@ static void view3d_panel_transform(const bContext *C, Panel *pa)
 
                RNA_id_pointer_create(&ob->id, &obptr);
                v3d_transform_butsR(col, &obptr);
+
+               /* dimensions and editmode just happen to be the same checks */
+               if (OB_TYPE_SUPPORT_EDITMODE(ob->type)) {
+                       View3D *v3d = CTX_wm_view3d(C);
+                       v3d_object_dimension_buts(NULL, col, v3d, ob);
+               }
        }
 }
 
index feb27018bcd8aac60d427a690d41c0566e6090ed..1c195ff559e1f6608e01d77e2b376098abc39b37 100644 (file)
@@ -903,12 +903,6 @@ static void rna_Object_dimensions_get(PointerRNA *ptr, float *value)
        BKE_object_dimensions_get(ob, value);
 }
 
-static void rna_Object_dimensions_set(PointerRNA *ptr, const float *value)
-{
-       Object *ob = ptr->data;
-       BKE_object_dimensions_set(ob, value);
-}
-
 static int rna_Object_location_editable(PointerRNA *ptr, int index)
 {
        Object *ob = (Object *)ptr->data;
@@ -2309,9 +2303,10 @@ static void rna_def_object(BlenderRNA *brna)
 
        prop = RNA_def_property(srna, "dimensions", PROP_FLOAT, PROP_XYZ_LENGTH);
        RNA_def_property_array(prop, 3);
-       /* only for the transform-panel and conflicts with animating scale */
-       RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
-       RNA_def_property_float_funcs(prop, "rna_Object_dimensions_get", "rna_Object_dimensions_set", NULL);
+       /* Only for the transform-panel and conflicts with animating scale. */
+       /* Disallow editing, it doesn't work properly, see: T54771. */
+       RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
+       RNA_def_property_float_funcs(prop, "rna_Object_dimensions_get", NULL, NULL);
        RNA_def_property_ui_range(prop, 0.0f, FLT_MAX, 1, RNA_TRANSLATION_PREC_DEFAULT);
        RNA_def_property_ui_text(prop, "Dimensions", "Absolute bounding box dimensions of the object");
        RNA_def_property_update(prop, NC_OBJECT | ND_TRANSFORM, "rna_Object_internal_update");