Xorn
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
instance.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.instance
21 ## Building one hierarchical netlist from instantiated sheet blueprints.
22 
23 import sys
24 
25 ## Instantiation of a schematic page.
26 #
27 # For every schematic instantiation (either via the command line, or
28 # via the \c source= attribute), a Sheet object is created, and its
29 # \a blueprint attribute is set to the instantiated
30 # xorn.geda.netlist.blueprint.Schematic object.
31 
32 class Sheet:
33  def __init__(self, netlist, blueprint, instantiating_component):
34  self.netlist = netlist
35  # schematic which is traversed
36  self.blueprint = blueprint
37 
38  self.instantiating_component = instantiating_component
39 
40  self.components = []
42  self.local_nets = []
44 
45  self.error = blueprint.error
46  self.warn = blueprint.warn
47 
48  netlist.sheets.append(self)
49  if instantiating_component is not None:
50  instantiating_component.subsheets.append(self)
51 
52  # Starting internal netlist creation
53 
54  for net_blueprint in self.blueprint.nets:
55  LocalNet(self, net_blueprint)
56 
57  for component_blueprint in self.blueprint.components:
58  Component(self, component_blueprint)
59 
60 ## Component.
61 #
62 # Represents a component in the netlist, either read from a toplevel
63 # schematic or instantiated via a subschematic symbol.
64 
65 class Component:
66  def __init__(self, sheet, blueprint):
67  self.sheet = sheet
68  self.blueprint = blueprint
69 
70  # set by netlist ctor
71  self.refdes = None
72 
73  self.cpins = [] # list of ComponentPin
75  self.cpins_by_number = {}
76 
77  self.subsheets = []
78 
79  self.error = blueprint.error
80  self.warn = blueprint.warn
81 
82  sheet.components.append(self)
83  sheet.components_by_blueprint[blueprint] = self
84 
85  # create component pins
86  for pin_blueprint in blueprint.pins:
87  if pin_blueprint.ob is not None and pin_blueprint.ob.data().is_bus:
88  # ignore bus pins
89  continue
90 
92  self, pin_blueprint,
93  sheet.local_nets_by_blueprint[pin_blueprint.net])
94 
95 ## Pin on a component.
96 #
97 # One such object exists for every pin on a component in the netlist.
98 
100  def __init__(self, component, blueprint, local_net):
101  ## The component object to which this pin belongs.
102  self.component = component
103 
104  ## The blueprint Pin object of which this is an instance.
105  #
106  # \c None for an artificial pin created via the \c "net=" attribute.
107  self.blueprint = blueprint
108 
109  #self.is_bus = blueprint is not None and blueprint.ob.data().is_bus
110 
111  ## The LocalNet object to which this pin is connected.
112  #
113  # For real pins, this is just the net instance for the
114  # blueprint pin's net
115  self.local_net = local_net
116 
117  self.error = blueprint.error
118  self.warn = blueprint.warn
119 
120  component.cpins.append(self)
121  local_net.cpins.append(self)
122 
123  assert blueprint not in component.cpins_by_blueprint
124  component.cpins_by_blueprint[blueprint] = self
125 
126  if blueprint.number is not None:
127  component.cpins_by_number[blueprint.number] = self
128 
129 class LocalNet:
130  def __init__(self, sheet, blueprint):
131  self.sheet = sheet
132  self.blueprint = blueprint
133  self.cpins = []
134  self.net = None
135 
136  sheet.local_nets.append(self)
137  sheet.local_nets_by_blueprint[blueprint] = self
local_net
The LocalNet object to which this pin is connected.
Definition: instance.py:115
Instantiation of a schematic page.
Definition: instance.py:32
component
The component object to which this pin belongs.
Definition: instance.py:102
blueprint
The blueprint Pin object of which this is an instance.
Definition: instance.py:107