Skip to content

Commit 5d6e5ea

Browse files
nonamepetterreinholdtsen
authored andcommitted
tooledit: Fix rounding issue
A tool length of 123.4567 would be rounded to 123.457 This commit allows for 9 digits instead of the default 6 digits.
1 parent a179f6e commit 5d6e5ea

7 files changed

Lines changed: 117 additions & 5 deletions

File tree

configs/sim/axis/sim_mm.tbl

Lines changed: 0 additions & 1 deletion
This file was deleted.

configs/sim/axis/sim_mm.tbl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
T1 P1 Z0.511 D3 ;3mm end mill
2+
T2 P4 Z0.1 D1.5 ;1.5mm end mill
3+
T3 P3 Z1.273 D5 ;5mm tap drill
4+
T4 P2 Z10 D16 ;16 mm schaftfräser
5+
T5 P5 Z25 D25 ;25'er fräser
6+
T6 P6 Z6 D6 ;tool 6
7+
T7 P7 Z7 D7 ;7
8+
T8 P8 Z8 D8 ;8
9+
T9 P9 Z9 D9 ;9
10+
T10 P10 Z10 D10 ;10
11+
T11 P11 Z11 D11 ;11
12+
T12 P12 Z12 D12 ;12
13+
T13 P13 Z13 D13 ;13
14+
T14 P14 Z14 D14 ;14
15+
T15 P15 Z15 D15 ;15
16+
T16 P16 Z16 D16 ;16
17+
T17 P17 Z17 D17 ;17
18+
T18 P18 Z18 D18 ;18
19+
T19 P19 Z19 D19 ;19
20+
T20 P20 Z20 D20 ;20
21+
T21 P21 Z21 D21 ;21
22+
T22 P22 Z22 D22 ;22
23+
T23 P23 Z23 D23 ;23
24+
T24 P24 Z24 D24 ;24

debian/control.top.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Build-Depends:
4343
tcl@TCLTK_VERSION@-dev,
4444
tclx,
4545
tk@TCLTK_VERSION@-dev,
46+
xvfb,
4647
yapps2
4748
Build-Depends-Indep:
4849
@DOC_DEPENDS@,

