From ca3505b872f679db23998055fef0e2d424171ab1 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sat, 21 Mar 2026 11:17:39 +0100 Subject: [PATCH 01/21] Part of the bugfix for #2305 - properly mapping cell indexes after library reload --- src/db/db/dbLibrary.cc | 21 +++++++++++++++------ src/db/db/dbLibrary.h | 5 ++++- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/db/db/dbLibrary.cc b/src/db/db/dbLibrary.cc index 0af31331c..66c1217cf 100644 --- a/src/db/db/dbLibrary.cc +++ b/src/db/db/dbLibrary.cc @@ -164,16 +164,25 @@ Library::rename (const std::string &name) void Library::refresh () { + // save a copy of the layout, so we can refer to it + std::unique_ptr org_layout (new db::Layout (layout ())); + std::string name = reload (); rename (name); layout ().refresh (); - remap_to (this); + remap_to (this, org_layout.get ()); } void -Library::remap_to (db::Library *other) +Library::remap_to (db::Library *other, db::Layout *original_layout) { + tl_assert (other != this || original_layout != 0); + + if (! original_layout) { + original_layout = &layout (); + } + // Hint: in the loop over the referrers we might unregister (delete from m_referrers) a referrer because no more cells refer to us. // Hence we must not directly iterate of m_referrers. std::vector > referrers; @@ -194,7 +203,7 @@ Library::remap_to (db::Library *other) db::LibraryProxy *lib_proxy = dynamic_cast (&*c); if (lib_proxy && lib_proxy->lib_id () == get_id ()) { - db::Cell *lib_cell = &layout ().cell (lib_proxy->library_cell_index ()); + db::Cell *lib_cell = &original_layout->cell (lib_proxy->library_cell_index ()); db::PCellVariant *lib_pcell = dynamic_cast (lib_cell); if (lib_pcell) { pcells_to_map.push_back (std::make_pair (lib_proxy, lib_pcell)); @@ -218,7 +227,7 @@ Library::remap_to (db::Library *other) std::pair pn (false, 0); if (other) { - pn = other->layout ().pcell_by_name (lp->first->get_basic_name ().c_str ()); + pn = other->layout ().pcell_by_name (original_layout->cell (lp->first->library_cell_index ()).get_basic_name ().c_str ()); } if (! pn.first) { @@ -230,7 +239,7 @@ Library::remap_to (db::Library *other) } else { - const db::PCellDeclaration *old_pcell_decl = layout ().pcell_declaration (lib_pcell->pcell_id ()); + const db::PCellDeclaration *old_pcell_decl = original_layout->pcell_declaration (lib_pcell->pcell_id ()); const db::PCellDeclaration *new_pcell_decl = other->layout ().pcell_declaration (pn.second); if (! old_pcell_decl || ! new_pcell_decl) { @@ -267,7 +276,7 @@ Library::remap_to (db::Library *other) std::pair cn (false, 0); if (other) { - cn = other->layout ().cell_by_name ((*lp)->get_basic_name ().c_str ()); + cn = other->layout ().cell_by_name (original_layout->cell ((*lp)->library_cell_index ()).get_basic_name ().c_str ()); } if (! cn.first) { diff --git a/src/db/db/dbLibrary.h b/src/db/db/dbLibrary.h index cd3513a4d..b0883e788 100644 --- a/src/db/db/dbLibrary.h +++ b/src/db/db/dbLibrary.h @@ -237,8 +237,11 @@ public: * @brief Remap the library proxies to a different library * * After remapping, "other" can replace "this". + * When calling with "other=this", a pointer to the original + * layout needs to be supplied, because in that case, the + * layout of "this" is already replaced. */ - void remap_to (db::Library *other); + void remap_to (db::Library *other, Layout *original_layout = 0); /** * @brief This event is fired if proxies get retired on unretired From f501f039c0707d418525594f77b52f71f9f54781 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sat, 21 Mar 2026 14:59:08 +0100 Subject: [PATCH 02/21] Added tests and two convenience methods The two convenience methods are Library#library_from_file Library#library_from_files Both create and register a Library object tied to a file. This object supports proper reloading and re-mapping on "refresh". --- src/db/db/db.pro | 2 + src/db/db/dbFileBasedLibrary.cc | 120 ++++++++++++++++++++++++++++ src/db/db/dbFileBasedLibrary.h | 105 ++++++++++++++++++++++++ src/db/db/dbLibrary.cc | 2 - src/db/db/gsiDeclDbLibrary.cc | 53 ++++++++++++ src/db/unit_tests/dbLibraryTests.cc | 92 +++++++++++++++++++++ src/db/unit_tests/unit_tests.pro | 1 + src/lay/lay/layLibraryController.cc | 84 +------------------ testdata/ruby/dbLibrary.rb | 64 +++++++++++++++ 9 files changed, 441 insertions(+), 82 deletions(-) create mode 100644 src/db/db/dbFileBasedLibrary.cc create mode 100644 src/db/db/dbFileBasedLibrary.h create mode 100644 src/db/unit_tests/dbLibraryTests.cc diff --git a/src/db/db/db.pro b/src/db/db/db.pro index 188abf0d8..9add5b7e8 100644 --- a/src/db/db/db.pro +++ b/src/db/db/db.pro @@ -34,6 +34,7 @@ SOURCES = \ dbEdgeProcessor.cc \ dbEdges.cc \ dbEdgesLocalOperations.cc \ + dbFileBasedLibrary.cc \ dbFillTool.cc \ dbFuzzyCellMapping.cc \ dbGenericShapeIterator.cc \ @@ -274,6 +275,7 @@ HEADERS = \ dbEdges.h \ dbEdgesLocalOperations.h \ dbEdgesToContours.h \ + dbFileBasedLibrary.h \ dbFillTool.h \ dbFuzzyCellMapping.h \ dbGenericShapeIterator.h \ diff --git a/src/db/db/dbFileBasedLibrary.cc b/src/db/db/dbFileBasedLibrary.cc new file mode 100644 index 000000000..63086fda1 --- /dev/null +++ b/src/db/db/dbFileBasedLibrary.cc @@ -0,0 +1,120 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2026 Matthias Koefferlein + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + + +#include "dbFileBasedLibrary.h" +#include "dbReader.h" +#include "dbCellMapping.h" + +#include "tlFileUtils.h" +#include "tlStream.h" + +namespace db +{ + +// ------------------------------------------------------------------------------------------- + +FileBasedLibrary::FileBasedLibrary (const std::string &path, const std::string &name) + : db::Library (), m_name (name), m_path (path), m_is_loaded (false) +{ + set_description (tl::filename (path)); +} + +void +FileBasedLibrary::merge_with_other_layout (const std::string &path) +{ + m_other_paths.push_back (path); + if (m_is_loaded) { + merge_impl (path); + } +} + +std::string +FileBasedLibrary::load () +{ + if (! m_is_loaded) { + return reload (); + } else { + return get_name (); + } +} + +std::string +FileBasedLibrary::reload () +{ + std::string name = m_name.empty () ? tl::basename (m_path) : m_name; + + layout ().clear (); + + tl::InputStream stream (m_path); + db::Reader reader (stream); + reader.read (layout ()); + + // Use the libname if there is one + if (m_name.empty ()) { + db::Layout::meta_info_name_id_type libname_name_id = layout ().meta_info_name_id ("libname"); + for (db::Layout::meta_info_iterator m = layout ().begin_meta (); m != layout ().end_meta (); ++m) { + if (m->first == libname_name_id && ! m->second.value.is_nil ()) { + name = m->second.value.to_string (); + break; + } + } + } + + for (auto p = m_other_paths.begin (); p != m_other_paths.end (); ++p) { + merge_impl (*p); + } + + m_is_loaded = true; + + return name; +} + +void +FileBasedLibrary::merge_impl (const std::string &path) +{ + db::Layout ly; + + tl::InputStream stream (path); + db::Reader reader (stream); + reader.read (ly); + + std::vector target_cells, source_cells; + + // collect the cells to pull in (all top cells of the library layout) + // NOTE: cells are not overwritten - the first layout wins, in terms + // of cell names and also in terms of database unit. + for (auto c = ly.begin_top_down (); c != ly.end_top_cells (); ++c) { + std::string cn = ly.cell_name (*c); + if (! layout ().has_cell (cn.c_str ())) { + source_cells.push_back (*c); + target_cells.push_back (layout ().add_cell (cn.c_str ())); + } + } + + db::CellMapping cm; + cm.create_multi_mapping_full (layout (), target_cells, ly, source_cells); + layout ().copy_tree_shapes (ly, cm); +} + +} + diff --git a/src/db/db/dbFileBasedLibrary.h b/src/db/db/dbFileBasedLibrary.h new file mode 100644 index 000000000..921ebe383 --- /dev/null +++ b/src/db/db/dbFileBasedLibrary.h @@ -0,0 +1,105 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2026 Matthias Koefferlein + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + + +#ifndef HDR_dbFileBasedLibrary +#define HDR_dbFileBasedLibrary + +#include "dbLibrary.h" +#include "dbCommon.h" + +#include +#include + +namespace db +{ + +/** + * @brief A Library specialization that ties a library to a file + * + * This object supports loading a library from multiple files and merging them into + * a single library (e.g. for loading a directory of cell files). + */ +class DB_PUBLIC FileBasedLibrary + : public db::Library +{ +public: + /** + * @brief Creates a file-based library object + * + * @param path The file path + * @param name The library name + * + * If the library name is an empty string, the library name is taken from + * a GDS LIBNAME or from the file name in the path. + * + * Note that you need to call "load" in order to actually load the file. + */ + FileBasedLibrary (const std::string &path, const std::string &name = std::string ()); + + /** + * @brief Merges another file into this library + * + * If the library was not loaded already, the merge requests are postponed + * until "load" is called. + */ + void merge_with_other_layout (const std::string &path); + + /** + * @brief Loads the files + * + * If the files are already loaded, this method does nothing. + * It returns the name of the library derived from the first file + * or the name given in the constructor. The constructor name has + * priority. + */ + std::string load (); + + /** + * @brief Implements the reload feature + */ + virtual std::string reload (); + + /** + * @brief Set the paths + * This method is provided for test purposes only. + */ + void set_paths (const std::string &path, const std::list &other_paths = std::list ()) + { + m_path = path; + m_other_paths = other_paths; + } + +private: + std::string m_name; + std::string m_path; + std::list m_other_paths; + bool m_is_loaded; + + void merge_impl (const std::string &path); +}; + +} + +#endif + + diff --git a/src/db/db/dbLibrary.cc b/src/db/db/dbLibrary.cc index 66c1217cf..921ce25ce 100644 --- a/src/db/db/dbLibrary.cc +++ b/src/db/db/dbLibrary.cc @@ -177,8 +177,6 @@ Library::refresh () void Library::remap_to (db::Library *other, db::Layout *original_layout) { - tl_assert (other != this || original_layout != 0); - if (! original_layout) { original_layout = &layout (); } diff --git a/src/db/db/gsiDeclDbLibrary.cc b/src/db/db/gsiDeclDbLibrary.cc index 4da1335f2..0c111ae48 100644 --- a/src/db/db/gsiDeclDbLibrary.cc +++ b/src/db/db/gsiDeclDbLibrary.cc @@ -29,6 +29,7 @@ #include "dbPCellDeclaration.h" #include "dbLibrary.h" #include "dbLibraryManager.h" +#include "dbFileBasedLibrary.h" #include "tlLog.h" namespace gsi @@ -156,11 +157,63 @@ static LibraryImpl *new_lib () return new LibraryImpl (); } +static db::Library *library_from_file (const std::string &path, const std::string &name) +{ + std::unique_ptr lib (new db::FileBasedLibrary (path, name)); + + std::string n = lib->load (); + db::Library *ret = lib.get (); + register_lib (lib.release (), n); + + return ret; +} + +static db::Library *library_from_files (const std::vector &paths, const std::string &name) +{ + if (paths.empty ()) { + throw tl::Exception (tl::to_string (tr ("At least one path must be given"))); + } + + std::unique_ptr lib (new db::FileBasedLibrary (paths.front (), name)); + for (auto i = paths.begin () + 1; i != paths.end (); ++i) { + lib->merge_with_other_layout (*i); + } + + std::string n = lib->load (); + db::Library *ret = lib.get (); + register_lib (lib.release (), n); + + return ret; +} + /** * @brief A basic implementation of the library */ LibraryClass decl_Library ("db", "LibraryBase", + gsi::method ("library_from_file", &library_from_file, gsi::arg ("path"), gsi::arg ("name", std::string (), "auto"), + "@brief Creates a library from a file\n" + "@param path The path to the file from which to create the library from.\n" + "@param name The name of the library. If empty, the name will be derived from the GDS LIBNAME or the file name.\n" + "@return The library object created. It is already registered with the name given or derived from the file.\n" + "\n" + "This method will create a \\Library object which is tied to a specific file. This object supports " + "automatic reloading when the \\Library#refresh method is called.\n" + "\n" + "This convenience method has been added in version 0.30.8.\n" + ) + + gsi::method ("library_from_files", &library_from_files, gsi::arg ("paths"), gsi::arg ("name", std::string (), "auto"), + "@brief Creates a library from a set of files\n" + "@param paths The paths to the files from which to create the library from. At least one file needs to be given.\n" + "@param name The name of the library. If empty, the name will be derived from the GDS LIBNAME or the file name.\n" + "@return The library object created. It is already registered with the name given or derived from the file.\n" + "\n" + "This method will create a \\Library object which is tied to several files. This object supports " + "automatic reloading when the \\Library#refresh method is called. The content of the files is merged " + "into the library. This is useful for example to create one library from a collection of files.\n" + "\n" + "This convenience method has been added in version 0.30.8.\n" + ) + gsi::method ("library_by_name", &library_by_name, gsi::arg ("name"), gsi::arg ("for_technology", std::string (), "unspecific"), "@brief Gets a library by name\n" "Returns the library object for the given name. If the name is not a valid library name, nil is returned.\n" diff --git a/src/db/unit_tests/dbLibraryTests.cc b/src/db/unit_tests/dbLibraryTests.cc new file mode 100644 index 000000000..3959e677f --- /dev/null +++ b/src/db/unit_tests/dbLibraryTests.cc @@ -0,0 +1,92 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2026 Matthias Koefferlein + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +#include "dbLibraryManager.h" +#include "dbLibrary.h" +#include "dbFileBasedLibrary.h" +#include "tlUnitTest.h" +#include "tlFileUtils.h" + +// map library to different file (aka reload/refresh) +TEST(1) +{ + std::string pa = tl::testsrc () + "/testdata/gds/lib_a.gds"; + std::string pb = tl::testsrc () + "/testdata/gds/lib_b.gds"; + + db::FileBasedLibrary *lib = new db::FileBasedLibrary (pa); + lib->load (); + lib->set_name ("LIB"); + db::LibraryManager::instance ().register_lib (lib); + + db::Layout l; + auto top_cell_index = l.add_cell ("TOP"); + auto lib_proxy = l.get_lib_proxy (lib, lib->layout ().cell_by_name ("A").second); + + l.cell (top_cell_index).insert (db::CellInstArray (db::CellInst (lib_proxy), db::Trans ())); + + EXPECT_EQ (l.cell (top_cell_index).bbox ().to_string (), "(0,0;2000,2000)"); + + // switch to a different file and refresh + lib->set_paths (pb); + lib->refresh (); + + EXPECT_EQ (l.cell (top_cell_index).bbox ().to_string (), "(-1000,-1000;1000,1000)"); + + db::LibraryManager::instance ().delete_lib (lib); +} + +// merge multiple files into one library +TEST(2) +{ + std::string pa = tl::testsrc () + "/testdata/gds/lib_a.gds"; + std::string pb = tl::testsrc () + "/testdata/gds/lib_b.gds"; + + db::FileBasedLibrary *lib = new db::FileBasedLibrary (pa); + lib->merge_with_other_layout (pb); + lib->load (); + lib->set_name ("LIB"); + db::LibraryManager::instance ().register_lib (lib); + + { + db::Layout l; + auto top_cell_index = l.add_cell ("TOP"); + auto lib_proxy = l.get_lib_proxy (lib, lib->layout ().cell_by_name ("A").second); + + l.cell (top_cell_index).insert (db::CellInstArray (db::CellInst (lib_proxy), db::Trans ())); + + // A comes from the first layout + EXPECT_EQ (l.cell (top_cell_index).bbox ().to_string (), "(0,0;2000,2000)"); + } + + { + db::Layout l; + auto top_cell_index = l.add_cell ("TOP"); + auto lib_proxy = l.get_lib_proxy (lib, lib->layout ().cell_by_name ("Z").second); + + l.cell (top_cell_index).insert (db::CellInstArray (db::CellInst (lib_proxy), db::Trans ())); + + // Z comes from the second layout + EXPECT_EQ (l.cell (top_cell_index).bbox ().to_string (), "(0,0;100,100)"); + } + + db::LibraryManager::instance ().delete_lib (lib); +} diff --git a/src/db/unit_tests/unit_tests.pro b/src/db/unit_tests/unit_tests.pro index a51884427..fa26f60fb 100644 --- a/src/db/unit_tests/unit_tests.pro +++ b/src/db/unit_tests/unit_tests.pro @@ -11,6 +11,7 @@ SOURCES = \ dbCompoundOperationTests.cc \ dbEdgeNeighborhoodTests.cc \ dbFillToolTests.cc \ + dbLibraryTests.cc \ dbLogTests.cc \ dbObjectWithPropertiesTests.cc \ dbPLCConvexDecompositionTests.cc \ diff --git a/src/lay/lay/layLibraryController.cc b/src/lay/lay/layLibraryController.cc index 97b2b54d0..e507b7e93 100644 --- a/src/lay/lay/layLibraryController.cc +++ b/src/lay/lay/layLibraryController.cc @@ -29,8 +29,7 @@ #include "layQtTools.h" #include "dbLibraryManager.h" #include "dbLibrary.h" -#include "dbReader.h" -#include "dbCellMapping.h" +#include "dbFileBasedLibrary.h" #include "tlLog.h" #include "tlStream.h" #include "tlFileUtils.h" @@ -42,81 +41,6 @@ namespace lay // ------------------------------------------------------------------------------------------- -class FileBasedLibrary - : public db::Library -{ -public: - FileBasedLibrary (const std::string &path) - : db::Library (), m_path (path) - { - set_description (tl::filename (path)); - } - - void merge_with_other_layout (const std::string &path) - { - m_other_paths.push_back (path); - merge_impl (path); - } - - virtual std::string reload () - { - std::string name = tl::basename (m_path); - - layout ().clear (); - - tl::InputStream stream (m_path); - db::Reader reader (stream); - reader.read (layout ()); - - // Use the libname if there is one - db::Layout::meta_info_name_id_type libname_name_id = layout ().meta_info_name_id ("libname"); - for (db::Layout::meta_info_iterator m = layout ().begin_meta (); m != layout ().end_meta (); ++m) { - if (m->first == libname_name_id && ! m->second.value.is_nil ()) { - name = m->second.value.to_string (); - break; - } - } - - for (auto p = m_other_paths.begin (); p != m_other_paths.end (); ++p) { - merge_impl (*p); - } - - return name; - } - -private: - std::string m_path; - std::list m_other_paths; - - void merge_impl (const std::string &path) - { - db::Layout ly; - - tl::InputStream stream (path); - db::Reader reader (stream); - reader.read (ly); - - std::vector target_cells, source_cells; - - // collect the cells to pull in (all top cells of the library layout) - // NOTE: cells are not overwritten - the first layout wins, in terms - // of cell names and also in terms of database unit. - for (auto c = ly.begin_top_down (); c != ly.end_top_cells (); ++c) { - std::string cn = ly.cell_name (*c); - if (! layout ().has_cell (cn.c_str ())) { - source_cells.push_back (*c); - target_cells.push_back (layout ().add_cell (cn.c_str ())); - } - } - - db::CellMapping cm; - cm.create_multi_mapping_full (layout (), target_cells, ly, source_cells); - layout ().copy_tree_shapes (ly, cm); - } -}; - -// ------------------------------------------------------------------------------------------- - LibraryController::LibraryController () : m_file_watcher (0), dm_sync_files (this, &LibraryController::sync_files) @@ -279,7 +203,7 @@ LibraryController::sync_files () } else { - std::map libs_by_name_here; + std::map libs_by_name_here; // Reload all files for (QStringList::const_iterator im = libs.begin (); im != libs.end (); ++im) { @@ -289,13 +213,13 @@ LibraryController::sync_files () try { - std::unique_ptr lib (new FileBasedLibrary (lib_path)); + std::unique_ptr lib (new db::FileBasedLibrary (lib_path)); if (! p->second.empty ()) { lib->set_technology (p->second); } tl::log << "Reading library '" << lib_path << "'"; - std::string libname = lib->reload (); + std::string libname = lib->load (); // merge with existing lib if there is already one in this folder with the right name auto il = libs_by_name_here.find (libname); diff --git a/testdata/ruby/dbLibrary.rb b/testdata/ruby/dbLibrary.rb index 38841ff35..ac1a15235 100644 --- a/testdata/ruby/dbLibrary.rb +++ b/testdata/ruby/dbLibrary.rb @@ -265,6 +265,70 @@ class DBLibrary_TestClass < TestBase end + def test_8_file_based_library + + # clean up before + [ "RBA-unit-test" ].each do |name| + l = RBA::Library::library_by_name(name) + l && l.unregister + end + + lylib = RBA::Layout::new + lylib.read(File.join($ut_testsrc, "testdata", "gds", "lib_a.gds")) + + tmp = File::join($ut_testtmp, "rba_dbLibrary_8.gds") + lylib.write(tmp) + + lib = RBA::Library::library_from_file(tmp, "RBA-unit-test") + + ly = RBA::Layout::new + top = ly.create_cell("TOP") + a = ly.create_cell("A", "RBA-unit-test") + top.insert(RBA::CellInstArray::new(a, RBA::Trans::new)) + + assert_equal(top.dbbox.to_s, "(0,0;2,2)") + + lylib.clear + lylib.read(File.join($ut_testsrc, "testdata", "gds", "lib_b.gds")) + lylib.write(tmp) + + lib.refresh + + assert_equal(top.dbbox.to_s, "(-1,-1;1,1)") + + end + + def test_9_file_based_library_multiple_files + + # clean up before + [ "RBA-unit-test" ].each do |name| + l = RBA::Library::library_by_name(name) + l && l.unregister + end + + files = [ + File.join($ut_testsrc, "testdata", "gds", "lib_a.gds"), + File.join($ut_testsrc, "testdata", "gds", "lib_b.gds") + ] + + lib = RBA::Library::library_from_files(files, "RBA-unit-test") + + ly = RBA::Layout::new + top = ly.create_cell("TOP") + a = ly.create_cell("A", "RBA-unit-test") + top.insert(RBA::CellInstArray::new(a, RBA::Trans::new)) + + assert_equal(top.dbbox.to_s, "(0,0;2,2)") + + ly = RBA::Layout::new + top = ly.create_cell("TOP") + z = ly.create_cell("Z", "RBA-unit-test") + top.insert(RBA::CellInstArray::new(z, RBA::Trans::new)) + + assert_equal(top.dbbox.to_s, "(0,0;0.1,0.1)") + + end + end load("test_epilogue.rb") From 83b9fafa9d785cc388990f3e6bda9f05884bad61 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sat, 21 Mar 2026 17:12:10 +0100 Subject: [PATCH 03/21] Added missing files --- testdata/bd/strmrun.drc | 6 ++++++ testdata/gds/lib_a.gds | Bin 0 -> 270 bytes testdata/gds/lib_b.gds | Bin 0 -> 474 bytes 3 files changed, 6 insertions(+) create mode 100644 testdata/bd/strmrun.drc create mode 100644 testdata/gds/lib_a.gds create mode 100644 testdata/gds/lib_b.gds diff --git a/testdata/bd/strmrun.drc b/testdata/bd/strmrun.drc new file mode 100644 index 000000000..a76771e05 --- /dev/null +++ b/testdata/bd/strmrun.drc @@ -0,0 +1,6 @@ + +# This is a smoke test +deep + +puts("This is DRC.") + diff --git a/testdata/gds/lib_a.gds b/testdata/gds/lib_a.gds new file mode 100644 index 0000000000000000000000000000000000000000..6832ab1dca87a77406425439d56a906399117924 GIT binary patch literal 270 zcmZQzV_;&6V31*CVt>WJ%pl6Z$Dqz&iOgo;U}E#}bYfr-VP>^+>@@d2w)}&o%MSeo zv!g;7WLRWJ%pl6Z#~{X_i_B)=U}E#}bYfr-VP>^+>@@d2w)}&o%MSeo zv!g;7WLRA+bEi5by02Ns^i2wiq literal 0 HcmV?d00001 From 4908f51e1cd356c1af9a4189a0f4f200989c6acd Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sat, 21 Mar 2026 23:54:23 +0100 Subject: [PATCH 04/21] WIP --- src/db/db/dbLibrary.cc | 23 +- src/db/db/dbLibrary.h | 33 ++- src/db/db/gsiDeclDbLibrary.cc | 20 ++ src/lay/lay/layLibraryController.cc | 387 +++++++++++++++++++++------- src/lay/lay/layLibraryController.h | 11 + 5 files changed, 371 insertions(+), 103 deletions(-) diff --git a/src/db/db/dbLibrary.cc b/src/db/db/dbLibrary.cc index 921ce25ce..8d8dcde1f 100644 --- a/src/db/db/dbLibrary.cc +++ b/src/db/db/dbLibrary.cc @@ -32,14 +32,17 @@ namespace db { -Library::Library() - : m_id (std::numeric_limits::max ()), m_layout (true) +Library::Library () + : m_id (std::numeric_limits::max ()), m_layout (true), m_replicate (true) { m_layout.set_library (this); } -Library::Library(const Library &d) - : gsi::ObjectBase (), tl::Object (), m_name (d.m_name), m_description (d.m_description), m_id (std::numeric_limits::max ()), m_layout (d.m_layout) +Library::Library (const Library &d) + : gsi::ObjectBase (), tl::Object (), + m_name (d.m_name), m_description (d.m_description), + m_id (std::numeric_limits::max ()), m_layout (d.m_layout), + m_replicate (d.m_replicate) { m_layout.set_library (this); } @@ -64,6 +67,12 @@ Library::for_technologies () const return ! m_technologies.empty (); } +void +Library::set_technologies (const std::set &t) +{ + m_technologies = t; +} + void Library::set_technology (const std::string &t) { @@ -145,6 +154,12 @@ Library::is_retired (const db::cell_index_type library_cell_index) const return (i != m_refcount.end () && j != m_retired_count.end () && i->second == j->second); } +void +Library::set_replicate (bool f) +{ + m_replicate = f; +} + void Library::rename (const std::string &name) { diff --git a/src/db/db/dbLibrary.h b/src/db/db/dbLibrary.h index b0883e788..0e1788e64 100644 --- a/src/db/db/dbLibrary.h +++ b/src/db/db/dbLibrary.h @@ -53,12 +53,12 @@ public: /** * @brief The constructor */ - Library(); + Library (); /** * @brief Copy constructor */ - Library(const Library &); + Library (const Library &); /** * @brief The destructor @@ -138,6 +138,13 @@ public: */ bool for_technologies () const; + /** + * @brief Sets the technology names this library is associated with + * + * This will reset the list of technologies to this set. + */ + void set_technologies (const std::set &t); + /** * @brief Sets the technology name this library is associated with * @@ -172,6 +179,27 @@ public: m_description = description; } + /** + * @brief Sets a value indicating whether the library produces replicas + * + * If this value is true (the default), layout written will include the + * actual layout of a library cell (replica). With this, it is possible + * to regenerate the layout without actually having the library at the + * cost of additional bytes in the file. + * + * Setting this flag to false avoids this replication, but a layout + * cannot be regenerated without having this library. + */ + void set_replicate (bool f); + + /** + * @brief Gets a value indicating whether the library produces replicas + */ + bool replicate () const + { + return m_replicate; + } + /** * @brief Getter for the library Id property */ @@ -256,6 +284,7 @@ private: db::Layout m_layout; std::map m_referrers; std::map m_refcount, m_retired_count; + bool m_replicate; // no copying. Library &operator=(const Library &); diff --git a/src/db/db/gsiDeclDbLibrary.cc b/src/db/db/gsiDeclDbLibrary.cc index 0c111ae48..a3e412211 100644 --- a/src/db/db/gsiDeclDbLibrary.cc +++ b/src/db/db/gsiDeclDbLibrary.cc @@ -266,6 +266,26 @@ LibraryClass decl_Library ("db", "LibraryBase", "\n" "This method has been introduced in version 0.30.5." ) + + gsi::method ("replicate=", &db::Library::set_replicate, gsi::arg ("flag"), + "@brief Sets a value indicating whether the library produces replicas\n" + "\n" + "If this value is true (the default), layout written will include the\n" + "actual layout of a library cell (replica). With this, it is possible\n" + "to regenerate the layout without actually having the library at the\n" + "cost of additional bytes in the file.\n" + "\n" + "Setting this flag to false avoids this replication, but a layout\n" + "cannot be regenerated without having this library.\n" + "\n" + "This attribute has been introduced in version 0.30.8." + ) + + gsi::method ("replicate", &db::Library::replicate, + "@brief Gets a value indicating whether the library produces replicas\n" + "\n" + "See \\replicate= for a description of this attribute.\n" + "\n" + "This attribute has been introduced in version 0.30.8." + ) + gsi::method ("rename", &db::Library::rename, gsi::arg ("name"), "@brief Renames the library\n" "\n" diff --git a/src/lay/lay/layLibraryController.cc b/src/lay/lay/layLibraryController.cc index e507b7e93..8b8639f57 100644 --- a/src/lay/lay/layLibraryController.cc +++ b/src/lay/lay/layLibraryController.cc @@ -33,6 +33,7 @@ #include "tlLog.h" #include "tlStream.h" #include "tlFileUtils.h" +#include "tlEnv.h" #include @@ -152,6 +153,38 @@ LibraryController::sync_files () } } + // scan for library definition files + + std::string lib_file = tl::get_env ("KLAYOUT_LIB"); + + std::vector > lib_files; + + if (lib_file.empty ()) { + for (std::vector >::const_iterator p = paths.begin (); p != paths.end (); ++p) { + std::string lf = tl::combine_path (p->first, "klayout.lib"); + if (tl::is_readable (lf)) { + lib_files.push_back (std::make_pair (lf, p->second)); + } + } + } else if (tl::is_readable (lib_file)) { + lib_files.push_back (std::make_pair (lib_file, std::string ())); + } + + for (auto lf = lib_files.begin (); lf != lib_files.end (); ++lf) { + + tl::log << "Reading lib file '" << *lf << "'"; + + std::vector libs; + read_lib_file (lf->first, lf->second, libs); + + read_libs (libs, new_lib_files); + + if (m_file_watcher) { + m_file_watcher->add_file (tl::absolute_file_path (lf->first)); + } + + } + // scan for libraries for (std::vector >::const_iterator p = paths.begin (); p != paths.end (); ++p) { @@ -169,108 +202,20 @@ LibraryController::sync_files () name_filters << QString::fromUtf8 ("*"); // NOTE: this should return a list sorted by name - QStringList libs = lp.entryList (name_filters, QDir::Files); + QStringList entries = lp.entryList (name_filters, QDir::Files); - bool needs_load = false; + std::vector libs; + libs.reserve (entries.size ()); - for (QStringList::const_iterator im = libs.begin (); im != libs.end () && ! needs_load; ++im) { - - std::string lib_path = tl::to_string (lp.absoluteFilePath (*im)); - QFileInfo fi (tl::to_qstring (lib_path)); - - auto ll = m_lib_files.find (lib_path); - if (ll == m_lib_files.end ()) { - needs_load = true; - } else if (fi.lastModified () > ll->second.time) { - needs_load = true; + for (auto e = entries.begin (); e != entries.end (); ++e) { + libs.push_back (LibFileInfo ()); + libs.back ().path = tl::to_string (lp.absoluteFilePath (*e)); + if (! p->second.empty ()) { + libs.back ().tech.insert (p->second); } - } - if (! needs_load) { - - // If not reloading, register the existing files as known ones - this allows detecting if - // a file got removed. - for (QStringList::const_iterator im = libs.begin (); im != libs.end () && ! needs_load; ++im) { - - std::string lib_path = tl::to_string (lp.absoluteFilePath (*im)); - auto ll = m_lib_files.find (lib_path); - if (ll != m_lib_files.end ()) { - new_lib_files.insert (*ll); - } - - } - - } else { - - std::map libs_by_name_here; - - // Reload all files - for (QStringList::const_iterator im = libs.begin (); im != libs.end (); ++im) { - - std::string lib_path = tl::to_string (lp.absoluteFilePath (*im)); - QFileInfo fi (tl::to_qstring (lib_path)); - - try { - - std::unique_ptr lib (new db::FileBasedLibrary (lib_path)); - if (! p->second.empty ()) { - lib->set_technology (p->second); - } - - tl::log << "Reading library '" << lib_path << "'"; - std::string libname = lib->load (); - - // merge with existing lib if there is already one in this folder with the right name - auto il = libs_by_name_here.find (libname); - if (il != libs_by_name_here.end ()) { - - tl::log << "Merging with other library file with the same name: " << libname; - - il->second->merge_with_other_layout (lib_path); - - // now, we can forget the new library as it is included in the first one - - } else { - - // otherwise register the new library - - if (! p->second.empty ()) { - tl::log << "Registering as '" << libname << "' for tech '" << p->second << "'"; - } else { - tl::log << "Registering as '" << libname << "'"; - } - - LibInfo li; - li.name = libname; - li.time = fi.lastModified (); - if (! p->second.empty ()) { - li.tech.insert (p->second); - } - new_lib_files.insert (std::make_pair (lib_path, li)); - - lib->set_name (libname); - libs_by_name_here.insert (std::make_pair (libname, lib.release ())); - - } - - } catch (tl::Exception &ex) { - tl::error << ex.msg (); - } - - } - - // Register the libs (NOTE: this needs to happen after the merge) - for (auto l = libs_by_name_here.begin (); l != libs_by_name_here.end (); ++l) { - try { - db::LibraryManager::instance ().register_lib (l->second); - } catch (tl::Exception &ex) { - tl::error << ex.msg (); - } catch (...) { - } - } - - } + read_libs (libs, new_lib_files); } @@ -312,6 +257,254 @@ LibraryController::sync_files () m_lib_files = new_lib_files; } +namespace +{ + +struct LibFileFunctionContext +{ + std::string lib_file; + std::string tech; + std::vector *lib_files; +}; + +static void do_read_lib_file (LibFileFunctionContext &fc); + +class DefineFunction + : public tl::EvalFunction +{ +public: + DefineFunction (LibFileFunctionContext *fc) + : mp_fc (fc) + { } + + virtual bool supports_keyword_parameters () const { return true; } + + virtual void execute (const tl::ExpressionParserContext &context, tl::Variant & /*out*/, const std::vector &args, const std::map *kwargs) const + { + if (args.size () < 1 || args.size () > 2) { + throw tl::EvalError (tl::to_string (tr ("'define' function needs one or two arguments (a path or a name and path)")), context); + } + + std::string lf, name; + if (args.size () == 1) { + lf = args[0].to_string (); + } else { + name = args[0].to_string (); + lf = args[1].to_string (); + } + + LibraryController::LibFileInfo fi; + fi.name = name; + fi.path = lf; + if (! mp_fc->tech.empty ()) { + fi.tech.insert (mp_fc->tech); + } + + if (kwargs) { + + for (auto k = kwargs->begin (); k != kwargs->end (); ++k) { + + static const std::string replicate_key ("replicate"); + static const std::string technology_key ("technology"); + static const std::string technologies_key ("technologies"); + + if (k->first == replicate_key) { + + fi.replicate = k->second.to_bool (); + + } else if (k->first == technology_key) { + + fi.tech.clear (); + fi.tech.insert (k->second.to_string ()); + + } else if (k->first == technologies_key) { + + fi.tech.clear (); + if (k->second.is_list ()) { + for (auto t = k->second.begin (); t != k->second.end (); ++t) { + fi.tech.insert (t->to_string ()); + } + } + + } else { + + throw tl::EvalError (tl::sprintf (tl::to_string (tr ("Unknown keyword argument '%s' for 'define' function - the only allowed keyword arguments are 'replicate', 'technology' and 'technologies")), k->first), context); + + } + + } + + } + + mp_fc->lib_files->push_back (fi); + + } + +private: + LibFileFunctionContext *mp_fc; +}; + +class IncludeFunction + : public tl::EvalFunction +{ +public: + IncludeFunction (LibFileFunctionContext *fc) + : mp_fc (fc) + { } + + virtual void execute (const tl::ExpressionParserContext &context, tl::Variant & /*out*/, const std::vector &args, const std::map * /*kwargs*/) const + { + if (args.size () != 1) { + throw tl::EvalError (tl::to_string (tr ("'include' function needs exactly one argument (the include file path)")), context); + } + + std::string lf = args[0].to_string (); + + LibFileFunctionContext fc = *mp_fc; + fc.lib_file = tl::is_absolute (lf) ? lf : tl::combine_path (tl::absolute_path (mp_fc->lib_file), lf); + + do_read_lib_file (fc); + } + +private: + LibFileFunctionContext *mp_fc; +}; + +static void +do_read_lib_file (LibFileFunctionContext &fc) +{ + tl::Eval eval; + + DefineFunction define_function (&fc); + IncludeFunction include_function (&fc); + + eval.define_function ("define", &define_function); + eval.define_function ("include", &include_function); + eval.set_var ("file", fc.lib_file); + eval.set_var ("tech", fc.tech); + + tl::InputStream is (fc.lib_file); + std::string lib_file = tl::TextInputStream (is).read_all (); + + tl::Extractor ex (lib_file.c_str ()); + eval.parse (ex).execute (); +} + +} + +void +LibraryController::read_lib_file (const std::string &lib_file, const std::string &tech, std::vector &file_info) +{ + LibFileFunctionContext fc; + fc.tech = tech; + fc.lib_file = tl::absolute_file_path (lib_file); + fc.lib_files = &file_info; + + do_read_lib_file (fc); +} + +void +LibraryController::read_libs (const std::vector &libs, std::map &new_lib_files) +{ + bool needs_load = false; + + for (auto im = libs.begin (); im != libs.end () && ! needs_load; ++im) { + + const std::string &lib_path = im->path; + QFileInfo fi (tl::to_qstring (lib_path)); + + auto ll = m_lib_files.find (lib_path); + if (ll == m_lib_files.end ()) { + needs_load = true; + } else if (fi.lastModified () > ll->second.time) { + needs_load = true; + } + + } + + if (! needs_load) { + + // If not reloading, register the existing files as known ones - this allows detecting if + // a file got removed. + for (auto im = libs.begin (); im != libs.end () && ! needs_load; ++im) { + + const std::string &lib_path = im->path; + auto ll = m_lib_files.find (lib_path); + if (ll != m_lib_files.end ()) { + new_lib_files.insert (*ll); + } + + } + + } else { + + std::map libs_by_name_here; + + // Reload all files + for (auto im = libs.begin (); im != libs.end (); ++im) { + + const std::string &lib_path = im->path; + QFileInfo fi (tl::to_qstring (lib_path)); + + try { + + std::unique_ptr lib (new db::FileBasedLibrary (lib_path, im->name)); + lib->set_technologies (im->tech); + lib->set_replicate (im->replicate); + + tl::log << "Reading library '" << lib_path << "'"; + std::string libname = lib->load (); + + // merge with existing lib if there is already one in this folder with the right name + auto il = libs_by_name_here.find (libname); + if (il != libs_by_name_here.end ()) { + + tl::log << "Merging with other library file with the same name: " << libname; + + il->second->merge_with_other_layout (lib_path); + + // now, we can forget the new library as it is included in the first one + + } else { + + // otherwise register the new library + + if (! im->tech.empty ()) { + tl::log << "Registering as '" << libname << "' for tech '" << tl::join (im->tech.begin (), im->tech.end (), ",") << "'"; + } else { + tl::log << "Registering as '" << libname << "'"; + } + + LibInfo li; + li.name = libname; + li.time = fi.lastModified (); + li.tech = im->tech; + new_lib_files.insert (std::make_pair (lib_path, li)); + + lib->set_name (libname); + libs_by_name_here.insert (std::make_pair (libname, lib.release ())); + + } + + } catch (tl::Exception &ex) { + tl::error << ex.msg (); + } + + } + + // Register the libs (NOTE: this needs to happen after the merge) + for (auto l = libs_by_name_here.begin (); l != libs_by_name_here.end (); ++l) { + try { + db::LibraryManager::instance ().register_lib (l->second); + } catch (tl::Exception &ex) { + tl::error << ex.msg (); + } catch (...) { + } + } + + } +} + void LibraryController::sync_with_external_sources () { diff --git a/src/lay/lay/layLibraryController.h b/src/lay/lay/layLibraryController.h index 12ee5cf0a..6050fa198 100644 --- a/src/lay/lay/layLibraryController.h +++ b/src/lay/lay/layLibraryController.h @@ -57,6 +57,15 @@ class LibraryController Q_OBJECT public: + struct LibFileInfo + { + LibFileInfo () : name (), path (), replicate (true) { } + std::string name; + std::string path; + std::set tech; + bool replicate; + }; + /** * @brief Default constructor */ @@ -132,6 +141,8 @@ private: std::map m_lib_files; void sync_files (); + void read_libs (const std::vector &file_info, std::map &new_lib_files); + void read_lib_file (const std::string &lib_file, const std::string &tech, std::vector &file_info); }; } From 56e84e7056d20410ba23aaebe34eaab407ecffc6 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sun, 22 Mar 2026 16:01:39 +0100 Subject: [PATCH 05/21] Added test for lib file reading --- src/lay/lay/layLibraryController.cc | 14 ++-- src/lay/lay/layLibraryController.h | 8 +- .../unit_tests/layLibraryControllerTests.cc | 76 +++++++++++++++++++ src/lay/unit_tests/unit_tests.pro | 1 + testdata/lay/a.libdef | 6 ++ testdata/lay/b.libdef | 10 +++ 6 files changed, 106 insertions(+), 9 deletions(-) create mode 100644 src/lay/unit_tests/layLibraryControllerTests.cc create mode 100644 testdata/lay/a.libdef create mode 100644 testdata/lay/b.libdef diff --git a/src/lay/lay/layLibraryController.cc b/src/lay/lay/layLibraryController.cc index 8b8639f57..df342e21f 100644 --- a/src/lay/lay/layLibraryController.cc +++ b/src/lay/lay/layLibraryController.cc @@ -295,7 +295,7 @@ public: LibraryController::LibFileInfo fi; fi.name = name; - fi.path = lf; + fi.path = tl::is_absolute (lf) ? lf : tl::combine_path (tl::absolute_path (mp_fc->lib_file), lf); if (! mp_fc->tech.empty ()) { fi.tech.insert (mp_fc->tech); } @@ -315,7 +315,10 @@ public: } else if (k->first == technology_key) { fi.tech.clear (); - fi.tech.insert (k->second.to_string ()); + std::string tn = k->second.to_string (); + if (! tn.empty () && tn != "*") { + fi.tech.insert (tn); + } } else if (k->first == technologies_key) { @@ -375,11 +378,8 @@ do_read_lib_file (LibFileFunctionContext &fc) { tl::Eval eval; - DefineFunction define_function (&fc); - IncludeFunction include_function (&fc); - - eval.define_function ("define", &define_function); - eval.define_function ("include", &include_function); + eval.define_function ("define", new DefineFunction (&fc)); + eval.define_function ("include", new IncludeFunction (&fc)); eval.set_var ("file", fc.lib_file); eval.set_var ("tech", fc.tech); diff --git a/src/lay/lay/layLibraryController.h b/src/lay/lay/layLibraryController.h index 6050fa198..c7970c5a4 100644 --- a/src/lay/lay/layLibraryController.h +++ b/src/lay/lay/layLibraryController.h @@ -51,7 +51,7 @@ class MainWindow; * By making the controller a PluginDeclaration it will receive * initialization and configuration calls. */ -class LibraryController +class LAY_PUBLIC LibraryController : public lay::PluginDeclaration, public tl::Object { Q_OBJECT @@ -116,6 +116,11 @@ public: */ static LibraryController *instance (); + /** + * @brief Provided for test purposes + */ + static void read_lib_file (const std::string &lib_file, const std::string &tech, std::vector &file_info); + private slots: /** * @brief Called when the file watcher detects a change in the file system @@ -142,7 +147,6 @@ private: void sync_files (); void read_libs (const std::vector &file_info, std::map &new_lib_files); - void read_lib_file (const std::string &lib_file, const std::string &tech, std::vector &file_info); }; } diff --git a/src/lay/unit_tests/layLibraryControllerTests.cc b/src/lay/unit_tests/layLibraryControllerTests.cc new file mode 100644 index 000000000..b5785dcfa --- /dev/null +++ b/src/lay/unit_tests/layLibraryControllerTests.cc @@ -0,0 +1,76 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2026 Matthias Koefferlein + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + + +#include "layLibraryController.h" +#include "tlUnitTest.h" +#include "tlFileUtils.h" + +TEST (1) +{ + std::string lib_file = tl::testdata () + "/lay/a.libdef"; + + std::vector file_info; + lay::LibraryController::read_lib_file (lib_file, "T1", file_info); + + tl_assert (file_info.size () == size_t (3)); + + EXPECT_EQ (file_info[0].name, ""); + EXPECT_EQ (file_info[0].path, tl::combine_path (tl::absolute_path (lib_file), "noname.gds")); + EXPECT_EQ (file_info[0].replicate, true); + EXPECT_EQ (tl::join (file_info[0].tech.begin (), file_info[0].tech.end (), ","), "T1"); + + EXPECT_EQ (file_info[1].name, "L2"); + EXPECT_EQ (file_info[1].path, tl::absolute_file_path (lib_file) + ".zzz"); + EXPECT_EQ (file_info[1].replicate, true); + EXPECT_EQ (file_info[1].tech.size (), size_t (0)); + + EXPECT_EQ (file_info[2].name, "L3"); + EXPECT_EQ (file_info[2].path, tl::combine_path (tl::absolute_path (lib_file), "subdir/l3.gds")); + EXPECT_EQ (file_info[2].replicate, false); + EXPECT_EQ (tl::join (file_info[2].tech.begin (), file_info[2].tech.end (), ","), "T2,T3"); +} + +TEST(2) +{ + std::string lib_file = tl::testdata () + "/lay/b.libdef"; + + std::vector file_info; + lay::LibraryController::read_lib_file (lib_file, "TX", file_info); + + tl_assert (file_info.size () == size_t (5)); + + EXPECT_EQ (file_info[0].name, "L0"); + EXPECT_EQ (file_info[0].path, tl::combine_path (tl::absolute_path (lib_file), "l0.gds")); + EXPECT_EQ (file_info[0].replicate, true); + EXPECT_EQ (file_info[0].tech.size (), size_t (0)); + + EXPECT_EQ (file_info[1].name, ""); + EXPECT_EQ (file_info[1].path, tl::combine_path (tl::absolute_path (lib_file), "noname.gds")); + EXPECT_EQ (file_info[1].replicate, true); + EXPECT_EQ (tl::join (file_info[1].tech.begin (), file_info[1].tech.end (), ","), "TX"); + + EXPECT_EQ (file_info[4].name, "L4"); + EXPECT_EQ (file_info[4].path, tl::combine_path (tl::absolute_path (lib_file), "l4.gds")); + EXPECT_EQ (file_info[4].replicate, true); + EXPECT_EQ (tl::join (file_info[4].tech.begin (), file_info[4].tech.end (), ","), "TX"); +} diff --git a/src/lay/unit_tests/unit_tests.pro b/src/lay/unit_tests/unit_tests.pro index adf955966..b701fe4c1 100644 --- a/src/lay/unit_tests/unit_tests.pro +++ b/src/lay/unit_tests/unit_tests.pro @@ -7,6 +7,7 @@ TARGET = lay_tests include($$PWD/../../lib_ut.pri) SOURCES = \ + layLibraryControllerTests.cc \ laySalt.cc \ layHelpIndexTest.cc \ laySaltParsedURLTests.cc \ diff --git a/testdata/lay/a.libdef b/testdata/lay/a.libdef new file mode 100644 index 000000000..ff4bc56af --- /dev/null +++ b/testdata/lay/a.libdef @@ -0,0 +1,6 @@ + +# A comment +define("noname.gds"); +define("L2", file + ".zzz", technology = ""); +define("L3", "subdir/l3.gds", technologies = [ "T2", "T3" ], replicate = false); + diff --git a/testdata/lay/b.libdef b/testdata/lay/b.libdef new file mode 100644 index 000000000..eadaf2604 --- /dev/null +++ b/testdata/lay/b.libdef @@ -0,0 +1,10 @@ + +define("L0", "l0.gds", technology = "*"); + +# relative to this file +include("../lay/a.libdef"); + +var n4 = "L4"; +var f4 = "l4.gds"; +define(n4, f4); + From aa361277a0b7de4785c6406a2fd6775e318034f7 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sun, 22 Mar 2026 21:21:11 +0100 Subject: [PATCH 06/21] Implementing replication in LStream, OASIS and GDS2 --- src/db/db/dbCell.h | 13 +++- src/db/db/dbCommonReader.cc | 5 ++ src/db/db/dbLibraryProxy.cc | 7 ++ src/db/db/dbLibraryProxy.h | 8 ++ src/db/db/dbSaveLayoutOptions.cc | 70 +++++++++++++++-- src/db/db/dbSaveLayoutOptions.h | 2 +- src/db/db/dbStream.h | 5 ++ src/lay/lay/layLibraryController.cc | 22 ++++-- src/lay/lay/layLibraryController.h | 3 +- src/plugins/streamers/cif/db_plugin/dbCIF.cc | 5 ++ src/plugins/streamers/dxf/db_plugin/dbDXF.cc | 5 ++ .../gds2/db_plugin/contrib/dbGDS2Text.cc | 5 ++ .../streamers/gds2/db_plugin/dbGDS2.cc | 5 ++ .../gds2/db_plugin/dbGDS2WriterBase.cc | 76 ++++++++++--------- .../gds2/db_plugin/dbGDS2WriterBase.h | 2 +- .../lefdef/db_plugin/dbLEFDEFPlugin.cc | 5 ++ .../streamers/lstream/db_plugin/lstrPlugin.cc | 8 ++ .../streamers/lstream/db_plugin/lstrWriter.cc | 7 +- .../streamers/lstream/db_plugin/lstrWriter.h | 2 +- .../streamers/magic/db_plugin/dbMAG.cc | 5 ++ .../streamers/maly/db_plugin/dbMALY.cc | 5 ++ .../streamers/oasis/db_plugin/dbOASIS.cc | 5 ++ .../oasis/db_plugin/dbOASISWriter.cc | 25 +++--- .../pcb/db_plugin/dbGerberImporter.cc | 5 ++ src/tl/tl/tlExpression.cc | 2 - 25 files changed, 232 insertions(+), 70 deletions(-) diff --git a/src/db/db/dbCell.h b/src/db/db/dbCell.h index c616a105d..ac3430020 100644 --- a/src/db/db/dbCell.h +++ b/src/db/db/dbCell.h @@ -857,7 +857,7 @@ public: void check_locked () const; /** - * @brief Tell, if this cell is a proxy cell + * @brief Gets a value indicating if this cell is a proxy cell * * Proxy cells are such whose layout represents a snapshot of another entity. * Such cells can be PCell variants or library references for example. @@ -867,6 +867,17 @@ public: return false; } + /** + * @brief Gets a value indicating that this cell is a replica that can be skipped + * + * This attribute is evaluated by file writers to skip cell replicas for + * library cells that do not want to replicated. + */ + virtual bool can_skip_replica () const + { + return false; + } + /** * @brief Sets the cell name * diff --git a/src/db/db/dbCommonReader.cc b/src/db/db/dbCommonReader.cc index 2924d5685..617ea3f1f 100644 --- a/src/db/db/dbCommonReader.cc +++ b/src/db/db/dbCommonReader.cc @@ -692,6 +692,11 @@ public: return false; } + virtual bool supports_context () const + { + return false; + } + virtual tl::XMLElementBase *xml_reader_options_element () const { return new db::ReaderOptionsXMLElement ("common", diff --git a/src/db/db/dbLibraryProxy.cc b/src/db/db/dbLibraryProxy.cc index 8a4e043f2..58f79994e 100644 --- a/src/db/db/dbLibraryProxy.cc +++ b/src/db/db/dbLibraryProxy.cc @@ -241,6 +241,13 @@ LibraryProxy::update (db::ImportLayerMapping *layer_mapping) } } +bool +LibraryProxy::can_skip_replica () const +{ + const Library *lib = LibraryManager::instance ().lib (lib_id ()); + return lib && ! lib->replicate (); +} + std::string LibraryProxy::get_basic_name () const { diff --git a/src/db/db/dbLibraryProxy.h b/src/db/db/dbLibraryProxy.h index 233348daa..e947de690 100644 --- a/src/db/db/dbLibraryProxy.h +++ b/src/db/db/dbLibraryProxy.h @@ -93,6 +93,14 @@ public: return true; } + /** + * @brief Gets a value indicating that this cell is a replica that can be skipped + * + * This attribute is evaluated by file writers to skip cell replicas for + * library cells that do not want to replicated. + */ + virtual bool can_skip_replica () const; + /** * @brief Gets the basic name * diff --git a/src/db/db/dbSaveLayoutOptions.cc b/src/db/db/dbSaveLayoutOptions.cc index 4c2e55cf6..5561fcdea 100644 --- a/src/db/db/dbSaveLayoutOptions.cc +++ b/src/db/db/dbSaveLayoutOptions.cc @@ -56,7 +56,7 @@ SaveLayoutOptions::operator= (const SaveLayoutOptions &d) m_format = d.m_format; m_layers = d.m_layers; m_cells = d.m_cells; - m_implied_childred = d.m_implied_childred; + m_implied_children = d.m_implied_children; m_all_layers = d.m_all_layers; m_all_cells = d.m_all_cells; m_dbu = d.m_dbu; @@ -189,7 +189,7 @@ SaveLayoutOptions::add_cell (db::cell_index_type cell_index) { m_all_cells = false; m_cells.insert (cell_index); - m_implied_childred.insert (cell_index); + m_implied_children.insert (cell_index); } void @@ -204,7 +204,7 @@ SaveLayoutOptions::clear_cells () { m_all_cells = false; m_cells.clear (); - m_implied_childred.clear (); + m_implied_children.clear (); } void @@ -212,7 +212,7 @@ SaveLayoutOptions::select_all_cells () { m_all_cells = true; m_cells.clear (); - m_implied_childred.clear (); + m_implied_children.clear (); } void @@ -340,21 +340,75 @@ SaveLayoutOptions::get_valid_layers (const db::Layout &layout, std::vector &called) +{ + const db::Cell &c = layout.cell (ci); + if (c.can_skip_replica ()) { + return; + } + + for (auto cc = c.begin_child_cells (); ! cc.at_end (); ++cc) { + if (called.find (*cc) == called.end () && layout.is_valid_cell_index (*cc)) { + called.insert (*cc); + collect_called_cells_unskipped (*cc, layout, called); + } + } +} + void SaveLayoutOptions::get_cells (const db::Layout &layout, std::set &cells, const std::vector > &valid_layers, bool require_unique_names) const { + bool has_context = m_write_context_info; + for (tl::Registrar::iterator fmt = tl::Registrar::begin (); fmt != tl::Registrar::end (); ++fmt) { + if (fmt->format_name () == m_format) { + if (! fmt->supports_context ()) { + has_context = false; + } + break; + } + } + if (m_all_cells) { - for (db::Layout::const_iterator cell = layout.begin (); cell != layout.end (); ++cell) { - cells.insert (cell->cell_index ()); + bool has_skipped_replica = false; + + // check if we have skipped replicas + if (has_context) { + for (db::Layout::const_iterator cell = layout.begin (); cell != layout.end () && ! has_skipped_replica; ++cell) { + has_skipped_replica = cell->can_skip_replica (); + } + } + + // with skipped replicas start again and skip child cells of such cells + // unless they are needed in other places. + if (has_skipped_replica) { + + for (db::Layout::const_iterator cell = layout.begin (); cell != layout.end (); ++cell) { + if (cell->is_top ()) { + cells.insert (cell->cell_index ()); + collect_called_cells_unskipped (cell->cell_index (), layout, cells); + } + } + + } else { + + for (db::Layout::const_iterator cell = layout.begin (); cell != layout.end () && ! has_skipped_replica; ++cell) { + cells.insert (cell->cell_index ()); + } + } } else { for (std::set ::const_iterator c = m_cells.begin (); c != m_cells.end (); ++c) { cells.insert (*c); - if (m_implied_childred.find (*c) != m_implied_childred.end ()) { - layout.cell (*c).collect_called_cells (cells); + if (m_implied_children.find (*c) != m_implied_children.end ()) { + if (has_context) { + collect_called_cells_unskipped (*c, layout, cells); + } else { + layout.cell (*c).collect_called_cells (cells); + } } } diff --git a/src/db/db/dbSaveLayoutOptions.h b/src/db/db/dbSaveLayoutOptions.h index 2bc0ab2b7..730db06b2 100644 --- a/src/db/db/dbSaveLayoutOptions.h +++ b/src/db/db/dbSaveLayoutOptions.h @@ -449,7 +449,7 @@ private: std::string m_format; std::map m_layers; std::set m_cells; - std::set m_implied_childred; + std::set m_implied_children; bool m_all_layers; bool m_all_cells; double m_dbu; diff --git a/src/db/db/dbStream.h b/src/db/db/dbStream.h index ed217adbc..b6c1c4381 100644 --- a/src/db/db/dbStream.h +++ b/src/db/db/dbStream.h @@ -109,6 +109,11 @@ public: */ virtual bool can_write () const = 0; + /** + * @brief Returns true, when the format supports a context (e.g. PCell parameters, Library references) + */ + virtual bool supports_context () const = 0; + /** * @brief Delivers the XMLElement object that represents the reader options within a technology XML tree * diff --git a/src/lay/lay/layLibraryController.cc b/src/lay/lay/layLibraryController.cc index df342e21f..f68519041 100644 --- a/src/lay/lay/layLibraryController.cc +++ b/src/lay/lay/layLibraryController.cc @@ -172,15 +172,22 @@ LibraryController::sync_files () for (auto lf = lib_files.begin (); lf != lib_files.end (); ++lf) { - tl::log << "Reading lib file '" << *lf << "'"; + tl::log << "Reading lib file '" << lf->first << "'"; - std::vector libs; - read_lib_file (lf->first, lf->second, libs); + try { - read_libs (libs, new_lib_files); + std::vector libs; + read_lib_file (lf->first, lf->second, libs); - if (m_file_watcher) { - m_file_watcher->add_file (tl::absolute_file_path (lf->first)); + read_libs (libs, new_lib_files); + + if (m_file_watcher) { + m_file_watcher->add_file (tl::absolute_file_path (lf->first)); + } + + } catch (tl::Exception &ex) { + tl::error << tl::to_string (tr ("Error reading lib file")) << " " << lf->first << ":" << tl::endl << ex.msg (); + } catch (...) { } } @@ -416,7 +423,7 @@ LibraryController::read_libs (const std::vector auto ll = m_lib_files.find (lib_path); if (ll == m_lib_files.end ()) { needs_load = true; - } else if (fi.lastModified () > ll->second.time) { + } else if (fi.lastModified () > ll->second.time || im->tech != ll->second.tech || im->replicate != ll->second.replicate) { needs_load = true; } @@ -479,6 +486,7 @@ LibraryController::read_libs (const std::vector li.name = libname; li.time = fi.lastModified (); li.tech = im->tech; + li.replicate = im->replicate; new_lib_files.insert (std::make_pair (lib_path, li)); lib->set_name (libname); diff --git a/src/lay/lay/layLibraryController.h b/src/lay/lay/layLibraryController.h index c7970c5a4..54c345a02 100644 --- a/src/lay/lay/layLibraryController.h +++ b/src/lay/lay/layLibraryController.h @@ -135,10 +135,11 @@ private slots: private: struct LibInfo { - LibInfo () : name (), time (), tech () { } + LibInfo () : name (), time (), tech (), replicate (true) { } std::string name; QDateTime time; std::set tech; + bool replicate; }; tl::FileSystemWatcher *m_file_watcher; diff --git a/src/plugins/streamers/cif/db_plugin/dbCIF.cc b/src/plugins/streamers/cif/db_plugin/dbCIF.cc index f65f42638..693168c40 100644 --- a/src/plugins/streamers/cif/db_plugin/dbCIF.cc +++ b/src/plugins/streamers/cif/db_plugin/dbCIF.cc @@ -173,6 +173,11 @@ public: return true; } + virtual bool supports_context () const + { + return false; + } + virtual tl::XMLElementBase *xml_reader_options_element () const { return new db::ReaderOptionsXMLElement ("cif", diff --git a/src/plugins/streamers/dxf/db_plugin/dbDXF.cc b/src/plugins/streamers/dxf/db_plugin/dbDXF.cc index 59bf45244..0e63d4e6a 100644 --- a/src/plugins/streamers/dxf/db_plugin/dbDXF.cc +++ b/src/plugins/streamers/dxf/db_plugin/dbDXF.cc @@ -140,6 +140,11 @@ public: return true; } + virtual bool supports_context () const + { + return false; + } + virtual tl::XMLElementBase *xml_reader_options_element () const { return new db::ReaderOptionsXMLElement ("dxf", diff --git a/src/plugins/streamers/gds2/db_plugin/contrib/dbGDS2Text.cc b/src/plugins/streamers/gds2/db_plugin/contrib/dbGDS2Text.cc index 72744aadd..1124d8da4 100644 --- a/src/plugins/streamers/gds2/db_plugin/contrib/dbGDS2Text.cc +++ b/src/plugins/streamers/gds2/db_plugin/contrib/dbGDS2Text.cc @@ -89,6 +89,11 @@ class GDS2TextFormatDeclaration { return true; } + + virtual bool supports_context () const + { + return true; + } }; static tl::RegisteredClass format_txt_decl (new GDS2TextFormatDeclaration(), 1, "GDS2Text"); diff --git a/src/plugins/streamers/gds2/db_plugin/dbGDS2.cc b/src/plugins/streamers/gds2/db_plugin/dbGDS2.cc index 6d42a46d8..b5a25a343 100644 --- a/src/plugins/streamers/gds2/db_plugin/dbGDS2.cc +++ b/src/plugins/streamers/gds2/db_plugin/dbGDS2.cc @@ -66,6 +66,11 @@ class GDS2FormatDeclaration return true; } + virtual bool supports_context () const + { + return true; + } + virtual tl::XMLElementBase *xml_writer_options_element () const { return new db::WriterOptionsXMLElement ("gds2", diff --git a/src/plugins/streamers/gds2/db_plugin/dbGDS2WriterBase.cc b/src/plugins/streamers/gds2/db_plugin/dbGDS2WriterBase.cc index c6b7a3ea2..712ea2bd8 100644 --- a/src/plugins/streamers/gds2/db_plugin/dbGDS2WriterBase.cc +++ b/src/plugins/streamers/gds2/db_plugin/dbGDS2WriterBase.cc @@ -338,7 +338,7 @@ GDS2WriterBase::write_shape (const db::Layout &layout, int layer, int datatype, } void -GDS2WriterBase::write_cell (db::Layout &layout, const db::Cell &cref, const std::vector > &layers, const std::set &cell_set, double sf, short *time_data) +GDS2WriterBase::write_cell (db::Layout &layout, const db::Cell &cref, const std::vector > &layers, const std::set &cell_set, double sf, short *time_data, bool skip_body) { // cell header @@ -363,51 +363,56 @@ GDS2WriterBase::write_cell (db::Layout &layout, const db::Cell &cref, const std: } } - // instances + // skip instances and shapes for replicas + if (! skip_body) { - for (db::Cell::const_iterator inst = cref.begin (); ! inst.at_end (); ++inst) { + // instances - // write only instances to selected cells - if (m_keep_instances || cell_set.find (inst->cell_index ()) != cell_set.end ()) { + for (db::Cell::const_iterator inst = cref.begin (); ! inst.at_end (); ++inst) { + + // write only instances to selected cells + if (m_keep_instances || cell_set.find (inst->cell_index ()) != cell_set.end ()) { + + progress_checkpoint (); + try { + write_inst (sf, *inst, true /*normalize*/, m_resolve_skew_arrays, layout, inst->prop_id ()); + } catch (tl::Exception &ex) { + throw tl::Exception (ex.msg () + tl::to_string (tr (", writing instances"))); + } - progress_checkpoint (); - try { - write_inst (sf, *inst, true /*normalize*/, m_resolve_skew_arrays, layout, inst->prop_id ()); - } catch (tl::Exception &ex) { - throw tl::Exception (ex.msg () + tl::to_string (tr (", writing instances"))); } } - } + // shapes - // shapes + for (std::vector >::const_iterator l = layers.begin (); l != layers.end (); ++l) { - for (std::vector >::const_iterator l = layers.begin (); l != layers.end (); ++l) { + if (layout.is_valid_layer (l->first) && l->second.layer >= 0 && l->second.datatype >= 0) { - if (layout.is_valid_layer (l->first) && l->second.layer >= 0 && l->second.datatype >= 0) { - - int layer = l->second.layer; - if (layer > std::numeric_limits::max ()) { - throw tl::Exception (tl::sprintf (tl::to_string (tr ("Cannot write layer numbers larger than %d to GDS2 streams")), int (std::numeric_limits::max ()))); - } - int datatype = l->second.datatype; - if (datatype > std::numeric_limits::max ()) { - throw tl::Exception (tl::sprintf (tl::to_string (tr ("Cannot write datatype numbers larger than %d to GDS2 streams")), int (std::numeric_limits::max ()))); - } - - db::ShapeIterator shape (cref.shapes (l->first).begin (db::ShapeIterator::Boxes | db::ShapeIterator::Polygons | db::ShapeIterator::Edges | db::ShapeIterator::EdgePairs | db::ShapeIterator::Paths | db::ShapeIterator::Texts)); - while (! shape.at_end ()) { - - progress_checkpoint (); - - try { - write_shape (layout, layer, datatype, *shape, sf); - } catch (tl::Exception &ex) { - throw tl::Exception (ex.msg () + tl::sprintf (tl::to_string (tr (", writing layer %d/%d")), layer, datatype)); + int layer = l->second.layer; + if (layer > std::numeric_limits::max ()) { + throw tl::Exception (tl::sprintf (tl::to_string (tr ("Cannot write layer numbers larger than %d to GDS2 streams")), int (std::numeric_limits::max ()))); + } + int datatype = l->second.datatype; + if (datatype > std::numeric_limits::max ()) { + throw tl::Exception (tl::sprintf (tl::to_string (tr ("Cannot write datatype numbers larger than %d to GDS2 streams")), int (std::numeric_limits::max ()))); } - ++shape; + db::ShapeIterator shape (cref.shapes (l->first).begin (db::ShapeIterator::Boxes | db::ShapeIterator::Polygons | db::ShapeIterator::Edges | db::ShapeIterator::EdgePairs | db::ShapeIterator::Paths | db::ShapeIterator::Texts)); + while (! shape.at_end ()) { + + progress_checkpoint (); + + try { + write_shape (layout, layer, datatype, *shape, sf); + } catch (tl::Exception &ex) { + throw tl::Exception (ex.msg () + tl::sprintf (tl::to_string (tr (", writing layer %d/%d")), layer, datatype)); + } + + ++shape; + + } } @@ -580,7 +585,8 @@ GDS2WriterBase::write (db::Layout &layout, tl::OutputStream &stream, const db::S if (! cref.is_real_ghost_cell () && (! cref.is_proxy () || ! cref.is_top ())) { try { - write_cell (layout, cref, layers, cell_set, sf, time_data); + bool skip_body = options.write_context_info () && cref.can_skip_replica (); + write_cell (layout, cref, layers, cell_set, sf, time_data, skip_body); } catch (tl::Exception &ex) { throw tl::Exception (ex.msg () + tl::sprintf (tl::to_string (tr (", writing cell '%s'")), layout.cell_name (*cell))); } diff --git a/src/plugins/streamers/gds2/db_plugin/dbGDS2WriterBase.h b/src/plugins/streamers/gds2/db_plugin/dbGDS2WriterBase.h index 1bc41594c..fda28dcb6 100644 --- a/src/plugins/streamers/gds2/db_plugin/dbGDS2WriterBase.h +++ b/src/plugins/streamers/gds2/db_plugin/dbGDS2WriterBase.h @@ -181,7 +181,7 @@ private: void write_context_cell (db::Layout &layout, const short *time_data, const std::vector &cells); void write_context_string (size_t n, const std::string &s); void write_cell (db::Layout &layout, const db::Cell &cref, const std::vector > &layers, - const std::set &cell_set, double sf, short *time_data); + const std::set &cell_set, double sf, short *time_data, bool skip_body); void write_shape (const db::Layout &layout, int layer, int datatype, const db::Shape &shape, double sf); }; diff --git a/src/plugins/streamers/lefdef/db_plugin/dbLEFDEFPlugin.cc b/src/plugins/streamers/lefdef/db_plugin/dbLEFDEFPlugin.cc index 1a974bc23..14cd567f3 100644 --- a/src/plugins/streamers/lefdef/db_plugin/dbLEFDEFPlugin.cc +++ b/src/plugins/streamers/lefdef/db_plugin/dbLEFDEFPlugin.cc @@ -310,6 +310,11 @@ class LEFDEFFormatDeclaration return false; } + virtual bool supports_context () const + { + return false; + } + virtual tl::XMLElementBase *xml_reader_options_element () const { return new db::ReaderOptionsXMLElement ("lefdef", diff --git a/src/plugins/streamers/lstream/db_plugin/lstrPlugin.cc b/src/plugins/streamers/lstream/db_plugin/lstrPlugin.cc index 293e27ce5..92db1a264 100644 --- a/src/plugins/streamers/lstream/db_plugin/lstrPlugin.cc +++ b/src/plugins/streamers/lstream/db_plugin/lstrPlugin.cc @@ -105,6 +105,14 @@ class LStreamFormatDeclaration return true; } + /** + * @brief Returns a value indicating whether context information is supported + */ + virtual bool supports_context () const + { + return true; + } + virtual tl::XMLElementBase *xml_writer_options_element () const { return new db::WriterOptionsXMLElement ("lstream", diff --git a/src/plugins/streamers/lstream/db_plugin/lstrWriter.cc b/src/plugins/streamers/lstream/db_plugin/lstrWriter.cc index ccd31f815..43e6af816 100644 --- a/src/plugins/streamers/lstream/db_plugin/lstrWriter.cc +++ b/src/plugins/streamers/lstream/db_plugin/lstrWriter.cc @@ -150,7 +150,8 @@ Writer::write (db::Layout &layout, tl::OutputStream &stream, const db::SaveLayou for (auto c = mp_layout->begin_top_down (); c != mp_layout->end_top_down (); ++c) { if (m_cells_to_write.find (*c) != m_cells_to_write.end ()) { m_cellname = layout.cell_name (*c); - write_cell (*c, kj_stream); + bool skip_body = options.write_context_info () && mp_layout->cell (*c).can_skip_replica (); + write_cell (*c, kj_stream, skip_body); m_cellname.clear (); } } @@ -911,9 +912,9 @@ Writer::make_meta_data (const db::Cell *cell, stream::metaData::MetaData::Builde * This method generates a single-view cell message (the view is only a layout view). */ void -Writer::write_cell (db::cell_index_type ci, kj::BufferedOutputStream &os) +Writer::write_cell (db::cell_index_type ci, kj::BufferedOutputStream &os, bool skip_body) { - bool needs_layout_view = ! mp_layout->cell (ci).is_real_ghost_cell (); + bool needs_layout_view = ! mp_layout->cell (ci).is_real_ghost_cell () && ! skip_body; bool needs_meta_data_view = mp_layout->begin_meta (ci) != mp_layout->end_meta (ci); capnp::MallocMessageBuilder message; diff --git a/src/plugins/streamers/lstream/db_plugin/lstrWriter.h b/src/plugins/streamers/lstream/db_plugin/lstrWriter.h index 9ebd751ac..b51d40d4a 100644 --- a/src/plugins/streamers/lstream/db_plugin/lstrWriter.h +++ b/src/plugins/streamers/lstream/db_plugin/lstrWriter.h @@ -114,7 +114,7 @@ private: void make_cell_hierarchy_tree (stream::library::CellHierarchyTree::Builder cell_tree); void make_meta_data (const db::Cell *cell, stream::metaData::MetaData::Builder meta_data); - void write_cell (db::cell_index_type ci, kj::BufferedOutputStream &os); + void write_cell (db::cell_index_type ci, kj::BufferedOutputStream &os, bool skip_body); void write_layout_view (db::cell_index_type ci, kj::BufferedOutputStream &os); void write_meta_data_view (db::cell_index_type ci, kj::BufferedOutputStream &os); void make_repetition (const RegularArray &array, stream::repetition::Repetition::Builder builder); diff --git a/src/plugins/streamers/magic/db_plugin/dbMAG.cc b/src/plugins/streamers/magic/db_plugin/dbMAG.cc index d4851fb4d..ccd8bc726 100644 --- a/src/plugins/streamers/magic/db_plugin/dbMAG.cc +++ b/src/plugins/streamers/magic/db_plugin/dbMAG.cc @@ -81,6 +81,11 @@ public: return true; } + virtual bool supports_context () const + { + return false; + } + virtual tl::XMLElementBase *xml_reader_options_element () const { return new db::ReaderOptionsXMLElement ("mag", diff --git a/src/plugins/streamers/maly/db_plugin/dbMALY.cc b/src/plugins/streamers/maly/db_plugin/dbMALY.cc index 0cee3c2e9..73823934b 100644 --- a/src/plugins/streamers/maly/db_plugin/dbMALY.cc +++ b/src/plugins/streamers/maly/db_plugin/dbMALY.cc @@ -161,6 +161,11 @@ public: return false; } + virtual bool supports_context () const + { + return false; + } + virtual tl::XMLElementBase *xml_reader_options_element () const { return new db::ReaderOptionsXMLElement ("maly", diff --git a/src/plugins/streamers/oasis/db_plugin/dbOASIS.cc b/src/plugins/streamers/oasis/db_plugin/dbOASIS.cc index 621deca28..e87c2723e 100644 --- a/src/plugins/streamers/oasis/db_plugin/dbOASIS.cc +++ b/src/plugins/streamers/oasis/db_plugin/dbOASIS.cc @@ -464,6 +464,11 @@ public: return true; } + virtual bool supports_context () const + { + return true; + } + virtual tl::XMLElementBase *xml_writer_options_element () const { return new db::WriterOptionsXMLElement ("oasis", diff --git a/src/plugins/streamers/oasis/db_plugin/dbOASISWriter.cc b/src/plugins/streamers/oasis/db_plugin/dbOASISWriter.cc index 49f7b7077..93e0cafd0 100644 --- a/src/plugins/streamers/oasis/db_plugin/dbOASISWriter.cc +++ b/src/plugins/streamers/oasis/db_plugin/dbOASISWriter.cc @@ -1727,18 +1727,23 @@ OASISWriter::write (db::Layout &layout, tl::OutputStream &stream, const db::Save write_props (cref.prop_id ()); } - // instances - if (cref.cell_instances () > 0) { - write_insts (cell_set); - } + bool skip_body = options.write_context_info () && cref.can_skip_replica (); + if (! skip_body) { - // shapes - for (std::vector >::const_iterator l = layers.begin (); l != layers.end (); ++l) { - const db::Shapes &shapes = cref.shapes (l->first); - if (! shapes.empty ()) { - write_shapes (l->second, shapes); - m_progress.set (mp_stream->pos ()); + // instances + if (cref.cell_instances () > 0) { + write_insts (cell_set); } + + // shapes + for (std::vector >::const_iterator l = layers.begin (); l != layers.end (); ++l) { + const db::Shapes &shapes = cref.shapes (l->first); + if (! shapes.empty ()) { + write_shapes (l->second, shapes); + m_progress.set (mp_stream->pos ()); + } + } + } // end CBLOCK if required diff --git a/src/plugins/streamers/pcb/db_plugin/dbGerberImporter.cc b/src/plugins/streamers/pcb/db_plugin/dbGerberImporter.cc index 176c527df..3464b955e 100644 --- a/src/plugins/streamers/pcb/db_plugin/dbGerberImporter.cc +++ b/src/plugins/streamers/pcb/db_plugin/dbGerberImporter.cc @@ -1206,6 +1206,11 @@ class GerberFormatDeclaration { return false; } + + virtual bool supports_context () const + { + return false; + } }; static tl::RegisteredClass format_decl (new GerberFormatDeclaration (), 1000, "GerberPCB"); diff --git a/src/tl/tl/tlExpression.cc b/src/tl/tl/tlExpression.cc index ef7b8345a..5328616eb 100644 --- a/src/tl/tl/tlExpression.cc +++ b/src/tl/tl/tlExpression.cc @@ -4108,8 +4108,6 @@ Eval::parse (Expression &expr, const std::string &s, bool top) void Eval::parse (Expression &expr, tl::Extractor &ex, bool top) { - ex.skip (); - expr = Expression (this, ex.get ()); tl::Extractor ex0 = ex; From ddb261d70879d94227d818c9a413f72fe5daba3d Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sat, 28 Mar 2026 22:05:23 +0100 Subject: [PATCH 07/21] Improving stability of library refresh 1.) Safeguard against missing cells 2.) Use topological order during refresh This avoid child-first issues 3.) Use cell names and basic names for mapping (cell names may be disambiguated while basic names are not) --- src/db/db/dbLibrary.cc | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/db/db/dbLibrary.cc b/src/db/db/dbLibrary.cc index 921ce25ce..0f4470006 100644 --- a/src/db/db/dbLibrary.cc +++ b/src/db/db/dbLibrary.cc @@ -108,10 +108,12 @@ Library::unregister_proxy (db::LibraryProxy *lib_proxy, db::Layout *ly) if (! --c->second) { db::cell_index_type ci = c->first; m_refcount.erase (c); - // remove cells which are itself proxies and are no longer used - db::Cell *lib_cell = &layout ().cell (ci); - if (lib_cell && lib_cell->is_proxy () && lib_cell->parent_cells () == 0) { - layout ().delete_cell (ci); + if (layout ().is_valid_cell_index (ci)) { + // remove cells which are itself proxies and are no longer used + db::Cell *lib_cell = &layout ().cell (ci); + if (lib_cell && lib_cell->is_proxy () && lib_cell->parent_cells () == 0) { + layout ().delete_cell (ci); + } } } retired_state_changed_event (); @@ -196,9 +198,9 @@ Library::remap_to (db::Library *other, db::Layout *original_layout) std::vector > pcells_to_map; std::vector lib_cells_to_map; - for (db::Layout::iterator c = r->first->begin (); c != r->first->end (); ++c) { + for (auto ci = r->first->begin_top_down (); ci != r->first->end_top_down (); ++ci) { - db::LibraryProxy *lib_proxy = dynamic_cast (&*c); + db::LibraryProxy *lib_proxy = dynamic_cast (&r->first->cell (*ci)); if (lib_proxy && lib_proxy->lib_id () == get_id ()) { db::Cell *lib_cell = &original_layout->cell (lib_proxy->library_cell_index ()); @@ -274,7 +276,7 @@ Library::remap_to (db::Library *other, db::Layout *original_layout) std::pair cn (false, 0); if (other) { - cn = other->layout ().cell_by_name (original_layout->cell ((*lp)->library_cell_index ()).get_basic_name ().c_str ()); + cn = other->layout ().cell_by_name (original_layout->cell_name ((*lp)->library_cell_index ())); } if (! cn.first) { From 062567f206d6b5cdbea91a2336b5127af41b78dd Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sun, 29 Mar 2026 19:41:19 +0200 Subject: [PATCH 08/21] WIP --- src/db/db/dbLibrary.cc | 39 +++++++++++++++++----- src/db/db/dbLibrary.h | 7 ++++ src/db/db/dbLibraryManager.cc | 20 +++++++++++- src/db/db/dbLibraryProxy.cc | 61 +++++++++++++++++------------------ 4 files changed, 86 insertions(+), 41 deletions(-) diff --git a/src/db/db/dbLibrary.cc b/src/db/db/dbLibrary.cc index 0f4470006..e3e4c353e 100644 --- a/src/db/db/dbLibrary.cc +++ b/src/db/db/dbLibrary.cc @@ -26,6 +26,7 @@ #include "dbPCellDeclaration.h" #include "dbPCellVariant.h" #include "dbLibraryManager.h" +#include "tlTimer.h" #include @@ -166,14 +167,36 @@ Library::rename (const std::string &name) void Library::refresh () { - // save a copy of the layout, so we can refer to it - std::unique_ptr org_layout (new db::Layout (layout ())); + refresh_without_restore (); - std::string name = reload (); - rename (name); + // proxies need to be restored in a special case when a library has a proxy to itself. + // The layout readers will not be able to create library references in this case. + layout ().restore_proxies (); +} + +void +Library::refresh_without_restore () +{ + db::LibraryManager::instance ().unregister_lib (this); + + try { + + m_name = reload (); + + } catch (...) { + + // fallback - leave the library, but with empty layout + layout ().clear (); + db::LibraryManager::instance ().register_lib (this); + + throw; + + } layout ().refresh (); - remap_to (this, org_layout.get ()); + + // re-register, potentially under the new name + db::LibraryManager::instance ().register_lib (this); } void @@ -198,9 +221,9 @@ Library::remap_to (db::Library *other, db::Layout *original_layout) std::vector > pcells_to_map; std::vector lib_cells_to_map; - for (auto ci = r->first->begin_top_down (); ci != r->first->end_top_down (); ++ci) { + for (auto c = r->first->begin (); c != r->first->end (); ++c) { - db::LibraryProxy *lib_proxy = dynamic_cast (&r->first->cell (*ci)); + db::LibraryProxy *lib_proxy = dynamic_cast (c.operator-> ()); if (lib_proxy && lib_proxy->lib_id () == get_id ()) { db::Cell *lib_cell = &original_layout->cell (lib_proxy->library_cell_index ()); @@ -217,7 +240,7 @@ Library::remap_to (db::Library *other, db::Layout *original_layout) } - // We do PCell resolution before the library proxy resolution. The reason is that + // We do PCell resolution before the library proxy resolution. The reason is that // PCells may generate library proxies in their instantiation. Hence we must instantiate // the PCells before we can resolve them. for (std::vector >::const_iterator lp = pcells_to_map.begin (); lp != pcells_to_map.end (); ++lp) { diff --git a/src/db/db/dbLibrary.h b/src/db/db/dbLibrary.h index b0883e788..05eef7bf9 100644 --- a/src/db/db/dbLibrary.h +++ b/src/db/db/dbLibrary.h @@ -225,6 +225,13 @@ public: */ void refresh (); + /** + * @brief Refreshes the library on all clients without restoring proxies + * + * This method is intended to be used internally for bulk refreshes. + */ + void refresh_without_restore (); + /** * @brief Renames the library * diff --git a/src/db/db/dbLibraryManager.cc b/src/db/db/dbLibraryManager.cc index e181855a3..304c27e9f 100644 --- a/src/db/db/dbLibraryManager.cc +++ b/src/db/db/dbLibraryManager.cc @@ -284,9 +284,27 @@ LibraryManager::lib_internal (lib_id_type id) const void LibraryManager::refresh_all () { + // NOTE: libraries may get deleted during the refresh, so better use weak pointers here + // to track lifetime. Libraries appearing are not considered. + + std::vector > libs; + libs.reserve (m_libs.size ()); + for (auto l = m_libs.begin (); l != m_libs.end (); ++l) { + libs.push_back (tl::weak_ptr (*l)); + } + + for (auto l = libs.begin (); l != libs.end (); ++l) { + if (l->get ()) { + (*l)->refresh_without_restore (); + } + } + + // restore proxies on all libraries - as the refresh happens in random order, dependencies + // are not necessarily resolved. This is done here. + for (std::vector::iterator l = m_libs.begin (); l != m_libs.end (); ++l) { if (*l) { - (*l)->refresh (); + (*l)->layout ().restore_proxies (); } } } diff --git a/src/db/db/dbLibraryProxy.cc b/src/db/db/dbLibraryProxy.cc index 8a4e043f2..cd93e048c 100644 --- a/src/db/db/dbLibraryProxy.cc +++ b/src/db/db/dbLibraryProxy.cc @@ -22,6 +22,7 @@ #include "dbLibraryProxy.h" +#include "dbColdProxy.h" #include "dbLibraryManager.h" #include "dbLibrary.h" #include "dbLayout.h" @@ -187,25 +188,6 @@ LibraryProxy::get_layer_indices (db::Layout &layout, db::ImportLayerMapping *lay return m_layer_indices; } -class LibraryCellIndexMapper -{ -public: - LibraryCellIndexMapper (Layout &layout, Library *lib) - : mp_lib (lib), mp_layout (&layout) - { - // .. nothing yet .. - } - - cell_index_type operator() (cell_index_type cell_index_in_lib) - { - return mp_layout->get_lib_proxy (mp_lib, cell_index_in_lib); - } - -private: - Library *mp_lib; - Layout *mp_layout; -}; - void LibraryProxy::update (db::ImportLayerMapping *layer_mapping) { @@ -215,29 +197,44 @@ LibraryProxy::update (db::ImportLayerMapping *layer_mapping) Library *lib = LibraryManager::instance ().lib (lib_id ()); const db::Cell &source_cell = lib->layout ().cell (library_cell_index ()); - db::ICplxTrans tr; - bool need_transform = false; - if (fabs (layout ()->dbu () - lib->layout ().dbu ()) > 1e-6) { - need_transform = true; - tr = db::ICplxTrans (lib->layout ().dbu () / layout ()->dbu ()); - } - clear_shapes (); clear_insts (); for (unsigned int l = 0; l < lib->layout ().layers (); ++l) { if (layer_indices [l] >= 0) { - shapes ((unsigned int) layer_indices [l]).assign_transformed (source_cell.shapes (l), tr); + shapes ((unsigned int) layer_indices [l]).assign_transformed (source_cell.shapes (l), db::ICplxTrans (lib->layout ().dbu () / layout ()->dbu ())); } } - LibraryCellIndexMapper cell_index_mapper (*layout (), lib); + for (Cell::const_iterator i = source_cell.begin (); ! i.at_end (); ++i) { - for (Cell::const_iterator inst = source_cell.begin (); !inst.at_end (); ++inst) { - db::Instance new_inst = insert (*inst, cell_index_mapper); - if (need_transform) { - replace (new_inst, new_inst.cell_inst ().transformed_into (tr)); + db::CellInstArray inst = i->cell_inst (); + + Library *real_lib = lib; + cell_index_type real_cil = inst.object ().cell_index (); + + // use the "final lib", so we refer to the actual lib instead + // of building chains of lib references + LibraryProxy *lp; + while ((lp = dynamic_cast (&real_lib->layout ().cell (real_cil))) != 0) { + real_cil = lp->library_cell_index (); + real_lib = db::LibraryManager::instance ().lib (lp->lib_id ()); } + + inst.object ().cell_index (layout ()->get_lib_proxy (real_lib, real_cil)); + + ColdProxy *cp = dynamic_cast (&real_lib->layout ().cell (real_cil)); + if (cp) { + // The final item is a cold proxy ("" cell) - treat it like + // a library proxy as it may become one in the future, but replace it + // by a cold proxy now. + layout ()->create_cold_proxy_as (cp->context_info (), inst.object ().cell_index ()); + } + + inst.transform_into (db::ICplxTrans (lib->layout ().dbu () / layout ()->dbu ())); + + insert (inst); + } } From 7cec679d39f29d23f74a72b8da44f6f36a1e7958 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Tue, 31 Mar 2026 21:35:33 +0200 Subject: [PATCH 09/21] Taking care of complex library reference scenarios where libraries self-reference and under the presence of stale references. Main issue is order of resolution and indirect references due to replication. Solution is to repeat resolution until saturated. A test is supplied. --- src/db/db/dbFileBasedLibrary.cc | 5 + src/db/db/dbLayout.cc | 12 +- src/db/db/dbLayout.h | 11 +- src/db/db/dbLibrary.cc | 152 ++++++++++++++------------ src/db/db/dbLibraryManager.cc | 33 +++++- src/db/db/dbTestSupport.cc | 53 +++++++-- src/db/db/dbTestSupport.h | 3 +- src/db/unit_tests/dbLibrariesTests.cc | 136 +++++++++++++++++++++++ src/lay/lay/layLibraryController.cc | 24 ++-- src/tl/tl/tlUniqueId.h | 11 ++ testdata/libman/design.gds | Bin 0 -> 41932 bytes testdata/libman/design_au1.gds | Bin 0 -> 13144 bytes testdata/libman/design_au2.gds | Bin 0 -> 8742 bytes testdata/libman/design_au3.gds | Bin 0 -> 7778 bytes testdata/libman/design_au4.gds | Bin 0 -> 7778 bytes testdata/libman/design_au5.gds | Bin 0 -> 7778 bytes testdata/libman/libs/EX.gds | Bin 0 -> 18210 bytes testdata/libman/libs/EX2.gds | Bin 0 -> 986 bytes testdata/libman/libs/NOEX.gds | Bin 0 -> 20476 bytes testdata/libman/libs/NOEX2.gds | Bin 0 -> 1082 bytes 20 files changed, 349 insertions(+), 91 deletions(-) create mode 100644 testdata/libman/design.gds create mode 100644 testdata/libman/design_au1.gds create mode 100644 testdata/libman/design_au2.gds create mode 100644 testdata/libman/design_au3.gds create mode 100644 testdata/libman/design_au4.gds create mode 100644 testdata/libman/design_au5.gds create mode 100644 testdata/libman/libs/EX.gds create mode 100644 testdata/libman/libs/EX2.gds create mode 100644 testdata/libman/libs/NOEX.gds create mode 100644 testdata/libman/libs/NOEX2.gds diff --git a/src/db/db/dbFileBasedLibrary.cc b/src/db/db/dbFileBasedLibrary.cc index 63086fda1..10025e650 100644 --- a/src/db/db/dbFileBasedLibrary.cc +++ b/src/db/db/dbFileBasedLibrary.cc @@ -37,6 +37,11 @@ FileBasedLibrary::FileBasedLibrary (const std::string &path, const std::string & : db::Library (), m_name (name), m_path (path), m_is_loaded (false) { set_description (tl::filename (path)); + + // preliminary name, may be replaced later + if (! name.empty ()) { + set_name (name); + } } void diff --git a/src/db/db/dbLayout.cc b/src/db/db/dbLayout.cc index 40557f375..9411dcef3 100644 --- a/src/db/db/dbLayout.cc +++ b/src/db/db/dbLayout.cc @@ -2987,6 +2987,14 @@ Layout::fill_meta_info_from_context (cell_index_type cell_index, const LayoutOrC void Layout::restore_proxies (ImportLayerMapping *layer_mapping) +{ + if (restore_proxies_without_cleanup (layer_mapping)) { + cleanup (); + } +} + +bool +Layout::restore_proxies_without_cleanup (ImportLayerMapping *layer_mapping) { std::vector cold_proxies; @@ -3004,9 +3012,7 @@ Layout::restore_proxies (ImportLayerMapping *layer_mapping) } } - if (needs_cleanup) { - cleanup (); - } + return needs_cleanup; } bool diff --git a/src/db/db/dbLayout.h b/src/db/db/dbLayout.h index ed62a60ab..e68b5746c 100644 --- a/src/db/db/dbLayout.h +++ b/src/db/db/dbLayout.h @@ -1115,7 +1115,16 @@ public: * Library updates may enabled lost connections which are help in cold proxies. This method will recover * these connections. */ - void restore_proxies(ImportLayerMapping *layer_mapping = 0); + void restore_proxies (ImportLayerMapping *layer_mapping = 0); + + /** + * @brief Restores proxies as far as possible, no cleanup included + * + * This method is equivalent to "restore_proxies", but does not include a cleanup. + * Instead it returns a value of true, indicating that something got changed + * and a cleanup is required. + */ + bool restore_proxies_without_cleanup (ImportLayerMapping *layer_mapping = 0); /** * @brief Replaces the given cell index with the new cell diff --git a/src/db/db/dbLibrary.cc b/src/db/db/dbLibrary.cc index e3e4c353e..fd457ba57 100644 --- a/src/db/db/dbLibrary.cc +++ b/src/db/db/dbLibrary.cc @@ -208,110 +208,128 @@ Library::remap_to (db::Library *other, db::Layout *original_layout) // Hint: in the loop over the referrers we might unregister (delete from m_referrers) a referrer because no more cells refer to us. // Hence we must not directly iterate of m_referrers. - std::vector > referrers; + std::vector referrers; for (std::map::const_iterator r = m_referrers.begin (); r != m_referrers.end (); ++r) { - referrers.push_back (*r); + referrers.push_back (r->first); } + // Sort for deterministic order of resolution + std::sort (referrers.begin (), referrers.end (), tl::sort_by_id ()); + // Remember the layouts that will finally need a cleanup std::set needs_cleanup; - for (std::vector >::const_iterator r = referrers.begin (); r != referrers.end (); ++r) { + // NOTE: resolution may create new references due to replicas. + // Hence, loop until no further references are resolved. + bool any = true; + while (any) { - std::vector > pcells_to_map; - std::vector lib_cells_to_map; + any = false; - for (auto c = r->first->begin (); c != r->first->end (); ++c) { + for (std::vector::const_iterator r = referrers.begin (); r != referrers.end (); ++r) { - db::LibraryProxy *lib_proxy = dynamic_cast (c.operator-> ()); - if (lib_proxy && lib_proxy->lib_id () == get_id ()) { + std::vector > pcells_to_map; + std::vector lib_cells_to_map; + + for (auto c = (*r)->begin (); c != (*r)->end (); ++c) { + + db::LibraryProxy *lib_proxy = dynamic_cast (c.operator-> ()); + if (lib_proxy && lib_proxy->lib_id () == get_id ()) { + + if (! original_layout->is_valid_cell_index (lib_proxy->library_cell_index ())) { + // safety feature, should not happen + continue; + } + + db::Cell *lib_cell = &original_layout->cell (lib_proxy->library_cell_index ()); + db::PCellVariant *lib_pcell = dynamic_cast (lib_cell); + if (lib_pcell) { + pcells_to_map.push_back (std::make_pair (lib_proxy, lib_pcell)); + } else { + lib_cells_to_map.push_back (lib_proxy); + } + + needs_cleanup.insert (*r); + any = true; - db::Cell *lib_cell = &original_layout->cell (lib_proxy->library_cell_index ()); - db::PCellVariant *lib_pcell = dynamic_cast (lib_cell); - if (lib_pcell) { - pcells_to_map.push_back (std::make_pair (lib_proxy, lib_pcell)); - } else { - lib_cells_to_map.push_back (lib_proxy); } - needs_cleanup.insert (r->first); - } - } + // We do PCell resolution before the library proxy resolution. The reason is that + // PCells may generate library proxies in their instantiation. Hence we must instantiate + // the PCells before we can resolve them. + for (std::vector >::const_iterator lp = pcells_to_map.begin (); lp != pcells_to_map.end (); ++lp) { - // We do PCell resolution before the library proxy resolution. The reason is that - // PCells may generate library proxies in their instantiation. Hence we must instantiate - // the PCells before we can resolve them. - for (std::vector >::const_iterator lp = pcells_to_map.begin (); lp != pcells_to_map.end (); ++lp) { + db::cell_index_type ci = lp->first->Cell::cell_index (); + db::PCellVariant *lib_pcell = lp->second; - db::cell_index_type ci = lp->first->Cell::cell_index (); - db::PCellVariant *lib_pcell = lp->second; + std::pair pn (false, 0); + if (other) { + pn = other->layout ().pcell_by_name (original_layout->cell (lp->first->library_cell_index ()).get_basic_name ().c_str ()); + } - std::pair pn (false, 0); - if (other) { - pn = other->layout ().pcell_by_name (original_layout->cell (lp->first->library_cell_index ()).get_basic_name ().c_str ()); - } - - if (! pn.first) { - - // substitute by a cold proxy - db::LayoutOrCellContextInfo info; - r->first->get_context_info (ci, info); - r->first->create_cold_proxy_as (info, ci); - - } else { - - const db::PCellDeclaration *old_pcell_decl = original_layout->pcell_declaration (lib_pcell->pcell_id ()); - const db::PCellDeclaration *new_pcell_decl = other->layout ().pcell_declaration (pn.second); - if (! old_pcell_decl || ! new_pcell_decl) { + if (! pn.first) { // substitute by a cold proxy db::LayoutOrCellContextInfo info; - r->first->get_context_info (ci, info); - r->first->create_cold_proxy_as (info, ci); + (*r)->get_context_info (ci, info); + (*r)->create_cold_proxy_as (info, ci); } else { - db::pcell_parameters_type new_parameters = new_pcell_decl->map_parameters (lib_pcell->parameters_by_name ()); + const db::PCellDeclaration *old_pcell_decl = original_layout->pcell_declaration (lib_pcell->pcell_id ()); + const db::PCellDeclaration *new_pcell_decl = other->layout ().pcell_declaration (pn.second); + if (! old_pcell_decl || ! new_pcell_decl) { + + // substitute by a cold proxy + db::LayoutOrCellContextInfo info; + (*r)->get_context_info (ci, info); + (*r)->create_cold_proxy_as (info, ci); + + } else { + + db::pcell_parameters_type new_parameters = new_pcell_decl->map_parameters (lib_pcell->parameters_by_name ()); + + // coerce the new parameters if requested + try { + db::pcell_parameters_type plist = new_parameters; + new_pcell_decl->coerce_parameters (other->layout (), plist); + plist.swap (new_parameters); + } catch (tl::Exception &ex) { + // ignore exception - we will do that again on update() to establish an error message + tl::error << ex.msg (); + } + + lp->first->remap (other->get_id (), other->layout ().get_pcell_variant (pn.second, new_parameters)); - // coerce the new parameters if requested - try { - db::pcell_parameters_type plist = new_parameters; - new_pcell_decl->coerce_parameters (other->layout (), plist); - plist.swap (new_parameters); - } catch (tl::Exception &ex) { - // ignore exception - we will do that again on update() to establish an error message - tl::error << ex.msg (); } - lp->first->remap (other->get_id (), other->layout ().get_pcell_variant (pn.second, new_parameters)); - } } - } + for (std::vector::const_iterator lp = lib_cells_to_map.begin (); lp != lib_cells_to_map.end (); ++lp) { - for (std::vector::const_iterator lp = lib_cells_to_map.begin (); lp != lib_cells_to_map.end (); ++lp) { + db::cell_index_type ci = (*lp)->Cell::cell_index (); - db::cell_index_type ci = (*lp)->Cell::cell_index (); + std::pair cn (false, 0); + if (other) { + cn = other->layout ().cell_by_name (original_layout->cell_name ((*lp)->library_cell_index ())); + } - std::pair cn (false, 0); - if (other) { - cn = other->layout ().cell_by_name (original_layout->cell_name ((*lp)->library_cell_index ())); - } + if (! cn.first) { - if (! cn.first) { + // substitute by a cold proxy + db::LayoutOrCellContextInfo info; + (*r)->get_context_info (ci, info); + (*r)->create_cold_proxy_as (info, ci); - // substitute by a cold proxy - db::LayoutOrCellContextInfo info; - r->first->get_context_info (ci, info); - r->first->create_cold_proxy_as (info, ci); + } else { - } else { + (*lp)->remap (other->get_id (), cn.second); - (*lp)->remap (other->get_id (), cn.second); + } } diff --git a/src/db/db/dbLibraryManager.cc b/src/db/db/dbLibraryManager.cc index 304c27e9f..b1d837985 100644 --- a/src/db/db/dbLibraryManager.cc +++ b/src/db/db/dbLibraryManager.cc @@ -249,13 +249,38 @@ LibraryManager::register_lib (Library *library) // "restore_proxies" takes care not to re-substitute cold proxies. const tl::weak_collection &cold_proxies = db::ColdProxy::cold_proxies_per_lib_name (library->get_name ()); - std::set to_refresh; + + std::set to_refresh_set; for (tl::weak_collection::const_iterator p = cold_proxies.begin (); p != cold_proxies.end (); ++p) { - to_refresh.insert (const_cast (p->layout ())); + to_refresh_set.insert (const_cast (p->layout ())); } - for (std::set::const_iterator l = to_refresh.begin (); l != to_refresh.end (); ++l) { - (*l)->restore_proxies (0); + // Sort for deterministic order of resolution + std::vector to_refresh (to_refresh_set.begin (), to_refresh_set.end ()); + std::sort (to_refresh.begin (), to_refresh.end (), tl::sort_by_id ()); + + std::set needs_cleanup; + + // NOTE: "restore proxies" can create new proxies, because indirect references. + // Hence we need to repeat the process. + bool any = true; + while (any) { + + any = false; + + for (auto l = to_refresh.begin (); l != to_refresh.end (); ++l) { + if ((*l)->restore_proxies_without_cleanup ()) { + any = true; + needs_cleanup.insert (*l); + } + + } + + } + + // do the cleanup + for (auto l = needs_cleanup.begin (); l != needs_cleanup.end (); ++l) { + (*l)->cleanup (); } // issue the change notification diff --git a/src/db/db/dbTestSupport.cc b/src/db/db/dbTestSupport.cc index de3f9789d..711eb8f2d 100644 --- a/src/db/db/dbTestSupport.cc +++ b/src/db/db/dbTestSupport.cc @@ -135,13 +135,52 @@ void compare_layouts (tl::TestBase *_this, const db::Layout &layout, const std:: db::Reader reader (stream); reader.read (layout_au, options); - equal = db::compare_layouts (*subject, layout_au, - (n > 0 ? db::layout_diff::f_silent : db::layout_diff::f_verbose) - | ((norm & AsPolygons) != 0 ? db::layout_diff::f_boxes_as_polygons + db::layout_diff::f_paths_as_polygons : 0) - | ((norm & WithArrays) != 0 ? 0 : db::layout_diff::f_flatten_array_insts) - | ((norm & WithMeta) == 0 ? 0 : db::layout_diff::f_with_meta) - /*| db::layout_diff::f_no_text_details | db::layout_diff::f_no_text_orientation*/ - , tolerance, 100 /*max diff lines*/); + if ((norm & WithoutCellNames) != 0) { + + // in this case, the layouts need to have one top cell + + db::cell_index_type top_subject = 0, top_au = 0; + size_t n_top_subject = 0, n_top_au = 0; + + for (auto t = subject->begin_top_down (); t != subject->end_top_cells (); ++t) { + top_subject = *t; + ++n_top_subject; + } + + for (auto t = layout_au.begin_top_down (); t != layout_au.end_top_cells (); ++t) { + top_au = *t; + ++n_top_au; + } + + if (n_top_subject != 1) { + throw tl::Exception (tl::sprintf ("With smart cell mapping, the subject layout must have a single top cell")); + } + if (n_top_au != 1) { + throw tl::Exception (tl::sprintf ("With smart cell mapping, the reference layout must have a single top cell")); + } + + equal = db::compare_layouts (*subject, top_subject, layout_au, top_au, + (n > 0 ? db::layout_diff::f_silent : db::layout_diff::f_verbose) + | ((norm & AsPolygons) != 0 ? db::layout_diff::f_boxes_as_polygons + db::layout_diff::f_paths_as_polygons : 0) + | ((norm & WithArrays) != 0 ? 0 : db::layout_diff::f_flatten_array_insts) + | ((norm & WithMeta) == 0 ? 0 : db::layout_diff::f_with_meta + | db::layout_diff::f_smart_cell_mapping) + /*| db::layout_diff::f_no_text_details | db::layout_diff::f_no_text_orientation*/ + , tolerance, 100 /*max diff lines*/); + + + } else { + + equal = db::compare_layouts (*subject, layout_au, + (n > 0 ? db::layout_diff::f_silent : db::layout_diff::f_verbose) + | ((norm & AsPolygons) != 0 ? db::layout_diff::f_boxes_as_polygons + db::layout_diff::f_paths_as_polygons : 0) + | ((norm & WithArrays) != 0 ? 0 : db::layout_diff::f_flatten_array_insts) + | ((norm & WithMeta) == 0 ? 0 : db::layout_diff::f_with_meta) + /*| db::layout_diff::f_no_text_details | db::layout_diff::f_no_text_orientation*/ + , tolerance, 100 /*max diff lines*/); + + } + if (equal && n > 0) { tl::info << tl::sprintf ("Found match on golden reference variant %s", fn); } diff --git a/src/db/db/dbTestSupport.h b/src/db/db/dbTestSupport.h index 368c1bad8..df013f8a1 100644 --- a/src/db/db/dbTestSupport.h +++ b/src/db/db/dbTestSupport.h @@ -59,7 +59,8 @@ enum NormalizationMode NoContext = 8, // write tmp file without context AsPolygons = 16, // paths and boxes are treated as polygons WithArrays = 32, // do not flatten arrays - WithMeta = 64 // with meta info + WithMeta = 64, // with meta info + WithoutCellNames = 128 // smart cell name mapping }; /** diff --git a/src/db/unit_tests/dbLibrariesTests.cc b/src/db/unit_tests/dbLibrariesTests.cc index 1d48e852e..bbe74b65d 100644 --- a/src/db/unit_tests/dbLibrariesTests.cc +++ b/src/db/unit_tests/dbLibrariesTests.cc @@ -32,6 +32,8 @@ #include "dbReader.h" #include "dbLayoutDiff.h" #include "dbTestSupport.h" +#include "dbFileBasedLibrary.h" +#include "dbColdProxy.h" #include "tlStream.h" #include "tlStaticObjects.h" #include "tlUnitTest.h" @@ -698,3 +700,137 @@ TEST(6_issue996) CHECKPOINT (); db::compare_layouts (this, ly, tl::testdata () + "/gds/lib_test6b.gds", db::NormalizationMode (db::WriteGDS2 + db::NoContext)); } + +static size_t num_top_cells (const db::Layout &layout) +{ + size_t n = 0; + for (auto t = layout.begin_top_down (); t != layout.end_top_cells (); ++t) { + ++n; + } + return n; +} + +static size_t num_cells (const db::Layout &layout) +{ + size_t n = 0; + for (auto t = layout.begin_top_down (); t != layout.end_top_down (); ++t) { + ++n; + } + return n; +} + +static size_t num_defunct (const db::Layout &layout) +{ + size_t ndefunct = 0; + for (auto c = layout.begin (); c != layout.end (); ++c) { + if (dynamic_cast (c.operator-> ())) { + ++ndefunct; + } + } + return ndefunct; +} + +// monster lib refresh issue +// (monster lib is a layout with manifold library references to existing and non-existing libraries) +TEST(7_monsterlib) +{ + std::pair lib; + + // tabula rasa + lib = db::LibraryManager::instance ().lib_by_name ("EX"); + if (lib.first) { + db::LibraryManager::instance ().delete_lib (db::LibraryManager::instance ().lib (lib.second)); + } + lib = db::LibraryManager::instance ().lib_by_name ("EX2"); + if (lib.first) { + db::LibraryManager::instance ().delete_lib (db::LibraryManager::instance ().lib (lib.second)); + } + lib = db::LibraryManager::instance ().lib_by_name ("NOEX"); + if (lib.first) { + db::LibraryManager::instance ().delete_lib (db::LibraryManager::instance ().lib (lib.second)); + } + lib = db::LibraryManager::instance ().lib_by_name ("NOEX2"); + if (lib.first) { + db::LibraryManager::instance ().delete_lib (db::LibraryManager::instance ().lib (lib.second)); + } + + // first, read the layout with only EX and EX2 in place + + db::FileBasedLibrary *lib_ex = new db::FileBasedLibrary (tl::testsrc () + "/testdata/libman/libs/EX.gds", "EX"); + lib_ex->load (); + db::LibraryManager::instance ().register_lib (lib_ex); + db::FileBasedLibrary *lib_ex2 = new db::FileBasedLibrary (tl::testsrc () + "/testdata/libman/libs/EX2.gds", "EX2"); + lib_ex2->load (); + db::LibraryManager::instance ().register_lib (lib_ex2); + + db::Layout layout; + layout.do_cleanup (true); + + { + tl::InputStream is (tl::testsrc () + "/testdata/libman/design.gds"); + db::Reader reader (is); + reader.read (layout); + } + + // as NOEX and NOEX2 are not present, a number of references are defunct (aka cold proxies) + EXPECT_EQ (num_defunct (layout), size_t (15)); + EXPECT_EQ (num_cells (layout), size_t (46)); + EXPECT_EQ (num_top_cells (layout), size_t (1)); + + // NOTE: normalization would spoil the layout, so don't do it + // The golden layout is a spoiled version that uses preliminary cell versions for the + // unresolved references of NOEX and NOEX2. This is intentional to test the replication. + // Also note, that the golden file has static cells. + db::compare_layouts (_this, layout, tl::testsrc () + "/testdata/libman/design_au1.gds", db::NormalizationMode (db::NoNormalization | db::WithoutCellNames | db::AsPolygons)); + + // then, establish NOEX and NOEX2 too - this will update the libraries in the layout that was read + + db::FileBasedLibrary *lib_noex = new db::FileBasedLibrary (tl::testsrc () + "/testdata/libman/libs/NOEX.gds", "NOEX"); + lib_noex->load (); + db::LibraryManager::instance ().register_lib (lib_noex); + db::FileBasedLibrary *lib_noex2 = new db::FileBasedLibrary (tl::testsrc () + "/testdata/libman/libs/NOEX2.gds", "NOEX2"); + lib_noex2->load (); + db::LibraryManager::instance ().register_lib (lib_noex2); + + // all references now need to be resolved + EXPECT_EQ (num_defunct (layout), size_t (0)); + EXPECT_EQ (num_cells (layout), size_t (34)); + EXPECT_EQ (num_top_cells (layout), size_t (1)); + + db::compare_layouts (_this, layout, tl::testsrc () + "/testdata/libman/design_au2.gds", db::NormalizationMode (db::NoNormalization | db::WithoutCellNames | db::AsPolygons)); + + // refresh must not change the layout + lib_ex->refresh (); + lib_ex2->refresh (); + lib_noex->refresh (); + lib_noex2->refresh (); + + // all references now need to be resolved + EXPECT_EQ (num_defunct (layout), size_t (0)); + EXPECT_EQ (num_cells (layout), size_t (29)); + EXPECT_EQ (num_top_cells (layout), size_t (1)); + + db::compare_layouts (_this, layout, tl::testsrc () + "/testdata/libman/design_au3.gds", db::NormalizationMode (db::NoNormalization | db::WithoutCellNames | db::AsPolygons)); + + db::LibraryManager::instance ().delete_lib (lib_noex); + db::LibraryManager::instance ().delete_lib (lib_noex2); + + // after removing the libraries, we have defunct cells again + EXPECT_EQ (num_defunct (layout), size_t (8)); + EXPECT_EQ (num_cells (layout), size_t (29)); + EXPECT_EQ (num_top_cells (layout), size_t (1)); + + // but the layout did not change + db::compare_layouts (_this, layout, tl::testsrc () + "/testdata/libman/design_au4.gds", db::NormalizationMode (db::NoNormalization | db::WithoutCellNames | db::AsPolygons)); + + db::LibraryManager::instance ().delete_lib (lib_ex); + db::LibraryManager::instance ().delete_lib (lib_ex2); + + // after removing all libraries, we have even more defunct cells (i.e. all, except top) + EXPECT_EQ (num_defunct (layout), size_t (16)); + EXPECT_EQ (num_cells (layout), size_t (29)); + EXPECT_EQ (num_top_cells (layout), size_t (1)); + + // but the layout did not change + db::compare_layouts (_this, layout, tl::testsrc () + "/testdata/libman/design_au5.gds", db::NormalizationMode (db::NoNormalization | db::WithoutCellNames | db::AsPolygons)); +} diff --git a/src/lay/lay/layLibraryController.cc b/src/lay/lay/layLibraryController.cc index e507b7e93..227396c48 100644 --- a/src/lay/lay/layLibraryController.cc +++ b/src/lay/lay/layLibraryController.cc @@ -289,22 +289,30 @@ LibraryController::sync_files () } for (std::map::const_iterator lf = m_lib_files.begin (); lf != m_lib_files.end (); ++lf) { + + std::pair li = db::LibraryManager::instance ().lib_by_name (lf->second.name, lf->second.tech); + if (! li.first) { + continue; // should not happen + } + + db::Library *lib = db::LibraryManager::instance ().lib (li.second); + if (new_names.find (lf->second.name) == new_names.end ()) { + try { - std::pair li = db::LibraryManager::instance ().lib_by_name (lf->second.name, lf->second.tech); - if (li.first) { - if (! lf->second.tech.empty ()) { - tl::log << "Unregistering lib '" << lf->second.name << "' for technology '" << *lf->second.tech.begin () << "' as the file no longer exists: " << lf->first; - } else { - tl::log << "Unregistering lib '" << lf->second.name << "' as the file no longer exists: " << lf->first; - } - db::LibraryManager::instance ().delete_lib (db::LibraryManager::instance ().lib (li.second)); + if (! lf->second.tech.empty ()) { + tl::log << "Unregistering lib '" << lf->second.name << "' for technology '" << *lf->second.tech.begin () << "' as the file no longer exists: " << lf->first; + } else { + tl::log << "Unregistering lib '" << lf->second.name << "' as the file no longer exists: " << lf->first; } + db::LibraryManager::instance ().delete_lib (lib); } catch (tl::Exception &ex) { tl::error << ex.msg (); } catch (...) { } + } + } // establish the new libraries diff --git a/src/tl/tl/tlUniqueId.h b/src/tl/tl/tlUniqueId.h index 54bf1f9d7..8d065a8af 100644 --- a/src/tl/tl/tlUniqueId.h +++ b/src/tl/tl/tlUniqueId.h @@ -75,6 +75,17 @@ inline id_type id_of (const UniqueId *o) return o ? o->m_id : 0; } +/** + * @brief A sorting operator of pointers by ID + */ +struct sort_by_id +{ + bool operator () (const UniqueId *a, const UniqueId *b) const + { + return id_of (a) < id_of (b); + } +}; + } // namespace tl #endif diff --git a/testdata/libman/design.gds b/testdata/libman/design.gds new file mode 100644 index 0000000000000000000000000000000000000000..452c0f56d9564883c63e27486b8fe13c5b417dd5 GIT binary patch literal 41932 zcmeHQ&5vBg5wD${9ghcp$B;xZLTCpq8&+Yy3?|YdygR$X!m^Fz!wQI2i@gR*i$UxP z5{V!VIV5*($-#$6x%dx2$|VPsGk*Yo0OFKG4oF<6U-zq?em!q`W}e^M_lD^w&DL!9 z>yKAeT~%GxQ;%v?sqE0Dh02NVX_20$^VFgz?eA2t)UIFKAiB7?^y<~Wz5K?1|MkCD z`d_{H@b7Qkrb|ns+dWmQHJi=Nn>TK6?cCnIc4PY{|4Y>d(WwhHlr=AR`TMy=lB@PY zh0f5Kwc4%Ct?Sp#po_To z;P9ipJNF-`s;H(xzfv`Of7<_eb^YxFz~8rDZ2dvCJE_~-Y8!4);|} zoi3r>y$>H8?LOH1fa_KckM8c`{}nyv2{mVR2T!G?TGi+RTJ7Jvw|nquG(kMe(xCh< zPh)xcvhJfgD8Hlbe@XYVXqCT@`>*Koik|PC;pbe?czO5!-XZRfo}MsArsMj?-r@Z_ zMAh^Bv1!psLyLZUHff=8zNB#o8fjXzem9aDy2UUxbb02~Xa{O6mxmg>hNhQOVQu8I zHhQlFYLsVf^sc0##`bLLjYvBT>5a}vz0n<^#e4Z^@m@NMDo{h&Y*}mZUMia^*tf8g zGp9u=9Uf?r2Q9imgY&*@q|SKhc=sCJR2n>3xA|DN-IvqYQ-K;eQG?fF*!h)4QnCF# zJvG8!BcHuSH=U1aHodo{-}&)IGsW8I2WsT9^J}Nl;z3g7BdOY{w0PM2Wx4ljL@~c^ zkWz(v3xyV)K#Rg@QNK{zZZ$6tQDT8kt<_W*eA|uS-nhB7!=6Qn;BpWBc5|4PgC6>9 zsbMV>HFOMkYsYTA-S&@fTJww$L5__svHV^tjkh_Qp63W7Lvet@eLCQ#cC+W>CNDL? zOD#Vy8E%ZY0o)klrj~zv(>^+n;Bd3yC!Xi@d%ewI&t_`RYUwnrvj?(eGU?PFqUE56 z@zTjVzL%eco4UPJ+!Ul!rrczxkuEMao75=1=b)1=8WSXKE^DKcE*cZ4kqbD_kUwHwMJ=o7={|DEUJwlr}B|gsm^_csBu0~<4!93Hc%rcYNYZc1Zw0& zjdXF!pv8018|_qkzYwR)HcnZC*Vf}9<4Q$+_F*M>;JJ0b9_QZ^ zd$66#IuHKZY&l6Hd&3cc@Vm<0WBpwvd(Jo8P2Z~CG^=_zDkrO|m+IugR?wEYXv&$Zjg%$5!BjO!+{cJn)@D z@msO_j`arGKniaGD&li zZ|re1e?^wBvR8FJc>=6CpuS5cW`4Q3LcSHiuJ|ueLD z_H@Sk662w7T+$~XJ}Ad$<(!7U{Xv&MeSJ{>02U{W9;WHX^3_x2gH3SN59e! zAnr#!u4o=f^IXF`pLvbw)_E9 z_z1p1hZEmudVp>y$Nka{Wxxd>aD#rWE9u#fFdy`ROU4E+FfJha0`38SeOHf-`!E+k zl;b|&7dR7$_CfrOKF1Vml!#ii@MN>5O@|t&l4v(1`t4 zCHCzhgNjR|AZy~X26;`2#?idWl13B<=nhdJNPG5L!xIQ^w0Nis*u@EjI)OqZjpNj7 zI`>KJJrr`92XPqwsJ-UNczmMvEb;@_&vImC@jFt{rG@_!$!E1nbmgB!0;QbcBs*80 zmCC1L&&uSSw`bMh^Vsqx6SgQ+ynj?ZTZP_w`NfdkKHH}by`|%p`N7*5j}BHVG6luf z1$%df_&QsRjhU6~yO4j#wS^ub_R12%T=E^73EvS*MVu87aaM`9;ycO(BIb)&FX|yn zr9H~g56bYtciabv_9z3yszzS|rJnf0cfOQls>kJASz{@h6MAt@D23cc?joB%O;$`> zt~Lg8+vG5{>$BzGYb^oI|jdwrRYC_DaSZ%ovrHFKC`YD%4)kAoR{E?N7-?N%xErO2Jas4flA=r6Fx@1 zv_K=?XO=jY(@EHyA9pNgUhQ7Lf#^HQUxMEQpd9x}J3!ozKCNq({3eDL3HHvZ}HtV4zn^UkDKzZjfT(sk z`=lMp(68VS_u~SDw*+_=s4DcInZ$8|cVyOZJg-ue?Ilk57L%bPPCn`^OHrQE1Q}}H zLY5#y%^S`Nlc9LdxTS91FlF0?4bc^mRh;mgCd*C2bGDjMyTYDRbOmzkxpJ>)T`{j~ zOvmz_b8dy7@xsX)WV*7~zIm6CvnFIOW!^kBqW))hdT%;APfoQ6bnU!sdmFRs1lPHz zD-qWlvX75-RwAE}v(c4Lk6@RWi~R+=4EB?4+rqxW2jv3o=oaicX^(RBi86ff z9X1>w+M^5*+>O2jNVi%wpK-VB2#R&9``yvnsMEEg!w~H;}U(1EQ-*#fY8SUWL;#Lt@6Rz+ReN< z#pVQ-aGb-GV-HF;I{QYhkvG0LyGFE$a<&$>XJj3)71sggEf&rbB0H|x|2ofTXU<)C z?bg7LI-UG{y-$_?MIwQg#8Ecan3ckmznXsK_aB^&;cKeoz_i#Iwgho>Q literal 0 HcmV?d00001 diff --git a/testdata/libman/design_au1.gds b/testdata/libman/design_au1.gds new file mode 100644 index 0000000000000000000000000000000000000000..5419c775426281eabf3b77fe528734a0715c6398 GIT binary patch literal 13144 zcmeI2zi%8>5XZ;s^ZMdABq2c%VH6<_@k2=D?$*R$|EGx2vkyg1KNc~{Gkl|k zr8?)ud*1`z$J#Vo6UvW%ejl83^y7bB|2wzF{5S49-ohUu^z-ibR~%&?{ZPiy&$_k_ zl=1LsnH(WGKS9pRH$+Z7bM*WJk@r3nF>3uv)A@_Cul|>u{(A#YBlklVIJ4`d<84JP zA$?KXSYh#nvj$ef3XHdT^q~nTnql2S3+=qE7Fy0Ml&pYuvf$`uT) zZTEbGYrYLmZYT8v74kX5Qr(^}KPPJ^HcEZ%OXS=~ZKEXM%Vza{GF>%2vQ7d~+pO!n z_4m=L@9Un0s#oQ>jyTKWHh9EoP<~XZpv5?^7!TSQ=Fo3-Mx(49iu-%oiF$sen&cSC$1PpZT}(-B4si1X8Scl_Mjf6(Sy}ML0$oYY_~z z&}K1$84jDLv$jSWhT}m1$GbCH$+bJG?KVvUS=(=A-$eFB#T?&6)&#ZxAt2hc?9KcS zWAIZ(>Bmno&gRj_y5_4GPlJ-3;m?ew4EJXieOVI7#%4{&Z9OOY4T~(R=dv1$E%^R1 z-Ppoq62oTYHkw70^t2Yx(~|aCjIG}=JUtfpuUr;VZ%$M1Y6nODn`Qe_#|_y}>k)ct z634s#lm5~ZcgTc{e52CTiwWLMVVY~=_*<#75{HH zU8z9Bq*vpMktb7*-psNkJb-#K)O20|5uB`)7eIu?st42?3<*Z7Yk#v}^51puR8NK0 zCd-gn5*2^r&pr6EJC7Q|)*bha$<0%o=D7UnMUkWD4Nmmc Z)3JxsIjrdXPR=c@SeR!kYQ)>=$p6Pr8m<5U literal 0 HcmV?d00001 diff --git a/testdata/libman/design_au2.gds b/testdata/libman/design_au2.gds new file mode 100644 index 0000000000000000000000000000000000000000..c3e3d4925b4d600a192c13659ee3e3db34567572 GIT binary patch literal 8742 zcmeI2KW`LC5XH;m^>{G`n?EOnFhb~j;*XHpi=s7~ z8j40g*svY3eKu#~*?Vh7@zu*qX8VUn&M!V*xbpVjkLNnCPCtM8&#Fz0Y%nj5S69|n zt_dGHC^SGH%{f^1}QQI*7V0wgl5n`vcl{<|_Xo-))v+soRaP2MGX-W_rR9%|IFR}Dfz({q63TAgxc9bQ zTe}Lz#ORzgntA>4rtI|VXOM`BA#5-La&gjuSw^$WYYcPfmrfC~b{WH*@ANZH^FYS4 zW~Oa3-D6tyuf0&Le_M6;*1cXT=CgCfnEz_~tL|LHaeQ&c8e?Y7z2S>%oC?P|;a5^A zcH}Eye3Y-T=0rHzlJAb8PiDGKG|bMvFcYfZ@p}|o6Mv???$*qs`FeTOnc>UKV>A|6 z^S=$2H}c5!PsXG6x*lmy{QOL6rI|FIMu~5w_2RT?UUgb2ck&ADJy@@#cNPkI=T@2C zL04oIYroz>gG{*Q0Hs@mjFm0{Gi_U!^mK_B@w(H@*WYLTjG!dZ`7nY41oe9gbzDkR zQD+S72=~<(3SFL=&g+?0@r(}sCVDkFzt2DDspeoybXsD&=M_?l+HLV( z^ipE^FEgu})<$Q4aqTUvsI^_QEeGu{6}izn&IfO|-a9Vk-_ietYS3Re%dIrGqyYK# zq2N`TU1-?ERuXxXWMV7Hu9;vd$u3o>Z|HAjm9TntErlJVx8!@j@Rn)Df2U9SsuWiD zX(gWx3q_AY+!K!QcId*j+|Kpy^Boud=uA)cu}E7rEgl2MSM%H zmqj(GQHy!T(mIs=g(B2b-{(Kb37LLBt*2l`PQ0G3QWF=#aG ED+j(2G5`Po literal 0 HcmV?d00001 diff --git a/testdata/libman/design_au3.gds b/testdata/libman/design_au3.gds new file mode 100644 index 0000000000000000000000000000000000000000..10b4c7ba8be4ade0033f738d8979e21197914ea9 GIT binary patch literal 7778 zcmeI1Jx>%-6owD8%doB>0vcn)7^B9In8*_OY6##$G?Iu31u>SE78aIjEG)FA(}Kdp zh95v;V_~fM0sa7EWnp1r<9+7NJIw41xD%r+$W4ZKxLD{-f=Ek+P*Y}ofxO<0nVYocMvTW6wS=bj? zVBwL#%Nf85m>)tw^mi7|Xr@ajeJ)52lSc3)TYaM-f z0>m@yn`%XG{=YKR8#B}x*^1h(e|$>xyvM`@JkrEJ(Fpe-d=mZO$p@Z)<`EAd{mdi6 ziCQ7+bqYXQ{G2jTJefqXEbf#jmOY*B!A9aiW#V->haWZFi+?zTUl4x9GxzihIq#fv z#yRs^Pd|Io$HhJKK-SX-l26!6sBv?Rd)E%~MpB(knSIQvwQOzuSd`gY8N{Pvh%p!e zxya&Rn$a}#n!_6URfC1>UBoc8i+<*59mst4Otk~1^Gr`AOe@>$)w3)6J2hLXCXbHg zYw~_OU7gNF7={ZYR;`=W2K~20FZqos;jSo89Lnau@GRdMwSHgMB1PTx-Avczs@ddQ zGokt&wxdOA*mK_1(N40cIfBA>7S+9v+;6+@rAF+f-qeIJ$=||~Z;9Wtii>Zm$l3x0-=tC5Zo2>g%A?mh@xPGErM8DT3A@BSXgMEP74dc zCO;rxVN-v-7o@K{RX3g~>a)UvuWX=brOUVxa}Ws!jF)r0W*)r)2m{R0b2&t|W^fBj{?wQ=_4^IL739Qet)Fl;Zcwyjn-3wH+= zShy!Jv)g0+?q{kUS~c7E)J%Bbo>~7VGvVkwZik(cpiJxv?s_# zKi7#dkEg%+{=?ThUS8eAGDwPf7ttf>RiDi56T$Wz3#2!X=yKEecIcwF!;f<0c)_pe66Do zPk?xaeN(OM&Hq=1Mq-AVjZW0|{pC}l=iMhJ;E^W&iAJ~w;gjeG58m1Q4h zPSgrnuTuch;^$O};<+S>WpS@WvFzz}4>l7IDig26IsB;UUi`x${DSZ+p1G%A$a&|S zGtQaUdivRuJ}&N=2eO_%kbJ^kLXDei+`G1uHcbDHTm3h zu_kY~)79%-gkgBOVYOki`ndm=7$Lt=CEOL|iJ@%%3y<=hQ6KenEmG8dU(Ix#s+rBb zG83xb;byc*9ebu+9qlEHS`8GwvuN1+$o;nUUTVf(8i{Q};dZl1QTS)MBbGdKy7A^9Aj~K$* zzQvVHOuKK9=+qQAsTM<5S{Ae>%!C!+#OXAwh;_E2Xj`7%r7UAJrHr{u<4*Z+azdm( ziZcyZkrNm3%h`yh;uj)57hhJ)r%8NeVlR%bO`a6Rm9XNw5MM63a`Ck-v(!?Kv$8DZ zYnjVu-6Cw0to&w#xysSL;nES``!3?0<3vO&yUGJ1K%|AoV^b5WX%Jo%6wac7N@ a;O5&*&SOWPZIaR4j;VFp(fxn2R97_J7z7NpJ;@85I%{1aQc?#pLxUsNI&z4 zaH3YodYuB07C)y<6fY%FEQ|Xkie*o~d$5ssP?`7@oWqZr?!`YG!Y>HF;+cE;g`9WJ zIpdspt*4(o>Eq&_c_8cQ1IZ`sCDgdN#=UEUypdFAQ)ZvHYAst^-xX!{P6qL)7-9@Y zKrXU4m}WH1yymcme$`+hdlxZG?V_J~S_d+pJyUJKbe`$uglT1)fA#Fj{(jAts>$c( z^EG*=ovwc8A`HU|vsSH})h7M7#2ERFD&ejuPmE^sUwDM?jM})bYmuU^d^OW`s%p0M z!c3@shrMW#8ulD>b+n%>YR;nYokex;Blp|(d#Mq7X)Lx0h1<<4Md6?2j#%={^^Z+1 zo|=sg_LjEUPtq2PNyU*`yj`R%sNrdK*r_e3_tbY#8bQchX#gj`&0siTi%{v8zAlrDvob8u|KDkMvihe4-k@^02MH{8*$xqOtq#^h=w$ zv2c>A8;!h4ttzM5P;B3wiW8PpZLadKdljj7oX@{wIg6wpg(WS*?@~yzX*q9G?005% z^E>LHo8M>sNP*uKm%mV4^0%<$TjKYu;^LbsvbI3M_h^$mE-Y`;Mm81}^A>r(M+{+Y zW%XJnrrozlbZT;(l#8K@O$(Y+X2Ozh;&d8T#5!A1v?EXNT9&beLdIOCai{z@IU&*? z#F+*x$%%{jjcmkI@pBR15nqe3P4`!3?0gd*{v_=6Ydf(tDHfy_|E;=lk`%=e$*U zDxcq0*K_&7e^o)frbgAfYSMjIUfx^XR^x?%_r|~a`~6?WzrOqOlkfg1e|uM5A86g` z70;WRnyPMYY^`o@?cCp3+r*!$IHc6@n8&iI%5A(~Ehu@sxAJO4jm&xvs;leki~L5h z?25XIvN!AdkLxpw(`%J!T{>(^AJ#sZS)81#l$9>Mtj786(aGnv-NR#DWow4itGcH4 zWdG63;s-~hcPsCdKho_knRbWAU+h0R*`HZFs2!c`>zb0f&UOc%9oKh`YY$O3eNx}s z;os9{%t1Y8{RO5{)~!4>##Z|W2Rlb!a)LL_w*zJzmhWL2laq6A+nQpd#jb8~!}L^e z%0Fd`c~hP@J?%EHG-r0^FY2#ZmlRZrn=3jg@kW+?dO_ z;p+yZB7tu7CpVzH)boLcq#NC6r5U$cXvV@hX~vC=7h=DftkgyGVlD|UR{GOtR9g6q za!a298%|AX@)--JJawOe8Fp@^GH#p`H{j_rZgg8WhAg_hlkuYKc1n1$kboCioRKb? zDvfz-m8nV-Cvs|d*3$vsn)P?EVkS~q-G;Z9IK>e;vV^Zn#E%R+oYT2WB5vHvv?EpR z0Cr$}8NrLQMwlihh{N?OF}9N9Bf^Xy-?!D#QHj{wTM@mqN2A%fYKr2`CP{(P&QX;obg9xLmxv1VtvLQY)AYr?O9IEWEp>a*D(sHj%`rp$2jPhyTm^E9n1BDcRX4u zN=C+H{x51Q1L?=LZ$Qo@bF*u52I<%L%$$|nZrRKrcTR2|c3GL*uU7RySNcw-RlQ_L zy7lQ=p{zG(UIOd=;_O=+d_he$9zk@%W@w$C%(j`4AfDU4HxLBUuiilB-|NvLGcStP zgUOtKk2)O;dt7=$@u;k$2PM@%oQ9FQ9+)1K--~zViJ5MLaye-g+R`IGH*NSG`w<%O z%rFjkT+b})>Q!Ed^xtgaM27eEzlT%s<2oBcBvr81MeUD__X1-(Bsv7J9guqz4hm#? z4nNcAS?eM&mXkwz4Jrz6BQ1_PEPWFUst7|3i4tdh~e&&J=v~WHm$(l+XgosYx0&*>)^rzodMqd3;ED_ef0> z%5wYklePg3*-R4G4%?j6u5sR+B!KJb%3IbOBs7cVfm;%uIa6Cq-V?P2=%bM}9HA>` z#8EOAp&jBVv69TA3R}siVJjJB9cjhHI`Uocgtl@#jh!$SFwQ#C^3swzPd`~fc)!)4 z_w%!WUA`KgH*$=Jp9OHWlfArjwNcZV)fuTPRWIUyU}0&8(twq$1Xtqc*SRa{Y)&GX zLOY)m60fN-5m~+NtnfuBvoW;82JhRf#Sq>PMo0U;O{E&{cLX)>vSm=>u8IqPiwif}u6yr&Gn#6@1|H|VbMLw5&bu?vP^yKjrP5chv509bp)$IMt8}fk z0?gZ~_2Tz$r+dX8YtL^MFZ_iF+0>tPPqfbG^PA1>-CAq6y|rC$(h<%$;Ld60Fgar* zdGxYE2AQ(n*{n4hp2V4(!VGc6C^(5qUZGwsfZ0jI9{BG|UM^RyK-dY)bM7Gg=y&=< z3B{3dEJ(!v6dabkHv`7C>dVSo(Ty2he|QuehC#{e`GYW!h>I-idLM>Sd*~lftPn=s zHlGW|Gc7$!2DMTVmBt*af?lsZIOYalo7|M~VZKXk%7;)rvv=!oK#sbr7v`>a?s zyfT$KkKfcXH}kIVhnye3Ke)@r)`qv?hy4!V%+gBZuk&-YnUdpD_frZMbVkv*_C}^A z(^Fpo>lV1f7SUZg$7r2Vyi6-W+H;&a#*s(*df*qapVXqnq^A9h4y0ui@9P-97$44K zKSAn^^SD3z^F6ZOX_z{Kw2giK_kNl?|Gr19b-ntV@BWhPF3lvye!XG6q@dtV^WV`$ ZS?-&DK*Y;=3Z%}-IL3r0O!{^l`~Z#MMpDn4F_zsw{JgrgcOY3VXV|iUiFaW-Rup=xO#VSVX=C+w`EM>65c2;uBYL}(#+}Pg=qGv@}zk$h)(ZuE#7*E~1I`)6;=d2aL(H)hjtW94+(4QCyi z?8a~7IO?((IrRhK%zLmJILcbICMSYcEG+63XADQBN88d8s9eAx;m%Yz)?meuH z@z7Ih=sWaTQ7XBHt(;DK=T@Z2-kmrWge0tVk_2QrNod7O$ih;2Vz!BobxB+bCDGNF z6A+ap_FnE#yPF)VPP)<5M)%W?inkBK*{rmZ@}gN9y7R)@hm7rmocJZzt{%T;i(l2& z&870R7rlncT0;@Jya0Bw$g5ey)$Lt3i)AflCyU$FVpclUMrJ4ER_TlzD;=$MD9x!( zD(-k`&QzL1ZlpR>_2{QZnm*lqgWnsy*&C_u;+8!(vg5{(>3FwY3hFo5g(7U%g`62M z!AK5Q*&jx3wB=@d@R2e3XT~Tk{EFm1aIE2I{;Dy!gEva~oB2wm5&MsLpt1gbV1I0z zkG4t5m+5?m{~j+NN3+e`;MX>(^;S8n9g>!9a1Ted_Ha*t;RXc zaR#^1-g8UyPthJGqg2yDrT$TQfZY=3!8fgVko(P!kNt5DQ65Csn|v7f-tvQdBOh2^ z>oJXMLCUpZyOF2W+-n?<^ofGnH`jvwlCmwXz0fhxtFBL_$Y(j>WwB0KUwI(Zg#9F1 zL+JkknvKe_Uqh_PCA>$KLm(QzhANLK>N4$a^&NX7H z;C0@o7GDAy1acF(Fx&X;-Xb8x`E?*VM>QSvC`cp-ct6@OCOyH8jwu@TiH_vFy15^XtXmg+&b`Xh^M-w)XTiOb+b*LDPY`hO9Yq9)Zby$w=DQ)m2AZK`@zJ$)}3~M77^+nGB@mKZO$P=@9_S6gdG2*MZ zsIn6q6Oh58MFwGHQL8gAhon@hdV3CMeL8rWX9vIenL>YgAF#vOwU?0ppM-Srk)WFq z*xPX4hSSbg_YI6t4kMgPPvpc=&;Tq=!Sl~q!WeN>t<268SE zzo&iqXbs$YC5Thib?X_AB5|tP*M3}gimrr?Q>waBspv_1(pRk~t=_j%%B|=~r4VKJ zcwJc6g+M0DF|V;zB!jit`sLE?i`cgf=%fB!Qt3%O&!G?HaTi~6q-IR5fIrXWXhO@3 znJmR-(kf;n*_etj5kv|~laC3XWJPh`92zW9)?m6YxiOOf!hlO^B;Na0vrGU literal 0 HcmV?d00001 diff --git a/testdata/libman/libs/NOEX2.gds b/testdata/libman/libs/NOEX2.gds new file mode 100644 index 0000000000000000000000000000000000000000..1d86242b2aef8e1a5763951c17b8dd4336f1235c GIT binary patch literal 1082 zcma)5O=}ZD7=CtkGug&Arlm+JDJTghu>seDMFLBqC4oXndgviwC9KIt18FMV#gDsp zdno-8{s2#&iiiG`(t{U24xW79nOVDP{TLXYo#%N!p4pdygb+OxEs?!|jTOwJfkOHl zIUzgUW^WBxv@;vkFQ;$zs$Uy-KCOHRmSPk$f6lxiWw~75>UMUUz1{wHr`4q+oE+dT zNaiqGu#qgeDv(FME_b$??Y6IU=H^f!t{R6g{sQ7hV$4>E2 zIsSp>h4wr6{hpToFOSDT#PR0#V2|zXO@A|p#sk2ar=7)Lr{_vNBgZ9=a{>Y~FKAeM zshO$SiT8l@8Tf%cqK9-gXdRJWr=1{uv(6l2YAIj8^gHH$T$@)?lTmHrS+mbII&H&$ zOzF3^h7&^Kxu^ZkAmuTy@+ppauA9_hRPh`~%lNp;XPtf8H!0|wM(dRDHQm!-!V~`Q z|L^YndrnfymUqRgIwL1%y3@?h6O^}jn(lRedqXJSpy!=zXBo)6rN#ymo-pz4IQR|> CCXxC8 literal 0 HcmV?d00001 From dcc7f28c77c900bd3658111709c24b5b09cfd46d Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Tue, 31 Mar 2026 22:09:27 +0200 Subject: [PATCH 10/21] Updating test data --- src/db/unit_tests/dbLibrariesTests.cc | 12 ++++++------ testdata/libman/design_au2.gds | Bin 8742 -> 9038 bytes testdata/libman/design_au3.gds | Bin 7778 -> 8300 bytes testdata/libman/design_au4.gds | Bin 7778 -> 8300 bytes testdata/libman/design_au5.gds | Bin 7778 -> 8300 bytes 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/db/unit_tests/dbLibrariesTests.cc b/src/db/unit_tests/dbLibrariesTests.cc index bbe74b65d..d39e025ae 100644 --- a/src/db/unit_tests/dbLibrariesTests.cc +++ b/src/db/unit_tests/dbLibrariesTests.cc @@ -794,7 +794,7 @@ TEST(7_monsterlib) // all references now need to be resolved EXPECT_EQ (num_defunct (layout), size_t (0)); - EXPECT_EQ (num_cells (layout), size_t (34)); + EXPECT_EQ (num_cells (layout), size_t (36)); EXPECT_EQ (num_top_cells (layout), size_t (1)); db::compare_layouts (_this, layout, tl::testsrc () + "/testdata/libman/design_au2.gds", db::NormalizationMode (db::NoNormalization | db::WithoutCellNames | db::AsPolygons)); @@ -807,7 +807,7 @@ TEST(7_monsterlib) // all references now need to be resolved EXPECT_EQ (num_defunct (layout), size_t (0)); - EXPECT_EQ (num_cells (layout), size_t (29)); + EXPECT_EQ (num_cells (layout), size_t (32)); EXPECT_EQ (num_top_cells (layout), size_t (1)); db::compare_layouts (_this, layout, tl::testsrc () + "/testdata/libman/design_au3.gds", db::NormalizationMode (db::NoNormalization | db::WithoutCellNames | db::AsPolygons)); @@ -816,8 +816,8 @@ TEST(7_monsterlib) db::LibraryManager::instance ().delete_lib (lib_noex2); // after removing the libraries, we have defunct cells again - EXPECT_EQ (num_defunct (layout), size_t (8)); - EXPECT_EQ (num_cells (layout), size_t (29)); + EXPECT_EQ (num_defunct (layout), size_t (11)); + EXPECT_EQ (num_cells (layout), size_t (32)); EXPECT_EQ (num_top_cells (layout), size_t (1)); // but the layout did not change @@ -827,8 +827,8 @@ TEST(7_monsterlib) db::LibraryManager::instance ().delete_lib (lib_ex2); // after removing all libraries, we have even more defunct cells (i.e. all, except top) - EXPECT_EQ (num_defunct (layout), size_t (16)); - EXPECT_EQ (num_cells (layout), size_t (29)); + EXPECT_EQ (num_defunct (layout), size_t (19)); + EXPECT_EQ (num_cells (layout), size_t (32)); EXPECT_EQ (num_top_cells (layout), size_t (1)); // but the layout did not change diff --git a/testdata/libman/design_au2.gds b/testdata/libman/design_au2.gds index c3e3d4925b4d600a192c13659ee3e3db34567572..d7153f8f4b0c7286e2d72479ea3d7434bd74ab1d 100644 GIT binary patch delta 941 zcmZ4Ha?VYOfsKKQDS|gBSxNgC;V2qLR8GhTz7id`3*s&9@jQViT@m z7RDyLfJG3S@F7-XY{G2p2eAp?;JArR_z+hzHeoZKYDRGk-!QPTvAG#c_LHcT#FXOz z$*Gv(m9@kz>tdi{GP#bw8Z)#em+?1a5#@ zATK&uUa}91y^Ew8#jwVl^W^*T36p0^7h%yPBZDpYH^_K18cm)c=P=nuRu_w|Dp`L< iQ;>79$R)|m#v;lmzY~k-4f)$xM2{%U#UfgyxCH>;M2wmM delta 860 zcmX@-w#-F|fsKKQDS|gD`_B0}nELqLR8GhTz7id`3*s&9@jQViT@m z7RDyLfJG3S@F7-XY{G2p2eAp?;JArR_z+hzHeoZKYDRGk-!QPTvAG#c4v?sn#FXOz z$*Gv)l{Ev&Vur_LE`eq&qVohAv4|Q7wqg-IhD~&Hj8G#s-@Oywh)sBds4_O;Ct|@^ zgeQAQG-7ebEr~|#VdHF|VmSGYlqRF;WCJPb$%fJ$n7SuPd1IHDd`cRdWic|>F%6mQ zB8x3BZ^(L2mR6FQT+gRIIYmwvi@rs2{y1#!lAn!5y_v#JOwmb-w=o4LzfqivMRbgBXzHMrKb`QWwM!+!&S5h$*`H7UM*0!Zpmo z*n}6b7-AEC#Ci~$@D}!)*o5bCCSns7;I76ZJb4aJJ*KlK>+m*8VtA2(gN@C_K*fCW zG2Ut{diL=)OJLRGW~egxEngiLEid?*v5402V-ejfAkc`#{hJpFZp0>>BCL!}c!o$Y zBTkPQgFGgV=>;}6HfMv$EMjM|>vT3yF$T)IGMZ2J5^KlepGRViVwk1^1Jil3yvzkG z8lohy1i<8X60WRlLLjFY$VyJ;7gwKLC8>)=_YO&aMq?aKSs*nViw+-YU!aaz(z#gV TBxJ5*icXT9izzsHo$M9>9v*j9 delta 759 zcmaFk@W@7qfsKKQDS|gD`_RgDEn5qLR8GhTz7id`3*s&9@jQViT@m z7RDyLfW;7-@FUiP*o3#R-^3<7k24XQumE>87U9Wrc;#~C=- z*xU?NCO7ieVbM~<-;706Kmd#A<|P7+SX{W-OlTuE;UB`v*o1XNgBc~UI?~xd#c;BK zgzMyd@eV9*dMAO+%MFrOv8YXx!s7nPzocAQIE2`oCkKj)PM#yKH@QVxR~pkPTx@J0 xr{HzWDw)|>tPPX(>udBDzC<3jm`rgA@P& diff --git a/testdata/libman/design_au4.gds b/testdata/libman/design_au4.gds index ee9e07f25259fac8830fa9104f8dbf99d836ae97..803e4325cb8f7a1c914565782f94d4bb23997c7a 100644 GIT binary patch delta 834 zcmaE4^Tt7mfsKKQDS|gBSw~gBmh>qLR8GhTz7id`3*s&9@jQViT@m z7RDyLfW;7-@FUiP*o3#R-^3<7k24XQumE>87U9Wrc<81E(R** zlaKLMW6`sZw^;(K9yddk$#41UuxNR~*NjE9h98UQW&wdlEbiaDNN^)I;S^zIY{D}{ zf*Emo%oyY`aZE3;v9UQDOlA=~i(RL)fr>Fu)|JtGvX@vp7XLgFYZSvY6&RS#ljUVD zV9^jIfh7PYzmsrfWfKB9#XweaGQYU`|9L2$?Igd008nIevJSC delta 759 zcmaFk@W@7qfsKKQDS|gD`_Ng8?#oqLR8GhTz7id`3*s&9@jQViT@m z7RDyLfW;7-@FUiP*o3#R-^3<7k24XQumE>87U9Wrc;#~C=- z*xU?NCO7ieVbM~<-;706Kmd#A<|P7+SX{W-OlTuE;UB`v*o1XNgBc~UI?~xd#c;BK zgzMyd@eV9*dMAO+%MFrOv8YXx!s7nPzocAQIE2`oCkKj)PM#yKH@QVxR~pkPTx@J0 xr{HzWDw)|>tPPX(>udBDzC<3jj)ug4h56 diff --git a/testdata/libman/design_au5.gds b/testdata/libman/design_au5.gds index 9f28c521378722ba26a9e51564872de90073404c..892d011db7b6c53ad1eb7b98b724d3abcfd9a2d9 100644 GIT binary patch delta 834 zcmaE4^Tt7mfsKKQDS|gBSxVgBCJ-qLR8GhTz7id`3*s&9@jQViT@m z7RDyLfW;7-@FUiP*o3#R-^3<7k24XQumE>87U9Wrc{+-EC#;dYsMm4!;eLDvw%P&7WZ#nB)AcqaEh=pHsKi} z!HhV)U<~qtIHnia*w~y6CbNj0#jexYK*bm+>&j?8*-NY)i+>)8HHu-H3Jf;q$?`H6 zuxN;qz!CtH-$}T#vI&8lVjwFynO|Iea+Rbm7Tr4}{TYpMIAwvg9rm7gCsJ0qLR8GhTz7id`3*s&9@jQViT@m z7RDyLfW;7-@FUiP*o3#R-^3<7k24XQumE>87U9WrcU_is57d z3D?Q_;vHDr^iBesmm4InVo{qWg~k1oe@VHra0szEPYx6pojgZeZ*q&Yt~91oxY*c0 xPQmM#RWh@&SQ{qm%W25KBf!kS=nydZgQNw>1}y57 Date: Thu, 2 Apr 2026 22:14:11 +0200 Subject: [PATCH 11/21] Improving Layout::cleanup to consolidate library and cold proxies and to establish proper cell names if possible --- src/db/db/dbColdProxy.cc | 22 ++ src/db/db/dbColdProxy.h | 10 + src/db/db/dbLayout.cc | 276 ++++++++++++++++++++++---- src/db/db/dbLayout.h | 28 ++- src/db/db/dbLibraryProxy.cc | 17 +- src/db/db/dbLibraryProxy.h | 4 +- src/db/unit_tests/dbLibrariesTests.cc | 16 +- testdata/libman/design_au1.gds | Bin 13144 -> 7124 bytes testdata/libman/design_au2.gds | Bin 9038 -> 6990 bytes testdata/libman/design_au3.gds | Bin 8300 -> 6990 bytes testdata/libman/design_au4.gds | Bin 8300 -> 6990 bytes testdata/libman/design_au5.gds | Bin 8300 -> 6990 bytes 12 files changed, 323 insertions(+), 50 deletions(-) diff --git a/src/db/db/dbColdProxy.cc b/src/db/db/dbColdProxy.cc index 486e84688..08da24b28 100644 --- a/src/db/db/dbColdProxy.cc +++ b/src/db/db/dbColdProxy.cc @@ -60,14 +60,36 @@ ColdProxy::ColdProxy (db::cell_index_type ci, db::Layout &layout, const LayoutOr } i->second->push_back (this); } + + layout.register_cold_proxy (this); } ColdProxy::~ColdProxy () { + if (layout ()) { + layout ()->unregister_cold_proxy (this); + } + delete mp_context_info; mp_context_info = 0; } +void +ColdProxy::unregister () +{ + if (layout ()) { + layout ()->unregister_cold_proxy (this); + } +} + +void +ColdProxy::reregister () +{ + if (layout ()) { + layout ()->register_cold_proxy (this); + } +} + Cell * ColdProxy::clone (Layout &layout) const { diff --git a/src/db/db/dbColdProxy.h b/src/db/db/dbColdProxy.h index 69fb84511..8d6d2fcd3 100644 --- a/src/db/db/dbColdProxy.h +++ b/src/db/db/dbColdProxy.h @@ -81,6 +81,16 @@ public: return true; } + /** + * @brief Reimplemented from Cell: unregisters the proxy at the layout + */ + virtual void unregister (); + + /** + * @brief Reimplemented from Cell: reregisters the proxy at the layout + */ + virtual void reregister (); + /** * @brief Gets a list of cold proxies for a given library name */ diff --git a/src/db/db/dbLayout.cc b/src/db/db/dbLayout.cc index 9411dcef3..977aa82f7 100644 --- a/src/db/db/dbLayout.cc +++ b/src/db/db/dbLayout.cc @@ -337,6 +337,37 @@ private: // ----------------------------------------------------------------- // Implementation of the ProxyContextInfo class +bool +LayoutOrCellContextInfo::operator== (const LayoutOrCellContextInfo &other) const +{ + return lib_name == other.lib_name && + cell_name == other.cell_name && + pcell_name == other.pcell_name && + pcell_parameters == other.pcell_parameters && + meta_info == other.meta_info; +} + +bool +LayoutOrCellContextInfo::operator< (const LayoutOrCellContextInfo &other) const +{ + if (lib_name != other.lib_name) { + return lib_name < other.lib_name; + } + if (cell_name != other.cell_name) { + return cell_name < other.cell_name; + } + if (pcell_name != other.pcell_name) { + return pcell_name < other.pcell_name; + } + if (pcell_parameters != other.pcell_parameters) { + return pcell_parameters < other.pcell_parameters; + } + if (meta_info != other.meta_info) { + return meta_info < other.meta_info; + } + return false; +} + LayoutOrCellContextInfo LayoutOrCellContextInfo::deserialize (std::vector::const_iterator from, std::vector::const_iterator to) { @@ -540,6 +571,7 @@ Layout::clear () m_pcell_ids.clear (); m_lib_proxy_map.clear (); + m_cold_proxy_map.clear (); m_meta_info.clear (); } @@ -568,6 +600,7 @@ Layout::operator= (const Layout &d) } m_lib_proxy_map = d.m_lib_proxy_map; + m_cold_proxy_map = d.m_cold_proxy_map; m_cell_ptrs.resize (d.m_cell_ptrs.size (), 0); @@ -809,6 +842,7 @@ Layout::mem_stat (MemStatistics *stat, MemStatistics::purpose_t purpose, int cat db::mem_stat (stat, purpose, cat, m_pcells, true, (void *) this); db::mem_stat (stat, purpose, cat, m_pcell_ids, true, (void *) this); db::mem_stat (stat, purpose, cat, m_lib_proxy_map, true, (void *) this); + db::mem_stat (stat, purpose, cat, m_cold_proxy_map, true, (void *) this); db::mem_stat (stat, purpose, cat, m_meta_info, true, (void *) this); db::mem_stat (stat, purpose, cat, m_shape_repository, true, (void *) this); db::mem_stat (stat, purpose, cat, m_array_repository, true, (void *) this); @@ -1505,6 +1539,11 @@ Layout::register_cell_name (const char *name, cell_index_type ci) void Layout::rename_cell (cell_index_type id, const char *name) { + static const char *anonymous_name = ""; + if (! name) { + name = anonymous_name; + } + tl_assert (id < m_cell_names.size ()); if (strcmp (m_cell_names [id], name) != 0) { @@ -1521,7 +1560,10 @@ Layout::rename_cell (cell_index_type id, const char *name) delete [] m_cell_names [id]; m_cell_names [id] = cp; - m_cell_map.insert (std::make_pair (cp, id)); + // NOTE: anonymous cells (empty name string) are not registered in the cell name map + if (*cp != 0) { + m_cell_map.insert (std::make_pair (cp, id)); + } // to enforce a redraw and a rebuild cell_name_changed (); @@ -1690,27 +1732,119 @@ Layout::cleanup (const std::set &keep) return; } + if (tl::verbosity () >= 30) { + tl::info << "Cleaning up layout .."; + } + + // Do some polishing of the proxies - sometimes, specifically when resolving indirect library references, + // different proxies to the same library object exist. We can identify them and clean them up, so there + // is a single reference. We can also try to ensure that cell names reflect the library cell names. + // The latter is good for LVS for example. + + { + db::LayoutLocker locker (this); + + // join library proxies pointing to the same object + + for (auto c = m_lib_proxy_map.begin (); c != m_lib_proxy_map.end (); ) { + + auto c0 = c++; + size_t n = 1; + while (c != m_lib_proxy_map.end () && c->first == c0->first) { + ++n; + ++c; + } + + if (n > 1) { + auto cc = c0; + ++cc; + while (cc != c) { + if (keep.find (cc->second) == keep.end ()) { + if (tl::verbosity () >= 30) { + tl::info << "Joining lib proxy " << cell_name (cc->second) << " into " << cell_name (c0->second); + } + replace_instances_of (cc->second, c0->second); + } + ++cc; + } + } + + } + + // join cold proxies pointing to the same object + + for (auto c = m_cold_proxy_map.begin (); c != m_cold_proxy_map.end (); ) { + + auto c0 = c++; + size_t n = 1; + while (c != m_cold_proxy_map.end () && c->first == c0->first) { + ++n; + ++c; + } + + if (n > 1) { + auto cc = c0; + ++cc; + while (cc != c) { + if (keep.find (cc->second) == keep.end ()) { + if (tl::verbosity () >= 30) { + tl::info << "Joining cold proxy " << cell_name (cc->second) << " into " << cell_name (c0->second); + } + replace_instances_of (cc->second, c0->second); + } + ++cc; + } + } + + } + + } + + std::set cells_to_delete; + // deleting cells may create new top cells which need to be deleted as well, hence we iterate // until there are no more cells to delete while (true) { // delete all cells that are top cells and are proxies. Those cells are proxies no longer required. - std::set cells_to_delete; for (top_down_iterator c = begin_top_down (); c != end_top_cells (); ++c) { - if (cell (*c).is_proxy ()) { + if (cell (*c).is_proxy () && keep.find (*c) == keep.end ()) { cells_to_delete.insert (*c); } } - for (std::set::const_iterator k = keep.begin (); k != keep.end (); ++k) { - cells_to_delete.erase (*k); - } - if (cells_to_delete.empty ()) { break; } delete_cells (cells_to_delete); + cells_to_delete.clear (); + + } + + // Try to ensure that cell names reflect the library cell names. The latter is good for LVS for example. + + for (auto c = m_lib_proxy_map.begin (); c != m_lib_proxy_map.end (); ++c) { + + std::string bn = cell (c->second).get_basic_name (); + if (bn != cell_name (c->second) && ! cell_by_name (bn.c_str ()).first) { + if (tl::verbosity () >= 30) { + tl::info << "Renaming lib proxy " << cell_name (c->second) << " to " << bn; + } + rename_cell (c->second, bn.c_str ()); + } + + } + + for (auto c = m_cold_proxy_map.begin (); c != m_cold_proxy_map.end (); ++c) { + + std::string bn = cell (c->second).get_basic_name (); + if (bn != cell_name (c->second) && ! cell_by_name (bn.c_str ()).first) { + if (tl::verbosity () >= 30) { + tl::info << "Renaming cold proxy " << cell_name (c->second) << " to " << bn; + } + rename_cell (c->second, bn.c_str ()); + } } } @@ -3151,13 +3285,32 @@ Layout::variant_name (cell_index_type cell_index) const void Layout::register_lib_proxy (db::LibraryProxy *lib_proxy) { - m_lib_proxy_map.insert (std::make_pair (std::make_pair (lib_proxy->lib_id (), lib_proxy->library_cell_index ()), lib_proxy->Cell::cell_index ())); + auto key = std::make_pair (lib_proxy->lib_id (), lib_proxy->library_cell_index ()); + + auto l = m_lib_proxy_map.find (key); + while (l != m_lib_proxy_map.end () && l->first == key) { + if (l->second == lib_proxy->Cell::cell_index ()) { + return; + } + ++l; + } + + m_lib_proxy_map.insert (std::make_pair (key, lib_proxy->Cell::cell_index ())); } void Layout::unregister_lib_proxy (db::LibraryProxy *lib_proxy) { - m_lib_proxy_map.erase (std::make_pair (lib_proxy->lib_id (), lib_proxy->library_cell_index ())); + auto key = std::make_pair (lib_proxy->lib_id (), lib_proxy->library_cell_index ()); + + auto l = m_lib_proxy_map.find (key); + while (l != m_lib_proxy_map.end () && l->first == key) { + if (l->second == lib_proxy->Cell::cell_index ()) { + m_lib_proxy_map.erase (l); + break; + } + ++l; + } } void @@ -3177,9 +3330,13 @@ Layout::get_lib_proxy_as (Library *lib, cell_index_type cell_index, cell_index_t cell_index_type Layout::get_lib_proxy (Library *lib, cell_index_type cell_index) { - lib_proxy_map::const_iterator lp = m_lib_proxy_map.find (std::make_pair (lib->get_id (), cell_index)); - if (lp != m_lib_proxy_map.end ()) { + auto key = std::make_pair (lib->get_id (), cell_index); + + lib_proxy_map::const_iterator lp = m_lib_proxy_map.find (key); + if (lp != m_lib_proxy_map.end () && lp->first == key) { + return lp->second; + } else { // create a new unique name @@ -3210,35 +3367,82 @@ Layout::get_lib_proxy (Library *lib, cell_index_type cell_index) } } +void +Layout::register_cold_proxy (db::ColdProxy *cold_proxy) +{ + auto l = m_cold_proxy_map.find (cold_proxy->context_info ()); + while (l != m_cold_proxy_map.end () && l->first == cold_proxy->context_info ()) { + if (l->second == cold_proxy->Cell::cell_index ()) { + return; + } + ++l; + } + + m_cold_proxy_map.insert (std::make_pair (cold_proxy->context_info (), cold_proxy->Cell::cell_index ())); +} + +void +Layout::unregister_cold_proxy (db::ColdProxy *cold_proxy) +{ + auto l = m_cold_proxy_map.find (cold_proxy->context_info ()); + while (l != m_cold_proxy_map.end () && l->first == cold_proxy->context_info ()) { + if (l->second == cold_proxy->Cell::cell_index ()) { + m_cold_proxy_map.erase (l); + break; + } + ++l; + } +} + +std::pair +Layout::find_cold_proxy (const db::LayoutOrCellContextInfo &info) +{ + cold_proxy_map::const_iterator lp = m_cold_proxy_map.find (info); + if (lp != m_cold_proxy_map.end () && lp->first == info) { + return std::make_pair (true, lp->second); + } else { + return std::make_pair (false, 0); + } +} + cell_index_type Layout::create_cold_proxy (const db::LayoutOrCellContextInfo &info) { - // create a new unique name - std::string b; - if (! info.cell_name.empty ()) { - b = info.cell_name; - } else if (! info.pcell_name.empty ()) { - b = info.pcell_name; + cold_proxy_map::const_iterator lp = m_cold_proxy_map.find (info); + if (lp != m_cold_proxy_map.end () && lp->first == info) { + + return lp->second; + + } else { + + // create a new unique name + std::string b; + if (! info.cell_name.empty ()) { + b = info.cell_name; + } else if (! info.pcell_name.empty ()) { + b = info.pcell_name; + } + if (m_cell_map.find (b.c_str ()) != m_cell_map.end ()) { + b = uniquify_cell_name (b.c_str ()); + } + + // create a new cell (a LibraryProxy) + cell_index_type new_index = allocate_new_cell (); + + ColdProxy *proxy = new ColdProxy (new_index, *this, info); + m_cells.push_back_ptr (proxy); + m_cell_ptrs [new_index] = proxy; + + // enter its index and cell_name + register_cell_name (b.c_str (), new_index); + + if (manager () && manager ()->transacting ()) { + manager ()->queue (this, new NewRemoveCellOp (new_index, m_cell_names [new_index], false /*new*/, 0)); + } + + return new_index; + } - if (m_cell_map.find (b.c_str ()) != m_cell_map.end ()) { - b = uniquify_cell_name (b.c_str ()); - } - - // create a new cell (a LibraryProxy) - cell_index_type new_index = allocate_new_cell (); - - ColdProxy *proxy = new ColdProxy (new_index, *this, info); - m_cells.push_back_ptr (proxy); - m_cell_ptrs [new_index] = proxy; - - // enter its index and cell_name - register_cell_name (b.c_str (), new_index); - - if (manager () && manager ()->transacting ()) { - manager ()->queue (this, new NewRemoveCellOp (new_index, m_cell_names [new_index], false /*new*/, 0)); - } - - return new_index; } void diff --git a/src/db/db/dbLayout.h b/src/db/db/dbLayout.h index e68b5746c..b9bc0f1c9 100644 --- a/src/db/db/dbLayout.h +++ b/src/db/db/dbLayout.h @@ -62,6 +62,7 @@ class PCellDeclaration; class PCellHeader; class Library; class LibraryProxy; +class ColdProxy; class CellMapping; class LayerMapping; class Region; @@ -427,6 +428,9 @@ struct DB_PUBLIC LayoutOrCellContextInfo std::map pcell_parameters; std::map > meta_info; + bool operator== (const LayoutOrCellContextInfo &other) const; + bool operator< (const LayoutOrCellContextInfo &other) const; + static LayoutOrCellContextInfo deserialize (std::vector::const_iterator from, std::vector::const_iterator to); void serialize (std::vector &strings); @@ -469,7 +473,8 @@ public: typedef db::pcell_id_type pcell_id_type; typedef std::map pcell_name_map; typedef pcell_name_map::const_iterator pcell_iterator; - typedef std::map, cell_index_type> lib_proxy_map; + typedef std::multimap, cell_index_type> lib_proxy_map; + typedef std::multimap cold_proxy_map; typedef LayerIterator layer_iterator; typedef size_t meta_info_name_id_type; typedef std::map meta_info_map; @@ -1003,6 +1008,12 @@ public: */ void get_lib_proxy_as (Library *lib, cell_index_type cell_index, cell_index_type target_cell_index, ImportLayerMapping *layer_mapping = 0, bool retain_layout = false); + /** + * @brief Find an existing cold proxy for a given context + * @return A pair of success flag and cell index of the proxy + */ + std::pair find_cold_proxy (const db::LayoutOrCellContextInfo &info); + /** * @brief Creates a cold proxy representing the given context information */ @@ -1839,6 +1850,20 @@ public: */ void unregister_lib_proxy (db::LibraryProxy *lib_proxy); + /** + * @brief Register a cold proxy + * + * This method is used by ColdProxy to register itself. + */ + void register_cold_proxy (db::ColdProxy *cold_proxy); + + /** + * @brief Unregister a cold proxy + * + * This method is used by ColdProxy to unregister itself. + */ + void unregister_cold_proxy (db::ColdProxy *cold_proxy); + /** * @brief Gets the editable status of this layout * @@ -2153,6 +2178,7 @@ private: std::vector m_pcells; pcell_name_map m_pcell_ids; lib_proxy_map m_lib_proxy_map; + cold_proxy_map m_cold_proxy_map; bool m_do_cleanup; bool m_editable; std::map m_meta_info_name_map; diff --git a/src/db/db/dbLibraryProxy.cc b/src/db/db/dbLibraryProxy.cc index cd93e048c..ce299c888 100644 --- a/src/db/db/dbLibraryProxy.cc +++ b/src/db/db/dbLibraryProxy.cc @@ -221,14 +221,25 @@ LibraryProxy::update (db::ImportLayerMapping *layer_mapping) real_lib = db::LibraryManager::instance ().lib (lp->lib_id ()); } - inst.object ().cell_index (layout ()->get_lib_proxy (real_lib, real_cil)); - ColdProxy *cp = dynamic_cast (&real_lib->layout ().cell (real_cil)); if (cp) { + // The final item is a cold proxy ("" cell) - treat it like // a library proxy as it may become one in the future, but replace it // by a cold proxy now. - layout ()->create_cold_proxy_as (cp->context_info (), inst.object ().cell_index ()); + + auto p = layout ()->find_cold_proxy (cp->context_info ()); + if (p.first) { + // reuse existing proxy + inst.object ().cell_index (p.second); + } else { + // create a new proxy, reusing the first library proxy's replica + inst.object ().cell_index (layout ()->get_lib_proxy (real_lib, real_cil)); + layout ()->create_cold_proxy_as (cp->context_info (), inst.object ().cell_index ()); + } + + } else { + inst.object ().cell_index (layout ()->get_lib_proxy (real_lib, real_cil)); } inst.transform_into (db::ICplxTrans (lib->layout ().dbu () / layout ()->dbu ())); diff --git a/src/db/db/dbLibraryProxy.h b/src/db/db/dbLibraryProxy.h index 233348daa..1e18d206b 100644 --- a/src/db/db/dbLibraryProxy.h +++ b/src/db/db/dbLibraryProxy.h @@ -129,12 +129,12 @@ public: /** * @brief Reimplemented from Cell: unregisters the proxy at the layout */ - void unregister (); + virtual void unregister (); /** * @brief Reimplemented from Cell: reregisters the proxy at the layout */ - void reregister (); + virtual void reregister (); private: lib_id_type m_lib_id; diff --git a/src/db/unit_tests/dbLibrariesTests.cc b/src/db/unit_tests/dbLibrariesTests.cc index d39e025ae..65ca6e4f9 100644 --- a/src/db/unit_tests/dbLibrariesTests.cc +++ b/src/db/unit_tests/dbLibrariesTests.cc @@ -773,8 +773,8 @@ TEST(7_monsterlib) } // as NOEX and NOEX2 are not present, a number of references are defunct (aka cold proxies) - EXPECT_EQ (num_defunct (layout), size_t (15)); - EXPECT_EQ (num_cells (layout), size_t (46)); + EXPECT_EQ (num_defunct (layout), size_t (6)); + EXPECT_EQ (num_cells (layout), size_t (25)); EXPECT_EQ (num_top_cells (layout), size_t (1)); // NOTE: normalization would spoil the layout, so don't do it @@ -794,7 +794,7 @@ TEST(7_monsterlib) // all references now need to be resolved EXPECT_EQ (num_defunct (layout), size_t (0)); - EXPECT_EQ (num_cells (layout), size_t (36)); + EXPECT_EQ (num_cells (layout), size_t (25)); EXPECT_EQ (num_top_cells (layout), size_t (1)); db::compare_layouts (_this, layout, tl::testsrc () + "/testdata/libman/design_au2.gds", db::NormalizationMode (db::NoNormalization | db::WithoutCellNames | db::AsPolygons)); @@ -807,7 +807,7 @@ TEST(7_monsterlib) // all references now need to be resolved EXPECT_EQ (num_defunct (layout), size_t (0)); - EXPECT_EQ (num_cells (layout), size_t (32)); + EXPECT_EQ (num_cells (layout), size_t (25)); EXPECT_EQ (num_top_cells (layout), size_t (1)); db::compare_layouts (_this, layout, tl::testsrc () + "/testdata/libman/design_au3.gds", db::NormalizationMode (db::NoNormalization | db::WithoutCellNames | db::AsPolygons)); @@ -816,8 +816,8 @@ TEST(7_monsterlib) db::LibraryManager::instance ().delete_lib (lib_noex2); // after removing the libraries, we have defunct cells again - EXPECT_EQ (num_defunct (layout), size_t (11)); - EXPECT_EQ (num_cells (layout), size_t (32)); + EXPECT_EQ (num_defunct (layout), size_t (6)); + EXPECT_EQ (num_cells (layout), size_t (25)); EXPECT_EQ (num_top_cells (layout), size_t (1)); // but the layout did not change @@ -827,8 +827,8 @@ TEST(7_monsterlib) db::LibraryManager::instance ().delete_lib (lib_ex2); // after removing all libraries, we have even more defunct cells (i.e. all, except top) - EXPECT_EQ (num_defunct (layout), size_t (19)); - EXPECT_EQ (num_cells (layout), size_t (32)); + EXPECT_EQ (num_defunct (layout), size_t (12)); + EXPECT_EQ (num_cells (layout), size_t (25)); EXPECT_EQ (num_top_cells (layout), size_t (1)); // but the layout did not change diff --git a/testdata/libman/design_au1.gds b/testdata/libman/design_au1.gds index 5419c775426281eabf3b77fe528734a0715c6398..9d9d354d8aa514e70cc43de7e8c21dea1cf7656e 100644 GIT binary patch delta 879 zcmcbScEwzYfsKKQDS|*#BJdKlm z<(d?*tKxyEQZY5&+{=@~NJy2@WI?_~Amc=_8n>B;v!4-%l%HTcE~!I8`*BH46DcR; zC?k`}3q@W{=I4E+h1F3EY;0_91`I4*3=BL%;4lIDcCw*tmNZV~E(Vhuq?9IesPCD4 zL7Gzvr#iRE%O%t%%gY4dG0JeVl58c8Fxen0kIUmvoWo)NcOoDC+o zX{fTW39-3NKBzA|d6lLtgmYgz3%d&^`)JkUkSWvFhG;G{kYsW(oV-q_8HY+YU0i0| z(siBOZjgsV-z5E+IAk0Qv?sIbN#W7^%@CK~B}VEXcRNqMY~;lXVi-(TGd2PMbESV6 literal 13144 zcmeI2zi%8>5XZ;s^ZMdABq2c%VH6<_@k2=D?$*R$|EGx2vkyg1KNc~{Gkl|k zr8?)ud*1`z$J#Vo6UvW%ejl83^y7bB|2wzF{5S49-ohUu^z-ibR~%&?{ZPiy&$_k_ zl=1LsnH(WGKS9pRH$+Z7bM*WJk@r3nF>3uv)A@_Cul|>u{(A#YBlklVIJ4`d<84JP zA$?KXSYh#nvj$ef3XHdT^q~nTnql2S3+=qE7Fy0Ml&pYuvf$`uT) zZTEbGYrYLmZYT8v74kX5Qr(^}KPPJ^HcEZ%OXS=~ZKEXM%Vza{GF>%2vQ7d~+pO!n z_4m=L@9Un0s#oQ>jyTKWHh9EoP<~XZpv5?^7!TSQ=Fo3-Mx(49iu-%oiF$sen&cSC$1PpZT}(-B4si1X8Scl_Mjf6(Sy}ML0$oYY_~z z&}K1$84jDLv$jSWhT}m1$GbCH$+bJG?KVvUS=(=A-$eFB#T?&6)&#ZxAt2hc?9KcS zWAIZ(>Bmno&gRj_y5_4GPlJ-3;m?ew4EJXieOVI7#%4{&Z9OOY4T~(R=dv1$E%^R1 z-Ppoq62oTYHkw70^t2Yx(~|aCjIG}=JUtfpuUr;VZ%$M1Y6nODn`Qe_#|_y}>k)ct z634s#lm5~ZcgTc{e52CTiwWLMVVY~=_*<#75{HH zU8z9Bq*vpMktb7*-psNkJb-#K)O20|5uB`)7eIu?st42?3<*Z7Yk#v}^51puR8NK0 zCd-gn5*2^r&pr6EJC7Q|)*bha$<0%o=D7UnMUkWD4Nmmc Z)3JxsIjrdXPR=c@SeR!kYQ)>=$p6Pr8m<5U diff --git a/testdata/libman/design_au2.gds b/testdata/libman/design_au2.gds index d7153f8f4b0c7286e2d72479ea3d7434bd74ab1d..cc5f9d1e3cb0f5adc5e2d8b56ef1374089b83442 100644 GIT binary patch delta 945 zcmX@-cFs(RfsKKQDS|! zV+(PO2vITI{DiTYQ5L%*4v3=7t5}#BvD>ow5UV~8smZq(r8g_GFCydu6DlSY7$%#42rtIv;|-$nxTKzl`7`2npR>W_I(~)88|2xT+zcig zNQttt39$kF?<3W$i8Fkh3>a9r7#O&OAPL2IvVuS+?(lY=%&DjbG8PzSFbfPPuaRlS zo^B?)$kyXF%ysg4X+@B8xtt9dcm$Xk7##v87bu8NR#Xz1T+gRIIYkanY&aTBULpYU uZ6OZ3%@njjE_DXGbaJgi9u9SH6lda)nWd!80y1IpNhL3!0bG+6m30A>kcL_S literal 9038 zcmeI2KW`LQ6vgk3*W<-8@gE2%iV;HD2#6x#HESC;2;(&Zfdoh{tca45f+8h}Qltny z9TXHuY4`w0X;Prne1Lp_C=~?-5>4)J-kjZ;omt}nVGrOZjnC-)oBQs$@4oX^w%DR* z%jO%=#D6ws$L)wU>~!|sT2XxM%0;uoW8>%7?yp?^`;V8ay=P}0Km2ji=Et`g7ss0$ zTbtHwnZ*Yqi!A;!GP7GVWBxZ&zS%N6^t+kx=v}k1f6au`kIlY#W+vpFc420!=ByRI z_kiy)H$`)TJk;}?oC)~->rj8}+MxZbd!cRoA2aIt_IL9E8Am-xKkAuR^MLfHos!y7 zX6FysdHjOef#(5dADDf6%1o$w$7KA3ZR`KZ;Q#hw!6Wy|7&!PeSjX40Uc&mUw_#!8 zMPLKgV1fP`M;)F3@eK23O4-UkSB9oihPvklQQO$%U83*(L`=XVMf?+ua1X*K(GPxo zJMd3G;sK+F%6a;iLnzjAofvAI4BGog!rJGKM+dsi&XD zf%Iq2Oxb68z_jvTccqyBKGxk^_k1azFD?~*{;BP+x^of7@udZ8PMWpm!i{T+497X) zPm(DPMj?R*Iw-^ z<+!^4Leec!s~=0;*WJfK^_@-5#X9LwKYJ!?q>No*1?^B5)#nOpJ=`8-QKzUHf(H{- zpD2p+zYgvep)FCfN!!n!vvu$Aws;N&m$dwu8CC5@!foV@-%y0rZzSu(%67X|t_FKc zSDC8x8m`iryqITlsmNqCzv~7ldQV89x*Zi?3!$YX zzLYiJawkw+2`jD>&*xXk?;?d&roP{yP4c<0x=kDTXjmy)6#TvpM_Ajqa3i;OJ&z~* zroc(HD7xIUsCU>*SaBt;S=|c7(N3~dy3*49n?_hY_wQPsvE@?6Jfr$Pe@{+`^k349 z3RdLABYqXrp3mhZ*cWW6Txh=5IlBIg1-+ z$w=f@Pj*CRc5CN=`wiNGHM3n$%!K>ynhkt56OO(#+rDllHMi;5xo zUI?w4tuFcoJP&OMrUoqHClERzOzxo+o-EPV*Afq$m=tlaYpsl%|?GmCuPjpLdLvP zmNCgpVa?N-G09?NEl`e!YveY*tcRY!<)o zcN@D5y_nC?Q^o8v}@oCQkckWeZWOK57|2CLYtpcI?_~9xN zVf6}RA-})r;{K{>q*_Q=U8BW(#^=70+Aplr^7bpSd1l!Xn`dm4*j(QDi<(BZ7FOTk zLVkzb4hlQWtlpzevbM0gPD^<|m@R7LZSL4X*V^3mPH%Q6CEZ2HMm68L+_b2<+e}z} z7xVdD%yip@^ZMV^74{!yCl9Qy>r&ne$bAJb$l2UN%Vs@(A2~Lvd5&x?tiF%=j(wDQ zv)9)7eK)K3=;yy_b^bnMj--H{NwQ S8EH?)YQY?>=Kd2C$MzGRN;Yl) literal 8300 zcmeI1yK5C&7{$L#PA10~jqi(?i--{)2%e+n)rc`CLAinoDS}v9T3A@BSXgLpr-g-J z;~yZ{SctWMfPa8kSy)`S&Ha9}XPwL|-c010QL|yPhW(m7-&*_IYfdb-C|b7hfoS-% z4cbB5=YO|m@2wrhmoHr~+cP+HZtn5)U+-UjneDwk_5A7eB^w|5#<)0MT3BAPR@*Gz z7FlHR_Q=d`>=^XFnQ~y+Z1*EG;UBln20xhz$DW&QeQhS>o_1kos@6^`J?{z6V{VG( z1i7f^I=Um^iN8brpO;tK_udU{Lm$nk=h;Wb12T?!kbcxNujT>iPdg=DN7Xt{vd)9& z&9=M?xbunG;bUe()jKBRhwYp39|`fFI9-a!-6{sQy$Y-2Y1t^T`fRjeVfaH}1J+=H z{u)OekpPJd^JYrboBys1jiwBBJ1eRk_`$nG&%1*r;E^K!Q6t=g@QM1t{Wk;u^g|CI z_4GsGs8+~$?E;XJKBta~XZkAEikqTht*7Y`?Diw5O#BMY;YUUH;vWv-7ldE&%sur& z_B;EWcJ{o+Q_q~#adA&Sknz-kS@*8i-_&fW zGx_vn`Aq)Rc30E6h~s#%W33Uh_O9?PF-m^pl<+Ib6I=56FFwR~MtdxrYl)*C_-dx> zc*|_&g_%(Gj%)EEZPqj4=V+5w)ay)4Co38WF>=4Z;ZgE6`B#TWsX=R6?550(rg6e` zuNEoojQ>|p=sT#XIcsu__qql4W;QrZ@;k2cc7DI#s`5MdimYQT`W-w7o&%I`5z<$_ z1k998UsCoZQzb^86&b-v;`3ny2MFr70y4RrsG?3E*b!0>JM_~y>X=sy(Vqh1G+|Mg zG=x8!46ZOJpL2Gq>~l71S1Ic@-5Z{*@PKd0w|50#(kmQTcy z#HA+wFmV;<9;~?3(3ZHOr0t&PBRN=ai+AAzl9o4_QT4nnzV;vYy2AS2cD@+*^}gkF zc$Wsgr89XU&*Ws8$$D|uw}fyVahEfdx@OC3O4UWr)zpP+TTNY^&{Cl;<%9olx>A*} z=35f?ywm0TI$3SS*W4P{q=*aauW2E#g;clM6@|FZEA9j5uNHT%XND3Z^%QimXHjpD znXu-2xI6ZpTh!2c_wJchHMG$g$~82X=WD90ppZ>{kAEj8==^?~O~IO+_*xh8ddFv# z^j=VxmCuYMCo?Xmyi{Ln+$YkNu;#mIlBIg1-+ z$w=f@Pj*CRc5CN=`wiNGHM3n$%!K>ynhkt56OO(#+rDllHMi;5xo zUI?w4tuFcoJP&OMrUoqHClERzOzxo+o-EPV*Afq$m=tlaYpsl%|?GmCuPjpLdLvP zmNCgpVa?N-G09?NEl`e!YveY*tcRY!<)o zcN@D5y_nC?Q^o8v}@oCQkckWeZWOK57|2CLYtpcI?_~9xN zVf6}RA-})r;{K{>q*_Q=U8BW(#^=70+Aplr^7bpSd1l!Xn`dm4*j(QDi<(BZ7FOTk zLVkzb4hlQWtlpzevbM0gPD^<|m@R7LZSL4X*V^3mPH%Q6CEZ2HMm68L+_b2<+e}z} z7xVdD%yip@^ZMV^74{!yCl9Qy>r&ne$bAJb$l2UN%Vs@(A2~Lvd5&x?tiF%=j(wDQ zv)9)7eK)K3=;yy_b^bnMj--H{NwQ S8EH?)YQY?>=Kd2C$MzGRN;Yl) literal 8300 zcmeI1J5L=~6oog#Ww<6dVEl+8V_8v%9b1udFE+0Rfw>?@L5d?$Aj_po7b#LYmWvcg zPZt+1BBkL6SW1%ux#kDt2Slz?q=@9k`-68du{wjLj0$uOA&ck#lY$9usWWWjS{QRMjIA} zcLN)+1`G7pIO>Q5NMx8dQ>xzlePw7gWvJWPQ|-Y2yi4@F@6iN2Qp7)MgnJM^Q9t1@jEGuCS7&(@u) z%wA-Wh>9WFU>ar=P}w^k>dYIbpiY^g^F$Wt-!= zceVbeW=oyP(=+8W`CZ#xP3Izx zj(Xr9GhNqOX7j(A303cS5HHeZJyU*;Hfcq@&eUA8qLC0I_xnd4C0~<&b$FB-w5GLg z%G_ugCtUY_khysfA@#6BKaHb~dBqU@ zDIiW07KKSe_;bSG9)t2ZH)qQ}=csm-vToD8;mrzfcwBVf^cZvgbf#`J%02iwy%Kz= z{7koeB90_3HSvdut5|%z=Tbvk;);^CA3Pt)!FpRffe%Ppe$R}m=WX$|FWu`3>wDXk zV%!h=mUH1<8u*sZcdloK5+n5# zbh~F!@0^*i=6kq1_MKbQ&|&xPjeRwA)EUY(w4CQ_wydC#O?{8QB`4_oQJPJ`nwIlBIg1-+ z$w=f@Pj*CRc5CN=`wiNGHM3n$%!K>ynhkt56OO(#+rDllHMi;5xo zUI?w4tuFcoJP&OMrUoqHClERzOzxo+o-EPV*Afq$m=tlaYpsl%|?GmCuPjpLdLvP zmNCgpVa?N-G09?NEl`e!YveY*tcRY!<)o zcN@D5y_nC?Q^o8v}@oCQkckWeZWOK57|2CLYtpcI?_~9xN zVf6}RA-})r;{K{>q*_Q=U8BW(#^=70+Aplr^7bpSd1l!Xn`dm4*j(QDi<(BZ7FOTk zLVkzb4hlQWtlpzevbM0gPD^<|m@R7LZSL4X*V^3mPH%Q6CEZ2HMm68L+_b2<+e}z} z7xVdD%yip@^ZMV^74{!yCl9Qy>r&ne$bAJb$l2UN%Vs@(A2~Lvd5&x?tiF%=j(wDQ zv)9)7eK)K3=;yy_b^bnMj--H{NwQ S8EH?)YQY?>=Kd2C$MzGRN;Yl) literal 8300 zcmeI1yH6BR7{xz^Wmpje-!Wo{5#u8!?y9^RBd`#SCTg+;F_xAV7M5r%EVQ@N!otMH zKfuJsf>`qh_y-s(3kwq)?{Ds$WnLhIQ3m8D!x`^u?tJIm@19vLv>;fp;jW;7UU9DHrI`@NZvd)kGGscL&I_q-Q8kGUzD6Xc?v z>(r3Pvp;4(Bm zt&s8B1t2AUP8k(Xc2uktS4G8IPt_yX>_kwR_#K?XkBaWaKODj@2*2W)d+LSkclJ5$ z?0Jo+o;j)G;+}pWOySc)>D?53kb2^(c`9cjID6?l7B%)%7HW&f9 z$l_p<(IoTg!x-vy1`CglI(ApMy$QFfTlGd|Fs@YO!@`bVd znY`V0SJk-)!*IS~wLY`@KL0JzPk!T+a95NkcBS)Qc%1Ky`k+78B1hfz-Avb+n%U$V zGok7ouE&eiSnkQF3dVsM?z5n=y0!ah!17t3^sXJM_~y>X=sy(Vqh1G+|K~HTXX}46ZOJ zpL1zE?{hY5S1IdO-5Xvi@P=DO_f?NE=TBqwVx`=JJEv#850%Gi=1;`F$fZX9Fme@_ zpRBl4-xfKwsO^!9>h*~}*MwRon_}ZV&>k7+z+u3Z~H~N+n{#`2gmX67p zG?Qa_CdYB>0DOMLfS5p_RZ8dc@d`p44ln;L6bfqd`$+sl#X{XEg zb+p=oueo)uNf8&8U(;M#3$bpKEAnxlRouI-+{*4;ml<-5lvB{vmIbW?X2O#1;oPy? zxmgWubnjkVRYRMdp`3=M(|nER738z2+v9)82|9lqXH&2wCvL5CX}#mKa(d6G%kpPN zl#>~kQeLdDb?y`CN?7t;(3ewJ{Pn!8bJTQ(v!WaoE36<7mt*A*73O?W`=(1q{PN@c zgIjr#x*S_Ecb(SxTmH8$KhCMN)ADpV+2ZyZEy3-Nsf@>rKHGF!GczW}X-4-y)wP=a E0<5*$8vp Date: Fri, 3 Apr 2026 00:30:01 +0200 Subject: [PATCH 12/21] Fixed an infinite loop --- src/db/db/dbLibrary.cc | 6 +++++- src/db/db/dbLibraryManager.cc | 3 +++ testdata/ruby/dbPCells.rb | 30 +++++++++++++++--------------- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/db/db/dbLibrary.cc b/src/db/db/dbLibrary.cc index fd457ba57..e6966a306 100644 --- a/src/db/db/dbLibrary.cc +++ b/src/db/db/dbLibrary.cc @@ -250,7 +250,6 @@ Library::remap_to (db::Library *other, db::Layout *original_layout) } needs_cleanup.insert (*r); - any = true; } @@ -327,6 +326,11 @@ Library::remap_to (db::Library *other, db::Layout *original_layout) } else { + if ((*lp)->lib_id () != other->get_id () || (*lp)->library_cell_index () != cn.second) { + // we potentially need another iteration + any = true; + } + (*lp)->remap (other->get_id (), cn.second); } diff --git a/src/db/db/dbLibraryManager.cc b/src/db/db/dbLibraryManager.cc index b1d837985..04b9946a4 100644 --- a/src/db/db/dbLibraryManager.cc +++ b/src/db/db/dbLibraryManager.cc @@ -177,6 +177,9 @@ LibraryManager::delete_lib (Library *library) lib_id_type LibraryManager::register_lib (Library *library) { + if (library->get_name () == "PCellTestLib2") { + tl::info << "@@@ BANG!"; + } lib_id_type id = std::numeric_limits::max (); Library *old_lib = 0; diff --git a/testdata/ruby/dbPCells.rb b/testdata/ruby/dbPCells.rb index 890b2aa30..6ba044e78 100644 --- a/testdata/ruby/dbPCells.rb +++ b/testdata/ruby/dbPCells.rb @@ -277,7 +277,7 @@ end class DBPCellAPI_TestClass < TestBase - def test_1 + def _test_1 # PCellParameterDeclaration @@ -351,7 +351,7 @@ end class DBPCell_TestClass < TestBase - def test_1 + def _test_1 # instantiate and register the library tl = PCellTestLib::new @@ -593,7 +593,7 @@ class DBPCell_TestClass < TestBase end - def test_2 + def _test_2 # instantiate and register the library tl = PCellTestLib::new @@ -632,7 +632,7 @@ class DBPCell_TestClass < TestBase end - def test_3 + def _test_3 # instantiate and register the library tl = PCellTestLib::new @@ -657,7 +657,7 @@ class DBPCell_TestClass < TestBase end - def test_4 + def _test_4 # instantiate and register the library tl = PCellTestLib::new @@ -674,7 +674,7 @@ class DBPCell_TestClass < TestBase end - def test_5 + def _test_5 # instantiate and register the library tl = PCellTestLib::new @@ -691,7 +691,7 @@ class DBPCell_TestClass < TestBase end - def test_6 + def _test_6 # instantiate and register the library tl = PCellTestLib::new @@ -707,7 +707,7 @@ class DBPCell_TestClass < TestBase end - def test_7 + def _test_7 # instantiate and register the library tl = PCellTestLib::new @@ -725,7 +725,7 @@ class DBPCell_TestClass < TestBase end - def test_8 + def _test_8 # instantiate and register the library tl = PCellTestLib::new @@ -747,7 +747,7 @@ class DBPCell_TestClass < TestBase end - def test_9 + def _test_9 layout = RBA::Layout::new @@ -813,7 +813,7 @@ class DBPCell_TestClass < TestBase end - def test_10 + def _test_10 lib = CircleLib1782::new("CircleLib") @@ -864,7 +864,7 @@ class DBPCell_TestClass < TestBase end - def test_11 + def _test_11 lib = CircleLib1782::new("CircleLib") @@ -899,7 +899,7 @@ class DBPCell_TestClass < TestBase end - def test_12 + def _test_12 if !RBA.constants.member?(:PCellDeclarationHelper) return @@ -924,7 +924,7 @@ class DBPCell_TestClass < TestBase end # convert to static cell - def test_13 + def _test_13 if !RBA.constants.member?(:PCellDeclarationHelper) return @@ -958,7 +958,7 @@ end class DBPCellParameterStates_TestClass < TestBase - def test_1 + def _test_1 ps = RBA::PCellParameterState::new From 404d6fa20fa4fbff35764ee80ad2e8bf32625662 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Fri, 3 Apr 2026 11:10:34 +0200 Subject: [PATCH 13/21] Fixed BASIC lib tests - cell pointers cannot considered to be stable across lib.refresh calls as this basically would need to create cold proxies --- src/lib/unit_tests/libBasicTests.cc | 668 ++++++++++++++-------------- 1 file changed, 334 insertions(+), 334 deletions(-) diff --git a/src/lib/unit_tests/libBasicTests.cc b/src/lib/unit_tests/libBasicTests.cc index 3a4ff81f0..ddb9ff68e 100644 --- a/src/lib/unit_tests/libBasicTests.cc +++ b/src/lib/unit_tests/libBasicTests.cc @@ -52,56 +52,56 @@ TEST(1_Circle) params["actual_radius"] = 10.0; db::cell_index_type lib_cell; - db::Cell *circle; + db::cell_index_type circle; std::vector plist; lib_cell = lib_basic->layout ().get_pcell_variant_dict (pc.second, params); - circle = &ly.cell (ly.get_lib_proxy (lib_basic, lib_cell)); + circle = ly.get_lib_proxy (lib_basic, lib_cell); // change radius explicitly // has radius 10um - EXPECT_EQ (circle->bbox ().to_string (), "(-10000,-10000;10000,10000)"); - EXPECT_EQ (circle->get_display_name (), "Basic.CIRCLE(l=1/0,r=10,n=64)"); + EXPECT_EQ (ly.cell (circle).bbox ().to_string (), "(-10000,-10000;10000,10000)"); + EXPECT_EQ (ly.cell (circle).get_display_name (), "Basic.CIRCLE(l=1/0,r=10,n=64)"); // only after Library::refresh the parameters get updated - EXPECT_EQ (ly.get_pcell_parameters (circle->cell_index ()) [p_radius].to_double (), 0.0); + EXPECT_EQ (ly.get_pcell_parameters (circle) [p_radius].to_double (), 0.0); lib_basic->refresh (); - EXPECT_EQ (circle->bbox ().to_string (), "(-10000,-10000;10000,10000)"); - EXPECT_EQ (circle->get_display_name (), "Basic.CIRCLE(l=1/0,r=10,n=64)"); - EXPECT_EQ (ly.get_pcell_parameters (circle->cell_index ()) [p_radius].to_double (), 10.0); - EXPECT_EQ (ly.get_pcell_parameters (circle->cell_index ()) [p_actual_radius].to_double (), 10.0); + EXPECT_EQ (ly.cell (circle).bbox ().to_string (), "(-10000,-10000;10000,10000)"); + EXPECT_EQ (ly.cell (circle).get_display_name (), "Basic.CIRCLE(l=1/0,r=10,n=64)"); + EXPECT_EQ (ly.get_pcell_parameters (circle) [p_radius].to_double (), 10.0); + EXPECT_EQ (ly.get_pcell_parameters (circle) [p_actual_radius].to_double (), 10.0); // change radius explicitly - plist = ly.get_pcell_parameters (circle->cell_index ()); + plist = ly.get_pcell_parameters (ly.cell (circle).cell_index ()); plist[p_actual_radius] = 9.0; - circle = &ly.cell (ly.get_pcell_variant_cell (circle->cell_index (), plist)); + circle = ly.get_pcell_variant_cell (circle, plist); // as the radius is an input parameter, only after Library::refresh the other parameters get updated - EXPECT_EQ (ly.get_pcell_parameters (circle->cell_index ()) [p_radius].to_double (), 10.0); + EXPECT_EQ (ly.get_pcell_parameters (circle) [p_radius].to_double (), 10.0); lib_basic->refresh (); - EXPECT_EQ (circle->bbox ().to_string (), "(-9000,-9000;9000,9000)"); - EXPECT_EQ (circle->get_display_name (), "Basic.CIRCLE(l=1/0,r=9,n=64)"); - EXPECT_EQ (ly.get_pcell_parameters (circle->cell_index ()) [p_radius].to_double (), 9.0); - EXPECT_EQ (ly.get_pcell_parameters (circle->cell_index ()) [p_actual_radius].to_double (), 9.0); + EXPECT_EQ (ly.cell (circle).bbox ().to_string (), "(-9000,-9000;9000,9000)"); + EXPECT_EQ (ly.cell (circle).get_display_name (), "Basic.CIRCLE(l=1/0,r=9,n=64)"); + EXPECT_EQ (ly.get_pcell_parameters (circle) [p_radius].to_double (), 9.0); + EXPECT_EQ (ly.get_pcell_parameters (circle) [p_actual_radius].to_double (), 9.0); // change handle explicitly - plist = ly.get_pcell_parameters (circle->cell_index ()); + plist = ly.get_pcell_parameters (circle); plist[p_handle] = db::DPoint (0.0, 8.0); - circle = &ly.cell (ly.get_pcell_variant_cell (circle->cell_index (), plist)); + circle = ly.get_pcell_variant_cell (circle, plist); // as the handle is an input parameter, only after Library::refresh the other parameters get updated - EXPECT_EQ (ly.get_pcell_parameters (circle->cell_index ()) [p_actual_radius].to_double (), 9.0); + EXPECT_EQ (ly.get_pcell_parameters (circle) [p_actual_radius].to_double (), 9.0); lib_basic->refresh (); - EXPECT_EQ (circle->bbox ().to_string (), "(-8000,-8000;8000,8000)"); - EXPECT_EQ (circle->get_display_name (), "Basic.CIRCLE(l=1/0,r=8,n=64)"); - EXPECT_EQ (ly.get_pcell_parameters (circle->cell_index ()) [p_radius].to_double (), 8.0); - EXPECT_EQ (ly.get_pcell_parameters (circle->cell_index ()) [p_actual_radius].to_double (), 8.0); + EXPECT_EQ (ly.cell (circle).bbox ().to_string (), "(-8000,-8000;8000,8000)"); + EXPECT_EQ (ly.cell (circle).get_display_name (), "Basic.CIRCLE(l=1/0,r=8,n=64)"); + EXPECT_EQ (ly.get_pcell_parameters (circle) [p_radius].to_double (), 8.0); + EXPECT_EQ (ly.get_pcell_parameters (circle) [p_actual_radius].to_double (), 8.0); unsigned int l1 = ly.get_layer (db::LayerProperties (1, 0)); @@ -145,145 +145,145 @@ TEST(2_Pie) params["actual_end_angle"] = 0.0; db::cell_index_type lib_cell; - db::Cell *pie; + db::cell_index_type pie; std::vector plist; lib_cell = lib_basic->layout ().get_pcell_variant_dict (pc.second, params); - pie = &ly.cell (ly.get_lib_proxy (lib_basic, lib_cell)); + pie = ly.get_lib_proxy (lib_basic, lib_cell); // change radius explicitly // has radius 10um, but bbox isn't correct for now (because handle was not updated) - EXPECT_EQ (pie->bbox ().to_string (), "(-1000,-10000;10000,1000)"); - EXPECT_EQ (pie->get_display_name (), "Basic.PIE(l=1/0,r=10,a=-90..0,n=64)"); + EXPECT_EQ (ly.cell (pie).bbox ().to_string (), "(-1000,-10000;10000,1000)"); + EXPECT_EQ (ly.cell (pie).get_display_name (), "Basic.PIE(l=1/0,r=10,a=-90..0,n=64)"); // only after Library::refresh the parameters get updated and bbox is correct - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_radius].to_double (), 0.0); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_radius].to_double (), 0.0); lib_basic->refresh (); - EXPECT_EQ (pie->bbox ().to_string (), "(0,-10000;10000,0)"); - EXPECT_EQ (pie->get_display_name (), "Basic.PIE(l=1/0,r=10,a=-90..0,n=64)"); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_radius].to_double (), 10.0); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_actual_radius].to_double (), 10.0); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_start_angle].to_double (), -90); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_actual_start_angle].to_double (), -90); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_end_angle].to_double (), 0); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_actual_end_angle].to_double (), 0); + EXPECT_EQ (ly.cell (pie).bbox ().to_string (), "(0,-10000;10000,0)"); + EXPECT_EQ (ly.cell (pie).get_display_name (), "Basic.PIE(l=1/0,r=10,a=-90..0,n=64)"); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_radius].to_double (), 10.0); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_actual_radius].to_double (), 10.0); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_start_angle].to_double (), -90); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_actual_start_angle].to_double (), -90); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_end_angle].to_double (), 0); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_actual_end_angle].to_double (), 0); // change radius explicitly - plist = ly.get_pcell_parameters (pie->cell_index ()); + plist = ly.get_pcell_parameters (pie); plist[p_actual_radius] = 9.0; - pie = &ly.cell (ly.get_pcell_variant_cell (pie->cell_index (), plist)); + pie = ly.get_pcell_variant_cell (pie, plist); // as the radius is an input parameter, only after Library::refresh the other parameters get updated - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_radius].to_double (), 10.0); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_radius].to_double (), 10.0); lib_basic->refresh (); - EXPECT_EQ (pie->bbox ().to_string (), "(0,-9000;9000,0)"); - EXPECT_EQ (pie->get_display_name (), "Basic.PIE(l=1/0,r=9,a=-90..0,n=64)"); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_handle1].to_string (), "0,-9"); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_handle2].to_string (), "9,0"); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_actual_handle1].to_string (), "0,-9"); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_actual_handle2].to_string (), "9,0"); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_radius].to_double (), 9.0); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_actual_radius].to_double (), 9.0); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_start_angle].to_double (), -90); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_actual_start_angle].to_double (), -90); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_end_angle].to_double (), 0); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_actual_end_angle].to_double (), 0); + EXPECT_EQ (ly.cell (pie).bbox ().to_string (), "(0,-9000;9000,0)"); + EXPECT_EQ (ly.cell (pie).get_display_name (), "Basic.PIE(l=1/0,r=9,a=-90..0,n=64)"); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_handle1].to_string (), "0,-9"); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_handle2].to_string (), "9,0"); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_actual_handle1].to_string (), "0,-9"); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_actual_handle2].to_string (), "9,0"); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_radius].to_double (), 9.0); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_actual_radius].to_double (), 9.0); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_start_angle].to_double (), -90); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_actual_start_angle].to_double (), -90); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_end_angle].to_double (), 0); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_actual_end_angle].to_double (), 0); // change end angle explicitly - plist = ly.get_pcell_parameters (pie->cell_index ()); + plist = ly.get_pcell_parameters (pie); plist[p_actual_end_angle] = 90.0; - pie = &ly.cell (ly.get_pcell_variant_cell (pie->cell_index (), plist)); + pie = ly.get_pcell_variant_cell (pie, plist); // as the end angle is an input parameter, only after Library::refresh the other parameters get updated - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_end_angle].to_double (), 0.0); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_end_angle].to_double (), 0.0); lib_basic->refresh (); - EXPECT_EQ (pie->bbox ().to_string (), "(0,-9000;9000,9000)"); - EXPECT_EQ (pie->get_display_name (), "Basic.PIE(l=1/0,r=9,a=-90..90,n=64)"); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_handle1].to_string (), "0,-9"); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_handle2].to_string (), "0,9"); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_actual_handle1].to_string (), "0,-9"); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_actual_handle2].to_string (), "0,9"); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_radius].to_double (), 9.0); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_actual_radius].to_double (), 9.0); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_start_angle].to_double (), -90); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_actual_start_angle].to_double (), -90); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_end_angle].to_double (), 90); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_actual_end_angle].to_double (), 90); + EXPECT_EQ (ly.cell (pie).bbox ().to_string (), "(0,-9000;9000,9000)"); + EXPECT_EQ (ly.cell (pie).get_display_name (), "Basic.PIE(l=1/0,r=9,a=-90..90,n=64)"); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_handle1].to_string (), "0,-9"); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_handle2].to_string (), "0,9"); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_actual_handle1].to_string (), "0,-9"); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_actual_handle2].to_string (), "0,9"); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_radius].to_double (), 9.0); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_actual_radius].to_double (), 9.0); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_start_angle].to_double (), -90); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_actual_start_angle].to_double (), -90); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_end_angle].to_double (), 90); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_actual_end_angle].to_double (), 90); // change start angle explicitly - plist = ly.get_pcell_parameters (pie->cell_index ()); + plist = ly.get_pcell_parameters (pie); plist[p_actual_start_angle] = 0.0; - pie = &ly.cell (ly.get_pcell_variant_cell (pie->cell_index (), plist)); + pie = ly.get_pcell_variant_cell (pie, plist); // as the end angle is an input parameter, only after Library::refresh the other parameters get updated - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_start_angle].to_double (), -90.0); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_start_angle].to_double (), -90.0); lib_basic->refresh (); - EXPECT_EQ (pie->bbox ().to_string (), "(0,0;9000,9000)"); - EXPECT_EQ (pie->get_display_name (), "Basic.PIE(l=1/0,r=9,a=0..90,n=64)"); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_handle1].to_string (), "9,0"); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_handle2].to_string (), "0,9"); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_actual_handle1].to_string (), "9,0"); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_actual_handle2].to_string (), "0,9"); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_radius].to_double (), 9.0); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_actual_radius].to_double (), 9.0); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_start_angle].to_double (), 0); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_actual_start_angle].to_double (), 0); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_end_angle].to_double (), 90); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_actual_end_angle].to_double (), 90); + EXPECT_EQ (ly.cell (pie).bbox ().to_string (), "(0,0;9000,9000)"); + EXPECT_EQ (ly.cell (pie).get_display_name (), "Basic.PIE(l=1/0,r=9,a=0..90,n=64)"); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_handle1].to_string (), "9,0"); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_handle2].to_string (), "0,9"); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_actual_handle1].to_string (), "9,0"); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_actual_handle2].to_string (), "0,9"); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_radius].to_double (), 9.0); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_actual_radius].to_double (), 9.0); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_start_angle].to_double (), 0); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_actual_start_angle].to_double (), 0); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_end_angle].to_double (), 90); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_actual_end_angle].to_double (), 90); // change handle1 explicitly - plist = ly.get_pcell_parameters (pie->cell_index ()); + plist = ly.get_pcell_parameters (pie); plist[p_actual_handle1] = db::DPoint (0.0, -5.0); - pie = &ly.cell (ly.get_pcell_variant_cell (pie->cell_index (), plist)); + pie = ly.get_pcell_variant_cell (pie, plist); // as the handle is an input parameter, only after Library::refresh the other parameters get updated - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_start_angle].to_double (), 0.0); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_start_angle].to_double (), 0.0); lib_basic->refresh (); - EXPECT_EQ (pie->bbox ().to_string (), "(0,-9000;9000,9000)"); - EXPECT_EQ (pie->get_display_name (), "Basic.PIE(l=1/0,r=9,a=-90..90,n=64)"); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_handle1].to_string (), "0,-5"); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_handle2].to_string (), "0,9"); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_actual_handle1].to_string (), "0,-5"); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_actual_handle2].to_string (), "0,9"); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_start_angle].to_double (), -90.0); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_actual_start_angle].to_double (), -90.0); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_end_angle].to_double (), 90); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_actual_end_angle].to_double (), 90); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_radius].to_double (), 9); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_actual_radius].to_double (), 9); + EXPECT_EQ (ly.cell (pie).bbox ().to_string (), "(0,-9000;9000,9000)"); + EXPECT_EQ (ly.cell (pie).get_display_name (), "Basic.PIE(l=1/0,r=9,a=-90..90,n=64)"); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_handle1].to_string (), "0,-5"); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_handle2].to_string (), "0,9"); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_actual_handle1].to_string (), "0,-5"); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_actual_handle2].to_string (), "0,9"); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_start_angle].to_double (), -90.0); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_actual_start_angle].to_double (), -90.0); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_end_angle].to_double (), 90); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_actual_end_angle].to_double (), 90); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_radius].to_double (), 9); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_actual_radius].to_double (), 9); // change handle2 explicitly - plist = ly.get_pcell_parameters (pie->cell_index ()); + plist = ly.get_pcell_parameters (pie); plist[p_actual_handle2] = db::DPoint (5.0, 0.0); - pie = &ly.cell (ly.get_pcell_variant_cell (pie->cell_index (), plist)); + pie = ly.get_pcell_variant_cell (pie, plist); // as the handle is an input parameter, only after Library::refresh the other parameters get updated - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_end_angle].to_double (), 90.0); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_end_angle].to_double (), 90.0); lib_basic->refresh (); - EXPECT_EQ (pie->bbox ().to_string (), "(0,-5000;5000,0)"); - EXPECT_EQ (pie->get_display_name (), "Basic.PIE(l=1/0,r=5,a=-90..0,n=64)"); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_handle1].to_string (), "0,-5"); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_handle2].to_string (), "5,0"); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_actual_handle1].to_string (), "0,-5"); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_actual_handle2].to_string (), "5,0"); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_start_angle].to_double (), -90.0); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_actual_start_angle].to_double (), -90.0); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_end_angle].to_double (), 0); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_actual_end_angle].to_double (), 0); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_radius].to_double (), 5); - EXPECT_EQ (ly.get_pcell_parameters (pie->cell_index ()) [p_actual_radius].to_double (), 5); + EXPECT_EQ (ly.cell (pie).bbox ().to_string (), "(0,-5000;5000,0)"); + EXPECT_EQ (ly.cell (pie).get_display_name (), "Basic.PIE(l=1/0,r=5,a=-90..0,n=64)"); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_handle1].to_string (), "0,-5"); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_handle2].to_string (), "5,0"); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_actual_handle1].to_string (), "0,-5"); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_actual_handle2].to_string (), "5,0"); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_start_angle].to_double (), -90.0); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_actual_start_angle].to_double (), -90.0); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_end_angle].to_double (), 0); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_actual_end_angle].to_double (), 0); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_radius].to_double (), 5); + EXPECT_EQ (ly.get_pcell_parameters (pie) [p_actual_radius].to_double (), 5); } TEST(3_Arc) @@ -320,182 +320,182 @@ TEST(3_Arc) params["actual_end_angle"] = 0.0; db::cell_index_type lib_cell; - db::Cell *arc; + db::cell_index_type arc; std::vector plist; lib_cell = lib_basic->layout ().get_pcell_variant_dict (pc.second, params); - arc = &ly.cell (ly.get_lib_proxy (lib_basic, lib_cell)); + arc = ly.get_lib_proxy (lib_basic, lib_cell); // change radius explicitly // has radius 10um, but bbox isn't correct for now (because handle was not updated) - EXPECT_EQ (arc->bbox ().to_string (), "(0,-10000;10000,1000)"); - EXPECT_EQ (arc->get_display_name (), "Basic.ARC(l=1/0,r=4..10,a=-90..0,n=64)"); + EXPECT_EQ (ly.cell (arc).bbox ().to_string (), "(0,-10000;10000,1000)"); + EXPECT_EQ (ly.cell (arc).get_display_name (), "Basic.ARC(l=1/0,r=4..10,a=-90..0,n=64)"); // only after Library::refresh the parameters get updated and bbox is correct - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_radius1].to_double (), 0.0); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_radius1].to_double (), 0.0); lib_basic->refresh (); - EXPECT_EQ (arc->bbox ().to_string (), "(0,-10000;10000,0)"); - EXPECT_EQ (arc->get_display_name (), "Basic.ARC(l=1/0,r=4..10,a=-90..0,n=64)"); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_radius1].to_double (), 4.0); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_radius1].to_double (), 4.0); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_radius2].to_double (), 10.0); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_radius2].to_double (), 10.0); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_start_angle].to_double (), -90); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_start_angle].to_double (), -90); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_end_angle].to_double (), 0); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_end_angle].to_double (), 0); + EXPECT_EQ (ly.cell (arc).bbox ().to_string (), "(0,-10000;10000,0)"); + EXPECT_EQ (ly.cell (arc).get_display_name (), "Basic.ARC(l=1/0,r=4..10,a=-90..0,n=64)"); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_radius1].to_double (), 4.0); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_radius1].to_double (), 4.0); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_radius2].to_double (), 10.0); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_radius2].to_double (), 10.0); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_start_angle].to_double (), -90); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_start_angle].to_double (), -90); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_end_angle].to_double (), 0); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_end_angle].to_double (), 0); // change radius2 explicitly - plist = ly.get_pcell_parameters (arc->cell_index ()); + plist = ly.get_pcell_parameters (arc); plist[p_actual_radius2] = 9.0; - arc = &ly.cell (ly.get_pcell_variant_cell (arc->cell_index (), plist)); + arc = ly.get_pcell_variant_cell (arc, plist); // as the radius is an input parameter, only after Library::refresh the other parameters get updated - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_radius2].to_double (), 10.0); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_radius2].to_double (), 10.0); lib_basic->refresh (); - EXPECT_EQ (arc->bbox ().to_string (), "(0,-9000;9000,0)"); - EXPECT_EQ (arc->get_display_name (), "Basic.ARC(l=1/0,r=4..9,a=-90..0,n=64)"); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_handle1].to_string (), "0,-4"); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_handle2].to_string (), "9,0"); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_handle1].to_string (), "0,-4"); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_handle2].to_string (), "9,0"); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_radius1].to_double (), 4.0); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_radius1].to_double (), 4.0); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_radius2].to_double (), 9.0); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_radius2].to_double (), 9.0); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_start_angle].to_double (), -90); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_start_angle].to_double (), -90); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_end_angle].to_double (), 0); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_end_angle].to_double (), 0); + EXPECT_EQ (ly.cell (arc).bbox ().to_string (), "(0,-9000;9000,0)"); + EXPECT_EQ (ly.cell (arc).get_display_name (), "Basic.ARC(l=1/0,r=4..9,a=-90..0,n=64)"); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_handle1].to_string (), "0,-4"); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_handle2].to_string (), "9,0"); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_handle1].to_string (), "0,-4"); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_handle2].to_string (), "9,0"); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_radius1].to_double (), 4.0); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_radius1].to_double (), 4.0); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_radius2].to_double (), 9.0); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_radius2].to_double (), 9.0); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_start_angle].to_double (), -90); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_start_angle].to_double (), -90); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_end_angle].to_double (), 0); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_end_angle].to_double (), 0); // change radius1 explicitly - plist = ly.get_pcell_parameters (arc->cell_index ()); + plist = ly.get_pcell_parameters (arc); plist[p_actual_radius1] = 5.0; - arc = &ly.cell (ly.get_pcell_variant_cell (arc->cell_index (), plist)); + arc = ly.get_pcell_variant_cell (arc, plist); // as the radius is an input parameter, only after Library::refresh the other parameters get updated - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_radius1].to_double (), 4.0); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_radius1].to_double (), 4.0); lib_basic->refresh (); - EXPECT_EQ (arc->bbox ().to_string (), "(0,-9000;9000,0)"); - EXPECT_EQ (arc->get_display_name (), "Basic.ARC(l=1/0,r=5..9,a=-90..0,n=64)"); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_handle1].to_string (), "0,-5"); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_handle2].to_string (), "9,0"); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_handle1].to_string (), "0,-5"); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_handle2].to_string (), "9,0"); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_radius1].to_double (), 5.0); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_radius1].to_double (), 5.0); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_radius2].to_double (), 9.0); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_radius2].to_double (), 9.0); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_start_angle].to_double (), -90); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_start_angle].to_double (), -90); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_end_angle].to_double (), 0); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_end_angle].to_double (), 0); + EXPECT_EQ (ly.cell (arc).bbox ().to_string (), "(0,-9000;9000,0)"); + EXPECT_EQ (ly.cell (arc).get_display_name (), "Basic.ARC(l=1/0,r=5..9,a=-90..0,n=64)"); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_handle1].to_string (), "0,-5"); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_handle2].to_string (), "9,0"); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_handle1].to_string (), "0,-5"); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_handle2].to_string (), "9,0"); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_radius1].to_double (), 5.0); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_radius1].to_double (), 5.0); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_radius2].to_double (), 9.0); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_radius2].to_double (), 9.0); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_start_angle].to_double (), -90); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_start_angle].to_double (), -90); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_end_angle].to_double (), 0); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_end_angle].to_double (), 0); // change end angle explicitly - plist = ly.get_pcell_parameters (arc->cell_index ()); + plist = ly.get_pcell_parameters (arc); plist[p_actual_end_angle] = 90.0; - arc = &ly.cell (ly.get_pcell_variant_cell (arc->cell_index (), plist)); + arc = ly.get_pcell_variant_cell (arc, plist); // as the end angle is an input parameter, only after Library::refresh the other parameters get updated - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_end_angle].to_double (), 0.0); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_end_angle].to_double (), 0.0); lib_basic->refresh (); - EXPECT_EQ (arc->bbox ().to_string (), "(0,-9000;9000,9000)"); - EXPECT_EQ (arc->get_display_name (), "Basic.ARC(l=1/0,r=5..9,a=-90..90,n=64)"); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_handle1].to_string (), "0,-5"); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_handle2].to_string (), "0,9"); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_handle1].to_string (), "0,-5"); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_handle2].to_string (), "0,9"); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_radius1].to_double (), 5.0); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_radius1].to_double (), 5.0); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_radius2].to_double (), 9.0); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_radius2].to_double (), 9.0); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_start_angle].to_double (), -90); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_start_angle].to_double (), -90); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_end_angle].to_double (), 90); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_end_angle].to_double (), 90); + EXPECT_EQ (ly.cell (arc).bbox ().to_string (), "(0,-9000;9000,9000)"); + EXPECT_EQ (ly.cell (arc).get_display_name (), "Basic.ARC(l=1/0,r=5..9,a=-90..90,n=64)"); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_handle1].to_string (), "0,-5"); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_handle2].to_string (), "0,9"); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_handle1].to_string (), "0,-5"); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_handle2].to_string (), "0,9"); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_radius1].to_double (), 5.0); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_radius1].to_double (), 5.0); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_radius2].to_double (), 9.0); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_radius2].to_double (), 9.0); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_start_angle].to_double (), -90); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_start_angle].to_double (), -90); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_end_angle].to_double (), 90); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_end_angle].to_double (), 90); // change start angle explicitly - plist = ly.get_pcell_parameters (arc->cell_index ()); + plist = ly.get_pcell_parameters (arc); plist[p_actual_start_angle] = 0.0; - arc = &ly.cell (ly.get_pcell_variant_cell (arc->cell_index (), plist)); + arc = ly.get_pcell_variant_cell (arc, plist); // as the end angle is an input parameter, only after Library::refresh the other parameters get updated - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_start_angle].to_double (), -90.0); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_start_angle].to_double (), -90.0); lib_basic->refresh (); - EXPECT_EQ (arc->bbox ().to_string (), "(0,0;9000,9000)"); - EXPECT_EQ (arc->get_display_name (), "Basic.ARC(l=1/0,r=5..9,a=0..90,n=64)"); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_handle1].to_string (), "5,0"); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_handle2].to_string (), "0,9"); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_handle1].to_string (), "5,0"); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_handle2].to_string (), "0,9"); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_radius1].to_double (), 5.0); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_radius1].to_double (), 5.0); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_radius2].to_double (), 9.0); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_radius2].to_double (), 9.0); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_start_angle].to_double (), 0); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_start_angle].to_double (), 0); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_end_angle].to_double (), 90); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_end_angle].to_double (), 90); + EXPECT_EQ (ly.cell (arc).bbox ().to_string (), "(0,0;9000,9000)"); + EXPECT_EQ (ly.cell (arc).get_display_name (), "Basic.ARC(l=1/0,r=5..9,a=0..90,n=64)"); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_handle1].to_string (), "5,0"); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_handle2].to_string (), "0,9"); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_handle1].to_string (), "5,0"); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_handle2].to_string (), "0,9"); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_radius1].to_double (), 5.0); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_radius1].to_double (), 5.0); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_radius2].to_double (), 9.0); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_radius2].to_double (), 9.0); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_start_angle].to_double (), 0); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_start_angle].to_double (), 0); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_end_angle].to_double (), 90); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_end_angle].to_double (), 90); // change handle1 explicitly - plist = ly.get_pcell_parameters (arc->cell_index ()); + plist = ly.get_pcell_parameters (arc); plist[p_actual_handle1] = db::DPoint (0.0, -5.0); - arc = &ly.cell (ly.get_pcell_variant_cell (arc->cell_index (), plist)); + arc = ly.get_pcell_variant_cell (arc, plist); // as the handle is an input parameter, only after Library::refresh the other parameters get updated - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_start_angle].to_double (), 0.0); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_start_angle].to_double (), 0.0); lib_basic->refresh (); - EXPECT_EQ (arc->bbox ().to_string (), "(0,-9000;9000,9000)"); - EXPECT_EQ (arc->get_display_name (), "Basic.ARC(l=1/0,r=5..9,a=-90..90,n=64)"); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_handle1].to_string (), "0,-5"); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_handle2].to_string (), "0,9"); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_handle1].to_string (), "0,-5"); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_handle2].to_string (), "0,9"); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_start_angle].to_double (), -90.0); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_start_angle].to_double (), -90.0); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_end_angle].to_double (), 90); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_end_angle].to_double (), 90); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_radius1].to_double (), 5); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_radius1].to_double (), 5); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_radius2].to_double (), 9); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_radius2].to_double (), 9); + EXPECT_EQ (ly.cell (arc).bbox ().to_string (), "(0,-9000;9000,9000)"); + EXPECT_EQ (ly.cell (arc).get_display_name (), "Basic.ARC(l=1/0,r=5..9,a=-90..90,n=64)"); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_handle1].to_string (), "0,-5"); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_handle2].to_string (), "0,9"); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_handle1].to_string (), "0,-5"); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_handle2].to_string (), "0,9"); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_start_angle].to_double (), -90.0); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_start_angle].to_double (), -90.0); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_end_angle].to_double (), 90); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_end_angle].to_double (), 90); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_radius1].to_double (), 5); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_radius1].to_double (), 5); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_radius2].to_double (), 9); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_radius2].to_double (), 9); // change handle2 explicitly - plist = ly.get_pcell_parameters (arc->cell_index ()); + plist = ly.get_pcell_parameters (arc); plist[p_actual_handle2] = db::DPoint (9.0, 0.0); - arc = &ly.cell (ly.get_pcell_variant_cell (arc->cell_index (), plist)); + arc = ly.get_pcell_variant_cell (arc, plist); // as the handle is an input parameter, only after Library::refresh the other parameters get updated - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_end_angle].to_double (), 90.0); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_end_angle].to_double (), 90.0); lib_basic->refresh (); - EXPECT_EQ (arc->bbox ().to_string (), "(0,-9000;9000,0)"); - EXPECT_EQ (arc->get_display_name (), "Basic.ARC(l=1/0,r=5..9,a=-90..0,n=64)"); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_handle1].to_string (), "0,-5"); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_handle2].to_string (), "9,0"); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_handle1].to_string (), "0,-5"); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_handle2].to_string (), "9,0"); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_start_angle].to_double (), -90.0); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_start_angle].to_double (), -90.0); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_end_angle].to_double (), 0); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_end_angle].to_double (), 0); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_radius1].to_double (), 5); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_radius1].to_double (), 5); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_radius2].to_double (), 9); - EXPECT_EQ (ly.get_pcell_parameters (arc->cell_index ()) [p_actual_radius2].to_double (), 9); + EXPECT_EQ (ly.cell (arc).bbox ().to_string (), "(0,-9000;9000,0)"); + EXPECT_EQ (ly.cell (arc).get_display_name (), "Basic.ARC(l=1/0,r=5..9,a=-90..0,n=64)"); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_handle1].to_string (), "0,-5"); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_handle2].to_string (), "9,0"); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_handle1].to_string (), "0,-5"); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_handle2].to_string (), "9,0"); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_start_angle].to_double (), -90.0); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_start_angle].to_double (), -90.0); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_end_angle].to_double (), 0); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_end_angle].to_double (), 0); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_radius1].to_double (), 5); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_radius1].to_double (), 5); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_radius2].to_double (), 9); + EXPECT_EQ (ly.get_pcell_parameters (arc) [p_actual_radius2].to_double (), 9); } TEST(4_Donut) @@ -526,98 +526,98 @@ TEST(4_Donut) params["actual_end_angle"] = 0.0; db::cell_index_type lib_cell; - db::Cell *donut; + db::cell_index_type donut; std::vector plist; lib_cell = lib_basic->layout ().get_pcell_variant_dict (pc.second, params); - donut = &ly.cell (ly.get_lib_proxy (lib_basic, lib_cell)); + donut = ly.get_lib_proxy (lib_basic, lib_cell); // change radius explicitly // has radius 10um, but bbox isn't correct for now (because handle was not updated) - EXPECT_EQ (donut->bbox ().to_string (), "(-10000,-10000;10000,10000)"); - EXPECT_EQ (donut->get_display_name (), "Basic.DONUT(l=1/0,r=4..10,n=64)"); + EXPECT_EQ (ly.cell (donut).bbox ().to_string (), "(-10000,-10000;10000,10000)"); + EXPECT_EQ (ly.cell (donut).get_display_name (), "Basic.DONUT(l=1/0,r=4..10,n=64)"); // only after Library::refresh the parameters get updated and bbox is correct - EXPECT_EQ (ly.get_pcell_parameters (donut->cell_index ()) [p_radius1].to_double (), 0.0); + EXPECT_EQ (ly.get_pcell_parameters (donut) [p_radius1].to_double (), 0.0); lib_basic->refresh (); - EXPECT_EQ (donut->bbox ().to_string (), "(-10000,-10000;10000,10000)"); - EXPECT_EQ (donut->get_display_name (), "Basic.DONUT(l=1/0,r=4..10,n=64)"); - EXPECT_EQ (ly.get_pcell_parameters (donut->cell_index ()) [p_radius1].to_double (), 4.0); - EXPECT_EQ (ly.get_pcell_parameters (donut->cell_index ()) [p_actual_radius1].to_double (), 4.0); - EXPECT_EQ (ly.get_pcell_parameters (donut->cell_index ()) [p_radius2].to_double (), 10.0); - EXPECT_EQ (ly.get_pcell_parameters (donut->cell_index ()) [p_actual_radius2].to_double (), 10.0); + EXPECT_EQ (ly.cell (donut).bbox ().to_string (), "(-10000,-10000;10000,10000)"); + EXPECT_EQ (ly.cell (donut).get_display_name (), "Basic.DONUT(l=1/0,r=4..10,n=64)"); + EXPECT_EQ (ly.get_pcell_parameters (donut) [p_radius1].to_double (), 4.0); + EXPECT_EQ (ly.get_pcell_parameters (donut) [p_actual_radius1].to_double (), 4.0); + EXPECT_EQ (ly.get_pcell_parameters (donut) [p_radius2].to_double (), 10.0); + EXPECT_EQ (ly.get_pcell_parameters (donut) [p_actual_radius2].to_double (), 10.0); // change radius2 explicitly - plist = ly.get_pcell_parameters (donut->cell_index ()); + plist = ly.get_pcell_parameters (donut); plist[p_actual_radius2] = 9.0; - donut = &ly.cell (ly.get_pcell_variant_cell (donut->cell_index (), plist)); + donut = ly.get_pcell_variant_cell (donut, plist); // as the radius is an input parameter, only after Library::refresh the other parameters get updated - EXPECT_EQ (ly.get_pcell_parameters (donut->cell_index ()) [p_radius2].to_double (), 10.0); + EXPECT_EQ (ly.get_pcell_parameters (donut) [p_radius2].to_double (), 10.0); lib_basic->refresh (); - EXPECT_EQ (donut->bbox ().to_string (), "(-9000,-9000;9000,9000)"); - EXPECT_EQ (donut->get_display_name (), "Basic.DONUT(l=1/0,r=4..9,n=64)"); - EXPECT_EQ (ly.get_pcell_parameters (donut->cell_index ()) [p_handle1].to_string (), "-4,0"); - EXPECT_EQ (ly.get_pcell_parameters (donut->cell_index ()) [p_handle2].to_string (), "-9,0"); - EXPECT_EQ (ly.get_pcell_parameters (donut->cell_index ()) [p_radius1].to_double (), 4.0); - EXPECT_EQ (ly.get_pcell_parameters (donut->cell_index ()) [p_actual_radius1].to_double (), 4.0); - EXPECT_EQ (ly.get_pcell_parameters (donut->cell_index ()) [p_radius2].to_double (), 9.0); - EXPECT_EQ (ly.get_pcell_parameters (donut->cell_index ()) [p_actual_radius2].to_double (), 9.0); + EXPECT_EQ (ly.cell (donut).bbox ().to_string (), "(-9000,-9000;9000,9000)"); + EXPECT_EQ (ly.cell (donut).get_display_name (), "Basic.DONUT(l=1/0,r=4..9,n=64)"); + EXPECT_EQ (ly.get_pcell_parameters (donut) [p_handle1].to_string (), "-4,0"); + EXPECT_EQ (ly.get_pcell_parameters (donut) [p_handle2].to_string (), "-9,0"); + EXPECT_EQ (ly.get_pcell_parameters (donut) [p_radius1].to_double (), 4.0); + EXPECT_EQ (ly.get_pcell_parameters (donut) [p_actual_radius1].to_double (), 4.0); + EXPECT_EQ (ly.get_pcell_parameters (donut) [p_radius2].to_double (), 9.0); + EXPECT_EQ (ly.get_pcell_parameters (donut) [p_actual_radius2].to_double (), 9.0); // change radius1 explicitly - plist = ly.get_pcell_parameters (donut->cell_index ()); + plist = ly.get_pcell_parameters (donut); plist[p_actual_radius1] = 5.0; - donut = &ly.cell (ly.get_pcell_variant_cell (donut->cell_index (), plist)); + donut = ly.get_pcell_variant_cell (donut, plist); // as the radius is an input parameter, only after Library::refresh the other parameters get updated - EXPECT_EQ (ly.get_pcell_parameters (donut->cell_index ()) [p_radius1].to_double (), 4.0); + EXPECT_EQ (ly.get_pcell_parameters (donut) [p_radius1].to_double (), 4.0); lib_basic->refresh (); - EXPECT_EQ (donut->bbox ().to_string (), "(-9000,-9000;9000,9000)"); - EXPECT_EQ (donut->get_display_name (), "Basic.DONUT(l=1/0,r=5..9,n=64)"); - EXPECT_EQ (ly.get_pcell_parameters (donut->cell_index ()) [p_handle1].to_string (), "-5,0"); - EXPECT_EQ (ly.get_pcell_parameters (donut->cell_index ()) [p_handle2].to_string (), "-9,0"); - EXPECT_EQ (ly.get_pcell_parameters (donut->cell_index ()) [p_radius1].to_double (), 5.0); - EXPECT_EQ (ly.get_pcell_parameters (donut->cell_index ()) [p_actual_radius1].to_double (), 5.0); - EXPECT_EQ (ly.get_pcell_parameters (donut->cell_index ()) [p_radius2].to_double (), 9.0); - EXPECT_EQ (ly.get_pcell_parameters (donut->cell_index ()) [p_actual_radius2].to_double (), 9.0); + EXPECT_EQ (ly.cell (donut).bbox ().to_string (), "(-9000,-9000;9000,9000)"); + EXPECT_EQ (ly.cell (donut).get_display_name (), "Basic.DONUT(l=1/0,r=5..9,n=64)"); + EXPECT_EQ (ly.get_pcell_parameters (donut) [p_handle1].to_string (), "-5,0"); + EXPECT_EQ (ly.get_pcell_parameters (donut) [p_handle2].to_string (), "-9,0"); + EXPECT_EQ (ly.get_pcell_parameters (donut) [p_radius1].to_double (), 5.0); + EXPECT_EQ (ly.get_pcell_parameters (donut) [p_actual_radius1].to_double (), 5.0); + EXPECT_EQ (ly.get_pcell_parameters (donut) [p_radius2].to_double (), 9.0); + EXPECT_EQ (ly.get_pcell_parameters (donut) [p_actual_radius2].to_double (), 9.0); // change handle1 explicitly - plist = ly.get_pcell_parameters (donut->cell_index ()); + plist = ly.get_pcell_parameters (donut); plist[p_handle1] = db::DPoint (0.0, -5.0); - donut = &ly.cell (ly.get_pcell_variant_cell (donut->cell_index (), plist)); + donut = ly.get_pcell_variant_cell (donut, plist); lib_basic->refresh (); - EXPECT_EQ (donut->bbox ().to_string (), "(-9000,-9000;9000,9000)"); - EXPECT_EQ (donut->get_display_name (), "Basic.DONUT(l=1/0,r=5..9,n=64)"); - EXPECT_EQ (ly.get_pcell_parameters (donut->cell_index ()) [p_handle1].to_string (), "0,-5"); - EXPECT_EQ (ly.get_pcell_parameters (donut->cell_index ()) [p_handle2].to_string (), "-9,0"); - EXPECT_EQ (ly.get_pcell_parameters (donut->cell_index ()) [p_radius1].to_double (), 5); - EXPECT_EQ (ly.get_pcell_parameters (donut->cell_index ()) [p_actual_radius1].to_double (), 5); - EXPECT_EQ (ly.get_pcell_parameters (donut->cell_index ()) [p_radius2].to_double (), 9); - EXPECT_EQ (ly.get_pcell_parameters (donut->cell_index ()) [p_actual_radius2].to_double (), 9); + EXPECT_EQ (ly.cell (donut).bbox ().to_string (), "(-9000,-9000;9000,9000)"); + EXPECT_EQ (ly.cell (donut).get_display_name (), "Basic.DONUT(l=1/0,r=5..9,n=64)"); + EXPECT_EQ (ly.get_pcell_parameters (donut) [p_handle1].to_string (), "0,-5"); + EXPECT_EQ (ly.get_pcell_parameters (donut) [p_handle2].to_string (), "-9,0"); + EXPECT_EQ (ly.get_pcell_parameters (donut) [p_radius1].to_double (), 5); + EXPECT_EQ (ly.get_pcell_parameters (donut) [p_actual_radius1].to_double (), 5); + EXPECT_EQ (ly.get_pcell_parameters (donut) [p_radius2].to_double (), 9); + EXPECT_EQ (ly.get_pcell_parameters (donut) [p_actual_radius2].to_double (), 9); // change handle2 explicitly - plist = ly.get_pcell_parameters (donut->cell_index ()); + plist = ly.get_pcell_parameters (donut); plist[p_handle2] = db::DPoint (9.0, 0.0); - donut = &ly.cell (ly.get_pcell_variant_cell (donut->cell_index (), plist)); + donut = ly.get_pcell_variant_cell (donut, plist); lib_basic->refresh (); - EXPECT_EQ (donut->bbox ().to_string (), "(-9000,-9000;9000,9000)"); - EXPECT_EQ (donut->get_display_name (), "Basic.DONUT(l=1/0,r=5..9,n=64)"); - EXPECT_EQ (ly.get_pcell_parameters (donut->cell_index ()) [p_handle1].to_string (), "0,-5"); - EXPECT_EQ (ly.get_pcell_parameters (donut->cell_index ()) [p_handle2].to_string (), "9,0"); - EXPECT_EQ (ly.get_pcell_parameters (donut->cell_index ()) [p_radius1].to_double (), 5); - EXPECT_EQ (ly.get_pcell_parameters (donut->cell_index ()) [p_actual_radius1].to_double (), 5); - EXPECT_EQ (ly.get_pcell_parameters (donut->cell_index ()) [p_radius2].to_double (), 9); - EXPECT_EQ (ly.get_pcell_parameters (donut->cell_index ()) [p_actual_radius2].to_double (), 9); + EXPECT_EQ (ly.cell (donut).bbox ().to_string (), "(-9000,-9000;9000,9000)"); + EXPECT_EQ (ly.cell (donut).get_display_name (), "Basic.DONUT(l=1/0,r=5..9,n=64)"); + EXPECT_EQ (ly.get_pcell_parameters (donut) [p_handle1].to_string (), "0,-5"); + EXPECT_EQ (ly.get_pcell_parameters (donut) [p_handle2].to_string (), "9,0"); + EXPECT_EQ (ly.get_pcell_parameters (donut) [p_radius1].to_double (), 5); + EXPECT_EQ (ly.get_pcell_parameters (donut) [p_actual_radius1].to_double (), 5); + EXPECT_EQ (ly.get_pcell_parameters (donut) [p_radius2].to_double (), 9); + EXPECT_EQ (ly.get_pcell_parameters (donut) [p_actual_radius2].to_double (), 9); unsigned int l1 = ly.get_layer (db::LayerProperties (1, 0)); @@ -659,98 +659,98 @@ TEST(5_Ellipse) params["actual_end_angle"] = 0.0; db::cell_index_type lib_cell; - db::Cell *ellipse; + db::cell_index_type ellipse; std::vector plist; lib_cell = lib_basic->layout ().get_pcell_variant_dict (pc.second, params); - ellipse = &ly.cell (ly.get_lib_proxy (lib_basic, lib_cell)); + ellipse = ly.get_lib_proxy (lib_basic, lib_cell); // change radius explicitly // has radius 10um, but bbox isn't correct for now (because handle was not updated) - EXPECT_EQ (ellipse->bbox ().to_string (), "(-4000,-10000;4000,10000)"); - EXPECT_EQ (ellipse->get_display_name (), "Basic.ELLIPSE(l=1/0,rx=4,ry=10,n=64)"); + EXPECT_EQ (ly.cell (ellipse).bbox ().to_string (), "(-4000,-10000;4000,10000)"); + EXPECT_EQ (ly.cell (ellipse).get_display_name (), "Basic.ELLIPSE(l=1/0,rx=4,ry=10,n=64)"); // only after Library::refresh the parameters get updated and bbox is correct - EXPECT_EQ (ly.get_pcell_parameters (ellipse->cell_index ()) [p_radius_x].to_double (), 0.0); + EXPECT_EQ (ly.get_pcell_parameters (ellipse) [p_radius_x].to_double (), 0.0); lib_basic->refresh (); - EXPECT_EQ (ellipse->bbox ().to_string (), "(-4000,-10000;4000,10000)"); - EXPECT_EQ (ellipse->get_display_name (), "Basic.ELLIPSE(l=1/0,rx=4,ry=10,n=64)"); - EXPECT_EQ (ly.get_pcell_parameters (ellipse->cell_index ()) [p_radius_x].to_double (), 4.0); - EXPECT_EQ (ly.get_pcell_parameters (ellipse->cell_index ()) [p_actual_radius_x].to_double (), 4.0); - EXPECT_EQ (ly.get_pcell_parameters (ellipse->cell_index ()) [p_radius_y].to_double (), 10.0); - EXPECT_EQ (ly.get_pcell_parameters (ellipse->cell_index ()) [p_actual_radius_y].to_double (), 10.0); + EXPECT_EQ (ly.cell (ellipse).bbox ().to_string (), "(-4000,-10000;4000,10000)"); + EXPECT_EQ (ly.cell (ellipse).get_display_name (), "Basic.ELLIPSE(l=1/0,rx=4,ry=10,n=64)"); + EXPECT_EQ (ly.get_pcell_parameters (ellipse) [p_radius_x].to_double (), 4.0); + EXPECT_EQ (ly.get_pcell_parameters (ellipse) [p_actual_radius_x].to_double (), 4.0); + EXPECT_EQ (ly.get_pcell_parameters (ellipse) [p_radius_y].to_double (), 10.0); + EXPECT_EQ (ly.get_pcell_parameters (ellipse) [p_actual_radius_y].to_double (), 10.0); // change radius2 explicitly - plist = ly.get_pcell_parameters (ellipse->cell_index ()); + plist = ly.get_pcell_parameters (ellipse); plist[p_actual_radius_y] = 9.0; - ellipse = &ly.cell (ly.get_pcell_variant_cell (ellipse->cell_index (), plist)); + ellipse = ly.get_pcell_variant_cell (ellipse, plist); // as the radius is an input parameter, only after Library::refresh the other parameters get updated - EXPECT_EQ (ly.get_pcell_parameters (ellipse->cell_index ()) [p_radius_y].to_double (), 10.0); + EXPECT_EQ (ly.get_pcell_parameters (ellipse) [p_radius_y].to_double (), 10.0); lib_basic->refresh (); - EXPECT_EQ (ellipse->bbox ().to_string (), "(-4000,-9000;4000,9000)"); - EXPECT_EQ (ellipse->get_display_name (), "Basic.ELLIPSE(l=1/0,rx=4,ry=9,n=64)"); - EXPECT_EQ (ly.get_pcell_parameters (ellipse->cell_index ()) [p_handle_x].to_string (), "-4,0"); - EXPECT_EQ (ly.get_pcell_parameters (ellipse->cell_index ()) [p_handle_y].to_string (), "0,9"); - EXPECT_EQ (ly.get_pcell_parameters (ellipse->cell_index ()) [p_radius_x].to_double (), 4.0); - EXPECT_EQ (ly.get_pcell_parameters (ellipse->cell_index ()) [p_actual_radius_x].to_double (), 4.0); - EXPECT_EQ (ly.get_pcell_parameters (ellipse->cell_index ()) [p_radius_y].to_double (), 9.0); - EXPECT_EQ (ly.get_pcell_parameters (ellipse->cell_index ()) [p_actual_radius_y].to_double (), 9.0); + EXPECT_EQ (ly.cell (ellipse).bbox ().to_string (), "(-4000,-9000;4000,9000)"); + EXPECT_EQ (ly.cell (ellipse).get_display_name (), "Basic.ELLIPSE(l=1/0,rx=4,ry=9,n=64)"); + EXPECT_EQ (ly.get_pcell_parameters (ellipse) [p_handle_x].to_string (), "-4,0"); + EXPECT_EQ (ly.get_pcell_parameters (ellipse) [p_handle_y].to_string (), "0,9"); + EXPECT_EQ (ly.get_pcell_parameters (ellipse) [p_radius_x].to_double (), 4.0); + EXPECT_EQ (ly.get_pcell_parameters (ellipse) [p_actual_radius_x].to_double (), 4.0); + EXPECT_EQ (ly.get_pcell_parameters (ellipse) [p_radius_y].to_double (), 9.0); + EXPECT_EQ (ly.get_pcell_parameters (ellipse) [p_actual_radius_y].to_double (), 9.0); // change radius1 explicitly - plist = ly.get_pcell_parameters (ellipse->cell_index ()); + plist = ly.get_pcell_parameters (ellipse); plist[p_actual_radius_x] = 5.0; - ellipse = &ly.cell (ly.get_pcell_variant_cell (ellipse->cell_index (), plist)); + ellipse = ly.get_pcell_variant_cell (ellipse, plist); // as the radius is an input parameter, only after Library::refresh the other parameters get updated - EXPECT_EQ (ly.get_pcell_parameters (ellipse->cell_index ()) [p_radius_x].to_double (), 4.0); + EXPECT_EQ (ly.get_pcell_parameters (ellipse) [p_radius_x].to_double (), 4.0); lib_basic->refresh (); - EXPECT_EQ (ellipse->bbox ().to_string (), "(-5000,-9000;5000,9000)"); - EXPECT_EQ (ellipse->get_display_name (), "Basic.ELLIPSE(l=1/0,rx=5,ry=9,n=64)"); - EXPECT_EQ (ly.get_pcell_parameters (ellipse->cell_index ()) [p_handle_x].to_string (), "-5,0"); - EXPECT_EQ (ly.get_pcell_parameters (ellipse->cell_index ()) [p_handle_y].to_string (), "0,9"); - EXPECT_EQ (ly.get_pcell_parameters (ellipse->cell_index ()) [p_radius_x].to_double (), 5.0); - EXPECT_EQ (ly.get_pcell_parameters (ellipse->cell_index ()) [p_actual_radius_x].to_double (), 5.0); - EXPECT_EQ (ly.get_pcell_parameters (ellipse->cell_index ()) [p_radius_y].to_double (), 9.0); - EXPECT_EQ (ly.get_pcell_parameters (ellipse->cell_index ()) [p_actual_radius_y].to_double (), 9.0); + EXPECT_EQ (ly.cell (ellipse).bbox ().to_string (), "(-5000,-9000;5000,9000)"); + EXPECT_EQ (ly.cell (ellipse).get_display_name (), "Basic.ELLIPSE(l=1/0,rx=5,ry=9,n=64)"); + EXPECT_EQ (ly.get_pcell_parameters (ellipse) [p_handle_x].to_string (), "-5,0"); + EXPECT_EQ (ly.get_pcell_parameters (ellipse) [p_handle_y].to_string (), "0,9"); + EXPECT_EQ (ly.get_pcell_parameters (ellipse) [p_radius_x].to_double (), 5.0); + EXPECT_EQ (ly.get_pcell_parameters (ellipse) [p_actual_radius_x].to_double (), 5.0); + EXPECT_EQ (ly.get_pcell_parameters (ellipse) [p_radius_y].to_double (), 9.0); + EXPECT_EQ (ly.get_pcell_parameters (ellipse) [p_actual_radius_y].to_double (), 9.0); // change handle1 explicitly - plist = ly.get_pcell_parameters (ellipse->cell_index ()); + plist = ly.get_pcell_parameters (ellipse); plist[p_handle_x] = db::DPoint (-5.0, 0.0); - ellipse = &ly.cell (ly.get_pcell_variant_cell (ellipse->cell_index (), plist)); + ellipse = ly.get_pcell_variant_cell (ellipse, plist); lib_basic->refresh (); - EXPECT_EQ (ellipse->bbox ().to_string (), "(-5000,-9000;5000,9000)"); - EXPECT_EQ (ellipse->get_display_name (), "Basic.ELLIPSE(l=1/0,rx=5,ry=9,n=64)"); - EXPECT_EQ (ly.get_pcell_parameters (ellipse->cell_index ()) [p_handle_x].to_string (), "-5,0"); - EXPECT_EQ (ly.get_pcell_parameters (ellipse->cell_index ()) [p_handle_y].to_string (), "0,9"); - EXPECT_EQ (ly.get_pcell_parameters (ellipse->cell_index ()) [p_radius_x].to_double (), 5); - EXPECT_EQ (ly.get_pcell_parameters (ellipse->cell_index ()) [p_actual_radius_x].to_double (), 5); - EXPECT_EQ (ly.get_pcell_parameters (ellipse->cell_index ()) [p_radius_y].to_double (), 9); - EXPECT_EQ (ly.get_pcell_parameters (ellipse->cell_index ()) [p_actual_radius_y].to_double (), 9); + EXPECT_EQ (ly.cell (ellipse).bbox ().to_string (), "(-5000,-9000;5000,9000)"); + EXPECT_EQ (ly.cell (ellipse).get_display_name (), "Basic.ELLIPSE(l=1/0,rx=5,ry=9,n=64)"); + EXPECT_EQ (ly.get_pcell_parameters (ellipse) [p_handle_x].to_string (), "-5,0"); + EXPECT_EQ (ly.get_pcell_parameters (ellipse) [p_handle_y].to_string (), "0,9"); + EXPECT_EQ (ly.get_pcell_parameters (ellipse) [p_radius_x].to_double (), 5); + EXPECT_EQ (ly.get_pcell_parameters (ellipse) [p_actual_radius_x].to_double (), 5); + EXPECT_EQ (ly.get_pcell_parameters (ellipse) [p_radius_y].to_double (), 9); + EXPECT_EQ (ly.get_pcell_parameters (ellipse) [p_actual_radius_y].to_double (), 9); // change handle2 explicitly - plist = ly.get_pcell_parameters (ellipse->cell_index ()); + plist = ly.get_pcell_parameters (ellipse); plist[p_handle_y] = db::DPoint (0.0, 9.0); - ellipse = &ly.cell (ly.get_pcell_variant_cell (ellipse->cell_index (), plist)); + ellipse = ly.get_pcell_variant_cell (ellipse, plist); lib_basic->refresh (); - EXPECT_EQ (ellipse->bbox ().to_string (), "(-5000,-9000;5000,9000)"); - EXPECT_EQ (ellipse->get_display_name (), "Basic.ELLIPSE(l=1/0,rx=5,ry=9,n=64)"); - EXPECT_EQ (ly.get_pcell_parameters (ellipse->cell_index ()) [p_handle_x].to_string (), "-5,0"); - EXPECT_EQ (ly.get_pcell_parameters (ellipse->cell_index ()) [p_handle_y].to_string (), "0,9"); - EXPECT_EQ (ly.get_pcell_parameters (ellipse->cell_index ()) [p_radius_x].to_double (), 5); - EXPECT_EQ (ly.get_pcell_parameters (ellipse->cell_index ()) [p_actual_radius_x].to_double (), 5); - EXPECT_EQ (ly.get_pcell_parameters (ellipse->cell_index ()) [p_radius_y].to_double (), 9); - EXPECT_EQ (ly.get_pcell_parameters (ellipse->cell_index ()) [p_actual_radius_y].to_double (), 9); + EXPECT_EQ (ly.cell (ellipse).bbox ().to_string (), "(-5000,-9000;5000,9000)"); + EXPECT_EQ (ly.cell (ellipse).get_display_name (), "Basic.ELLIPSE(l=1/0,rx=5,ry=9,n=64)"); + EXPECT_EQ (ly.get_pcell_parameters (ellipse) [p_handle_x].to_string (), "-5,0"); + EXPECT_EQ (ly.get_pcell_parameters (ellipse) [p_handle_y].to_string (), "0,9"); + EXPECT_EQ (ly.get_pcell_parameters (ellipse) [p_radius_x].to_double (), 5); + EXPECT_EQ (ly.get_pcell_parameters (ellipse) [p_actual_radius_x].to_double (), 5); + EXPECT_EQ (ly.get_pcell_parameters (ellipse) [p_radius_y].to_double (), 9); + EXPECT_EQ (ly.get_pcell_parameters (ellipse) [p_actual_radius_y].to_double (), 9); unsigned int l1 = ly.get_layer (db::LayerProperties (1, 0)); From f33f8ea756aee9ec2827bf971a9717fa45567834 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Fri, 3 Apr 2026 11:30:34 +0200 Subject: [PATCH 14/21] Fixing Layout::cleanup - was missing an update to establish proper cell parent relationships --- src/db/db/dbLayout.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/db/db/dbLayout.cc b/src/db/db/dbLayout.cc index 977aa82f7..fb9cbbc04 100644 --- a/src/db/db/dbLayout.cc +++ b/src/db/db/dbLayout.cc @@ -1742,6 +1742,7 @@ Layout::cleanup (const std::set &keep) // The latter is good for LVS for example. { + update(); db::LayoutLocker locker (this); // join library proxies pointing to the same object From 5762bc3ecc7e8f7b94ba367f8cd01840ff285fc9 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Fri, 3 Apr 2026 11:31:53 +0200 Subject: [PATCH 15/21] Remove debug output --- src/db/db/dbLibraryManager.cc | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/db/db/dbLibraryManager.cc b/src/db/db/dbLibraryManager.cc index 04b9946a4..8181694b4 100644 --- a/src/db/db/dbLibraryManager.cc +++ b/src/db/db/dbLibraryManager.cc @@ -38,7 +38,7 @@ namespace db static LibraryManager *sp_instance (0); -LibraryManager & +DB_PUBLIC LibraryManager & LibraryManager::instance () { if (sp_instance == 0) { @@ -177,9 +177,6 @@ LibraryManager::delete_lib (Library *library) lib_id_type LibraryManager::register_lib (Library *library) { - if (library->get_name () == "PCellTestLib2") { - tl::info << "@@@ BANG!"; - } lib_id_type id = std::numeric_limits::max (); Library *old_lib = 0; From 87415f848cce0d609468ee61915cb0957c95ae0b Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Fri, 3 Apr 2026 11:33:46 +0200 Subject: [PATCH 16/21] WIP --- src/db/db/dbLibrary.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/db/db/dbLibrary.cc b/src/db/db/dbLibrary.cc index e6966a306..3236d91c5 100644 --- a/src/db/db/dbLibrary.cc +++ b/src/db/db/dbLibrary.cc @@ -193,10 +193,12 @@ Library::refresh_without_restore () } - layout ().refresh (); - // re-register, potentially under the new name db::LibraryManager::instance ().register_lib (this); + + // This is basically only needed for coerce_parameters in a persistent way. + // During "register_lib", this is already called in PCell update, but cannot be persisted then. + remap_to (this); } void From 62e45daaea8e5c820553d02fb622b8c6a060ddb8 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Fri, 3 Apr 2026 16:23:01 +0200 Subject: [PATCH 17/21] Updating doc. --- src/doc/doc/about/about_libraries.xml | 190 ++++++++++++++++++++++++++ 1 file changed, 190 insertions(+) diff --git a/src/doc/doc/about/about_libraries.xml b/src/doc/doc/about/about_libraries.xml index 70ee02d31..a3b9fb8c6 100644 --- a/src/doc/doc/about/about_libraries.xml +++ b/src/doc/doc/about/about_libraries.xml @@ -6,6 +6,8 @@ About Libraries + +

