From 531071765ff8b27228134be69373c31b2dbc7962 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Wed, 18 Sep 2024 19:11:04 +0200 Subject: [PATCH] Fixed issue #1860 (problem with undo after delete layer) --- src/db/db/dbLayoutLayers.cc | 10 +++++++- src/db/unit_tests/dbLayoutTests.cc | 39 ++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/db/db/dbLayoutLayers.cc b/src/db/db/dbLayoutLayers.cc index c4c5eef1e9..d321da9138 100644 --- a/src/db/db/dbLayoutLayers.cc +++ b/src/db/db/dbLayoutLayers.cc @@ -251,7 +251,7 @@ LayoutLayers::do_insert_layer (unsigned int index, bool special) if (index >= layers ()) { // add layer to the end of the list. - // add as may freelist entries as required. + // add as many freelist entries as required. while (index > layers ()) { m_free_indices.push_back (layers ()); m_layer_states.push_back (Free); @@ -262,6 +262,14 @@ LayoutLayers::do_insert_layer (unsigned int index, bool special) tl_assert (m_layer_states [index] == Free); m_layer_states [index] = special ? Special : Normal; + + // remove from the list of free indexes (issue #1860) + for (auto i = m_free_indices.begin (); i != m_free_indices.end (); ++i) { + if (*i == index) { + m_free_indices.erase (i); + break; + } + } } diff --git a/src/db/unit_tests/dbLayoutTests.cc b/src/db/unit_tests/dbLayoutTests.cc index d20db9187c..6bd1454785 100644 --- a/src/db/unit_tests/dbLayoutTests.cc +++ b/src/db/unit_tests/dbLayoutTests.cc @@ -871,3 +871,42 @@ TEST(11_FindPath) std::string d = tl::join (path.begin (), path.end (), ";"); EXPECT_EQ (d, "cell_index=1 r90 *1 0,0;cell_index=2 r0 *1 100,200"); } + +// issue #1860 +TEST(100_UndoOfDeleteLayer) +{ + db::Manager m; + db::Layout l (&m); + db::Cell &top = l.cell (l.add_cell ("TOP")); + + unsigned int li = 0, li2 = 0; + + { + db::Transaction t (&m, "insert_layer"); + li = l.insert_layer (db::LayerProperties (1, 0)); + } + + EXPECT_EQ (l.is_valid_layer (li), true); + + { + db::Transaction t (&m, "remove_layer"); + l.delete_layer (li); + } + + EXPECT_EQ (l.is_valid_layer (li), false); + + m.undo (); + + EXPECT_EQ (l.is_valid_layer (li), true); + EXPECT_EQ (l.get_properties (li).to_string (), "1/0"); + + { + db::Transaction t (&m, "remove_layer"); + li2 = l.insert_layer (db::LayerProperties (2, 0)); + } + + EXPECT_EQ (l.is_valid_layer (li2), true); + EXPECT_NE (li, li2); + EXPECT_EQ (l.get_properties (li).to_string (), "1/0"); + EXPECT_EQ (l.get_properties (li2).to_string (), "2/0"); +}