Make default text in dimension box the exact (up to ten digits

after decimal) current value of the dimension, not the value
truncated to the same number of digits that are usually displayed.

And make the paste transformed screen accept expressions, not
just integers, for the count, angle, and scale.

[git-p4: depot-paths = "//depot/solvespace/": change = 2181]
solver
Jonathan Westhues 2010-10-11 19:13:41 -08:00
parent cc3b17f60e
commit 3dea64af47
2 changed files with 28 additions and 5 deletions

View File

@ -235,9 +235,12 @@ void GraphicsWindow::MenuClipboard(int id) {
} }
bool TextWindow::EditControlDoneForPaste(char *s) { bool TextWindow::EditControlDoneForPaste(char *s) {
Expr *e;
switch(edit.meaning) { switch(edit.meaning) {
case EDIT_PASTE_TIMES_REPEATED: { case EDIT_PASTE_TIMES_REPEATED: {
int v = atoi(s); e = Expr::From(s, true);
if(!e) break;
int v = (int)e->Eval();
if(v > 0) { if(v > 0) {
shown.paste.times = v; shown.paste.times = v;
} else { } else {
@ -246,11 +249,14 @@ bool TextWindow::EditControlDoneForPaste(char *s) {
break; break;
} }
case EDIT_PASTE_ANGLE: case EDIT_PASTE_ANGLE:
shown.paste.theta = WRAP_SYMMETRIC(atof(s)*PI/180, 2*PI); e = Expr::From(s, true);
if(!e) break;
shown.paste.theta = WRAP_SYMMETRIC((e->Eval())*PI/180, 2*PI);
break; break;
case EDIT_PASTE_SCALE: { case EDIT_PASTE_SCALE: {
double v = atof(s); e = Expr::From(s, true);
double v = e->Eval();
if(fabs(v) > 1e-6) { if(fabs(v) > 1e-6) {
shown.paste.scale = v; shown.paste.scale = v;
} else { } else {

View File

@ -1134,9 +1134,26 @@ void GraphicsWindow::MouseLeftDoubleClick(double mx, double my) {
sprintf(s, "%.3f", c->valA); sprintf(s, "%.3f", c->valA);
break; break;
default: default: {
strcpy(s, SS.MmToString(fabs(c->valA))); double v = fabs(c->valA);
char *def = SS.MmToString(v);
double eps = 1e-12;
if(fabs(SS.StringToMm(def) - v) < eps) {
// Show value with default number of digits after decimal,
// which is at least enough to represent it exactly.
strcpy(s, def);
} else {
// Show value with as many digits after decimal as
// required to represent it exactly, up to 10.
v /= SS.MmPerUnit();
int i;
for(i = 0; i <= 10; i++) {
sprintf(s, "%.*f", i, v);
if(fabs(atof(s) - v) < eps) break;
}
}
break; break;
}
} }
ShowGraphicsEditControl((int)p2.x, (int)p2.y-4, s); ShowGraphicsEditControl((int)p2.x, (int)p2.y-4, s);
} }