mirror of https://github.com/KLayout/klayout.git
Renaming a library will also change the references
This commit is contained in:
parent
d1e440d565
commit
b3cc5d73fe
|
|
@ -149,12 +149,7 @@ void
|
||||||
Library::rename (const std::string &name)
|
Library::rename (const std::string &name)
|
||||||
{
|
{
|
||||||
if (name != get_name () && db::LibraryManager::initialized ()) {
|
if (name != get_name () && db::LibraryManager::initialized ()) {
|
||||||
|
db::LibraryManager::instance ().rename (get_id (), name);
|
||||||
// if the name changed, reregister the library under the new name
|
|
||||||
db::LibraryManager::instance ().unregister_lib (this);
|
|
||||||
set_name (name);
|
|
||||||
db::LibraryManager::instance ().register_lib (this);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,39 @@ LibraryManager::~LibraryManager ()
|
||||||
clear ();
|
clear ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
LibraryManager::rename (lib_id_type lib_id, const std::string &name)
|
||||||
|
{
|
||||||
|
db::Library *lib = 0;
|
||||||
|
|
||||||
|
{
|
||||||
|
tl::MutexLocker locker (&m_lock);
|
||||||
|
|
||||||
|
lib = lib_internal (lib_id);
|
||||||
|
if (! lib) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string org_name = lib->get_name ();
|
||||||
|
|
||||||
|
for (auto it = m_lib_by_name.find (org_name);it != m_lib_by_name.end () && it->first == org_name; ++it) {
|
||||||
|
if (it->second == lib_id) {
|
||||||
|
m_lib_by_name.erase (it);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m_lib_by_name.insert (std::make_pair (name, lib_id));
|
||||||
|
lib->set_name (name);
|
||||||
|
}
|
||||||
|
|
||||||
|
// triggers a layout update
|
||||||
|
lib->remap_to (lib);
|
||||||
|
|
||||||
|
// issue the change notification
|
||||||
|
changed_event ();
|
||||||
|
}
|
||||||
|
|
||||||
std::pair<bool, lib_id_type>
|
std::pair<bool, lib_id_type>
|
||||||
LibraryManager::lib_by_name (const std::string &name, const std::set<std::string> &for_technologies) const
|
LibraryManager::lib_by_name (const std::string &name, const std::set<std::string> &for_technologies) const
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,11 @@ public:
|
||||||
return m_lib_by_name.end ();
|
return m_lib_by_name.end ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Renames a library
|
||||||
|
*/
|
||||||
|
void rename (lib_id_type lib_id, const std::string &name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the library by name which is valid for all given technologies
|
* @brief Get the library by name which is valid for all given technologies
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -216,8 +216,8 @@ LibraryClass<db::Library> decl_Library ("db", "LibraryBase",
|
||||||
gsi::method ("rename", &db::Library::rename, gsi::arg ("name"),
|
gsi::method ("rename", &db::Library::rename, gsi::arg ("name"),
|
||||||
"@brief Renames the library\n"
|
"@brief Renames the library\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Re-registers the library under a new name. Note that this will not change library references - "
|
"Re-registers the library under a new name. Note that this method will also change the references "
|
||||||
"i.e. references to the old name will become invalid after calling this method.\n"
|
"to the library.\n"
|
||||||
"\n"
|
"\n"
|
||||||
"This method has been introduced in version 0.30.5."
|
"This method has been introduced in version 0.30.5."
|
||||||
) +
|
) +
|
||||||
|
|
|
||||||
|
|
@ -127,6 +127,7 @@ class DBLibrary_TestClass < TestBase
|
||||||
assert_equal(lib.destroyed?, true)
|
assert_equal(lib.destroyed?, true)
|
||||||
|
|
||||||
lib = RBA::Library::new
|
lib = RBA::Library::new
|
||||||
|
lib.layout.create_cell("A")
|
||||||
lib.description = "LIB1"
|
lib.description = "LIB1"
|
||||||
lib.register("RBA-unit-test")
|
lib.register("RBA-unit-test")
|
||||||
assert_equal(RBA::Library::library_by_name("RBA-unit-test").description, "LIB1")
|
assert_equal(RBA::Library::library_by_name("RBA-unit-test").description, "LIB1")
|
||||||
|
|
@ -138,14 +139,22 @@ class DBLibrary_TestClass < TestBase
|
||||||
lib.register("RBA-unit-test")
|
lib.register("RBA-unit-test")
|
||||||
assert_equal(RBA::Library::library_by_name("RBA-unit-test").description, "LIB1")
|
assert_equal(RBA::Library::library_by_name("RBA-unit-test").description, "LIB1")
|
||||||
|
|
||||||
|
ly = RBA::Layout::new
|
||||||
|
ci = ly.create_cell("A", "RBA-unit-test").cell_index
|
||||||
|
assert_equal(ly.cell(ci).qname, "RBA-unit-test.A")
|
||||||
|
|
||||||
lib.rename("RBA-unit-test2")
|
lib.rename("RBA-unit-test2")
|
||||||
assert_equal(RBA::Library::library_by_name("RBA-unit-test"), nil)
|
assert_equal(RBA::Library::library_by_name("RBA-unit-test"), nil)
|
||||||
assert_equal(RBA::Library::library_by_name("RBA-unit-test2").description, "LIB1")
|
assert_equal(RBA::Library::library_by_name("RBA-unit-test2").description, "LIB1")
|
||||||
|
|
||||||
|
assert_equal(ly.cell(ci).qname, "RBA-unit-test2.A")
|
||||||
|
|
||||||
lib.delete
|
lib.delete
|
||||||
assert_equal(RBA::Library::library_by_name("RBA-unit-test"), nil)
|
assert_equal(RBA::Library::library_by_name("RBA-unit-test"), nil)
|
||||||
assert_equal(RBA::Library::library_by_name("RBA-unit-test2"), nil)
|
assert_equal(RBA::Library::library_by_name("RBA-unit-test2"), nil)
|
||||||
|
|
||||||
|
assert_equal(ly.cell(ci).qname, "<defunct>RBA-unit-test2.A")
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_5_reload
|
def test_5_reload
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue