unit grid snap while transforming, display units in the header.

This commit is contained in:
2009-08-12 17:02:03 +00:00
parent a86aa8c34b
commit b8fcda9ea5
4 changed files with 43 additions and 13 deletions

View File

@@ -39,6 +39,9 @@ int bUnit_ReplaceString(char *str, char *str_orig, char *str_prev, double scale
/* 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);

View File

@@ -68,11 +68,16 @@ static struct bUnitDef buMetricLenDef[] = {
{"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 @@ static struct bUnitDef buImperialLenDef[] = {
{"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 @@ double bUnit_ClosestScalar(double value, int system, int type)
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)
{

View File

@@ -244,7 +244,6 @@ static void drawgrid(ARegion *ar, View3D *v3d, char **grid_unit)
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 @@ static void drawgrid(ARegion *ar, View3D *v3d, char **grid_unit)
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 @@ static void drawgrid(ARegion *ar, View3D *v3d, char **grid_unit)
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,14 +294,15 @@ static void drawgrid(ARegion *ar, View3D *v3d, char **grid_unit)
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);
blend_fac= 1-(GRID_MIN_PX/dx_scalar);
v3d->gridview= (scalar * U.unit_scale_length);
}
blend_fac= 1-((GRID_MIN_PX*2)/dx_scalar);
/* tweak to have the fade a bit nicer */
blend_fac= (blend_fac * blend_fac) * 2.0f;
@@ -313,6 +316,8 @@ static void drawgrid(ARegion *ar, View3D *v3d, char **grid_unit)
}
}
else {
short sublines = v3d->gridsubdiv;
if(dx<GRID_MIN_PX) {
v3d->gridview*= sublines;
dx*= sublines;

View File

@@ -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 @@ static void headerTranslation(TransInfo *t, float vec[3], char *str) {
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);