diff --git a/history.md b/history.md index 70653e2..0f25455 100644 --- a/history.md +++ b/history.md @@ -242,4 +242,8 @@ ### Version 0.5.11 (Nov 4, 2024) * New functions: add_port, reset_ports_source and get_port_transmission for FDTDSimulation. * Add precision parameter for inversion operations. -* New function: remove_other_cells for Cell. \ No newline at end of file +* New function: remove_other_cells for Cell. + +### Version 0.5.12 (Dec 5, 2024) +* New parameter: relative_point_list for MAKE_COMPONENT function. +* New function: get_point_list() for customized components. diff --git a/splayout/__init__.py b/splayout/__init__.py index 29392af..07c5a16 100644 --- a/splayout/__init__.py +++ b/splayout/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.5.11" +__version__ = "0.5.12" ## Submodules from . import utils diff --git a/splayout/components/selfdefinecomponent.py b/splayout/components/selfdefinecomponent.py index 1c9eff2..5dd4f68 100644 --- a/splayout/components/selfdefinecomponent.py +++ b/splayout/components/selfdefinecomponent.py @@ -1,10 +1,13 @@ from ..utils.utils import * +import numpy as np ## global parameters SelfDefineCount = -1 SelfDefineComponent_cell_list = [] -def MAKE_COMPONENT(filename,rename=None,relative_start_point=Point(0,0),relative_end_point=None,relative_input_point=None,relative_through_point=None,relative_drop_point=None,relative_add_point=None,initial_relative_position = RIGHT): +def MAKE_COMPONENT(filename,rename=None,relative_start_point=Point(0,0), relative_point_list=None, relative_end_point=None, + relative_input_point=None,relative_through_point=None,relative_drop_point=None, + relative_add_point=None,initial_relative_position = RIGHT): """ Make an self-defined Class with another gdsii file. @@ -16,6 +19,8 @@ def MAKE_COMPONENT(filename,rename=None,relative_start_point=Point(0,0),relative Name of the cell (default: the filename). relative_start_point : Point The start point in the file that contains your component (can be missing). + relative_point_list : List of Point + List of points that contains your component (can be missing). relative_end_point : Point The end point in the file that contains your component (can be missing). relative_input_point : Point @@ -65,6 +70,22 @@ def MAKE_COMPONENT(filename,rename=None,relative_start_point=Point(0,0),relative SelfDefineCount_local = SelfDefineCount relative_start_point = tuple_to_point(relative_start_point) + + if (type(relative_point_list) == np.ndarray): + relative_point_list = relative_point_list.tolist() + point_list = [] + for item in relative_point_list: + if type(item) == Point: + point_list.append(item) + elif type(item) == tuple: + point_list.append(Point(item[0], item[1])) + elif type(item) == list: + point_list.append(Point(item[0], item[1])) + elif type(item) == np.ndarray: + point_list.append(Point(item[0], item[1])) + else: + raise Exception("relative_point_list wrong type input!") + relative_end_point = tuple_to_point(relative_end_point) relative_input_point =tuple_to_point(relative_input_point) relative_through_point =tuple_to_point(relative_through_point) @@ -101,6 +122,26 @@ def __init__(self, start_point, relative_position=RIGHT): raise Exception("Wrong relative position!") else: self.start_point_for_return = None + if not relative_point_list is None: + self.point_list_for_return = [] + for item in point_list: + relative_point_transfer = item + if (self.rotate_radian == RIGHT): + point_for_return = self.start_point + relative_point_transfer + elif (self.rotate_radian == UP): + point_for_return = self.start_point + Point(-relative_point_transfer.y, + relative_point_transfer.x) + elif (self.rotate_radian == LEFT): + point_for_return = self.start_point + Point(-relative_point_transfer.x, + - relative_point_transfer.y) + elif (self.rotate_radian == DOWN): + point_for_return = self.start_point + Point(relative_point_transfer.y, + -relative_point_transfer.x) + else: + raise Exception("Wrong relative position!") + self.point_list_for_return.append(point_for_return) + else: + self.point_list_for_return = None if (type(relative_end_point) != type(None)): relative_end_point_transfer = relative_end_point if (self.rotate_radian == RIGHT): @@ -194,6 +235,12 @@ def draw(self,cell): def get_start_point(self): return self.start_point_for_return + def get_point_list(self): + if self.point_list_for_return is None: + raise Exception("You did not define a relative point list for your component!") + else: + return self.point_list_for_return + def get_end_point(self): if (type(self.end_point_for_return) == type(None)): raise Exception("You did not define a relative end point for your component!")