I was able to make some progress on this with some help from pieces of code found on the site and on-line. I wanted to specifically attribute the basic code to what I found on the following link and in this chain:
http://www.klayout.org/svn-public/klayout-resources/trunk/scripts/write_childcells.rbm
I am posting the code for which I still need some help. The code below reports the branch cell (2nd level of hierarchy) and the final leaf cell with the x & y center of the layer shapes for the layer index = 32. Unfortunately, the x & y center is with respect to the branch cell instantiation rather than the top cell instantiation. I think I have already killed a lot of brain cells reaching this point and was hoping that someone could point to the "trivial" change I am missing and need to make to report the x & y with respect to the top cell instead of the branch cell.
The code is hard to read since it lacks the indents (hint: use four blanks in front of each line that are supposed to be formatted as code).
But basically the code is quite good. You just need to add the following:
1.) To get the layer index for a given layer/datatype pair, use layer_index = ly.layer(layer, datatype)
2.) Add a current-cell to top-cell transformation to the get_cells_at_hierarchy_level method. For the top cell, this transformation is unity:
def get_cells_at_hierarchy_level(layout, from_cell, level, cells, trans)
..
end
# use a unity transformation for the top cell
get_cells_at_hierarchy_level(cv.layout, cv.cell, level, cells_to_write, RBA::CplxTrans::new)
3.) Iterate over instances instead of the child cells:
from_cell.each_inst do |inst|
cell = inst.cell
..
end
When a cell is instantiated twice, you will visit this cell two times. each_child_cell only does so once.
4.) Inside this function when you call get_cells_at_hierarchy_level recursively combine the given transformation with that of the instance:
get_cells_at_hierarchy_level(layout, layout.cell(cc), level - 1, cells, trans * inst.cplx_trans)
5.) You don't need to recursively iterate over the shapes, since you have coded the same yourself:
cell.shapes(layer_index).each do |s|
bbox = s.bbox.transformed(trans)
name = cell.name
... print bbox, cell name etc. ...
end
How can you adapt the code to extract the lower left and upper right x,y coordinates (in the Box Properties)? I tried replacing center with lower.left as well as upper.right and it didn't work.
Comments
http://www.klayout.org/svn-public/klayout-resources/trunk/scripts/write_childcells.rbm
I am posting the code for which I still need some help. The code below reports the branch cell (2nd level of hierarchy) and the final leaf cell with the x & y center of the layer shapes for the layer index = 32. Unfortunately, the x & y center is with respect to the branch cell instantiation rather than the top cell instantiation. I think I have already killed a lot of brain cells reaching this point and was hoping that someone could point to the "trivial" change I am missing and need to make to report the x & y with respect to the top cell instead of the branch cell.
Thanks,
Vikas
mw = RBA::Application::instance.main_window
lv = mw.current_view # layout view
ly = lv.active_cellview.layout # layout
cv = lv.cellview(lv.active_cellview_index)
level = 2
cells_to_write = {} # defined as a hash
layer = 100 # layer index = 32 which is hard coded for now below
datatype = 0
# input = ly.layer_indices.find { |li| lp = ly.get_info(li); lp.layer == layer && lp.datatype = datatype }
def get_cells_at_hierarchy_level(layout, from_cell, level, cells)
from_cell.each_child_cell do |cc|
input = 32
si = layout.cell(layout.cell_name(cc)).begin_shapes_rec(input)
while !si.at_end?
bbox = si.shape.bbox.transformed(si.trans)
name = si.cell.name
puts "#{layout.cell_name(cc)}, #{name}, #{'%.3f'%(bbox.center.x*layout.dbu)}, #{'%.3f'%(bbox.center.y*layout.dbu)}"
si.next
end
if level == 1
cells[cc] = 1
else
get_cells_at_hierarchy_level(layout, layout.cell(cc), level - 1, cells)
end
end
end
get_cells_at_hierarchy_level(cv.layout, cv.cell, level, cells_to_write)
Hi Vikas,
The code is hard to read since it lacks the indents (hint: use four blanks in front of each line that are supposed to be formatted as code).
But basically the code is quite good. You just need to add the following:
1.) To get the layer index for a given layer/datatype pair, use
layer_index = ly.layer(layer, datatype)
2.) Add a current-cell to top-cell transformation to the
get_cells_at_hierarchy_level
method. For the top cell, this transformation is unity:3.) Iterate over instances instead of the child cells:
When a cell is instantiated twice, you will visit this cell two times.
each_child_cell
only does so once.4.) Inside this function when you call
get_cells_at_hierarchy_level
recursively combine the given transformation with that of the instance:5.) You don't need to recursively iterate over the shapes, since you have coded the same yourself:
Matthias
puts "#{'%.3f'%(bbox.center.x*ly.dbu)},#{'%.3f'%(bbox.center.y*ly.dbu)}"
replace with:
puts "#{'%.3f'%(bbox.lower.left.x*ly.dbu)},#{'%.3f'%(bbox.lower.left.y*ly.dbu)}"
Basically, I'm trying to extract the corners coordinates of my bond pads from the GDS.
Thanks!