Skip to content

Commit 70ba27c

Browse files
Merge pull request #2131 from KLayout/vias-development
Vias development
2 parents 0b7ef4b + a7518f5 commit 70ba27c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+5652
-2819
lines changed

src/db/db/db.pro

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ SOURCES = \
112112
dbUserObject.cc \
113113
dbUtils.cc \
114114
dbVector.cc \
115+
dbVia.cc \
115116
dbWriter.cc \
116117
dbWriterTools.cc \
117118
dbVariableWidthPath.cc \
@@ -239,7 +240,8 @@ SOURCES = \
239240
dbNetShape.cc \
240241
dbShapeCollection.cc \
241242
gsiDeclDbShapeCollection.cc \
242-
dbShapeCollectionUtils.cc
243+
dbShapeCollectionUtils.cc \
244+
gsiDeclDbVia.cc
243245

244246
HEADERS = \
245247
dbArray.h \
@@ -354,6 +356,7 @@ HEADERS = \
354356
dbUserObject.h \
355357
dbUtils.h \
356358
dbVector.h \
359+
dbVia.h \
357360
dbWriter.h \
358361
dbWriterTools.h \
359362
dbGlyphs.h \

src/db/db/dbCell.cc

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,7 @@ Cell::get_pcell_parameters (const instance_type &ref) const
777777
Cell::instance_type
778778
Cell::change_pcell_parameters (const instance_type &ref, const std::vector<tl::Variant> &new_parameters)
779779
{
780+
tl_assert (mp_layout != 0);
780781
cell_index_type new_cell_index = mp_layout->get_pcell_variant_cell (ref.cell_index (), new_parameters);
781782
if (new_cell_index != ref.cell_index ()) {
782783

@@ -790,6 +791,61 @@ Cell::change_pcell_parameters (const instance_type &ref, const std::vector<tl::V
790791
}
791792
}
792793

794+
Cell::instance_type
795+
Cell::change_pcell_parameters (const instance_type &ref, const std::map<std::string, tl::Variant> &map)
796+
{
797+
tl_assert (mp_layout != 0);
798+
799+
const db::PCellDeclaration *pcd = pcell_declaration_of_inst (ref);
800+
if (! pcd) {
801+
return Cell::instance_type ();
802+
}
803+
804+
const std::vector<db::PCellParameterDeclaration> &pcp = pcd->parameter_declarations ();
805+
806+
std::vector<tl::Variant> p = get_pcell_parameters (ref);
807+
bool needs_update = false;
808+
809+
for (size_t i = 0; i < pcp.size () && i < p.size (); ++i) {
810+
std::map<std::string, tl::Variant>::const_iterator pm = map.find (pcp [i].get_name ());
811+
if (pm != map.end () && p [i] != pm->second) {
812+
p [i] = pm->second;
813+
needs_update = true;
814+
}
815+
}
816+
817+
if (needs_update) {
818+
return change_pcell_parameters (ref, p);
819+
} else {
820+
return ref;
821+
}
822+
823+
}
824+
825+
const db::PCellDeclaration *
826+
Cell::pcell_declaration_of_inst (const db::Cell::instance_type &ref) const
827+
{
828+
tl_assert (mp_layout != 0);
829+
return mp_layout->cell (ref.cell_index ()).pcell_declaration ();
830+
}
831+
832+
const db::PCellDeclaration *
833+
Cell::pcell_declaration () const
834+
{
835+
tl_assert (mp_layout != 0);
836+
std::pair<bool, db::pcell_id_type> pc = mp_layout->is_pcell_instance (cell_index ());
837+
if (pc.first) {
838+
db::Library *lib = mp_layout->defining_library (cell_index ()).first;
839+
if (lib) {
840+
return lib->layout ().pcell_declaration (pc.second);
841+
} else {
842+
return mp_layout->pcell_declaration (pc.second);
843+
}
844+
} else {
845+
return 0;
846+
}
847+
}
848+
793849
void
794850
Cell::sort_inst_tree (bool force)
795851
{

src/db/db/dbCell.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class Library;
5757
class ImportLayerMapping;
5858
class CellMapping;
5959
class LayerMapping;
60+
class PCellDeclaration;
6061

6162
/**
6263
* @brief The cell object
@@ -473,6 +474,27 @@ class DB_PUBLIC Cell
473474
*/
474475
instance_type change_pcell_parameters (const instance_type &ref, const std::vector<tl::Variant> &new_parameters);
475476

477+
/**
478+
* @brief Changes the PCell parameters of a PCell instance using a dict
479+
*
480+
* @return A reference to the new instance. The original reference may be invalid.
481+
*/
482+
instance_type change_pcell_parameters (const instance_type &ref, const std::map<std::string, tl::Variant> &new_parameters);
483+
484+
/**
485+
* @brief Gets the PCellDeclaration object of the instance if the instance is a PCell instance
486+
*
487+
* If the instance is not a PCell instance, 0 is returned.
488+
*/
489+
const db::PCellDeclaration *pcell_declaration_of_inst (const db::Cell::instance_type &ref) const;
490+
491+
/**
492+
* @brief Gets the PCellDeclaration object of the cell is the cell is a PCell variant
493+
*
494+
* If the cell is not a PCell variant, 0 is returned.
495+
*/
496+
const db::PCellDeclaration *pcell_declaration () const;
497+
476498
/**
477499
* @brief The cell index accessor method
478500
*

src/db/db/dbManager.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ Manager::transaction (const std::string &description, transaction_id_t join_with
122122
tl_assert (! m_replay);
123123

124124
if (! m_transactions.empty () && reinterpret_cast<transaction_id_t> (& m_transactions.back ()) == join_with) {
125-
m_transactions.back ().second = description;
125+
if (! description.empty ()) {
126+
m_transactions.back ().second = description;
127+
}
126128
} else {
127129
// delete all following transactions and add a new one
128130
erase_transactions (m_current, m_transactions.end ());

src/db/db/dbPCellDeclaration.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include "gsiObject.h"
3030
#include "dbLayout.h"
31+
#include "dbVia.h"
3132
#include "tlVariant.h"
3233
#include "tlObject.h"
3334
#include "tlOptional.h"
@@ -672,6 +673,16 @@ class DB_PUBLIC PCellDeclaration
672673
return std::string ();
673674
}
674675

676+
/**
677+
* @brief Returns the description text of the PCell
678+
*
679+
* The description text is a for human interpretation only. By default, the name will be returned.
680+
*/
681+
virtual std::string get_description () const
682+
{
683+
return m_name;
684+
}
685+
675686
/**
676687
* @brief Returns true, if the PCell can be created from the given shape on the given layer
677688
*
@@ -717,6 +728,25 @@ class DB_PUBLIC PCellDeclaration
717728
return false;
718729
}
719730

731+
/**
732+
* @brief Returns the via types the PCell can provide
733+
*
734+
* This method returns a list of via types the PCell can support.
735+
* If this list is non-empty, the PCell will be used to implement
736+
* vias of one of the given type.
737+
*
738+
* Such a PCell needs to support the following (maybe hidden) parameters
739+
* * "via" (string): the name of the via type
740+
* * "w_bottom" (float): the bottom wire width in um or 0 if not specified
741+
* * "h_bottom" (float): the bottom wire height in um or 0 if not specified
742+
* * "w_top" (float): the top wire width in um or 0 if not specified
743+
* * "h_top" (float): the top wire height in um or 0 if not specified
744+
*/
745+
virtual std::vector<ViaType> via_types () const
746+
{
747+
return std::vector<ViaType> ();
748+
}
749+
720750
/**
721751
* @brief Gets the Layout object the PCell is registered inside or NULL if it is not registered
722752
*/

src/db/db/dbVia.cc

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
2+
/*
3+
4+
KLayout Layout Viewer
5+
Copyright (C) 2006-2025 Matthias Koefferlein
6+
7+
This program is free software; you can redistribute it and/or modify
8+
it under the terms of the GNU General Public License as published by
9+
the Free Software Foundation; either version 2 of the License, or
10+
(at your option) any later version.
11+
12+
This program is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
GNU General Public License for more details.
16+
17+
You should have received a copy of the GNU General Public License
18+
along with this program; if not, write to the Free Software
19+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20+
21+
*/
22+
23+
#include "dbVia.h"
24+
#include "dbLibraryManager.h"
25+
#include "dbPCellDeclaration.h"
26+
27+
namespace db
28+
{
29+
30+
void
31+
ViaType::init ()
32+
{
33+
wbmin = 0.0;
34+
wbmax = -1.0;
35+
hbmin = 0.0;
36+
hbmax = -1.0;
37+
wtmin = 0.0;
38+
wtmax = -1.0;
39+
htmin = 0.0;
40+
htmax = -1.0;
41+
bottom_wired = true;
42+
bottom_grid = 0.0;
43+
top_wired = true;
44+
top_grid = 0.0;
45+
}
46+
47+
// ---------------------------------------------------------------------------------------
48+
49+
std::vector<SelectedViaDefinition>
50+
find_via_definitions_for (const std::string &technology, const db::LayerProperties &layer, int dir)
51+
{
52+
std::vector<SelectedViaDefinition> via_defs;
53+
54+
// Find vias with corresponding top an bottom layers
55+
for (auto l = db::LibraryManager::instance ().begin (); l != db::LibraryManager::instance ().end (); ++l) {
56+
57+
db::Library *lib = db::LibraryManager::instance ().lib (l->second);
58+
if (lib->for_technologies () && ! lib->is_for_technology (technology)) {
59+
continue;
60+
}
61+
62+
for (auto pc = lib->layout ().begin_pcells (); pc != lib->layout ().end_pcells (); ++pc) {
63+
64+
const db::PCellDeclaration *pcell = lib->layout ().pcell_declaration (pc->second);
65+
66+
auto via_types = pcell->via_types ();
67+
for (auto vt = via_types.begin (); vt != via_types.end (); ++vt) {
68+
if ((dir >= 0 && vt->bottom.log_equal (layer) && vt->bottom_wired) ||
69+
(dir <= 0 && vt->top.log_equal (layer) && vt->top_wired)) {
70+
via_defs.push_back (SelectedViaDefinition (lib, pc->second, *vt));
71+
}
72+
}
73+
74+
}
75+
76+
}
77+
78+
return via_defs;
79+
}
80+
81+
}

0 commit comments

Comments
 (0)