Bugfix: PCellDeclarationHelper was not present after 'import * from pya', more modern version of PCell samples

This commit is contained in:
Matthias Koefferlein 2023-09-10 23:41:01 +02:00
parent 109696a1e0
commit 9bb8b4e548
4 changed files with 13 additions and 16 deletions

View File

@ -563,6 +563,7 @@ for k in dir(pya.PCellParameterDeclaration):
# Inject the PCellDeclarationHelper into pya module for consistency:
setattr(pya, "PCellDeclarationHelper", _PCellDeclarationHelper)
pya.__all__.append("PCellDeclarationHelper")
</text>
</klayout-macro>

View File

@ -38,7 +38,7 @@ module MyLib
super
# declare the parameters
param(:l, TypeLayer, "Layer", :default =&gt; LayerInfo::new(1, 0))
param(:l, TypeLayer, "Layer")
param(:s, TypeShape, "", :default =&gt; DPoint::new(0, 0))
param(:r, TypeDouble, "Radius", :default =&gt; 0.1)
param(:n, TypeInt, "Number of points", :default =&gt; 64)
@ -100,18 +100,14 @@ module MyLib
# This is the main part of the implementation: create the layout
# fetch the parameters
ru_dbu = ru / layout.dbu
# compute the circle
pts = []
da = Math::PI * 2 / n
n.times do |i|
pts.push(Point.from_dpoint(DPoint.new(ru_dbu * Math::cos(i * da), ru_dbu * Math::sin(i * da))))
pts = n.times.collect do |i|
DPoint.new(ru * Math::cos(i * da), ru * Math::sin(i * da))
end
# create the shape
cell.shapes(l_layer).insert(Polygon.new(pts))
cell.shapes(l_layer).insert(DPolygon.new(pts))
end

View File

@ -32,7 +32,7 @@ class Circle(pya.PCellDeclarationHelper):
super(Circle, self).__init__()
# declare the parameters
self.param("l", self.TypeLayer, "Layer", default = pya.LayerInfo(1, 0))
self.param("l", self.TypeLayer, "Layer")
self.param("s", self.TypeShape, "", default = pya.DPoint(0, 0))
self.param("r", self.TypeDouble, "Radius", default = 0.1)
self.param("n", self.TypeInt, "Number of points", default = 64)
@ -88,17 +88,12 @@ class Circle(pya.PCellDeclarationHelper):
# This is the main part of the implementation: create the layout
# fetch the parameters
ru_dbu = self.ru / self.layout.dbu
# compute the circle
pts = []
da = math.pi * 2 / self.n
for i in range(0, self.n):
pts.append(pya.Point.from_dpoint(pya.DPoint(ru_dbu * math.cos(i * da), ru_dbu * math.sin(i * da))))
pts = [ pya.DPoint(self.ru * math.cos(i * da), self.ru * math.sin(i * da)) for i in range(0, self.n) ]
# create the shape
self.cell.shapes(self.l_layer).insert(pya.Polygon(pts))
self.cell.shapes(self.l_layer).insert(pya.DPolygon(pts))
class MyLib(pya.Library):

View File

@ -163,6 +163,11 @@ def nh(h):
class DBPCellTests(unittest.TestCase):
def test_0(self):
# PCellDeclarationHelper is inside "pya.__all__"
self.assertEqual("PCellDeclarationHelper" in pya.__all__, True)
def test_1(self):
# instantiate and register the library