#
# 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.rbm ...
# or put the script as "dump_flat_shapes.rbm" into the installation path (on Unix for version <=0.21:
# set $KLAYOUTPATH to the installation folder).
#
class MenuAction < RBA::Action
def initialize( title, shortcut, &action )
self.title = title
self.shortcut = shortcut
@action = action
end
def triggered
@action.call( self )
end
private
@action
end
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_cplx(itrans)
file.puts(" #{box.to_s}")
elsif shape.is_path?
path = shape.path.transformed_cplx(itrans)
file.puts(" #{path.to_s}")
elsif shape.is_polygon?
polygon = shape.polygon.transformed_cplx(itrans)
file.puts(" #{polygon.to_s}")
elsif shape.is_text?
text = shape.text.transformed_cplx(itrans)
file.puts(" #{text.to_s}")
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
$dump_flat_shapes = MenuAction.new( "Dump Flat Shapes", "" ) do
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("")
layers.each do |l|
file.puts(" ")
dump_shapes(file, cv.layout, cv.cell, l, RBA::CplxTrans.new)
file.puts(" ")
end
file.puts("")
end
end
end
app = RBA::Application.instance
mw = app.main_window
menu = mw.menu
menu.insert_separator("tools_menu.end", "name")
menu.insert_item("tools_menu.end", "dump_flat_shapes", $dump_flat_shapes)