File: cmd-change-brd-width.ulp

package info (click to toggle)
eagle 4.16-5
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 36,508 kB
  • sloc: sh: 82; makefile: 32
file content (253 lines) | stat: -rw-r--r-- 6,773 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#usage "<qt>This ULP changes the wire width of certain signals and do have "
       "a wire width in between the minimum (minwidth) and maximum (maxwidth) values.<p>"
       "NameOff = 1 switches off the checking of net names.<p>"

string hilfe =
       "Dieses ULP ndert die Leiterbahnbreite abhaengig vom Signalnamen und "
       "der vorgegebenen min. max. Breite.<p>" +
       "! Mit NameOff kann die Netz-Namen-Ueberpruefung abgeschaltet werden.<p>";

//     "THIS PROGRAM IS PROVIDED AS IS AND WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED.</qt>"

// *  02.03.2005 alf@cadsoft.de

string help = usage;
if (language() == "de") help = hilfe;


int Gridval = 1;              // 1=mm 2=mil 3=inch    ***
                              // choose the value for the units you're working with
string grid_unit;

real changewidth =  0.3;     // gewuenschte Breite in ***
                             // enter desired width here

real minwidth    =  0.0;     // Auswahl-Min-Breite in ***
                             // minimum width and
real maxwidth    = 13.1;     // Auswahl-Max-Breite in ***
                             // maximum width of tracks that will be taken into consideration.

int NameOff = 0;       // 0 = Breite abhaengig vom Netznamen aendern
                       // 0 = change width by name
                       // 1 = Breite unabhaengig vom Netznamen aendern
                       // 1 = change width without name

string signals[]   = { "" };
string chsignals[] = { "" };
int    chngsig     = 0;
int    lastSigCh   = 0;
int decs;

string list;

string grid[]         = { "MIC",  "MM", "MIL", "INCH" };
real   maxwidthUnit[] = { 13100.0, 13.1, 516.0, 0.516 };

string Version = " Version 1.5";

int index[];
int x1[], y1[], x2[], y2[], layer[];
int usedlayer[];
int n = 1;


int found(string fnam) {
  int fnd = 0;
  do {
    if (chsignals[fnd] == fnam) {
      return 1;
      break;
    }
    ++fnd;
  } while (chsignals[fnd]);
  return 0;
}


real fwidth(real ww) {
  if (ww <= maxwidth && ww >= minwidth) return 1;
  return 0;
}


void disp(int l) {
  printf("DISPLAY NONE %d ;\n", l);
  return;
}

void clearlay() {
  for (int ly = 0; ly <= 255; ly++) usedlayer[ly] = 0;
  return;
}


void clearsig (int selct) {
  for (int r = selct; r < lastSigCh; r++) {
    chsignals[r] = chsignals[r + 1];
  }
  chsignals[r + 1] = "";
  if (lastSigCh) lastSigCh--;
  return;
}


void  AddList (string SigName) {
  int found = 0;
  for (int r = 0; r < lastSigCh; r++) {
    if (chsignals[r] == SigName) {
      found = 1;
      break;
    }
  }
  if (!found) {
    chsignals[r] = SigName;
    lastSigCh++;
  }
  return;
}


void menue() {
  int cs;
  int l;
  int Result = dlgDialog("Change wire with") {
    string slist[];
    dlgLabel(help);
    dlgSpacing(40);
    dlgGridLayout {
      dlgCell (0, 1) dlgSpacing(200);
      dlgCell (0, 5) dlgSpacing(200);
      dlgCell (1, 1) dlgLabel("&Signal list");
      dlgCell (2, 1) dlgComboBox(signals, chngsig);
      dlgCell (2, 3) dlgPushButton("&Add -->>") {
                       AddList(signals[chngsig]);
                     }
      dlgCell (1, 5) dlgLabel("Signals &to change");
      dlgCell (2, 5) dlgComboBox(chsignals, decs);
      dlgCell (2, 6) dlgPushButton("&Delete") {
                       clearsig(decs);
                     }
    }

    dlgStretch(1);
    dlgCheckBox("&Change without Signal name", NameOff);

    dlgHBoxLayout {
      dlgGroup("between wire width : " + grid_unit) {
        dlgHBoxLayout {
          dlgLabel("Mi&n. "); dlgRealEdit(minwidth, 0.0, maxwidthUnit[Gridval]);
          dlgLabel(" Ma&x. "); dlgRealEdit(maxwidth, minwidth, maxwidthUnit[Gridval]);
        }
      }
      dlgLabel(" new wire &width ");
      dlgRealEdit(changewidth);
      dlgStretch(1);
    }

    dlgHBoxLayout {
      dlgStretch(0);
      dlgPushButton("&OK") dlgAccept();
      dlgStretch(1);
      dlgPushButton("-Cancel") dlgReject();
      dlgStretch(0);
    }
    dlgStretch(0);
  };
  if (Result == 0) exit (0);
  return;
}


