the fair gds editor LayerCVSImport

Layer Import/Export in CVS format

Instead of storing the layer information in a macro as this feature does the below listed macro will store/read layer information in CVS format which can be edited by any spreadsheet software. Thanks to John for providing this macro!

Download: LayerDefinitions.layout

   1 #!/usr/bin/layout
   2 #name=LayerDefinitions
   3 #help=Save/Load/Reset current layer defintions
   4 
   5 //----------------------------------------------------
   6 // Utility routines to log variables to file
   7 //----------------------------------------------------
   8 void log_bool( string tag, bool bl, string eol, file *f ){
   9    string s="";
  10    if (tag.length()>0) {
  11       s=tag;
  12       s=s+",";
  13    }
  14    if (bl) {
  15       s=s+"true";
  16       }
  17    else {
  18       s=s+"false";
  19       }
  20    s=s+",";
  21    s=s+eol;
  22    f->write(s);
  23 }
  24 //----------------------------------------------------
  25 void log_str( string tag, string str, string eol, file *f ){
  26         string s="";
  27         if (tag.length()>0) {
  28                 s=tag;
  29                 s=s+",";
  30         }
  31         s=s+str;
  32         s=s+",";
  33         s=s+eol;
  34         f->write(s);
  35 }
  36 //----------------------------------------------------
  37 void log_int( string tag, int i, string eol, file *f ){
  38         string s="";
  39         if (tag.length()>0) {
  40                 s=tag;
  41                 s=s+",";
  42         }
  43         s=s+i;
  44         s=s+",";
  45         s=s+eol;
  46         f->write(s);
  47 }
  48 //----------------------------------------------------
  49 void log_dbl( string tag, double x, string eol, file *f ){
  50         string s="";
  51         if (tag.length()>0) {
  52                 s=tag;
  53                 s=s+",";
  54         }
  55         s=s+x;
  56         s=s+",";
  57         s=s+eol;
  58         f->write(s);
  59 }
  60 //----------------------------------------------------
  61 void log_pnt( string tag, point p, string eol, file *f ){
  62         string s="";
  63         if (tag.length()>0) {
  64                 s=tag;
  65                 s=s+",";
  66         }
  67         s=s+p.x();
  68         s=s+","+p.y();
  69         s=s+",";
  70         s=s+eol;
  71         f->write(s);
  72 }
  73 //----------------------------------------------------
  74 void log_pa( string tag, pointArray pa, string eol, file *f ){
  75         string s="";
  76         if (tag.length()>0) {
  77                 s=tag;
  78                 f->write(s);
  79         }
  80         string s1="";
  81         string s2="";
  82         int i;
  83         for (i=0; i<pa.size(); i++) {
  84                 s1=s1+","+pa.point(i).x();
  85                 s2=s2+","+pa.point(i).y();
  86         }
  87         s1=s1+eol;
  88         f->write(s1);
  89         s2=s2+eol;
  90         f->write(s2);
  91 }
  92 //----------------------------------------------------
  93 // Example usage:
  94 //----------------------------------------------------
  95 //void some_function( string aString, file *f){
  96 //      log_str( "Inside some_function", aString, "\n", f );
  97 //}
  98 
  99 //int main() {
 100 //      bool bRead=true;
 101 //      bool bWrite=false;
 102 //      file f;
 103 //      string f_name;
 104 
 105         // Open the file
 106 //      f_name="List.csv";
 107 //      f.filename=f_name;
 108 //      f.open(bWrite);         //open file for output
 109 //      log_str( "At main level", "some-string", "\n", &f );
 110 
 111         // random code
 112 //      some_function( "another-string", &f);
 113         
 114 //      f.write("Script-finished\n");
 115 //      layout->showStatus( "Script-finished" );
 116 //      f.close();                      // close file
 117 //      textEdit *te=layout->showTextEditor();
 118 //      te->open(f_name);
 119 //};
 120 //----------------------------------------------------
 121 void saveLayers( ){
 122         bool bRead=true;
 123         bool bWrite=false;
 124         file f;
 125         string f_name, s;
 126         int layNum, layStyle, layRed, layGreen, layBlue, layMapTo, layDType, lay3Dtop, lay3Dbot;
 127         string layName;
 128         bool layEnabled;
 129         // Open output file
 130         f_name="layerDefinitions.csv";
 131         f_name=layout->getText("Null Title","Definition file to load => ",f_name);
 132         f.filename=f_name;
 133         f.open(bWrite);         //open file for output
 134         log_str( "Current Layer Definitions:", "", "\n", &f );
 135         log_str( "", "layNum,layName,layStyle,layRed,layGreen,layBlue,layMapTo,layDType,layEnabled", "\n", &f );
 136 
 137         for (layNum=0; layNum<layers::displayedLayers; layNum++) {
 138                 layName  = layers::num[layNum].name;
 139                 layStyle = layers::num[layNum].getStyle();
 140                 layRed   = layers::num[layNum].red();
 141                 layGreen = layers::num[layNum].green();
 142                 layBlue  = layers::num[layNum].blue();
 143                 layMapTo = layers::num[layNum].mapToLayer;
 144                 layDType = layers::num[layNum].mapToDatatype;
 145                 layEnabled = layers::num[layNum].isEnabled();
 146 
 147                 if (layEnabled ) {
 148                         log_int("", layNum,    "", &f);
 149                         log_str("", layName,   "", &f);
 150                         log_int("", layStyle,  "", &f);
 151                         log_int("", layRed,    "", &f);
 152                         log_int("", layGreen,  "", &f);
 153                         log_int("", layBlue,   "", &f);
 154                         log_int("", layMapTo,   "", &f);
 155                         log_int("", layDType,   "", &f);
 156                         log_bool("", layEnabled, "\n", &f);
 157                 }
 158         }
 159         
 160         f.write("Script-finished\n");
 161         layout->showStatus( "Script-finished" );
 162         
 163         f.close();              // close file
 164 
 165         textEdit *te=layout->showTextEditor();
 166         te->open(f_name);
 167 }
 168 //----------------------------------------------------
 169 void loadLayers( ){
 170         bool bRead=true;
 171         bool bWrite=false;
 172         file f;
 173         int i;
 174         string f_name, s;
 175         stringList sl, sl_parms;
 176         int layNum, layStyle, layRed, layGreen, layBlue, layMapTo, layDType, lay3Dtop, lay3Dbot;
 177         string layName;
 178         bool layEnabled;
 179         // Read layer definitions from specified file
 180         f_name="layerDefinitions.csv";
 181         f_name=layout->getText("Null Title","Definition file to load => ",f_name);
 182         f.filename=f_name;
 183         f.open(bRead);          // open file for input
 184         s=f.read();                     // read entire file into string
 185         f.close();
 186         sl=s.split("\n");       // split file into lines
 187         for (i=0; i<sl.size(); i++) {
 188                 sl_parms=sl.at(i).split(",");   // split line into parms
 189 //              s = "Line "+ i;
 190 //              s = s+" <"+sl.at(i);
 191 //              s = s+"> # Parms = "+sl_parms.size();
 192 //              s = s+"\n";
 193 //              layout->showMessage("Null Title",s);
 194 //              layout->showMessage("Null Title","layName  <"+sl_parms.at(1)+"> " + "\n");
 195                 if ((sl_parms.size()==10) && (sl_parms.at(0)!="layNum")) {
 196 //                      Parm list: layNum,layName,layStyle,layRed,layGreen,layBlue,layMapTo,layDType,layEnabled
 197                         layNum                     = sl_parms.at(0).toInt();
 198                         layers::num[layNum].name   = sl_parms.at(1);
 199                         layers::num[layNum].setStyle(sl_parms.at(2).toInt());
 200                         layers::num[layNum].setColor(sl_parms.at(3).toInt(),sl_parms.at(4).toInt(),sl_parms.at(5).toInt());
 201                         layers::num[layNum].mapToLayer    = sl_parms.at(6).toInt();
 202                         layers::num[layNum].mapToDatatype = sl_parms.at(7).toInt();
 203                         if ((sl_parms.at(8)=="true") || (sl_parms.at(8)=="TRUE")) {
 204                                 layers::num[layNum].enable();
 205                                 }
 206                         else {
 207                                 layers::num[layNum].disable();
 208                                 }
 209                 }
 210         }
 211 }
 212 //----------------------------------------------------
 213 void resetLayers( ){
 214         bool bRead=true;
 215         bool bWrite=false;
 216         file f;
 217         string f_name, s;
 218         int layNum, layStyle, layRed, layGreen, layBlue, layMapTo, layDType, lay3Dtop, lay3Dbot;
 219         string layName;
 220         bool layEnabled;
 221 
 222         for (layNum=0; layNum<layers::displayedLayers; layNum++) {
 223                 layers::num[layNum].name   = layNum;
 224                 layers::num[layNum].mapToLayer    = layNum;
 225                 layers::num[layNum].mapToDatatype = -1;
 226                 layers::num[layNum].disable();
 227         }
 228 }
 229 //----------------------------------------------------
 230 //----------------------------------------------------
 231 int main() {
 232         bool bRead=true;
 233         bool bWrite=false;
 234         cell *aCell;
 235         cellList *cells;
 236         element *el;
 237         elementList *els;
 238         file f;
 239         int i;
 240         string cell_name, f_name, s, str;
 241         stringList cellNames, parentChild, sl, sl_parms;
 242         intList    cellCount;
 243         point p;
 244         pointArray pa,pb;
 245 
 246         layout->showMessage("Null Title","# of Layers =" + layers::displayedLayers);
 247         str=layout->getText("Null Title","Save/Load layer definitions => ","Save/Load/Reset");
 248 
 249         switch (str) {
 250           case "S"   :  
 251           case "Save":  saveLayers( );
 252                                         break;
 253           case "L"   :  
 254           case "Load":  loadLayers( );
 255                                         break;
 256           case "R"    : 
 257           case "Reset": resetLayers( );
 258                                         break;
 259           default:              break;
 260         }
 261 };

See also


CategoryMacro


LayerCVSImport (last edited 2014-11-01 12:29:47 by JurgenThies)