From 1cd9cbc8ba02ab6a491d9da128b3e9c3eb2ba874 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sat, 11 Jul 2026 22:32:42 +0200 Subject: [PATCH] Enhancement: using PCell parameter 'name' won't break PCell's cell_name_impl default implementation --- .../pcell_declaration_helper.lym | 7 +++- .../klayout/db/pcell_declaration_helper.py | 2 +- testdata/python/dbPCells.py | 27 +++++++++++++++ testdata/ruby/dbPCells.rb | 34 +++++++++++++++++++ 4 files changed, 68 insertions(+), 2 deletions(-) diff --git a/src/db/db/built-in-macros/pcell_declaration_helper.lym b/src/db/db/built-in-macros/pcell_declaration_helper.lym index 774a33028..4e57ef672 100644 --- a/src/db/db/built-in-macros/pcell_declaration_helper.lym +++ b/src/db/db/built-in-macros/pcell_declaration_helper.lym @@ -289,6 +289,11 @@ module RBA alias_method :_layout_base, :layout end + # makes PCellDeclaration's "name" method available + if ! self.method_defined?(:_name_base) + alias_method :_name_base, :name + end + # import the Type... constants from PCellParameterDeclaration PCellParameterDeclaration.constants.each do |c| if !const_defined?(c) @@ -595,7 +600,7 @@ module RBA # default implementation def cell_name_impl - self.name + _name_base() end # default implementation diff --git a/src/pymod/distutils_src/klayout/db/pcell_declaration_helper.py b/src/pymod/distutils_src/klayout/db/pcell_declaration_helper.py index 6a89fc446..8edc5a808 100644 --- a/src/pymod/distutils_src/klayout/db/pcell_declaration_helper.py +++ b/src/pymod/distutils_src/klayout/db/pcell_declaration_helper.py @@ -352,7 +352,7 @@ class _PCellDeclarationHelperMixin: """ default implementation """ - return self.name() + return super(_PCellDeclarationHelperMixin, self).name() def coerce_parameters_impl(self): """ diff --git a/testdata/python/dbPCells.py b/testdata/python/dbPCells.py index 0384e3253..885ad1e29 100644 --- a/testdata/python/dbPCells.py +++ b/testdata/python/dbPCells.py @@ -134,6 +134,16 @@ if "PCellDeclarationHelper" in pya.__dict__: self.width = self.shape.box.width() * self.layout.dbu self.height = self.shape.box.height() * self.layout.dbu + # A PCell with a parameter named "name" + class PCellWithNameParameter(pya.PCellDeclarationHelper): + + def __init__(self): + super(PCellWithNameParameter, self).__init__() + self.param("name", self.TypeString, "Name", default = "") + + def produce_impl(self): + self.cell.shapes(self.layout.layer(1, 0)).insert(pya.Text(self.name, pya.Trans())) + class PCellTestLib2(pya.Library): def __init__(self): @@ -143,6 +153,7 @@ if "PCellDeclarationHelper" in pya.__dict__: # create the PCell declarations self.layout().register_pcell("Box2", BoxPCell2()) + self.layout().register_pcell("PCellWithNameParameter", PCellWithNameParameter()) # register us with the name "PCellTestLib2" self.register("PCellTestLib2") @@ -588,6 +599,22 @@ class DBPCellTests(unittest.TestCase): self.assertEqual(c2.display_title(), "PCellTestLib3.RecursivePCell(L=1/0,E=(0,0;20,0),LVL=4") self.assertEqual(str(c1.dbbox()), "(0,0;20,5.774)") + # PCell with "name" parameter + def test_15(self): + + # instantiate and register the library + tl = PCellTestLib2() + + lib = pya.Library.library_by_name("PCellTestLib2") + pcell_decl_id = lib.layout().pcell_id("PCellWithNameParameter") + + param = { "name": "xyz" } + pcell_var_id = lib.layout().add_pcell_variant(pcell_decl_id, param) + + self.assertEqual(lib.layout().cell(pcell_var_id).name, "PCellWithNameParameter") + self.assertEqual(lib.layout().begin_shapes(pcell_var_id, lib.layout().layer(1, 0)).shape().to_s(), "text ('xyz',r0 0,0)") + + # run unit tests if __name__ == '__main__': suite = unittest.TestLoader().loadTestsFromTestCase(DBPCellTests) diff --git a/testdata/ruby/dbPCells.rb b/testdata/ruby/dbPCells.rb index 864b82ead..82e6f5624 100644 --- a/testdata/ruby/dbPCells.rb +++ b/testdata/ruby/dbPCells.rb @@ -173,6 +173,20 @@ if RBA.constants.member?(:PCellDeclarationHelper) end + # A PCell with a parameter named "name" + class PCellWithNameParameter < RBA::PCellDeclarationHelper + + def initialize + super() + param(:name, TypeString, "Name", :default => "") + end + + def produce_impl + cell.shapes(layout.layer(1, 0)).insert(RBA::Text::new(name, RBA::Trans::new)) + end + + end + class PCellTestLib2 < RBA::Library def initialize @@ -182,6 +196,7 @@ if RBA.constants.member?(:PCellDeclarationHelper) # create the PCell declarations layout.register_pcell("Box2", BoxPCell2::new) + layout.register_pcell("PCellWithNameParameter", PCellWithNameParameter::new) # register us with the name "MyLib" self.register("PCellTestLib2") @@ -1012,6 +1027,25 @@ class DBPCell_TestClass < TestBase end + # PCell with "name" parameter + def test_15 + + # instantiate and register the library + tl = PCellTestLib2::new + + lib = RBA::Library::library_by_name("PCellTestLib2") + pcell_decl_id = lib.layout.pcell_id("PCellWithNameParameter") + + param = { "name" => "xyz" } + pcell_var_id = lib.layout.add_pcell_variant(pcell_decl_id, param) + + assert_equal(lib.layout.cell(pcell_var_id).name, "PCellWithNameParameter") + assert_equal(first_shape(lib.layout.begin_shapes(pcell_var_id, lib.layout.layer(1, 0))).to_s, "text ('xyz',r0 0,0)") + + tl._destroy + + end + end class DBPCellParameterStates_TestClass < TestBase