]> www.fi.muni.cz Git - tinyboard.git/blob - panel2pcb
rgb-led-string: Christmas tree mod after real-world testing
[tinyboard.git] / panel2pcb
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";
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 [-l regex] boards.pcb\n";
12     print "and edit/print boards.panel.pcb\n";
13     exit 0;
14 }
15
16 $mydir = $0;
17 if ($mydir =~ m@/@) {
18     $mydir =~ s@[^/]*$@@;
19 } else {
20     $mydir = ".";
21 }
22
23 require "$mydir/panel.pl";
24
25 $panel = shift;
26
27 if ($panel eq "-l") {
28     $panelcopperlayers = shift;
29     $panel = shift;
30 }
31
32 open(P, $panel);
33 while (<P>) {
34     if (/PCB\[.* (\S+) (\S+)\]/) {
35         $panel_width = &parseval($1);
36         $panel_height = &parseval($2);
37     }
38     if (/Element\[\"[^\"]*\" \"([^\"]*)\" \"([^\"]*)\" \"([^\"]*)\" (\S+) (\S+)/) {
39         $pcb = $1;
40         $base = $2;
41         $value = $3;
42         $mx = &parseval($4);
43         $my = &parseval($5);
44         %pinx = ();
45         %piny = ();
46     }
47     if (/Pin\[(\S+) (\S+) \S+ \S+ \S+ \S+ \"(\d)\"/) {
48         $pinx{$3} = &parseval($1);
49         $piny{$3} = &parseval($2);
50     }
51     if ($pcb && /\)/) {
52         if ($pinx{'1'} < $pinx{'2'}) {
53             $rot = 0;
54         } elsif ($pinx{'1'} > $pinx{'2'}) {
55             $rot = 2;
56         } elsif ($piny{'1'} < $piny{'2'}) {
57             $rot = 3;
58         } elsif ($piny{'1'} > $piny{'2'}) {
59             $rot = 1;
60         }
61         push (@paste, "$pcb\0$rot\0$mx\0$my");
62         $pcb = undef;
63     }
64     if (/Via/) {
65         push (@panelvias, $_);
66     }
67     if (/^Layer\([^)]*\)$/) {
68         $junk = <P>; # The opening '('
69         while ($junk = <P>) {
70             last if $junk =~ /^\)/;
71             push (@panelcopper, $junk);
72         }
73     }
74 }
75
76 $tmp = "/tmp/panel$$.pcb";
77
78 $start = $paste[0];
79 $start =~ s/\0.*//;
80
81 $panel =~ s/\.pcb$//;
82 &baseboard($start, $panel_width, $panel_height, $panel);
83
84 $lastboard = undef;
85 for $paste (sort @paste) {
86     ($pcb, $rot, $mx, $my) = split(/\0/, $paste);
87     if ($lastboard ne $pcb) {
88         &loadboard ($pcb);
89         $lastboard = $pcb;
90         $lastrot = 0;
91     }
92     while ($lastrot != $rot) {
93         print PS "PasteBuffer(Rotate,1)\n";
94         $lastrot = ($lastrot+1) % 4;
95     }
96     print PS "PasteBuffer(ToLayout,$mx,$my)\n";
97 }
98
99 &done();