#usage "functions for Eagle3D v1.05"
"
"
"Author: Matthias Weißer matthias@matwei.de"
//Wandelt den Widerstandswert in eine Dreifarbkombination zur Übergabe an DR
//Widerstanswert müßen angegeben werden als Zahlen bzw. ZahlenBuchstabenkombination
//100 = 100Ohm = Braun,Schwarz,Braun
//4k7 = 4,7kOhm = Gelb,Violett,Rot
//12k = 12000Ohm = Braun,Rot,Orange
//1M = 1000000Ohm = Braun,Schwarz,Grün
//1R2 = 1,2Ohm = Braun,Rot,Gold
string rval2color(string val)
{
string out;
string temp[];
int i,j,k;
real l;
//Dezimaltrennzeichen
k = strchr(val, ',');
if(k != -1) val[k] = '.';
//Großschreibung
val = strupr(val);
//Dezimaltrennzeichen für R
k = strchr(val, 'R');
if(k != -1) val[k] = '.';
//Darstellung des Widerstandswert in 100tel Ohm
if(strchr(val,'.') != -1)
{
strsplit(temp, val, '.');
i = strtol(temp[0]);
i*=100;
j=(strtol(temp[1])*10);
if(j>100) j/=10;
i+=j;
k=0;
if(strchr(temp[1],'K') != -1) k=3;
if(strchr(temp[1],'M') != -1) k=6;
}
else if(strchr(val,'K') != -1)
{
strsplit(temp, val, 'K');
i = strtol(temp[0]);
i*=100;
i+=(strtol(temp[1])*10);
k=3;
}
else if(strchr(val,'M') != -1)
{
strsplit(temp, val, 'M');
i = strtol(temp[0]);
i*=100;
i+=(strtol(temp[1])*10);
k=6;
}
else
{
i = strtol(val);
i*=100;
k=0;
}
j=i;
while(j>=10) j/=10;
switch(j)
{
case 0: sprintf(temp[0],"texture{pigment{Black}finish{phong 0.2}}"); break;
case 1: sprintf(temp[0],"texture{pigment{DarkBrown}finish{phong 0.2}}"); break;
case 2: sprintf(temp[0],"texture{pigment{Red*0.7}finish{phong 0.2}}"); break;
case 3: sprintf(temp[0],"texture{pigment{Orange}finish{phong 0.2}}"); break;
case 4: sprintf(temp[0],"texture{pigment{Yellow}finish{phong 0.2}}"); break;
case 5: sprintf(temp[0],"texture{pigment{Green*0.7}finish{phong 0.2}}"); break;
case 6: sprintf(temp[0],"texture{pigment{Blue}finish{phong 0.2}}"); break;
case 7: sprintf(temp[0],"texture{pigment{Violet*1.2}finish{phong 0.2}}"); break;
case 8: sprintf(temp[0],"texture{pigment{Gray45}finish{phong 0.2}}"); break;
case 9: sprintf(temp[0],"texture{pigment{White}finish{phong 0.2}}"); break;
default: sprintf(temp[0],"texture{pigment{checker Black White}finish{phong 0.2}}"); break;
}
j=i;
while(j>=100) j/=10;
j%=10;
switch(j)
{
case 0: sprintf(temp[1],"texture{pigment{Black}finish{phong 0.2}}"); break;
case 1: sprintf(temp[1],"texture{pigment{DarkBrown}finish{phong 0.2}}"); break;
case 2: sprintf(temp[1],"texture{pigment{Red*0.7}finish{phong 0.2}}"); break;
case 3: sprintf(temp[1],"texture{pigment{Orange}finish{phong 0.2}}"); break;
case 4: sprintf(temp[1],"texture{pigment{Yellow}finish{phong 0.2}}"); break;
case 5: sprintf(temp[1],"texture{pigment{Green*0.7}finish{phong 0.2}}"); break;
case 6: sprintf(temp[1],"texture{pigment{Blue}finish{phong 0.2}}"); break;
case 7: sprintf(temp[1],"texture{pigment{Violet*1.2}finish{phong 0.2}}"); break;
case 8: sprintf(temp[1],"texture{pigment{Gray45}finish{phong 0.2}}"); break;
case 9: sprintf(temp[1],"texture{pigment{White}finish{phong 0.2}}"); break;
default: sprintf(temp[1],"texture{pigment{checker Black White}finish{phong 0.2}}"); break;
}
l = real(i)/100;
l*= pow(10,k);
if(l<1) sprintf(temp[2],"texture {T_Silver_5E finish{reflection 0.1}}");
else if(l<10) sprintf(temp[2],"texture {T_Gold_5C finish{reflection 0.1}}");
else if(l<100) sprintf(temp[2],"texture{pigment{Black}finish{phong 0.2}}");
else if(l<1000) sprintf(temp[2],"texture{pigment{DarkBrown}finish{phong 0.2}}");
else if(l<10000) sprintf(temp[2],"texture{pigment{Red*0.7}finish{phong 0.2}}");
else if(l<100000) sprintf(temp[2],"texture{pigment{Orange}finish{phong 0.2}}");
else if(l<1000000) sprintf(temp[2],"texture{pigment{Yellow}finish{phong 0.2}}");
else if(l<10000000) sprintf(temp[2],"texture{pigment{Green*0.7}finish{phong 0.2}}");
else if(l<100000000) sprintf(temp[2],"texture{pigment{Blue}finish{phong 0.2}}");
else if(l<1000000000) sprintf(temp[2],"texture{pigment{Violet*1.2}finish{phong 0.2}}");
else if(l<10000000000.0) sprintf(temp[2],"texture{pigment{Gray45}finish{phong 0.2}}");
else if(l<100000000000.0) sprintf(temp[2],"texture{pigment{White}finish{phong 0.2}}");
else if(l<1000000000000.0) sprintf(temp[2],"texture{pigment{checker Black White}finish{phong 0.2}}");
sprintf(out,"%s,%s,%s",temp[0],temp[1],temp[2]);
return out;
}
//Wandelt den Widerstandswert in eine Dreizahlkombination zur Übergabe an SR 0402,0603 usw.
//Widerstanswert müßen angegeben werden als Zahlen bzw. ZahlenBuchstabenkombination
//100 = 100Ohm = 101
//12k = 12000Ohm = 123
//1M = 1000000Ohm = 105
//1R2 = 1,2Ohm = 1R2
string rval2rcde(string val)
{
string out;
string temp[];
int i,j,k;
real l;
//Dezimaltrennzeichen
k = strchr(val, ',');
if(k != -1) val[k] = '.';
//Großschreibung
val = strupr(val);
//Dezimaltrennzeichen für R
k = strchr(val, 'R');
if(k != -1) val[k] = '.';
//Darstellung des Widerstandswert in 100tel Ohm
if(strchr(val,'.') != -1)
{
strsplit(temp, val, '.');
i = strtol(temp[0]);
i*=100;
j=(strtol(temp[1])*10);
if(j>100) j/=10;
i+=j;
k=0;
if(strchr(temp[1],'K') != -1) k=3;
if(strchr(temp[1],'M') != -1) k=6;
}
else if(strchr(val,'K') != -1)
{
strsplit(temp, val, 'K');
i = strtol(temp[0]);
i*=100;
i+=(strtol(temp[1])*10);
k=3;
}
else if(strchr(val,'M') != -1)
{
strsplit(temp, val, 'M');
i = strtol(temp[0]);
i*=100;
i+=(strtol(temp[1])*10);
k=6;
}
else
{
i = strtol(val);
i*=100;
k=0;
}
j=i;
while(j>=10) j/=10;
switch(j)
{
case 0: sprintf(temp[0],"0"); break;
case 1: sprintf(temp[0],"1"); break;
case 2: sprintf(temp[0],"2"); break;
case 3: sprintf(temp[0],"3"); break;
case 4: sprintf(temp[0],"4"); break;
case 5: sprintf(temp[0],"5"); break;
case 6: sprintf(temp[0],"6"); break;
case 7: sprintf(temp[0],"7"); break;
case 8: sprintf(temp[0],"8"); break;
case 9: sprintf(temp[0],"9"); break;
default: sprintf(temp[0],"x"); break;
}
j=i;
if(j>10) while(j>=100) j/=10; else j*=10;
j%=10;
switch(j)
{
case 0: sprintf(temp[1],"0"); break;
case 1: sprintf(temp[1],"1"); break;
case 2: sprintf(temp[1],"2"); break;
case 3: sprintf(temp[1],"3"); break;
case 4: sprintf(temp[1],"4"); break;
case 5: sprintf(temp[1],"5"); break;
case 6: sprintf(temp[1],"6"); break;
case 7: sprintf(temp[1],"7"); break;
case 8: sprintf(temp[1],"8"); break;
case 9: sprintf(temp[1],"9"); break;
default: sprintf(temp[1],"x"); break;
}
if((i<1000)&&(k==0))
{
temp[2]=temp[1];
temp[1]="R";
}
else
{
l = real(i)/100;
l*= pow(10,k);
if(l<1) sprintf(temp[2],"x");
else if(l<10) sprintf(temp[2],"x");
else if(l<100) sprintf(temp[2],"0");
else if(l<1000) sprintf(temp[2],"1");
else if(l<10000) sprintf(temp[2],"2");
else if(l<100000) sprintf(temp[2],"3");
else if(l<1000000) sprintf(temp[2],"4");
else if(l<10000000) sprintf(temp[2],"5");
else if(l<100000000) sprintf(temp[2],"6");
else if(l<1000000000) sprintf(temp[2],"7");
else if(l<10000000000.0) sprintf(temp[2],"8");
else if(l<100000000000.0) sprintf(temp[2],"9");
else if(l<1000000000000.0) sprintf(temp[2],"x");
}
sprintf(out,"%s%s%s",temp[0],temp[1],temp[2]);
return out;
}
//Gibt einen formatierten String zurück der eine Linie zeichnen kann
//erwartet Angaben in units
//c_x1 und c_x2 erzeugen Abschlußzylinder wenn 1
string create_line(int ix1, int iy1, int ix2, int iy2, int iwid, real t, real dis, int c_x1, int c_x2)
{
string out,tmp;
real x1 = u2mm(ix1);
real x2 = u2mm(ix2);
real y1 = u2mm(iy1);
real y2 = u2mm(iy2);
real width = u2mm(iwid);
real angel,length;
if(c_x1==1) sprintf(out,"cylinder{<0,0,0><0,%f,0>%f translate<%f,%f,%f>}\n",t,width/2,x1,dis,y1);
if(c_x2==1) sprintf(tmp,"cylinder{<0,0,0><0,%f,0>%f translate<%f,%f,%f>}\n",t,width/2,x2,dis,y2);
out=out+tmp;
if(x1<%f,%f,%f> rotate<0,%f,0> translate<%f,%f,%f> }\n",-width/2,length,t,width/2,angel,x1,dis,y1);
}
else if(x2<%f,%f,%f> rotate<0,%f,0> translate<%f,%f,%f> }\n",-width/2,length,t,width/2,angel,x2,dis,y2);
}
else if(x1==x2)
{
if(y1<%f,%f,%f> rotate<0,%f,0> translate<%f,%f,%f> }\n",-width/2,length,t,width/2,angel,x2,dis,y2);
}
return out+tmp;
}
//Gibt einen formatierten String zurück der einen ARC zeichnen kann
//erwartet Angaben in units
//c_x1 und c_x2 erzeugen Abschlußzylinder wenn 1
string create_arc(int xc, int yc, int r, int w, real a1, real a2, real t, real dis, int c_x1, int c_x2)
{
string out,tmp;
real i;
for(i=a1;i,<%f,%f,%f> translate<%f,0,0> rotate<0,%f,0> translate<%f,0,%f>}\n",
out,
u2mm(w/2),
u2mm(r)*3.14*2/(a2-a1)/2,
u2mm(w/2),
t,
u2mm(r)*6.28/(a2-a1)/2,
u2mm(r),
-i,
u2mm(xc),u2mm(yc));
}
return out;
}
//Ersetzt alle Zeichen in str die den einzelnen Zeichen aus rpl entsprechen mit chr
string strreplace(string str, string rpl, char chr)
{
int i,j;
for(i=0;iµ",'_');
if((in[0]>='1')&&(in[0]<='9')) in[0] = 'Z';
return in;
}
int is_num_in_str(string a,int n)
{
string b[];
int i,j;
j = strsplit(b, a, ',');
for(i=0;i=ver1)&&
(u2mm(val1)<=ver2)&&
(u2mm(val2)>=ver1)&&
(u2mm(val2)<=ver2)) return 1;
else return 0;
}
//Berechnet die Entfernung zwischen zwei Punkten
real calc_distance(int x1, int y1, int x2, int y2)
{
real dx = real(x1)-real(x2);
real dy = real(y1)-real(y2);
return sqrt(dx*dx + dy*dy);
}
//Erzeugt ein prism-Objekt aus dem übergebenen UL_BOARD
string make_prism_from_board_layer(UL_BOARD B, int layer, int precision, real lower, real upper, string texture)
{
string out;
int i=0; //Alle Eckpunkte inkl. ARC-Segmente
int j=0; //Gesamtgeraden (Arc behandelt als normale Gerade)
int k,l;
real x1,x2;
B.wires(W)
{
if(W.layer == layer)
{
i+=2;
j++;
if(W.arc) i+=precision-1;
}
}
sprintf(out,"%sprism{%f,%f,%d\n",out,lower,upper,i);
//Array in dem die bearbeiteten Segmente für den Boardumriss eingetragen werden
int processed_board_segments[];
for(k=0;k-<%f,0,%f>,<0,-%f,0>)+<%f,0,%f>).x",out,u2mm(W.x1),u2mm(W.y1),u2mm(W.arc.xc),u2mm(W.arc.yc), x2, u2mm(W.arc.xc),u2mm(W.arc.yc));
sprintf(out,"%s,(vrotate(<%f,0,%f>-<%f,0,%f>,<0,-%f,0>)+<%f,0,%f>).z>\n",out,u2mm(W.x1),u2mm(W.y1),u2mm(W.arc.xc),u2mm(W.arc.yc), x2, u2mm(W.arc.xc),u2mm(W.arc.yc));
}
else
{
sprintf(out,"%s<(vrotate(<%f,0,%f>-<%f,0,%f>,<0,%f,0>)+<%f,0,%f>).x",out,u2mm(W.x1),u2mm(W.y1),u2mm(W.arc.xc),u2mm(W.arc.yc), x2, u2mm(W.arc.xc),u2mm(W.arc.yc));
sprintf(out,"%s,(vrotate(<%f,0,%f>-<%f,0,%f>,<0,%f,0>)+<%f,0,%f>).z>\n",out,u2mm(W.x1),u2mm(W.y1),u2mm(W.arc.xc),u2mm(W.arc.yc), x2, u2mm(W.arc.xc),u2mm(W.arc.yc));
}
}
}
else
{
sprintf(out,"%s<%f,%f>",out,u2mm(W.x1),u2mm(W.y1));
}
sprintf(out,"%s<%f,%f>",out,u2mm(W.x2),u2mm(W.y2));
cur_x=W.x2;
cur_y=W.y2;
}
else
{
if(W.arc)
{
for(i=0;i-<%f,0,%f>,<0,%f,0>)+<%f,0,%f>).x",out,u2mm(W.x2),u2mm(W.y2),u2mm(W.arc.xc),u2mm(W.arc.yc), x2, u2mm(W.arc.xc),u2mm(W.arc.yc));
sprintf(out,"%s,(vrotate(<%f,0,%f>-<%f,0,%f>,<0,%f,0>)+<%f,0,%f>).z>\n",out,u2mm(W.x2),u2mm(W.y2),u2mm(W.arc.xc),u2mm(W.arc.yc), x2, u2mm(W.arc.xc),u2mm(W.arc.yc));
}
else
{
sprintf(out,"%s<(vrotate(<%f,0,%f>-<%f,0,%f>,<0,-%f,0>)+<%f,0,%f>).x",out,u2mm(W.x2),u2mm(W.y2),u2mm(W.arc.xc),u2mm(W.arc.yc), x2, u2mm(W.arc.xc),u2mm(W.arc.yc));
sprintf(out,"%s,(vrotate(<%f,0,%f>-<%f,0,%f>,<0,-%f,0>)+<%f,0,%f>).z>\n",out,u2mm(W.x2),u2mm(W.y2),u2mm(W.arc.xc),u2mm(W.arc.yc), x2, u2mm(W.arc.xc),u2mm(W.arc.yc));
}
}
}
else
{
sprintf(out,"%s<%f,%f>",out,u2mm(W.x2),u2mm(W.y2));
}
sprintf(out,"%s<%f,%f>",out,u2mm(W.x1),u2mm(W.y1));
cur_x=W.x1;
cur_y=W.y1;
}
sprintf(out,"%s\n",out);
processed_board_segments[cur_segment] = 1;
break;
}
}
l++;
}
}
sprintf(out,"%s%s}\n",out,texture);
return out;
}
//Erzeugt ein prism-Objekt aus dem übergebenen UL_PACKAGE
string make_prism_from_package_layer(UL_PACKAGE P, int layer, int precision, real lower, real upper, string texture)
{
string out;
int i=0; //Alle Eckpunkte inkl. ARC-Segmente
int j=0; //Gesamtgeraden (Arc behandelt als normale Gerade)
int k,l;
real x1,x2;
P.wires(W)
{
if(W.layer == layer)
{
i+=2;
j++;
if(W.arc) i+=precision-1;
}
}
if(j<3)
{
return "";
}
sprintf(out,"%sprism{%f,%f,%d\n",out,lower,upper,i);
//Array in dem die bearbeiteten Segmente für den Boardumriss eingetragen werden
int processed_board_segments[];
for(k=0;k-<%f,0,%f>,<0,-%f,0>)+<%f,0,%f>).x",out,u2mm(W.x1),u2mm(W.y1),u2mm(W.arc.xc),u2mm(W.arc.yc), x2, u2mm(W.arc.xc),u2mm(W.arc.yc));
sprintf(out,"%s,(vrotate(<%f,0,%f>-<%f,0,%f>,<0,-%f,0>)+<%f,0,%f>).z>\n",out,u2mm(W.x1),u2mm(W.y1),u2mm(W.arc.xc),u2mm(W.arc.yc), x2, u2mm(W.arc.xc),u2mm(W.arc.yc));
}
else
{
sprintf(out,"%s<(vrotate(<%f,0,%f>-<%f,0,%f>,<0,%f,0>)+<%f,0,%f>).x",out,u2mm(W.x1),u2mm(W.y1),u2mm(W.arc.xc),u2mm(W.arc.yc), x2, u2mm(W.arc.xc),u2mm(W.arc.yc));
sprintf(out,"%s,(vrotate(<%f,0,%f>-<%f,0,%f>,<0,%f,0>)+<%f,0,%f>).z>\n",out,u2mm(W.x1),u2mm(W.y1),u2mm(W.arc.xc),u2mm(W.arc.yc), x2, u2mm(W.arc.xc),u2mm(W.arc.yc));
}
}
}
else
{
sprintf(out,"%s<%f,%f>",out,u2mm(W.x1),u2mm(W.y1));
}
sprintf(out,"%s<%f,%f>",out,u2mm(W.x2),u2mm(W.y2));
cur_x=W.x2;
cur_y=W.y2;
}
else
{
if(W.arc)
{
for(i=0;i-<%f,0,%f>,<0,%f,0>)+<%f,0,%f>).x",out,u2mm(W.x2),u2mm(W.y2),u2mm(W.arc.xc),u2mm(W.arc.yc), x2, u2mm(W.arc.xc),u2mm(W.arc.yc));
sprintf(out,"%s,(vrotate(<%f,0,%f>-<%f,0,%f>,<0,%f,0>)+<%f,0,%f>).z>\n",out,u2mm(W.x2),u2mm(W.y2),u2mm(W.arc.xc),u2mm(W.arc.yc), x2, u2mm(W.arc.xc),u2mm(W.arc.yc));
}
else
{
sprintf(out,"%s<(vrotate(<%f,0,%f>-<%f,0,%f>,<0,-%f,0>)+<%f,0,%f>).x",out,u2mm(W.x2),u2mm(W.y2),u2mm(W.arc.xc),u2mm(W.arc.yc), x2, u2mm(W.arc.xc),u2mm(W.arc.yc));
sprintf(out,"%s,(vrotate(<%f,0,%f>-<%f,0,%f>,<0,-%f,0>)+<%f,0,%f>).z>\n",out,u2mm(W.x2),u2mm(W.y2),u2mm(W.arc.xc),u2mm(W.arc.yc), x2, u2mm(W.arc.xc),u2mm(W.arc.yc));
}
}
}
else
{
sprintf(out,"%s<%f,%f>",out,u2mm(W.x2),u2mm(W.y2));
}
sprintf(out,"%s<%f,%f>",out,u2mm(W.x1),u2mm(W.y1));
cur_x=W.x1;
cur_y=W.y1;
}
sprintf(out,"%s\n",out);
processed_board_segments[cur_segment] = 1;
break;
}
}
l++;
}
}
sprintf(out,"%s%s}\n",out,texture);
return out;
}
//Erzeugt ein Gehäuse aus den übergebenen Layern als union{prism{} prism{} ...}
string create_case_from_layers_in_element(UL_ELEMENT E, string layers, real pcb_height)
{
string dbg;
string out;
string layer_arr[];
int layer_numbers[];
int num_layers;
int i;
int object=0;
layers = strreplace(layers," ,;.",'#');
num_layers = strsplit(layer_arr, layers, '#');
//Anzahl zu bearbeitender Layer ermitteln
for(i=0;i0.0) return 0.0;
else return d;
}
real deg2rad(real deg)
{
return (deg/360)*(2*PI);
}
real rad2deg(real rad)
{
return (rad/(2*PI))*360;
}