Skip to content

Commit

Permalink
Merge pull request #1842 from KLayout/bugfix/issue-1835
Browse files Browse the repository at this point in the history
Bugfix/issue 1835
  • Loading branch information
klayoutmatthias authored Sep 8, 2024
2 parents 445d8a4 + a4467cf commit b3fd515
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
30 changes: 27 additions & 3 deletions src/db/db/dbCommonReader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@


#include "dbCommonReader.h"
#include "dbColdProxy.h"
#include "dbStream.h"
#include "tlXMLParser.h"

Expand Down Expand Up @@ -475,7 +476,7 @@ CommonReaderBase::finish (db::Layout &layout)
}

if (name) {
// need to rename: add a new madding to m_layer_map_out and adjust the layout's layer properties
// need to rename: add a new mapping to m_layer_map_out and adjust the layout's layer properties
db::LayerProperties lpp = lp;
join_layer_names (lpp.name, *name);
layout.set_properties (*i, lpp);
Expand Down Expand Up @@ -580,9 +581,32 @@ CommonReader::read (db::Layout &layout, const db::LoadLayoutOptions &options)
}

// A cleanup may be necessary because of the following scenario: if library proxies contain subcells
// which are proxies itself, the proxy update may make them orphans (the proxies are regenerated).
// which are proxies themselves, the proxy update may make them orphans (the proxies are regenerated).
// The cleanup will removed these.
layout.cleanup ();

// Adressing issue #1835 (reading proxy-only GDS file renders empty layout) we do not delete
// the first (non-cold) proxy if there are only proxy top cells.
// We never clean up the top cell if there is a single one. This catches the case of having
// defunct proxies for top cells.

std::set<db::cell_index_type> keep;
if (layout.end_top_cells () - layout.begin_top_down () == 1) {
keep.insert (*layout.begin_top_down ());
} else {
for (auto c = layout.begin_top_down (); c != layout.end_top_cells (); ++c) {
const db::Cell *cptr = &layout.cell (*c);
if (cptr->is_proxy ()) {
if (! dynamic_cast <const db::ColdProxy *> (cptr) && keep.empty ()) {
keep.insert (*c);
}
} else {
keep.clear ();
break;
}
}
}

layout.cleanup (keep);

return layer_map_out ();
}
Expand Down
5 changes: 3 additions & 2 deletions src/layui/layui/layLayoutViewFunctions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1230,11 +1230,12 @@ LayoutViewFunctions::do_cm_paste (bool interactive)
void
LayoutViewFunctions::cm_new_cell ()
{
lay::CellView cv = view ()->cellview (view ()->active_cellview_index ());
if (! cv.is_valid ()) {
if (view ()->active_cellview_index () < 0) {
throw tl::Exception (tl::to_string (tr ("No layout present to add a cell to")));
}

lay::CellView cv = view ()->cellview (view ()->active_cellview_index ());

static double s_new_cell_window_size = 2.0;
static std::string s_new_cell_cell_name;

Expand Down
21 changes: 21 additions & 0 deletions src/plugins/streamers/gds2/unit_tests/dbGDS2ReaderTests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -704,3 +704,24 @@ TEST(5_issue893)
db::compare_layouts (_this, layout, fn_au, db::WriteGDS2, 1);
}

// PCell saved as top cell
TEST(6_issue1835)
{
db::Manager m (false);
db::Layout layout (&m);

db::LoadLayoutOptions options;

{
tl::InputStream file (tl::testdata () + "/gds/issue_1835.gds");
db::Reader reader (file);
reader.read (layout, options);
}

tl_assert (layout.begin_top_down () != layout.end_top_cells ());
layout.convert_cell_to_static (*layout.begin_top_down ());

std::string fn_au (tl::testdata () + "/gds/issue_1835_au.gds");
db::compare_layouts (_this, layout, fn_au, db::WriteGDS2, 1);
}

Binary file added testdata/gds/issue_1835.gds
Binary file not shown.
Binary file added testdata/gds/issue_1835_au.gds
Binary file not shown.

0 comments on commit b3fd515

Please sign in to comment.