Skip to content

Commit

Permalink
Version 0.5.14
Browse files Browse the repository at this point in the history
* Layer operations for libraries apart from the common_lib.
  • Loading branch information
Hideousmon committed Dec 15, 2024
1 parent 9ebeb91 commit 14b03a7
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 28 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,5 @@ SPLayout.egg-info
new_features.md
*.fsp
boolean*.gds
temporary_figures/
temporary_figures/
*.h5
3 changes: 3 additions & 0 deletions history.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,6 @@

### Version 0.5.13 (Dec 10, 2024)
* Fix layout bug for CirclePixelsRegionwithGroup.

### Version 0.5.14 (Dec 15, 2024)
* Layer operations for libraries apart from the common_lib.
2 changes: 1 addition & 1 deletion splayout/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.5.13"
__version__ = "0.5.14"

## Submodules
from . import utils
Expand Down
53 changes: 27 additions & 26 deletions splayout/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
## global library
common_lib = gdspy.GdsLibrary(unit=1.0e-6, precision=1.0e-9)

def remove_cell(cell):
def remove_cell(cell, lib = common_lib):
"""
Remove a cell.
Expand All @@ -35,9 +35,9 @@ def remove_cell(cell):
Cell to be removed.
"""
if type(cell) == str:
common_lib.remove(cell)
lib.remove(cell)
elif type(cell) == Cell:
common_lib.remove(cell.cell)
lib.remove(cell.cell)


class Point:
Expand Down Expand Up @@ -161,7 +161,7 @@ def __init__(self,layer,datatype = 0):
self.layer = layer
self.datatype = datatype

