fc482b24fd20be7c1650cab65561a5b36894d7a9
[hw/teledongle] / panel.pl
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 sub baseboard {
8     my ($file, $width, $height, $nbase) = @_;
9     if (! $nbase) {
10         $base = $file;
11         $base =~ s@.*/@@;
12     } else {
13         $base = $nbase;
14     }
15
16     $pscript = "$base.pscript";
17     open(PS, ">$pscript");
18     push(@files_to_remove, "$base.pscript");
19
20     open(S, $file) || die("$file: $!");
21     $outname = "$base.panel.pcb";
22     $outname =~ s/pnl\.panel\.pcb/pcb/;
23     open(O, ">$outname");
24     while (<S>) {
25         if (/PCB\[.* (\d+) (\d+)\]/) {
26             s/ (\d+) (\d+)\]/ $width $height\]/;
27         }
28         s/Cursor\[.*\]/Cursor[0 0 0.0]/;
29         next if /\b(Via|Pin|Pad|ElementLine|Line|Arc|ElementArc|Text)/;
30         if (/Polygon|Element/) {
31             while (<S>) {
32                 last if /^\s*\)\s*$/;
33             }
34             next;
35         }
36         if (/Layer/) {
37             if (@panelvias) {
38                 print O @panelvias;
39                 @panelvias = ();
40             }
41         }
42         print O;
43         if (/Layer/) {
44             print O scalar <S>;
45             print O @panelcopper;
46         }
47     }
48     close O;
49     close S;
50
51     print PS "LoadFrom(Layout,$outname)\n";
52
53     $ox = $oy = 0;
54 }
55
56 sub loadboard {
57     my ($file) = @_;
58     $seq = 1 + $seq;
59
60     open(S, $file);
61     open(O, ">temp-panel.$seq");
62     while (<S>) {
63         if (/PCB\[.* (\d+) (\d+)\]/) {
64             $width = $1;
65             $height = $2;
66         }
67         s/Cursor\[.*\]/Cursor[0 0 0.0]/;
68         print O;
69     }
70     close O;
71     close S;
72     print PS "LoadFrom(LayoutToBuffer,temp-panel.$seq)\n";
73     push(@files_to_remove, "temp-panel.$seq");
74 }
75
76 sub opaste {
77     $vx = $ox;
78     $vy = $oy + $height;
79     print PS "PasteBuffer(ToLayout,$ox,$oy)\n";
80     $ox += $width;
81     $oy = 0;
82 }
83
84 sub vpaste {
85     print PS "PasteBuffer(ToLayout,$vx,$vy)\n";
86     $vy += $height;
87 }
88
89 sub done {
90     print PS "SaveTo(LayoutAs,$outname)\n";
91     print PS "Quit()\n";
92
93     close PS;
94
95     system "set -x; pcb --action-script $pscript";
96     #system "pcb -x ps $base.panel.pcb";
97     #unlink @files_to_remove;
98 }
99
100 1;