4 geda_sym_format.h - gEDA symbol write function
5 Copyright (C) 2002-2010 Mario Pascucci <m.pas@libero.it>
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 visit the URL http://www.fsf.org/
29 #define PIN_SPACE 3*SCALE
30 #define PIN_LEN 3*SCALE
31 #define LABEL_SPACE 2*SCALE
32 #define DOT_SIZE SCALE
33 #define CLK_SIZE SCALE
49 #define EDACOLOR_REF 8 /* detached attrib = RED */
50 #define EDACOLOR_LABEL 9 /* text and label = GREEN */
51 #define EDACOLOR_ATTRIB 5 /* attached attribute = YELLOW */
52 #define EDACOLOR_PIN 1 /* pin = WHITE */
53 #define EDACOLOR_DOT 6 /* logic bubble = CYAN */
54 #define EDACOLOR_BODY 3 /* body part = GREEN */
57 /* text size macros */
58 #define EDASIZE_LABEL 10 /* label size */
59 #define EDASIZE_ATTRIB 10 /* attribute */
60 #define EDASIZE_PIN 8 /* pin number size */
61 #define EDASIZE_TYPE 8 /* type of pin */
66 static int text_scale
[] = {
74 * Format of gEDA .sym files
77 * T x y color size visibility show_name_value angle alignment
83 * L x1 y1 x2 y2 color width end type length space
86 * type x y width height color width end type length space filling fillwidth angle1 pitch1 angle2 pitch2
88 * B 33000 67300 2000 2000 3 60 0 2 75 50 0 -1 -1 -1 -1 -1
91 * V 38000 67000 900 3 0 0 2 75 50 0 -1 -1 -1 -1 -1
92 * type x y radius color width end type length space filling fillwidth angle1 pitch1 angle2 pitch2
95 * type x y radius start_angle sweep_angle color width end type length space
97 * A 30600 75000 2000 0 45 3 0 0 3 75 50
102 #define PI 3.141592653588
106 int initangle(float dx
, float dy
)
112 if (dy
>= 0.0) return 90;
117 if (dx
>= 0.0) return 0;
127 /* write down the gEDA symbol file
128 most of the work must be done for
129 correct symbol rendering
137 int pinx
,piny
,pinalign
; /* pin number */
138 int npinx
,npiny
,npinalign
; /* pin name */
139 int tpinx
,tpiny
,tpinalign
; /* pin type */
141 xe
= ye
= xs
= ys
= txtangle
= pinx
= piny
= pinalign
=
142 npinx
= npiny
= npinalign
= tpinx
= tpiny
= tpinalign
= 0;
145 fprintf(stderr
,"Unable to write down sym file, no pin definition available\n");
148 /* if 'VECTOR' keyword was found, but no draw instruction
149 * makes file .sym.part that stands for "partial" symbol */
150 if (vector_found
&& vector_count
== 0)
151 strcat(fnsym
,".part");
152 if (!(fsym
= fopen(fnsym
,"wb")))
154 perror("Opening sym output file");
157 xt
= sizex
+ PIN_LEN
;
159 yt
= sizey
+ PIN_LEN
;
161 /* gEDA file version */
162 fprintf(fsym
,"v %s\n",sym_version
);
164 fprintf(fsym
,"T %d %d %d %d 1 1 0 %d\n",xt
,yt
+SCALE
,EDACOLOR_REF
,EDASIZE_ATTRIB
,EDATEXT_RB
);
166 fprintf(fsym
,"uref=%s?\n",ref_str
);
168 fprintf(fsym
,"refdes=%s?\n",ref_str
);
170 fprintf(fsym
,"T %d %d %d %d 1 0 0 %d\n",xb
,yt
+SCALE
,EDACOLOR_LABEL
,EDASIZE_LABEL
,EDATEXT_LB
);
171 fprintf(fsym
,"%s\n",part_aliases
[0]);
173 fprintf(fsym
,"T %d %d %d %d 0 0 0 %d\n",xb
,yt
+3*SCALE
,EDACOLOR_ATTRIB
,EDASIZE_ATTRIB
,EDATEXT_LB
);
174 fprintf(fsym
,"device=%s\n",part_aliases
[0]);
175 if (vector_count
== 0)
178 fprintf(fsym
,"B %d %d %d %d %d 0 0 0 -1 -1 0 -1 -1 -1 -1 -1\n",xb
,yb
,sizex
,sizey
,EDACOLOR_BODY
);
182 /* drawing vectors */
183 for (i
= 0; i
< vector_count
; i
++)
185 switch (part_vectors
[i
].type
)
189 xs
= (int) (part_vectors
[i
].p
[0] * PIN_SPACE
+ 0.5) + PIN_LEN
;
190 ys
= (int) yt
- (part_vectors
[i
].p
[1] * PIN_SPACE
+ 0.5);
191 fprintf(fsym
,"T %d %d %d %d 1 0 0 %d\n",xs
,ys
,EDACOLOR_BODY
,
192 text_scale
[(int)part_vectors
[i
].p
[2]],EDATEXT_LB
);
193 fprintf(fsym
,"%s\n",part_vectors
[i
].str
);
194 free(part_vectors
[i
].str
);
198 xs
= (int) (part_vectors
[i
].p
[0] * PIN_SPACE
+ 0.5) + PIN_LEN
;
199 ys
= (int) yt
- (part_vectors
[i
].p
[1] * PIN_SPACE
+ 0.5);
200 xe
= (int) (part_vectors
[i
].p
[2] * PIN_SPACE
+ 0.5) + PIN_LEN
;
201 ye
= (int) yt
- (part_vectors
[i
].p
[3] * PIN_SPACE
+ 0.5);
202 fprintf(fsym
,"L %d %d %d %d %d 0 0 0 -1 -1\n",xs
,ys
,xe
,ye
,
207 xs
= (int) (part_vectors
[i
].p
[0] * PIN_SPACE
+ PIN_LEN
+ 0.5);
208 ys
= (int) yt
- (part_vectors
[i
].p
[1] * PIN_SPACE
+ 0.5);
209 xe
= (int) (part_vectors
[i
].p
[2] * PIN_SPACE
+ 0.5); /* radius */
210 fprintf(fsym
,"V %d %d %d %d 0 0 0 -1 -1 0 -1 -1 -1 -1 -1\n",xs
,ys
,xe
,
215 xs
= (int) (part_vectors
[i
].p
[0] * PIN_SPACE
+ PIN_LEN
+ 0.5);
216 ys
= (int) yt
- (part_vectors
[i
].p
[1] * PIN_SPACE
+ 0.5);
217 xe
= initangle(part_vectors
[i
].p
[2],-part_vectors
[i
].p
[3]); /* init angle */
218 ye
= initangle(part_vectors
[i
].p
[4],-part_vectors
[i
].p
[5]); /* end angle */
219 if (xe
< 0) xe
+= 360;
220 if (ye
< 0) ye
+= 360;
229 pinx
= (int) (part_vectors
[i
].p
[6] * PIN_SPACE
+ 0.5); /* radius */
230 fprintf(fsym
,"A %d %d %d %d %d %d 0 0 0 -1 -1\n",xs
,ys
,pinx
,xe
,ye
,
236 /* pin definiton and drawing */
238 for (i
=0; i
<pincount
; i
++)
240 if ((pinlist
[i
].num
== 0) && (pinlist
[i
].type
== PIN_TYPE_PWR
) &&
241 ((pinlist
[i
].pos
== 'T') || (pinlist
[i
].pos
== 'B')))
243 /* is a "virtual" pin, i.e. a net */
244 fprintf(fsym
,"T %d %d %d %d 0 0 0 %d\n",xb
,yt
+labely
,EDACOLOR_ATTRIB
,
245 EDASIZE_ATTRIB
,EDATEXT_LB
);
246 fprintf(fsym
,"net=%s:%d\n",pinlist
[i
].name
,pinlist
[i
].pin
);
247 labely
+= LABEL_SPACE
;
250 switch (pinlist
[i
].pos
)
255 ys
= ye
= yt
- pinlist
[i
].num
* PIN_SPACE
;
260 pinalign
= EDATEXT_RB
;
264 npinalign
= EDATEXT_LB
;
268 tpinalign
= EDATEXT_LT
;
269 if ((pinlist
[i
].flags
& PIN_CLKFLAG
) != 0)
271 /* there is "CLK" modifier */
274 fprintf(fsym
,"L %d %d %d %d %d 0 0 0 -1 -1\n",xs
,ys
+CLK_SIZE
,xs
+CLK_SIZE
,ys
,
276 fprintf(fsym
,"L %d %d %d %d %d 0 0 0 -1 -1\n",xs
,ys
-CLK_SIZE
,xs
+CLK_SIZE
,ys
,
279 if ((pinlist
[i
].flags
& PIN_DOTFLAG
) != 0)
281 /* there is "DOT" modifier */
284 fprintf(fsym
,"V %d %d %d %d 0 0 0 -1 -1 0 -1 -1 -1 -1 -1\n",xs
+DOT_SIZE
/2,ys
,DOT_SIZE
/2,
291 ys
= ye
= yt
- pinlist
[i
].num
* PIN_SPACE
;
296 pinalign
= EDATEXT_LB
;
300 npinalign
= EDATEXT_RB
;
304 tpinalign
= EDATEXT_RT
;
305 if ((pinlist
[i
].flags
& PIN_CLKFLAG
) != 0)
307 /* there is "CLK" modifier */
310 fprintf(fsym
,"L %d %d %d %d %d 0 0 0 -1 -1\n",xs
,ys
+CLK_SIZE
,xs
-CLK_SIZE
,ys
,
312 fprintf(fsym
,"L %d %d %d %d %d 0 0 0 -1 -1\n",xs
,ys
-CLK_SIZE
,xs
-CLK_SIZE
,ys
,
315 if ((pinlist
[i
].flags
& PIN_DOTFLAG
) != 0)
317 /* there is "DOT" modifier */
320 fprintf(fsym
,"V %d %d %d %d 0 0 0 -1 -1 0 -1 -1 -1 -1 -1\n",xs
-DOT_SIZE
/2,ys
,DOT_SIZE
/2,
327 xs
= xe
= xb
+ pinlist
[i
].num
* PIN_SPACE
;
332 pinalign
= EDATEXT_LB
;
336 npinalign
= EDATEXT_RB
;
340 tpinalign
= EDATEXT_RT
;
341 if ((pinlist
[i
].flags
& PIN_CLKFLAG
) != 0)
343 /* there is "CLK" modifier */
346 fprintf(fsym
,"L %d %d %d %d %d 0 0 0 -1 -1\n",xs
-CLK_SIZE
,ys
,xs
,ys
-CLK_SIZE
,
348 fprintf(fsym
,"L %d %d %d %d %d 0 0 0 -1 -1\n",xs
,ys
-CLK_SIZE
,xs
+CLK_SIZE
,ys
,
351 if ((pinlist
[i
].flags
& PIN_DOTFLAG
) != 0)
353 /* there is "DOT" modifier */
356 fprintf(fsym
,"V %d %d %d %d 0 0 0 -1 -1 0 -1 -1 -1 -1 -1\n",xs
,ys
-DOT_SIZE
/2,DOT_SIZE
/2,
362 ye
= yb
- PIN_LEN
; /* should be always 0 */
363 xs
= xe
= xb
+ pinlist
[i
].num
* PIN_SPACE
;
368 pinalign
= EDATEXT_LB
;
372 npinalign
= EDATEXT_RB
;
376 tpinalign
= EDATEXT_RT
;
377 if ((pinlist
[i
].flags
& PIN_CLKFLAG
) != 0)
379 /* there is "CLK" modifier */
382 fprintf(fsym
,"L %d %d %d %d %d 0 0 0 -1 -1\n",xs
-CLK_SIZE
,ys
,xs
,ys
+CLK_SIZE
,
384 fprintf(fsym
,"L %d %d %d %d %d 0 0 0 -1 -1\n",xs
,ys
+CLK_SIZE
,xs
+CLK_SIZE
,ys
,
387 if ((pinlist
[i
].flags
& PIN_DOTFLAG
) != 0)
389 /* there is "DOT" modifier */
392 fprintf(fsym
,"V %d %d %d %d 0 0 0 -1 -1 0 -1 -1 -1 -1 -1\n",xs
,ys
+DOT_SIZE
/2,DOT_SIZE
/2,
398 fprintf(fsym
,"P %d %d %d %d %d\n",xs
,ys
,xe
,ye
,EDACOLOR_PIN
);
401 /* pin sequence and number */
402 if (partspp
!= 0) /* handling for parts per package = 0 */
404 fprintf(fsym
,"T %d %d %d %d 1 1 %d %d\n",pinx
,piny
,EDACOLOR_ATTRIB
,
405 EDASIZE_PIN
,txtangle
,pinalign
);
409 /* if no pin number in the original symbol, make pin number hidden */
410 fprintf(fsym
,"T %d %d %d %d 0 1 %d %d\n",pinx
,piny
,EDACOLOR_ATTRIB
,
411 EDASIZE_PIN
,txtangle
,pinalign
);
414 fprintf(fsym
,"pin%d=%d\n",i
+1,pinlist
[i
].pin
);
417 fprintf(fsym
,"pinnumber=%d\n",pinlist
[i
].pin
);
418 fprintf(fsym
,"T %d %d %d %d 0 1 %d %d\n",pinx
,piny
,EDACOLOR_ATTRIB
,
419 EDASIZE_PIN
,txtangle
,pinalign
);
420 fprintf(fsym
,"pinseq=%d\n",i
+1);
423 /* hides pin name if symbol is VECTOR drawed and '-n' switch given */
424 if ((vector_count
!= 0) && (pin_name_hidden
))
426 fprintf(fsym
,"T %d %d %d %d 0 1 %d %d\n",npinx
,npiny
,EDACOLOR_LABEL
,
427 EDASIZE_LABEL
,txtangle
,npinalign
);
431 fprintf(fsym
,"T %d %d %d %d 1 1 %d %d\n",npinx
,npiny
,EDACOLOR_LABEL
,
432 EDASIZE_LABEL
,txtangle
,npinalign
);
435 fprintf(fsym
,"label=%s\n",pinlist
[i
].name
);
437 fprintf(fsym
,"pinlabel=%s\n",pinlist
[i
].name
);
439 fprintf(fsym
,"T %d %d %d %d 0 1 %d %d\n",tpinx
,tpiny
,EDACOLOR_ATTRIB
,
440 EDASIZE_LABEL
,txtangle
,tpinalign
);
442 fprintf(fsym
,"type=%s\n",edapintype
[pinlist
[i
].type
]);
444 fprintf(fsym
,"pintype=%s\n",edapintype
[pinlist
[i
].type
]);