if (board) board(B) {
  int s = 0;
  B.signals(S) {
    signals[s] = S.name;
    s++;
  }
  Gridval = B.grid.unit;
  grid_unit = "Unit " + grid[Gridval];
  maxwidth = maxwidthUnit[Gridval];
  menue();

  clearlay();
  string file = filesetext(B.name, "chnwidth.scr");
  output (file, "wtD") {
    printf("# %s\n", Version);
    printf("# %s\n\n", EAGLE_SIGNATURE);
    printf("# exported from %s\n# at %s\n\n", B.name, t2string(time()) );
    printf("# This Script changed Wire Width between %.3f %s and %.3f %s to %.3f %s\n",
                   minwidth, grid[Gridval], maxwidth, grid[Gridval], changewidth, grid[Gridval]);

    printf("GRID %s FINEST;\n", grid[Gridval]);

    B.signals(S) {
      if (found(S.name) || NameOff) {
        real Wwidth;

        S.wires(W) {
          switch (Gridval) {
            case 0: Wwidth = u2mic(W.width);
                    break;

            case 1: Wwidth = u2mm(W.width);
                    break;

            case 2: Wwidth = u2mil(W.width);
                    break;

            case 3: Wwidth = u2inch(W.width);
                    break;
          }

          if(fwidth(Wwidth)) {
            x1[n] = W.x1;
            y1[n] = W.y1;
            x2[n] = W.x2;
            y2[n] = W.y2;
            layer[n] = W.layer;
            ++n;
          }
        }
      }
    }

    sort(n, index, layer);
    int dl = 0;
    for (int i = 1; i < n; ++i) {
      if(dl != layer[index[i]]) {
        dl = layer[index[i]];
        disp(dl);
        usedlayer[dl] = 1;
      }
      switch (Gridval) {
        case 0: printf("CHANGE WIDTH %.3f (%.3f %.3f);\n",
                changewidth, (u2mic(x1[index[i]]) + u2mic(x2[index[i]])) / 2,
                             (u2mic(y1[index[i]]) + u2mic(y2[index[i]])) / 2 );
                break;

        case 1: printf("CHANGE WIDTH %.3f (%.3f %.3f);\n",
                changewidth, (u2mm(x1[index[i]]) + u2mm(x2[index[i]])) / 2,
                             (u2mm(y1[index[i]]) + u2mm(y2[index[i]])) / 2 );
                break;

        case 2: printf("CHANGE WIDTH %.3f (%.3f %.3f);\n",
                changewidth, (u2mil(x1[index[i]]) + u2mil(x2[index[i]])) / 2,
                             (u2mil(y1[index[i]]) + u2mil(y2[index[i]])) / 2 );
                break;

        case 3: printf("CHANGE WIDTH %.3f (%.3f %.3f);\n",
                changewidth, (u2inch(x1[index[i]]) + u2inch(x2[index[i]])) / 2,
                             (u2inch(y1[index[i]]) + u2inch(y2[index[i]])) / 2 );
                break;
      }
    }
    printf("DISPLAY  ");
    for (int ly = 0; ly <= 255; ly++) {
      if( usedlayer[ly]) printf("%d ",ly);
    }
    printf(";\n");
  }
  exit ("SCRIPT '" + file + "';");
}
else dlgMessageBox("start this ULP in Board", "OK");