📄 statistic-lbr.ulp
字号:
#usage "<b>RUN Library statistics</b>\n"
"<p>"
"<author>Author: support@cadsoft.de</author>"
string Revision = "1.01"; // 2005.11.15 alf@cadsoft.de
string src_dev[];
string src_pac[];
string src_sym[];
string src_tec[];
string src_var[];
int cnt_variant[];
string srt_dev[];
string srt_pac[];
string srt_sym[];
string srt_tec[];
string srt_var[];
string srt_drills[];
int index_dev[];
int index_pac[];
int index_sym[];
int index_tec[];
int index_var[];
int index_dril[];
int drills[];
int cntdril[];
int cntdev = 0;
int cntpac = 0;
int cntsym = 0;
int cnttec = 0;
int cntvar = 0;
int cntdrills = 0;
int used_pac[];
int used_sym[];
string unUsed_pac[];
string unUsed_sym[];
string usedlabel = " ";
string used[] = { "used in Devices\tcnt" };
int cntclearused = 0; // Error in dlgListView,
// clear all strings in array befor use dlgListView
// if used a second time less string entry
int cntUnUsed_pac = 0;
int cntUnUsed_sym = 0;
int us, up;
string PackInfo = " \n \n \n ";
string SymbolInfo = " \n \n";
string used_layers[] = {"" };
int cnt_used_layers = 0;
string user_layers[] = {"" };
int cnt_user_layers = 0;
// *** --- Functions --- ***
void checkVariant(string var) {
int f = 0;
for (int n = 0; n <= cntvar; n++) {
if (src_var[n] == var) {
f = 1;
break;
}
}
if (f) return;
src_var[cntvar] = var;
cntvar++;
return;
}
void checkTechno(string tech) {
string techno[];
int t = strsplit(techno, tech, ' ');
for (int xt = 0; xt < t; xt++) {
int notf = 1;
for (int n = 0; n <= cnttec; n++) {
if (src_tec[n] == techno[xt]) {
notf = 0;
break;
}
}
if (notf) {
src_tec[cnttec] = techno[xt];
cnttec++;
}
}
return;
}
void checkUsedPac(string pac) {
int f = 0;
for (int n = 0; n <= cntpac; n++) {
if (src_pac[n] == pac) {
used_pac[n]++;
return;
}
}
dlgMessageBox("Pac not found!", "OK");
}
void checkUsedSym(string sym) {
int f = 0;
for (int n = 0; n <= cntsym; n++) {
if (src_sym[n] == sym) {
used_sym[n]++;
return;
}
}
dlgMessageBox("Sym not found!", "OK");
}
// ** ------------------------ **
void checkDrill(int drill) {
int nof = 1;
for (int n = 0; n < cntdrills; n++) {
if (drills[n] == drill) {
nof = 0;
cntdril[n]++;
break;
}
}
if (nof) {
drills[cntdrills] = drill;
cntdril[cntdrills]++;
cntdrills++;
}
return;
}
int countPAD(UL_PACKAGE P) {
int Pads;
P.contacts(C) {
if (C.pad) {
Pads++;
}
}
return Pads;
}
int countSMD(UL_PACKAGE P) {
int Smds;
P.contacts(C) {
if (C.smd) {
Smds++;
}
}
return Smds;
}
int countHOLE(UL_PACKAGE P) {
int Holes;
P.holes(H) {
Holes++;
}
return Holes;
}
int countPIN(UL_SYMBOL S) {
int Pins;
S.pins(P) {
Pins++;
}
return Pins;
}
int newUsed(string use_name) {
int new = 1;
int n = 0;
do {
if (used[n] == use_name) {
new = 0;
break;
}
n++;
} while(used[n]);
return new;
}
void syminfo(string Name_and_count) {
string symbolname[];
int n = strsplit(symbolname, Name_and_count, '\t');
usedlabel = "<b>" + symbolname[0]+".SYM</b>";
used[0] = "used in Devices\tcnt";
int usedcount = 1;
used[usedcount] = "";
for (int u = 1; u < cntclearused; u++) used[u] = ""; // while error in dlgListView()
// clear all strings in array 03.05.2005 alf
library(L) {
L.symbols(S) {
if (S.name == symbolname[0]) {
sprintf(SymbolInfo, "<b>%s</b><br>%3d Pin in symbol", S.name, countPIN(S) );
}
}
L.devicesets(DS) {
int cntinuse;
int new = 0;
DS.gates(G) {
if (G.symbol.name == symbolname[0]) {
if (newUsed(DS.name)) {
used[usedcount] = DS.name;
usedcount++;
used[usedcount] = "";
new++;
}
cntinuse++;
}
}
if (new) {
string h;
sprintf(h, "\t%d", cntinuse);
used[usedcount-1] += h;
}
}
}
used[usedcount] = "";
if (cntclearused < usedcount) cntclearused = usedcount;
return;
}
void pacinfo(string Name_and_count) {
string packname[];
int n = strsplit(packname, Name_and_count, '\t');
usedlabel = "<b>" + packname[0]+".PAC</b>";
used[0] = "used in Devices\tcnt";
int usedcount = 1;
used[usedcount] = "";
for (int u = 1; u < cntclearused; u++) used[u] = ""; // while error in dlgListView()
// clear all strings in array 03.05.2005 alf
library(L) {
L.packages(P) {
if (P.name == packname[0]) {
sprintf(PackInfo, "<b>%s</b><br>%3d Pad<br>%3d Smd<br>%3d Hole", P.name, countPAD(P), countSMD(P), countHOLE(P) );
}
}
L.devicesets(DS) {
int cntinuse;
int new = 0;
DS.devices(D) {
if (D.package) {
if (D.package.name == packname[0]) {
if (newUsed(DS.name)) {
used[usedcount] = DS.name;
usedcount++;
used[usedcount] = "";
new++;
}
cntinuse++;
}
}
}
if (new) {
string h;
sprintf(h, "\t%d", cntinuse);
used[usedcount-1] += h;
}
}
}
used[usedcount] = "";
if (cntclearused < usedcount) cntclearused = usedcount;
return;
}
void drillinfo(int Drill) {
sprintf(usedlabel, "<b>Drill %.4f mm</b>", u2mm(Drill));
used[0] = "used in Package\tcnt";
int usedcount = 1;
used[usedcount] = "";
for (int u = 1; u < cntclearused; u++) used[u] = ""; // while error in dlgListView()
// clear all strings in array 03.05.2005 alf
library(L) {
L.packages(P) {
int cntinuse;
int new = 0;
P.contacts(C) {
if (C.pad) {
if (C.pad.drill == Drill) {
if (newUsed(P.name)) {
used[usedcount] = P.name;
usedcount++;
used[usedcount] = "";
new++;
}
cntinuse++;
}
}
}
if (new) {
string h;
sprintf(h, "\t%d", cntinuse);
used[usedcount-1] += h;
}
}
}
used[usedcount] = "";
if (cntclearused < usedcount) cntclearused = usedcount;
return;
}
void collectLbr(UL_LIBRARY L) {
L.packages(P) {
src_pac[cntpac] = P.name ;
cntpac++;
src_pac[cntpac] = "";
P.contacts(C) {
if (C.pad) {
checkDrill(C.pad.drill);
}
}
}
L.symbols(S) {
src_sym[cntsym] = S.name ;
cntsym++;
src_sym[cntsym] = "";
}
L.devicesets(DS) {
src_dev[cntdev] = DS.name ;
DS.devices(D) {
checkVariant(D.name);
checkTechno(D.technologies);
if (D.package) {
checkUsedPac(D.package.name);
}
cnt_variant[cntdev]++;
}
cntdev++;
src_dev[cntdev] = "";
DS.gates(G) {
checkUsedSym(G.symbol.name);
}
}
return;
}
void sort_data(void) {
int n;
string s;
sort (cntdev, index_dev, src_dev, cnt_variant); // 2005.11.15 alf
sort (cntvar, index_var, src_var);
sort (cnttec, index_tec, src_tec);
sort (cntpac, index_pac, src_pac, used_pac);
sort (cntsym, index_sym, src_sym, used_sym);
sort (cntdrills, index_dril, drills, cntdril);
for (n = 0; n < cntdev; n++) {
srt_dev[n] = src_dev[index_dev[n]];
}
for (n = 0; n < cntvar; n++) {
srt_var[n] = src_var[index_var[n]];
}
for (n = 0; n < cnttec; n++) {
srt_tec[n] = src_tec[index_tec[n]];
}
for (n = 0; n < cntpac; n++) {
if (used_pac[index_pac[n]]) sprintf(s, "\t%d", used_pac[index_pac[n]]);
else {
s = "\t -";
unUsed_pac[cntUnUsed_pac] = src_pac[index_pac[n]];
cntUnUsed_pac++;
}
srt_pac[n] = src_pac[index_pac[n]] + s;
}
for (n = 0; n < cntsym; n++) {
if (used_sym[index_sym[n]]) sprintf(s, "\t%d", used_sym[index_sym[n]]);
else {
s = "\t -";
unUsed_sym[cntUnUsed_sym] = src_sym[index_sym[n]];
cntUnUsed_sym++;
}
srt_sym[n] = src_sym[index_sym[n]] + s;
}
for (n = 0; n < cntdrills; n++) {
sprintf(srt_drills[n], "%.4f\t%d", u2mm(drills[index_dril[n]]), cntdril[index_dril[n]]);
}
return;
}
//
void menue_1(void) {
int seldev = 0;
int seltec = 0;
int selvar = 0;
int selsym = -1;
int selpac = -1;
int seldril = -1;
int selused = 0;
string ndev, nvar, ntec, npac, nsym, ndril, cupac, cusym;
string usedVariants = " select Device";
sprintf(ndev, "%3d", cntdev);
sprintf(nvar, "%3d", cntvar);
sprintf(ntec, "%3d", cnttec);
sprintf(npac, "%3d", cntpac);
sprintf(nsym, "%3d", cntsym);
sprintf(ndril, "%3d", cntdrills);
sprintf(cupac, "%3d", cntUnUsed_pac);
sprintf(cusym, "%3d", cntUnUsed_sym);
int listsort = 0;
int sellay;
int Result = dlgDialog("Library statistic") {
dlgHBoxLayout {
dlgVBoxLayout dlgSpacing(400);
dlgGridLayout {
dlgCell(0,0) { dlgLabel(ndev); dlgLabel("&Devices"); }
dlgCell(0,1) dlgComboBox(srt_dev, seldev) { sprintf(usedVariants, "%d Variant ", cnt_variant[seldev]); }
dlgCell(0,2) dlgLabel(usedVariants, 1);
dlgCell(1,0) { dlgLabel(nvar); dlgLabel("&Variants"); }
dlgCell(1,1) dlgComboBox(srt_var, selvar);
dlgCell(0,2) dlgSpacing(100);
dlgCell(2,0) { dlgLabel(ntec); dlgLabel("&Technoligies"); }
dlgCell(2,1) dlgComboBox(srt_tec, seltec);
dlgCell(2,2) dlgSpacing(10);
dlgCell(3,0) dlgLabel("&Used Layers");
dlgCell(3,1) dlgComboBox(used_layers, sellay);
if (cnt_user_layers) {
dlgCell(4,1) dlgLabel("<font color = red>Layer user defined</font>");
dlgCell(5,1) dlgComboBox(user_layers, sellay);
}
dlgCell(6,1) dlgVBoxLayout {
dlgLabel(usedlabel, 1);
dlgListView("", used, selused, listsort);
}
dlgCell(7,0) dlgLabel("Unused &Package");
dlgCell(7,1) dlgComboBox(unUsed_pac, up);
dlgCell(7,2) dlgLabel(cupac);
dlgCell(8,0) dlgLabel("Unused &Symbol");
dlgCell(8,1) dlgComboBox(unUsed_sym, us);
dlgCell(8,2) dlgLabel(cusym);
}
dlgVBoxLayout {
dlgLabel("Symbols " + nsym);
dlgListView("Symbol\tUsed", srt_sym, selsym) {
syminfo(srt_sym[selsym]);
selpac = -1;
seldril = -1;
}
dlgLabel(SymbolInfo, 1);
}
dlgVBoxLayout {
dlgLabel("Packages " + npac);
dlgListView("Package\tUsed", srt_pac, selpac) {
pacinfo(srt_pac[selpac]);
selsym = -1;
seldril = -1;
}
dlgLabel(PackInfo, 1);
}
dlgVBoxLayout {
dlgLabel("Drills " + ndril);
dlgListView("Drill mm\tUsed", srt_drills, seldril) {
drillinfo(drills[index_dril[seldril]]);
selsym = -1;
selpac = -1;
}
}
dlgVBoxLayout dlgSpacing(300);
}
dlgSpacing(12);
dlgHBoxLayout {
dlgPushButton("+&OK") dlgAccept();
dlgStretch(1);
}
};
return ;
}
// main
if (library) library(L) {
L.layers(LAY) {
if (LAY.used) {
sprintf(used_layers[cnt_used_layers], "%d %s", LAY.number, LAY.name);
cnt_used_layers++;
}
if (LAY.number >= 100) {
sprintf(user_layers[cnt_user_layers], "%d %s", LAY.number, LAY.name);
cnt_user_layers++;
}
}
collectLbr(L);
sort_data();
menue_1();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -