Stefan Schuermans commited on 2013-06-25 19:30:26
Showing 1 changed files, with 69 additions and 0 deletions.
| ... | ... |
@@ -0,0 +1,69 @@ |
| 1 |
+#! /usr/bin/perl |
|
| 2 |
+ |
|
| 3 |
+use strict; |
|
| 4 |
+use warnings; |
|
| 5 |
+ |
|
| 6 |
+if (@ARGV < 1) {
|
|
| 7 |
+ print STDERR "usage: $0 <angle in deg (cw)>\n"; |
|
| 8 |
+ exit 2; |
|
| 9 |
+} |
|
| 10 |
+my $angle = shift(@ARGV); |
|
| 11 |
+my $angle_rad = $angle * 3.14159265 / 180.0; |
|
| 12 |
+my $angle_cos = cos($angle_rad); |
|
| 13 |
+my $angle_sin = sin($angle_rad); |
|
| 14 |
+ |
|
| 15 |
+sub round |
|
| 16 |
+{
|
|
| 17 |
+ my ($val) = @_; |
|
| 18 |
+ return $val < 0 ? int($val - 0.5) : int($val + 0.5); |
|
| 19 |
+} |
|
| 20 |
+ |
|
| 21 |
+sub rotate |
|
| 22 |
+{
|
|
| 23 |
+ my ($x, $y) = @_; |
|
| 24 |
+ |
|
| 25 |
+ my $xx = $angle_cos * $x - $angle_sin * $y; |
|
| 26 |
+ my $yy = $angle_sin * $x + $angle_cos * $y; |
|
| 27 |
+ |
|
| 28 |
+ return (round($xx), round($yy)); |
|
| 29 |
+} |
|
| 30 |
+ |
|
| 31 |
+while (my $line = <>) {
|
|
| 32 |
+ chomp $line; |
|
| 33 |
+ |
|
| 34 |
+ if ($line =~ /^\s+Pad\s*\[([0-9-]+)\s+([0-9-]+)\s+([0-9-]+)\s+([0-9-]+)\s+([0-9-]+)\s+([0-9-]+)\s+([0-9-]+)\s+"([^"]*)"\s+"([^"]*)"\s+("[^"]*"|0x[0-9A-Fa-f]+)\]\s*$/) {
|
|
| 35 |
+ my ($x1, $y1, $x2, $y2, $width, $clear, $mask, $name, $no, $flags) = |
|
| 36 |
+ ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10); |
|
| 37 |
+ my ($xx1, $yy1) = rotate($x1, $y1); |
|
| 38 |
+ my ($xx2, $yy2) = rotate($x2, $y2); |
|
| 39 |
+ $line = "\tPad[$xx1 $yy1 $xx2 $yy2 $width $clear $mask \"$name\" \"$no\" $flags]"; |
|
| 40 |
+ } |
|
| 41 |
+ |
|
| 42 |
+ elsif ($line =~ /^\s+Pin\s*\[([0-9-]+)\s+([0-9-]+)\s+([0-9-]+)\s+([0-9-]+)\s+([0-9-]+)\s+([0-9-]+)\s+"([^"]*)"\s+"([^"]*)"\s+("[^"]*"|0x[0-9A-Fa-f]+)\]\s*$/) {
|
|
| 43 |
+ my ($x, $y, $diam, $clear, $mask, $drill, $name, $no, $flags) = |
|
| 44 |
+ ($1, $2, $3, $4, $5, $6, $7, $8, $9); |
|
| 45 |
+ my ($xx, $yy) = rotate($x, $y); |
|
| 46 |
+ $line = "\tPin[$xx $yy $diam $clear $mask $drill \"$name\" \"$no\" $flags]"; |
|
| 47 |
+ } |
|
| 48 |
+ |
|
| 49 |
+ elsif ($line =~ /^\s+ElementLine\s*\[([0-9-]+)\s+([0-9-]+)\s+([0-9-]+)\s+([0-9-]+)\s+([0-9-]+)\]\s*$/) {
|
|
| 50 |
+ my ($x1, $y1, $x2, $y2, $width) = ($1, $2, $3, $4, $5); |
|
| 51 |
+ my ($xx1, $yy1) = rotate($x1, $y1); |
|
| 52 |
+ my ($xx2, $yy2) = rotate($x2, $y2); |
|
| 53 |
+ $line = "\tElementLine[$xx1 $yy1 $xx2 $yy2 $width]"; |
|
| 54 |
+ } |
|
| 55 |
+ |
|
| 56 |
+ elsif ($line =~ /^\s+ElementArc\s*\[([0-9-]+)\s+([0-9-]+)\s+([0-9-]+)\s+([0-9-]+)\s+([0-9-]+)\s+([0-9-]+)\s+([0-9-]+)\]\s*$/) {
|
|
| 57 |
+ my ($x, $y, $rx, $ry, $start, $delta, $width) = ($1, $2, $3, $4, $5, $6, $7); |
|
| 58 |
+ my ($xx, $yy) = rotate($x, $y); |
|
| 59 |
+ if ($rx != $ry) {
|
|
| 60 |
+ print STDERR "WARNING: ElementArc with rx=$rx != ry=$ry\n"; |
|
| 61 |
+ } |
|
| 62 |
+ my $start_rot = round($start - $angle); |
|
| 63 |
+ my $rr = round(($rx + $ry) / 2.0); |
|
| 64 |
+ $line = "\tElementArc[$xx $yy $rr $rr $start_rot $delta $width]"; |
|
| 65 |
+ } |
|
| 66 |
+ |
|
| 67 |
+ print $line . "\n"; |
|
| 68 |
+} |
|
| 69 |
+ |
|
| 0 | 70 |