-
Notifications
You must be signed in to change notification settings - Fork 1
/
PathToCPW.lym
113 lines (91 loc) · 4.71 KB
/
PathToCPW.lym
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?xml version="1.0" encoding="utf-8"?>
<klayout-macro>
<description/>
<version/>
<category>pymacros</category>
<prolog/>
<epilog/>
<doc/>
<autorun>false</autorun>
<autorun-early>false</autorun-early>
<shortcut/>
<show-in-menu>false</show-in-menu>
<group-name/>
<menu-path/>
<interpreter>python</interpreter>
<dsl-interpreter-name/>
<text># Usage: Draw a path, and select it. Then go to Edit->Selection->Convert To Pcell.
# Select PathToCPW. Once the PCell is created, double-click it to change parameters if needed.
import pya
import math
class PathToCPW(pya.PCellDeclarationHelper):
"""
The PCell declaration for PathToCPW
"""
def __init__(self):
# Important: initialize the super class
super(PathToCPW, self).__init__()
# declare the parameters
#self.param("l", self.TypeLayer, "Layer", default = pya.LayerInfo(1, 0))
self.param("p", self.TypeLayer, "OUTLINE Layer", default = pya.LayerInfo(0, 2))
self.param("k", self.TypeLayer, "KEEPOUT Layer", default = pya.LayerInfo(0, 1))
self.param("c", self.TypeLayer, "IMAGE Layer", default = pya.LayerInfo(1, 0))
self.param("s", self.TypeShape, "", default = pya.DPath.new()) # Use "D-type" shapes
self.param("name", self.TypeString,"CPW name", default='PathToCPW')
# parameters in um shapes_in_IMAGE_layer_region)
self.param("cr", self.TypeDouble, "center conductor radius", default = 50)
self.param("cw", self.TypeDouble, "c.c width", default = 10)
self.param("gw", self.TypeDouble, "gap width", default = 6)
self.param("kw", self.TypeDouble, "keepout width", default = 6)
self.param("n", self.TypeInt, "Number of points per 360 degree", default = 360)
def display_text_impl(self):
# Provide a descriptive text for the cell
#return "CPWfromPath(CC width=" + str(self.cw) + ",gap width=" + ('%.3f' % self.gw) + ")"
cc_dpath = self.s.dup()
cc_dpath.width = self.cw
cc_dpath_rounded = cc_dpath.round_corners(self.cr, self.n, 0.001/2.0)
length = cc_dpath_rounded.length()
return self.name + '_' + f'{length:.3f}um'
def coerce_parameters_impl(self):
# We employ coerce_parameters_impl to decide whether the handle or the
# numeric parameter has changed (by comparing against the effective
# radius ru) and set ru to the effective radius. We also update the
# numerical value or the shape, depending on which one has not changed.
pass
def can_create_from_shape_impl(self):
# Implement the "Create PCell from shape" protocol: we can use any shape which
# has a finite bounding box
#return self.shape.is_box() or self.shape.is_polygon() or self.shape.is_path()
return self.shape.is_path()
def parameters_from_shape_impl(self):
# Implement the "Create PCell from shape" protocol: we set r and l from the shape's
# bounding box width and layer
# self.tmp = self.shape.bbox().width() * self.layout.dbu / 2
# self.l = self.layout.get_info(self.layer)
self.s = self.shape.dpath # read selected path obj. dpath in um unit
def transformation_from_shape_impl(self):
# Implement the "Create PCell from shape" protocol: we use the center of the shape's
# bounding box to determine the transformation
return pya.Trans()
def produce_impl(self):
# create three paths based on parameter of selected path
cc_dpath = self.s.dup()
gap_dpath = self.s.dup()
keepout_dpath = self.s.dup()
# set width of each path
cc_dpath.width = self.cw
gap_dpath.width = cc_dpath.width + self.gw * 2.0
keepout_dpath.width = gap_dpath.width + self.kw * 2.0
# round path
cc_dpath_rounded = cc_dpath.round_corners(self.cr, self.n, self.layout.dbu/2.0)
gap_dpath_rounded = gap_dpath.round_corners(self.cr, self.n, self.layout.dbu/2.0)
keepout_dpath_rounded = keepout_dpath.round_corners(self.cr, self.n, self.layout.dbu/2.0)
# turn path to region to do boolean operation
cc_region = pya.Region.new(pya.Path.new(cc_dpath_rounded.to_itype(self.layout.dbu))) # to_itype method to translate the floating-point coordinate path in micron units to an integer-coordinate path in database units.
gap_region = pya.Region.new(pya.Path.new(gap_dpath_rounded.to_itype(self.layout.dbu)))
keepout_region = pya.Region.new(pya.Path.new(keepout_dpath_rounded.to_itype(self.layout.dbu)))
# create shape
#self.cell.shapes(self.p_layer).insert(pya.Path.new(cc_dpath.to_itype(self.layout.dbu)))
self.cell.shapes(self.c_layer).insert(gap_region - cc_region)
self.cell.shapes(self.k_layer).insert(keepout_region)</text>
</klayout-macro>