Xorn
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
pp_hierarchy.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_hierarchy
21 ## Post-processing: Hierarchy traversal.
22 
23 from gettext import gettext as _
24 
25 ## Connect subsheet I/O ports to the instantiating component's pins.
26 #
27 # Disconnect all connections from and to composite components as
28 # they have been replaced with the actual subschematics.
29 #
30 # remove all composite components and ports
31 
32 def postproc_instances(netlist):
33  remove_components = set()
34 
35  for component in netlist.components:
36  if not component.blueprint.composite_sources:
37  continue
38 
39  for cpin in component.cpins:
40  label = cpin.blueprint.get_attribute('pinlabel', None)
41  if label is None:
42  cpin.error(_("pin on composite component is missing a label"))
43  continue
44 
45  dest_net = cpin.local_net.net
46 
47  # search for the matching port
48  ports = [potential_port for subsheet in component.subsheets
49  for potential_port in subsheet.components
50  if potential_port.blueprint.refdes == label]
51 
52  if not ports:
53  cpin.warn(_("missing I/O symbol with refdes `%s' "
54  "inside schematic") % label)
55  elif len(ports) > 1:
56  cpin.warn(_("multiple I/O symbols with refdes `%s' "
57  "inside schematic") % label)
58 
59  for port in ports:
60  if not port.cpins:
61  port.error(_("I/O symbol doesn't have pins"))
62  continue
63  if len(port.cpins) > 1:
64  port.error(_("multiple pins on I/O symbol"))
65  continue
66  if port.blueprint.is_graphical:
67  port.error(_("I/O symbol can't be graphical"))
68 
69  src_net = port.cpins[0].local_net.net
70 
71  # merge nets
72  if src_net != dest_net:
73  src_net.merge_into(dest_net)
74  dest_net.component_pins += src_net.component_pins
75  del src_net.component_pins[:]
76 
77  # remove port component
78  remove_components.add(port)
79  port.sheet.components.remove(port)
80  del port.sheet.components_by_blueprint[port.blueprint]
81 
82  port.cpins[0].local_net.cpins.remove(port.cpins[0])
83  dest_net.component_pins.remove(port.cpins[0])
84 
85  # After the pin has been connected, remove it.
86  cpin.local_net.cpins.remove(cpin)
87  dest_net.component_pins.remove(cpin)
88 
89  # After all pins have been connected, remove the component.
90  remove_components.add(component)
91  component.sheet.components.remove(component)
92  del component.sheet.components_by_blueprint[component.blueprint]
93 
94  netlist.components = [component for component in netlist.components
95  if component not in remove_components]
def postproc_instances
Connect subsheet I/O ports to the instantiating component's pins.
Definition: pp_hierarchy.py:32