Fill klayout dialogs from RBA

edited July 2012 in General
Is it possible to fill a KLayout dialog from RBA?
For some DRC automation job, I would like to open the Marker Browser dialog from ruby (which can be done by triggering the menu item) and fill the Database field.

Comments

  • edited 12:32AM

    Hallo,

    it is possible to create a marker database by script and show the marker browser dialog with that marker database.

    I have added a sample script that demonstrates how to create, fill and show a marker database. In that script the database is filled from the shapes on the currently selected layer.

    Best regards,

    Matthias

    def scan_layers
    
      app = RBA::Application.instance
      mw = app.main_window
      view = mw.current_view
      return unless view
    
      layers = view.selected_layers
      return unless layers.size > 0
    
      cv_index = -1
      view.selected_layers.each do |l|
        if cv_index >= 0 
          if l.current.source_cellview(true) >= 0 && cv_index != l.current.source_cellview(true)
            raise "Selected layers must originate from the same layout"
          end
        else
          cv_index = l.current.source_cellview(true)
        end
      end
    
      cv = view.cellview(cv_index)
      return unless cv.is_valid?
    
      layout = cv.layout
    
      dbu_trans = RBA::DCplxTrans::new(layout.dbu)
    
      rdb_index = view.create_rdb("layer_scan")
      rdb = view.rdb(rdb_index)
      rdb.top_cell_name = layout.cell_name(cv.cell_index)
    
      cells = {}
      layout.each_cell do |cell|
        cells[cell.cell_index] = rdb.create_cell(layout.cell_name(cell.cell_index))
      end
    
      view.selected_layers.each do |l|
    
        if cv_index == l.current.source_cellview(true)
    
          layer_index = l.current.layer_index
          if layout.is_valid_layer?(layer_index)
    
            cat_name = l.current.source(true)
            rdb_cat = rdb.create_category(cat_name)
            rdb_cat_id = rdb_cat.rdb_id
    
            layout.each_cell do |cell|
    
              rdb_cell = cells[cell.cell_index]
              rdb_cell_id = rdb_cell.rdb_id
    
              cell.shapes(layer_index).each do |shape|
    
                if shape.is_polygon? || shape.is_path? || shape.is_box?
                  rdb_item = rdb.create_item(rdb_cell_id, rdb_cat_id)
                  dpoly = RBA::DPolygon::from_ipoly(shape.polygon).transformed_cplx(dbu_trans)
                  value = RBA::RdbItemValue::new(dpoly)
                  rdb_item.add_value(value)
                end
    
              end
    
            end
    
          end
    
        end
    
      end
    
      # Hint: a corresponding cm_... method is missing
      action_path = "tools_menu.browse_markers"
      if mw.menu.is_valid(action_path)
        mw.menu.action(action_path).trigger
      end
    
    end
    
    
    # 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
    
    # register the function in the toolbar
    # TODO: add shortcut, correct title etc.
    app = RBA::Application.instance
    mw = app.main_window
    
    menu = mw.menu
    menu.insert_separator("@lcp_context_menu.end", "tb_separator")
    menu.insert_item("@lcp_context_menu.end", "scan_layers", MenuAction.new("Scan Layers Into RDB", "") { scan_layers })
    
  • edited 12:32AM
    thanks!
Sign In or Register to comment.