]> www.fi.muni.cz Git - heater.git/blob - pcb2panel
case.scad: more improvements
[heater.git] / 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 $mydir = $0;
8 if ($mydir =~ m@/@) {
9     $mydir =~ s@[^/]*$@@;
10 } else {
11     $mydir = ".";
12 }
13
14 require "$mydir/panel.pl";
15
16 if (! @ARGV) {
17     print "Usage: pcb2panel board1.pcb board2.pcb board3.pcb > boards.pcb\n";
18     print "Then edit boards.pcb, putting each outline where you want it\n";
19     print "and sizing the board.  Then:\n";
20     print "panel2pcb boards.pcb\n";
21     print "and edit/print boards.panel.pcb\n";
22     exit 0;
23 }
24
25 for $pcb (@ARGV) {
26     $base = $pcb;
27     $base =~ s@.*/@@;
28     $base =~ s@\.pcb$@@;
29     $base{$pcb} = $base;
30     push (@pcbs, $pcb);
31     open(PCB, $pcb);
32     while (<PCB>) {
33         if (/^PCB\[".*" (\S+) (\S+)\]/) {
34             $width{$pcb} = &parseval($1);
35             $height{$pcb} = &parseval($2);
36             printf STDERR "%s : %d x %d\n", $pcb, $width{$pcb}, $height{$pcb};
37             last;
38         }
39     }
40     $outline = '';
41     while (<PCB>) {
42         if (/Layer\(.*"outline"\)/) {
43             $junk = <PCB>; # open paren
44             while (<PCB>) {
45                 last if /^\)/; # close paren
46                 ($args) = m@\[(.*)\]@;
47                 ($x1, $y1, $x2, $y2, $width) = split(' ', $args);
48                 $outline .= "  ElementLine[$x1 $y1 $x2 $y2 $width]\n";
49             }
50         }
51     }
52     push (@outlines, $outline);
53     close PCB;
54 }
55
56 $pw = 10000;
57 $ph = 0;
58 for $pcb (@pcbs) {
59     $pw += 10000;
60     $pw += $width{$pcb};
61     $ph = $height{$pcb} if $ph < $height{$pcb};
62 }
63 $ph += 20000;
64
65 print "PCB[\"\" $pw $ph]\n";
66 print "Grid[10000.0 0 0 1]\n";
67 print "DRC[799 799 800 100 1500 800]\n";
68 print "Groups(\"1,c:2,s\")\n"; #"
69
70 $x = 10000;
71 $y = 10000;
72 for ($i=0; $i<@pcbs; $i++) {
73     $pcb = $pcbs[$i];
74     $outline = $outlines[$i];
75     $desc = $pcb;
76     $name = $base{$pcb};
77     $value = "$width{$pcb} x $height{$pcb}";
78     $w = $width{$pcb};
79     $h = $height{$pcb};
80
81     print "Element[\"\" \"$desc\" \"$name\" \"$value\" $x $y 2000 2000 0 50 \"\"] (\n";
82     print "  Pin[0  0 1000 0 0 400 \"1\" \"1\" \"\"]\n";
83     print "  Pin[$w 0 1000 0 0 400 \"2\" \"2\" \"\"]\n";
84     if ($outline =~ /\S/) {
85         print $outline;
86     } else {
87         print "  ElementLine[0 0 $w 0 100]\n";
88         print "  ElementLine[0 0 0 $h 100]\n";
89         print "  ElementLine[$w 0 $w $h 100]\n";
90         print "  ElementLine[0 $h $w $h 100]\n";
91     }
92     print ")\n";
93     $x += $w + 10000;
94 }
95
96 print "Layer(1 \"component\")()\n";
97 print "Layer(2 \"solder\")()\n";
98 print "Layer(3 \"silk\")()\n";
99 print "Layer(4 \"silk\")()\n";
100
101 exit 0;