Merge fixes from branch 'xorn'
[geda-gaf.git] / xorn / src / backend / gnet_redac.py
blobfe2974c2d0ebb00b464d8666ef4d20c00058ddd6
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 # RACAL-REDAC / Cadstar netlist format by Wojciech Kazubski 2003
22 class NewlineReplacer:
23 def __init__(self, f):
24 self.f = f
26 def write(self, s):
27 self.f.write(str(s).replace('\n', '\r\n'))
29 def run(f, netlist):
30 f = NewlineReplacer(f)
31 f.write('.PCB\n')
32 f.write('.REM CREATED BY gEDA GNETLIST\n')
33 f.write('.CON\n')
34 f.write('.COD 2\n')
35 f.write('\n')
36 for net in reversed(netlist.nets):
37 f.write('.REM %s\n' % net.name)
38 # Display the individual net connections
39 k = 7
40 for i, pin in enumerate(reversed(net.connections)):
41 item = '%s %s' % (pin.package.refdes, pin.number)
42 f.write(item)
43 if i == len(net.connections) - 1:
44 continue
45 if k > 0:
46 f.write(' ')
47 k -= 1
48 else:
49 f.write('\n' + item + ' ')
50 k += 6
51 f.write('\n')
52 f.write('.EOD\n')