Layout View Saving Issue

Hi,
After upgrading klayout to 0.28.3, there comes a layout saving bug.
Here is the code:

shape1 = RBA::Box::new(-100000,-100000,100000,100000)
shape2 = RBA::Box::new(-200000,-200000,0,0)
main_window = Application::instance.main_window
ly = main_window.create_layout(1).layout
layout = CellView.active.layout
ly.add_cell("TOP")
ly.dbu = 0.001
layout_view = main_window.current_view
top = layout.cell("TOP")
layout_view.select_cell(0, 0)
l1 = layout.layer(1, 0)
l2 = layout.layer(2, 0)
top.shapes(l1).insert(shape1)
top.shapes(l2).insert(shape2)
layout_view.add_missing_layers
layout_view.zoom_fit
layout_view.max_hier_levels=100

a2 = layout_view.each_layer.to_a  
a2[1].fill_color = 100100100
a2[0].fill_color = 255255255

layout_view.get_image(1000,2000).save(File.join(File.dirname(__FILE__),"shot.png"))

After running the script above, the output image is empty.

Then I run the code#2:

layout_view = $main_window.current_view
layout_view.get_image(1000,2000).save(File.join(File.dirname(__FILE__),"shot2.png"))

The correct image comes back!

I think maybe it is a bug? Could you help me solve this problem?
Thanks

Wang

Comments

  • Hello Wang,

    I am 0.28.3 ( Binary ) user. I try to do it under my own understanding , and it works. Please refer to below

    ly = RBA::Layout.new
    l1 = ly.layer(1, 0)
    l2 = ly.layer(2, 0)
    ly.dbu = 0.001
    top = ly.create_cell("TOP")
    
    shape1 = RBA::Box::new(-100000,-100000,100000,100000)
    shape2 = RBA::Box::new(-200000,-200000,0,0)
    top.shapes(l1).insert(shape1)
    top.shapes(l2).insert(shape2)
    
    mw = RBA::MainWindow.instance
    vw = mw.view(mw.create_view())
    vw.show_layout(ly, true)  
    
    lv = RBA::LayoutView.current
    a2 = lv.each_layer.to_a  
    a2[1].fill_color = 100100100
    a2[0].fill_color = 255255255
    
    lv.get_image(1000,2000).save(File.join(File.dirname(__FILE__),"shot.png"))  
    

    Good luck
    Vincent

  • Hi @Default,

    please refer to @Vincent Lin 's code (thanks for sharing). Your code uses two layout objects which are not necessarily the same and the correct behavior depends on side effects that are not guaranteed. The below code is clean and guaranteed to work.

    BTW: for the colors you should use hex notation - 255255255 is not "white" (which does not make sense on a white background anyway). Red for example is 0xff0000.

    Matthias

  • edited June 2023

    Hi @Vincent%20Lin
    Thanks for your code, but there is another problem: The color of box is incorrect.

    Do you know what the problem is ? thanks a lot.
    Wang

  • Hi Matthias,
    Thanks!
    Wang

  • edited June 2023

    Hi @Matthias ,
    I printed the hash value of layout_view in each macro, the value is same.
    So Maybe it's not the problem?

    # code 1
    shape1 = RBA::Box::new(-100000,-100000,100000,100000)
    shape2 = RBA::Box::new(-200000,-200000,0,0)
    main_window = RBA::MainWindow.instance
    ly = main_window.create_layout(1).layout
    ly.dbu = 0.001
    top = ly.create_cell("TOP")
    layout_view  = RBA::LayoutView.current
    layout_view.select_cell(0, 0)
    l1 = ly.layer(1, 0)
    l2 = ly.layer(2, 0)
    top.shapes(l1).insert(shape1)
    top.shapes(l2).insert(shape2)
    layout_view.add_missing_layers
    layout_view.zoom_fit
    layout_view.max_hier_levels=100
    
    a2 = layout_view.each_layer.to_a  
    a2[1].fill_color = 100100100
    a2[0].fill_color = 255255255
    layout_view  = RBA::LayoutView.current
    p layout_view.hash
    layout_view.get_image(1000,2000).save(File.join(File.dirname(__FILE__),"shot.png"))
    
    # code 2
    main_window = RBA::MainWindow.instance
    p layout_view.hash
    layout_view.get_image(1000,2000).save(File.join(File.dirname(__FILE__),"shot2.png"))
    
    OUTPUT: 
    1612230759862236657
    1612230759862236657
    
  • No, that's simply the way the colors are specified. See my note about hexadecimal notation of color codes.

    If you want the layer to take a specific color use the hex RGB triplet notation that HTML uses too (e.g. #ffd700 for "gold") and turn it into a hex integer constant (`0xffd700´ in that case). Also make sure you set fill and frame color to the same value if you want them to be the same. In the above example, only the fill color is set and "100100100" is not a meaningful RGB triplet.

    Matthias

  • Hi @Matthias,
    Sorry, I forgot to change that values .
    Now I change the code to
    a2[1].fill_color = 0x0000CD
    a2[0].fill_color = 0xDC143C
    and the problem still exist..
    the screenshot of code #1 is empty , then I run the code #2 ,It returned the same layout_view hash but the screenshot came back.
    Wang

  • Try to insert "layout_view.update_content" before "get_image" or use "get_image_with_options".
    "get_image" shares the view with the event-driven Window system and changes to the view may not be immediate.

    This works for me:

    main_window = RBA::MainWindow.instance
    
    ly = main_window.create_layout(1).layout
    ly.dbu = 0.001
    top = ly.create_cell("TOP")
    
    layout_view  = RBA::LayoutView.current
    layout_view.select_cell(0, 0)
    l1 = ly.layer(1, 0)
    l2 = ly.layer(2, 0)
    
    shape1 = RBA::Box::new(-100000,-100000,100000,100000)
    shape2 = RBA::Box::new(-200000,-200000,0,0)
    top.shapes(l1).insert(shape1)
    top.shapes(l2).insert(shape2)
    
    layout_view.add_missing_layers
    layout_view.zoom_fit
    layout_view.max_hier_levels=100
    
    a2 = layout_view.each_layer.to_a
     a2[1].fill_color = 0x0000CD
    a2[0].fill_color = 0xDC143C
    
    layout_view.update_content
    layout_view.get_image(1000,2000).save("/tmp/shot.png")
    

    Matthias

  • It works perfectly!
    Thanks a lot Matthias!

Sign In or Register to comment.