# # 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: A simple technology manager for KLayout # # Run the script with # klayout -rm tech_manager.rbm ... # or put the script as "tech_manager.rbm" into the installation path (on Unix for version <=0.21: # set $KLAYOUTPATH to the installation folder). # # A helper class for a menu bound action 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 class TechManager @@tech_info_keys = [ "grid-micron", "default_grids", "dbu", "technologies", "default-layer-properties", "default-add-other" ] def TechManager.get_techinfo ti = { } @@tech_info_keys.each do |k| ti[k] = RBA::Application.instance.get_config(k) end return ti end def TechManager.restore_techinfo(ti) ti.each_pair do |k,v| RBA::Application.instance.set_config(k, v) end end def filename fn = ENV["HOME"] fn ||= "." fn += "/.klayout_tech_info.txt" end def read_techinfo @info = nil begin File.open(filename(), "r") do |file| text = file.read @info = eval(text) end rescue puts "*** ERROR: reading #{filename()}: $!" end @info ||= { } end def save_techinfo begin File.open(filename(), "w") do |file| file.puts(@info.inspect) end rescue puts "*** ERROR: writing #{filename()}: $!" end end def build_menu # remove existing menu items menu = RBA::Application::instance.main_window.menu menu.group("techmanager").each do |item| menu.delete_item(item) end @menus = [] if !menu.is_valid("tech_menu") menu.insert_menu("help_menu", "tech_menu", "Technology") end a = MenuAction.new("Save", "") do tech = RBA::InputDialog.get_string("Save Technology Info", "Technology name", "") if tech.has_value? @info[tech.value] = TechManager.get_techinfo end build_menu save_techinfo end menu.insert_item("tech_menu.end:", "tm_save:techmanager", a) @menus.push(a) # keep the reference a = MenuAction.new("Remove", "") do technologies = [] @info.each_pair do |k,v| technologies.push(k) end if technologies.length tech = RBA::InputDialog.get_item("Remove Technology Info", "Technology to remove", technologies, 0) if tech.has_value? @info.delete(tech.value) end end build_menu save_techinfo end menu.insert_item("tech_menu.end", "tm_remove:techmanager", a) @menus.push(a) # keep the reference menu.insert_separator("tech_menu.end", "tm_separator") id = 1 @info.each_pair do |k,v| a = MenuAction.new(k, "") do TechManager.restore_techinfo(@info[k]) end menu.insert_item("tech_menu.end", "tm_tech#{id}:techmanager", a) @menus.push(a) # keep the reference id += 1 end end end $tech_manager = TechManager.new $tech_manager.read_techinfo $tech_manager.build_menu