From 3dea64af47b3d2d9f5072487f865ef81b60fc54c Mon Sep 17 00:00:00 2001 From: Jonathan Westhues Date: Mon, 11 Oct 2010 19:13:41 -0800 Subject: [PATCH] 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] --- clipboard.cpp | 12 +++++++++--- mouse.cpp | 21 +++++++++++++++++++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/clipboard.cpp b/clipboard.cpp index a93b47d2..392fe7c2 100644 --- a/clipboard.cpp +++ b/clipboard.cpp @@ -235,9 +235,12 @@ void GraphicsWindow::MenuClipboard(int id) { } bool TextWindow::EditControlDoneForPaste(char *s) { + Expr *e; switch(edit.meaning) { 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) { shown.paste.times = v; } else { @@ -246,11 +249,14 @@ bool TextWindow::EditControlDoneForPaste(char *s) { break; } 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; case EDIT_PASTE_SCALE: { - double v = atof(s); + e = Expr::From(s, true); + double v = e->Eval(); if(fabs(v) > 1e-6) { shown.paste.scale = v; } else { diff --git a/mouse.cpp b/mouse.cpp index fa879b6f..f3e9df4c 100644 --- a/mouse.cpp +++ b/mouse.cpp @@ -1134,9 +1134,26 @@ void GraphicsWindow::MouseLeftDoubleClick(double mx, double my) { sprintf(s, "%.3f", c->valA); break; - default: - strcpy(s, SS.MmToString(fabs(c->valA))); + default: { + 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; + } } ShowGraphicsEditControl((int)p2.x, (int)p2.y-4, s); }