Remove symbols, use shared symbols now
[hw/micropeak] / packages / footprint.5c
1 /*
2  * Copyright © 2012 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 namespace Footprint {
19
20         /* process clearance requirement */
21         public real clearance = 0.6;
22
23         public int mm2mils100(real mm) = floor (mm / 25.4 * 1000 * 100 + 0.5);
24
25         public void element_start(string name) {
26                 printf ("# author: Keith Packard\n");
27                 printf ("# email: keithp@keithp.com\n");
28                 printf ("# dist-license: GPL 2\n");
29                 printf ("# use-license: unlimited\n");
30                 printf ("Element [\"\" \"%s\" \"\" \"\" 0 0 0 0 0 100 \"\"]\n",
31                         name);
32                 printf ("(\n");
33                 
34         }
35
36         public void element_end() {
37                 printf (")\n");
38         }
39         
40         public void pad_mm(real center_x,
41                            real center_y,
42                            real width,
43                            real height,
44                            string name,
45                            string num)
46         {
47                 real    x1 = 0;
48                 real    y1 = 0;
49                 real    x2 = 0;
50                 real    y2 = 0;
51                 real    thickness = 0;
52
53                 if (width > height) {
54                         thickness = height;
55                         y1 = center_y;
56                         x1 = center_x - (width - height) / 2;
57                         y2 = center_y;
58                         x2 = center_x + (width - height) / 2;
59                 } else {
60                         thickness = width;
61                         x1 = center_x;
62                         y1 = center_y - (height - width) / 2;
63                         x2 = center_x;
64                         y2 = center_y + (height - width) / 2;
65                 }
66
67                 real mask = thickness + clearance / 2;
68
69                 printf ("    Pad[");
70                 printf (" %6d %6d %6d %6d",
71                         mm2mils100(x1),
72                         mm2mils100(y1),
73                         mm2mils100(x2),
74                         mm2mils100(y2));
75                 printf (" %6d %6d %6d",
76                         mm2mils100(thickness),
77                         mm2mils100(clearance),
78                         mm2mils100(mask));
79                 printf (" \"%s\" \"%s\" \"square\"]\n",
80                         name, num);
81         }
82
83         public void pin_mm(real x, real y, real drill, real copper,
84                         string name,
85                         string number)
86         {
87                 real thickness = drill + copper * 2;
88                 real mask = thickness + clearance / 2;
89                 printf("    Pin[");
90                 printf(" %6d %6d",
91                        mm2mils100(x),
92                        mm2mils100(y));
93                 printf(" %6d %6d %6d %6d",
94                        mm2mils100(thickness),
95                        mm2mils100(clearance),
96                        mm2mils100(mask),
97                        mm2mils100(drill));
98                 printf (" \"%s\" \"%s\"",
99                         name, number);
100                 printf (" \"\"]\n");
101                        
102         }
103
104         public void line (real x1, real y1, real x2, real y2)
105         {
106                 printf ("    ElementLine[");
107                 printf (" %6d %6d %6d %6d",
108                         mm2mils100(x1),
109                         mm2mils100(y1),
110                         mm2mils100(x2),
111                         mm2mils100(y2));
112                 printf (" 1000]\n");
113         }
114
115         public void rect (real x, real y, real w, real h)
116         {
117                 line(x,y,x+w,y);
118                 line(x+w,y,x+w,y+h);
119                 line(x+w,y+h,x,y+h);
120                 line(x,y+h,x,y);
121         }
122 }