Usage of "each_cell" method of class Layout

edited May 2010 in KLayout Support
Hi,

I'd like to dump some information associated with cells using RBA (KLyout version is 0.20.0 on 64-bit Ubuntu 9.04).
The below is my Ruby script.
When this script is given to klayout with -r option, a design file "test1.oas" that contains four cells is
normally loaded and views are set as intended.
Everything is fine.

However, the output text file "dump.txt" contains only two lines:
## start dumping 'test1.oas'
## end dumping 'test1.oas'

It looks "each_cell" iterator does not iterate over the
current layout. What is my fundamental misunderstanding
regarding the usage of this iterator?

Thank you.
Kazzz


#---------------------------------------------------------
# Create a new application
#---------------------------------------------------------
app = RBA::Application.instance

#---------------------------------------------------------
# Create a new layout
#---------------------------------------------------------
mw = app.main_window
mw.create_layout(0)

#---------------------------------------------------------
# Set a view and load a layout
#---------------------------------------------------------
datafile = "test1.oas"
view = mw.current_view
view.load_layout( "#{datafile}", true )
view.set_title( "My first test of RBA using #{datafile}" )
view.max_hier_levels=(2)
layout = view.cellview(0).layout
### Fine up to this point ###

File.open( "dump.txt", "w" ) do |fo|
fo << "## start dumping \'#{datafile}\'\n"
layout.each_cell do |cell|
fo.print( cell.cell_index.to_s )
fo.print( cell.cell_instances.to_s )
fo.print( cell.caller_cells.to_s )
fo.print( cell.called_cells.to_s )
fo.print( cell.bbox.to_s )
end
fo << "## end dumping \'#{datafile}\'\n"
end

# run the application
RBA::Application.instance.exec

Comments

  • edited May 2010

    Hi Kazzz,

    The cell iterator is correct. The problem is that create_layout is creating an empty layout. Because of the second parameter of load_layout (true), the layout that is loaded is added to the view (the first layout still persists). Since the iterator walks over the cells of the first layout (the index of cellview is 0), it reports all the cells of the empty layout - which is basically nothing :-)

    I have rewritten the code somewhat to reflect what I think was the intention of the script. Mainly I have fixed the problem of the empty layout and added some nice formatting to the output.

    Best regards,

    Matthias

    #---------------------------------------------------------
    # Create a new application
    #---------------------------------------------------------
    app = RBA::Application.instance
    
    #---------------------------------------------------------
    # Load the layout
    #---------------------------------------------------------
    mw = app.main_window
    datafile = "clip2.oas"
    mw.load_layout( "#{datafile}", 0 )
    
    #---------------------------------------------------------
    # Get a view 
    #---------------------------------------------------------
    view = mw.current_view
    view.set_title( "My first test of RBA using #{datafile}" )
    view.max_hier_levels=(2)
    layout = view.cellview(view.active_cellview_index).layout
    
    File.open( "dump.txt", "w" ) do |fo|
      fo << "## start dumping \'#{datafile}\'\n"
      layout.each_cell do |cell|
        fo.print("Cell [#{cell.cell_index}] #{layout.cell_name(cell.cell_index)}:\n")
        fo.print("  Instances:\n")
        cell.each_inst do |inst|
          fo.printf("    #{inst}\n")
        end
        fo.print("  Caller cells:\n")
        cell.caller_cells.each do |cc|
          fo.print("     #{layout.cell_name(cc)}\n")
        end
        fo.print("  Caller cells:\n")
        cell.called_cells.each do |cc|
          fo.print("     #{layout.cell_name(cc)}\n")
        end
        fo.print("  BBox: #{cell.bbox}\n")
      end
      fo << "## end dumping \'#{datafile}\'\n"
    end
    
    # run the application
    RBA::Application.instance.exec
    
  • edited May 2010
    Hi Matthias,

    Thank you for clarification and rewriting the script, which is what I wanted to do.
    I could clearly understand the cause of my problem.

    This became a good start point in studying RBA.
    Thank you for providing a good tool kit.

    Best regards,
    Kazzz
Sign In or Register to comment.