1 # gaf.netlist - gEDA Netlist Extraction and Generation
2 # Copyright (C) 1998-2010 Ales Hvezda
3 # Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details)
4 # Copyright (C) 2013-2020 Roland Lutz
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software Foundation,
18 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 # Allegro netlist format
24 def open_and_check(device
):
33 f
= open('devfiles/%s.txt' % device
.lower(), 'w')
35 if e
.errno
== errno
.ENOENT
and mkdir_error
is not None:
36 sys
.stderr
.write("%s\n" % mkdir_error
)
38 sys
.stderr
.write("%s\n" % e
)
39 sys
.stderr
.write("The device files are expected to be "
40 "in the 'devfiles' directory.\n")
45 def output_netlist(f
, package
):
46 f
.write('(Device File generated by gEDA Allegro Netlister)\n')
47 f
.write('PACKAGE %s\n' % package
.get_attribute('footprint', 'unknown'))
48 f
.write('CLASS %s\n' % package
.get_attribute('class', 'unknown'))
49 f
.write('PINCOUNT %s\n' % package
.get_attribute('pins', 'unknown'))
50 altfoot
= package
.get_attribute('alt_foot', None)
51 if altfoot
is not None:
52 f
.write('PACKAGEPROP ALT_SYMBOLS\n')
53 f
.write("'(%s)'\n" % altfoot
)
56 def get_component_text(package
, default
):
58 return package
.get_attribute('value')
61 return package
.get_attribute('label')
63 return package
.get_attribute('device', default
)
66 f
.write('(Allegro netlister by M. Ettus)\n')
68 f
.write('$PACKAGES\n')
69 for package
in reversed(netlist
.packages
):
70 footprint
= package
.get_attribute('footprint', None)
71 if footprint
is not None:
73 f
.write('! %s! %s; %s\n' % (package
.get_attribute('device', 'unknown'),
74 get_component_text(package
, 'unknown'),
78 for net
in reversed(netlist
.nets
):
81 f
.write(',\n'.join(' %s.%s' % (pin
.package
.refdes
, pin
.number
)
82 for pin
in reversed(net
.connections
)) + '\n')
88 for package
in reversed(netlist
.packages
):
89 device
= package
.get_attribute('device', 'unknown')
94 output_netlist(f
, package
)
96 g
= open_and_check(device
)
98 output_netlist(g
, package
)