24 from gettext
import gettext
as _
30 self.
names = {
False: [],
True: [] }
49 self, has_attrib_name, has_attrib_value, wanted_attrib):
50 if not isinstance(has_attrib_name, basestring)
or \
51 not isinstance(has_attrib_value, basestring)
or \
52 not isinstance(wanted_attrib, basestring):
60 if cpin.component.blueprint.get_attribute(has_attrib_name,
None) \
64 l.append(cpin.component.blueprint.get_attribute(wanted_attrib))
70 if not isinstance(other, Net):
72 if other.netlist != self.
netlist:
78 assert local_net.net == self
82 for from_netattrib
in [
False,
True]:
83 for name
in self.
names[from_netattrib]:
84 if name
not in other.names[from_netattrib]:
85 other.names[from_netattrib].append(name)
88 del self.
names[
False][:]
89 del self.
names[
True][:]
91 self.netlist.nets.remove(self)
94 sys.stderr.write(_(
"net `%s': error: %s\n") % (self.
name, msg))
95 self.netlist.failed =
True
98 sys.stderr.write(_(
"net `%s': warning: %s\n") % (self.
name, msg))
101 default_net_name, default_bus_name):
106 for sheet
in netlist.sheets:
107 for local_net
in sheet.local_nets:
111 for net_name, from_netattrib
in \
112 [(name,
False)
for name
in local_net.blueprint.names] + \
113 [(net_name,
True)
for net_name
in
114 local_net.blueprint.names_from_net_attribute]:
115 if not isinstance(net_name, basestring):
118 if flat_namespace[from_netattrib] \
119 or sheet.instantiating_component
is None:
120 net_name =
None, net_name
122 net_name = sheet, net_name
125 net = net_dict[net_name]
128 netlist.nets.append(net)
129 net_dict[net_name] = net
131 if net_name
not in net.names[from_netattrib]:
132 net.names[from_netattrib].append(net_name)
134 if local_net.net == net:
137 if local_net.net
is None:
139 net.local_nets.append(local_net)
141 a = netlist.nets.index(local_net.net)
142 b = netlist.nets.index(net)
143 dst = netlist.nets[min(a, b)]
144 src = netlist.nets[max(a, b)]
146 for name
in set(src.names[
False] + src.names[
True]):
147 assert net_dict[name] == src
151 assert local_net
in dst.local_nets
154 prio =
not prefer_netname_attribute
156 for net
in netlist.nets:
157 if len(net.names[prio]) == 0:
159 if len(net.names[
not prio]) == 0:
161 elif len(net.names[
not prio]) == 1:
162 net.namespace, net.unmangled_name = net.names[
not prio][0]
164 netlist.warn(_(
"net has more than one name: %s")
167 for ns, name
in net.names[
not prio]))
168 net.namespace, net.unmangled_name = net.names[
not prio][-1]
169 elif len(net.names[prio]) == 1:
170 net.namespace, net.unmangled_name = net.names[prio][0]
172 netlist.warn(_(
"net has more than one name: %s")
173 % _(
" vs. ").join(
"\"%s\"" % name
174 for ns, name
in net.names[prio]))
175 net.namespace, net.unmangled_name = net.names[prio][-1]
179 unnamed_net_bus_counter = {
False: 1,
True: 1 }
180 unnamed_pin_counter = 1
182 for component
in netlist.components:
183 for cpin
in component.cpins:
184 local_net = cpin.local_net
185 assert local_net
is not None
186 assert cpin
in local_net.cpins
195 netlist.nets.append(net)
197 net.local_nets.append(local_net)
199 if len(net.local_nets) == 1
and \
200 len(net.local_nets[0].blueprint.pins) == 1
and \
201 not net.local_nets[0].blueprint.net_segments:
202 net.is_unconnected_pin =
True
205 unnamed_counter =
None
207 while net_name
is None or net_name
in net_dict:
213 if net.is_unconnected_pin:
214 net_name =
'unconnected_pin-%d' % unnamed_pin_counter
215 unnamed_pin_counter += 1
219 unnamed_counter = unnamed_net_bus_counter[is_bus]
220 unnamed_net_bus_counter[is_bus] += 1
223 unnamed_string = default_net_name
225 unnamed_string = default_bus_name
227 net_name =
'%s%d' % (unnamed_string, unnamed_counter)
229 if flat_namespace[
False] \
230 or component.sheet.instantiating_component
is None:
231 net_name =
None, net_name
233 net_name = component.sheet, net_name
235 net.namespace, net.unmangled_name = net_name
236 net.unnamed_counter = unnamed_counter
237 net_dict[net_name] = net
251 for component
in netlist.components:
252 for cpin
in component.cpins:
253 if cpin.local_net.net
not in net_set:
255 nets.append(cpin.local_net.net)
256 net_set.add(cpin.local_net.net)
261 assert sorted(netlist.nets) == sorted(nets)
sheets_and_net_blueprints
def graphical_objs_with_attrib_get_attrib
Given an attribute and a wanted attribute, return all the given attribute of all the graphical object...