[consider merging] Fixing two problems with layer mapping

1. Mapping "[*/*] 100/0:0/0" (for example) created 0/0
   two times when the input contains 100/0 and 0/0. Now
   it is a single layer only
2. The mapping table generated from strings now uses
   layer indexes from a range that should not collide
   with existing layer indexes.
This commit is contained in:
Matthias Koefferlein 2025-02-25 21:16:49 +01:00
parent 094fccce74
commit c437d75a01
3 changed files with 48 additions and 4 deletions

View File

@ -236,7 +236,19 @@ LayerMap::substitute_placeholder (const db::LayerProperties &p, const std::set<u
lp_new.layer = db::ld_combine (p.layer, lp_ph.layer);
lp_new.datatype = db::ld_combine (p.datatype, lp_ph.datatype);
unsigned int l_new = layout.insert_layer (lp_new);
// if the placeholder-extrapolated layer is a target layer, go to that one
unsigned int l_new = std::numeric_limits<unsigned int>::max ();
for (std::map<unsigned int, db::LayerProperties>::const_iterator t = m_target_layers.begin (); t != m_target_layers.end (); ++t) {
if (t->second.log_equal (lp_new) && layout.is_valid_layer (t->first)) {
l_new = t->first;
break;
}
}
if (l_new == std::numeric_limits<unsigned int>::max ()) {
l_new = layout.insert_layer (lp_new);
}
map (p, l_new, lp_new);
res.insert (l_new);
@ -929,7 +941,10 @@ db::LayerMap
LayerMap::from_string_file_format (const std::string &s)
{
db::LayerMap lm;
unsigned int l = 0;
// NOTE: this should be outside the normal layer index range of a Layout and below
// the space reserved for placeholders. With numbers like this we don't get messed
// up with existing layers.
unsigned int l = std::numeric_limits<unsigned int>::max () / 2;
int lnr = 0;

View File

@ -577,3 +577,33 @@ TEST(8)
EXPECT_EQ (db::LayerMap::from_string_file_format (lm.to_string_file_format ()).to_string (), lm.to_string ());
}
// mapping of relative target to real target
TEST(9)
{
db::Layout ly;
db::LayerMap lm;
EXPECT_EQ (layers_to_string (ly), "");
unsigned int l0 = ly.insert_layer (db::LayerProperties (0, 0));
unsigned int l101 = ly.insert_layer (db::LayerProperties (101, 0));
unsigned int n = std::numeric_limits<unsigned int>::max () / 2;
lm.map_expr ("*/* : */*", n++);
lm.map_expr ("100/0 : 0/0", n++);
lm.prepare (ly);
std::pair<bool, unsigned int> p;
p = lm.first_logical (db::LayerProperties (100, 0), ly);
EXPECT_EQ (p.first, true);
EXPECT_EQ (p.second, l0);
p = lm.first_logical (db::LayerProperties (101, 0), ly);
EXPECT_EQ (p.first, true);
EXPECT_EQ (p.second, l101);
// maps to the target 0/0
p = lm.first_logical (db::LayerProperties (0, 0), ly);
EXPECT_EQ (p.first, true);
EXPECT_EQ (p.second, l0);
}

View File

@ -417,9 +417,8 @@ TEST(3_AdvancedMapping)
}
EXPECT_EQ (lm_read.to_string_file_format (),
"1/10 : 1/0\n"
"1/0,10 : 1/0\n"
"2/0-1 : 2/0\n"
"1/0 : 1/0\n"
"1/1 : 1/1\n"
"1/20 : 1/1020\n"
"1/21 : 1/1021\n"