4 # awk script to convert viewlogic symbol files to geda files
7 # Copyright (C) 1998 Mike Jarabek
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 reading_net =
0; # used to keep track of when we are reading a net
30 segment_count =
1; # the number of net segments read for a net
37 # just fetch the values and store
46 # unattached attribute
49 # if we are inside of a pin definition, terminate
52 # for the moment just represent as text
54 # viewlogic unnatached attributes have this format:
55 # U #X #Y #SIZE #ROTATION #origin #Visibility ATTR_TEXT
63 # if there are more fields on the line, they must be text
64 # this works, but some spacing may be lost
66 for(i =
9; i
<=
NF; i
++) {
71 # evaluate visibility for attributes
73 if( viewvis ==
0 ) { # not at all visibile
76 } else if (viewvis ==
1) { # attribute and name visible
79 } else if (viewvis ==
2) { # only name visible
82 } else if (viewvis ==
3) { # only value visible
88 text_object
( x
, y
, color
, size
, visibility
, show_name_value
, angle
, text
, \
96 # attached attributes have the following format:
97 # A #X #Y #SIZE #ROTATION #ORIGIN #VISIBILITY ATTR_TEXT
99 # extract interesting bits:
107 # if there are more fields on the line, they must be text
108 # this works, but some spacing may be lost
110 for(i =
9; i
<=
NF; i
++) {
116 # evaluate visibility for attributes
118 if( viewvis ==
0 ) { # not at all visibile
121 } else if (viewvis ==
1) { # attribute and name visible
124 } else if (viewvis ==
2) { # only name visible
127 } else if (viewvis ==
3) { # only value visible
132 # output the attachment magic if needed.
134 text_object
( x
, y
, color
, size
, visibility
, show_name_value
, angle
, text
, \
142 # if we are inside of a pin definition, terminate
145 # viewlogic text have the following format:
146 # T #X #Y #SIZE #ROTATION #ORIGIN TEXT
156 # if there are more fields on the line, they must be text
157 # this works, but some spacing may be lost
159 for(i =
8; i
<=
NF; i
++) {
165 text_object
(x
, y
, color
, size
, visibility
, show_name_value
, angle
, text
, \
173 # if we are inside of a pin definition, terminate
177 # the viewlogic line primitive is composed of
178 # l #PAIRS #X1 #Y1 #X2 #Y2 ... - Line
183 # represent this as a series of simple geda lines
184 for (i=
0; i
< (pairs
-1); i
++) {
185 x1 = $
((i
*2)+3) * 10;
186 y1 = $
((i
*2)+4) * 10;
187 x2 = $
((i
*2)+5) * 10;
188 y2 = $
((i
*2)+6) * 10;
190 line_object
(x1
,y1
,x2
,y2
,color
);
197 # if we are inside of a pin definition, terminate
200 # viewlogic pin primitives have the following format:
201 # P #PININSTANCE #X1 #Y1 #X2 #Y2 # #PINDIRECTION #PINSENSE
215 # if this pin has to be of negative polarity, add a bitty bubble
216 # and adjust the size of the pin
223 #print "pindir:" pindir
224 # get the bubble on the right end
226 # one of the coordinates will match up with the bounding box
227 # then just choose the other end for the bubble
229 if(x1 == minx
) { # left hand side of pin touches bounding box
234 } else if (x1 == maxx
) { # left end touches right side
239 } else if (x2 == minx
) { # right end touches left side
244 } else if (x2 == maxx
) { # right end touches right side
249 } else if (y1 == miny
) { # left end touches bottom
254 } else if (y1 == maxy
) { # left end touches top
259 } else if (y2 == miny
) { # right end touches bottom
264 } else if (y2 == maxy
) { # right end touches top
269 print "Pinsense error!";
275 circle_object
(bx
,by
,radius
,bcolor
);
278 pin_object
(x1
,y1
,x2
,y2
,color
);
281 add_attributes =
1; # add attributes
282 attach_pending =
1; # signal that an attachment could be coming
283 pin_attributes =
1; # and that they are pin attributes
284 pin_count
++; # bump the number of pins
290 # if we are inside of a pin definition, terminate
293 # a viewlogic box has the following format:
295 # geda view of a box has the corner, width and height
306 box_object
(x1
,y1
,width
,height
,color
);
313 # if we are inside of a pin definition, terminate
316 # a circle has the following format:
324 circle_object
(x
,y
,radius
,color
);
330 # if we are inside of a pin definition, terminate
333 # arcs have the following format:
334 # a #X1 #Y1 #X2 #Y2 #X3 #Y3
335 # we need to transform this into the geda convention of
336 # center, radius, start angle, stop angle.
351 yop =
(x2p
* ( x3p^
2 + y3p^
2 ) - x3p
* ( x2p^
2 + y2p^
2 )) / \
352 (2 * (x2p
* y3p
- y2p
* x3p
));
354 xop =
(x2p^
2 - 2*y2p
*yop
) / (2 * x2p
);
360 radius = int
(sqrt
(xop^
2 + yop^
2));
362 # calculate start and end angles
363 to_rad =
180.0/atan2
(0,-1);
364 start_angle = int
(atan2
(y1
-yo
, x1
-xo
) * to_rad
);
365 end_angle = int
(atan2
(y3
-yo
, x3
-xo
) * to_rad
);
367 if(start_angle
> end_angle
) {
369 sweep_angle = start_angle
- end_angle
;
371 gstart = start_angle
;
372 sweep_angle = end_angle
- start_angle
;
376 #end_angle = int(atan2(y1-yo, x1-xo) * to_rad) % 360;
377 #start_angle = int(atan2(y3-yo, x3-xo) * to_rad) % 360;
382 arc_object
(int
(xo
),int
(yo
), radius
, gstart
, sweep_angle
, color
);
389 # labels have the following format:
390 # L #X #Y #SIZE #ROTATION #ORIGIN #GLOBAL #VISIBILITY #OVERBAR TEXT
392 # reproduce as simple text
401 # Note from Ales, some ViewDraw symbols of mine had text labels which
402 # had an angle of 3 which is wrong, so I just changed the next line to:
407 # if there are more fields on the line, they must be text
408 # this works, but some spacing may be lost
410 for(i =
11; i
<=
NF; i
++) {
417 # if we are inside a pin definition, mangle the pin name
418 if(pin_attributes ==
1) {
419 text =
"pin" pin_count
"=" text
;
420 show_name_value =
1; # and show just the name
421 } else if(net_attributes ==
1) {
422 text =
"net=" text
; # a label on a net is the net name
424 } else if(complex_attributes ==
1) {
425 text =
"refdes=" text
; # a label on a complex is its designator
430 text_object
(x
, y
, color
, size
, visibility
, show_name_value
, angle
, text
, \
442 delete net_nodes_x
; # zap the array
448 # in geda nets are composed of a number of segments, gschem connects
449 # them together on the screen, since viewlogic stores a net as a series
450 # of nodes we need to tabulate them and only output segments when we
451 # get connectivity information
453 # net segments have the following format:
454 # J #X #Y #SEGNUM - Net segment
456 # get the current info
460 net_nodes_x
[segment_count
] = x
;
461 net_nodes_y
[segment_count
] = y
;
470 # net segment connectivity records have the following format:
471 # S #N1 #N2 - Net connectivity, Node N1 is connected to N2
477 # output a geda net segment
478 net_segment
(net_nodes_x
[n1
], net_nodes_y
[n1
], \
479 net_nodes_x
[n2
], net_nodes_y
[n2
], color
);
481 # there could be attributes to follow
482 add_attributes =
1; # add attributes
483 attach_pending =
1; # signal that an attachment could be coming
484 net_attributes =
1; # and that they are net attributes
492 # bus segment connectivity records have the following format:
493 # B #N1 #N2 - Bus connectivity, Node N1 is connected to N2
499 # output a geda net segment -- since geda does not know about busses -- yet
500 net_segment
(net_nodes_x
[n1
], net_nodes_y
[n1
], \
501 net_nodes_x
[n2
], net_nodes_y
[n2
], color
);
503 # there could be attributes to follow
504 add_attributes =
1; # add attributes
505 attach_pending =
1; # signal that an attachment could be coming
506 net_attributes =
1; # and that they are net attributes
514 # a component instance has the following format
515 # I #instance LIB:NAME #PAGE #X #Y #ROTATION #MAGNIFICATION
521 mirror =
0; # need to add logic to decode rotation and mirror
525 split(fullname
, names
, ":");
530 # produce proper file name:
531 name =
tolower(names
[2]) "." extension
".sym";
533 complex_object
(x
, y
, selectable
, angle
, mirror
, name
);
535 # there could be attributes to follow
536 add_attributes =
1; # add attributes
537 attach_pending =
1; # signal that an attachment could be coming
538 complex_attributes =
1; # and that they are complex attributes
541 # just junk any records we do not deal with
545 function text_object
( x
, y
, color
, size
, visibility
, show_name_value
, \
546 angle
, text
, origin
) {
548 # fudge the text size, in viewdraw it is actually the height
549 # in geda it is the point size
551 text_size = int
(size
* 0.72);
553 # emulate the viewdraw text origin by shifting the text around
555 # if the origin is one of the ones that are along the center line,
558 if ( (origin ==
2) || (origin ==
5) || (origin ==
8) ) {
562 if( (origin ==
1) || (origin ==
4) || (origin ==
7) ) {
566 # approximate the length of the text
567 if(show_name_value ==
0) {
568 text_to_measure = text
;
569 } else if(show_name_value ==
1) {
571 text_to_measure = a
[2]; # measure just the value part
572 } else if(show_name_value ==
2) {
574 text_to_measure = a
[1]; # measure just the textual part
577 textlen =
length(text_to_measure
) * size
* 10;
578 # if the origin is one of the middle ones
579 # fix the x coordinate
580 if( (origin ==
4) || (origin ==
5) || (origin ==
6) ) {
584 if( (origin ==
7) || (origin ==
8) || (origin ==
9) ) {
589 print "T", x
, y
, color
, text_size
, visibility
, show_name_value
, angle
;
593 function line_object
( x1
,y1
,x2
,y2
,color
) {
595 print "L",x1
,y1
,x2
,y2
,color
;
598 function circle_object
( bx
,by
,radius
,bcolor
) {
600 print "V",bx
,by
,radius
,bcolor
;
603 function pin_object
( x1
,y1
,x2
,y2
,color
) {
605 print "P",x1
,y1
,x2
,y2
,color
;
608 function box_object
( x1
,y1
,width
,height
,color
) {
610 print "B",x1
,y1
,width
,height
,color
;
613 function arc_object
( x1
, y1
, radius
, start_angle
, sweep_angle
, color
) {
615 print "A",x1
, y1
, radius
, start_angle
, sweep_angle
, color
;
619 function net_segment
( x1
, y1
, x2
, y2
, color
) {
621 print "N", x1
, y1
, x2
, y2
, color
;
625 function complex_object
(x
, y
, selectable
, angle
, mirror
, name
) {
627 print "C", x
, y
, selectable
, angle
, mirror
, name
;
630 function begin_attach
() {
632 if(attach_pending ==
1) { # begin an attachment if one is pending
638 function end_attach
() {
643 function reset_attributes
() {
645 # if we are inside of some kind of attribute attachment
646 # terminate it, but only if we output the begin_attach.
647 if((add_attributes ==
1) && (attach_pending ==
0)) {
651 attach_pending =
0; # keep track of whether the last object
652 # read may have attachments pending.
654 add_attributes =
0; # keep track of whether we are adding attributes
655 # to some previous object
656 pin_attributes =
0; # when true, we are adding attributes to a pin
657 net_attributes =
0; # when true, we are adding atrributes to a net
658 complex_attributes =
0; # when true, we are addint attibutes to a complex
659 pin_count =
0; # to keep track of the number of pins