[Bf-blender-cvs] [0e3fa0b] master: Fix T41590: When scene scale is not 1.0, and units are "None, " Blender assumes translations are in meters.

Bastien Montagne noreply at git.blender.org
Tue Aug 26 12:31:18 CEST 2014


Commit: 0e3fa0b7618fa86e97c5f46ae7208c082fd26eb7
Author: Bastien Montagne
Date:   Tue Aug 26 12:04:24 2014 +0200
Branches: master
https://developer.blender.org/rB0e3fa0b7618fa86e97c5f46ae7208c082fd26eb7

Fix T41590: When scene scale is not 1.0, and units are "None," Blender assumes translations are in meters.

Turned out there were several issues in handling of scale parameter by numinput.
Fixed that by factorizing more some code in common with 'usual' numbuttons eval code
(new `bUnit_getScaleUnit()` helper will return valid scaled value, depending on
given system and type).

Now, numinput behaves as expected - using default unit amended by scale in case no unit is given
(i.e. entering '20' with a scale of 0.01 will give you 20cm, and '20cm' as well!).

===================================================================

M	source/blender/blenkernel/BKE_unit.h
M	source/blender/blenkernel/intern/unit.c
M	source/blender/editors/animation/anim_markers.c
M	source/blender/editors/include/ED_numinput.h
M	source/blender/editors/interface/interface.c
M	source/blender/editors/mesh/editmesh_bevel.c
M	source/blender/editors/mesh/editmesh_inset.c
M	source/blender/editors/mesh/editmesh_loopcut.c
M	source/blender/editors/transform/transform.c
M	source/blender/editors/util/numinput.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_unit.h b/source/blender/blenkernel/BKE_unit.h
index b351bc6..c784794 100644
--- a/source/blender/blenkernel/BKE_unit.h
+++ b/source/blender/blenkernel/BKE_unit.h
@@ -31,6 +31,8 @@
 extern "C" {
 #endif
 
+struct UnitSettings;
+
 /* in all cases the value is assumed to be scaled by the user preference */
 
 /* humanly readable representation of a value in units (used for button drawing) */
@@ -39,6 +41,11 @@ size_t  bUnit_AsString(char *str, int len_max, double value, int prec, int syste
 /* replace units with values, used before python button evaluation */
 bool bUnit_ReplaceString(char *str, int len_max, const char *str_prev, double scale_pref, int system, int type);
 
+/* Apply the needed correction factor to value, based on unit_type (only length-related are affected currently)
+ * and unit->scale_length.
+ */
+double bUnit_getScaleUnit(struct UnitSettings *unit, const int unit_type, double value);
+
 /* make string keyboard-friendly: 10µm --> 10um */
 void bUnit_ToUnitAltName(char *str, int len_max, const char *orig_str, int system, int type);
 
diff --git a/source/blender/blenkernel/intern/unit.c b/source/blender/blenkernel/intern/unit.c
index 98b16b0..cdaf72a 100644
--- a/source/blender/blenkernel/intern/unit.c
+++ b/source/blender/blenkernel/intern/unit.c
@@ -37,6 +37,8 @@
 
 #include "BKE_unit.h"  /* own include */
 
+#include "DNA_scene_types.h"
+
 #ifdef WIN32
 #  include "BLI_winstuff.h"
 #endif
@@ -789,6 +791,29 @@ double bUnit_BaseScalar(int system, int type)
 	return unit_default(usys)->scalar;
 }
 
+double bUnit_getScaleUnit(UnitSettings *unit, const int unit_type, double value)
+{
+	if (unit->system == USER_UNIT_NONE) {
+		/* Never apply scale_length when not using a unit setting! */
+		return value;
+	}
+
+	switch (unit_type) {
+		case B_UNIT_LENGTH:
+			return value * (double)unit->scale_length;
+		case B_UNIT_CAMERA:
+			return value * (double)unit->scale_length;
+		case B_UNIT_AREA:
+			return value * pow(unit->scale_length, 2);
+		case B_UNIT_VOLUME:
+			return value * pow(unit->scale_length, 3);
+		case B_UNIT_MASS:
+			return value * pow(unit->scale_length, 3);
+		default:
+			return value;
+	}
+}
+
 /* external access */
 bool bUnit_IsValid(int system, int type)
 {
diff --git a/source/blender/editors/animation/anim_markers.c b/source/blender/editors/animation/anim_markers.c
index 3313b70..7cd47fa 100644
--- a/source/blender/editors/animation/anim_markers.c
+++ b/source/blender/editors/animation/anim_markers.c
@@ -637,7 +637,7 @@ static void ed_marker_move_update_header(bContext *C, wmOperator *op)
 	}
 
 	if (hasNumInput(&mm->num)) {
-		outputNumInput(&mm->num, str_offs, scene->unit.scale_length);
+		outputNumInput(&mm->num, str_offs, &scene->unit);
 	}
 	else if (use_time) {
 		BLI_snprintf(str_offs, sizeof(str_offs), "%.2f", FRA2TIME(offs));
diff --git a/source/blender/editors/include/ED_numinput.h b/source/blender/editors/include/ED_numinput.h
index 4e96ed0..f9a2242 100644
--- a/source/blender/editors/include/ED_numinput.h
+++ b/source/blender/editors/include/ED_numinput.h
@@ -64,6 +64,8 @@ enum {
 	/* (1 << 9) and above are reserved for internal flags! */
 };
 
+struct UnitSettings;
+
 /*********************** NumInput ********************************/
 
 /* There are important things to note here for code using numinput:
@@ -76,7 +78,7 @@ enum {
  */
 
 void initNumInput(NumInput *n);
-void outputNumInput(NumInput *n, char *str, const float scale_length);
+void outputNumInput(NumInput *n, char *str, struct UnitSettings *unit_settings);
 bool hasNumInput(const NumInput *n);
 bool applyNumInput(NumInput *n, float *vec);
 bool handleNumInput(struct bContext *C, NumInput *n, const struct wmEvent *event);
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index b4c2a43..698d3f0 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -1942,27 +1942,13 @@ static double ui_get_but_scale_unit(uiBut *but, double value)
 	UnitSettings *unit = but->block->unit;
 	int unit_type = uiButGetUnitType(but);
 
-	if (unit_type == PROP_UNIT_LENGTH) {
-		return value * (double)unit->scale_length;
-	}
-	else if (unit_type == PROP_UNIT_CAMERA) {
-		return value * (double)unit->scale_length;
-	}
-	else if (unit_type == PROP_UNIT_AREA) {
-		return value * pow(unit->scale_length, 2);
-	}
-	else if (unit_type == PROP_UNIT_VOLUME) {
-		return value * pow(unit->scale_length, 3);
-	}
-	else if (unit_type == PROP_UNIT_MASS) {
-		return value * pow(unit->scale_length, 3);
-	}
-	else if (unit_type == PROP_UNIT_TIME) { /* WARNING - using evil_C :| */
+	/* Time unit is a bit special, not handled by bUnit_getScaleUnit() for now. */
+	if (unit_type == PROP_UNIT_TIME) { /* WARNING - using evil_C :| */
 		Scene *scene = CTX_data_scene(but->block->evil_C);
 		return FRA2TIME(value);
 	}
 	else {
-		return value;
+		return bUnit_getScaleUnit(unit, RNA_SUBTYPE_UNIT_VALUE(unit_type), value);
 	}
 }
 
diff --git a/source/blender/editors/mesh/editmesh_bevel.c b/source/blender/editors/mesh/editmesh_bevel.c
index 545ecba..48d5113 100644
--- a/source/blender/editors/mesh/editmesh_bevel.c
+++ b/source/blender/editors/mesh/editmesh_bevel.c
@@ -88,7 +88,7 @@ static void edbm_bevel_update_header(bContext *C, wmOperator *op)
 		PropertyRNA *prop = RNA_struct_find_property(op->ptr, "offset_type");
 
 		if (hasNumInput(&opdata->num_input)) {
-			outputNumInput(&opdata->num_input, offset_str, sce->unit.scale_length);
+			outputNumInput(&opdata->num_input, offset_str, &sce->unit);
 		}
 		else {
 			BLI_snprintf(offset_str, NUM_STR_REP_LEN, "%f", RNA_float_get(op->ptr, "offset"));
diff --git a/source/blender/editors/mesh/editmesh_inset.c b/source/blender/editors/mesh/editmesh_inset.c
index 4a552d0..a4942d0 100644
--- a/source/blender/editors/mesh/editmesh_inset.c
+++ b/source/blender/editors/mesh/editmesh_inset.c
@@ -90,7 +90,7 @@ static void edbm_inset_update_header(wmOperator *op, bContext *C)
 	if (sa) {
 		char flts_str[NUM_STR_REP_LEN * 2];
 		if (hasNumInput(&opdata->num_input))
-			outputNumInput(&opdata->num_input, flts_str, sce->unit.scale_length);
+			outputNumInput(&opdata->num_input, flts_str, &sce->unit);
 		else {
 			BLI_snprintf(flts_str, NUM_STR_REP_LEN, "%f", RNA_float_get(op->ptr, "thickness"));
 			BLI_snprintf(flts_str + NUM_STR_REP_LEN, NUM_STR_REP_LEN, "%f", RNA_float_get(op->ptr, "depth"));
diff --git a/source/blender/editors/mesh/editmesh_loopcut.c b/source/blender/editors/mesh/editmesh_loopcut.c
index 3329d25..59fbe73 100644
--- a/source/blender/editors/mesh/editmesh_loopcut.c
+++ b/source/blender/editors/mesh/editmesh_loopcut.c
@@ -686,7 +686,7 @@ static int loopcut_modal(bContext *C, wmOperator *op, const wmEvent *event)
 		char buf[64 + NUM_STR_REP_LEN * 2];
 		char str_rep[NUM_STR_REP_LEN * 2];
 		if (hasNumInput(&lcd->num)) {
-			outputNumInput(&lcd->num, str_rep, sce->unit.scale_length);
+			outputNumInput(&lcd->num, str_rep, &sce->unit);
 		}
 		else {
 			BLI_snprintf(str_rep, NUM_STR_REP_LEN, "%d", cuts);
diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c
index 58dee62..a85801a 100644
--- a/source/blender/editors/transform/transform.c
+++ b/source/blender/editors/transform/transform.c
@@ -2872,7 +2872,7 @@ static void Bend(TransInfo *t, const int UNUSED(mval[2]))
 	if (hasNumInput(&t->num)) {
 		char c[NUM_STR_REP_LEN * 2];
 
-		outputNumInput(&(t->num), c, t->scene->unit.scale_length);
+		outputNumInput(&(t->num), c, &t->scene->unit);
 		
 		BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Bend Angle: %s Radius: %s Alt, Clamp %s"),
 		             &c[0], &c[NUM_STR_REP_LEN],
@@ -3040,7 +3040,7 @@ static void applyShear(TransInfo *t, const int UNUSED(mval[2]))
 	if (hasNumInput(&t->num)) {
 		char c[NUM_STR_REP_LEN];
 		
-		outputNumInput(&(t->num), c, t->scene->unit.scale_length);
+		outputNumInput(&(t->num), c, &t->scene->unit);
 		
 		BLI_snprintf(str, MAX_INFO_LEN, IFACE_("Shear: %s %s"), c, t->proptext);
 	}
@@ -3141,7 +3141,7 @@ static void headerResize(TransInfo *t, float vec[3], char str[MAX_INFO_LEN])
 	char tvec[NUM_STR_REP_LEN * 3];
 	size_t ofs = 0;
 	if (hasNumInput(&t->num)) {
-		outputNumInput(&(t->num), tvec, t->scene->unit.scale_length);
+		outputNumInput(&(t->num), tvec, &t->scene->unit);
 	}
 	else {
 		BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.4f", vec[0]);
@@ -3555,7 +3555,7 @@ static void applyToSphere(TransInfo *t, const int UNUSED(mval[2]))
 	if (hasNumInput(&t->num)) {
 		char c[NUM_STR_REP_LEN];
 		
-		outputNumInput(&(t->num), c, t->scene->unit.scale_length);
+		outputNumInput(&(t->num), c, &t->scene->unit);
 		
 		BLI_snprintf(str, MAX_INFO_LEN, IFACE_("To Sphere: %s %s"), c, t->proptext);
 	}
@@ -3919,7 +3919,7 @@ static void applyRotation(TransInfo *t, const int UNUSED(mval[2]))
 	if (hasNumInput(&t->num)) {
 		char c[NUM_STR_REP_LEN];
 		
-		outputNumInput(&(t->num), c, t->scene->unit.scale_length);
+		outputNumInput(&(t->num), c, &t->scene->unit);
 		
 		ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("Rot: %s %s %s"), &c[0], t->con.text, t->proptext);
 	}
@@ -4023,7 +4023,7 @@ static void applyTrackball(TransInfo *t, const int UNUSED(mval[2]))
 	if (hasNumInput(&t->num)) {
 		char c[NUM_STR_REP_LEN * 2];
 
-		outputNumInput(&(t->num), c, t->scene->unit.scale_length);
+		outputNumInput(&(t->num), c, &t->scene->unit);
 
 		ofs += BLI_snprintf(str + ofs, MAX_INFO_LEN - ofs, IFACE_("Trackball: %s %s %s"),
 		                    &c[0], &c[NUM_STR_REP_LEN], t->proptext);
@@ -4125,7 +4125,7 @@ static void headerTranslation(TransInfo *t, float vec[3], char str[MAX_INFO_LEN]
 	float dist;
 
 	if (hasNumInput(&t->num)) {
-		outputNumInput(&(t->num), tvec, t->scene->unit.scale_length);
+		outputNumInput(&(t->num), tvec, &t->scene->unit);
 		dist = len_v3(t->num.val);
 	}
 	else {
@@ -4373,7 +4373,7 @@ static void applyShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
 	ofs += BLI_strncpy_rlen(str + ofs, IFACE_("Shrink/Fatten:"), MAX_INFO_LEN - ofs);
 	if (hasNumInput(&t->num)) {
 		char c[NUM_STR_REP_LEN];
-		outputNumInput(&(t->num), c, t->scene->unit.scale_length);
+		outputNumInput(&(t->num), c, &t->scen

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list