From c437d75a014f9d18830c944175092802fc3e8489 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Tue, 25 Feb 2025 21:16:49 +0100 Subject: [PATCH] [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. --- src/db/db/dbStreamLayers.cc | 19 ++++++++++-- src/db/unit_tests/dbStreamLayerTests.cc | 30 +++++++++++++++++++ .../gds2/unit_tests/dbGDS2ReaderTests.cc | 3 +- 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/db/db/dbStreamLayers.cc b/src/db/db/dbStreamLayers.cc index c8b1b0f92..c4038549b 100644 --- a/src/db/db/dbStreamLayers.cc +++ b/src/db/db/dbStreamLayers.cc @@ -236,7 +236,19 @@ LayerMap::substitute_placeholder (const db::LayerProperties &p, const std::set::max (); + for (std::map::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::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::max () / 2; int lnr = 0; diff --git a/src/db/unit_tests/dbStreamLayerTests.cc b/src/db/unit_tests/dbStreamLayerTests.cc index 3e3287aee..fc4da9fce 100644 --- a/src/db/unit_tests/dbStreamLayerTests.cc +++ b/src/db/unit_tests/dbStreamLayerTests.cc @@ -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::max () / 2; + lm.map_expr ("*/* : */*", n++); + lm.map_expr ("100/0 : 0/0", n++); + + lm.prepare (ly); + + std::pair 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); +} diff --git a/src/plugins/streamers/gds2/unit_tests/dbGDS2ReaderTests.cc b/src/plugins/streamers/gds2/unit_tests/dbGDS2ReaderTests.cc index 5552c8d3b..d65f9f3a4 100644 --- a/src/plugins/streamers/gds2/unit_tests/dbGDS2ReaderTests.cc +++ b/src/plugins/streamers/gds2/unit_tests/dbGDS2ReaderTests.cc @@ -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"