the fair gds editor ExpandLineMacro

Expand Line Macro

To use this macro select one ore more polygons and the macro will place boxes over all horizontal and vertical segments.

Download: expand_line.layout

   1 #!/usr/bin/layout
   2 #name=poly line->set of boxes
   3 #help=takes a simple line and converts it to boxes of a given width
   4 /***
   5  * written by Arun (arun@users.sf.net) 2006-03
   6  * using layout version 2006-3-15 (cvs)
   7  *
   8  * this is just to show what macros can do...
   9  * it worked for me, but your mileage may vary
  10  */
  11 
  12  
  13 int  main() 
  14 {
  15   cellList    *cells;
  16   elementList *elements;
  17 
  18   bool selected = 0;
  19 
  20   /* check if something was selected at all */
  21   for(cells = layout->drawing->firstCell; cells != NULL; cells = cells->nextCell)
  22     {
  23       if(cells->thisCell != NULL)
  24         {
  25           for(elements = cells->thisCell->firstElement; elements != NULL; elements = elements->nextElement)
  26             {
  27               if(elements->thisElement != NULL)
  28                 if(elements->thisElement->select)
  29                   selected = 1;
  30             };
  31         };
  32     };
  33   
  34   if(!selected)
  35     layout->showMessage("Macro Help","To use this macro select one ore more polygons and the macro "+
  36                         "will place boxes over all horizontal and vertical segments.");
  37   else
  38     {
  39       double line_width = layout->getDouble("Input","Please input the line width:");
  40       double user_unit  = layout->drawing->userunits;
  41       bool first = true;
  42 
  43       /* from user units to internal units */
  44       line_width = line_width / user_unit;
  45 
  46       for(cells = layout->drawing->firstCell; cells != NULL; cells = cells->nextCell)
  47         {
  48           if(cells->thisCell != NULL)
  49             {
  50               for(elements = cells->thisCell->firstElement; elements != NULL; elements = elements->nextElement)
  51                 {
  52                   if(elements->thisElement != NULL)
  53                     if(elements->thisElement->select)
  54                       {
  55                         pointArray pa;
  56                         point p1,p2;
  57                         int x1,x2,y1,y2;
  58                         
  59                         int i;
  60                         int ln = elements->thisElement->layerNum;
  61                         
  62                         pa = elements->thisElement->getPoints();
  63                         
  64                         for(i=0;i<pa.size()-1;i++)
  65                           {
  66                             p1 = pa.point(i);
  67                             p2 = pa.point(i+1);
  68                             
  69                             x1 = p1.x();
  70                             y1 = p1.y();
  71                             
  72                             x2 = p2.x();
  73                             y2 = p2.y();
  74 
  75                             /* output a square at the beginning this is done, so that the next boxes can
  76                                be positioned, so that they don't overlap */
  77                             if(first)
  78                               {
  79                                 cells->thisCell->addBox(x1-line_width/2,y1-line_width/2,line_width,line_width,ln);
  80                                 first = 0;
  81                               };
  82 
  83                             
  84                             /* do we need to rotate the box? 
  85                                Not if two X values or two Y are the same... */
  86                             if(  (x1==x2) && (y1<y2))
  87                               cells->thisCell->addBox(x1-line_width/2,y1-line_width/2,line_width,(y2-y1),ln);
  88                             else if(  x1==x2 )
  89                               cells->thisCell->addBox(x1-line_width/2,y1+line_width/2,line_width,(y2-y1),ln);
  90                             else if(  (y1==y2)  && (x1<x2))
  91                               cells->thisCell->addBox(x1-line_width/2,y1-line_width/2,(x2-x1),line_width,ln);
  92                             else if(  y1==y2 )
  93                               cells->thisCell->addBox(x1+line_width/2,y1-line_width/2,(x2-x1),line_width,ln);
  94                             /* if box needs to be rotated */
  95                             /* problem: would need to rotate without deselecting everything else to be able to do this
  96                                haven't figured out how to do it at the moment 
  97                               {
  98                                 element *e,*n;
  99                                 double w = e->distance(p1,p2);
 100                                 double a = e->angle(p1,p2);
 101 
 102                                 n=cells->thisCell->addBox(x1-5/d,y1-5/d,w,10/d,ln);
 103                                 cells->thisCell->deselectAll();
 104                                 n->select=1;
 105                                 cells->thisCell->rotateSelect(a,p1);
 106                                 cells->thisCell->deselectAll();
 107                                 }
 108                             */
 109                           };
 110                         /* add last box */
 111                         cells->thisCell->addBox(x2-line_width/2,y2-line_width/2,line_width,line_width,ln);
 112                       };
 113                 };
 114             };
 115         }; /* end for loop over cells */
 116     }; /* end if selected */
 117 };
 118 
 119 /* Local Variables:    */
 120 /* mode: c             */
 121 /* End:                */  

See also


CategoryMacro


ExpandLineMacro (last edited 2011-02-28 14:01:43 by dslb-092-074-059-143)