def cut(self, another_layer, output_layer = None):
def cut(self, another_layer, output_layer = None, lib=common_lib):
"""
Cut the components in this layer with the components from another_layer, which means generate components 'in
this layer but not in another_layer'. If output_layer is not specified the result will replace the components
Expand All @@ -180,7 +180,7 @@ def cut(self, another_layer, output_layer = None):
"""
if output_layer is None:
output_layer = self
top_cell = common_lib.top_level()[0]
top_cell = lib.top_level()[0]
polygons = top_cell.get_polygons(by_spec=True)
cutted_components = gdspy.boolean(polygons[(self.layer, self.datatype)],
polygons[(another_layer.layer, another_layer.datatype)],
Expand All @@ -189,7 +189,7 @@ def cut(self, another_layer, output_layer = None):
top_cell.remove_polygons(lambda p, l, d:(l==output_layer.layer and d==output_layer.datatype))
top_cell.add(cutted_components)

def add(self, another_layer, output_layer = None):
def add(self, another_layer, output_layer = None, lib=common_lib):
"""
Add the components in this layer with the components from another_layer, which means generate components 'in
this layer or in another_layer'. If output_layer is not specified the result will replace the components
Expand All @@ -208,7 +208,7 @@ def add(self, another_layer, output_layer = None):
"""
if output_layer is None:
output_layer = self
top_cell = common_lib.top_level()[0]
top_cell = lib.top_level()[0]
polygons = top_cell.get_polygons(by_spec=True)
added_components = gdspy.boolean(polygons[(self.layer, self.datatype)],
polygons[(another_layer.layer, another_layer.datatype)],
Expand All @@ -217,7 +217,7 @@ def add(self, another_layer, output_layer = None):
top_cell.remove_polygons(lambda p, l, d:(l==output_layer.layer and d==output_layer.datatype))
top_cell.add(added_components)

def common(self, another_layer, output_layer = None):
def common(self, another_layer, output_layer = None, lib=common_lib):
"""
Find the common part of the components in this layer and the components from another_layer, which means
generate components 'in this layer and in another_layer'. If output_layer is not specified the result will
Expand All @@ -236,7 +236,7 @@ def common(self, another_layer, output_layer = None):
"""
if output_layer is None:
output_layer = self
top_cell = common_lib.top_level()[0]
top_cell = lib.top_level()[0]
polygons = top_cell.get_polygons(by_spec=True)
common_components = gdspy.boolean(polygons[(self.layer, self.datatype)],
polygons[(another_layer.layer, another_layer.datatype)],
Expand All @@ -245,7 +245,7 @@ def common(self, another_layer, output_layer = None):
top_cell.remove_polygons(lambda p, l, d:(l==output_layer.layer and d==output_layer.datatype))
top_cell.add(common_components)

def dilation(self, distance = 2, output_layer = None):
def dilation(self, distance = 2, output_layer = None, lib=common_lib):
"""
Dilate the components in this layer. If output_layer is not specified the result will
replace the components in this layer.
Expand All @@ -263,15 +263,15 @@ def dilation(self, distance = 2, output_layer = None):
"""
if output_layer is None:
output_layer = self
top_cell = common_lib.top_level()[0]
top_cell = lib.top_level()[0]
polygons = top_cell.get_polygons(by_spec=True)
dilation_components = gdspy.offset(polygons[(self.layer, self.datatype)], distance=distance,
join_first=True, layer=output_layer.layer, datatype=output_layer.datatype,
tolerance=0.0001, max_points=100000)
top_cell.remove_polygons(lambda p, l, d: (l == output_layer.layer and d == output_layer.datatype))
top_cell.add(dilation_components)

def inversion(self, distance = 2, output_layer = None, precision = 0.001):
def inversion(self, distance = 2, output_layer = None, precision = 0.001, lib=common_lib):
"""
Make inversion for the components in this layer. If output_layer is not specified the result will
replace the components in this layer.
Expand All @@ -290,7 +290,7 @@ def inversion(self, distance = 2, output_layer = None, precision = 0.001):
"""
if output_layer is None:
output_layer = self
top_cell = common_lib.top_level()[0]
top_cell = lib.top_level()[0]
polygons = top_cell.get_polygons(by_spec=True)
dilation_components = gdspy.offset(polygons[(self.layer, self.datatype)], distance=distance, join_first=True,
layer=output_layer.layer, datatype=output_layer.datatype, tolerance=0.0001, max_points=100000,
Expand All @@ -300,23 +300,23 @@ def inversion(self, distance = 2, output_layer = None, precision = 0.001):
top_cell.remove_polygons(lambda p, l, d: (l == output_layer.layer and d == output_layer.datatype))
top_cell.add(inversion_components)

def flip_horizontally(self):
def flip_horizontally(self, lib=common_lib):
"""
Flip the components in this layer horizontally relative to Point(0, 0).
"""
top_cell = common_lib.top_level()[0]
top_cell = lib.top_level()[0]
polygons = top_cell.get_polygons(by_spec=True)
flipped_components = []
for poly in polygons[(self.layer, self.datatype)]:
flipped_components.append(gdspy.Polygon(poly, self.layer, self.datatype).mirror((0, -1), (0, 1)))
top_cell.remove_polygons(lambda p, l, d: (l == self.layer and d == self.datatype))
top_cell.add(flipped_components)

def flip_vertically(self):
def flip_vertically(self, lib=common_lib):
"""
Flip the components in this layer vertically relative to Point(0, 0).
"""
top_cell = common_lib.top_level()[0]
top_cell = lib.top_level()[0]
polygons = top_cell.get_polygons(by_spec=True)
flipped_components = []
for poly in polygons[(self.layer, self.datatype)]:
Expand All @@ -325,7 +325,7 @@ def flip_vertically(self):
top_cell.add(flipped_components)


def rotate(self, radian):
def rotate(self, radian, lib=common_lib):
"""
Rotate the components in this layer relative to Point(0, 0).
Expand All @@ -334,7 +334,7 @@ def rotate(self, radian):
radian : Float
Rotation angle in radian.
"""
top_cell = common_lib.top_level()[0]
top_cell = lib.top_level()[0]
polygons = top_cell.get_polygons(by_spec=True)
rotated_components = []
for poly in polygons[(self.layer, self.datatype)]:
Expand All @@ -343,7 +343,7 @@ def rotate(self, radian):
top_cell.add(rotated_components)


def scale(self, scalex, scaley=None):
def scale(self, scalex, scaley=None, lib=common_lib):
"""
Scale the components in this layer relative to Point(0, 0).
Expand All @@ -356,15 +356,15 @@ def scale(self, scalex, scaley=None):
"""
if scaley is None:
scaley = scalex
top_cell = common_lib.top_level()[0]
top_cell = lib.top_level()[0]
polygons = top_cell.get_polygons(by_spec=True)
scaled_components = []
for poly in polygons[(self.layer, self.datatype)]:
scaled_components.append(gdspy.Polygon(poly, self.layer, self.datatype).scale(scalex, scaley, (0, 0)))
top_cell.remove_polygons(lambda p, l, d: (l == self.layer and d == self.datatype))
top_cell.add(scaled_components)

def move(self, distance_x=0, distance_y=0):
def move(self, distance_x=0, distance_y=0, lib=common_lib):
"""
Move the components in this layer by a certain distance.
Expand All @@ -375,7 +375,7 @@ def move(self, distance_x=0, distance_y=0):
distance_y : Int or Float
Moving distance in y-axis. (unit: micrometer, default: 0)
"""
top_cell = common_lib.top_level()[0]
top_cell = lib.top_level()[0]
polygons = top_cell.get_polygons(by_spec=True)
scaled_components = []
for poly in polygons[(self.layer, self.datatype)]:
Expand All @@ -400,7 +400,8 @@ class Cell():
def __init__(self,name,lib=common_lib):
if type(name) != str :
raise Exception("The name of a cell should be a string!")
self.cell = lib.new_cell(name, overwrite_duplicate=True)
self.lib = lib
self.cell = self.lib.new_cell(name, overwrite_duplicate=True)

def remove_components(self):
"""
Expand Down Expand Up @@ -430,10 +431,10 @@ def remove_other_cells(self):
"""
Remove other cells.
"""
cells = common_lib.top_level()
cells = self.lib.top_level()
cells.remove(self.cell)
for temp_cell in cells:
common_lib.remove(temp_cell)
self.lib.remove(temp_cell)

def tuple_to_point(input_tuple):
"""
Expand Down

0 comments on commit 14b03a7

Please sign in to comment.