Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def tree():
p1 = gdspy.Polygon(((0, 0), (0, 1), (1, 0)), 0, 0)
p2 = gdspy.Polygon(((2, 0), (2, 1), (1, 0)), 1, 1)
l1 = gdspy.Label("label1", (0, 0), layer=11)
l2 = gdspy.Label("label2", (2, 1), layer=12)
c1 = gdspy.Cell("tree_" + unique())
c1.add(p1)
c1.add(l1)
c2 = gdspy.Cell("tree_" + unique())
c2.add(l2)
c2.add(p2)
c2.add(gdspy.CellReference(c1))
c3 = gdspy.Cell("tree_" + unique())
c3.add(gdspy.CellArray(c2, 3, 2, (3, 3)))
return c3, c2, c1
def tree():
p1 = gdspy.Polygon(((0, 0), (0, 1), (1, 0)), 0, 0)
p2 = gdspy.Polygon(((2, 0), (2, 1), (1, 0)), 1, 1)
l1 = gdspy.Label("label1", (0, 0), layer=11)
l2 = gdspy.Label("label2", (2, 1), layer=12)
c1 = gdspy.Cell("tree_" + unique())
c1.add(p1)
c1.add(l1)
c2 = gdspy.Cell("tree_" + unique())
c2.add(l2)
c2.add(p2)
c2.add(gdspy.CellReference(c1))
c3 = gdspy.Cell("tree_" + unique())
c3.add(gdspy.CellArray(c2, 3, 2, (3, 3)))
return c3, c2, c1
def test_rw_gds(tmpdir):
lib = gdspy.GdsLibrary("lib", unit=2e-3, precision=1e-5)
c1 = gdspy.Cell("gl_rw_gds_1")
c1.add(gdspy.Rectangle((0, -1), (1, 2), 2, 4))
c1.add(gdspy.Label("label", (1, -1), "w", 45, 1.5, True, 5, 6))
c2 = gdspy.Cell("gl_rw_gds_2")
c2.add(gdspy.Round((0, 0), 1, number_of_points=32, max_points=20))
c3 = gdspy.Cell("gl_rw_gds_3")
c3.add(gdspy.CellReference(c1, (0, 1), -90, 2, True))
c4 = gdspy.Cell("gl_rw_gds_4")
c4.add(gdspy.CellArray(c2, 2, 3, (1, 4), (-1, -2), 180, 0.5, True))
lib.add((c1, c2, c3, c4))
fname1 = str(tmpdir.join("test1.gds"))
lib.write_gds(fname1)
lib1 = gdspy.GdsLibrary(
infile=fname1,
unit=1e-3,
precision=1e-6,
units="convert",
rename={"gl_rw_gds_1": "1"},
def test_copy():
name = "c_copy"
p = gdspy.Polygon(((0, 0), (1, 0), (0, 1)))
lbl = gdspy.Label("label", (0, 0))
c1 = gdspy.Cell(name)
c1.add(p)
c1.add(lbl)
c3 = c1.copy(name, False)
assert c3.polygons == c1.polygons and c3.polygons is not c1.polygons
assert c3.labels == c1.labels and c3.labels is not c1.labels
cref = gdspy.Cell("c_ref").add(gdspy.Rectangle((-1, -1), (-2, -2)))
c1.add(gdspy.CellReference(cref))
c1.get_bounding_box()
c4 = c1.copy("c_copy_1", True)
assert c4.polygons != c1.polygons
assert c4.labels != c1.labels
assert c1._bb_valid
assert cref._bb_valid
assert not c4._bb_valid
'Created with gsdpy ' + gdspy.__version__, 7, (-7, -35), layer=6))
# Labels are special text objects which don't define any actual
# geometry, but can be used to annotate the drawing. Rotation,
# magnification and reflection of the text are not supported by the
# included GUI, but they are included in the resulting GDSII file.
ref_cell.add(
gdspy.Label(
'text TYPE 0', (-7, -36), 'nw', layer=6, texttype=0))
ref_cell.add(
gdspy.Label(
'text TYPE 1', (-7, -38), 'se', layer=6, texttype=1))
ref_cell.add(
gdspy.Label(
'text TYPE 2', (-7, -40), 'nw', layer=6, texttype=2))
ref_cell.add(
gdspy.Label(
'text TYPE 3', (-7, -42), 'se', layer=6, texttype=3))
# ------------------------------------------------------------------ #
# Translation
# ------------------------------------------------------------------ #
trans_cell = gdspy.Cell('TRANS')
# Any geometric object can be translated by providing the distance to
# translate in the x-direction and y-direction: translate(dx, dy)
rect1 = gdspy.Rectangle((80, 0), (81, 1), 1)
rect1.translate(2, 0)
trans_cell.add(rect1)
yc = y0 + yidx * spy
self._add_gds_via(gds_cell, via, lay_map, via_lay_info, xc, yc)
else:
self._add_gds_via(gds_cell, via, lay_map, via_lay_info, x0, y0)
# add pins
for pin in content_list.pin_list: # type: PinInfo
lay_id, purp_id = lay_map[pin.layer]
bbox = pin.bbox
label = pin.label
if pin.make_rect:
cur_rect = gdspy.Rectangle((bbox.left, bbox.bottom), (bbox.right, bbox.top),
layer=lay_id, datatype=purp_id)
gds_cell.add(cur_rect)
angle = 90 if bbox.height_unit > bbox.width_unit else 0
cur_lbl = gdspy.Label(label, (bbox.xc, bbox.yc), rotation=angle,
layer=lay_id, texttype=purp_id)
gds_cell.add(cur_lbl)
for path in content_list.path_list:
# Photonic paths should be treated like polygons
lay_id, purp_id = lay_map[path['layer']]
cur_path = gdspy.Polygon(path['polygon_points'], layer=lay_id, datatype=purp_id,
verbose=False)
gds_cell.add(cur_path.fracture(precision=res))
for blockage in content_list.blockage_list:
pass
for boundary in content_list.boundary_list:
pass
# Text are also sets of polygons. They have edges parallel to 'x' and
# 'y' only.
ref_cell.add(
gdspy.Text(
'Created with gsdpy ' + gdspy.__version__, 7, (-7, -35), layer=6))
# Labels are special text objects which don't define any actual
# geometry, but can be used to annotate the drawing. Rotation,
# magnification and reflection of the text are not supported by the
# included GUI, but they are included in the resulting GDSII file.
ref_cell.add(
gdspy.Label(
'text TYPE 0', (-7, -36), 'nw', layer=6, texttype=0))
ref_cell.add(
gdspy.Label(
'text TYPE 1', (-7, -38), 'se', layer=6, texttype=1))
ref_cell.add(
gdspy.Label(
'text TYPE 2', (-7, -40), 'nw', layer=6, texttype=2))
ref_cell.add(
gdspy.Label(
'text TYPE 3', (-7, -42), 'se', layer=6, texttype=3))
# ------------------------------------------------------------------ #
# Translation
# ------------------------------------------------------------------ #
trans_cell = gdspy.Cell('TRANS')
# Any geometric object can be translated by providing the distance to
multi_path.segment(4)
# Create a copy with joined polygons and no fracturing
joined = gdspy.boolean(multi_path, None, "or", max_points=0)
joined.translate(0, -5)
# Fillet applied to each polygon in the path
multi_path.fillet(0.5)
# Fillet applied to the joined copy
joined.fillet(0.5)
draw(gdspy.Cell("fillet_operation").add([joined, multi_path]))
# Text
# Label anchored at (1, 3) by its north-west corner
label = gdspy.Label("Sample label", (1, 3), "nw")
# Horizontal text with height 2.25
htext = gdspy.Text("12345", 2.25, (0.25, 6))
# Vertical text with height 1.5
vtext = gdspy.Text("ABC", 1.5, (10.5, 4), horizontal=False)
rect = gdspy.Rectangle((0, 0), (10, 6), layer=10)
draw(gdspy.Cell("text").add([htext, vtext, label, rect]))
rect2 = gdspy.Rectangle((80, 0), (81, 1), 2)
rect3 = gdspy.copy(rect2, 0, 3)
trans_cell.add(rect2)
trans_cell.add(rect3)
# Reference Cells are also translatable, and thus copyable.
ref1 = gdspy.CellReference(poly_cell, (25, 0), rotation=180)
ref2 = gdspy.copy(ref1, 30, 30)
trans_cell.add(ref1)
trans_cell.add(ref2)
# Same goes for Labels & Text
text1 = gdspy.Text(
'Created with gsdpy ' + gdspy.__version__, 7, (-7, -35), layer=6)
text2 = gdspy.copy(text1, 0, -20)
label1 = gdspy.Label(
'Created with gdspy ' + gdspy.__version__, (-7, -36), 'nw', layer=6)
label2 = gdspy.copy(label1, 0, -20)
trans_cell.add(text1)
trans_cell.add(text2)
trans_cell.add(label1)
trans_cell.add(label2)
# ------------------------------------------------------------------ #
# OUTPUT
# ------------------------------------------------------------------ #
# Output the layout to a GDSII file (default to all created cells).
# Set the units we used to micrometers and the precision to nanometers.
gdspy.write_gds('tutorial.gds', unit=1.0e-6, precision=1.0e-9)
# ------------------------------------------------------------------ #
# Translatable objects can also be copied & translated in the same way.
rect2 = gdspy.Rectangle((80, 0), (81, 1), 2)
rect3 = gdspy.copy(rect2, 0, 3)
trans_cell.add(rect2)
trans_cell.add(rect3)
# Reference Cells are also translatable, and thus copyable.
ref1 = gdspy.CellReference(poly_cell, (25, 0), rotation=180)
ref2 = gdspy.copy(ref1, 30, 30)
trans_cell.add(ref1)
trans_cell.add(ref2)
# Same goes for Labels & Text
text1 = gdspy.Text('Created with gdspy ' + gdspy.__version__, 7, (-7, -35), layer=6)
text2 = gdspy.copy(text1, 0, -20)
label1 = gdspy.Label('Created with gdspy ' + gdspy.__version__, (-7, -36), 'nw', layer=6)
label2 = gdspy.copy(label1, 0, -20)
trans_cell.add(text1)
trans_cell.add(text2)
trans_cell.add(label1)
trans_cell.add(label2)
# Reflection across a line defined by 2 points allows the mirroring of
# a polygon over an arbitrary axis:
rect4 = gdspy.Rectangle((80, 0), (81, 1), 3)
rect4.mirror((80, 2), (79, 0))
trans_cell.add(rect4)
# ------------------------------------------------------------------ #
# OUTPUT
# ------------------------------------------------------------------ #