import pya # =RBA of Ruby; RBA is the integrated Ruby API (RBA) used for programming extentions for KLayout and pya is integrated Python API (pya) - ELsewhr also refers to them as the KLayout module # PCell template # This macro template provides the framework for a PCell library # The PCell declaration class PSAW01(pya.PCellDeclarationHelper): def __init__(self): # Important: initialize the super class super(PSAW01, self).__init__() # declare the parameters gapL= 100 busBarW= 150000 # ~ 1x total digit width connected to it busBarL= 1500000 # ~ should be a typical value to support most gap spacings ( nearly the same spacings as the previous design) - design in a way that pads of all samples are the same place padHotW= 200000 padHotL= 200000 padGndW= 200000 padGndL= 200000 padGndUConnL= 2*200000+2*10000 padGndUConnW = 150000 padClrncHotGnd = 100 # declare the parameters self.param("lyr", self.TypeLayer, "Layer") self.param("shp", self.TypeShape, "", default = pya.DPoint(0, 0)) self.param("gapL", self.TypeDouble, "Gap Length", default = busBarW) self.param("busBarW", self.TypeDouble, "Busbar Width", default = busBarW) self.param("busBarL", self.TypeDouble, "Busbar Length", default = busBarL) self.param("padHotW", self.TypeDouble, "Hot Pad Width", default = padHotW) self.param("padHotL", self.TypeDouble, "Hot Pad Length", default = padHotL) self.param("padGndW", self.TypeDouble, "Gnd Pad Width", default = padGndW) self.param("padGndL", self.TypeDouble, "Gnd Pad Length", default = padGndL) self.param("padGndUConnW", self.TypeDouble, "Pad Gnd U-Shaped Width", default = padGndUConnW) self.param("padGndUConnL", self.TypeDouble, "Pad Gnd U-Shaped Length", default = padGndUConnL) def display_text_impl(self): return "SAW01 - DSAW (Lyr=" + str(self.lyr) + ",gapL=" + ('%.3f' % (self.gapL)) + ")" def coerce_parameters_impl(self): pass def produce_impl(self): self.cell.clear(self.lyr_layer) # Clear shapes already on the layer shps = [ s for s in self.cell.each_shape(self.lyr_layer) ] print("# of shapes in layer (at the start of produce_impl()): " + str(len(shps))) """ ly = db.Layout() top_cell = ly.create_cell("TOP") layer = ly.layer(1, 0) # The parameter names are specific for the parameters = { "layer": db.LayerInfo(1, 0), "text": "KLAYOUT", "mag": 10.0 } cell = ly.create_cell("TEXT", "Basic", parameters) top_cell.insert(db.CellInstArray(cell.cell_index(), db.DTrans())) ly.write("pcell_instances.gds") """ lyo = pya.Layout() # Take the current cell (displayed in the view): #top_cell = pya.CellView.active().cell # create the top cell or get current top cell #top_cell=lyo.top_cell() top_cell = lyo.create_cell("TOP1") #top_cell = self.layout.create_cell("TOP") print(str(top_cell)) # finding the PCell declaration object ... lib = pya.Library.library_by_name("MyLibT2") if lib == None: raise Exception("Unknown lib 'MyLibT2'") pcell_decl = lib.layout().pcell_declaration("ParrTnPatch"); if pcell_decl == None: raise Exception("Unknown PCell 'ParrTnPatch'") # translating named parameters into an ordered sequence ... # named parameters param = { "lyr": pya.LayerInfo(1, 0), # target layer of the text: layer 1, datatype 0 or (17, 5) #"digitW": 1.5 } # translate to array (in pv) pv = [] for p in pcell_decl.get_parameters(): if p.name in param: pv.append(param[p.name]) else: pv.append(p.default) # create the PCell variant cell p [in the library of this class?] #pcell_var = self.layout.add_pcell_variant(self.lib, self.pcell_decl.id(), pv) pcell_var_index = lyo.add_pcell_variant(lib, pcell_decl.id(), pv) # instantiating that cell or place the PCell ... # transformation xpos=1000 ypos=1000 t=pya.DCplxTrans(xpos, ypos) #t = pya.Trans(pya.Trans.R0, xpos, ypos) # The tip of the left-most digit of ParrTnPatch is at origin (0,0) (in the class not in the instance) So top Busbar: rgtX=(2*numD-1)*digitW+digitW, # lwrY=digitL+tipClrnc+overlpExtention top_cell.insert(pya.CellInstArray(pcell_var_index, t)) # insert into "top_cell" (must be provided by the caller) #pcell_inst = top_cell.insert(pya.CellInstArray(pcell_var, t)) # The PCell library declaration # The main purpose of this class is to provide the PCell declarations and to register itself # with a proper name. class MyPCellLib(pya.Library): def __init__(self): # TODO: change the description self.description = "My PCell library" # register the PCell declarations # TODO: change the names self.layout().register_pcell("PSAW01", PSAW01()) # TODO: register more PCell declarations # register our library with the name "PCellLib" # TODO: change the library name self.register("MyPCellLib") # instantiate and register the library # TODO: change the library name MyPCellLib()