From 605fa44ca67c217ddf308dd839145e97f587e1eb Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Wed, 5 Mar 2025 10:26:45 +0100 Subject: [PATCH] Another refinement for DSS bug fix. --- src/db/db/dbDeepShapeStore.cc | 34 +++++++++++------ src/db/unit_tests/dbDeepShapeStoreTests.cc | 41 +++++++++++++++++++++ testdata/algo/dss_bug3.gds | Bin 0 -> 926 bytes testdata/algo/dss_bug3_au.gds | Bin 0 -> 1026 bytes 4 files changed, 63 insertions(+), 12 deletions(-) create mode 100644 testdata/algo/dss_bug3.gds create mode 100644 testdata/algo/dss_bug3_au.gds diff --git a/src/db/db/dbDeepShapeStore.cc b/src/db/db/dbDeepShapeStore.cc index 9a2cd9599..687008b9c 100644 --- a/src/db/db/dbDeepShapeStore.cc +++ b/src/db/db/dbDeepShapeStore.cc @@ -1244,7 +1244,7 @@ DeepShapeStore::cell_mapping_to_original (unsigned int layout_index, db::Layout std::map::const_iterator icm = cm_skipped_variants.find (var_org); if (icm != cm_skipped_variants.end ()) { - // create the variant clone in the original layout too and delete this cell + // create the variant clone in the original layout too VariantsCollectorBase::copy_shapes (*into_layout, np->second, icm->second.original_cell); new_variants.push_back (std::make_pair (np->second, icm->second.original_cell)); @@ -1269,22 +1269,32 @@ DeepShapeStore::cell_mapping_to_original (unsigned int layout_index, db::Layout // copy cell instances for the new variants - // collect the cells that are handled during cell mapping - - // we do not need to take care of them when creating variants, - // but there may be others inside "into_layout" which are - // not present in the DSS and for which we need to copy the - // instances. - std::vector mapped = cm->second.target_cells (); - std::sort (mapped.begin (), mapped.end ()); + std::map variant_to_org; + for (auto vv = new_variants.begin (); vv != new_variants.end (); ++vv) { + variant_to_org.insert (std::make_pair (vv->first, vv->second)); + } // Copy the variant instances - but only those for cells which are not handled by the cell mapping object. for (auto vv = new_variants.begin (); vv != new_variants.end (); ++vv) { - const db::Cell &from = into_layout->cell (vv->second); - db::Cell &to = into_layout->cell (vv->first); + const db::Cell &from = into_layout->cell (vv->second); // original + db::Cell &to = into_layout->cell (vv->first); // variant + + // Collect and copy the cells which are not mapped already. + // Skip variant original cells if their variants are included. + std::set dont_copy; + + for (auto c = to.begin_child_cells (); ! c.at_end (); ++c) { + auto v2o = variant_to_org.find (*c); + if (v2o != variant_to_org.end ()) { + dont_copy.insert (v2o->second); + } else { + dont_copy.insert (*c); + } + } + for (db::Cell::const_iterator i = from.begin (); ! i.at_end (); ++i) { - auto m = std::lower_bound (mapped.begin (), mapped.end (), i->cell_index ()); - if (m == mapped.end () || *m != i->cell_index ()) { + if (dont_copy.find (i->cell_index ()) == dont_copy.end ()) { to.insert (*i); } } diff --git a/src/db/unit_tests/dbDeepShapeStoreTests.cc b/src/db/unit_tests/dbDeepShapeStoreTests.cc index 4a01e194c..d14be57fe 100644 --- a/src/db/unit_tests/dbDeepShapeStoreTests.cc +++ b/src/db/unit_tests/dbDeepShapeStoreTests.cc @@ -341,3 +341,44 @@ TEST(7_RestoreWithCellSelection2) db::compare_layouts (_this, ly, tl::testdata () + "/algo/dss_bug2_au.gds"); } +TEST(8_RestoreWithCellSelection3) +{ + db::Layout ly; + + { + std::string fn (tl::testdata ()); + fn += "/algo/dss_bug3.gds"; + tl::InputStream stream (fn); + db::Reader reader (stream); + reader.read (ly); + } + + unsigned int l2 = ly.get_layer (db::LayerProperties (2, 0)); + + db::Cell &top_cell = ly.cell (*ly.begin_top_down ()); + + db::RecursiveShapeIterator in_it (ly, top_cell, l2); + db::RecursiveShapeIterator other_it (ly, top_cell, l2); + + std::set us; + us.insert (ly.cell_by_name ("X").second); + us.insert (ly.cell_by_name ("C3").second); + in_it.unselect_cells (us); + + std::set us2; + us2.insert (top_cell.cell_index ()); + other_it.unselect_cells (us2); + other_it.select_cells (us); + + db::DeepShapeStore dss; + + db::Region in_region (in_it, dss); + db::Region other_region (other_it, dss); + in_region += other_region; + + ly.clear_layer (l2); + in_region.insert_into (&ly, top_cell.cell_index (), l2); + + db::compare_layouts (_this, ly, tl::testdata () + "/algo/dss_bug3_au.gds"); +} + diff --git a/testdata/algo/dss_bug3.gds b/testdata/algo/dss_bug3.gds new file mode 100644 index 0000000000000000000000000000000000000000..39c289ac5c4cd031cad63edc79dd6e2f9bbcf6d5 GIT binary patch literal 926 zcmbW0KQ9D97{;HO*_oST$>Aa)TdO2;rw|H>qaY*{TO74q)S^&{LPH^#BV0w5AE6vVU2WTq2x^}s= z{rvF0yz#Vfe|Hcf(8c?VG3$%)EMUeY1kAVuFyBy76rC{69075}2s38$j_@V`uZGer zZFr;1GU@W!DVIwiXeeeoWW4-hd~T{s4(l59n71EAgC3wR7}puIdB@7STK~~iUT>GK zr1iF7W(Di>1KoKf-IsGfUIFzF;0I#|(lgp+XQ)>|H|a#41uiBc^l3tWj(a)In9Y+F zySx8~YAyR^j%h)jg-T_RsC2B~Qsv4w-AcM%MX5C=+})$rk@zN3wV&K{`nH+Wnyj#U U?Adv~XZ)8Bj2?@dFJC+lpVU2ctpET3 literal 0 HcmV?d00001 diff --git a/testdata/algo/dss_bug3_au.gds b/testdata/algo/dss_bug3_au.gds new file mode 100644 index 0000000000000000000000000000000000000000..45c7459465a4b3dc0aba46c97a8eeda0cbcd074c GIT binary patch literal 1026 zcmcIju}Z^G6g}@Hd40xKs@6p^7AHYc2hl;WcCaWY*r7U0aTW(Bad6Q=#I+7?{(ysD zAby3ro0DVXxk;l9r8Wo#ZqDPrX^|=G0h9Yod(^|{eYlfknh{PrD|`w;*&*W*<8=u0)V6W$@EA4Uj2zEPsUwKE_1?U7GrmZdj)im6cL=b zW8t+Ql%4*5p6RgHcG9a%y*92>=MC^GbS8^26ZQJBUO7i&6zgkt{K-zUI8w2w^3LQ< zwF}8Q#WYXMqnPKhwYx{netgn7sbX@QsA?;zknGSGs<_C`jo