Skip to content

Commit 605fa44

Browse files
author
Matthias Koefferlein
committed
Another refinement for DSS bug fix.
1 parent 70af6bd commit 605fa44

File tree

4 files changed

+63
-12
lines changed

4 files changed

+63
-12
lines changed

src/db/db/dbDeepShapeStore.cc

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,7 @@ DeepShapeStore::cell_mapping_to_original (unsigned int layout_index, db::Layout
12441244
std::map<db::cell_index_type, db::HierarchyBuilder::CellMapKey>::const_iterator icm = cm_skipped_variants.find (var_org);
12451245
if (icm != cm_skipped_variants.end ()) {
12461246

1247-
// create the variant clone in the original layout too and delete this cell
1247+
// create the variant clone in the original layout too
12481248
VariantsCollectorBase::copy_shapes (*into_layout, np->second, icm->second.original_cell);
12491249
new_variants.push_back (std::make_pair (np->second, icm->second.original_cell));
12501250

@@ -1269,22 +1269,32 @@ DeepShapeStore::cell_mapping_to_original (unsigned int layout_index, db::Layout
12691269

12701270
// copy cell instances for the new variants
12711271

1272-
// collect the cells that are handled during cell mapping -
1273-
// we do not need to take care of them when creating variants,
1274-
// but there may be others inside "into_layout" which are
1275-
// not present in the DSS and for which we need to copy the
1276-
// instances.
1277-
std::vector<db::cell_index_type> mapped = cm->second.target_cells ();
1278-
std::sort (mapped.begin (), mapped.end ());
1272+
std::map<db::cell_index_type, db::cell_index_type> variant_to_org;
1273+
for (auto vv = new_variants.begin (); vv != new_variants.end (); ++vv) {
1274+
variant_to_org.insert (std::make_pair (vv->first, vv->second));
1275+
}
12791276

12801277
// Copy the variant instances - but only those for cells which are not handled by the cell mapping object.
12811278
for (auto vv = new_variants.begin (); vv != new_variants.end (); ++vv) {
12821279

1283-
const db::Cell &from = into_layout->cell (vv->second);
1284-
db::Cell &to = into_layout->cell (vv->first);
1280+
const db::Cell &from = into_layout->cell (vv->second); // original
1281+
db::Cell &to = into_layout->cell (vv->first); // variant
1282+
1283+
// Collect and copy the cells which are not mapped already.
1284+
// Skip variant original cells if their variants are included.
1285+
std::set<db::cell_index_type> dont_copy;
1286+
1287+
for (auto c = to.begin_child_cells (); ! c.at_end (); ++c) {
1288+
auto v2o = variant_to_org.find (*c);
1289+
if (v2o != variant_to_org.end ()) {
1290+
dont_copy.insert (v2o->second);
1291+
} else {
1292+
dont_copy.insert (*c);
1293+
}
1294+
}
1295+
12851296
for (db::Cell::const_iterator i = from.begin (); ! i.at_end (); ++i) {
1286-
auto m = std::lower_bound (mapped.begin (), mapped.end (), i->cell_index ());
1287-
if (m == mapped.end () || *m != i->cell_index ()) {
1297+
if (dont_copy.find (i->cell_index ()) == dont_copy.end ()) {
12881298
to.insert (*i);
12891299
}
12901300
}

src/db/unit_tests/dbDeepShapeStoreTests.cc

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,44 @@ TEST(7_RestoreWithCellSelection2)
341341
db::compare_layouts (_this, ly, tl::testdata () + "/algo/dss_bug2_au.gds");
342342
}
343343

344+
TEST(8_RestoreWithCellSelection3)
345+
{
346+
db::Layout ly;
347+
348+
{
349+
std::string fn (tl::testdata ());
350+
fn += "/algo/dss_bug3.gds";
351+
tl::InputStream stream (fn);
352+
db::Reader reader (stream);
353+
reader.read (ly);
354+
}
355+
356+
unsigned int l2 = ly.get_layer (db::LayerProperties (2, 0));
357+
358+
db::Cell &top_cell = ly.cell (*ly.begin_top_down ());
359+
360+
db::RecursiveShapeIterator in_it (ly, top_cell, l2);
361+
db::RecursiveShapeIterator other_it (ly, top_cell, l2);
362+
363+
std::set<db::cell_index_type> us;
364+
us.insert (ly.cell_by_name ("X").second);
365+
us.insert (ly.cell_by_name ("C3").second);
366+
in_it.unselect_cells (us);
367+
368+
std::set<db::cell_index_type> us2;
369+
us2.insert (top_cell.cell_index ());
370+
other_it.unselect_cells (us2);
371+
other_it.select_cells (us);
372+
373+
db::DeepShapeStore dss;
374+
375+
db::Region in_region (in_it, dss);
376+
db::Region other_region (other_it, dss);
377+
in_region += other_region;
378+
379+
ly.clear_layer (l2);
380+
in_region.insert_into (&ly, top_cell.cell_index (), l2);
381+
382+
db::compare_layouts (_this, ly, tl::testdata () + "/algo/dss_bug3_au.gds");
383+
}
384+

testdata/algo/dss_bug3.gds

926 Bytes
Binary file not shown.

testdata/algo/dss_bug3_au.gds

1 KB
Binary file not shown.

0 commit comments

Comments
 (0)