Enhancement: using PCell parameter 'name' won't break PCell's cell_name_impl default implementation

This commit is contained in:
Matthias Koefferlein 2026-07-11 22:32:42 +02:00
parent b2afb55fe3
commit 1cd9cbc8ba
4 changed files with 68 additions and 2 deletions

View File

@ -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

View File

@ -352,7 +352,7 @@ class _PCellDeclarationHelperMixin:
"""
default implementation
"""
return self.name()
return super(_PCellDeclarationHelperMixin, self).name()
def coerce_parameters_impl(self):
"""

View File

@ -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)

View File

@ -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