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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
|
#usage "<b>functions for Eagle3D v1.05</b>"
"<p>"
"<author>Author: Matthias Weißer matthias@matwei.de</author>"
//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<x2)
{
angel = (360/6.2836)*atan((y1-y2)/(x2-x1));
length = sqrt((y1-y2)*(y1-y2)+(x1-x2)*(x1-x2));
sprintf(tmp,"box{<0,0,%f><%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<x1)
{
angel = (360/6.2836)*atan((y2-y1)/(x1-x2));
length = sqrt((y1-y2)*(y1-y2)+(x1-x2)*(x1-x2));
sprintf(tmp,"box{<0,0,%f><%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<y2) angel = 90; else angel = -90;
length = abs(y1-y2);
sprintf(tmp,"box{<0,0,%f><%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<a2;i=i+1)
{
sprintf(out,"%sbox{<-%f,0,-%f>,<%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<strlen(rpl);i++)
{
while((j = strchr(str,rpl[i]))!=-1) str[j] = chr;
}
return str;
}
//Erzeugt einen String ohne Sonderzeichen der von POVRay verarbeitet werden kann
string make_pov_str(string in)
{
int i,j;
while((i = strchr(in,'Ü'))!=-1) in[i] = 'U';
while((i = strchr(in,'Ä'))!=-1) in[i] = 'A';
while((i = strchr(in,'Ö'))!=-1) in[i] = 'O';
while((i = strchr(in,'ü'))!=-1) in[i] = 'U';
while((i = strchr(in,'ä'))!=-1) in[i] = 'A';
while((i = strchr(in,'ö'))!=-1) in[i] = 'O';
while((i = strchr(in,'ß'))!=-1) in[i] = 'S';
in = strreplace(in,". -&$+:;,!\"§%/()=#*~'<>µ",'_');
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<j;i++)
{
if(strtol(b[i])==n) return 1;
}
return 0;
}
int is_in_range(int val1, int val2, real ver1, real ver2)
{
if( (u2mm(val1)>=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++;
}
}
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<j;k++)
{
processed_board_segments[k] = 0;
}
int cur_x = -2147483647;
int cur_y = -2147483647;
real cur_dist;
int cur_segment;
int cur_corner;
for(k=0;k<j;k++)
{
l=0;
cur_segment = -1;
cur_dist = 1e308;
//nächstgelegenes Segment suchen
B.wires(W)
{
if((W.layer == layer)&&(processed_board_segments[l]==0))
{
if(calc_distance(cur_x,cur_y,W.x1,W.y1) < cur_dist)
{
cur_dist = calc_distance(cur_x,cur_y,W.x1,W.y1);
cur_segment = l;
cur_corner = 1;
}
if(calc_distance(cur_x,cur_y,W.x2,W.y2) < cur_dist)
{
cur_dist = calc_distance(cur_x,cur_y,W.x2,W.y2);
cur_segment = l;
cur_corner = 2;
}
}
l++;
}
l=0;
B.wires(W)
{
if(W.layer == layer)
{
if(l==cur_segment)
{
if(cur_corner == 1)
{
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
{
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(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<j;k++)
{
processed_board_segments[k] = 0;
}
int cur_x = -2147483647;
int cur_y = -2147483647;
real cur_dist;
int cur_segment;
int cur_corner;
for(k=0;k<j;k++)
{
l=0;
cur_segment = -1;
cur_dist = 1e308;
//nächstgelegenes Segment suchen
P.wires(W)
{
if((W.layer == layer)&&(processed_board_segments[l]==0))
{
if(calc_distance(cur_x,cur_y,W.x1,W.y1) < cur_dist)
{
cur_dist = calc_distance(cur_x,cur_y,W.x1,W.y1);
cur_segment = l;
cur_corner = 1;
}
if(calc_distance(cur_x,cur_y,W.x2,W.y2) < cur_dist)
{
cur_dist = calc_distance(cur_x,cur_y,W.x2,W.y2);
cur_segment = l;
cur_corner = 2;
}
}
l++;
}
l=0;
P.wires(W)
{
if(W.layer == layer)
{
if(l==cur_segment)
{
if(cur_corner == 1)
{
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
{
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;i<num_layers;i++)
{
if(layer_arr[i]=="") break;
layer_numbers[i] = strtol(layer_arr[i]);
}
num_layers = i;
out += "//" + E.name + "\nunion{\n";
//Zu bearbeitende Layer durchgehen
for(i=0;i<num_layers;i++)
{
string color = "Black";
real height = 5.0;
real top;
real bot;
//Wir suchen uns den Info-String
E.package.texts(T)
{
if(T.layer==layer_numbers[i])
{
real rtmp = strtod(T.value);
if(rtmp!=0.0) height = rtmp;
string stmp = strsub(T.value, strchr(T.value,' '));
if(stmp!="") color = stmp;
object=1;
}
}
//Prüfen ob die Farbangabe ein komplette POVRay texture ist
if(strstr(color,"texture")==-1)
{
if(strstr(color,"pigment")==-1)
{
color = "pigment{" + color + "}";
}
color = "texture{" + color + "}";
}
//Höheninformationen generieren
if(E.mirror)
{
top = -pcb_height;
bot = -height - pcb_height;
}
else
{
top = height;
bot = 0;
}
out += make_prism_from_package_layer(E.package, layer_numbers[i], 10, bot, top, color);
}
out += "} //" + E.name + " ";
out += object ? "1" : "0";
out += "\n";
//dlgMessageBox(out);
return out;
}
//Clips the given number to zero if it is negativ
real clip_negativ_to_zero(real d)
{
if(d<0.0) return 0.0;
else return d;
}
//Clips the given number to zero if it is positiv
real clip_positiv_to_zero(real d)
{
if(d>0.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;
}
|