[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [22410] branches/blender2.5/blender/source /blender: unit grid snap while transforming, display units in the header.

Campbell Barton ideasman42 at gmail.com
Wed Aug 12 19:02:03 CEST 2009


Revision: 22410
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=22410
Author:   campbellbarton
Date:     2009-08-12 19:02:03 +0200 (Wed, 12 Aug 2009)

Log Message:
-----------
unit grid snap while transforming, display units in the header.

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/blenkernel/BKE_unit.h
    branches/blender2.5/blender/source/blender/blenkernel/intern/unit.c
    branches/blender2.5/blender/source/blender/editors/space_view3d/view3d_draw.c
    branches/blender2.5/blender/source/blender/editors/transform/transform.c

Modified: branches/blender2.5/blender/source/blender/blenkernel/BKE_unit.h
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/BKE_unit.h	2009-08-12 16:37:05 UTC (rev 22409)
+++ branches/blender2.5/blender/source/blender/blenkernel/BKE_unit.h	2009-08-12 17:02:03 UTC (rev 22410)
@@ -39,6 +39,9 @@
 /* the size of the unit used for this value (used for calculating the ckickstep) */
 double bUnit_ClosestScalar(double value, int system, int type);
 
+/* base scale for these units */
+double bUnit_BaseScalar(int system, int type);
+
 /* loop over scales, coudl add names later */
 //double bUnit_Iter(void **unit, char **name, int system, int type);
 

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/unit.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/unit.c	2009-08-12 16:37:05 UTC (rev 22409)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/unit.c	2009-08-12 17:02:03 UTC (rev 22410)
@@ -68,11 +68,16 @@
 	{"centimeter", "Centimeters",	"cm", NULL,	0.01, 0.0,			B_UNIT_DEF_NONE},
 	{"millimeter", "Millimeters",	"mm", NULL,	0.001, 0.0,			B_UNIT_DEF_NONE},
 	{"micrometer", "Micrometers",	"um", "µm",	0.000001, 0.0,		B_UNIT_DEF_NONE}, // micron too?
+
+	/* These get displayed because of float precision problems in the transform header,
+	 * could work around, but for now probably people wont use these */
+	/*
 	{"nanometer", "Nanometers",		"nm", NULL,	0.000000001, 0.0,	B_UNIT_DEF_NONE},
 	{"picometer", "Picometers",		"pm", NULL,	0.000000000001, 0.0,B_UNIT_DEF_NONE},
+	*/
 	{NULL, NULL, NULL,	NULL, 0.0, 0.0}
 };
-static struct bUnitCollection buMetricLenCollecton = {buMetricLenDef, 1, 0, sizeof(buMetricLenDef)/sizeof(bUnitDef)};
+static struct bUnitCollection buMetricLenCollecton = {buMetricLenDef, 3, 0, sizeof(buMetricLenDef)/sizeof(bUnitDef)};
 
 static struct bUnitDef buImperialLenDef[] = {
 	{"mile", "Miles",				"mi", "m",	1609.344, 0.0,	B_UNIT_DEF_NONE},
@@ -83,7 +88,7 @@
 	{"thou", "Thous",				"mil", NULL,0.0000254, 0.0,	B_UNIT_DEF_NONE},
 	{NULL, NULL, NULL, NULL, 0.0, 0.0}
 };
-static struct bUnitCollection buImperialLenCollecton = {buImperialLenDef, 2, 0, sizeof(buImperialLenDef)/sizeof(bUnitDef)};
+static struct bUnitCollection buImperialLenCollecton = {buImperialLenDef, 3, 0, sizeof(buImperialLenDef)/sizeof(bUnitDef)};
 
 
 /* Time */
@@ -390,6 +395,12 @@
 	return unit->scalar;
 }
 
