mirror of https://github.com/KLayout/klayout.git
Small bugfix: do not mess up annotation templates after used older KLayout versions again.
This commit is contained in:
parent
5f7ae00ed3
commit
a9833bf32e
|
|
@ -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 ();
|
||||
|
||||
|
|
|
|||
|
|
@ -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<Template>
|
|||
Template::from_string (const std::string &s)
|
||||
{
|
||||
std::vector<Template> r;
|
||||
|
||||
|
||||
try {
|
||||
|
||||
tl::Extractor ex (s.c_str ());
|
||||
|
|
@ -140,10 +150,18 @@ Template::from_string (const std::string &s)
|
|||
if (! ex.at_end ()) {
|
||||
|
||||
r.push_back (Template ());
|
||||
r.back ().version (0);
|
||||
|
||||
while (! ex.at_end ()) {
|
||||
|
||||
if (ex.test ("mode=")) {
|
||||
if (ex.test ("version=")) {
|
||||
|
||||
int v = 0;
|
||||
ex.read (v);
|
||||
r.back ().version (v);
|
||||
ex.test (",");
|
||||
|
||||
} else if (ex.test ("mode=")) {
|
||||
|
||||
std::string s;
|
||||
ex.read_word_or_quoted (s);
|
||||
|
|
@ -299,11 +317,17 @@ Template::from_string (const std::string &s)
|
|||
|
||||
ex.expect (";");
|
||||
r.push_back (Template ());
|
||||
r.back ().version (0);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// downgrade version
|
||||
if (r.back ().version () > current_version ()) {
|
||||
r.back ().version (current_version ());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} catch (tl::Exception &ex) {
|
||||
|
|
@ -338,6 +362,9 @@ Template::to_string (const std::vector<Template> &v)
|
|||
r += "category=";
|
||||
r += tl::to_word_or_quoted_string (t->category ());
|
||||
r += ",";
|
||||
r += "version=";
|
||||
r += tl::to_string (t->version ());
|
||||
r += ",";
|
||||
r += "fmt=";
|
||||
r += tl::to_word_or_quoted_string (t->fmt ());
|
||||
r += ",";
|
||||
|
|
|
|||
|
|
@ -107,6 +107,27 @@ public:
|
|||
*/
|
||||
Template &operator= (const ant::Template &d);
|
||||
|
||||
/**
|
||||
* @brief Gets the current version
|
||||
*/
|
||||
static int current_version ();
|
||||
/**
|
||||
* @brief Gets the version
|
||||
* The version is used to provide a migration path for KLayout versions.
|
||||
*/
|
||||
int version () const
|
||||
{
|
||||
return m_version;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the version
|
||||
*/
|
||||
void version (int v)
|
||||
{
|
||||
m_version = v;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets the category string
|
||||
* The category string is used to label the rulers generated from this template.
|
||||
|
|
@ -424,6 +445,7 @@ public:
|
|||
static std::string to_string (const std::vector<Template> &v);
|
||||
|
||||
private:
|
||||
int m_version;
|
||||
std::string m_title;
|
||||
std::string m_category;
|
||||
std::string m_fmt_x;
|
||||
|
|
|
|||
Loading…
Reference in New Issue