From e35e9fe8f79af79f05e8b84710d98980982ec123 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Thu, 30 Mar 2017 00:11:09 +0200 Subject: [PATCH] Tech data accessible as "technology-data" config value Previously, the "technology-data" complex configuration value was stored in the configuration file, but not accessible from scripts through Application#set_config and Applicatiob#get_config. It was as pseudo parameter that wasn't dynamically connected to the application state. Now it's handled separately as if it was a normal parameter. This is just an intermediate solution required because this interface is the only one through which tech data is accessible from scripts. --- src/lay/layApplication.cc | 28 ++++++++++++++++++++++++++-- src/laybasic/layTechnology.cc | 12 +++++++++++- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/lay/layApplication.cc b/src/lay/layApplication.cc index 09da07490..44ff914ca 100644 --- a/src/lay/layApplication.cc +++ b/src/lay/layApplication.cc @@ -1639,7 +1639,22 @@ void Application::set_config (const std::string &name, const std::string &value) { if (mp_plugin_root) { - mp_plugin_root->config_set (name, value); + + if (name == cfg_technologies) { + + // HACK: cfg_technologies is not a real configuration parameter currently. Hence we emulate that + // behavior. But currently this is the only way to access technology data indirectly from a script. + // Note that this method will set only the technologies accessible through the configuration parameter. + // I.e. the ones not auto-imported. + // TODO: rework this one. This is only half-hearted. + if (! value.empty ()) { + lay::Technologies::instance ()->load_from_xml (value); + } + + } else { + mp_plugin_root->config_set (name, value); + } + } } @@ -1655,7 +1670,16 @@ std::string Application::get_config (const std::string &name) const { if (mp_plugin_root) { - return mp_plugin_root->config_get (name); + if (name == cfg_technologies) { + // HACK: cfg_technologies is not a real configuration parameter currently. Hence we emulate that + // behavior. But currently this is the only way to access technology data indirectly from a script. + // Note that this method will return only the technologies accessible through the configuration parameter. + // I.e. the ones not auto-imported. + // TODO: rework this one. + return lay::Technologies::instance ()->to_xml (); + } else { + return mp_plugin_root->config_get (name); + } } else { return std::string (); } diff --git a/src/laybasic/layTechnology.cc b/src/laybasic/layTechnology.cc index 84bbec0e8..9750e2995 100644 --- a/src/laybasic/layTechnology.cc +++ b/src/laybasic/layTechnology.cc @@ -97,9 +97,19 @@ Technologies::to_xml () const void Technologies::load_from_xml (const std::string &s) { + // create a copy to filter out the ones which are not persisted and remain + lay::Technologies copy; + for (const_iterator t = begin (); t != end (); ++t) { + if (! t->is_persisted ()) { + copy.add (new Technology (*t)); + } + } + tl::XMLStringSource source (s); tl::XMLStruct xml_struct ("technologies", xml_elements ()); - xml_struct.parse (source, *this); + xml_struct.parse (source, copy); + + *this = copy; } void