1
0
mirror of git://projects.qi-hardware.com/cae-tools.git synced 2024-12-23 15:26:45 +02:00
cae-tools/cameo/zstack.pl

65 lines
1.1 KiB
Perl
Raw Normal View History

#!/usr/bin/perl
#
# zstack.pl - Convert 2.5D paths into a stack with limited Z steps
#
# Written 2012 by Werner Almesberger
# Copyright 2012 Werner Almesberger
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
sub usage
{
print STDERR "usage: $0 z-start z-maxstep [file ...]\n";
exit(1);
}
sub issue
{
local ($z) = @_;
my $t;
#
# The order here is a bit arbitrary. We sort to make the outcome
# more predictable but it shouldn't really matter.
#
for my $c (sort { $b <=> $a } grep { $_ <= $z } keys %z) {
($t = $z{$c}) =~ s/\s+-?\d+(\.\d*)?$/ $z/mg;
print $t;
}
}
$z0 = shift @ARGV;
$zs = shift @ARGV;
$z0 =~ s/mm$//;
$zs =~ s/mm$//;
&usage unless $zs > 0;
while (<>) {
if (/^\s*$/) {
$z{$z} .= "$s\n";
undef $s;
}
$z = $3 if /^-?\d+(\.\d*)?\s+-?\d+(\.\d*)?\s+(-?\d+(\.\d*)?)/;
$s .= $_;
}
$z{$z} .= "$s\n";
$z = $z0;
for $c (sort { $b <=> $a } keys %z) {
while ($z > $c+$zs) {
$z -= $zs;
&issue($z);
}
$z = $c;
&issue($z);
}