From 5596019eceedba230d03d3903593fd96177131c2 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Fri, 1 May 2026 00:03:11 +0200 Subject: [PATCH] Fixing issue #2344 (preserving properties on PCell instantiation with instances) --- src/db/db/dbLibraryProxy.cc | 6 ++- src/db/unit_tests/dbLibrariesTests.cc | 62 +++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/db/db/dbLibraryProxy.cc b/src/db/db/dbLibraryProxy.cc index 84317d341..b1c24f2bb 100644 --- a/src/db/db/dbLibraryProxy.cc +++ b/src/db/db/dbLibraryProxy.cc @@ -244,7 +244,11 @@ LibraryProxy::update (db::ImportLayerMapping *layer_mapping) inst.transform_into (db::ICplxTrans (lib->layout ().dbu () / layout ()->dbu ())); - insert (inst); + if (i->has_prop_id ()) { + insert (db::CellInstArrayWithProperties (inst, i->prop_id ())); + } else { + insert (inst); + } } } diff --git a/src/db/unit_tests/dbLibrariesTests.cc b/src/db/unit_tests/dbLibrariesTests.cc index 70f1fba5c..e3bb44f8b 100644 --- a/src/db/unit_tests/dbLibrariesTests.cc +++ b/src/db/unit_tests/dbLibrariesTests.cc @@ -34,6 +34,7 @@ #include "dbTestSupport.h" #include "dbFileBasedLibrary.h" #include "dbColdProxy.h" +#include "dbTextWriter.h" #include "tlStream.h" #include "tlStaticObjects.h" #include "tlUnitTest.h" @@ -861,3 +862,64 @@ TEST(7_monsterlib) // but the layout did not change db::compare_layouts (_this, layout, tl::testsrc () + "/testdata/libman/design_au5.gds", db::NormalizationMode (db::NoNormalization | db::WithoutCellNames | db::AsPolygons)); } + +namespace { + +class PCellWithChildDeclaration : + public db::PCellDeclaration +{ + void produce (const db::Layout &layout, const std::vector & /*layer_ids*/, const db::pcell_parameters_type & /*parameters*/, db::Cell &cell) const + { + auto cid = const_cast (layout).add_cell ("CHILD"); + + db::PropertiesSet ps; + ps.insert ("id", tl::Variant ("my_id")); + + auto ps_id = db::properties_id (ps); + cell.insert (db::CellInstArrayWithProperties (db::CellInstArray (cid, db::Trans ()), ps_id)); + } +}; + +} + +static std::string l2s (const db::Layout &layout) +{ + tl::OutputStringStream os; + tl::OutputStream ostream (os); + db::TextWriter writer (ostream); + writer.write (layout); + return os.string (); +} + +// PCells with subcells with properties +TEST(8_issue2344) +{ + std::unique_ptr lib (new db::Library ()); + lib->set_name ("__PCellLibrary"); + lib->layout ().register_pcell ("PCell1", new PCellWithChildDeclaration ()); + db::LibraryManager::instance ().register_lib (lib.get ()); + + db::Layout ly; + std::pair pc = lib->layout ().pcell_by_name ("PCell1"); + tl_assert (pc.first); + + db::cell_index_type lib_cell = lib->layout ().get_pcell_variant_dict (pc.second, std::map ()); + ly.get_lib_proxy (lib.get (), lib_cell); + + EXPECT_EQ (l2s (ly), + "begin_lib 0.001\n" + "begin_cell {CHILD}\n" + "end_cell\n" + "begin_cell {PCell1}\n" + "set props {\n" + " {{id} {my_id}}\n" + "}\n" + "srefp $props {CHILD} 0 0 1 {0 0}\n" + "end_cell\n" + "end_lib\n" + ); + + db::LibraryManager::instance ().delete_lib (lib.release ()); + EXPECT (true); +} +