From 541f9a377f1b607baf05c772ff0a485cf2f4e528 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sun, 16 Apr 2023 21:31:25 +0200 Subject: [PATCH] Small refactoring, added persisted flag for meta info --- src/db/db/dbLayout.cc | 18 ++++---- src/db/db/dbLayout.h | 20 ++++----- src/db/db/dbMetaInfo.h | 6 ++- src/db/db/gsiDeclDbCell.cc | 24 ++++++++++- src/db/db/gsiDeclDbLayout.cc | 25 ++++++++++- src/db/db/gsiDeclDbMetaInfo.cc | 32 +++++++++++--- src/db/db/gsiDeclDbMetaInfo.h | 13 ++++-- src/lay/lay/layLibraryController.cc | 5 ++- src/laybasic/laybasic/layLayoutViewBase.cc | 43 +++++++++---------- src/layui/layui/layLayoutStatisticsForm.cc | 26 ++++++----- .../gds2/db_plugin/dbGDS2ReaderBase.cc | 10 ++--- .../gds2/db_plugin/dbGDS2WriterBase.cc | 10 ++--- .../gds2/lay_plugin/layGDS2WriterPlugin.cc | 5 ++- .../streamers/gds2/unit_tests/dbGDS2Reader.cc | 4 +- .../streamers/magic/db_plugin/dbMAGReader.cc | 8 ++-- .../streamers/magic/db_plugin/dbMAGWriter.cc | 9 ++-- .../pcb/db_plugin/dbGerberImporter.cc | 2 +- 17 files changed, 169 insertions(+), 91 deletions(-) diff --git a/src/db/db/dbLayout.cc b/src/db/db/dbLayout.cc index 8885fd6de..f92b19a47 100644 --- a/src/db/db/dbLayout.cc +++ b/src/db/db/dbLayout.cc @@ -1753,7 +1753,7 @@ Layout::do_update () delete pr; } -static Layout::meta_info s_empty_meta; +static Layout::meta_info_map s_empty_meta; Layout::meta_info_iterator Layout::begin_meta (db::cell_index_type ci) const @@ -1823,12 +1823,12 @@ Layout::remove_meta_info (meta_info_name_id_type name_id) m_meta_info.erase (name_id); } -const tl::Variant & -Layout::meta_info_value (meta_info_name_id_type name_id) const +const MetaInfo & +Layout::meta_info (meta_info_name_id_type name_id) const { auto n = m_meta_info.find (name_id); - static tl::Variant null_value; - return n != m_meta_info.end () ? n->second.value : null_value; + static MetaInfo null_value; + return n != m_meta_info.end () ? n->second : null_value; } void @@ -1852,18 +1852,18 @@ Layout::remove_meta_info (db::cell_index_type ci, meta_info_name_id_type name_id } } -const tl::Variant & -Layout::meta_info_value (db::cell_index_type ci, meta_info_name_id_type name_id) const +const MetaInfo & +Layout::meta_info (db::cell_index_type ci, meta_info_name_id_type name_id) const { auto c = m_meta_info_by_cell.find (ci); if (c != m_meta_info_by_cell.end ()) { auto i = c->second.find (name_id); if (i != c->second.end ()) { - return i->second.value; + return i->second; } } - static tl::Variant null_value; + static MetaInfo null_value; return null_value; } diff --git a/src/db/db/dbLayout.h b/src/db/db/dbLayout.h index 265561f6b..2038ae52b 100644 --- a/src/db/db/dbLayout.h +++ b/src/db/db/dbLayout.h @@ -466,8 +466,8 @@ public: typedef std::map, cell_index_type> lib_proxy_map; typedef LayerIterator layer_iterator; typedef size_t meta_info_name_id_type; - typedef std::map meta_info; - typedef meta_info::const_iterator meta_info_iterator; + typedef std::map meta_info_map; + typedef meta_info_map::const_iterator meta_info_iterator; /** * @brief A helper functor to compare "const char *" by the content @@ -1876,15 +1876,15 @@ public: * @brief Gets the meta info value for a meta info object with the given name * If no object with that name exists, an empty string is returned */ - const tl::Variant &meta_info_value (const std::string &name) const + const MetaInfo &meta_info (const std::string &name) const { - return meta_info_value (meta_info_name_id (name)); + return meta_info (meta_info_name_id (name)); } /** * @brief Gets the meta info value for a meta info object with the given name ID */ - const tl::Variant &meta_info_value (meta_info_name_id_type name_id) const; + const MetaInfo &meta_info (meta_info_name_id_type name_id) const; /** * @brief Clears the meta information for a specific cell @@ -1927,16 +1927,16 @@ public: * @brief Gets the meta info value for a meta info object with the given name for the given cell * If no object with that name exists, an empty string is returned */ - const tl::Variant &meta_info_value (db::cell_index_type ci, const std::string &name) const + const MetaInfo &meta_info (db::cell_index_type ci, const std::string &name) const { - return meta_info_value (ci, meta_info_name_id (name)); + return meta_info (ci, meta_info_name_id (name)); } /** * @brief Gets the meta info value for a meta info object with the given name ID for the given cell * If no object with that name exists, an empty string is returned */ - const tl::Variant &meta_info_value (db::cell_index_type ci, meta_info_name_id_type name_id) const; + const MetaInfo &meta_info (db::cell_index_type ci, meta_info_name_id_type name_id) const; /** * @brief This event is triggered when the technology changes @@ -1980,8 +1980,8 @@ private: bool m_editable; std::map m_meta_info_name_map; std::vector m_meta_info_names; - meta_info m_meta_info; - std::map m_meta_info_by_cell; + meta_info_map m_meta_info; + std::map m_meta_info_by_cell; std::string m_tech_name; tl::Mutex m_lock; diff --git a/src/db/db/dbMetaInfo.h b/src/db/db/dbMetaInfo.h index 9a3778f6a..16166455d 100644 --- a/src/db/db/dbMetaInfo.h +++ b/src/db/db/dbMetaInfo.h @@ -41,19 +41,21 @@ namespace db */ struct DB_PUBLIC MetaInfo { - MetaInfo (const std::string &d, const tl::Variant &v) - : description (d), value (v) + MetaInfo (const std::string &d, const tl::Variant &v, bool p = false) + : description (d), value (v), persisted (p) { // .. nothing else .. } MetaInfo () + : persisted (false) { // .. nothing else .. } std::string description; tl::Variant value; + bool persisted; }; /** diff --git a/src/db/db/gsiDeclDbCell.cc b/src/db/db/gsiDeclDbCell.cc index fd86ac3a8..4acfc278b 100644 --- a/src/db/db/gsiDeclDbCell.cc +++ b/src/db/db/gsiDeclDbCell.cc @@ -1010,7 +1010,18 @@ static const tl::Variant &cell_meta_info_value (db::Cell *cell, const std::strin static tl::Variant null_value; return null_value; } else { - return cell->layout ()->meta_info_value (cell->cell_index (), name); + return cell->layout ()->meta_info (cell->cell_index (), name).value; + } +} + +static MetaInfo cell_meta_info (db::Cell *cell, const std::string &name) +{ + if (! cell->layout ()) { + static MetaInfo null_value; + return null_value; + } else { + const db::MetaInfo &value = cell->layout ()->meta_info (cell->cell_index (), name); + return MetaInfo (name, value); } } @@ -1841,7 +1852,16 @@ Class decl_Cell ("db", "Cell", "@brief Gets the meta information value for a given name\n" "See \\LayoutMetaInfo for details about cells and meta information.\n" "\n" - "If no meta information with the given name exists, an nil value will be returned.\n" + "If no meta information with the given name exists, a nil value will be returned.\n" + "A more generic version that delivers all fields of the meta information is \\meta_info.\n" + "\n" + "This method has been introduced in version 0.28.7." + ) + + gsi::method_ext ("meta_info", &cell_meta_info, gsi::arg ("name"), + "@brief Gets the meta information for a given name\n" + "See \\LayoutMetaInfo for details about cells and meta information.\n" + "\n" + "If no meta information with the given name exists, a default object with empty fields will be returned.\n" "\n" "This method has been introduced in version 0.28.7." ) + diff --git a/src/db/db/gsiDeclDbLayout.cc b/src/db/db/gsiDeclDbLayout.cc index de20c8e6f..d82c7c464 100644 --- a/src/db/db/gsiDeclDbLayout.cc +++ b/src/db/db/gsiDeclDbLayout.cc @@ -908,6 +908,18 @@ static void layout_add_meta_info (db::Layout *layout, const MetaInfo &mi) layout->add_meta_info (mi.name, db::MetaInfo (mi.description, mi.value)); } +static MetaInfo layout_get_meta_info (db::Layout *layout, const std::string &name) +{ + const db::MetaInfo &value = layout->meta_info (name); + return MetaInfo (name, value); +} + +static const tl::Variant &layout_get_meta_info_value (db::Layout *layout, const std::string &name) +{ + const db::MetaInfo &value = layout->meta_info (name); + return value.value; +} + static MetaInfoIterator layout_each_meta_info (const db::Layout *layout) { return MetaInfoIterator (layout, layout->begin_meta (), layout->end_meta ()); @@ -1052,14 +1064,23 @@ Class decl_Layout ("db", "Layout", "\n" "This method has been introduced in version 0.25." ) + - gsi::method ("meta_info_value", static_cast (&db::Layout::meta_info_value), gsi::arg ("name"), + gsi::method_ext ("meta_info_value", &layout_get_meta_info_value, gsi::arg ("name"), "@brief Gets the meta information value for a given name\n" "See \\LayoutMetaInfo for details about layouts and meta information.\n" "\n" - "If no meta information with the given name exists, an nil value will be returned.\n" + "If no meta information with the given name exists, a nil value will be returned.\n" + "A more generic version that delivers all fields of the meta information is \\meta_info.\n" "\n" "This method has been introduced in version 0.25. Starting with version 0.28.7, the value is of variant type instead of string only.\n" ) + + gsi::method_ext ("meta_info", &layout_get_meta_info, gsi::arg ("name"), + "@brief Gets the meta information for a given name\n" + "See \\LayoutMetaInfo for details about layouts and meta information.\n" + "\n" + "If no meta information with the given name exists, a default object with empty fields will be returned.\n" + "\n" + "This method has been introduced in version 0.28.7.\n" + ) + gsi::iterator_ext ("each_meta_info", &layout_each_meta_info, "@brief Iterates over the meta information of the layout\n" "See \\LayoutMetaInfo for details about layouts and meta information.\n" diff --git a/src/db/db/gsiDeclDbMetaInfo.cc b/src/db/db/gsiDeclDbMetaInfo.cc index 656a6d611..1e182805e 100644 --- a/src/db/db/gsiDeclDbMetaInfo.cc +++ b/src/db/db/gsiDeclDbMetaInfo.cc @@ -27,9 +27,9 @@ namespace gsi { -static MetaInfo *layout_meta_info_ctor (const std::string &name, const std::string &value, const std::string &description) +static MetaInfo *layout_meta_info_ctor (const std::string &name, const std::string &value, const std::string &description, bool persisted) { - return new MetaInfo (name, description, value); + return new MetaInfo (name, description, value, persisted); } static void layout_meta_set_name (MetaInfo *mi, const std::string &n) @@ -62,13 +62,26 @@ static const std::string &layout_meta_get_description (const MetaInfo *mi) return mi->description; } +static void layout_meta_set_persisted (MetaInfo *mi, bool f) +{ + mi->persisted = f; +} + +static bool layout_meta_get_persisted (const MetaInfo *mi) +{ + return mi->persisted; +} + Class decl_LayoutMetaInfo ("db", "LayoutMetaInfo", - gsi::constructor ("new", &layout_meta_info_ctor, gsi::arg ("name"), gsi::arg ("value"), gsi::arg ("description", std::string ()), + gsi::constructor ("new", &layout_meta_info_ctor, gsi::arg ("name"), gsi::arg ("value"), gsi::arg ("description", std::string ()), gsi::arg ("persisted", false), "@brief Creates a layout meta info object\n" "@param name The name\n" "@param value The value\n" "@param description An optional description text\n" + "@param persisted If true, the meta information will be persisted in some file formats, like GDS2\n" + "\n" + "The 'persisted' attribute has been introduced in version 0.28.7.\n" ) + gsi::method_ext ("name", &layout_meta_get_name, "@brief Gets the name of the layout meta info object\n" @@ -87,6 +100,14 @@ Class decl_LayoutMetaInfo ("db", "LayoutMetaInfo", ) + gsi::method_ext ("description=", &layout_meta_set_description, "@brief Sets the description of the layout meta info object\n" + ) + + gsi::method_ext ("persisted", &layout_meta_get_persisted, + "@brief Gets a value indicating whether the meta information will be persisted\n" + "This predicate was introduced in version 0.28.7.\n" + ) + + gsi::method_ext ("persisted=", &layout_meta_set_persisted, + "@brief Sets a value indicating whether the meta information will be persisted\n" + "This predicate was introduced in version 0.28.7.\n" ), "@brief A piece of layout meta information\n" "Layout meta information is basically additional data that can be attached to a layout. " @@ -97,9 +118,10 @@ Class decl_LayoutMetaInfo ("db", "LayoutMetaInfo", "Meta information is identified by a unique name and carries a string value plus an optional description string. " "The description string is for information only and is not evaluated by code.\n" "\n" - "See also \\Layout#each_meta_info and \\Layout#meta_info_value and \\Layout#remove_meta_info" + "See also \\Layout#each_meta_info, \\Layout#meta_info_value, \\Layout#meta_info and \\Layout#remove_meta_info as " + "well as the corresponding \\Cell methods.\n" "\n" - "This class has been introduced in version 0.25." + "This class has been introduced in version 0.25 and was extended in version 0.28.7." ); } diff --git a/src/db/db/gsiDeclDbMetaInfo.h b/src/db/db/gsiDeclDbMetaInfo.h index aea636b05..84bbadc0a 100644 --- a/src/db/db/gsiDeclDbMetaInfo.h +++ b/src/db/db/gsiDeclDbMetaInfo.h @@ -35,17 +35,22 @@ namespace gsi struct MetaInfo { - MetaInfo (const std::string &n, const std::string &d, const tl::Variant &v) - : name (n), description (d), value (v) + MetaInfo (const std::string &n, const std::string &d, const tl::Variant &v, bool p) + : name (n), description (d), value (v), persisted (p) + { } + + MetaInfo (const std::string &n, const db::MetaInfo &mi) + : name (n), description (mi.description), value (mi.value), persisted (mi.persisted) { } MetaInfo () - : name (), description (), value () + : name (), description (), value (), persisted (false) { } std::string name; std::string description; tl::Variant value; + bool persisted; }; struct MetaInfoIterator @@ -79,7 +84,7 @@ struct MetaInfoIterator MetaInfo operator* () const { if (mp_layout) { - return MetaInfo (mp_layout->meta_info_name (m_b->first), m_b->second.description, m_b->second.value); + return MetaInfo (mp_layout->meta_info_name (m_b->first), m_b->second); } else { return MetaInfo (); } diff --git a/src/lay/lay/layLibraryController.cc b/src/lay/lay/layLibraryController.cc index 0a42bcb37..a07b857a1 100644 --- a/src/lay/lay/layLibraryController.cc +++ b/src/lay/lay/layLibraryController.cc @@ -200,9 +200,10 @@ LibraryController::sync_files () reader.read (lib->layout ()); // Use the libname if there is one + db::Layout::meta_info_name_id_type libname_name_id = lib->layout ().meta_info_name_id ("libname"); for (db::Layout::meta_info_iterator m = lib->layout ().begin_meta (); m != lib->layout ().end_meta (); ++m) { - if (m->name == "libname" && ! m->value.empty ()) { - lib->set_name (m->value); + if (m->first == libname_name_id && ! m->second.value.is_nil ()) { + lib->set_name (m->second.value.to_string ()); break; } } diff --git a/src/laybasic/laybasic/layLayoutViewBase.cc b/src/laybasic/laybasic/layLayoutViewBase.cc index c697441fc..b59495ef3 100644 --- a/src/laybasic/laybasic/layLayoutViewBase.cc +++ b/src/laybasic/laybasic/layLayoutViewBase.cc @@ -3202,6 +3202,25 @@ LayoutViewBase::reload_layout (unsigned int cv_index) goto_view (state); } +static void +get_lyp_from_meta_info (const db::Layout &layout, std::string &lyp_file, bool &add_other_layers) +{ + db::Layout::meta_info_name_id_type layer_properties_file_name_id = layout.meta_info_name_id ("layer-properties-file"); + db::Layout::meta_info_name_id_type layer_properties_add_other_layers_name_id = layout.meta_info_name_id ("layer-properties-add-other-layers"); + + for (db::Layout::meta_info_iterator meta = layout.begin_meta (); meta != layout.end_meta (); ++meta) { + if (meta->first == layer_properties_file_name_id) { + lyp_file = meta->second.value.to_string (); + } + if (meta->first == layer_properties_add_other_layers_name_id) { + try { + add_other_layers = meta->second.value.to_bool (); + } catch (...) { + } + } + } +} + unsigned int LayoutViewBase::add_layout (lay::LayoutHandle *layout_handle, bool add_cellview, bool initialize_layers) { @@ -3266,17 +3285,7 @@ LayoutViewBase::add_layout (lay::LayoutHandle *layout_handle, bool add_cellview, } // Give the layout object a chance to specify a certain layer property file - for (db::Layout::meta_info_iterator meta = cv->layout ().begin_meta (); meta != cv->layout ().end_meta (); ++meta) { - if (meta->name == "layer-properties-file") { - lyp_file = meta->value; - } - if (meta->name == "layer-properties-add-other-layers") { - try { - tl::from_string (meta->value, add_other_layers); - } catch (...) { - } - } - } + get_lyp_from_meta_info (cv->layout (), lyp_file, add_other_layers); // interpolate the layout properties file name tl::Eval expr; @@ -3438,17 +3447,7 @@ LayoutViewBase::load_layout (const std::string &filename, const db::LoadLayoutOp } // Give the layout object a chance to specify a certain layer property file - for (db::Layout::meta_info_iterator meta = cv->layout().begin_meta (); meta != cv->layout().end_meta (); ++meta) { - if (meta->name == "layer-properties-file") { - lyp_file = meta->value; - } - if (meta->name == "layer-properties-add-other-layers") { - try { - tl::from_string (meta->value, add_other_layers); - } catch (...) { - } - } - } + get_lyp_from_meta_info (cv->layout (), lyp_file, add_other_layers); // interpolate the layout properties file name tl::Eval expr; diff --git a/src/layui/layui/layLayoutStatisticsForm.cc b/src/layui/layui/layLayoutStatisticsForm.cc index b5d8af8cb..59b3200b7 100644 --- a/src/layui/layui/layLayoutStatisticsForm.cc +++ b/src/layui/layui/layLayoutStatisticsForm.cc @@ -612,7 +612,7 @@ StatisticsSource::get (const std::string &url) } os << "" << std::endl - << "" << layout.get_properties (*l).to_string () << "" << std::endl + << "" << tl::escaped_to_html (layout.get_properties (*l).to_string (), true) << "" << std::endl // Boxes (total, single, array) << "" << st_hier.box_total () << "

" << st_flat.box_total () << "" << std::endl << "" << st_hier.box_single () << "

" << st_flat.box_single () << "" << std::endl @@ -678,19 +678,19 @@ StatisticsSource::get (const std::string &url) os << "" << std::endl << "" << std::endl - << "

" << tl::to_string (QObject::tr ("Common Statistics For '")) << m_h->name () << "'

" << std::endl + << "

" << tl::to_string (QObject::tr ("Common Statistics For '")) << tl::escaped_to_html (m_h->name (), true) << "'

" << std::endl << "

" << std::endl << "" << std::endl << "" - << "" + << "" << "" << std::endl; if (! m_h->save_options ().format ().empty ()) { os << "" - << "" + << "" << "" << std::endl; } os << "" - << "" + << "" << "" << std::endl << "" << "" @@ -702,13 +702,17 @@ StatisticsSource::get (const std::string &url) << "" << "" << std::endl; for (db::Layout::meta_info_iterator meta = layout.begin_meta (); meta != layout.end_meta (); ++meta) { - os << "" << std::endl; + std::string d = meta->second.description; + if (!d.empty ()) { + d = layout.meta_info_name (meta->first); + } + os << "" << std::endl; } os << "
" << tl::to_string (QObject::tr ("Path")) << ": " << m_h->filename () << "" << tl::to_string (QObject::tr ("Path")) << ": " << tl::escaped_to_html (m_h->filename (), true) << "
" << tl::to_string (QObject::tr ("Format")) << ": " << m_h->save_options ().format () << "" << tl::to_string (QObject::tr ("Format")) << ": " << tl::escaped_to_html (m_h->save_options ().format (), true) << "
" << tl::to_string (QObject::tr ("Technology")) << ": " << m_h->technology ()->description () << format_tech_name (m_h->tech_name ()) << "" << tl::to_string (QObject::tr ("Technology")) << ": " << tl::escaped_to_html (m_h->technology ()->description (), true) << tl::escaped_to_html (format_tech_name (m_h->tech_name ()), true) << "
" << tl::to_string (QObject::tr ("Database unit")) << ": " << tl::sprintf ("%.12g ", layout.dbu ()) << tl::to_string (QObject::tr ("micron")) << "" << tl::to_string (QObject::tr ("Number of layers")) << ": " << num_layers << "
" << meta->description << "" << meta->value << "
" << tl::escaped_to_html (d, true) << "" << tl::escaped_to_html (meta->second.value.to_string (), true) << "
" << std::endl << "

" << tl::to_string (QObject::tr ("Top Cells")) << "

" << std::endl << "" << std::endl; for (db::Layout::top_down_const_iterator tc = layout.begin_top_down (); tc != layout.end_top_cells (); ++tc) { - os << "" << std::endl; + os << "" << std::endl; } os << "
" << layout.cell_name (*tc) << "
" << tl::escaped_to_html (layout.cell_name (*tc), true) << "
" << std::endl; os << "

" << std::endl; @@ -733,7 +737,7 @@ StatisticsSource::get (const std::string &url) if (! layers_sorted_by_ld.empty ()) { os << "

" << tl::to_string (QObject::tr ("Layers (sorted by layer and datatype)")) << "

" << std::endl - << "

Detailed layer statistics

" << std::endl + << "

Detailed layer statistics

" << std::endl << "

" << std::endl << "" << std::endl << ""; @@ -748,7 +752,7 @@ StatisticsSource::get (const std::string &url) os << "" << ""; if (! layers_with_oasis_names.empty ()) { - os << ""; + os << ""; } os << "" << std::endl; } @@ -762,7 +766,7 @@ StatisticsSource::get (const std::string &url) if (! layers_with_oasis_names.empty ()) { os << "

" << tl::to_string (QObject::tr ("Layers (sorted by layer names)")) << "

" << std::endl - << "

Detailed layer statistics

" << std::endl + << "

Detailed layer statistics

" << std::endl << "

" << std::endl << "

" << tl::to_string (QObject::tr ("Layer/Datatype")) << "  
" << tl::sprintf ("%d/%d", lp.layer, lp.datatype) << "" << lp.name << "" << tl::escaped_to_html (lp.name, true) << "
" << std::endl << "" << std::endl; @@ -772,7 +776,7 @@ StatisticsSource::get (const std::string &url) const db::LayerProperties &lp = layout.get_properties (*i); if (! lp.name.empty ()) { os << "" - << "" + << "" << "" << "" << std::endl; } diff --git a/src/plugins/streamers/gds2/db_plugin/dbGDS2ReaderBase.cc b/src/plugins/streamers/gds2/db_plugin/dbGDS2ReaderBase.cc index afc4e95fe..91c940d1c 100644 --- a/src/plugins/streamers/gds2/db_plugin/dbGDS2ReaderBase.cc +++ b/src/plugins/streamers/gds2/db_plugin/dbGDS2ReaderBase.cc @@ -185,8 +185,8 @@ GDS2ReaderBase::do_read (db::Layout &layout) unsigned int mod_time[6] = { 0, 0, 0, 0, 0, 0 }; unsigned int access_time[6] = { 0, 0, 0, 0, 0, 0 }; get_time (mod_time, access_time); - layout.add_meta_info (MetaInfo ("mod_time", tl::to_string (tr ("Modification Time")), tl::sprintf ("%d/%d/%d %d:%02d:%02d", mod_time[1], mod_time[2], mod_time[0], mod_time[3], mod_time[4], mod_time[5]))); - layout.add_meta_info (MetaInfo ("access_time", tl::to_string (tr ("Access Time")), tl::sprintf ("%d/%d/%d %d:%02d:%02d", access_time[1], access_time[2], access_time[0], access_time[3], access_time[4], access_time[5]))); + layout.add_meta_info ("mod_time", MetaInfo (tl::to_string (tr ("Modification Time")), tl::sprintf ("%d/%d/%d %d:%02d:%02d", mod_time[1], mod_time[2], mod_time[0], mod_time[3], mod_time[4], mod_time[5]))); + layout.add_meta_info ("access_time", MetaInfo (tl::to_string (tr ("Access Time")), tl::sprintf ("%d/%d/%d %d:%02d:%02d", access_time[1], access_time[2], access_time[0], access_time[3], access_time[4], access_time[5]))); long attr = 0; db::PropertiesRepository::properties_set layout_properties; @@ -234,9 +234,9 @@ GDS2ReaderBase::do_read (db::Layout &layout) double dbuu = get_double (); double dbum = get_double (); - layout.add_meta_info (MetaInfo ("dbuu", tl::to_string (tr ("Database unit in user units")), tl::to_string (dbuu))); - layout.add_meta_info (MetaInfo ("dbum", tl::to_string (tr ("Database unit in meter")), tl::to_string (dbum))); - layout.add_meta_info (MetaInfo ("libname", tl::to_string (tr ("Library name")), m_libname)); + layout.add_meta_info ("dbuu", MetaInfo (tl::to_string (tr ("Database unit in user units")), tl::to_string (dbuu))); + layout.add_meta_info ("dbum", MetaInfo (tl::to_string (tr ("Database unit in meter")), tl::to_string (dbum))); + layout.add_meta_info ("libname", MetaInfo (tl::to_string (tr ("Library name")), m_libname)); m_dbuu = dbuu; m_dbu = dbum * 1e6; /*in micron*/ diff --git a/src/plugins/streamers/gds2/db_plugin/dbGDS2WriterBase.cc b/src/plugins/streamers/gds2/db_plugin/dbGDS2WriterBase.cc index 8fdf46fde..f6bb95413 100644 --- a/src/plugins/streamers/gds2/db_plugin/dbGDS2WriterBase.cc +++ b/src/plugins/streamers/gds2/db_plugin/dbGDS2WriterBase.cc @@ -86,9 +86,9 @@ GDS2WriterBase::write (db::Layout &layout, tl::OutputStream &stream, const db::S db::GDS2WriterOptions gds2_options = options.get_options (); - layout.add_meta_info (MetaInfo ("dbuu", tl::to_string (tr ("Database unit in user units")), tl::to_string (dbu / std::max (1e-9, gds2_options.user_units)))); - layout.add_meta_info (MetaInfo ("dbum", tl::to_string (tr ("Database unit in meter")), tl::to_string (dbu * 1e-6))); - layout.add_meta_info (MetaInfo ("libname", tl::to_string (tr ("Library name")), gds2_options.libname)); + layout.add_meta_info ("dbuu", MetaInfo (tl::to_string (tr ("Database unit in user units")), tl::to_string (dbu / std::max (1e-9, gds2_options.user_units)))); + layout.add_meta_info ("dbum", MetaInfo (tl::to_string (tr ("Database unit in meter")), tl::to_string (dbu * 1e-6))); + layout.add_meta_info ("libname", MetaInfo (tl::to_string (tr ("Library name")), gds2_options.libname)); std::vector > layers; options.get_valid_layers (layout, layers, db::SaveLayoutOptions::LP_AssignNumber); @@ -123,8 +123,8 @@ GDS2WriterBase::write (db::Layout &layout, tl::OutputStream &stream, const db::S } std::string str_time = tl::sprintf ("%d/%d/%d %d:%02d:%02d", time_data[1], time_data[2], time_data[0], time_data[3], time_data[4], time_data[5]); - layout.add_meta_info (MetaInfo ("mod_time", tl::to_string (tr ("Modification Time")), str_time)); - layout.add_meta_info (MetaInfo ("access_time", tl::to_string (tr ("Access Time")), str_time)); + layout.add_meta_info ("mod_time", MetaInfo (tl::to_string (tr ("Modification Time")), str_time)); + layout.add_meta_info ("access_time", MetaInfo (tl::to_string (tr ("Access Time")), str_time)); bool multi_xy = gds2_options.multi_xy_records; size_t max_cellname_length = std::max (gds2_options.max_cellname_length, (unsigned int)8); diff --git a/src/plugins/streamers/gds2/lay_plugin/layGDS2WriterPlugin.cc b/src/plugins/streamers/gds2/lay_plugin/layGDS2WriterPlugin.cc index 443f63027..59a259d6b 100644 --- a/src/plugins/streamers/gds2/lay_plugin/layGDS2WriterPlugin.cc +++ b/src/plugins/streamers/gds2/lay_plugin/layGDS2WriterPlugin.cc @@ -145,9 +145,10 @@ public: // Initialize the libname property from meta data with key "libname". db::GDS2WriterOptions *options = dynamic_cast (o); if (options) { + db::Layout::meta_info_name_id_type libname_name_id = lh.layout().meta_info_name_id ("libname"); for (db::Layout::meta_info_iterator meta = lh.layout().begin_meta (); meta != lh.layout().end_meta (); ++meta) { - if (meta->name == "libname" && !meta->value.empty ()) { - options->libname = meta->value; + if (meta->first == libname_name_id && !meta->second.value.is_nil ()) { + options->libname = meta->second.value.to_string (); } } } diff --git a/src/plugins/streamers/gds2/unit_tests/dbGDS2Reader.cc b/src/plugins/streamers/gds2/unit_tests/dbGDS2Reader.cc index 18f3c860e..33b2e3e2b 100644 --- a/src/plugins/streamers/gds2/unit_tests/dbGDS2Reader.cc +++ b/src/plugins/streamers/gds2/unit_tests/dbGDS2Reader.cc @@ -229,7 +229,7 @@ TEST(1) db::LayerMap map = reader.read (layout); EXPECT_EQ (fabs (layout.dbu () / 0.001 - 1.0) < 1e-6, true); - EXPECT_EQ (layout.meta_info_value ("libname"), "LIB.DB"); + EXPECT_EQ (layout.meta_info ("libname").value.to_string (), "LIB.DB"); EXPECT_EQ (layout.layers (), size_t (11)); EXPECT_EQ (map.mapping_str (0), "2/0 : 2/0"); @@ -289,7 +289,7 @@ TEST(2) db::Reader reader (file); map = reader.read (layout_none, options); EXPECT_EQ (fabs (layout_none.dbu () / 0.001 - 1.0) < 1e-6, true); - EXPECT_EQ (layout.meta_info_value ("libname"), "LIB.DB"); + EXPECT_EQ (layout.meta_info ("libname").value.to_string (), "LIB.DB"); } EXPECT_EQ (layout_none.layers (), size_t (0)); diff --git a/src/plugins/streamers/magic/db_plugin/dbMAGReader.cc b/src/plugins/streamers/magic/db_plugin/dbMAGReader.cc index d76dd434f..3346c6c6f 100644 --- a/src/plugins/streamers/magic/db_plugin/dbMAGReader.cc +++ b/src/plugins/streamers/magic/db_plugin/dbMAGReader.cc @@ -316,7 +316,7 @@ MAGReader::do_read_part (db::Layout &layout, db::cell_index_type cell_index, tl: error (tl::to_string (tr ("Could not find 'magic' header line - is this a MAGIC file?"))); } - layout.add_meta_info (db::MetaInfo ("lambda", "lambda value (tech scaling)", tl::to_string (m_lambda))); + layout.add_meta_info ("lambda", db::MetaInfo ("lambda value (tech scaling)", tl::to_string (m_lambda))); bool valid_layer = false; unsigned int current_layer = 0; @@ -339,11 +339,11 @@ MAGReader::do_read_part (db::Layout &layout, db::cell_index_type cell_index, tl: if (&m_stream == &stream) { // initial file - store technology - layout.add_meta_info (db::MetaInfo ("magic_technology", tl::to_string (tr ("MAGIC technology string")), m_tech)); + layout.add_meta_info ("magic_technology", db::MetaInfo (tl::to_string (tr ("MAGIC technology string")), m_tech)); // propose this is the KLayout technology unless a good one is given if (! mp_klayout_tech) { - layout.add_meta_info (db::MetaInfo ("technology", tl::to_string (tr ("Technology name")), m_tech)); + layout.add_meta_info ("technology", db::MetaInfo (tl::to_string (tr ("Technology name")), m_tech)); } } @@ -357,7 +357,7 @@ MAGReader::do_read_part (db::Layout &layout, db::cell_index_type cell_index, tl: if (&m_stream == &stream) { // initial file - store timestamp - layout.add_meta_info (db::MetaInfo ("magic_timestamp", "MAGIC main file timestamp", tl::to_string (ts))); + layout.add_meta_info ("magic_timestamp", db::MetaInfo ("MAGIC main file timestamp", tl::to_string (ts))); } ex.expect_end (); diff --git a/src/plugins/streamers/magic/db_plugin/dbMAGWriter.cc b/src/plugins/streamers/magic/db_plugin/dbMAGWriter.cc index 8b899164d..a104e5fef 100644 --- a/src/plugins/streamers/magic/db_plugin/dbMAGWriter.cc +++ b/src/plugins/streamers/magic/db_plugin/dbMAGWriter.cc @@ -82,11 +82,14 @@ MAGWriter::write (db::Layout &layout, tl::OutputStream &stream, const db::SaveLa double lambda = m_options.lambda; if (lambda <= 0.0) { - const std::string &lv = layout.meta_info_value ("lambda"); - if (lv.empty ()) { + const tl::Variant &lv = layout.meta_info ("lambda").value; + if (lv.is_nil ()) { throw tl::Exception (tl::to_string (tr ("No lambda value configured for MAG writer and no 'lambda' metadata present in layout."))); + } else if (lv.is_a_string ()) { + tl::from_string (lv.to_string (), lambda); + } else if (lv.can_convert_to_double ()) { + lambda = lv.to_double (); } - tl::from_string (lv, lambda); } m_sf = layout.dbu () / lambda; diff --git a/src/plugins/streamers/pcb/db_plugin/dbGerberImporter.cc b/src/plugins/streamers/pcb/db_plugin/dbGerberImporter.cc index d85ca8173..8b8982d24 100644 --- a/src/plugins/streamers/pcb/db_plugin/dbGerberImporter.cc +++ b/src/plugins/streamers/pcb/db_plugin/dbGerberImporter.cc @@ -1146,7 +1146,7 @@ public: std::string lyr_file = data.get_layer_properties_file (); if (! lyr_file.empty ()) { - layout.add_meta_info (db::MetaInfo ("layer-properties-file", "Layer Properties File", lyr_file)); + layout.add_meta_info ("layer-properties-file", db::MetaInfo ("Layer Properties File", lyr_file)); } return m_layers;
" << tl::to_string (QObject::tr ("Layer name")) << "  " << tl::to_string (QObject::tr ("Layer/Datatype")) << "
" << lp.name << "" << tl::escaped_to_html (lp.name, true) << "" << tl::sprintf ("%d/%d", lp.layer, lp.datatype) << "