Round Cell Array
Placeing cell references into a round wafer is a common task. This macro will place a named cell reference into a circular wafer as often as possible. Please set baseCell, circleRadius and x/yCenter in line 15 to line 18 to your requirements before starting this macro.
Download: roundCellArray.layout
1 #!/usr/bin/layout
2 #name=Macro: roundCellArray.layout
3 #help=filling a wafer with cell references
4
5 bool insideCircle(point p, int radius){
6 double x=p.x();
7 double y=p.y();
8 double r=radius;
9 double d=x*x+y*y;
10 if (d<r*r) return true;
11 return false;
12 }
13
14 int main(){
15 string baseCell="baseCell";
16 int circleRadius=50000000; //in databaseunits
17 int xCenter=0; // center of the circle
18 int yCenter=0;
19 //layout->drawing->selectAll(); //uncomment these two line to delete design first
20 //layout->drawing->deleteSelect();
21 string cellname=layout->drawing->currentCell->cellName;
22 cell *c=layout->drawing->findCell(baseCell);
23 if (c==NULL){
24 layout->showMessage("Error","base cell not found");
25 return 0;
26 }
27 point min=c->minimum();
28 point max=c->maximum();
29 point size=max-min;
30 point center; center.set(xCenter,yCenter);
31 int startX=min.x();
32 int startY=min.y();
33 while (startY>-circleRadius) startY-=size.y();
34 while (startX>-circleRadius) startX-=size.x();
35 int x=startX;
36 int y=-startY;
37 do {
38 y=startY;
39 do {
40 point pc; pc.set(x-min.x()+xCenter,y-min.y()+yCenter);
41 point p1,p2,p3,p4;
42 p1.set(x,y); //lower left
43 p2.set(x+size.x(),y); //lower right
44 p3.set(x,y+size.y()); // upper left
45 p4.set(x+size.x(),y+size.y()); // upper right
46 if (insideCircle(p1,circleRadius)&&insideCircle(p2,circleRadius)
47 &&insideCircle(p3,circleRadius)&&insideCircle(p4,circleRadius)){
48 element *e=layout->drawing->currentCell->addCellref(c,pc);
49 }
50 y+= size.y();
51 } while (y<circleRadius+size.y());
52 x+= size.x();
53 } while (x<circleRadius+size.x());
54 //layout->drawing->currentCell->addCircle(1,center,circleRadius,360); //uncomment to show circle
55 layout->drawing->scaleFull();
56 }