Mail Archives: geda-user/2016/03/23/16:58:07
The easiest way to do custom outputs like this is to post-process the
*.pcb file to a new file, and print that (just grepping out all the
line/arc/via entries, for example). For example, I have a pcb2paste
script that extracts all the pads and edits them (attached).
Otherwise, drawing pins and pads is handled differently for the GUI
than for the exporters.
#!/usr/bin/perl
# -*- perl -*-
$margin = 10000;
while ($ARGV[0] =~ /^-/) {
$opt = shift;
$bothsides = 1 if $opt eq "-b";
if ($opt eq "-m") {
$margin = shift;
}
}
$in = shift;
$out = shift;
if (! $in) {
print "pcb2paste [-b] [-m] in.pcb out.pcb\n";
print "-b\tboth sided\n";
print "\m\tmargin\n";
exit 0;
}
open (IN, $in);
open (OUT, ">$out");
while (<IN>) {
if (/^PCB\["(.*)" (.*) (.*)\]/ && $bothsides) {
($name, $width, $height) = ($1, $2, $3);
$width = $width * 2 + $margin;
$_ = "PCB[\"$name\" $width $height]\n";
}
if (/^Element/) {
if (/^Element\["" "" "" "" \d+ \d+ 0 0 0 100 ""\]/) {
$target = 1;
} else {
$target = 0;
}
($ex, $ey) = m@ ([-0-9]+) ([-0-9]+) @;
$save = $_;
$keep = 0;
while (<IN>) {
next if /Pin/;
next if /Element(Arc|Line)/;
next if /nopaste/;
if (/Pad/) {
$keep = 1;
if ($target && /Pad\[-1250 -1250 -1250 -1250 2450 2000 3500 "" "1" "square"\]/) {
$save .= "Pad[-2500 0 2500 0 100 100 100 \"\" \"1\" \"\"]\n";
$save .= "Pad[0 -2500 0 2500 100 100 100 \"\" \"1\" \"\"]\n";
if ($bothsides) {
$x1 = $width - 2*$ex - 2500;
$x2 = $width - 2*$ex + 2500;
$save .= "Pad[$x1 0 $x2 0 100 100 100 \"\" \"1\" \"\"]\n";
$x1 = $width - 2*$ex;
$save .= "Pad[$x1 -2500 $x1 2500 100 100 100 \"\" \"1\" \"\"]\n";
}
$save .= ")\n";
$_ = scalar <IN> while ! /^\s*\)/;
} else {
($prefix, $x1, $y1, $x2, $y2, $pwidth, $suffix) =
/(\s*Pad.) *(\S+) +(\S+) +(\S+) +(\S+) +(\S+) +(.*)/;
if (0) {
if ($pwidth > 7000) {
$pwidth = int($pwidth * 0.8);
} else {
$pwidth = int($pwidth * 0.8);
}
}
$save .= "$prefix$x1 $y1 $x2 $y2 $pwidth $suffix\n";
if (/Pad/ && $bothsides) {
$x1 = $width - 2*$ex - $x1;
$x2 = $width - 2*$ex - $x2;
$save .= "$prefix$x1 $y1 $x2 $y2 $pwidth $suffix\n";
}
}
} else {
$save .= $_;
}
last if /^\s+\)/;
}
print OUT $save if $keep;
next;
}
if (/^Layer.*paste/) {
print OUT;
print OUT scalar <IN>;
while (<IN>) {
print OUT;
last if /^\)/;
}
next;
}
next if /^\s*Text/;
next if /^Via/;
next if /^\s+Line/;
next if /^\s+Arc/;
next if /^\s+Arc/;
if (/Polygon/) {
while (($_=<IN>) !~ /\)/) {
if (/Hole/) {
while (($_=<IN>) !~ /\)/) {
}
}
}
next;
}
print OUT;
}
close IN;
close OUT;
- Raw text -