diff --git a/changelog.d/143.fixed.md b/changelog.d/143.fixed.md new file mode 100644 index 00000000..04399d58 --- /dev/null +++ b/changelog.d/143.fixed.md @@ -0,0 +1 @@ +Fixed add_port ignore keep_mirror flag \ No newline at end of file diff --git a/src/kfactory/kcell.py b/src/kfactory/kcell.py index 662e6d43..7f923674 100644 --- a/src/kfactory/kcell.py +++ b/src/kfactory/kcell.py @@ -998,7 +998,7 @@ def add_port( """ if self._locked: raise LockedError(self) - self.ports.add_port(port=port, name=name) + self.ports.add_port(port=port, name=name, keep_mirror=keep_mirror) def add_ports( self, ports: Iterable[Port], prefix: str = "", keep_mirror: bool = False @@ -2243,10 +2243,10 @@ def add_port( """ _port = port.copy() if not keep_mirror: - if port._trans: - port._trans.mirror = False - elif port._dcplx_trans: - port._dcplx_trans.mirror = False + if _port._trans: + _port._trans.mirror = False + elif _port._dcplx_trans: + _port._dcplx_trans.mirror = False if name is not None: _port.name = name self._ports.append(_port) @@ -2257,7 +2257,7 @@ def add_ports( """Append a list of ports.""" for p in ports: name = p.name or "" - self.add_port(port=p, name=prefix + name) + self.add_port(port=p, name=prefix + name, keep_mirror=keep_mirror) @overload def create_port( diff --git a/tests/test_ports.py b/tests/test_ports.py index 573e6ba1..5143300f 100644 --- a/tests/test_ports.py +++ b/tests/test_ports.py @@ -100,3 +100,41 @@ def test_connect_integer(wg): wg2.connect("o1", wg1, "o1") assert wg2.ports["o1"].trans == kf.kdb.Trans(0, False, 0, 0) + + +def test_keep_mirror(LAYER): + c = kf.KCell() + + p1 = kf.Port(trans=kf.kdb.Trans.M90, width=1000, layer=LAYER.WG) + + c.add_port(p1, name="o1") + c.add_port(p1, name="o2", keep_mirror=True) + + assert c["o1"].trans.is_mirror() is False + assert c["o2"].trans.is_mirror() is True + + +def test_addports_keep_mirror(LAYER): + c = kf.KCell() + + ports = [ + kf.Port( + name=f"{i}", + width=1000, + layer=LAYER.WG, + trans=kf.kdb.Trans(i, True, 0, 0), + ) + for i in range(4) + ] + + c.add_ports(ports, prefix="mirr_", keep_mirror=True) + c.add_ports(ports, prefix="nomirr_", keep_mirror=False) + + for i in range(4): + t1 = c[f"mirr_{i}"].trans + t2 = c[f"nomirr_{i}"].trans + + t2_mirr = t2.dup() + t2_mirr.mirror = not t2_mirr.is_mirror() + + assert t1 == t2_mirr