4 * gerbertotk, simple Gerber file to tcl/tk program converter
5 * Copyright (C) 1996 Albert John FitzPatrick III
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * Contact addresses for paper mail and Email:
22 * Albert John FitzPatrick III/ 8803 Humming Bird Lane/ Quinton, VA 23141/
28 /* WARNING: This is an alpha version. Use it with many grains of salt. */
30 static char Copyright
[] = "Copyright (C) 1996 Albert John FitzPatrick III";
34 * cat *.gbr | gerbertotk | wish
40 typedef long GerberValue
;
58 #define tkX(x) (800L * (x) * tkScale / gbMaxX)
59 #define tkY(y) ((600L * (gbMaxY - (y)) * tkScale / gbMaxY))
62 do_cmd(GerberContext
*gc
, int cmd
, char *buffer
)
64 GerberValue value
= atol(buffer
);
89 /* Move with light on. */
90 printf(".f.c create line %ld %ld %ld %ld\n",
91 (long) tkX(gc
->gc_x1
),
92 (long) tkY(gc
->gc_y1
),
93 (long) tkX(gc
->gc_x2
),
96 gc
->gc_x1
= gc
->gc_x2
;
97 gc
->gc_y1
= gc
->gc_y2
;
100 /* Move with light off. */
101 gc
->gc_x1
= gc
->gc_x2
;
102 gc
->gc_y1
= gc
->gc_y2
;
105 /* Move with light off. Flash light on. Turn light off. */
106 printf(".f.c create line %ld %ld %ld %ld\n",
107 (long) tkX(gc
->gc_x2
),
108 (long) tkY(gc
->gc_y2
),
109 (long) tkX(gc
->gc_x2
),
110 (long) tkY(gc
->gc_y2
)
121 gc
->gc_inComment
= 0;
124 /* FIXME: what if missing on first time?
125 fprintf(stderr, "Missing Gerber command character.\n");
132 main(int argc
, char *argv
[])
140 fprintf(stderr
, "%s: %s\n",
144 fprintf(stderr
, "%s: Usage: %s\n",
162 printf("button .exit \\\n");
163 printf("\t-command exit \\\n");
164 printf("\t-text Exit\n");
165 printf("frame .f\n");
166 printf("canvas .f.c \\\n");
167 printf("\t-width 800 \\\n");
168 printf("\t-height 600 \\\n");
169 printf("\t-scrollregion { 0 0 10000 10000 } \\\n");
170 printf("\t-xscroll { .f.h set } \\\n");
171 printf("\t-yscroll { .f.v set }\n");
172 printf("scrollbar .f.v \\\n");
173 printf("\t-orient vertical \\\n");
174 printf("\t-command { .f.c yview }\n");
175 printf("scrollbar .f.h \\\n");
176 printf("\t-orient horizontal \\\n");
177 printf("\t-command { .f.c xview }\n");
180 printf("pack .exit .f \\\n");
181 printf("\t-side top \\\n");
182 printf("\t-expand yes \\\n");
183 printf("\t-fill both\n");
184 printf("pack .f.v \\\n");
185 printf("\t-side right \\\n");
186 printf("\t-fill y\n");
187 printf("pack .f.h \\\n");
188 printf("\t-side bottom \\\n");
189 printf("\t-fill x\n");
190 printf("pack .f.c \\\n");
191 printf("\t-side left\n");
195 while ((ch
= getchar()) != EOF
) {
196 if (gc
.gc_inComment
&& ch
!= '*')
207 do_cmd(&gc
, cmd
, buffer
);
212 /* FIXME: Handle other EOB characters. */
214 do_cmd(&gc
, ch
, buffer
);
216 do_cmd(&gc
, cmd
, buffer
);
221 /* FIXME: only after EOB. */
226 /* FIXME: only after EOB. */
246 do_cmd(&gc
, cmd
, buffer
);
249 if (! gc
.gc_inComment
)
250 fprintf(stderr
, "Unknown Gerber command '%c' (%d).\n",