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 # gnetlist back end for dumping all attributes and netlist in xml format
21 # Copyright (C) 2014 Tibor 'Igor2' Palinkas
23 from dump_common
import *
26 def write_begin(self
, f
):
27 f
.write('<?xml version="1.0" encoding="UTF-8"?>\n')
29 f
.write('\t<elements>\n')
31 # Formatting: write (element) pins
33 def write_pin_attribs_pre(self
, f
, component
):
34 f
.write('\t\t\t<pins>\n')
36 def write_pin_attrib_pre(self
, f
, component
, cpin
):
37 f
.write('\t\t\t\t<pin name="%s-%s">\n' % (
38 get_refdes(component
), cpin
.blueprint
.number
))
40 def write_pin_attrib(self
, f
, component
, cpin
, pinattrib
):
41 f
.write('\t\t\t\t\t<attrib name="%s" value="%s" />\n' % (
42 pinattrib
, cpin
.blueprint
.get_attribute(pinattrib
, 'unknown')))
44 def write_pin_attrib_post(self
, f
, component
, cpin
):
45 f
.write('\t\t\t\t</pin>\n')
47 def write_pin_attribs_post(self
, f
, component
):
48 f
.write('\t\t\t</pins>\n')
50 def write_pin_nets_pre(self
, f
, component
):
51 f
.write('\t\t\t<pin-conns>\n')
53 def write_pin_net_pre(self
, f
, component
, cpin
):
56 def write_pin_net(self
, f
, component
, cpin
):
57 f
.write('\t\t\t\t<pin-conn name="%s-%s" value="%s" />\n' % (
58 get_refdes(component
), cpin
.blueprint
.number
,
59 cpin
.local_net
.net
.name
))
61 def write_pin_net_post(self
, f
, component
, cpin
):
64 def write_pin_nets_post(self
, f
, component
):
65 f
.write('\t\t\t</pin-conns>\n')
67 def write_pinlist(self
, f
, component
, cpin
):
70 def write_pinlist_pre(self
, f
, component
):
73 def write_pinlist_post(self
, f
, component
):
76 # Formatting: write elements
78 def write_element_pre(self
, f
, component
):
79 f
.write('\t\t<element name="%s">\n' % get_refdes(component
))
81 def write_element_attrib_pre(self
, f
, component
):
82 f
.write('\t\t\t<attributes>\n')
84 def write_element_attrib(self
, f
, component
, attribname
):
85 f
.write('\t\t\t\t<attrib name="%s" value="%s" />\n' % (
86 attribname
, component
.blueprint
.get_attribute(attribname
)))
88 def write_element_attrib_post(self
, f
, component
):
89 f
.write('\t\t\t</attributes>\n')
91 def write_element_post(self
, f
, component
):
92 f
.write('\t\t</element>\n')
94 def write_middle(self
, f
):
95 f
.write('\t</elements>\n')
98 # Formatting: print netlists
100 def write_netlist_pin(self
, f
, cpin
):
101 f
.write('\t\t\t<pin name="%s-%s" />\n' % (
102 get_refdes(cpin
.component
), cpin
.blueprint
.number
))
104 def write_netlist_pre(self
, f
, net
):
105 f
.write('\t\t<net name="%s">\n' % net
.name
)
107 def write_netlist_post(self
, f
, net
):
108 f
.write('\t\t</net>\n')
110 def write_end(self
, f
):
111 f
.write('\t</nets>\n')
112 f
.write('</gschem>\n')
115 dump(f
, netlist
, Callback())