@@ -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 }
0 commit comments