From 4908f51e1cd356c1af9a4189a0f4f200989c6acd Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sat, 21 Mar 2026 23:54:23 +0100 Subject: [PATCH 1/3] 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 2/3] 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 3/3] 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;