Beispiel #1
0
def test_port_remove():
    D = Device()
    D.add_port(name='test123', midpoint=(5.7, 9.2), orientation=37)
    D.add_port(name='test456', midpoint=(1.5, 6.7), orientation=99)
    E = Device()
    d = E << D
    D.remove(D.ports['test123'])
    assert (len(D.ports) == 1)
    assert (len(d.ports) == 1)
    assert (D.ports['test456'])
    assert (d.ports['test456'])
#==============================================================================
# Removing geometry
#==============================================================================
# If you want, you can remove DeviceReferences or Polygons with D.remove()

# Let's add some geometry to a blank Device D:
D = Device()
myell1 = D.add_ref(pg.L())
mytee2 = D.add_ref(pg.tee().movex(15))
mypoly1 = D.add_polygon([(8, 6, 7, 9), (6, 8, 9, 5)])
mypoly2 = D.add_polygon([(0, 0), (1, 1), (1, 3), (-3, 3)]).movey(-5)
qp(D)

# Now we can remove two of the elements we don't want anymore
D.remove(mytee2)
D.remove(mypoly2)
qp(D)

#==============================================================================
# Save / export to SVG
#==============================================================================
# For figure-quality publications sometimes you want to save your geometry
# as a more convenient vector file format like SVG (for Inkscape, Illustrator,
# etc). For that purpose you can use the write_svg() command
from phidl.utilities import write_svg

D = Device()
D << pg.snspd_expanded(layer=1)
D << pg.snspd_expanded(layer=2).rotate(45)
write_svg(D, filename='MyGeometryFigure.svg')