From 9bb8b4e5483bf434a22d00d0ce4ed7aa178ba6b6 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sun, 10 Sep 2023 23:41:01 +0200 Subject: [PATCH] Bugfix: PCellDeclarationHelper was not present after 'import * from pya', more modern version of PCell samples --- .../built-in-pymacros/pcell_declaration_helper.lym | 1 + src/lay/lay/macro_templates/pcell_sample.lym | 12 ++++-------- src/lay/lay/macro_templates/pcell_sample_python.lym | 11 +++-------- testdata/python/dbPCells.py | 5 +++++ 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/db/db/built-in-pymacros/pcell_declaration_helper.lym b/src/db/db/built-in-pymacros/pcell_declaration_helper.lym index 81ea44c44..24c889f31 100644 --- a/src/db/db/built-in-pymacros/pcell_declaration_helper.lym +++ b/src/db/db/built-in-pymacros/pcell_declaration_helper.lym @@ -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") diff --git a/src/lay/lay/macro_templates/pcell_sample.lym b/src/lay/lay/macro_templates/pcell_sample.lym index 5bd072566..358945d32 100644 --- a/src/lay/lay/macro_templates/pcell_sample.lym +++ b/src/lay/lay/macro_templates/pcell_sample.lym @@ -38,7 +38,7 @@ module MyLib super # declare the parameters - param(:l, TypeLayer, "Layer", :default => LayerInfo::new(1, 0)) + param(:l, TypeLayer, "Layer") param(:s, TypeShape, "", :default => DPoint::new(0, 0)) param(:r, TypeDouble, "Radius", :default => 0.1) param(:n, TypeInt, "Number of points", :default => 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 diff --git a/src/lay/lay/macro_templates/pcell_sample_python.lym b/src/lay/lay/macro_templates/pcell_sample_python.lym index 42f9e524d..f2a60bdbc 100644 --- a/src/lay/lay/macro_templates/pcell_sample_python.lym +++ b/src/lay/lay/macro_templates/pcell_sample_python.lym @@ -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): diff --git a/testdata/python/dbPCells.py b/testdata/python/dbPCells.py index 88f3f6f36..14ca10e5e 100644 --- a/testdata/python/dbPCells.py +++ b/testdata/python/dbPCells.py @@ -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