Skip to content

Commit

Permalink
Merge branch 'master' of github.com:KLayout/klayout
Browse files Browse the repository at this point in the history
  • Loading branch information
klayoutmatthias committed Nov 15, 2021
2 parents 748c331 + 5fcc8c1 commit 26da9f7
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/db/db/dbLayout.cc
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ ProxyContextInfo::serialize (std::vector<std::string> &strings)

Layout::Layout (db::Manager *manager)
: db::Object (manager),
mp_library (0),
m_cells_size (0),
m_invalid (0),
m_top_cells (0),
Expand All @@ -362,6 +363,7 @@ Layout::Layout (db::Manager *manager)

Layout::Layout (bool editable, db::Manager *manager)
: db::Object (manager),
mp_library (0),
m_cells_size (0),
m_invalid (0),
m_top_cells (0),
Expand All @@ -382,6 +384,7 @@ Layout::Layout (const db::Layout &layout)
gsi::ObjectBase (),
tl::Object (),
tl::UniqueId (),
mp_library (0),
m_cells_size (0),
m_invalid (0),
m_top_cells (0),
Expand Down Expand Up @@ -2270,6 +2273,7 @@ Layout::register_pcell (const std::string &name, pcell_declaration_type *declara

declaration->m_id = id;
declaration->m_name = name;
declaration->mp_layout = this;

// marks this object being held by the layout
declaration->keep ();
Expand Down
17 changes: 17 additions & 0 deletions src/db/db/dbLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,22 @@ class DB_PUBLIC Layout
return m_tech_name;
}

/**
* @brief Gets the library the layout lives in or NULL if the layout is not part of a library
*/
Library *library () const
{
return mp_library;
}

/**
* @brief Sets the library pointer
*/
void set_library (db::Library *library)
{
mp_library = library;
}

/**
* @brief Gets the technology object the layout is associated with or null if no valid technology is associated
*/
Expand Down Expand Up @@ -1843,6 +1859,7 @@ class DB_PUBLIC Layout
private:
enum LayerState { Normal, Free, Special };

db::Library *mp_library;
cell_list m_cells;
size_t m_cells_size;
cell_ptr_vector m_cell_ptrs;
Expand Down
4 changes: 2 additions & 2 deletions src/db/db/dbLibrary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ namespace db
Library::Library()
: m_id (0), m_layout (true)
{
// .. nothing yet ..
m_layout.set_library (this);
}

Library::Library(const Library &d)
: gsi::ObjectBase (), tl::Object (), m_name (d.m_name), m_description (d.m_description), m_id (0), m_layout (d.m_layout)
{
// .. nothing yet ..
m_layout.set_library (this);
}

Library::~Library ()
Expand Down
2 changes: 1 addition & 1 deletion src/db/db/dbPCellDeclaration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace db
{

PCellDeclaration::PCellDeclaration ()
: m_ref_count (0), m_id (0), m_has_parameter_declarations (false)
: m_ref_count (0), m_id (0), mp_layout (0), m_has_parameter_declarations (false)
{
// .. nothing yet ..
}
Expand Down
9 changes: 9 additions & 0 deletions src/db/db/dbPCellDeclaration.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,14 @@ class DB_PUBLIC PCellDeclaration
return db::Trans ();
}

/**
* @brief Gets the Layout object the PCell is registered inside or NULL if it is not registered
*/
db::Layout *layout () const
{
return mp_layout;
}

/**
* @brief Add a reference to this object
*
Expand Down Expand Up @@ -518,6 +526,7 @@ class DB_PUBLIC PCellDeclaration
int m_ref_count;
pcell_id_type m_id;
std::string m_name;
db::Layout *mp_layout;
mutable bool m_has_parameter_declarations;
mutable std::vector<PCellParameterDeclaration> m_parameter_declarations;

Expand Down
4 changes: 4 additions & 0 deletions src/db/db/gsiDeclDbLayout.cc
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,10 @@ Class<db::Layout> decl_Layout ("db", "Layout",
"\n"
"This method was introduced in version 0.22.\n"
) +
gsi::method ("library", &db::Layout::library,
"@brief Gets the library this layout lives in or nil if the layout is not part of a library\n"
"This attribute has been introduced in version 0.27.5."
) +
gsi::method ("add_meta_info", &db::Layout::add_meta_info, gsi::arg ("info"),
"@brief Adds meta information to the layout\n"
"See \\LayoutMetaInfo for details about layouts and meta information."
Expand Down
4 changes: 4 additions & 0 deletions src/db/db/gsiDeclDbLibrary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ Class<db::PCellDeclaration> decl_PCellDeclaration_Native ("db", "PCellDeclaratio
gsi::method ("parameters_from_shape", &db::PCellDeclaration::parameters_from_shape) +
gsi::method ("transformation_from_shape", &db::PCellDeclaration::transformation_from_shape) +
gsi::method ("display_text", &db::PCellDeclaration::get_display_name) +
gsi::method ("layout", &db::PCellDeclaration::layout,
"@brief Gets the Layout object the PCell is registered in or nil if it is not registered yet.\n"
"This attribute has been added in version 0.27.5."
) +
gsi::method ("id", &db::PCellDeclaration::id,
"@brief Gets the integer ID of the PCell declaration\n"
"This ID is used to identify the PCell in the context of a Layout object for example"
Expand Down
4 changes: 4 additions & 0 deletions testdata/ruby/dbLibrary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def test_1_registration
lib_id = lib.id
assert_equal(lib_id != 0, true)

# the layout inside the library knows the library
assert_equal(lib.layout.library.id == lib.id, true)
assert_equal(lib.layout.library.name, "RBA-unit-test")

assert_equal(RBA::Library::library_names.member?("RBA-unit-test"), true)
assert_equal(RBA::Library::library_by_name("RBA-unit-test").id, lib_id)

Expand Down
15 changes: 15 additions & 0 deletions testdata/ruby/dbPCells.rb
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,21 @@ def test_8

end

def test_9

layout = RBA::Layout::new

pcell = BoxPCell::new
assert_equal(pcell.layout == nil, true)

# sets the layout reference of the PCell declaration:
layout.register_pcell("Box", pcell)

assert_equal(pcell.layout == nil, false)
assert_equal(pcell.layout.object_id == layout.object_id, true)

end

end

load("test_epilogue.rb")
Expand Down

0 comments on commit 26da9f7

Please sign in to comment.