Make the number of digits after the decimal point (for dimensions,

as they are displayed on the drawing, and for many other places) a
user-configurable parameter.

Also reshuffle some options in the configuration screen, to put all
the stuff relating to exports together.

[git-p4: depot-paths = "//depot/solvespace/": change = 2179]
This commit is contained in:
Jonathan Westhues 2010-09-23 18:58:34 -08:00
parent e672706770
commit cc3b17f60e
5 changed files with 74 additions and 27 deletions

View File

@ -53,16 +53,23 @@ void TextWindow::ScreenChangeGridSpacing(int link, DWORD v) {
SS.TW.edit.meaning = EDIT_GRID_SPACING;
}
void TextWindow::ScreenChangeDigitsAfterDecimal(int link, DWORD v) {
char buf[128];
sprintf(buf, "%d", SS.UnitDigitsAfterDecimal());
SS.TW.ShowEditControl(55, 3, buf);
SS.TW.edit.meaning = EDIT_DIGITS_AFTER_DECIMAL;
}
void TextWindow::ScreenChangeExportScale(int link, DWORD v) {
char str[1024];
sprintf(str, "%.3f", (double)SS.exportScale);
SS.TW.ShowEditControl(57, 5, str);
SS.TW.ShowEditControl(61, 5, str);
SS.TW.edit.meaning = EDIT_EXPORT_SCALE;
}
void TextWindow::ScreenChangeExportOffset(int link, DWORD v) {
SS.TW.ShowEditControl(61, 3, SS.MmToString(SS.exportOffset));
SS.TW.ShowEditControl(65, 3, SS.MmToString(SS.exportOffset));
SS.TW.edit.meaning = EDIT_EXPORT_OFFSET;
}
@ -114,7 +121,7 @@ void TextWindow::ScreenChangeCanvasSize(int link, DWORD v) {
default: return;
}
int row = 75, col;
int row = 81, col;
if(v < 10) {
row += v*2;
col = 11;
@ -129,7 +136,7 @@ void TextWindow::ScreenChangeCanvasSize(int link, DWORD v) {
void TextWindow::ScreenChangeGCodeParameter(int link, DWORD v) {
char buf[1024] = "";
int row = 95;
int row = 93;
switch(link) {
case 'd':
SS.TW.edit.meaning = EDIT_G_CODE_DEPTH;
@ -203,6 +210,11 @@ void TextWindow::ShowConfiguration(void) {
Printf(false, "%Ba %s %Fl%Ll%f%D[change]%E",
SS.MmToString(SS.gridSpacing),
&ScreenChangeGridSpacing, 0);
Printf(false, "%Ft digits after decimal point to show%E");
Printf(false, "%Ba %d %Fl%Ll%f%D[change]%E (e.g. '%s')",
SS.UnitDigitsAfterDecimal(),
&ScreenChangeDigitsAfterDecimal, 0,
SS.MmToString(SS.StringToMm("1.23456789")));
Printf(false, "");
Printf(false, "%Ft export scale factor (1:1=mm, 1:25.4=inch)");
@ -218,7 +230,6 @@ void TextWindow::ShowConfiguration(void) {
Printf(false, " %Fd%f%Ll%c export shaded 2d triangles%E",
&ScreenChangeShadedTriangles,
SS.exportShadedTriangles ? CHECK_TRUE : CHECK_FALSE);
if(fabs(SS.exportOffset) > LENGTH_EPS) {
Printf(false, " %Fd%c curves as piecewise linear%E "
"(since cutter radius is not zero)", CHECK_TRUE);
@ -227,6 +238,9 @@ void TextWindow::ShowConfiguration(void) {
&ScreenChangePwlCurves,
SS.exportPwlCurves ? CHECK_TRUE : CHECK_FALSE);
}
Printf(false, " %Fd%f%Ll%c fix white exported lines%E",
&ScreenChangeFixExportColors,
SS.fixExportColors ? CHECK_TRUE : CHECK_FALSE);
Printf(false, "");
Printf(false, "%Ft export canvas size: "
@ -259,17 +273,6 @@ void TextWindow::ShowConfiguration(void) {
SS.MmToString(SS.exportCanvas.dy), &ScreenChangeCanvasSize, 13);
}
Printf(false, "");
Printf(false, " %Fd%f%Ll%c fix white exported lines%E",
&ScreenChangeFixExportColors,
SS.fixExportColors ? CHECK_TRUE : CHECK_FALSE);
Printf(false, " %Fd%f%Ll%c draw triangle back faces in red%E",
&ScreenChangeBackFaces,
SS.drawBackFaces ? CHECK_TRUE : CHECK_FALSE);
Printf(false, " %Fd%f%Ll%c check sketch for closed contour%E",
&ScreenChangeCheckClosedContour,
SS.checkClosedContour ? CHECK_TRUE : CHECK_FALSE);
Printf(false, "");
Printf(false, "%Ft exported g code parameters");
Printf(false, "%Ba%Ft depth: %Fd%s %Fl%Ld%f[change]%E",
@ -280,6 +283,14 @@ void TextWindow::ShowConfiguration(void) {
SS.MmToString(SS.gCode.feed), &ScreenChangeGCodeParameter);
Printf(false, "%Bd%Ft plunge fd: %Fd%s %Fl%LP%f[change]%E",
SS.MmToString(SS.gCode.plungeFeed), &ScreenChangeGCodeParameter);
Printf(false, "");
Printf(false, " %Fd%f%Ll%c draw triangle back faces in red%E",
&ScreenChangeBackFaces,
SS.drawBackFaces ? CHECK_TRUE : CHECK_FALSE);
Printf(false, " %Fd%f%Ll%c check sketch for closed contour%E",
&ScreenChangeCheckClosedContour,
SS.checkClosedContour ? CHECK_TRUE : CHECK_FALSE);
Printf(false, "");
Printf(false, " %Ftgl vendor %E%s", glGetString(GL_VENDOR));
@ -338,6 +349,16 @@ bool TextWindow::EditControlDoneForConfiguration(char *s) {
InvalidateGraphics();
break;
}
case EDIT_DIGITS_AFTER_DECIMAL: {
int v = atoi(s);
if(v < 0 || v > 8) {
Error("Specify between 0 and 8 digits after the decimal.");
} else {
SS.SetUnitDigitsAfterDecimal(v);
}
InvalidateGraphics();
break;
}
case EDIT_EXPORT_SCALE: {
Expr *e = Expr::From(s, true);
if(e) {

View File

@ -64,6 +64,9 @@ void SolveSpace::Init(char *cmdLine) {
maxSegments = CnfThawDWORD(10, "MaxSegments");
// View units
viewUnits = (Unit)CnfThawDWORD((DWORD)UNIT_MM, "ViewUnits");
// Number of digits after the decimal point
afterDecimalMm = CnfThawDWORD(2, "AfterDecimalMm");
afterDecimalInch = CnfThawDWORD(3, "AfterDecimalInch");
// Camera tangent (determines perspective)
cameraTangent = CnfThawFloat(0.3f/1e3f, "CameraTangent");
// Grid spacing
@ -157,8 +160,11 @@ void SolveSpace::Exit(void) {
CnfFreezeFloat((float)chordTol, "ChordTolerance");
// Max pwl segments to generate
CnfFreezeDWORD((DWORD)maxSegments, "MaxSegments");
// Display/entry units
// View units
CnfFreezeDWORD((DWORD)viewUnits, "ViewUnits");
// Number of digits after the decimal point
CnfFreezeDWORD((DWORD)afterDecimalMm, "AfterDecimalMm");
CnfFreezeDWORD((DWORD)afterDecimalInch, "AfterDecimalInch");
// Camera tangent (determines perspective)
CnfFreezeFloat((float)cameraTangent, "CameraTangent");
// Grid spacing
@ -228,15 +234,18 @@ char *SolveSpace::UnitName(void) {
char *SolveSpace::MmToString(double v) {
static int WhichBuf;
static char Bufs[8][128];
char fmt[128];
WhichBuf++;
if(WhichBuf >= 8 || WhichBuf < 0) WhichBuf = 0;
char *s = Bufs[WhichBuf];
if(viewUnits == UNIT_INCHES) {
sprintf(s, "%.3f", v/25.4);
sprintf(fmt, "%%.%df", afterDecimalInch);
sprintf(s, fmt, v/25.4);
} else {
sprintf(s, "%.2f", v);
sprintf(fmt, "%%.%df", afterDecimalMm);
sprintf(s, fmt, v);
}
return s;
}
@ -249,6 +258,16 @@ double SolveSpace::StringToMm(char *str) {
double SolveSpace::ChordTolMm(void) {
return SS.chordTol / SS.GW.scale;
}
int SolveSpace::UnitDigitsAfterDecimal(void) {
return (viewUnits == UNIT_INCHES) ? afterDecimalInch : afterDecimalMm;
}
void SolveSpace::SetUnitDigitsAfterDecimal(int v) {
if(viewUnits == UNIT_INCHES) {
afterDecimalInch = v;
} else {
afterDecimalMm = v;
}
}
double SolveSpace::CameraTangent(void) {
if(!usePerspectiveProj) {

View File

@ -645,11 +645,16 @@ public:
UNIT_INCHES,
} Unit;
Unit viewUnits;
int afterDecimalMm;
int afterDecimalInch;
char *MmToString(double v);
double ExprToMm(Expr *e);
double StringToMm(char *s);
char *UnitName(void);
double MmPerUnit(void);
int UnitDigitsAfterDecimal(void);
void SetUnitDigitsAfterDecimal(int v);
double ChordTolMm(void);
bool usePerspectiveProj;
double CameraTangent(void);

16
ui.h
View File

@ -141,13 +141,14 @@ public:
static const int EDIT_MAX_SEGMENTS = 104;
static const int EDIT_CAMERA_TANGENT = 105;
static const int EDIT_GRID_SPACING = 106;
static const int EDIT_EXPORT_SCALE = 107;
static const int EDIT_EXPORT_OFFSET = 108;
static const int EDIT_CANVAS_SIZE = 109;
static const int EDIT_G_CODE_DEPTH = 110;
static const int EDIT_G_CODE_PASSES = 111;
static const int EDIT_G_CODE_FEED = 112;
static const int EDIT_G_CODE_PLUNGE_FEED = 113;
static const int EDIT_DIGITS_AFTER_DECIMAL = 107;
static const int EDIT_EXPORT_SCALE = 108;
static const int EDIT_EXPORT_OFFSET = 109;
static const int EDIT_CANVAS_SIZE = 110;
static const int EDIT_G_CODE_DEPTH = 120;
static const int EDIT_G_CODE_PASSES = 121;
static const int EDIT_G_CODE_FEED = 122;
static const int EDIT_G_CODE_PLUNGE_FEED = 123;
// For TTF text
static const int EDIT_TTF_TEXT = 300;
// For the step dimension screen
@ -285,6 +286,7 @@ public:
static void ScreenChangeMaxSegments(int link, DWORD v);
static void ScreenChangeCameraTangent(int link, DWORD v);
static void ScreenChangeGridSpacing(int link, DWORD v);
static void ScreenChangeDigitsAfterDecimal(int link, DWORD v);
static void ScreenChangeExportScale(int link, DWORD v);
static void ScreenChangeExportOffset(int link, DWORD v);
static void ScreenChangeGCodeParameter(int link, DWORD v);

View File

@ -3,7 +3,7 @@ fix anti-aliased edge bug with filled contours
crude DXF, HPGL import
a request to import a plane thing
make export assemble only contours in same group
rotation works about first point under cursor
rotation of model view works about z of first point under cursor
-----
rounding, as a special group