+double bUnit_BaseScalar(int system, int type)
+{
+	bUnitCollection *usys = unit_get_system(system, type);
+	return unit_default(usys)->scalar;
+}
+
 /* external access */
 void bUnit_GetSystem(void **usys_pt, int *len, int system, int type)
 {

Modified: branches/blender2.5/blender/source/blender/editors/space_view3d/view3d_draw.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/space_view3d/view3d_draw.c	2009-08-12 16:37:05 UTC (rev 22409)
+++ branches/blender2.5/blender/source/blender/editors/space_view3d/view3d_draw.c	2009-08-12 17:02:03 UTC (rev 22410)
@@ -244,7 +244,6 @@
 	float wx, wy, x, y, fw, fx, fy, dx;
 	float vec4[4];
 	char col[3], col2[3];
-	short sublines = v3d->gridsubdiv;
 	
 	*grid_unit= NULL;
 
@@ -261,7 +260,8 @@
 	x= (wx)*fx/fw;
 	y= (wy)*fy/fw;
 
-	vec4[0]=vec4[1]=v3d->grid; 
+	vec4[0]=vec4[1]= (U.unit_system) ? 1.0 : v3d->grid;
+
 	vec4[2]= 0.0;
 	vec4[3]= 1.0;
 	Mat4MulVec4fl(rv3d->persmat, vec4);
@@ -278,6 +278,8 @@
 	UI_ThemeColor(TH_GRID);
 	
 	if(U.unit_system) {
+		/* Use GRID_MIN_PX*2 for units because very very small grid
+		 * items are less useful when dealing with units */
 		void *usys;
 		int len, i;
 		double scalar;
@@ -292,15 +294,16 @@
 				scalar= bUnit_GetScaler(usys, i);
 
 				dx_scalar = dx * scalar * U.unit_scale_length;
-				if (dx_scalar < GRID_MIN_PX)
+				if (dx_scalar < (GRID_MIN_PX*2))
 					continue;
 
-				/* Store the smallest drawn grid size units name so users know how bit each grid cell is */
-				if(*grid_unit==NULL)
+				/* Store the smallest drawn grid size units name so users know how big each grid cell is */
+				if(*grid_unit==NULL) {
 					*grid_unit= bUnit_GetNamePlural(usys, i);
+					v3d->gridview= (scalar * U.unit_scale_length);
+				}
+				blend_fac= 1-((GRID_MIN_PX*2)/dx_scalar);
 
-				blend_fac= 1-(GRID_MIN_PX/dx_scalar);
-
 				/* tweak to have the fade a bit nicer */
 				blend_fac= (blend_fac * blend_fac) * 2.0f;
 				CLAMP(blend_fac, 0.3f, 1.0f);
@@ -313,6 +316,8 @@
 		}
 	}
 	else {
+		short sublines = v3d->gridsubdiv;
+
 		if(dx<GRID_MIN_PX) {
 			v3d->gridview*= sublines;
 			dx*= sublines;

Modified: branches/blender2.5/blender/source/blender/editors/transform/transform.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/transform/transform.c	2009-08-12 16:37:05 UTC (rev 22409)
+++ branches/blender2.5/blender/source/blender/editors/transform/transform.c	2009-08-12 17:02:03 UTC (rev 22410)
@@ -89,6 +89,7 @@
 #include "BKE_pointcache.h"
 #include "BKE_utildefines.h"
 #include "BKE_context.h"
+#include "BKE_unit.h"
 
 //#include "BSE_view.h"
 
@@ -3039,12 +3040,22 @@
 		applyAspectRatio(t, dvec);
 
 		dist = VecLength(vec);
-		sprintf(&tvec[0], "%.4f", dvec[0]);
-		sprintf(&tvec[20], "%.4f", dvec[1]);
-		sprintf(&tvec[40], "%.4f", dvec[2]);
+		if(U.unit_system) {
+			int i, do_split= U.unit_flag & USER_UNIT_OPT_SPLIT ? 1:0;
+
+			for(i=0; i<3; i++)
+				bUnit_AsString(&tvec[i*20], dvec[i]*U.unit_scale_length, 4, U.unit_system, B_UNIT_LENGTH, do_split, 1);
+		}
+		else {
+			sprintf(&tvec[0], "%.4f", dvec[0]);
+			sprintf(&tvec[20], "%.4f", dvec[1]);
+			sprintf(&tvec[40], "%.4f", dvec[2]);
+		}
 	}
 
-	if( dist > 1e10 || dist < -1e10 )	/* prevent string buffer overflow */
+	if(U.unit_system)
+		bUnit_AsString(distvec, dist*U.unit_scale_length, 4, U.unit_system, B_UNIT_LENGTH, U.unit_flag & USER_UNIT_OPT_SPLIT, 0);
+	else if( dist > 1e10 || dist < -1e10 )	/* prevent string buffer overflow */
 		sprintf(distvec, "%.4e", dist);
 	else
 		sprintf(distvec, "%.4f", dist);





More information about the Bf-blender-cvs mailing list