add support for arbitrary pads, use it to add diagonals to cubesatshield
[hw/altusmetrum] / 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 process_clearance = 0.6;
22
23         public int mm2mils100(real mm) = floor (mm / 25.4 * 1000 * 100 + 0.5);
24
25         public real mils1002mm(real mils100) = mils100 * 25.4 / 100 / 1000;
26
27         public int line_thickness = 1000;
28
29         public void element_start(string name) {
30                 printf ("# author: Keith Packard\n");
31                 printf ("# email: keithp@keithp.com\n");
32                 printf ("# dist-license: GPL 2\n");
33                 printf ("# use-license: unlimited\n");
34                 printf ("Element [\"\" \"%s\" \"\" \"\" 0 0 0 0 0 100 \"\"]\n",
35                         name);
36                 printf ("(\n");
37                 
38         }
39
40         public void element_end() {
41                 printf (")\n");
42         }
43         
44         public void pad_mm_clear_mask_options(real center_x,
45                                               real center_y,
46                                               real width,
47                                               real height,
48                                               real clearance,
49                                               real mask,
50                                               string name,
51                                               string num,
52                                               string options)
53         {
54                 real    x1 = 0;
55                 real    y1 = 0;
56                 real    x2 = 0;
57                 real    y2 = 0;
58                 real    thickness = 0;
59
60                 if (width > height) {
61                         thickness = height;
62                         y1 = center_y;
63                         x1 = center_x - (width - height) / 2;
64                         y2 = center_y;
65                         x2 = center_x + (width - height) / 2;
66                 } else {
67                         thickness = width;
68                         x1 = center_x;
69                         y1 = center_y - (height - width) / 2;
70                         x2 = center_x;
71                         y2 = center_y + (height - width) / 2;
72                 }
73
74
75                 printf ("    Pad[");
76                 printf (" %6d %6d %6d %6d",
77                         mm2mils100(x1),
78                         mm2mils100(y1),
79                         mm2mils100(x2),
80                         mm2mils100(y2));
81                 printf (" %6d %6d %6d",
82                         mm2mils100(thickness),
83                         mm2mils100(clearance),
84                         mm2mils100(mask));
85                 printf (" \"%s\" \"%s\" \"%s\"]\n",
86                         name, num, options);
87         }
88
89         public void pad_mm_clear_options(real center_x,
90                                          real center_y,
91                                          real width,
92                                          real height,
93                                          real clearance,
94                                          string name,
95                                          string num,
96                                          string options)
97         {
98                 real    x1 = 0;
99                 real    y1 = 0;
100                 real    x2 = 0;
101                 real    y2 = 0;
102                 real    thickness = 0;
103
104                 if (width > height) {
105                         thickness = height;
106                         y1 = center_y;
107                         x1 = center_x - (width - height) / 2;
108                         y2 = center_y;
109                         x2 = center_x + (width - height) / 2;
110                 } else {
111                         thickness = width;
112                         x1 = center_x;
113                         y1 = center_y - (height - width) / 2;
114                         x2 = center_x;
115                         y2 = center_y + (height - width) / 2;
116                 }
117
118                 real mask = thickness + clearance / 2;
119
120                 printf ("    Pad[");
121                 printf (" %6d %6d %6d %6d",
122                         mm2mils100(x1),
123                         mm2mils100(y1),
124                         mm2mils100(x2),
125                         mm2mils100(y2));
126                 printf (" %6d %6d %6d",
127                         mm2mils100(thickness),
128                         mm2mils100(clearance),
129                         mm2mils100(mask));
130                 printf (" \"%s\" \"%s\" \"%s\"]\n",
131                         name, num, options);
132         }
133
134         public void pad_mm_clear(real center_x,
135                                  real center_y,
136                                  real width,
137                                  real height,
138                                  real clearance,
139                                  string name,
140                                  string num)
141         {
142                 pad_mm_clear_options(center_x,
143                                      center_y,
144                                      width,
145                                      height,
146                                      clearance,
147                                      name,
148                                      num,
149                                      "square");
150         }
151
152         public void pad_mm(real center_x,
153                            real center_y,
154                            real width,
155                            real height,
156                            string name,
157                            string num)
158         {
159                 pad_mm_clear(center_x,
160                              center_y,
161                              width,
162                              height,
163                              process_clearance,
164                              name,
165                              num);
166         }
167
168 public void pad_mm_arbitrary(   real x1,
169                                 real y1,
170                                 real x2,
171                                 real y2,
172                                 real thickness,
173                                 string name,
174                                 string num,
175                                 string options)
176 {
177         real clearance = process_clearance;
178
179         real mask = thickness + clearance / 2;
180
181         printf ("    Pad[");
182                 printf (" %6d %6d %6d %6d",
183                         mm2mils100(x1),
184                         mm2mils100(y1),
185                         mm2mils100(x2),
186                         mm2mils100(y2));
187                 printf (" %6d %6d %6d",
188                         mm2mils100(thickness),
189                         mm2mils100(clearance),
190                         mm2mils100(mask));
191                 printf (" \"%s\" \"%s\" \"%s\"]\n",
192                         name, num, options);
193 }
194
195         public void pin_mm_clear(real x, real y, real drill, real copper, real clearance,
196                         string name,
197                         string number)
198         {
199                 real thickness = drill + copper * 2;
200                 real mask = thickness + clearance / 2;
201                 printf("    Pin[");
202                 printf(" %6d %6d",
203                        mm2mils100(x),
204                        mm2mils100(y));
205                 printf(" %6d %6d %6d %6d",
206                        mm2mils100(thickness),
207                        mm2mils100(clearance),
208                        mm2mils100(mask),
209                        mm2mils100(drill));
210                 printf (" \"%s\" \"%s\"",
211                         name, number);
212                 printf (" \"\"]\n");
213                        
214         }
215
216         public void pin_mm_clear_options(real x, real y, real drill, real copper, real clearance,
217                                          string name,
218                                          string number,
219                                          string options)
220         {
221                 real thickness = drill + copper * 2;
222                 real mask = thickness + clearance / 2;
223                 printf("    Pin[");
224                 printf(" %6d %6d",
225                        mm2mils100(x),
226                        mm2mils100(y));
227                 printf(" %6d %6d %6d %6d",
228                        mm2mils100(thickness),
229                        mm2mils100(clearance),
230                        mm2mils100(mask),
231                        mm2mils100(drill));
232                 printf (" \"%s\" \"%s\"",
233                         name, number);
234                 printf (" \"%s\"]\n", options);
235                        
236         }
237
238         public void pin_mm_clear_mask_options(real x, real y,
239                                               real drill, real copper, real clearance, real mask,
240                                               string name, string number, string options)
241         {
242                 real thickness = drill + copper * 2;
243                 printf("    Pin[");
244                 printf(" %6d %6d",
245                        mm2mils100(x),
246                        mm2mils100(y));
247                 printf(" %6d %6d %6d %6d",
248                        mm2mils100(thickness),
249                        mm2mils100(clearance),
250                        mm2mils100(mask),
251                        mm2mils100(drill));
252                 printf (" \"%s\" \"%s\"",
253                         name, number);
254                 printf (" \"%s\"]\n", options);
255                        
256         }
257         public void pin_mm_clear_mask(real x, real y,
258                                       real drill, real copper, real clearance, real mask,
259                                       string name, string number)
260         {
261                 real thickness = copper;
262                 printf("    Pin[");
263                 printf(" %6d %6d",
264                        mm2mils100(x),
265                        mm2mils100(y));
266                 printf(" %6d %6d %6d %6d",
267                        mm2mils100(thickness),
268                        mm2mils100(clearance),
269                        mm2mils100(mask),
270                        mm2mils100(drill));
271                 printf (" \"%s\" \"%s\"",
272                         name, number);
273                 printf (" \"\"]\n");
274                        
275         }
276
277         public void pin_mm(real x, real y, real drill, real copper,
278                         string name,
279                         string number)
280         {
281                 pin_mm_clear(x, y, drill, copper, process_clearance,
282                              name, number);
283         }
284
285         public void pin_mm_options(real x, real y, real drill, real copper,
286                                    string name,
287                                    string number,
288                                    string options)
289         {
290                 pin_mm_clear_options(x, y, drill, copper, process_clearance,
291                                      name, number, options);
292         }
293
294         public void line (real x1, real y1, real x2, real y2)
295         {
296                 printf ("    ElementLine[");
297                 printf (" %6d %6d %6d %6d",
298                         mm2mils100(x1),
299                         mm2mils100(y1),
300                         mm2mils100(x2),
301                         mm2mils100(y2));
302                 printf (" %d]\n", line_thickness);
303         }
304
305         public void rect (real x, real y, real w, real h)
306         {
307                 line(x,y,x+w,y);
308                 line(x+w,y,x+w,y+h);
309                 line(x+w,y+h,x,y+h);
310                 line(x,y+h,x,y);
311         }
312
313         public void arc (real center_x, real center_y,
314                          real radius_x, real radius_y,
315                          real start_angle, real delta_angle)
316         {
317                 printf ("    ElementArc[ %6d %6d %6d %6d %3d %3d %d]\n",
318                         mm2mils100(center_x), mm2mils100(center_y),
319                         mm2mils100(radius_x), mm2mils100(radius_y),
320                         start_angle, delta_angle, line_thickness);
321         }
322 }