63206dc8636bceb9cda09eeafc7100da200b5e41
[hw/teledongle] / pcb2panel
1 #!/usr/bin/perl
2 # -*- perl -*-
3
4 # Copyright 2006 DJ Delorie <dj@delorie.com>
5 # Released under the terms of the GNU General Public License, version 2
6
7 if (! @ARGV) {
8     print "Usage: pcb2panel board1.pcb board2.pcb board3.pcb > boards.pcb\n";
9     print "Then edit boards.pcb, putting each outline where you want it\n";
10     print "and sizing the board.  Then:\n";
11     print "panel2pcb boards.pcb\n";
12     print "and edit/print boards.panel.pcb\n";
13     exit 0;
14 }
15
16 for $pcb (@ARGV) {
17     $base = $pcb;
18     $base =~ s@.*/@@;
19     $base =~ s@\.pcb$@@;
20     $base{$pcb} = $base;
21     push (@pcbs, $pcb);
22     open(PCB, $pcb);
23     while (<PCB>) {
24         if (/^PCB\[".*" (\d+) (\d+)\]/) {
25             $width{$pcb} = $1;
26             $height{$pcb} = $2;
27             break;
28         }
29     }
30     close PCB;
31 }
32
33 $pw = 10000;
34 $ph = 0;
35 for $pcb (@pcbs) {
36     $pw += 10000;
37     $pw += $width{$pcb};
38     $ph = $height{$pcb} if $ph < $height{$pcb};
39 }
40 $ph += 20000;
41
42 print "PCB[\"\" $pw $ph]\n";
43 print "Grid[10000.0 0 0 1]\n";
44 print "Groups(\"1,c:2,s\")\n";
45
46 $x = 10000;
47 $y = 10000;
48 for $pcb (@pcbs) {
49     $desc = $pcb;
50     $name = $base{$pcb};
51     $value = "$width{$pcb} x $height{$pcb}";
52     $w = $width{$pcb};
53     $h = $height{$pcb};
54     print "Element[\"\" \"$desc\" \"$name\" \"$value\" $x $y 2000 2000 0 50 \"\"] (\n";
55     print "  Pin[0 0 300 0 0 100 \"1\" \"1\" \"\"]\n";
56     print "  Pin[$w 0 300 0 0 100 \"2\" \"2\" \"\"]\n";
57     print "  ElementLine[0 0 $w 0 100]\n";
58     print "  ElementLine[0 0 0 $h 100]\n";
59     print "  ElementLine[$w 0 $w $h 100]\n";
60     print "  ElementLine[0 $h $w $h 100]\n";
61     print ")\n";
62     $x += $w + 10000;
63 }
64
65 print "Layer(1 \"component\")()\n";
66 print "Layer(2 \"solder\")()\n";
67 print "Layer(3 \"silk\")()\n";
68 print "Layer(4 \"silk\")()\n";
69
70 exit 0;