From b84ec19da183f6a7e4a5448a2ea78968f8e233eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20K=C3=B6fferlein?= Date: Mon, 23 May 2022 20:37:26 +0200 Subject: [PATCH] Issue 1071 (GDS2Text format options issues) (#1085) * Fixed first issue (UI problem with GDS2Text options) * Fixed problem with 'save' when the file extension does not indicate one of the known formats In this case, and when plain 'save' is used, the original format is delivered. The session files also store the original format now. The statistics page will now indicate the format of the file that was loaded. --- src/db/db/dbStream.cc | 1 + src/lay/lay/layMainWindow.cc | 10 ++-- src/laybasic/laybasic/layCellView.cc | 8 +++- .../laybasic/layLayoutStatisticsForm.cc | 9 +++- .../laybasic/laySaveLayoutOptionsDialog.cc | 47 +++++++++++++++---- src/laybasic/laybasic/layStream.h | 8 ++++ .../gds2/lay_plugin/layGDS2WriterPlugin.cc | 40 +++++++++++++--- 7 files changed, 103 insertions(+), 20 deletions(-) diff --git a/src/db/db/dbStream.cc b/src/db/db/dbStream.cc index 347e95f63..4b0a0adef 100644 --- a/src/db/db/dbStream.cc +++ b/src/db/db/dbStream.cc @@ -51,6 +51,7 @@ tl::XMLElementList load_options_xml_element_list () tl::XMLElementList save_options_xml_element_list () { tl::XMLElementList elements; + elements.append (tl::make_member (&db::SaveLayoutOptions::format, &db::SaveLayoutOptions::set_format, "format")); for (tl::Registrar::iterator cls = tl::Registrar::begin (); cls != tl::Registrar::end (); ++cls) { const StreamFormatDeclaration *decl = dynamic_cast (&*cls); diff --git a/src/lay/lay/layMainWindow.cc b/src/lay/lay/layMainWindow.cc index f6dc15a82..77455f3b2 100644 --- a/src/lay/lay/layMainWindow.cc +++ b/src/lay/lay/layMainWindow.cc @@ -2298,12 +2298,14 @@ MainWindow::do_save (bool as) db::SaveLayoutOptions options = cv->save_options (); if (!cv->save_options_valid () && cv->technology ()) { options = cv->technology ()->save_layout_options (); + options.set_format (cv->save_options ().format ()); } options.set_dbu (cv->layout ().dbu ()); - options.set_format_from_filename (fn); - cv->update_save_options (options); + if (as || options.format ().empty ()) { + options.set_format_from_filename (fn); + } tl::OutputStream::OutputStreamMode om = tl::OutputStream::OM_Auto; @@ -2340,7 +2342,9 @@ MainWindow::cm_save_all () db::SaveLayoutOptions options (cv->save_options ()); options.set_dbu (cv->layout ().dbu ()); - options.set_format_from_filename (fn); + if (options.format ().empty ()) { + options.set_format_from_filename (fn); + } tl::OutputStream::OutputStreamMode om = tl::OutputStream::OM_Auto; diff --git a/src/laybasic/laybasic/layCellView.cc b/src/laybasic/laybasic/layCellView.cc index 476b6867e..08f187383 100644 --- a/src/laybasic/laybasic/layCellView.cc +++ b/src/laybasic/laybasic/layCellView.cc @@ -277,7 +277,7 @@ LayoutHandle::update_save_options (db::SaveLayoutOptions &options) for (tl::Registrar::iterator cls = tl::Registrar::begin (); cls != tl::Registrar::end (); ++cls) { const lay::StreamWriterPluginDeclaration *decl = dynamic_cast (&*cls); - if (! decl) { + if (! decl || decl->options_alias ()) { continue; } @@ -350,6 +350,8 @@ db::LayerMap LayoutHandle::load (const db::LoadLayoutOptions &options, const std::string &technology) { m_load_options = options; + m_save_options = db::SaveLayoutOptions (); + m_save_options_valid = false; set_tech_name (technology); @@ -369,6 +371,7 @@ LayoutHandle::load (const db::LoadLayoutOptions &options, const std::string &tec file_watcher ().remove_file (filename ()); file_watcher ().add_file (filename ()); + m_save_options.set_format (reader.format ()); m_dirty = false; return new_lmap; } @@ -377,6 +380,8 @@ db::LayerMap LayoutHandle::load () { m_load_options = db::LoadLayoutOptions (); + m_save_options = db::SaveLayoutOptions (); + m_save_options_valid = false; set_tech_name (std::string ()); @@ -394,6 +399,7 @@ LayoutHandle::load () file_watcher ().remove_file (filename ()); file_watcher ().add_file (filename ()); + m_save_options.set_format (reader.format ()); m_dirty = false; return new_lmap; } diff --git a/src/laybasic/laybasic/layLayoutStatisticsForm.cc b/src/laybasic/laybasic/layLayoutStatisticsForm.cc index e671fa0e5..a2e9db0b9 100644 --- a/src/laybasic/laybasic/layLayoutStatisticsForm.cc +++ b/src/laybasic/laybasic/layLayoutStatisticsForm.cc @@ -682,8 +682,13 @@ StatisticsSource::get (const std::string &url) << "" << std::endl << "" << "" - << "" << std::endl - << "" + << "" << std::endl; + if (! m_h->save_options ().format ().empty ()) { + os << "" + << "" + << "" << std::endl; + } + os << "" << "" << "" << std::endl << "" diff --git a/src/laybasic/laybasic/laySaveLayoutOptionsDialog.cc b/src/laybasic/laybasic/laySaveLayoutOptionsDialog.cc index c1fc62cb4..675373333 100644 --- a/src/laybasic/laybasic/laySaveLayoutOptionsDialog.cc +++ b/src/laybasic/laybasic/laySaveLayoutOptionsDialog.cc @@ -338,16 +338,47 @@ SaveLayoutAsOptionsDialog::SaveLayoutAsOptionsDialog (QWidget *parent, const std fmt_cbx->addItem (tl::to_qstring (fmt->format_title ())); - StreamWriterOptionsPage *page = 0; - // obtain the config page from the plugin which we identify by format name const StreamWriterPluginDeclaration *decl = plugin_for_format (fmt->format_name ()); - if (decl) { - page = decl->format_specific_options_page (options_stack); - } - m_pages.push_back (std::make_pair (page, fmt->format_name ())); - m_tab_positions.push_back (page ? options_stack->addWidget (page) : empty_widget_index); + if (decl) { + + const char *alias = decl->options_alias (); + if (alias) { + + // alias needs to come before + int index = -1; + int n = 0; + for (tl::Registrar::iterator i = tl::Registrar::begin (); i != tl::Registrar::end (); ++i) { + if (i->format_name () == alias) { + index = n; + } + ++n; + } + + if (index >= 0 && index < int (m_tab_positions.size ())) { + m_pages.push_back (std::make_pair (m_pages [index].first, fmt->format_name ())); + m_tab_positions.push_back (m_tab_positions[index]); + } else { + m_pages.push_back (std::make_pair ((StreamWriterOptionsPage *) 0, fmt->format_name ())); + m_tab_positions.push_back (empty_widget_index); + } + + } else { + + StreamWriterOptionsPage *page = decl->format_specific_options_page (options_stack); + + m_pages.push_back (std::make_pair (page, fmt->format_name ())); + m_tab_positions.push_back (page ? options_stack->addWidget (page) : empty_widget_index); + + } + + } else { + + m_pages.push_back (std::make_pair ((StreamWriterOptionsPage *) 0, fmt->format_name ())); + m_tab_positions.push_back (empty_widget_index); + + } } @@ -440,7 +471,7 @@ SaveLayoutAsOptionsDialog::get_options (lay::LayoutView *view, unsigned int cv_i for (std::vector< std::pair >::iterator page = m_pages.begin (); page != m_pages.end (); ++page) { const StreamWriterPluginDeclaration *decl = plugin_for_format (page->second); - if (decl) { + if (decl && ! decl->options_alias ()) { std::unique_ptr specific_options; if (options.get_options (page->second)) { diff --git a/src/laybasic/laybasic/layStream.h b/src/laybasic/laybasic/layStream.h index 333e86331..6d3facfd3 100644 --- a/src/laybasic/laybasic/layStream.h +++ b/src/laybasic/laybasic/layStream.h @@ -229,6 +229,14 @@ public: */ static const StreamWriterPluginDeclaration *plugin_for_format (const std::string &format_name); + /** + * @brief If the options are shared with another declaration, returns this name of this declaration here + */ + virtual const char *options_alias () const + { + return 0; + } + /** * @brief Create a format specific options page */ diff --git a/src/plugins/streamers/gds2/lay_plugin/layGDS2WriterPlugin.cc b/src/plugins/streamers/gds2/lay_plugin/layGDS2WriterPlugin.cc index 9a3c03b31..41738a15f 100644 --- a/src/plugins/streamers/gds2/lay_plugin/layGDS2WriterPlugin.cc +++ b/src/plugins/streamers/gds2/lay_plugin/layGDS2WriterPlugin.cc @@ -118,12 +118,14 @@ GDS2WriterOptionPage::multi_xy_clicked () // --------------------------------------------------------------- // GDS2WriterPluginDeclaration definition and implementation -class GDS2WriterPluginDeclaration +namespace { + +class GDS2WriterPluginDeclarationBase : public StreamWriterPluginDeclaration { public: - GDS2WriterPluginDeclaration () - : StreamWriterPluginDeclaration (db::GDS2WriterOptions ().format_name ()) + GDS2WriterPluginDeclarationBase (const std::string &name) + : StreamWriterPluginDeclaration (name) { // .. nothing yet .. } @@ -152,21 +154,47 @@ public: } }; +} + /** - * @brief A dummy plugin for GDS2Text + * @brief A plugin for GDS2 + */ +class GDS2WriterPluginDeclaration + : public GDS2WriterPluginDeclarationBase +{ +public: + GDS2WriterPluginDeclaration () + : GDS2WriterPluginDeclarationBase (db::GDS2WriterOptions ().format_name ()) + { + // .. nothing yet .. + } +}; + +/** + * @brief A plugin for GDS2Text * * GDS2Text shares the options with GDS2, although some limitations do not exist. * There is not specific option set for GDS2Text. The writer will take the options from GDS2. */ class GDS2TextWriterPluginDeclaration - : public StreamWriterPluginDeclaration + : public GDS2WriterPluginDeclarationBase { public: GDS2TextWriterPluginDeclaration () - : StreamWriterPluginDeclaration ("GDS2Text") + : GDS2WriterPluginDeclarationBase ("GDS2Text") { // .. nothing yet .. } + + virtual const char *options_alias () const + { + return db::GDS2WriterOptions ().format_name ().c_str (); + } + + StreamWriterOptionsPage *format_specific_options_page (QWidget *) const + { + return 0; + } }; static tl::RegisteredClass plugin_decl1 (new lay::GDS2WriterPluginDeclaration (), 10000, "GDS2Writer");
" << tl::to_string (QObject::tr ("Path")) << ": " << m_h->filename () << "
" << tl::to_string (QObject::tr ("Format")) << ": " << m_h->save_options ().format () << "
" << tl::to_string (QObject::tr ("Technology")) << ": " << m_h->technology ()->description () << format_tech_name (m_h->tech_name ()) << "