Skip to content

Commit

Permalink
Merge branch 'master' of github.com:KLayout/klayout
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koefferlein committed Sep 20, 2024
2 parents 43235a1 + 304df2f commit b194d50
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/db/db/dbLayoutLayers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
}

}

Expand Down
39 changes: 39 additions & 0 deletions src/db/unit_tests/dbLayoutTests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

0 comments on commit b194d50

Please sign in to comment.