[PortPather] add default_spacing (.at(..., spacing=...))
This commit is contained in:
parent
833f5dd159
commit
d36a1a53e6
3 changed files with 105 additions and 10 deletions
|
|
@ -1173,30 +1173,50 @@ class Pather(PortList):
|
|||
self.pattern.flatten(self.library)
|
||||
return self
|
||||
|
||||
def at(self, portspec: str | Iterable[str]) -> 'PortPather':
|
||||
return PortPather(portspec, self)
|
||||
def at(
|
||||
self,
|
||||
portspec: str | Iterable[str],
|
||||
*,
|
||||
spacing: float | ArrayLike | None = None,
|
||||
) -> 'PortPather':
|
||||
return PortPather(portspec, self, default_spacing=spacing)
|
||||
|
||||
|
||||
class PortPather:
|
||||
""" Port state manager for fluent pathing. """
|
||||
def __init__(self, ports: str | Iterable[str], pather: Pather) -> None:
|
||||
def __init__(
|
||||
self,
|
||||
ports: str | Iterable[str],
|
||||
pather: Pather,
|
||||
*,
|
||||
default_spacing: float | ArrayLike | None = None,
|
||||
) -> None:
|
||||
self.ports = [ports] if isinstance(ports, str) else list(ports)
|
||||
self.pather = pather
|
||||
self.default_spacing = default_spacing
|
||||
|
||||
def retool(self, tool: Tool) -> Self:
|
||||
self.pather.retool(tool, self.ports)
|
||||
return self
|
||||
|
||||
def set_spacing(self, spacing: float | ArrayLike | None) -> Self:
|
||||
self.default_spacing = spacing
|
||||
return self
|
||||
|
||||
@contextmanager
|
||||
def toolctx(self, tool: Tool) -> Iterator[Self]:
|
||||
with self.pather.toolctx(tool, keys=self.ports):
|
||||
yield self
|
||||
|
||||
def trace(self, ccw: SupportsBool | None, length: float | None = None, **kw: Any) -> Self:
|
||||
if 'spacing' not in kw and self.default_spacing is not None and len(self.ports) > 1 and ccw is not None:
|
||||
kw['spacing'] = self.default_spacing
|
||||
self.pather.trace(self.ports, ccw, length, **kw)
|
||||
return self
|
||||
|
||||
def trace_to(self, ccw: SupportsBool | None, **kw: Any) -> Self:
|
||||
if 'spacing' not in kw and self.default_spacing is not None and len(self.ports) > 1 and ccw is not None:
|
||||
kw['spacing'] = self.default_spacing
|
||||
self.pather.trace_to(self.ports, ccw, **kw)
|
||||
return self
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue