Skip to content

Commit ff49a81

Browse files
Merge pull request #2199 from KLayout/feature/issue-2195
Feature/issue 2195
2 parents d015b98 + fc31851 commit ff49a81

File tree

19 files changed

+376
-36
lines changed

19 files changed

+376
-36
lines changed

src/db/db/built-in-macros/pcell_declaration_helper.lym

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,18 @@ created as well.
149149
This method must be reimplemented in a PCell class to identify the PCell in human-readable form.
150150
This text is shown in the cell tree for the PCell for example.
151151

152+
@method cell_name_impl
153+
154+
@brief Delivers the cell name to be used for the PCell variant
155+
156+
A PCell variant is represented in the cell tree by a placeholder cell. By
157+
default, the name of this cell is the PCell name. Since multiple variants
158+
may exist, usually a disambiguator is added to the name (e.g. "..$1").
159+
160+
This method allows encoding the PCell parameters into that cell name,
161+
so the PCell variant is easier to identify in the cell tree - for example
162+
in the GDS file - instead of the unspecific disambiguator.
163+
152164
@method produce_impl
153165

154166
@brief Produces the layout
@@ -466,6 +478,19 @@ module RBA
466478
text
467479
end
468480

481+
# implementation of cell_name
482+
def cell_name(parameters)
483+
self._start
484+
@param_values = parameters
485+
text = ""
486+
begin
487+
text = cell_name_impl
488+
ensure
489+
self._finish
490+
end
491+
text
492+
end
493+
469494
# get the parameters
470495
def get_parameters
471496
@param_decls
@@ -568,6 +593,11 @@ module RBA
568593
""
569594
end
570595

596+
# default implementation
597+
def cell_name_impl
598+
self.name
599+
end
600+
571601
# default implementation
572602
def coerce_parameters_impl
573603
end

src/db/db/built-in-pymacros/pcell_declaration_helper.lym

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,18 @@ created as well.
158158
This method must be reimplemented in a PCell class to identify the PCell in human-readable form.
159159
This text is shown in the cell tree for the PCell for example.
160160

161+
@method cell_name_impl
162+
163+
@brief Delivers the cell name to be used for the PCell variant
164+
165+
A PCell variant is represented in the cell tree by a placeholder cell. By
166+
default, the name of this cell is the PCell name. Since multiple variants
167+
may exist, usually a disambiguator is added to the name (e.g. "..$1").
168+
169+
This method allows encoding the PCell parameters into that cell name,
170+
so the PCell variant is easier to identify in the cell tree - for example
171+
in the GDS file - instead of the unspecific disambiguator.
172+
161173
@method produce_impl
162174

163175
@brief Produces the layout

src/db/db/dbCell.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,12 @@ Cell::get_basic_name () const
862862
return layout ()->cell_name (cell_index ());
863863
}
864864

