[Library.flatten] add dangling_ok param
This commit is contained in:
parent
f8a82336f6
commit
c1c83afc98
@ -378,7 +378,7 @@ class SimpleTool(Tool, metaclass=ABCMeta):
|
|||||||
else:
|
else:
|
||||||
straight_tree = straight_pat_or_tree
|
straight_tree = straight_pat_or_tree
|
||||||
top = straight_tree.top()
|
top = straight_tree.top()
|
||||||
straight_tree.flatten(top)
|
straight_tree.flatten(top, dangling_ok=True)
|
||||||
pat.plug(straight_tree[top], pmap, append=True)
|
pat.plug(straight_tree[top], pmap, append=True)
|
||||||
if data.ccw is not None:
|
if data.ccw is not None:
|
||||||
bend, bport_in, bport_out = self.bend
|
bend, bport_in, bport_out = self.bend
|
||||||
@ -653,7 +653,7 @@ class AutoTool(Tool, metaclass=ABCMeta):
|
|||||||
else:
|
else:
|
||||||
straight_tree = straight_pat_or_tree
|
straight_tree = straight_pat_or_tree
|
||||||
top = straight_tree.top()
|
top = straight_tree.top()
|
||||||
straight_tree.flatten(top)
|
straight_tree.flatten(top, dangling_ok=True)
|
||||||
pat.plug(straight_tree[top], pmap, append=True)
|
pat.plug(straight_tree[top], pmap, append=True)
|
||||||
if data.b_transition:
|
if data.b_transition:
|
||||||
pat.plug(data.b_transition.abstract, {port_names[1]: data.b_transition.our_port_name})
|
pat.plug(data.b_transition.abstract, {port_names[1]: data.b_transition.our_port_name})
|
||||||
@ -801,7 +801,7 @@ class AutoTool(Tool, metaclass=ABCMeta):
|
|||||||
else:
|
else:
|
||||||
straight_tree = straight_pat_or_tree
|
straight_tree = straight_pat_or_tree
|
||||||
top = straight_tree.top()
|
top = straight_tree.top()
|
||||||
straight_tree.flatten(top)
|
straight_tree.flatten(top, dangling_ok=True)
|
||||||
pat.plug(straight_tree[top], pmap, append=True)
|
pat.plug(straight_tree[top], pmap, append=True)
|
||||||
if data.b_transition:
|
if data.b_transition:
|
||||||
pat.plug(data.b_transition.abstract, {port_names[1]: data.b_transition.our_port_name})
|
pat.plug(data.b_transition.abstract, {port_names[1]: data.b_transition.our_port_name})
|
||||||
@ -813,7 +813,7 @@ class AutoTool(Tool, metaclass=ABCMeta):
|
|||||||
else:
|
else:
|
||||||
sbend_tree = sbend_pat_or_tree
|
sbend_tree = sbend_pat_or_tree
|
||||||
top = sbend_tree.top()
|
top = sbend_tree.top()
|
||||||
sbend_tree.flatten(top)
|
sbend_tree.flatten(top, dangling_ok=True)
|
||||||
pat.plug(sbend_tree[top], pmap, append=True, mirrored=data.jog_remaining < 0)
|
pat.plug(sbend_tree[top], pmap, append=True, mirrored=data.jog_remaining < 0)
|
||||||
if data.out_transition:
|
if data.out_transition:
|
||||||
pat.plug(data.out_transition.abstract, {port_names[1]: data.out_transition.our_port_name})
|
pat.plug(data.out_transition.abstract, {port_names[1]: data.out_transition.our_port_name})
|
||||||
|
|||||||
@ -264,6 +264,7 @@ class ILibraryView(Mapping[str, 'Pattern'], metaclass=ABCMeta):
|
|||||||
self,
|
self,
|
||||||
tops: str | Sequence[str],
|
tops: str | Sequence[str],
|
||||||
flatten_ports: bool = False,
|
flatten_ports: bool = False,
|
||||||
|
dangling_ok: bool = False,
|
||||||
) -> dict[str, 'Pattern']:
|
) -> dict[str, 'Pattern']:
|
||||||
"""
|
"""
|
||||||
Returns copies of all `tops` patterns with all refs
|
Returns copies of all `tops` patterns with all refs
|
||||||
@ -276,6 +277,9 @@ class ILibraryView(Mapping[str, 'Pattern'], metaclass=ABCMeta):
|
|||||||
tops: The pattern(s) to flattern.
|
tops: The pattern(s) to flattern.
|
||||||
flatten_ports: If `True`, keep ports from any referenced
|
flatten_ports: If `True`, keep ports from any referenced
|
||||||
patterns; otherwise discard them.
|
patterns; otherwise discard them.
|
||||||
|
dangling_ok: If `True`, no error will be thrown if any
|
||||||
|
ref points to a name which is not present in the library.
|
||||||
|
Default False.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
{name: flat_pattern} mapping for all flattened patterns.
|
{name: flat_pattern} mapping for all flattened patterns.
|
||||||
@ -292,6 +296,8 @@ class ILibraryView(Mapping[str, 'Pattern'], metaclass=ABCMeta):
|
|||||||
for target in pat.refs:
|
for target in pat.refs:
|
||||||
if target is None:
|
if target is None:
|
||||||
continue
|
continue
|
||||||
|
if dangling_ok and target not in self:
|
||||||
|
continue
|
||||||
if target not in flattened:
|
if target not in flattened:
|
||||||
flatten_single(target)
|
flatten_single(target)
|
||||||
|
|
||||||
@ -307,7 +313,9 @@ class ILibraryView(Mapping[str, 'Pattern'], metaclass=ABCMeta):
|
|||||||
p.ports.clear()
|
p.ports.clear()
|
||||||
pat.append(p)
|
pat.append(p)
|
||||||
|
|
||||||
pat.refs.clear()
|
for target in set(pat.refs.keys()) & set(self.keys()):
|
||||||
|
del pat.refs[target]
|
||||||
|
|
||||||
flattened[name] = pat
|
flattened[name] = pat
|
||||||
|
|
||||||
for top in tops:
|
for top in tops:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user