From 4fa9e129ee75ed86b4db629094622a41a760029a Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Sat, 2 Nov 2013 13:26:04 -0300 Subject: [PATCH] cameo/fped2stl.pl: sort layers by Z position This way, the ordering of the layer stack doesn't matter. --- cameo/fped2stl.pl | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/cameo/fped2stl.pl b/cameo/fped2stl.pl index 79940b9..51204f4 100755 --- a/cameo/fped2stl.pl +++ b/cameo/fped2stl.pl @@ -23,10 +23,11 @@ sub usage sub flush { - local ($z1) = sprintf("%e", $_[0]); + local ($name, $z, $z1, $s) = @_; - $z = sprintf("%e", $z); return unless defined $s; + $z = sprintf("%e", $z); + $z1 = sprintf("%e", $z1); print STDERR "$name $z ...\n"; $^F = 20; pipe SR, SW; @@ -66,16 +67,21 @@ $pfx = shift @ARGV; $skip = 1; while (<>) { if (/^# $pfx(.*?)-(\d+(\.\d*)?)\s*$/) { - &flush($2); - $name = $1; $z = $2; - undef $s; + $name{$z} = $1; + undef $s{$z}; $skip = 0; } elsif (/^# /) { $skip = 1; } next if $skip; next if /^#/; - $s .= $_; + $s{$z} .= $_; } -&flush(0); + +undef $last; +for $z (sort { $b <=> $a } keys %s) { + &flush($name{$last}, $last, $z, $s{$last}) if defined $last; + $last = $z; +} +&flush($name{$last}, $last, 0, $s{$last});