1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663
|
#!/usr/bin/awk -f
# $Id: convert_sym.awk,v 1.1 2002/07/27 23:22:33 ahvezda Exp $
# $Author: ahvezda $
# awk script to convert viewlogic symbol files to geda files
#
#
# Copyright (C) 1998 Mike Jarabek
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
BEGIN {
print "v 19981025";
reset_attributes();
reading_net = 0; # used to keep track of when we are reading a net
segment_count = 1; # the number of net segments read for a net
}
# bounding box
$1 == "D" {
# just fetch the values and store
minx = $2 * 10;
miny = $3 * 10;
maxx = $4 * 10;
maxy = $5 * 10;
}
# unattached attribute
$1 == "U" {
# if we are inside of a pin definition, terminate
reset_attributes();
# for the moment just represent as text
# viewlogic unnatached attributes have this format:
# U #X #Y #SIZE #ROTATION #origin #Visibility ATTR_TEXT
x = ($2) * 10;
y = ($3) * 10;
color = 1;
size = $4;
angle = $5;
text = $8;
# if there are more fields on the line, they must be text
# this works, but some spacing may be lost
if (NF > 8) {
for(i = 9; i <= NF; i++) {
text = text " " $i;
}
} origin = $6;
# evaluate visibility for attributes
viewvis = $7;
if( viewvis == 0 ) { # not at all visibile
visibility = 0;
show_name_value = 0;
} else if (viewvis == 1) { # attribute and name visible
visibility = 1;
show_name_value = 0;
} else if (viewvis == 2) { # only name visible
visibility = 2;
show_name_value = 1;
} else if (viewvis == 3) { # only value visible
visibility = 1;
show_name_value = 1;
}
text_object( x, y, color, size, visibility, show_name_value, angle, text, \
origin);
}
# attached attribute
$1 == "A" {
# attached attributes have the following format:
# A #X #Y #SIZE #ROTATION #ORIGIN #VISIBILITY ATTR_TEXT
# extract interesting bits:
x = ($2) * 10;
y = ($3) * 10;
color = 1;
size = $4;
angle = $5;
text = $8;
# if there are more fields on the line, they must be text
# this works, but some spacing may be lost
if (NF > 8) {
for(i = 9; i <= NF; i++) {
text = text " " $i;
}
}
origin = $6;
# evaluate visibility for attributes
viewvis = $7;
if( viewvis == 0 ) { # not at all visibile
visibility = 0;
show_name_value = 0;
} else if (viewvis == 1) { # attribute and name visible
visibility = 1;
show_name_value = 0;
} else if (viewvis == 2) { # only name visible
visibility = 2;
show_name_value = 1;
} else if (viewvis == 3) { # only value visible
visibility = 1;
show_name_value = 1;
}
# output the attachment magic if needed.
begin_attach();
text_object( x, y, color, size, visibility, show_name_value, angle, text, \
origin);
}
# text primitive
$1 == "T" {
# if we are inside of a pin definition, terminate
reset_attributes();
# viewlogic text have the following format:
# T #X #Y #SIZE #ROTATION #ORIGIN TEXT
x = $2 * 10;
y = $3 * 10;
color = 3;
size = $4;
visibility = 1;
show_name_value = 0;
angle = $5;
text = $7;
# if there are more fields on the line, they must be text
# this works, but some spacing may be lost
if (NF > 7) {
for(i = 8; i <= NF; i++) {
text = text " " $i;
}
}
origin = $6
text_object(x, y, color, size, visibility, show_name_value, angle, text, \
origin);
}
# line primitive
$1 == "l" {
# if we are inside of a pin definition, terminate
reset_attributes();
# the viewlogic line primitive is composed of
# l #PAIRS #X1 #Y1 #X2 #Y2 ... - Line
pairs = $2;
color = 3;
# represent this as a series of simple geda lines
for (i=0; i < (pairs-1); i++) {
x1 = $((i*2)+3) * 10;
y1 = $((i*2)+4) * 10;
x2 = $((i*2)+5) * 10;
y2 = $((i*2)+6) * 10;
line_object(x1,y1,x2,y2,color);
}
}
# pin primitive
$1 == "P" {
# if we are inside of a pin definition, terminate
reset_attributes();
# viewlogic pin primitives have the following format:
# P #PININSTANCE #X1 #Y1 #X2 #Y2 # #PINDIRECTION #PINSENSE
pinsense = $9;
pindir = $8;
x1 = $3 * 10;
y1 = $4 * 10;
x2 = $5 * 10;
y2 = $6 * 10;
color = 1;
# if this pin has to be of negative polarity, add a bitty bubble
# and adjust the size of the pin
radius = 25;
radius2 = 2*radius;
bcolor = 6;
if(pinsense == 1) {
#print "pindir:" pindir
# get the bubble on the right end
# one of the coordinates will match up with the bounding box
# then just choose the other end for the bubble
if(x1 == minx) { # left hand side of pin touches bounding box
bx = x2-radius;
by = y2;
x2 -= radius2;
} else if (x1 == maxx) { # left end touches right side
bx = x2+radius;
by = y2;
x2 += radius2;
} else if (x2 == minx) { # right end touches left side
bx = x1-radius;
by = y1;
x1 -= radius2;
} else if (x2 == maxx) { # right end touches right side
bx = x1+radius;
by = y1;
x1 += radius2;
} else if (y1 == miny) { # left end touches bottom
bx = x2;
by = y2-radius;
y2 -= radius2;
} else if (y1 == maxy) { # left end touches top
bx = x2;
by = y2+radius;
y2 += radius2;
} else if (y2 == miny) { # right end touches bottom
bx = x1;
by = y1-radius;
y1 -= radius2;
} else if (y2 == maxy) { # right end touches top
bx = x1;
by = y1+radius;
y1 += radius2;
} else {
print "Pinsense error!";
exit;
}
circle_object(bx,by,radius,bcolor);
}
pin_object(x1,y1,x2,y2,color);
add_attributes = 1; # add attributes
attach_pending = 1; # signal that an attachment could be coming
pin_attributes = 1; # and that they are pin attributes
pin_count++; # bump the number of pins
}
# box primitive
$1 == "b" {
# if we are inside of a pin definition, terminate
reset_attributes();
# a viewlogic box has the following format:
# b #X1 #Y1 #X2 #Y2
# geda view of a box has the corner, width and height
x1 = $2 * 10;
y1 = $3 * 10;
x2 = $4 * 10;
y2 = $5 * 10;
width = x2-x1;
height = y2-y1;
color = 3;
box_object(x1,y1,width,height,color);
}
# circle primitive
$1 == "c" {
# if we are inside of a pin definition, terminate
reset_attributes();
# a circle has the following format:
# c #x #y #radius
x = $2 * 10;
y = $3 * 10;
radius = $4 * 10;
color = 3;
circle_object(x,y,radius,color);
}
# arc primitive
$1 == "a" {
# if we are inside of a pin definition, terminate
reset_attributes()
# arcs have the following format:
# a #X1 #Y1 #X2 #Y2 #X3 #Y3
# we need to transform this into the geda convention of
# center, radius, start angle, stop angle.
x1 = $2*10.0;
y1 = $3*10.0;
x2 = $4*10.0;
y2 = $5*10.0;
x3 = $6*10.0;
y3 = $7*10.0;
x2p = x2 - x1;
y2p = y2 - y1;
x3p = x3 - x1;
y3p = y3 - y1;
yop = (x2p * ( x3p^2 + y3p^2 ) - x3p * ( x2p^2 + y2p^2 )) / \
(2 * (x2p * y3p - y2p * x3p));
xop = (x2p^2 - 2*y2p*yop) / (2 * x2p);
xo = xop + x1;
yo = yop + y1;
radius = int(sqrt(xop^2 + yop^2));
# calculate start and end angles
to_rad = 180.0/atan2(0,-1);
start_angle = int(atan2(y1-yo, x1-xo) * to_rad);
end_angle = int(atan2(y3-yo, x3-xo) * to_rad);
if(start_angle > end_angle) {
gstart = end_angle;
sweep_angle = start_angle - end_angle;
} else {
gstart = start_angle;
sweep_angle = end_angle - start_angle;
}
#end_angle =
#end_angle = int(atan2(y1-yo, x1-xo) * to_rad) % 360;
#start_angle = int(atan2(y3-yo, x3-xo) * to_rad) % 360;
color = 1;
arc_object(int(xo),int(yo), radius, gstart, sweep_angle, color);
}
# label primitive
$1 == "L" {
# labels have the following format:
# L #X #Y #SIZE #ROTATION #ORIGIN #GLOBAL #VISIBILITY #OVERBAR TEXT
# reproduce as simple text
x = $2 * 10;
y = $3 * 10;
color = 5;
size = $4;
visibility = 1;
show_name_value = 0;
# Note from Ales, some ViewDraw symbols of mine had text labels which
# had an angle of 3 which is wrong, so I just changed the next line to:
# angle = 0
angle = $5;
text = $10;
# if there are more fields on the line, they must be text
# this works, but some spacing may be lost
if (NF > 10) {
for(i = 11; i <= NF; i++) {
text = text " " $i;
}
}
origin = $6;
# if we are inside a pin definition, mangle the pin name
if(pin_attributes == 1) {
text = "pin" pin_count "=" text;
show_name_value = 1; # and show just the name
} else if(net_attributes == 1) {
text = "net=" text; # a label on a net is the net name
show_name_value = 1;
} else if(complex_attributes == 1) {
text = "refdes=" text; # a label on a complex is its designator
show_name_value = 1;
}
begin_attach();
text_object(x, y, color, size, visibility, show_name_value, angle, text, \
origin);
}
# nets
$1 == "N" {
reset_attributes();
reading_net = 1;
segment_count = 1;
delete net_nodes_x; # zap the array
delete net_nodes_y;
}
$1 == "J" {
# in geda nets are composed of a number of segments, gschem connects
# them together on the screen, since viewlogic stores a net as a series
# of nodes we need to tabulate them and only output segments when we
# get connectivity information
# net segments have the following format:
# J #X #Y #SEGNUM - Net segment
# get the current info
x = $2*10;
y = $3*10;
net_nodes_x[segment_count] = x;
net_nodes_y[segment_count] = y;
segment_count++;
}
$1 == "S" {
reset_attributes();
# net segment connectivity records have the following format:
# S #N1 #N2 - Net connectivity, Node N1 is connected to N2
n1 = int($2);
n2 = int($3);
color = 4;
# output a geda net segment
net_segment(net_nodes_x[n1], net_nodes_y[n1], \
net_nodes_x[n2], net_nodes_y[n2], color);
# there could be attributes to follow
add_attributes = 1; # add attributes
attach_pending = 1; # signal that an attachment could be coming
net_attributes = 1; # and that they are net attributes
}
$1 == "B" {
reset_attributes();
# bus segment connectivity records have the following format:
# B #N1 #N2 - Bus connectivity, Node N1 is connected to N2
n1 = int($2);
n2 = int($3);
color = 4;
# output a geda net segment -- since geda does not know about busses -- yet
net_segment(net_nodes_x[n1], net_nodes_y[n1], \
net_nodes_x[n2], net_nodes_y[n2], color);
# there could be attributes to follow
add_attributes = 1; # add attributes
attach_pending = 1; # signal that an attachment could be coming
net_attributes = 1; # and that they are net attributes
}
# component instance
$1 == "I" {
reset_attributes();
# a component instance has the following format
# I #instance LIB:NAME #PAGE #X #Y #ROTATION #MAGNIFICATION
x = $5*10;
y = $6*10;
selectable = 1;
angle = 0;
mirror = 0; # need to add logic to decode rotation and mirror
# get name
fullname = $3;
split(fullname, names, ":");
# get extension
extension = $4;
# produce proper file name:
name = tolower(names[2]) "." extension ".sym";
complex_object(x, y, selectable, angle, mirror, name);
# there could be attributes to follow
add_attributes = 1; # add attributes
attach_pending = 1; # signal that an attachment could be coming
complex_attributes = 1; # and that they are complex attributes
}
# just junk any records we do not deal with
{}
# utility functions
function text_object( x, y, color, size, visibility, show_name_value, \
angle, text, origin) {
# fudge the text size, in viewdraw it is actually the height
# in geda it is the point size
text_size = int(size * 0.72);
# emulate the viewdraw text origin by shifting the text around
# if the origin is one of the ones that are along the center line,
# adjust y
if ( (origin == 2) || (origin == 5) || (origin == 8) ) {
y -= (size*10) / 2;
}
if( (origin == 1) || (origin == 4) || (origin == 7) ) {
y -= size * 10;
}
# approximate the length of the text
if(show_name_value == 0) {
text_to_measure = text;
} else if(show_name_value == 1) {
split(text,a,"=");
text_to_measure = a[2]; # measure just the value part
} else if(show_name_value == 2) {
split(text,a,"=");
text_to_measure = a[1]; # measure just the textual part
}
textlen = length(text_to_measure) * size * 10;
# if the origin is one of the middle ones
# fix the x coordinate
if( (origin == 4) || (origin == 5) || (origin == 6) ) {
x -= textlen / 2;
}
if( (origin == 7) || (origin == 8) || (origin == 9) ) {
x -= textlen;
}
print "T", x, y, color, text_size, visibility, show_name_value, angle;
print text;
}
function line_object( x1,y1,x2,y2,color ) {
print "L",x1,y1,x2,y2,color;
}
function circle_object( bx,by,radius,bcolor ) {
print "V",bx,by,radius,bcolor;
}
function pin_object( x1,y1,x2,y2,color ) {
print "P",x1,y1,x2,y2,color;
}
function box_object( x1,y1,width,height,color ) {
print "B",x1,y1,width,height,color;
}
function arc_object( x1, y1, radius, start_angle, sweep_angle, color) {
print "A",x1, y1, radius, start_angle, sweep_angle, color;
}
function net_segment( x1, y1, x2, y2, color ) {
print "N", x1, y1, x2, y2, color;
}
function complex_object(x, y, selectable, angle, mirror, name) {
print "C", x, y, selectable, angle, mirror, name;
}
function begin_attach() {
if(attach_pending == 1) { # begin an attachment if one is pending
print "{";
attach_pending = 0;
}
}
function end_attach() {
print "}";
}
function reset_attributes() {
# if we are inside of some kind of attribute attachment
# terminate it, but only if we output the begin_attach.
if((add_attributes == 1) && (attach_pending == 0)) {
end_attach();
}
attach_pending = 0; # keep track of whether the last object
# read may have attachments pending.
add_attributes = 0; # keep track of whether we are adding attributes
# to some previous object
pin_attributes = 0; # when true, we are adding attributes to a pin
net_attributes = 0; # when true, we are adding atrributes to a net
complex_attributes = 0; # when true, we are addint attibutes to a complex
pin_count = 0; # to keep track of the number of pins
}
|