#!/usr/bin/perl # -*- perl -*- # Copyright 2002 DJ Delorie # Distributed under the terms of the GNU General Public License sub usage() { printf STDERR "Usage: track2pcb [flags] pcbin track [pcbout]\n"; printf STDERR "-d or --viadrill - specify via drill size\n"; exit(1); } while ($ARGV[0] =~ /^-/) { $arg = shift; if ($arg eq "-d" || $arg eq "--viadrill") { $via_drill = shift; if ($via_drill != /^\d+$/) { &usage(); } next; } &usage(); } $pcbin = shift; $track = shift; $pcbout = shift; if (!$track) { &usage(); } open(PCBIN, $pcbin) or die("can't read $pcbin: $!"); open(TRACK, $track) or die("can't read $track: $!"); if ($pcbin eq $pcbout) { $pcbtmp = "$pcbout.new"; } else { $pcbtmp = $pcbout; } if ($pcbtmp) { open(PCBOUT, ">$pcbtmp"); } else { open(PCBOUT, ">&STDOUT"); } while () { if (/^v/) { ($type, $sym, $x, $y, $sl, $el, $link, $ns) = split(' ', $_); ($type, $pad, $angle, $diam, $breadth, $sl, $fl) = split(' ', ); if ($via_drill) { $drill = $via_drill; } else { $drill = int($diam * 0.60); } $vias{"$x $y"} = "$diam $drill"; $have_vias = 1; } if (/^t/) { ($type, $image, $width, $xs, $ys, $xe, $ye, $layer, $nc) = split(' ', $_); for ($c = 0; $c<$nc; $c++) { ($type, $x, $y) = split(' ', ); $i = $index{$layer}; $index{$layer}++; $lines{$layer}[$i]{'s'} = "$xs $ys"; $lines{$layer}[$i]{'e'} = "$x $y"; $lines{$layer}[$i]{'w'} = $width; $xs = $x; $ys = $y; } $i = $index{$layer}; $index{$layer}++; $lines{$layer}[$i]{'s'} = "$xs $ys"; $lines{$layer}[$i]{'e'} = "$xe $ye"; $lines{$layer}[$i]{'w'} = $width; } } close(TRACK); while ($l = ) { if ($l =~ /Layer\((\d+).*\)/) { $cur_layer = $1; if ($have_vias) { for $v (sort keys %vias) { print PCBOUT "Via($v $vias{$v} \"\" 0)\n"; } $have_vias = undef; %vias = (); } } if ($cur_layer && $l =~ /^\s*Line\((.*\))/) { ($x1,$y1,$x2,$y2,$w,$fl) = split(' ', $1); if ($flag !~ /^0x.*10$/) { $have_line{"$x1 $y1 $x2 $y2 $layer"} = 1; $have_line{"$x2 $y2 $x1 $y1 $layer"} = 1; } } if (/Via\((\d+) (\d+) .*\)/) { delete $vias{"$1 $2"}; } if ($cur_layer && $l =~ /^\)/) { for ($i=0; $i<$index{$cur_layer}; $i++) { $m = sprintf("%s %s %d", $lines{$cur_layer}[$i]{'s'}, $lines{$cur_layer}[$i]{'e'}, $cur_layer); if (! $have_line{$m}) { printf PCBOUT ("\tLine(%s %s %d 0)\n", $lines{$cur_layer}[$i]{'s'}, $lines{$cur_layer}[$i]{'e'}, $lines{$cur_layer}[$i]{'w'}); } } $cur_layer = 0; } print PCBOUT $l; } close(PCBIN); close(PCBOUT); if ($pcbtmp ne $pcbout) { rename("$pcbout", "$pcbout.old"); rename("$pcbout.new", "$pcbout"); }