1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
|
# encoding: UTF-8
# KLayout Layout Viewer
# Copyright (C) 2006-2025 Matthias Koefferlein
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
if !$:.member?(File::dirname($0))
$:.push(File::dirname($0))
end
load("test_prologue.rb")
class DBCellTests_TestClass < TestBase
def make_layout
ly = RBA::Layout::new
top = ly.create_cell("TOP")
a = ly.create_cell("A")
l1 = ly.layer(1, 0)
a.shapes(l1).insert(RBA::DBox::new(1, 2, 3, 4))
top.insert(RBA::DCellInstArray::new(a.cell_index, RBA::DTrans::R0))
top.insert(RBA::DCellInstArray::new(a.cell_index, RBA::DTrans::R90))
ly
end
# writing cells
def test_1
tmp = File::join($ut_testtmp, "tmp.gds")
ly = make_layout
top = ly.top_cell
top.write(tmp)
ly2 = RBA::Layout::new
ly2.read(tmp)
assert_equal(RBA::Region::new(ly2.top_cell.begin_shapes_rec(ly2.layer(1, 0))).to_s, "(1000,2000;1000,4000;3000,4000;3000,2000);(-4000,1000;-4000,3000;-2000,3000;-2000,1000)")
tmp = File::join($ut_testtmp, "tmp2.gds")
opt = RBA::SaveLayoutOptions::new
opt.dbu = 0.005
top.write(tmp, opt)
ly2 = RBA::Layout::new
ly2.read(tmp)
assert_equal(RBA::Region::new(ly2.top_cell.begin_shapes_rec(ly2.layer(1, 0))).to_s, "(200,400;200,800;600,800;600,400);(-800,200;-800,600;-400,600;-400,200)")
end
# reading cells
def test_2
tmp = File::join($ut_testtmp, "tmp.gds")
ly = make_layout
top = ly.top_cell
top.write(tmp)
ly2 = RBA::Layout::new
ly2.dbu = 0.005
top = ly2.create_cell("IMPORTED")
top.read(tmp)
assert_equal(RBA::Region::new(top.begin_shapes_rec(ly2.layer(1, 0))).to_s, "(200,400;200,800;600,800;600,400);(-800,200;-800,600;-400,600;-400,200)")
ly2 = RBA::Layout::new
ly2.dbu = 0.005
top = ly2.create_cell("IMPORTED")
opt = RBA::LoadLayoutOptions::new
lm = RBA::LayerMap::new
lm.map("1/0 : 5/0", 0)
opt.layer_map = lm
top.read(tmp, opt)
assert_equal(RBA::Region::new(top.begin_shapes_rec(ly2.layer(5, 0))).to_s, "(200,400;200,800;600,800;600,400);(-800,200;-800,600;-400,600;-400,200)")
end
# methods with LayerInfo instead layer index
def test_3
ly = RBA::Layout::new
top = ly.create_cell("TOP")
l1 = ly.layer(1, 0)
top.shapes(RBA::LayerInfo::new(1, 0)).insert(RBA::Box::new(0, 0, 100, 200))
assert_equal(top.shapes(l1).size, 1)
# unknown layers are ignored in clear
top.clear(RBA::LayerInfo::new(2, 0))
assert_equal(top.shapes(l1).size, 1)
# clear with LayerInfo
top.clear(RBA::LayerInfo::new(1, 0))
assert_equal(top.shapes(l1).size, 0)
# layer is created if not there
assert_equal(ly.layer_infos, [ RBA::LayerInfo::new(1, 0) ])
top.shapes(RBA::LayerInfo::new(2, 0)).insert(RBA::Box::new(0, 0, 100, 200))
assert_equal(ly.layer_infos, [ RBA::LayerInfo::new(1, 0), RBA::LayerInfo::new(2, 0) ])
end
# locking
def test_4
ly = RBA::Layout::new
top = ly.create_cell("TOP")
other = ly.create_cell("OTHER")
child = ly.create_cell("CHILD")
l1 = ly.layer(1, 0)
l2 = ly.layer(2, 0)
shape = top.shapes(l1).insert(RBA::Box::new(0, 0, 100, 200))
inst = top.insert(RBA::CellInstArray::new(child, RBA::Trans::new(RBA::Vector::new(100, 200))))
other.insert(RBA::CellInstArray::new(child, RBA::Trans::new(RBA::Vector::new(10, 20))))
assert_equal(top.is_locked?, false)
top.locked = false
assert_equal(top.is_locked?, false)
top.locked = true
assert_equal(top.is_locked?, true)
# rename is still possible
top.name = "TOP2"
# instances of the cell can still be created
toptop = ly.create_cell("TOPTOP")
toptop.insert(RBA::CellInstArray::new(top, RBA::Trans::new))
assert_equal(top.each_parent_inst.to_a[0].child_inst.to_s, "cell_index=0 r0 0,0")
begin
# forbidden now
top.shapes(l2).insert(RBA::Box::new(0, 0, 100, 200))
assert_equal(true, false)
rescue => ex
assert_equal(ex.to_s, "Cell 'TOP2' cannot be modified as it is locked in Shapes::insert")
end
begin
# forbidden now
shape.box = RBA::Box::new(1, 2, 101, 202)
assert_equal(true, false)
rescue => ex
assert_equal(ex.to_s, "Cell 'TOP2' cannot be modified as it is locked in Shape::box=")
end
begin
# forbidden now
shape.prop_id = 1
assert_equal(true, false)
rescue => ex
assert_equal(ex.to_s, "Cell 'TOP2' cannot be modified as it is locked in Shape::prop_id=")
end
begin
# forbidden now
shape.polygon = RBA::Polygon::new(RBA::Box::new(0, 0, 200, 100))
assert_equal(true, false)
rescue => ex
assert_equal(ex.to_s, "Cell 'TOP2' cannot be modified as it is locked in Shape::polygon=")
end
begin
# forbidden now
inst.cell_index = other.cell_index
assert_equal(true, false)
rescue => ex
assert_equal(ex.to_s, "Cell 'TOP2' cannot be modified as it is locked in Instance::cell_index=")
end
begin
# forbidden now
inst.prop_id = 1
assert_equal(true, false)
rescue => ex
assert_equal(ex.to_s, "Cell 'TOP2' cannot be modified as it is locked in Instance::prop_id=")
end
begin
# also forbidden
top.insert(RBA::CellInstArray::new(child, RBA::Trans::new))
assert_equal(true, false)
rescue => ex
assert_equal(ex.to_s, "Cell 'TOP2' cannot be modified as it is locked in Cell::insert")
end
begin
# clear is forbidding
top.clear
assert_equal(true, false)
rescue => ex
assert_equal(ex.to_s, "Cell 'TOP2' cannot be modified as it is locked in Cell::clear")
end
begin
# clear layer is forbidden
top.shapes(l1).clear
assert_equal(true, false)
rescue => ex
assert_equal(ex.to_s, "Cell 'TOP2' cannot be modified as it is locked in Shapes::clear")
end
begin
# clear layer is forbidden
top.clear(l1)
assert_equal(true, false)
rescue => ex
assert_equal(ex.to_s, "Cell 'TOP2' cannot be modified as it is locked in Cell::clear")
end
begin
# layer copy is forbidden
top.copy(l1, l2)
assert_equal(true, false)
rescue => ex
assert_equal(ex.to_s, "Cell 'TOP2' cannot be modified as it is locked in Cell::copy")
end
begin
# layer move is forbidden
top.move(l1, l2)
assert_equal(true, false)
rescue => ex
assert_equal(ex.to_s, "Cell 'TOP2' cannot be modified as it is locked in Cell::move")
end
begin
# layer swap is forbidden
top.swap(l1, l2)
assert_equal(true, false)
rescue => ex
assert_equal(ex.to_s, "Cell 'TOP2' cannot be modified as it is locked in Cell::swap")
end
begin
# copy_instances is forbidden
top.copy_instances(other)
assert_equal(true, false)
rescue => ex
assert_equal(ex.to_s, "Cell 'TOP2' cannot be modified as it is locked in Cell::copy_instances")
end
begin
# move_instances is forbidden
top.move_instances(other)
assert_equal(true, false)
rescue => ex
assert_equal(ex.to_s, "Cell 'TOP2' cannot be modified as it is locked in Cell::move_instances")
end
begin
# copy_tree is forbidden
top.copy_tree(other)
assert_equal(true, false)
rescue => ex
assert_equal(ex.to_s, "Cell 'TOP2' cannot be modified as it is locked in Cell::copy_tree")
end
begin
# move_tree is forbidden
top.move_tree(other)
assert_equal(true, false)
rescue => ex
assert_equal(ex.to_s, "Cell 'TOP2' cannot be modified as it is locked in Cell::move_tree")
end
begin
# copy_shapes is forbidden
top.copy_shapes(other)
assert_equal(true, false)
rescue => ex
assert_equal(ex.to_s, "Cell 'TOP2' cannot be modified as it is locked in Cell::copy_shapes")
end
begin
# move_shapes is forbidden
top.move_shapes(other)
assert_equal(true, false)
rescue => ex
assert_equal(ex.to_s, "Cell 'TOP2' cannot be modified as it is locked in Cell::move_shapes")
end
begin
# flatten is forbidden
top.flatten(true)
assert_equal(true, false)
rescue => ex
assert_equal(ex.to_s, "Cell 'TOP2' cannot be modified as it is locked in Cell::flatten")
end
begin
# cell cannot be deleted
top.delete
assert_equal(true, false)
rescue => ex
assert_equal(ex.to_s, "Cell 'TOP2' cannot be modified as it is locked in Cell::delete")
end
# locked attribute is copied
ly2 = ly.dup
assert_equal(ly2.cell("TOP2").is_locked?, true)
begin
# cell cannot be deleted
ly2.cell("TOP2").delete
assert_equal(true, false)
rescue => ex
assert_equal(ex.to_s, "Cell 'TOP2' cannot be modified as it is locked in Cell::delete")
end
# clear and _destroy is always possible
ly2.clear
ly2 = ly.dup
ly2._destroy
# resetting the locked flag enables things again (not all tested here)
top.locked = false
inst.cell_index = other.cell_index
top.shapes(l2).insert(RBA::Box::new(0, 0, 100, 200))
shape.box = RBA::Box::new(1, 2, 101, 202)
top.delete
end
end
load("test_epilogue.rb")
|