From a9833bf32ec17559a0803bab7f69c5f7244838ff Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Wed, 7 Dec 2022 21:43:43 +0100 Subject: [PATCH] Small bugfix: do not mess up annotation templates after used older KLayout versions again. --- src/ant/ant/antPlugin.cc | 17 +++++++++++++++-- src/ant/ant/antTemplate.cc | 37 ++++++++++++++++++++++++++++++++----- src/ant/ant/antTemplate.h | 22 ++++++++++++++++++++++ 3 files changed, 69 insertions(+), 7 deletions(-) diff --git a/src/ant/ant/antPlugin.cc b/src/ant/ant/antPlugin.cc index 3545deb40..2c19ec65e 100644 --- a/src/ant/ant/antPlugin.cc +++ b/src/ant/ant/antPlugin.cc @@ -26,6 +26,7 @@ #include "layDispatcher.h" #include "layAbstractMenu.h" #include "tlColor.h" +#include "tlLog.h" #if defined(HAVE_QT) # include "layConfigurationDialog.h" #endif @@ -217,7 +218,8 @@ PluginDeclaration::initialized (lay::Dispatcher *root) bool any_missing = false; auto std_templates = make_standard_templates (); for (auto t = std_templates.begin (); ! any_missing && t != std_templates.end (); ++t) { - if (! t->category ().empty () && cat_names.find (t->category ()) == cat_names.end ()) { + if (! t->category ().empty () && + (cat_names.find (t->category ()) == cat_names.end () || cat_names.find (t->category ())->second->version () != ant::Template::current_version ())) { any_missing = true; } } @@ -225,6 +227,9 @@ PluginDeclaration::initialized (lay::Dispatcher *root) if (cat_names.empty ()) { // full initial configuration + if (tl::verbosity () >= 20) { + tl::info << "Resetting annotation templates"; + } root->config_set (cfg_ruler_templates, ant::TemplatesConverter ().to_string (make_standard_templates ())); root->config_end (); @@ -235,9 +240,12 @@ PluginDeclaration::initialized (lay::Dispatcher *root) for (auto t = std_templates.begin (); t != std_templates.end (); ++t) { if (! t->category ().empty ()) { auto tt = cat_names.find (t->category ()); - if (tt != cat_names.end ()) { + if (tt != cat_names.end () && tt->second->version () == ant::Template::current_version ()) { new_templates.push_back (*tt->second); } else { + if (tl::verbosity () >= 20) { + tl::info << "Resetting annotation template: " << t->title (); + } new_templates.push_back (*t); } } @@ -248,6 +256,11 @@ PluginDeclaration::initialized (lay::Dispatcher *root) } } + // upgrade + for (auto i = new_templates.begin (); i != new_templates.end (); ++i) { + i->version (ant::Template::current_version ()); + } + root->config_set (cfg_ruler_templates, ant::TemplatesConverter ().to_string (new_templates)); root->config_end (); diff --git a/src/ant/ant/antTemplate.cc b/src/ant/ant/antTemplate.cc index 84590a2e2..572a84214 100644 --- a/src/ant/ant/antTemplate.cc +++ b/src/ant/ant/antTemplate.cc @@ -30,6 +30,12 @@ namespace ant { +int +Template::current_version () +{ + return 1; +} + ant::Template Template::from_object (const ant::Object &a, const std::string &title, int mode) { @@ -57,7 +63,8 @@ Template::from_object (const ant::Object &a, const std::string &title, int mode) } Template::Template () - : m_title (tl::to_string (tr ("Ruler"))), + : m_version (current_version ()), + m_title (tl::to_string (tr ("Ruler"))), m_fmt_x ("$X"), m_fmt_y ("$Y"), m_fmt ("$D"), m_style (ant::Object::STY_ruler), m_outline (ant::Object::OL_diag), m_snap (true), m_angle_constraint (lay::AC_Global), @@ -74,7 +81,8 @@ Template::Template (const std::string &title, const std::string &fmt_x, const std::string &fmt_y, const std::string &fmt, style_type style, outline_type outline, bool snap, lay::angle_constraint_type angle_constraint, const std::string &cat) - : m_title (title), + : m_version (current_version ()), + m_title (title), m_category (cat), m_fmt_x (fmt_x), m_fmt_y (fmt_y), m_fmt (fmt), m_style (style), m_outline (outline), @@ -89,7 +97,8 @@ Template::Template (const std::string &title, } Template::Template (const ant::Template &d) - : m_title (d.m_title), + : m_version (d.m_version), + m_title (d.m_title), m_category (d.m_category), m_fmt_x (d.m_fmt_x), m_fmt_y (d.m_fmt_y), m_fmt (d.m_fmt), m_style (d.m_style), m_outline (d.m_outline), @@ -107,6 +116,7 @@ Template & Template::operator= (const ant::Template &d) { if (this != &d) { + m_version = d.m_version; m_title = d.m_title; m_category = d.m_category; m_fmt_x = d.m_fmt_x; @@ -132,7 +142,7 @@ std::vector