It looks like you're new here. If you want to get involved, click one of these buttons!
import pya
import math
"""
This sample PCell implements a library called "MyLib" with a single PCell that
draws a circle. It demonstrates the basic implementation techniques for a PCell
and how to use the "guiding shape" feature to implement a handle for the circle
radius.
NOTE: after changing the code, the macro needs to be rerun to install the new
implementation. The macro is also set to "auto run" to install the PCell
when KLayout is run.
"""
class Parray(pya.PCellDeclarationHelper):
"""
The PCell declaration for the circle
"""
def __init__(self):
# Important: initialize the super class
super(Parray, self).__init__()
# declare the parameters
self.param("l", self.TypeLayer, "Layer", default = pya.LayerInfo(1, 0))
self.param("ref", self.TypeShape, "", default = pya.DPoint(0, 0))
self.param("shp", self.TypeShape, "", default = pya.Polygon([pya.DPoint(-500, -500),pya.DPoint(1000, 0),pya.DPoint(0, 1000)]))
self.param("rownum", self.TypeInt, "Row Number", default = 4)
self.param("rowx", self.TypeInt, "Row X", default = 0)
self.param("rowy", self.TypeInt, "Row Y", default = 50)
self.param("rowm", self.TypeInt, "Row Mag", default = 1)
self.param("rowa", self.TypeInt, "Row Ang", default = 0)
self.param("colnum", self.TypeInt, "Col Number", default = 4)
self.param("colx", self.TypeInt, "Col X", default = 50)
self.param("coly", self.TypeInt, "Col Y", default = 0)
self.param("colm", self.TypeInt, "Col Mag", default = 1)
self.param("cola", self.TypeInt, "Col Ang", default = 0)
def display_text_impl(self):
# Provide a descriptive text for the cell
return "Parray(L=" + str(self.l) + ")"
def coerce_parameters_impl(self):
pass
def can_create_from_shape_impl(self):
# Implement the "Create PCell from shape" protocol: we can use any shape which
# has a finite bounding box
return self.shape.is_polygon()
def parameters_from_shape_impl(self):
# Implement the "Create PCell from shape" protocol: we set r and l from the shape's
# bounding box width and layer
self.shp =self.shape.dpolygon
self.ref = self.shape.bbox().center()
self.l = self.layout.get_info(self.layer)
def transformation_from_shape_impl(self):
# Implement the "Create PCell from shape" protocol: we use the center of the shape's
# bounding box to determine the transformation
return pya.Trans(pya.Point(0,0))
def produce_impl(self):
# This is the main part of the implementation: create the layout
# fetch the parameters
self.cell.shapes(self.l_layer).insert(self.shp)
for j in self.cell.shapes(self.l_layer).each():
self.shp=j.dpolygon
for j in range(rownum):
for k in range(colnum):
tt=pya.DCplxTrans(self.rowx*j+self.colx*k, self.rowy*j+self.coly*k)
self.cell.shapes(self.l_layer).insert(tt.trans(self.shp))
class MyLib(pya.Library):
"""
The library where we will put the PCell into
"""
def __init__(self):
# Set the description
self.description = "My First Library"
# Create the PCell declarations
self.layout().register_pcell("Parray", Parray())
# That would be the place to put in more PCells ...
# Register us with the name "MyLib".
# If a library with that name already existed, it will be replaced then.
self.register("MyLib")
# Instantiate and register the library
MyLib()
Comments
Why is changing the default parameters invalid here
@zhenganqi Sorry, I don't understand. Please help me. What is the problem?
And please mark Python code with a triple backtick line before and after so it gets formatted as code. Like on github. I took the liberty to edit your post.
Maybe some things are "baked in" and if you want to change
the recipe, you have to go all the way back to making dough?
If you want to make a cake that is different from the one you just got - than that's the right approach