Dump Flat Shapes false false true dump_flat_shapes tools_menu.end ruby # # 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. # # DESCRIPTION: Dump all shapes of the current cell recursively to a XML file # # Run the script with # klayout -rm dump_flat_shapes.lym ... # or put the script as "dump_flat_shapes.lym" into the installation path (on Unix for version <=0.21: # set $KLAYOUTPATH to the installation folder). # def dump_shapes(file, layout, cell, layer, trans) itrans = RBA::ICplxTrans.from_trans(trans) cell.shapes(layer).each do |shape| if shape.is_box? box = shape.box.transformed(itrans) file.puts(" <box>#{box.to_s}</box>") elsif shape.is_path? path = shape.path.transformed(itrans) file.puts(" <path>#{path.to_s}</path>") elsif shape.is_polygon? polygon = shape.polygon.transformed(itrans) file.puts(" <polygon>#{polygon.to_s}</polygon>") elsif shape.is_text? text = shape.text.transformed(itrans) file.puts(" <text>#{text.to_s}</text>") end end cell.each_inst do |inst| if inst.is_regular_array? na = inst.na nb = inst.nb a = inst.a b = inst.b (0..(na-1)).each do |ia| (0..(nb-1)).each do |ib| disp = RBA::Point.new(a.x * ia + b.x * ib, a.y * ia + b.y * ib) disp_trans = RBA::CplxTrans.new(RBA::Trans.new(disp)) dump_shapes(file, layout, layout.cell(inst.cell_index), layer, trans * disp_trans * inst.cplx_trans) end end else dump_shapes(file, layout, layout.cell(inst.cell_index), layer, trans * inst.cplx_trans) end end end # main functionality app = RBA::Application.instance mw = app.main_window lv = mw.current_view if lv == nil raise "No view selected" end cv = lv.active_cellview if !cv.is_valid? raise "No cell or no layout found" end layers = [] lnode = lv.begin_layers while !lnode.at_end? if !lnode.current.has_children? && lnode.current.layer_index >=0 && lnode.current.visible?(true) layers.push(lnode.current.layer_index) end lnode.next end # Ask for the file name filename = RBA::FileDialog.get_save_file_name("Flat Dump", ".", "All files (*)") if filename.has_value? File.open(filename.value, "w") do |file| file.puts("<shape_dump cell=\"#{cv.layout.cell_name(cv.cell_index)}\" dbu=\"#{cv.layout.dbu}\">") layers.each do |l| file.puts(" <layer source=\"#{cv.layout.get_info(l).to_s}\">") dump_shapes(file, cv.layout, cv.cell, l, RBA::CplxTrans.new) file.puts(" </layer>") end file.puts("</shape_dump>") end end