# CAE Tools Commit Details

Date: 2013-11-04 03:21:43 (5 months 19 days ago) Werner Almesberger e82667e6805ee00677ad222fd63810bb70cc0ad2 cameo/fped2d2z.pl: new options -x and -y to flip on X and Y axis cameo/fped2d2z.pl (3 diffs)

## Change Details

cameo/fped2d2z.pl
22#
33# fped2d2z.pl - Convert fped 2D stacks into 2.5D paths with Z information
44#
5# Written 2012 by Werner Almesberger
5# Written 2012, 2013 by Werner Almesberger
6# Copyright 2012, 2013 Werner Almesberger
77#
88# This program is free software; you can redistribute it and/or modify
......
1414
1515sub usage
1616{
17    print STDERR "usage: \$0 [-r|-t Zmax] [Zin=Zout ...] prefix ".
17    print STDERR "usage: \$0 [-r [-x] [-y] |-t Zmax] [Zin=Zout ...] prefix ".
1818        "[file ...]\n\n";
1919    print STDERR " Zin=Zout replace Zin with Zout\n";
2020    print STDERR " -t Zmax set the top of the piece\n";
2121    print STDERR " -r reverse Z stacking. Also swaps X and Y.\n";
22    print STDERR " -x flip on the X axis\n";
23    print STDERR " -y flip on the Y axis\n";
2224    exit(1);
2325}
2426
2527
26if (\$ARGV[0] eq "-r") {
27    shift @ARGV;
28    \$reverse = 1;
29}
30if (\$ARGV[0] eq "-t") {
28while (\$ARGV[0] =~ /^-/) {
29    if (\$ARGV[0] eq "-r") {
30        \$reverse = 1;
31    } elsif (\$ARGV[0] eq "-t") {
32        shift @ARGV;
33        \$top = \$ARGV[0];
34    } elsif (\$ARGV[0] eq "-x") {
35        \$flip_x = 1;
36    } elsif (\$ARGV[0] eq "-y") {
37        \$flip_y = 1;
38    } elsif (\$ARGV[0] =~ /^-[^0-9]/) {
39        last;
40    } else {
41        &usage;
42    }
3143    shift @ARGV;
32    \$top = shift @ARGV;
3344}
34&usage if \$ARGV[0] =~ /^-[^0-9]/;
3545
3646while (\$ARGV[0] =~ /=/) {
3747    \$map{\$`} = \$';
......
5060        \$skip = 1;
5161    }
5262    next if \$skip;
63    if (/^(-?[0-9]*\.[0-9]*)\s+(-?[0-9]*\.[0-9]*)/) {
64        \$xmin = \$1 if \$1 < \$xmin || !defined \$xmin;
65        \$xmax = \$1 if \$1 > \$xmax || !defined \$xmax;
66        \$ymin = \$2 if \$2 < \$ymin || !defined \$ymin;
67        \$ymax = \$2 if \$2 > \$ymax || !defined \$ymax;
68    }
5369    \$z{\$z} .= \$_;
5470    \$zmax = \$z if \$z > \$zmax || !defined \$zmax;
5571}
5672
73for \$z (keys %z) {
74    undef \$t;
75    for \$s (split(/\n/, \$z{\$z})) {
76        if (\$s =~ /^(-?[0-9]*\.[0-9]*)\s+(-?[0-9]*\.[0-9]*)/) {
77            \$s = ((\$xmax+\$xmin)/2-\$1)." \$2" if \$flip_y;
78
79            # re-scan, so that we can flip on both axes
80            die unless \$s =~
81                /^(-?[0-9]*\.[0-9]*)\s+(-?[0-9]*\.[0-9]*)/;
82            \$s = "\$1 ".((\$ymax+\$ymin)/2-\$2) if \$flip_x;
83        }
84        \$t .= "\$s\n";
85    }
86    \$z{\$z} = "\$t\n";
87}
88
5789if (\$reverse) {
5890    for (keys %z) {
5991        (\$t{\$zmax-\$_} = \$z{\$_}) =~

Branches:
master