mirror of
https://github.com/KLayout/klayout.git
synced 2026-08-30 09:49:21 +02:00
CellMapping: documentation, some convenience bindings
This commit is contained in:
Vendored
+102
-20
@@ -25,14 +25,14 @@ load("test_prologue.rb")
|
||||
|
||||
def mapping_to_s(ly1, ly2, cm)
|
||||
r = ""
|
||||
ly1.each_cell_top_down do |c|
|
||||
s = ly1.cell(c).name
|
||||
ly2.each_cell_top_down do |c|
|
||||
s = ly2.cell(c).name
|
||||
if cm.has_mapping?(c)
|
||||
t = cm.cell_mapping(c)
|
||||
if t == RBA::CellMapping::DropCell
|
||||
s += "=>(0)"
|
||||
else
|
||||
s += "=>" + ly2.cell(t).name
|
||||
s += "=>" + ly1.cell(t).name
|
||||
end
|
||||
end
|
||||
r == "" || (r += ";")
|
||||
@@ -44,14 +44,14 @@ end
|
||||
def mapping_to_s_from_table(ly1, ly2, cm)
|
||||
table = cm.table
|
||||
r = ""
|
||||
ly1.each_cell_top_down do |c|
|
||||
s = ly1.cell(c).name
|
||||
ly2.each_cell_top_down do |c|
|
||||
s = ly2.cell(c).name
|
||||
if table[c]
|
||||
t = table[c]
|
||||
if t == RBA::CellMapping::DropCell
|
||||
s += "=>(0)"
|
||||
else
|
||||
s += "=>" + ly2.cell(t).name
|
||||
s += "=>" + ly1.cell(t).name
|
||||
end
|
||||
end
|
||||
r == "" || (r += ";")
|
||||
@@ -120,12 +120,21 @@ class DBCellMapping_TestClass < TestBase
|
||||
|
||||
mp = RBA::CellMapping::new
|
||||
mp.from_names(ly1, top1, ly2, top2)
|
||||
assert_equal(mapping_to_s(ly2, ly1, mp), "c0;c2=>c2;c1=>c1;c3=>c3")
|
||||
assert_equal(mapping_to_s_from_table(ly2, ly1, mp), "c0;c2=>c2;c1=>c1;c3=>c3")
|
||||
assert_equal(mapping_to_s(ly1, ly2, mp), "c0;c2=>c2;c1=>c1;c3=>c3")
|
||||
assert_equal(mapping_to_s_from_table(ly1, ly2, mp), "c0;c2=>c2;c1=>c1;c3=>c3")
|
||||
|
||||
mp = RBA::CellMapping::new
|
||||
mp.from_names(ly1.cell(top1), ly2.cell(top2))
|
||||
assert_equal(mapping_to_s(ly1, ly2, mp), "c0;c2=>c2;c1=>c1;c3=>c3")
|
||||
assert_equal(mapping_to_s_from_table(ly1, ly2, mp), "c0;c2=>c2;c1=>c1;c3=>c3")
|
||||
|
||||
mp = RBA::CellMapping::new
|
||||
mp.from_geometry(ly1, top1, ly2, top2)
|
||||
assert_equal(mapping_to_s(ly2, ly1, mp), "c0;c2=>c2;c1=>c1;c3=>c3")
|
||||
assert_equal(mapping_to_s(ly1, ly2, mp), "c0;c2=>c2;c1=>c1;c3=>c3")
|
||||
|
||||
mp = RBA::CellMapping::new
|
||||
mp.from_geometry(ly1.cell(top1), ly2.cell(top2))
|
||||
assert_equal(mapping_to_s(ly1, ly2, mp), "c0;c2=>c2;c1=>c1;c3=>c3")
|
||||
|
||||
ly = RBA::Layout::new
|
||||
|
||||
@@ -150,17 +159,23 @@ class DBCellMapping_TestClass < TestBase
|
||||
|
||||
mp = RBA::CellMapping::new
|
||||
mp.from_names(ly1, top1, ly2, top2)
|
||||
assert_equal(mapping_to_s(ly2, ly1, mp), "c0;c2=>c2;c1=>c1;cx")
|
||||
assert_equal(mapping_to_s(ly1, ly2, mp), "c0;c2=>c2;c1=>c1;cx")
|
||||
|
||||
ly1dup = ly1.dup
|
||||
mp = RBA::CellMapping::new
|
||||
nc = mp.from_names_full(ly1dup, top1, ly2, top2)
|
||||
assert_equal(mapping_to_s(ly2, ly1dup, mp), "c0;c2=>c2;c1=>c1;cx=>cx")
|
||||
assert_equal(mapping_to_s(ly1dup, ly2, mp), "c0;c2=>c2;c1=>c1;cx=>cx")
|
||||
assert_equal(nc.inspect, "[3]")
|
||||
|
||||
ly1dup = ly1.dup
|
||||
mp = RBA::CellMapping::new
|
||||
nc = mp.from_names_full(ly1dup.cell(top1), ly2.cell(top2))
|
||||
assert_equal(mapping_to_s(ly1dup, ly2, mp), "c0;c2=>c2;c1=>c1;cx=>cx")
|
||||
assert_equal(nc.inspect, "[3]")
|
||||
|
||||
mp = RBA::CellMapping::new
|
||||
mp.from_geometry(ly1, top1, ly2, top2)
|
||||
assert_equal(mapping_to_s(ly2, ly1, mp), "c0;c2=>c2;c1=>c1;cx=>c3")
|
||||
assert_equal(mapping_to_s(ly1, ly2, mp), "c0;c2=>c2;c1=>c1;cx=>c3")
|
||||
|
||||
ly = RBA::Layout::new
|
||||
|
||||
@@ -185,23 +200,29 @@ class DBCellMapping_TestClass < TestBase
|
||||
|
||||
mp = RBA::CellMapping::new
|
||||
mp.from_names(ly1, top1, ly2, top2)
|
||||
assert_equal(mapping_to_s(ly2, ly1, mp), "c0;c2=>c2;c1=>c1;c3=>c3")
|
||||
assert_equal(mapping_to_s(ly1, ly2, mp), "c0;c2=>c2;c1=>c1;c3=>c3")
|
||||
|
||||
mp = RBA::CellMapping::new
|
||||
mp.from_geometry(ly1, top1, ly2, top2)
|
||||
assert_equal(mapping_to_s(ly2, ly1, mp), "c0;c2=>c2;c1=>c1;c3")
|
||||
assert_equal(mapping_to_s(ly1, ly2, mp), "c0;c2=>c2;c1=>c1;c3")
|
||||
|
||||
ly1dup = ly1.dup
|
||||
mp = RBA::CellMapping::new
|
||||
nc = mp.from_geometry_full(ly1dup, top1, ly2, top2)
|
||||
assert_equal(mapping_to_s(ly2, ly1dup, mp), "c0;c2=>c2;c1=>c1;c3=>c3$1")
|
||||
assert_equal(mapping_to_s(ly1dup, ly2, mp), "c0;c2=>c2;c1=>c1;c3=>c3$1")
|
||||
assert_equal(nc.inspect, "[3]")
|
||||
|
||||
ly1dup = ly1.dup
|
||||
mp = RBA::CellMapping::new
|
||||
nc = mp.from_geometry_full(ly1dup.cell(top1), ly2.cell(top2))
|
||||
assert_equal(mapping_to_s(ly1dup, ly2, mp), "c0;c2=>c2;c1=>c1;c3=>c3$1")
|
||||
assert_equal(nc.inspect, "[3]")
|
||||
|
||||
mp.clear
|
||||
mp.from_geometry(ly1, top1, ly2, top2)
|
||||
mp.map(ci2, RBA::CellMapping::DropCell)
|
||||
assert_equal(mapping_to_s(ly2, ly1, mp), "c0;c2=>(0);c1=>c1;c3")
|
||||
assert_equal(mapping_to_s_from_table(ly2, ly1, mp), "c0;c2=>(0);c1=>c1;c3")
|
||||
assert_equal(mapping_to_s(ly1, ly2, mp), "c0;c2=>(0);c1=>c1;c3")
|
||||
assert_equal(mapping_to_s_from_table(ly1, ly2, mp), "c0;c2=>(0);c1=>c1;c3")
|
||||
|
||||
end
|
||||
|
||||
@@ -223,6 +244,53 @@ class DBCellMapping_TestClass < TestBase
|
||||
a1.insert(RBA::CellInstArray::new(a3.cell_index, RBA::Trans::new))
|
||||
a2.insert(RBA::CellInstArray::new(a4.cell_index, RBA::Trans::new))
|
||||
|
||||
ly_target = RBA::Layout::new
|
||||
b0 = ly_target.create_cell("b0")
|
||||
|
||||
cm = RBA::CellMapping::new
|
||||
cm.for_single_cell(ly_target, b0.cell_index, ly, a1.cell_index)
|
||||
|
||||
assert_equal(mapping_to_s(ly_target, ly, cm), "a0;a1=>b0;a2;a3;a4;a5")
|
||||
|
||||
cm = RBA::CellMapping::new
|
||||
cm.for_single_cell(b0, a1)
|
||||
|
||||
assert_equal(mapping_to_s(ly_target, ly, cm), "a0;a1=>b0;a2;a3;a4;a5")
|
||||
|
||||
lytdup = ly_target.dup
|
||||
cm = RBA::CellMapping::new
|
||||
nc = cm.for_single_cell_full(lytdup, b0.cell_index, ly, a1.cell_index)
|
||||
assert_equal(nc.inspect, "[1, 2, 3]")
|
||||
|
||||
assert_equal(mapping_to_s(lytdup, ly, cm), "a0;a1=>b0;a2;a3=>a3;a4=>a4;a5=>a5")
|
||||
|
||||
lytdup = ly_target.dup
|
||||
cm = RBA::CellMapping::new
|
||||
nc = cm.for_single_cell_full(lytdup.cell(b0.cell_index), a1)
|
||||
assert_equal(nc.inspect, "[1, 2, 3]")
|
||||
|
||||
assert_equal(mapping_to_s(lytdup, ly, cm), "a0;a1=>b0;a2;a3=>a3;a4=>a4;a5=>a5")
|
||||
|
||||
end
|
||||
|
||||
def test_3
|
||||
|
||||
ly = RBA::Layout::new
|
||||
|
||||
a0 = ly.create_cell("a0")
|
||||
a1 = ly.create_cell("a1")
|
||||
a2 = ly.create_cell("a2")
|
||||
a3 = ly.create_cell("a3")
|
||||
a4 = ly.create_cell("a4")
|
||||
a5 = ly.create_cell("a5")
|
||||
|
||||
a3.insert(RBA::CellInstArray::new(a4.cell_index, RBA::Trans::new))
|
||||
a3.insert(RBA::CellInstArray::new(a5.cell_index, RBA::Trans::new))
|
||||
|
||||
a1.insert(RBA::CellInstArray::new(a4.cell_index, RBA::Trans::new))
|
||||
a1.insert(RBA::CellInstArray::new(a3.cell_index, RBA::Trans::new))
|
||||
a2.insert(RBA::CellInstArray::new(a4.cell_index, RBA::Trans::new))
|
||||
|
||||
ly_target = RBA::Layout::new
|
||||
b0 = ly_target.create_cell("b0")
|
||||
b1 = ly_target.create_cell("b1")
|
||||
@@ -231,12 +299,26 @@ class DBCellMapping_TestClass < TestBase
|
||||
cm = RBA::CellMapping::new
|
||||
cm.for_multi_cells(ly_target, [ b0, b1, b2 ].collect { |c| c.cell_index }, ly, [ a0, a1, a2 ].collect { |c| c.cell_index })
|
||||
|
||||
assert_equal(mapping_to_s(ly_target, ly, cm), "b0=>a0;b1=>a1;b2=>a2")
|
||||
assert_equal(mapping_to_s(ly_target, ly, cm), "a0=>b0;a1=>b1;a2=>b2;a3;a4;a5")
|
||||
|
||||
cm = RBA::CellMapping::new
|
||||
cm.for_multi_cells_full(ly_target, [ b0, b1, b2 ].collect { |c| c.cell_index }, ly, [ a0, a1, a2 ].collect { |c| c.cell_index })
|
||||
cm.for_multi_cells([ b0, b1, b2 ], [ a0, a1, a2 ])
|
||||
|
||||
assert_equal(mapping_to_s(ly_target, ly, cm), "b0=>a0;b1=>a1;b2=>a2;a3=>a3;a4=>a4;a5=>a5")
|
||||
assert_equal(mapping_to_s(ly_target, ly, cm), "a0=>b0;a1=>b1;a2=>b2;a3;a4;a5")
|
||||
|
||||
lytdup = ly_target.dup
|
||||
cm = RBA::CellMapping::new
|
||||
nc = cm.for_multi_cells_full(lytdup, [ b0, b1, b2 ].collect { |c| c.cell_index }, ly, [ a0, a1, a2 ].collect { |c| c.cell_index })
|
||||
assert_equal(nc.inspect, "[3, 4, 5]")
|
||||
|
||||
assert_equal(mapping_to_s(lytdup, ly, cm), "a0=>b0;a1=>b1;a2=>b2;a3=>a3;a4=>a4;a5=>a5")
|
||||
|
||||
lytdup = ly_target.dup
|
||||
cm = RBA::CellMapping::new
|
||||
cm.for_multi_cells_full([ b0, b1, b2 ].collect { |c| lytdup.cell(c.cell_index) }, [ a0, a1, a2 ])
|
||||
assert_equal(nc.inspect, "[3, 4, 5]")
|
||||
|
||||
assert_equal(mapping_to_s(lytdup, ly, cm), "a0=>b0;a1=>b1;a2=>b2;a3=>a3;a4=>a4;a5=>a5")
|
||||
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user