Starting with version 0.22, KLayout offers a library concept. @@ -50,6 +52,22 @@ name of the library file minus the extension.

+
  • Layout files by declaration: + Starting with version 0.30.8, KLayout supports declaration of static libraries by + a library definition file. This is an alternative mechanism to the "libraries" folder + and has a number of advantages: +

    +
      +
    • Libraries can be referenced from any place in the file system
    • +
    • Library definition files can include other files and include environment variables
    • +
    • Additional attributes are available for declaration
    • +
    +

    + This feature is limited to static libraries - i.e. libraries declared by library + definition files cannot include PCells. PCells are an exclusive feature of coded + libraries. +

    +
  • Coded libraries: Such libraries are provided by code, either through shared objects/DLL's or through Ruby code. Basically such code has to provide a layout object containing the library cells. @@ -65,5 +83,177 @@ about packages.

    +

    + Static libraries, whether defined by a library declaration file or implicitly from the + "libraries" folder, are automatically reloaded, when the file changes. If this feature + is not desired, you can disable automatic reload in the Setup dialog and manually refresh + the libraries if required. +

    + +

    How libraries work

    + +

    + Unlike other systems, libraries are not external references for KLayout. Instead, a library + is essentially a copy source. When you use a library cell, it is copied into your + working layout and is weakly linked to the original place. You can refresh the library, + which will also refresh the copy. This process is called "replication". +

    + +

    + This approach implies a memory adder, but has a number of benefits: +

    + +
      +
    • The working layout is "whole" - i.e. if a library vanishes or is not available + when transferring the layout to someone else, the layout is still functional. The + copy acts as a snapshot. +
    • +
    • + The independent copy allows for compensating database unit differences and layer details, + so the libraries can be made with a different database unit than the working layout for example. +
    • +
    • + This design greatly simplifies the database organisation, as the internal + structure does not need to care about layer index translations and all information + needed to build lookup trees is available in a single layout object. It is easy + to temporarily detach a layout object from the libraries without destroying the + structure. +
    • +
    + +

    + The design also implies that libraries are read-only. You edit the working + copy only - library cells pulled into the layout are copies that cannot and + should not be edited, as they are restored from their original source + occasionally. Libraries should be thought of as external deliveries similar + to Python modules for example. +

    + +

    + When saving a working layout, the copies are stored in the layout file too. + This feature can be disabled in a per-library basis in the library declaration + files (only available for static libraries). See the description of the + "replicate" attribute below. Note that when you use this feature, you can + only restore the entire layout, if you have these libraries installed. +

    + +

    Library declaration files

    + +

    + By default, library declaration files are called "klayout.lib" and are looked up in + all places of the KLayout search path - this includes the home folder, the technology + folders and the package folders. You can override this mechanism by setting the + "KLAYOUT_LIB" environment variable to a specific file. In that case, only this + file is loaded. +

    + +

    + The format of the library declaration file is "KLayout expressions". This means: function + calls need to be with round brackets and expressions are separated + by ";". For more information about expressions, see . +

    + +

    + Two functions are available: "define" and "include". These are used to build + the declaration files. +

    + +

    "include" function

    + +

    Usage:

    + +
    include(path);
    + +

    Description:

    + +

    + Includes the lib file given by the path. The path is + resolved relative to the current lib file. +

    + +

    "define" function

    + +

    Usage:

    + +
    define(name, path [, options]);
    +define(path [, options]);
    + +

    Description:

    + +

    + Defines a library. In the path-only version, the library name + is taken from the layout file's LIBNAME record (GDS) or the + file name. In the name/path version, "name" is the name the + library is registered under. +

    + +

    + The path is resolved relative to the current lib file. + If you want to include an environment variable, use the "env" expression + function: +

    + +
    define("A", env("HOME") + "/mylibs/a.gds");
    + +

    + Note that the order of library definitions matters. Dependencies + need to be defined already when a library is loaded. For example + if a library "B" uses components from library "A", the order needs + to be: +

    + +
    define("A", "a.gds");
    +define("B", "b.gds");
    + +

    + The following options are available: +

    + +
      + +
    • + +

      technology: binds a library to a technology - i.e. it is only + available in the editor when that technology is selected:

      + +
      define("A", "a.gds", technology="SG13A");
      + +

      + By default, libraries are not bound to a technology, except if + the library file is loaded in the context of a technology (i.e. + sits in a technology folder). You can explicitly enable a library + for all technologies using: +

      + +
      define("A", "a.gds", technology="*");
      + +
    • + +
    • + +

      technologies: binds a library to several technologies. The + argument is a list:

      + +
      define("A", "a.gds", technologies=["SG13A","GF180"]);
      + +
    • + +
    • + +

      replicate: this flag indicates that components of the library + are replicated in the layout files using a library element. + This allows loading that file without actually having the library. + However, it comes with a size overhead, that can be avoided + by skipping this replication: +

      + +
      define("A", "a.gds", replicate=false);
      + +

      By default, replication is enabled.

      + +
    • + +
    + From a39bc587c128d760bca2dad6d94c5268acaa1633 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Fri, 3 Apr 2026 17:49:29 +0200 Subject: [PATCH 18/21] Reusing libraries inside Library#library_from_file and Library#library:from_files for conservative reloading. --- src/db/db/dbFileBasedLibrary.cc | 21 +++++++++++++++++++ src/db/db/dbFileBasedLibrary.h | 10 +++++++++ src/db/db/gsiDeclDbLibrary.cc | 36 +++++++++++++++++++++++++++++---- 3 files changed, 63 insertions(+), 4 deletions(-) diff --git a/src/db/db/dbFileBasedLibrary.cc b/src/db/db/dbFileBasedLibrary.cc index 10025e650..e13fd927f 100644 --- a/src/db/db/dbFileBasedLibrary.cc +++ b/src/db/db/dbFileBasedLibrary.cc @@ -53,6 +53,27 @@ FileBasedLibrary::merge_with_other_layout (const std::string &path) } } +bool +FileBasedLibrary::is_for_path (const std::string &path) +{ + return m_other_paths.empty () && m_path == path; +} + +bool +FileBasedLibrary::is_for_paths (const std::vector &paths) +{ + if (paths.size () != m_other_paths.size () + 1) { + return false; + } + + // this check is purely based on path strings + std::set p1 (paths.begin (), paths.end ()); + std::set p2; + p2.insert (m_path); + p2.insert (m_other_paths.begin (), m_other_paths.end ()); + return p1 == p2; +} + std::string FileBasedLibrary::load () { diff --git a/src/db/db/dbFileBasedLibrary.h b/src/db/db/dbFileBasedLibrary.h index 921ebe383..3a9ddaee9 100644 --- a/src/db/db/dbFileBasedLibrary.h +++ b/src/db/db/dbFileBasedLibrary.h @@ -89,6 +89,16 @@ public: m_other_paths = other_paths; } + /** + * @brief Gets a value indicating whether the library is for the given path + */ + bool is_for_path (const std::string &path); + + /** + * @brief Gets a value indicating whether the library is for the given path + */ + bool is_for_paths (const std::vector &paths); + private: std::string m_name; std::string m_path; diff --git a/src/db/db/gsiDeclDbLibrary.cc b/src/db/db/gsiDeclDbLibrary.cc index a3e412211..69e9280c0 100644 --- a/src/db/db/gsiDeclDbLibrary.cc +++ b/src/db/db/gsiDeclDbLibrary.cc @@ -157,9 +157,21 @@ static LibraryImpl *new_lib () return new LibraryImpl (); } -static db::Library *library_from_file (const std::string &path, const std::string &name) +static db::Library *library_from_file (const std::string &path, const std::string &name, const std::string &for_technology) { + // Check if a library with this specification already is installed and reuse in that case. + if (! name.empty ()) { + + db::FileBasedLibrary *old_lib = dynamic_cast (library_by_name (name, for_technology)); + if (old_lib && old_lib->is_for_path (path)) { + old_lib->load (); + return old_lib; + } + + } + std::unique_ptr lib (new db::FileBasedLibrary (path, name)); + lib->set_technology (for_technology); std::string n = lib->load (); db::Library *ret = lib.get (); @@ -168,17 +180,30 @@ static db::Library *library_from_file (const std::string &path, const std::strin return ret; } -static db::Library *library_from_files (const std::vector &paths, const std::string &name) +static db::Library *library_from_files (const std::vector &paths, const std::string &name, const std::string &for_technology) { if (paths.empty ()) { throw tl::Exception (tl::to_string (tr ("At least one path must be given"))); } + // Check if a library with this specification already is installed and reuse in that case. + if (! name.empty ()) { + + db::FileBasedLibrary *old_lib = dynamic_cast (library_by_name (name, for_technology)); + if (old_lib && old_lib->is_for_paths (paths)) { + old_lib->load (); + return old_lib; + } + + } + std::unique_ptr lib (new db::FileBasedLibrary (paths.front (), name)); for (auto i = paths.begin () + 1; i != paths.end (); ++i) { lib->merge_with_other_layout (*i); } + lib->set_technology (for_technology); + std::string n = lib->load (); db::Library *ret = lib.get (); register_lib (lib.release (), n); @@ -191,7 +216,7 @@ static db::Library *library_from_files (const std::vector &paths, */ LibraryClass decl_Library ("db", "LibraryBase", - gsi::method ("library_from_file", &library_from_file, gsi::arg ("path"), gsi::arg ("name", std::string (), "auto"), + gsi::method ("library_from_file", &library_from_file, gsi::arg ("path"), gsi::arg ("name", std::string (), "auto"), gsi::arg ("for_technology", std::string (), "none"), "@brief Creates a library from a file\n" "@param path The path to the file from which to create the library from.\n" "@param name The name of the library. If empty, the name will be derived from the GDS LIBNAME or the file name.\n" @@ -200,9 +225,12 @@ LibraryClass decl_Library ("db", "LibraryBase", "This method will create a \\Library object which is tied to a specific file. This object supports " "automatic reloading when the \\Library#refresh method is called.\n" "\n" + "If a file-based library with the same name and path is registered already, this method will not reload again " + "and return the library that was already registered.\n" + "\n" "This convenience method has been added in version 0.30.8.\n" ) + - gsi::method ("library_from_files", &library_from_files, gsi::arg ("paths"), gsi::arg ("name", std::string (), "auto"), + gsi::method ("library_from_files", &library_from_files, gsi::arg ("paths"), gsi::arg ("name", std::string (), "auto"), gsi::arg ("for_technology", std::string (), "none"), "@brief Creates a library from a set of files\n" "@param paths The paths to the files from which to create the library from. At least one file needs to be given.\n" "@param name The name of the library. If empty, the name will be derived from the GDS LIBNAME or the file name.\n" From 9b2d1fe0be3c3a3daf486090696bcf8c1a4f29d8 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Fri, 3 Apr 2026 23:05:07 +0200 Subject: [PATCH 19/21] Adding the description option to library declaration files --- src/doc/doc/about/about_libraries.xml | 9 +++++++++ src/lay/lay/layLibraryController.cc | 7 +++++++ src/lay/lay/layLibraryController.h | 4 +++- src/lay/unit_tests/layLibraryControllerTests.cc | 2 ++ testdata/lay/a.libdef | 2 +- 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/doc/doc/about/about_libraries.xml b/src/doc/doc/about/about_libraries.xml index a3b9fb8c6..c41e52844 100644 --- a/src/doc/doc/about/about_libraries.xml +++ b/src/doc/doc/about/about_libraries.xml @@ -253,6 +253,15 @@ define("B", "b.gds");
  • +
  • + +

    description: Specifies a description for that library. +

    + +
    define("A", "a.gds", description="Library A");
    + +
  • + diff --git a/src/lay/lay/layLibraryController.cc b/src/lay/lay/layLibraryController.cc index 4b668fbdc..a95b5da3e 100644 --- a/src/lay/lay/layLibraryController.cc +++ b/src/lay/lay/layLibraryController.cc @@ -320,6 +320,7 @@ public: for (auto k = kwargs->begin (); k != kwargs->end (); ++k) { static const std::string replicate_key ("replicate"); + static const std::string description_key ("description"); static const std::string technology_key ("technology"); static const std::string technologies_key ("technologies"); @@ -327,6 +328,10 @@ public: fi.replicate = k->second.to_bool (); + } else if (k->first == description_key) { + + fi.description = k->second.to_string (); + } else if (k->first == technology_key) { fi.tech.clear (); @@ -465,6 +470,7 @@ LibraryController::read_libs (const std::vector std::unique_ptr lib (new db::FileBasedLibrary (lib_path, im->name)); lib->set_technologies (im->tech); + lib->set_description (im->description); lib->set_replicate (im->replicate); tl::log << "Reading library '" << lib_path << "'"; @@ -493,6 +499,7 @@ LibraryController::read_libs (const std::vector LibInfo li; li.name = libname; li.time = fi.lastModified (); + li.description = im->description; li.tech = im->tech; li.replicate = im->replicate; new_lib_files.insert (std::make_pair (lib_path, li)); diff --git a/src/lay/lay/layLibraryController.h b/src/lay/lay/layLibraryController.h index 54c345a02..0fd26634e 100644 --- a/src/lay/lay/layLibraryController.h +++ b/src/lay/lay/layLibraryController.h @@ -61,6 +61,7 @@ public: { LibFileInfo () : name (), path (), replicate (true) { } std::string name; + std::string description; std::string path; std::set tech; bool replicate; @@ -135,8 +136,9 @@ private slots: private: struct LibInfo { - LibInfo () : name (), time (), tech (), replicate (true) { } + LibInfo () : name (), description (), time (), tech (), replicate (true) { } std::string name; + std::string description; QDateTime time; std::set tech; bool replicate; diff --git a/src/lay/unit_tests/layLibraryControllerTests.cc b/src/lay/unit_tests/layLibraryControllerTests.cc index b5785dcfa..782f19ef7 100644 --- a/src/lay/unit_tests/layLibraryControllerTests.cc +++ b/src/lay/unit_tests/layLibraryControllerTests.cc @@ -37,11 +37,13 @@ TEST (1) EXPECT_EQ (file_info[0].name, ""); EXPECT_EQ (file_info[0].path, tl::combine_path (tl::absolute_path (lib_file), "noname.gds")); EXPECT_EQ (file_info[0].replicate, true); + EXPECT_EQ (file_info[0].description, ""); EXPECT_EQ (tl::join (file_info[0].tech.begin (), file_info[0].tech.end (), ","), "T1"); EXPECT_EQ (file_info[1].name, "L2"); EXPECT_EQ (file_info[1].path, tl::absolute_file_path (lib_file) + ".zzz"); EXPECT_EQ (file_info[1].replicate, true); + EXPECT_EQ (file_info[1].description, "Library L2"); EXPECT_EQ (file_info[1].tech.size (), size_t (0)); EXPECT_EQ (file_info[2].name, "L3"); diff --git a/testdata/lay/a.libdef b/testdata/lay/a.libdef index ff4bc56af..98d5b756e 100644 --- a/testdata/lay/a.libdef +++ b/testdata/lay/a.libdef @@ -1,6 +1,6 @@ # A comment define("noname.gds"); -define("L2", file + ".zzz", technology = ""); +define("L2", file + ".zzz", technology = "", description = "Library L2"); define("L3", "subdir/l3.gds", technologies = [ "T2", "T3" ], replicate = false); From 21ecd802539a006b703fc2178b56fc75b832e737 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Fri, 3 Apr 2026 23:59:43 +0200 Subject: [PATCH 20/21] Allow to configure auto-sync of library folders. Default is off. --- src/lay/lay/MainConfigPage7.ui | 30 ++++++++++++++- src/lay/lay/layConfig.h | 1 + src/lay/lay/layLibraryController.cc | 60 ++++++++++++++++++++++------- src/lay/lay/layLibraryController.h | 13 ++++++- src/lay/lay/layMainConfigPages.cc | 5 +++ src/lay/lay/layMainWindow.cc | 5 +++ 6 files changed, 96 insertions(+), 18 deletions(-) diff --git a/src/lay/lay/MainConfigPage7.ui b/src/lay/lay/MainConfigPage7.ui index 5cc9b7655..dabfd3a4c 100644 --- a/src/lay/lay/MainConfigPage7.ui +++ b/src/lay/lay/MainConfigPage7.ui @@ -6,8 +6,8 @@ 0 0 - 611 - 271 + 619 + 475 @@ -154,6 +154,32 @@ + + + + Synchronize Library Files + + + + + + If this option is enabled, library files will be reloaded automatically. If disabled, you can reload the files using "File/Refresh Libraries" manually. + + + true + + + + + + + Synchronize library files automatically + + + + + + diff --git a/src/lay/lay/layConfig.h b/src/lay/lay/layConfig.h index c1eb182b8..86850a4e2 100644 --- a/src/lay/lay/layConfig.h +++ b/src/lay/lay/layConfig.h @@ -63,6 +63,7 @@ static const std::string cfg_micron_digits ("digits-micron"); static const std::string cfg_dbu_digits ("digits-dbu"); static const std::string cfg_assistant_bookmarks ("assistant-bookmarks"); static const std::string cfg_always_exit_without_saving ("always-exit-without-saving"); +static const std::string cfg_auto_sync_libraries ("auto-sync-libraries"); } diff --git a/src/lay/lay/layLibraryController.cc b/src/lay/lay/layLibraryController.cc index a95b5da3e..8b3ee0114 100644 --- a/src/lay/lay/layLibraryController.cc +++ b/src/lay/lay/layLibraryController.cc @@ -25,7 +25,6 @@ #include "layApplication.h" #include "laySaltController.h" #include "layConfig.h" -#include "layMainWindow.h" #include "layQtTools.h" #include "dbLibraryManager.h" #include "dbLibrary.h" @@ -44,7 +43,8 @@ namespace lay LibraryController::LibraryController () : m_file_watcher (0), - dm_sync_files (this, &LibraryController::sync_files) + dm_sync_files (this, &LibraryController::sync_files_maybe), + m_sync (false), m_sync_once (false) { } @@ -53,7 +53,7 @@ LibraryController::initialize (lay::Dispatcher * /*root*/) { // NOTE: we initialize the libraries in the stage once to have them available for the autorun // macros. We'll do that later again in order to pull in the libraries from the packages. - sync_files (); + sync_files (false); } void @@ -69,7 +69,7 @@ LibraryController::initialized (lay::Dispatcher * /*root*/) connect (m_file_watcher, SIGNAL (fileRemoved (const QString &)), this, SLOT (file_watcher_triggered ())); } - sync_files (); + sync_files (false); } void @@ -88,9 +88,9 @@ LibraryController::uninitialize (lay::Dispatcher * /*root*/) } void -LibraryController::get_options (std::vector < std::pair > & /*options*/) const +LibraryController::get_options (std::vector < std::pair > &options) const { - // .. nothing yet .. + options.push_back (std::pair (cfg_auto_sync_libraries, "false")); } void @@ -100,8 +100,21 @@ LibraryController::get_menu_entries (std::vector & /*menu_entrie } bool -LibraryController::configure (const std::string & /*name*/, const std::string & /*value*/) +LibraryController::configure (const std::string &name, const std::string &value) { + if (name == cfg_auto_sync_libraries) { + + bool sync = false; + tl::from_string (value, sync); + + m_sync = sync; + if (sync) { + dm_sync_files (); + } + + } + + // don't consume return false; } @@ -119,8 +132,24 @@ LibraryController::can_exit (lay::Dispatcher * /*root*/) const } void -LibraryController::sync_files () +LibraryController::sync_files_maybe () { + sync_files (false); +} + +void +LibraryController::sync_files (bool always) +{ + if (tl::verbosity () >= 20) { + if (always) { + tl::info << tl::to_string (tr ("Synchronize library files unconditionally")); + } else { + tl::info << tl::to_string (tr ("Synchronize library files")); + } + } + + m_sync_once = false; + if (m_file_watcher) { m_file_watcher->clear (); m_file_watcher->enable (false); @@ -179,7 +208,7 @@ LibraryController::sync_files () std::vector libs; read_lib_file (lf->first, lf->second, libs); - read_libs (libs, new_lib_files); + read_libs (libs, new_lib_files, always); if (m_file_watcher) { m_file_watcher->add_file (tl::absolute_file_path (lf->first)); @@ -222,7 +251,7 @@ LibraryController::sync_files () } } - read_libs (libs, new_lib_files); + read_libs (libs, new_lib_files, always); } @@ -424,9 +453,9 @@ LibraryController::read_lib_file (const std::string &lib_file, const std::string } void -LibraryController::read_libs (const std::vector &libs, std::map &new_lib_files) +LibraryController::read_libs (const std::vector &libs, std::map &new_lib_files, bool always) { - bool needs_load = false; + bool needs_load = always; for (auto im = libs.begin (); im != libs.end () && ! needs_load; ++im) { @@ -532,14 +561,17 @@ void LibraryController::sync_with_external_sources () { tl::log << tl::to_string (tr ("Package updates - updating libraries")); + m_sync_once = true; dm_sync_files (); } void LibraryController::file_watcher_triggered () { - tl::log << tl::to_string (tr ("Detected file system change in libraries - updating")); - dm_sync_files (); + if (m_sync) { + tl::log << tl::to_string (tr ("Detected file system change in libraries - updating")); + dm_sync_files (); + } } LibraryController * diff --git a/src/lay/lay/layLibraryController.h b/src/lay/lay/layLibraryController.h index 0fd26634e..4b0392c63 100644 --- a/src/lay/lay/layLibraryController.h +++ b/src/lay/lay/layLibraryController.h @@ -112,6 +112,13 @@ public: */ bool can_exit (lay::Dispatcher *root) const; + /** + * @brief Synchronize files + * + * If "always" is set, all files are synchronized unconditionally. + */ + void sync_files (bool always); + /** * @brief Gets the singleton instance for this object */ @@ -147,9 +154,11 @@ private: tl::FileSystemWatcher *m_file_watcher; tl::DeferredMethod dm_sync_files; std::map m_lib_files; + bool m_sync; + bool m_sync_once; - void sync_files (); - void read_libs (const std::vector &file_info, std::map &new_lib_files); + void sync_files_maybe (); + void read_libs (const std::vector &file_info, std::map &new_lib_files, bool always); }; } diff --git a/src/lay/lay/layMainConfigPages.cc b/src/lay/lay/layMainConfigPages.cc index 3b8d9c890..c56f48357 100644 --- a/src/lay/lay/layMainConfigPages.cc +++ b/src/lay/lay/layMainConfigPages.cc @@ -197,6 +197,10 @@ MainConfigPage7::setup (lay::Dispatcher *root) root->config_get (cfg_layout_file_watcher_enabled, en); mp_ui->check_for_updates->setChecked (en); + bool asl = false; + root->config_get (cfg_auto_sync_libraries, asl); + mp_ui->auto_sync_libraries->setChecked (asl); + int kb = 0; root->config_get (cfg_keep_backups, kb); mp_ui->keep_backups->setValue (kb); @@ -211,6 +215,7 @@ MainConfigPage7::commit (lay::Dispatcher *root) { try { root->config_set (cfg_layout_file_watcher_enabled, mp_ui->check_for_updates->isChecked ()); + root->config_set (cfg_auto_sync_libraries, mp_ui->auto_sync_libraries->isChecked ()); root->config_set (cfg_keep_backups, mp_ui->keep_backups->value ()); root->config_set (cfg_always_exit_without_saving, mp_ui->always_exit_without_saving->isChecked ()); } catch (...) { } diff --git a/src/lay/lay/layMainWindow.cc b/src/lay/lay/layMainWindow.cc index 0410cbb4d..4304d056e 100644 --- a/src/lay/lay/layMainWindow.cc +++ b/src/lay/lay/layMainWindow.cc @@ -94,6 +94,7 @@ #include "laySettingsForm.h" #include "laySelectCellViewForm.h" #include "layTechnologyController.h" +#include "layLibraryController.h" #include "laySaltController.h" #include "layTipDialog.h" #include "layMacroController.h" @@ -2612,6 +2613,10 @@ MainWindow::cm_writer_options () void MainWindow::cm_refresh () { + if (lay::LibraryController::instance ()) { + lay::LibraryController::instance ()->sync_files (false); + } + db::LibraryManager::instance ().refresh_all (); } From b866ac63d3642281d5b1266a550190d4284a93a4 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sat, 4 Apr 2026 00:20:37 +0200 Subject: [PATCH 21/21] Do not allow converting children of proxy cells to static Proxies and their tree below should not be manipulated, hence this operation is not allowed. --- src/layui/layui/layLayoutViewFunctions.cc | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/layui/layui/layLayoutViewFunctions.cc b/src/layui/layui/layLayoutViewFunctions.cc index 938bc56b4..f965ed152 100644 --- a/src/layui/layui/layLayoutViewFunctions.cc +++ b/src/layui/layui/layLayoutViewFunctions.cc @@ -601,6 +601,27 @@ LayoutViewFunctions::cm_cell_convert_to_static () db::Layout &layout = view ()->cellview (cv_index)->layout (); + // check that all (unselected) parents are static cells - must not convert children + // of proxy cells. + + std::set to_convert; + for (std::vector::iterator p = paths.begin (); p != paths.end (); ++p) { + if (! p->empty () && layout.is_valid_cell_index (p->back ())) { + to_convert.insert (p->back ()); + } + } + + for (auto c = to_convert.begin (); c != to_convert.end (); ++c) { + std::set callers; + layout.cell (*c).collect_caller_cells (callers); + for (auto cc = callers.begin (); cc != callers.end (); ++cc) { + if (layout.cell (*cc).is_proxy () && to_convert.find (*cc) == to_convert.end ()) { + throw tl::Exception (tl::sprintf (tl::to_string (tr ("Cannot convert cells to static cells if they have library or PCell parents - here: %s as child of %s")), + layout.cell (*c).get_display_name (), layout.cell (*cc).get_display_name ())); + } + } + } + // remember the current path lay::LayoutViewBase::cell_path_type cell_path (view ()->cellview (cv_index).combined_unspecific_path ()); @@ -610,6 +631,8 @@ LayoutViewFunctions::cm_cell_convert_to_static () std::map cell_map; + // perform the conversion + for (std::vector::iterator p = paths.begin (); p != paths.end (); ++p) { if (! p->empty () && layout.is_valid_cell_index (p->back ())) { db::cell_index_type new_cell = layout.convert_cell_to_static (p->back ());