Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow labels on different layers when label_layer=None in add_labels #2331

Merged
merged 1 commit into from Nov 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 14 additions & 10 deletions gdsfactory/add_labels.py
Expand Up @@ -167,7 +167,7 @@ def get_input_label_electrical(
def add_labels(
component: Component,
get_label_function: Callable = get_input_label_electrical,
layer_label: LayerSpec = "TEXT",
layer_label: LayerSpec | None = "TEXT",
gc: Component | None = None,
**kwargs,
) -> Component:
Expand All @@ -176,7 +176,7 @@ def add_labels(
Args:
component: to add labels to.
get_label_function: function to get label.
layer_label: LayerSpec for the label.
layer_label: LayerSpec for the label. None will use the port layer.
gc: Optional grating coupler.

Keyword Args:
Expand All @@ -200,7 +200,7 @@ def add_labels(
gc=gc,
gc_index=i,
component_name=component.name,
layer_label=layer_label,
layer_label=layer_label if layer_label else port.layer,
)
component.add(label)

Expand Down Expand Up @@ -259,18 +259,18 @@ def add_siepic_labels(

def add_labels_to_ports(
component: Component,
label_layer: LayerSpec = "TEXT",
label_layer: LayerSpec | None = "TEXT",
port_type: str | None = None,
**kwargs,
) -> Component:
"""Add labels to component ports.

Args:
component: to add labels.
label_layer: layer spec for the label.
label_layer: layer spec for the label. None will use the port layer.
port_type: to select ports.

keyword Args:
Keyword Args:
layer: select ports with GDS layer.
prefix: select ports with prefix in port name.
suffix: select ports with port name suffix.
Expand All @@ -282,22 +282,26 @@ def add_labels_to_ports(
"""
ports = component.get_ports_list(port_type=port_type, **kwargs)
for port in ports:
component.add_label(text=port.name, position=port.center, layer=label_layer)
component.add_label(
text=port.name,
position=port.center,
layer=label_layer if label_layer else port.layer,
)

return component


def add_labels_to_ports_x_y(
component: Component,
label_layer: LayerSpec = "TEXT",
label_layer: LayerSpec | None = "TEXT",
port_type: str | None = None,
**kwargs,
) -> Component:
"""Add labels to component ports. Prepends -x-y coordinates

Args:
component: to add labels.
label_layer: layer spec for the label.
label_layer: layer spec for the label. None will use the port layer.
port_type: to select ports.

keyword Args:
Expand All @@ -316,7 +320,7 @@ def add_labels_to_ports_x_y(
component.add_label(
text=f"{port.name}/{int(x)}/{int(y)}",
position=port.center,
layer=label_layer,
layer=label_layer if label_layer else port.layer,
)

return component
Expand Down