Skip to content

Commit

Permalink
make Component.remap_layers safe
Browse files Browse the repository at this point in the history
Former-commit-id: dd80ff1 [formerly 051d74e]
Former-commit-id: c922bd4db2d47a49f4bc8bad406bd8a69ff5d1c2
  • Loading branch information
joamatab committed Feb 5, 2023
1 parent 1fe2a49 commit f9c9e47
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
9 changes: 5 additions & 4 deletions gdsfactory/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -2071,17 +2071,18 @@ def get_info(self):
def remap_layers(
self, layermap, include_labels: bool = True, include_paths: bool = True
) -> Component:
"""Moves all polygons in the Component from one layer to another according to the layermap argument.
"""Returns a copy of the component with remapped layers.
Args:
layermap: Dictionary of values in format {layer_from : layer_to}.
include_labels: Selects whether to move Labels along with polygons.
include_paths: Selects whether to move Paths along with polygons.
"""
component = self.copy()
layermap = {_parse_layer(k): _parse_layer(v) for k, v in layermap.items()}

all_D = list(self.get_dependencies(True))
all_D.append(self)
all_D = list(component.get_dependencies(True))
all_D.append(component)
for D in all_D:
for p in D.polygons:
layer = (p.layer, p.datatype)
Expand Down Expand Up @@ -2112,7 +2113,7 @@ def remap_layers(
new_datatypes[layer_number] = new_layer[1]
path.set_layers(*new_layers)
path.set_datatypes(*new_datatypes)
return self
return component


def copy(
Expand Down
8 changes: 4 additions & 4 deletions tests/test_remap.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ def test_remap_layers():
c2 = c.remap_layers({gf.LAYER.WG: gf.LAYER.WGN, gf.LAYER.PORT: gf.LAYER.PORTE})

assert len(c.polygons) == 1, len(c.polygons)
assert len(c2.polygons) == 0, len(c2.polygons)
assert len(c2.polygons) == 1, len(c2.polygons)
assert len(c.paths) == 2, len(c.paths)
assert len(c2.paths) == 2, len(c2.paths)
assert gf.LAYER.WGCLAD in c.layers
assert gf.LAYER.PORT in c2.layers
assert gf.LAYER.WG in c.layers
assert gf.LAYER.WGN in c2.layers
assert gf.LAYER.PORTE in c2.layers
return c2


Expand All @@ -22,6 +23,5 @@ def test_remap_layers():
# c.show()

c = gf.components.straight(length=1, width=0.5, add_pins=add_pins_siepic)
# c2 = c.remap_layers({gf.LAYER.WG: gf.LAYER.WGN})
c2 = c.remap_layers({gf.LAYER.WG: gf.LAYER.WGN, gf.LAYER.PORT: gf.LAYER.PORTE})
c2.show()

0 comments on commit f9c9e47

Please sign in to comment.