-
Notifications
You must be signed in to change notification settings - Fork 183
/
copy.py
61 lines (55 loc) · 1.81 KB
/
copy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import copy as python_copy
import gdspy
from phidl.device_layout import CellArray, DeviceReference
from gdsfactory.component import Component, ComponentReference
def copy(
D: Component,
prefix: str = "",
suffix: str = "_copy",
) -> Component:
"""Returns a deep copy of a Component.
Args:
D: component.
prefix: to add to new component name.
suffix: to add to new component name.
"""
D_copy = Component(name=f"{prefix}{D.name}{suffix}")
D_copy.info = python_copy.deepcopy(D.info)
for ref in D.references:
if isinstance(ref, DeviceReference):
new_ref = ComponentReference(
ref.parent,
origin=ref.origin,
rotation=ref.rotation,
magnification=ref.magnification,
x_reflection=ref.x_reflection,
)
new_ref.owner = D_copy
elif isinstance(ref, gdspy.CellArray):
new_ref = CellArray(
device=ref.parent,
columns=ref.columns,
rows=ref.rows,
spacing=ref.spacing,
origin=ref.origin,
rotation=ref.rotation,
magnification=ref.magnification,
x_reflection=ref.x_reflection,
)
D_copy.add(new_ref)
for alias_name, alias_ref in D.aliases.items():
if alias_ref == ref:
D_copy.aliases[alias_name] = new_ref
for port in D.ports.values():
D_copy.add_port(port=port)
for poly in D.polygons:
D_copy.add_polygon(poly)
for path in D.paths:
D_copy.add(path)
for label in D.labels:
D_copy.add_label(
text=label.text,
position=label.position,
layer=(label.layer, label.texttype),
)
return D_copy