Xorn
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
pp_netattrib.py
Go to the documentation of this file.
1 # xorn.geda.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-2016 Roland Lutz
5 #
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.
10 #
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.
15 #
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.
19 
20 ## \namespace xorn.geda.netlist.pp_netattrib
21 ## Post-processing: Artificial pins.
22 
23 from gettext import gettext as _
24 import xorn.geda.attrib
26 
27 ## Characters used to separate the pin numbers in a \c "net=" attribute.
28 NET_ATTRIB_DELIMITERS = ',; '
29 
30 ## Split a string into non-empty parts separated by a set of delimiters.
31 
32 def strtok(s, delim):
33  start = 0
34  while start < len(s):
35  found = [i for i in (s.find(d, start) for d in delim) if i != -1]
36  if found:
37  end = min(found)
38  else:
39  end = len(s)
40  if end != start:
41  yield s[start:end]
42  start = end + 1
43 
44 def postproc_blueprints(netlist):
45  # Handle a "net=name:pin,pin..." attribute by creating appropriate
46  # Pin objects.
47 
48  for schematic in netlist.schematics:
49  for component in schematic.components:
50  # first look inside the component, then outside the component
51  pinnumbers = []
52  assignments = {}
53 
54  for is_inherited, func in [
55  (True, xorn.geda.attrib.search_inherited),
56  (False, xorn.geda.attrib.search_attached)]:
57  for value in func(component.ob, 'net'):
58  # A "net=" attribute has been found in the component.
59 
60  try:
61  pos = value.index(':')
62  except ValueError:
63  component.error(
64  _("invalid net= attribute: \"%s\"") % value)
65  continue
66 
67  # skip over first colon
68  for pinnumber in strtok(
69  value[pos + 1:], NET_ATTRIB_DELIMITERS):
70  try:
71  l = assignments[pinnumber]
72  except KeyError:
73  pinnumbers.append(pinnumber)
74  l = assignments[pinnumber] = []
75  l.append((value[:pos], is_inherited))
76 
77  for pinnumber in pinnumbers:
78  try:
79  pin = component.pins_by_number[pinnumber]
80  except KeyError:
81  net = xorn.geda.netlist.blueprint.Net(schematic, [])
82  pin = xorn.geda.netlist.blueprint.Pin(component, None)
83  pin.number = pinnumber
84  component.pins_by_number[pinnumber] = pin
85  pin.net = net
86  net.pins.append(pin)
87 
88  netnames = [netname for netname, is_inherited in
89  assignments[pinnumber]
90  if not is_inherited]
91  if not netnames:
92  netnames = [netname for netname, is_inherited in
93  assignments[pinnumber]
94  if is_inherited]
95 
96  if len(netnames) > 1:
97  pin.error(_("more than one netname assigned "
98  "via \"net=\" attribute: %s") %
99  _(" vs. ").join(netnames))
100 
101  pin.has_netattrib = True
102  pin.net.names_from_net_attribute += netnames
Attribute parsing and lookup.
Definition: attrib.py:1
Pin in a single schematic's netlist.
Definition: blueprint.py:265
Visually connected net piece in a single schematic's netlist.
Definition: blueprint.py:354
def strtok
Split a string into non-empty parts separated by a set of delimiters.
Definition: pp_netattrib.py:32
Netlists for individual schematic files.
Definition: blueprint.py:1