]> www.fi.muni.cz Git - tinyboard.git/blob - panel.pl
Experimental step-up driver for chain of 5630 LEDs.
[tinyboard.git] / 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     $panelcopperlayers = ".*" unless $panelcopperlayers;
17
18     $pscript = "$base.pscript";
19     open(PS, ">$pscript");
20     push(@files_to_remove, "$base.pscript");
21
22     open(S, $file) || die("$file: $!");
23     $outname = "$base.panel.pcb";
24     $outname =~ s/pnl\.panel\.pcb/pcb/;
25     open(O, ">$outname");
26     while (<S>) {
27         if (/PCB\[.* (\S+) (\S+)\]/) {
28             s/ (\S+) (\S+)\]/ $width $height\]/;
29         }
30         s/Cursor\[.*\]/Cursor[0 0 0.0]/;
31         if (/^Flags/) {
32             s/,uniquename,/,/;
33             s/,uniquename//;
34             s/uniquename,//;
35         }
36         next if /\b(Via|Pin|Pad|ElementLine|Line|Arc|ElementArc|Text)/;
37         if (/Polygon|Element/) {
38             $hole = 0;
39             while (<S>) {
40                 $hole++ if /Hole \(/;
41                 last if /^\s*\)\s*$/ && $hole <= 0;
42                 $hole-- if /\)/;
43             }
44             next;
45         }
46         if (/Layer/) {
47             if (@panelvias) {
48                 print O @panelvias;
49                 @panelvias = ();
50             }
51         }
52         print O;
53         if (/Layer\((\d+) \"(.*)\"\)/) {
54             $lnum = $1;
55             $lname = $2;
56             print O scalar <S>;
57             print STDERR "layer $lnum $lname vs '$panelcopperlayers'\n";
58             if ($lnum =~ /$panelcopperlayers/ || $lname =~ /$panelcopperlayers/) {
59                 print O @panelcopper;
60             }
61         }
62     }
63     close O;
64     close S;
65
66     print PS "LoadFrom(Layout,$outname)\n";
67
68     $ox = $oy = 0;
69 }
70
71 sub loadboard {
72     my ($file) = @_;
73     $seq = 1 + $seq;
74
75     open(S, $file);
76     open(O, ">temp-panel.$seq");
77     while (<S>) {
78         if (/PCB\[.* (\S+) (\S+)\]/) {
79             $width = &parseval($1);
80             $height = &parseval($2);
81         }
82         s/Cursor\[.*\]/Cursor[0 0 0.0]/;
83         print O;
84     }
85     close O;
86     close S;
87     print PS "LoadFrom(LayoutToBuffer,temp-panel.$seq)\n";
88     push(@files_to_remove, "temp-panel.$seq");
89 }
90
91 sub opaste {
92     $vx = $ox;
93     $vy = $oy + $height;
94     print PS "PasteBuffer(ToLayout,$ox,$oy)\n";
95     $ox += $width;
96     $oy = 0;
97 }
98
99 sub vpaste {
100     print PS "PasteBuffer(ToLayout,$vx,$vy)\n";
101     $vy += $height;
102 }
103
104 sub done {
105     print PS "SaveTo(LayoutAs,$outname)\n";
106     print PS "Quit()\n";
107
108     close PS;
109
110     system "set -x; pcb --action-script $pscript";
111     #system "pcb -x ps $base.panel.pcb";
112     #unlink @files_to_remove;
113 }
114
115 sub parseval {
116     my ($v) = @_;
117     if ($v =~ /mil/) {
118         $v *= 100;
119     }
120     if ($v =~ /mm/) {
121         $v *= 3937.007874015748;
122     }
123     return 0 + $v;
124 }
125
126 1;