865+
std::string
866+
Cell::get_variant_name () const
867+
{
868+
return get_basic_name ();
869+
}
870+
865871
std::string
866872
Cell::get_qualified_name () const
867873
{

src/db/db/dbCell.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,14 +890,22 @@ class DB_PUBLIC Cell
890890
void set_name (const std::string &name);
891891

892892
/**
893-
* @brief Get the basic name
893+
* @brief Gets the basic name
894894
*
895895
* The basic name of the cell is either the cell name or the cell name in the
896896
* target library (for library proxies) or the PCell name (for PCell proxies).
897897
* The actual name may be different by a extension to make it unique.
898898
*/
899899
virtual std::string get_basic_name () const;
900900

901+
/**
902+
* @brief Gets the variant name
903+
*
904+
* The variant name is the PCell's "cell_name" - which may encode the PCell parameters
905+
* into a formal name. Usually that is identical to the PCell name.
906+
*/
907+
virtual std::string get_variant_name () const;
908+
901909
/**
902910
* @brief Gets the display name
903911
*

src/db/db/dbColdProxy.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ ColdProxy::get_basic_name () const
8989
}
9090
}
9191

92-
std::string
92+
std::string
9393
ColdProxy::get_display_name () const
9494
{
9595
if (! mp_context_info->lib_name.empty ()) {

src/db/db/dbLayout.cc

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2462,7 +2462,7 @@ Layout::get_pcell_variant_dict (pcell_id_type pcell_id, const std::map<std::stri
24622462
pcell_variant_type *variant = header->get_variant (*this, parameters);
24632463
if (! variant) {
24642464

2465-
std::string b (header->get_name ());
2465+
std::string b (header->declaration ()->get_cell_name (parameters));
24662466
if (m_cell_map.find (b.c_str ()) != m_cell_map.end ()) {
24672467
b = uniquify_cell_name (b.c_str ());
24682468
}
@@ -2501,7 +2501,7 @@ Layout::get_pcell_variant (pcell_id_type pcell_id, const std::vector<tl::Variant
25012501
pcell_variant_type *variant = header->get_variant (*this, parameters);
25022502
if (! variant) {
25032503

2504-
std::string b (header->get_name ());
2504+
std::string b (header->declaration ()->get_cell_name (parameters));
25052505
if (m_cell_map.find (b.c_str ()) != m_cell_map.end ()) {
25062506
b = uniquify_cell_name (b.c_str ());
25072507
}
@@ -2627,9 +2627,18 @@ Layout::convert_cell_to_static (db::cell_index_type ci)
26272627

26282628
const cell_type &org_cell = cell (ci);
26292629

2630-
// Note: convert to static cell by explicitly cloning to the db::Cell class
2631-
ret_ci = add_cell (org_cell.get_basic_name ().c_str ());
2630+
std::string vn = org_cell.get_variant_name ();
2631+
if (vn == std::string (cell_name (ci), vn.size ())) {
2632+
// there is a cell name conflict: give priority to the static cell, so it
2633+
// will see the variant name or at least the original disambiguated name
2634+
std::string rename_org = uniquify_cell_name (vn.c_str ());
2635+
vn = cell_name (ci);
2636+
rename_cell (ci, rename_org.c_str ());
2637+
}
2638+
2639+
ret_ci = add_cell (vn.c_str ());
26322640
cell_type &new_cell = cell (ret_ci);
2641+
// Note: we convert to static cell by explicitly converting to the db::Cell class
26332642
new_cell = org_cell;
26342643
new_cell.set_cell_index (ret_ci);
26352644

@@ -3126,6 +3135,12 @@ Layout::basic_name (cell_index_type cell_index) const
31263135
return cell (cell_index).get_basic_name ();
31273136
}
31283137

3138+
std::string
3139+
Layout::variant_name (cell_index_type cell_index) const
3140+
{
3141+
return cell (cell_index).get_variant_name ();
3142+
}
3143+
31293144
void
31303145
Layout::register_lib_proxy (db::LibraryProxy *lib_proxy)
31313146
{
@@ -3161,7 +3176,7 @@ Layout::get_lib_proxy (Library *lib, cell_index_type cell_index)
31613176
} else {
31623177

31633178
// create a new unique name
3164-
std::string b (lib->layout ().basic_name (cell_index));
3179+
std::string b (lib->layout ().variant_name (cell_index));
31653180
if (m_cell_map.find (b.c_str ()) != m_cell_map.end ()) {
31663181
b = uniquify_cell_name (b.c_str ());
31673182
}

src/db/db/dbLayout.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ class DB_PUBLIC Layout
675675
std::string display_name (cell_index_type cell_index) const;
676676

677677
/**
678-
* @brief Return the basic name for the given cell
678+
* @brief Returns the basic name for the given cell
679679
*
680680
* This method is forwarded to the respective method of the cell.
681681
* The basic name is the "original" cell name within the library or
@@ -684,7 +684,16 @@ class DB_PUBLIC Layout
684684
*/
685685
std::string basic_name (cell_index_type cell_index) const;
686686

687-
/**
687+
/**
688+
* @brief Returns the variant name for the given cell
689+
*
690+
* The variant name usually is the basic name. For PCells, this name
691+
* can encode PCell parameters, depending on the definition of the
692+
* PCell.
693+
*/
694+
std::string variant_name (cell_index_type cell_index) const;
695+
696+
/**
688697
* @brief Add a cell object with the given ID and name
689698
*
690699
* This method is basically supposed to be used for "undo" and "redo".

src/db/db/dbLibraryProxy.cc

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,23 @@ LibraryProxy::get_basic_name () const
257257
}
258258
}
259259

260-
std::string
260+
std::string
261+
LibraryProxy::get_variant_name () const
262+
{
263+
Library *lib = LibraryManager::instance ().lib (lib_id ());
264+
if (lib) {
265+
if (! lib->layout ().is_valid_cell_index (library_cell_index ())) {
266+
return "<defunct>";
267+
} else {
268+
const db::Cell &lib_cell = lib->layout ().cell (library_cell_index ());
269+
return lib_cell.get_variant_name ();
270+
}
271+
} else {
272+
return Cell::get_variant_name ();
273+
}
274+
}
275+
276+
std::string
261277
LibraryProxy::get_display_name () const
262278
{
263279
Library *lib = LibraryManager::instance ().lib (lib_id ());

src/db/db/dbLibraryProxy.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,25 +96,28 @@ class DB_PUBLIC LibraryProxy
9696
/**
9797
* @brief Gets the basic name
9898
*
99-
* The basic name of the cell is either the cell name or the cell name in the
100-
* target library (for library proxies) or the PCell name (for PCell proxies).
101-
* The actual name may be different by a extension to make it unique.
99+
* This returns the basic name of the proxy target
102100
*/
103101
virtual std::string get_basic_name () const;
104102

103+
/**
104+
* @brief Gets the variant name
105+
*
106+
* This returns the basic name of the proxy target
107+
*/
108+
virtual std::string get_variant_name () const;
109+
105110
/**
106111
* @brief Gets the display name
107112
*
108-
* The display name is some "nice" descriptive name of the cell (variant)
109-
* For normal cells this name is equivalent to the normal cell name.
113+
* This returns the basic name of the proxy target
110114
*/
111115
virtual std::string get_display_name () const;
112116

113117
/**
114118
* @brief Gets the qualified name
115119
*
116-
* The qualified name for a library proxy is made from the library name, a
117-
* dot and the cell's name.
120+
* Gets a combination of the library name and the target cell's qualified name
118121
*/
119122
virtual std::string get_qualified_name () const;
120123

src/db/db/dbPCellDeclaration.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,18 @@ class DB_PUBLIC PCellDeclaration
673673
return std::string ();
674674
}
675675

676+
/**
677+
* @brief Gets a cell name for the PCell, which can depend on the parameters
678+
*
679+
* The actual cell name in the layout may differ by disambiguation. This method
680+
* delivers a proposal for a cell name.
681+
* By default, the PCell name is returned.
682+
*/
683+
virtual std::string get_cell_name (const pcell_parameters_type &) const
684+
{
685+
return m_name;
686+
}
687+
676688
/**
677689
* @brief Returns the description text of the PCell
678690
*

0 commit comments

Comments
 (0)