tcl/tooledit.tcl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,17 @@ if [catch {package require Linuxcnc} msg] {
5454
# since "_" is not defined for standalone usage, make a proc named "_"
5555
if {"" == [info command "_"]} {
5656
package require msgcat
57-
proc _ {s} {return [::msgcat::mc $s]}
57+
proc _ {s} {
58+
return [::msgcat::mc $s]
59+
}
5860
}
5961
#-----------------------------------------------------------------------
6062

6163

6264
proc ::tooledit::init { {columns ""} } {
6365
if [file readable ~/.tooleditrc] {
6466
if [catch {source ~/.tooleditrc} msg] {
65-
puts stderr "[_ "Problem reading ~/.tooleditrc"]:"\n$msg"
67+
puts stderr "[_ "Problem reading ~/.tooleditrc"]:\n$msg"
6668
}
6769
if [info exists geometry] {
6870
set ::te(top,restore,geometry) $geometry
@@ -96,7 +98,7 @@ proc ::tooledit::init { {columns ""} } {
9698

9799
set ::te(filemod) 0
98100
set ::te(fmt,int) %d
99-
set ::te(fmt,real) %g
101+
set ::te(fmt,real) %.9g
100102
set ::te(fmt,angle) %f
101103
set ::te(msg,last) ""
102104
set ::te(pollms) 2000
@@ -311,7 +313,7 @@ proc ::tooledit::readfile {filename} {
311313
foreach item {t p x y z a b c u v w d i j q comment} {
312314
set u($item) ""
313315
}
314-
set newline [string tolower $newline]
316+
# extract the comment as is (without converting it to lower case)
315317
set i1 [string first \; $newline]
316318
if {$i1 >= 0} {
317319
set u(comment) [string range $newline [expr $i1 +1] end]
@@ -320,6 +322,7 @@ proc ::tooledit::readfile {filename} {
320322
set newline [string trim $newline]
321323
}
322324

325+
set newline [string tolower $newline]
323326
if {"$newline" == ""} {
324327
lappend ::te(global,comments) $u(comment)
325328
continue

tests/tooledit/expected

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
T1 P1 Z123 D3 ;3mm end mill
2+
T2 P4 Z123 D1.5 ;1.5mm end mill
3+
T3 P3 Z123 D5 ;5mm tap drill
4+
T4 P2 Z123.456 D16 ;16 mm Schaftfräser
5+
T5 P5 Z0.1 D25 ;25'er Fräser
6+
T6 P6 Z0.001 D6 ;tool 6
7+
T7 P7 Z0.0001 D7 ;7
8+
T8 P8 Z12345.6789 D8 ;8
9+
T9 P9 Z12345 D9 ;9
10+
T10 P10 Z1234.12346 D10 ;10
11+
T11 P11 Z12345.1235 D11 ;11
12+
T12 P12 Z123456.123 D12 ;12
13+
T13 P13 Z1234567.12 D13 ;13
14+
T14 P14 Z12345678.1 D14 ;14
15+
T15 P15 Z123456789 D15 ;15
16+
T16 P16 Z1.01 D16 ;16
17+
T17 P17 Z1.001 D17 ;17
18+
T18 P18 Z1.0001 D18 ;18
19+
T19 P19 Z1.00001 D19 ;19
20+
T20 P20 Z1.000001 D20 ;20
21+
T21 P21 Z1.0000001 D21 ;21

tests/tooledit/test.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
# test if floating point numbers are formatted correctly
3+
4+
if ! command -v xvfb-run &> /dev/null; then
5+
echo "xvfb-run could not be found, we assume everything works" > /dev/stderr
6+
cat expected
7+
exit 0
8+
fi
9+
10+
11+
#create temporary files so we don't write into write access problems
12+
infile=$(mktemp)
13+
outfile=$(mktemp)
14+
cat test.tbl > $infile
15+
16+
# run the test
17+
xvfb-run ${LINUXCNC_EMCSH/wish/tclsh} test.tcl $infile $outfile 2> tclerror.log;
18+
19+
if [ $(cat tclerror.log | wc -l) -ne 0 ]; then
20+
cat tclerror.log
21+
exit 1
22+
fi
23+
24+
# write the resulting tool table to stdout so the test framework can evaluate it
25+
cat $outfile
26+
27+
# remove the temporary files
28+
rm $infile $outfile $outfile".bak"
29+
30+
exit 0

tests/tooledit/test.tbl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
T1 P1 Z123 D3 ;3mm end mill
2+
T2 P4 Z123.0 D1.5 ;1.5mm end mill
3+
T3 P3 Z123.000 D5 ;5mm tap drill
4+
T4 P2 Z123.456 D16 ;16 mm Schaftfräser
5+
T5 P5 Z0.1 D25 ;25'er Fräser
6+
T6 P6 Z0.001 D6 ;tool 6
7+
T7 P7 Z0.0001 D7 ;7
8+
T8 P8 Z12345.6789 D8 ;8
9+
T9 P9 Z12345.0 D9 ;9
10+
T10 P10 Z1234.123456 D10 ;10
11+
T11 P11 Z12345.123456 D11 ;11
12+
T12 P12 Z123456.123456 D12 ;12
13+
T13 P13 Z1234567.123456 D13 ;13
14+
T14 P14 Z12345678.123456 D14 ;14
15+
T15 P15 Z123456789.123456 D15 ;15
16+
T16 P16 Z1.01 D16 ;16
17+
T17 P17 Z1.001 D17 ;17
18+
T18 P18 Z1.0001 D18 ;18
19+
T19 P19 Z1.00001 D19 ;19
20+
T20 P20 Z1.000001 D20 ;20
21+
T21 P21 Z1.0000001 D21 ;21

tests/tooledit/test.tcl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
source ../../tcl/tooledit.tcl
2+
3+
set infile [lindex $argv 0]
4+
set outfile [lindex $argv 1]
5+
6+
# get rid of the default window
7+
wm withdraw .
8+
# run tooledit using the test.tbl
9+
tooledit::tooledit $infile {x y z a b c u v w diam front back orien}
10+
# write the test.tbl to result.tbl
11+
tooledit::writefile $outfile
12+
# finish up
13+
exit 0

0 commit comments

Comments
 (0)