1
0
mirror of git://projects.qi-hardware.com/cae-tools.git synced 2024-12-23 04:50:49 +02:00

cameo/fped2d2z.pl: new options -x and -y to flip on X and Y axis

This commit is contained in:
Werner Almesberger 2013-11-03 23:21:43 -03:00
parent 30676651ec
commit e82667e680

View File

@ -2,8 +2,8 @@
#
# fped2d2z.pl - Convert fped 2D stacks into 2.5D paths with Z information
#
# Written 2012 by Werner Almesberger
# Copyright 2012 Werner Almesberger
# Written 2012, 2013 by Werner Almesberger
# Copyright 2012, 2013 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
@ -14,24 +14,34 @@
sub usage
{
print STDERR "usage: $0 [-r|-t Zmax] [Zin=Zout ...] prefix ".
print STDERR "usage: $0 [-r [-x] [-y] |-t Zmax] [Zin=Zout ...] prefix ".
"[file ...]\n\n";
print STDERR " Zin=Zout replace Zin with Zout\n";
print STDERR " -t Zmax set the top of the piece\n";
print STDERR " -r reverse Z stacking. Also swaps X and Y.\n";
print STDERR " -x flip on the X axis\n";
print STDERR " -y flip on the Y axis\n";
exit(1);
}
if ($ARGV[0] eq "-r") {
while ($ARGV[0] =~ /^-/) {
if ($ARGV[0] eq "-r") {
$reverse = 1;
} elsif ($ARGV[0] eq "-t") {
shift @ARGV;
$top = $ARGV[0];
} elsif ($ARGV[0] eq "-x") {
$flip_x = 1;
} elsif ($ARGV[0] eq "-y") {
$flip_y = 1;
} elsif ($ARGV[0] =~ /^-[^0-9]/) {
last;
} else {
&usage;
}
shift @ARGV;
$reverse = 1;
}
if ($ARGV[0] eq "-t") {
shift @ARGV;
$top = shift @ARGV;
}
&usage if $ARGV[0] =~ /^-[^0-9]/;
while ($ARGV[0] =~ /=/) {
$map{$`} = $';
@ -50,10 +60,32 @@ while (<>) {
$skip = 1;
}
next if $skip;
if (/^(-?[0-9]*\.[0-9]*)\s+(-?[0-9]*\.[0-9]*)/) {
$xmin = $1 if $1 < $xmin || !defined $xmin;
$xmax = $1 if $1 > $xmax || !defined $xmax;
$ymin = $2 if $2 < $ymin || !defined $ymin;
$ymax = $2 if $2 > $ymax || !defined $ymax;
}
$z{$z} .= $_;
$zmax = $z if $z > $zmax || !defined $zmax;
}
for $z (keys %z) {
undef $t;
for $s (split(/\n/, $z{$z})) {
if ($s =~ /^(-?[0-9]*\.[0-9]*)\s+(-?[0-9]*\.[0-9]*)/) {
$s = (($xmax+$xmin)/2-$1)." $2" if $flip_y;
# re-scan, so that we can flip on both axes
die unless $s =~
/^(-?[0-9]*\.[0-9]*)\s+(-?[0-9]*\.[0-9]*)/;
$s = "$1 ".(($ymax+$ymin)/2-$2) if $flip_x;
}
$t .= "$s\n";
}
$z{$z} = "$t\n";
}
if ($reverse) {
for (keys %z) {
($t{$zmax-$_} = $z{$_}) =~