forked from robertstarr/ulp_user
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eagle_to_3d.ulp
2421 lines (1745 loc) · 64.1 KB
/
eagle_to_3d.ulp
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
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#usage "<b>Generate IDF files and interface to SimplifiedSolutionsinc.com to generate 3D model.</b><p>\n"
"Generates the EMN and EMP IDF files from the board.<BR>"
"IDF files are then submitted to SimplifiedSolutionsinc.com<br/>"
"and a 3D assembly model is generated. On the SimplifiedSolutionsinc.com<BR/>"
"site mappings are executed from the board elements to fully rendered<BR>"
"3D models. The site then responses with a thumbnail and several free and<br/>"
"purchase options.<BR>"
"Version: 1.0 - Initial Release - 4-30-12<br/>"
"Version: 1.1 - Includes banner and dynamic library logic - 5-5-12<br/>"
"Version: 1.2 - Includes fix for board outline loop order and improved logic for component outlines - 5-9-12<br/>"
"Version: 1.3 - Includes fix for zero value max/min x/y values on component outlines - 5-10-12<br/>"
"Version: 1.4 - Includes fix for missing holes - 5-12-12<br/>"
"Version: 1.5 - Modified banner url for dynamic version based message. Fix in board outline for lines linked end to end vs end to start. Updated text in UI. - 5-13-12<br/>"
"Version: 1.6 - Fix for component outlines where max/min values are equal resulting in failures in Proe - 5-14-12<br/>"
"Version: 1.7 - Enabled purchase links to pcb-pool site. Include UI customizations for Windows and Mac. - 5-14-12<br/>"
"Version: 1.8 - Updated links shown after build completed. - 6-21-12<br/>"
"Version: 1.9 - UI updates based on feedback. Added in third link to enable user to continue working on board. - 7-1-12<br/>"
"Version: 2.0 - UI fixes for Mac/Linux - 7-2-12<br/>"
"Version: 2.1 - Updated UI on page. - 7-8-12<br/>"
"Version: 2.2 - Improved board outline algorithm. - 7-10-12<br/>"
"Version: 2.3 - Changed port number to 8080. 9-17-12<br/>"
"Version: 2.3b - Fix for space in generation of .placement section values. - 7-30-12<br/>"
"Version: 3.0 - Improvements to handling of outline defects and swap package/value in writing to IDF files. Fixed issue with unique alname/ecad outlines in emp. Includes logic to handle boards with circle outline. - 9-13-12<br/>"
"</p>"
"<author>Author: [email protected]</author>"
#require 5.1000
string version = "3.0"; //ulp version
//vars used for the text dialog
string textMessageDialog; //used to store text shown to user
string textMessageHeader = "<h1>Welcome to the EAGLE-to-3D Tool</h1>";
string textDisclaimer = "The 3D component libraries supplied by Simplified Solutions have been compiled with great care. However, with the large number of 3D models available and the occasional package changes made by suppliers, an occasional discrepancy is unavoidable. Please note, therefore, that Simplified Solutions and Beta LAYOUT takes no responsibility for the complete accuracy of information included in the 3D library components. Please verify all 3D PCB STEP file geometry prior to using the data in product designs. By choosing the \"Generate 3D Data\" button you are also agreeing to our <a href=\"http://www.simplifiedsolutionsinc.com/copy/terms_of_service.html\">Terms of Service</a>";
//web request urls
string host = "http://www.simplifiedsolutionsinc.com";
string service_port = "8080";
string static_port = "80";
string service_name = "EMN-EMPAdvancedApp/EagleTo3DServlet";
string static_name = "EagleTo3D/";
string service_url = host + ":" + service_port + "/" + service_name;
string static_url = host + ":" + static_port + "/" + static_name;
string libraries[]; //used to hold libraries from web
string packageOutlines[]; //used to hold outlines of packages
int packageCounter = 0; //keeps track of how many entries in packages outline array
//html used in the UI
string tagImgActive = "<img src=\""+ service_url + "/images/ajax-loader.gif\" size=\"50\">";
string tagBanner = ""; //Initial value. Once its retrieved first time it will have actual data.
//debug flags
int debug = 0; //general debug flag
int debugIDFFile = 1; //debug to write out local idf files
int debugIDFHtml = 0; //debug to write out local idf files in html format
//-----------------------------------------------------------------------------
// dictionary
//-----------------------------------------------------------------------------
string Dictionary[] = {
"en\v"
"de\v",
"English message 1 here. \v"
"German message 1 here. \v",
"English message 2 here. \v"
"German message 3 here. \v"
};
string DlgLang = language();
if (DlgLang != "de") DlgLang = "en"; //force to en if not german
int LangIdx = strstr(Dictionary[0], DlgLang) / 3; //language index
///// Translate, based on dictionary
string tr(string s) {
string t = lookup(Dictionary, s, LangIdx, '\v');
return t ? t : s;
}
//-----------------------------------------------------------------------------
// subroutines
//-----------------------------------------------------------------------------
string itos( int num ){
string temp;
sprintf( temp, "%d", num );
return temp;
}
string rtos( real num ){
string temp;
sprintf( temp, "%f", num );
return temp;
}
int compareReals( real n1, real n2 ){
string n1s;
string n2s;
sprintf( n1s, "%1.2f", n1 );
sprintf( n2s, "%1.2f", n2 );
if( n1s == n2s ){
return 1;
}
else{
return 0;
}
}
string getBoardThickness(){
int unitsInt;
string thickness;
/* removed to force board to mm
board(B) {
unitsInt = B.grid.unit;
}
switch( unitsInt ){
case 0:
thickness = "1.6";
break;
case 1:
thickness = "1.6";
break;
case 2:
thickness = "1.6";
break;
case 3:
thickness = "1.6";
break;
} //end switch
*/
thickness = "1.6";
return thickness;
} //end func
string getBoardUnits(){
/*
GRID_UNIT_MIC microns
GRID_UNIT_MM millimeter
GRID_UNIT_MIL mil
GRID_UNIT_INCH inch
*/
/* force to mm
string unitsMap[] = { "MIC", "MM", "MIL", "IN" };
board(B) {
return unitsMap[ B.grid.unit ];
}
*/
return "MM";
}
real backConvertDimensions( real mmDim ){
real boardDim;
int unitsInt;
//get board dimensions
board(B) {
unitsInt = B.grid.unit;
}
/*
GRID_UNIT_MIC microns
GRID_UNIT_MM millimeter
GRID_UNIT_MIL mil
GRID_UNIT_INCH inch
*/
switch( unitsInt ){
case 0:
//micron
boardDim = mmDim * 1000;
break;
case 1:
//mm
boardDim = mmDim;
break;
case 2:
//mil
boardDim = mmDim * 39.3700787;
break;
case 3:
//inch
boardDim = mmDim * 0.0393701;
break;
} //end switch
//string unitsMap[] = { "MIC", "MM", "MIL", "IN" };
//dlgMessageBox( "MM:" + rtos( mmDim ) + ", " + unitsMap[ unitsInt ] + ": " + rtos( boardDim ) );
return boardDim;
} //end func
real getDimInBoardUnits( int dim ){
int unitsInt;
real convDim;
/* removed for force to mm
board(B) {
unitsInt = B.grid.unit;
}
switch( unitsInt ){
case 0:
convDim = u2mic( dim );
break;
case 1:
convDim = u2mm( dim );
break;
case 2:
convDim = u2mil( dim );
break;
case 3:
convDim = u2inch( dim );
break;
} //end switch
*/
convDim = u2mm( dim );
return convDim;
} //end func
real getTolerance(){
int unitsInt;
real tolerance;
/* removed to force to mm
board(B) {
unitsInt = B.grid.unit;
}
switch( unitsInt ){
case 0:
tolerance = 100;
break;
case 1:
tolerance = 0.05;
break;
case 2:
tolerance = 3.9;
break;
case 3:
tolerance = 0.004;
break;
} //end switch
*/
tolerance = 0.05;
return tolerance;
} //end func
string getBoardFilename(){
board( BRD ){
return filename( BRD.name );
} //end board
}
string getBoardDir(){
board( BRD ){
return filedir( BRD.name );
} //end board
}
string getBoardPath(){
return getBoardDir() + getBoardFilename();
}
int isWindows() {
//Returns 1, if EAGLE is running under Windows (0 for Linux/Mac)
if ((strsub(argv[0],0,1)=="/") && (strsub(argv[0],0,2)!="//"))
return 0;
return 1;
} //end sub
//count number of times a char shows up in a string.
int countOccurancesOfChar( string strToScan, char toMatch ){
int count = 0;
for (int i = 0; strToScan[i]; ++i) {
if( strToScan[i] == toMatch ){
count++;
} //end if
} //end for
return count;
} //end sub
// Removes carriage returns from a string and replaces with <BR/>
string removeCarriageReturns( string dirtyString ){
string cleanedString;
for (int i = 0; dirtyString[i]; ++i) {
if( dirtyString[i] == '\n' ){
cleanedString += "<BR/>";
}
else{
cleanedString += dirtyString[i];
} //end if-else
} //end for
return cleanedString;
} //end sub
// Removes spaces in string and replaces with <S/>
string removeSpaces( string dirtyString ){
string cleanedString;
for (int i = 0; dirtyString[i]; ++i) {
if( dirtyString[i] == ' ' ){
cleanedString += "<S/>";
}
else{
cleanedString += dirtyString[i];
} //end if-else
} //end for
return cleanedString;
} //end sub
// Removes spaces in string and replaces with <S/>
string replaceSpaceWithUnderscore( string dirtyString ){
string cleanedString;
for (int i = 0; dirtyString[i]; ++i) {
if( dirtyString[i] == ' ' ){
cleanedString += "_";
}
else{
cleanedString += dirtyString[i];
} //end if-else
} //end for
return cleanedString;
} //end sub
// Reads in file and converts it to be used in a html form submit
string parseFileToHtmlForm( string filePath ){
string fileContents;
int in = fileread( fileContents, filePath );
fileContents = removeCarriageReturns( fileContents );
fileContents = removeSpaces( fileContents );
//dlgMessageBox( "File input value:" + in );
return fileContents;
} //end sub
string parseStringToHtmlForm( string input ){
return removeSpaces( removeCarriageReturns( input ) );
} //end sub
//this function is used to get the html to show in the UI. it uses a fixed header and footer and the call sets the body.
string getHtmlText( string body ){
string os;
//detect if windows or other
if( isWindows() ){
os = "Windows";
}
else{
os = "Mac/Linux";
}
string htmlHeader = "<hr size=1>" + textMessageHeader + "<hr size=1> \
<table border=0 width=\"100%\" height=\"100%\"> \
<tr> \
<td width=\"100%\">";
string htmlFooter = "</td>";
htmlFooter += "<td>";
//build window based on OS
if( isWindows() ){
htmlFooter += "<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/></td>";
}
else{
htmlFooter += "<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/></td>";
} //end if-else
htmlFooter += "</tr></table>";
htmlFooter += "<hr size=1>";
htmlFooter += "<table border=0 width=\"100%\" height=\"100%\"><tr><td align=left width=\"65%\">EAGLE-to-3D is a product of <a href=\"http://www.simplifiedsolutionsinc.com\">Simplified Solutions Inc.</a> and <a href=\"www.beta-layout.com\">Beta LAYOUT</a></td><td align=right>( ULP Version: " + version + "\t, OS: " + os + " )</td></tr><tr><td colspan=2><hr size=1></td></tr><tr><td colspan=2><font size=-1>" + textDisclaimer + "</font><td></tr></table><br/>";
return htmlHeader + body + htmlFooter;
} //end sub
//general function to do url get
string getWebFile( string url_path ){
return "";
}
//this sub is used to get the Html banner to show on the UI. It should only need to be called once on first call
void loadBanner(){
string banner;
//do netget
if( netget( banner, static_url + "eagle_banner.php?ulp_version=" + version + "&lang=" + language() ) ){
if( debug ){
dlgMessageBox( banner );
} //end if
tagBanner = banner;
}
else{
tagBanner = "Not retrieved";
} //end if-else
} //end sub
void loadTerms(){
string term;
//do netget
if( netget( term, static_url + "terms.html" ) ){
if( debug ){
dlgMessageBox( term );
} //end if
//tagBanner = banner;
}
else{
//tagBanner = "Not retrieved";
} //end if-else
} //end sub
void loadLibraries(){
//string libraries[];
string libResponse;
int libraryCount = 0;
//string defaultLib[] = { "RCL", "RESISTOR" };
//do netget
if( netget( libResponse, static_url + "eagle_libraries.txt" ) ){
if( debug ){
dlgMessageBox( libResponse );
} //end if
//load library string in to libraries array
libraryCount = strsplit( libraries, libResponse, ':');
} //end if
//in case some issue load RCL and RESISTOR as default
if( libraryCount == 0 ){
libraries[0] = "RCL";
libraries[1] = "RESISTOR";
} //end if
} //end sub
real getDistBetweenPts( real x1, real y1, real x2, real y2 ){
//dist = sqrt( ( x2 - x1 )^2 + ( y2 - y1 )^2 )
return sqrt( pow( ( x2 - x1 ), 2 ) + pow( ( y2 - y1 ), 2 ) );
} //end sub
void writeToFile( string filePath, string fileContents ){
output( filePath, "wt" ){
printf( fileContents );
}
}
//-----------------------------------------------------------------------------
// emp subroutines
//-----------------------------------------------------------------------------
string getDateTime(){
//time for date.time in header
int now = time();
string dateStr;
sprintf( dateStr, "%d/%02d/%02d.%02d:%02d:%02d", t2year(now), t2month(now), t2day(now), t2hour(now), t2minute(now), t2second(now) );
return dateStr;
} //end sub
//used to detect if outline should be closed by checking if point is within tolerance/radius of first point
int closeOutline( real bx1, real by1, real firstX, real firstY, real radius ){
string temp;
//debug
if( debug ){
real xCalc = pow( ( bx1 - firstX ), 2 );
real yCalc = pow( ( by1 - firstY ), 2 );
real radCalc = pow( radius, 2 );
sprintf( temp, "%f + %f < %f", xCalc, yCalc, radCalc );
dlgMessageBox( temp );
}
//(x-center_x)^2 + (y - center_y)^2 < radius^2
if( ( pow( ( bx1 - firstX ), 2 ) + pow( ( by1 - firstY ), 2 ) ) < pow( radius, 2 ) ){
return 1;
}
else{
return 0;
}
} //end sub
//looks up package outline and generates text for .electical section entry
string getComponentOutline( string footprint, string altname, string packageName, string units ){
//package array = [ { packname1, maxX, maxY, minX, minY },
// { packname2, maxX, maxY, minX, minY }
// ]
//board->Library->Package->Wires
int foundPackage = 0;
//lookup package name in array
string packageNameLookup = lookup( packageOutlines, packageName, 0 );
//check if found in lookup. if not then generate and put in array
if( packageNameLookup == "" ){
//if package not in lookup then generate it
//init max/min values
real maxX = 0, maxY = 0, minX = 0, minY;
//loop thru all libraries to find packagename
board(B) {
//go into library
B.libraries(LBR) {
//loop thru packages in library
LBR.packages(P){
if( P.name == packageName ){
//set found package flag
foundPackage = 1;
//used to capture first loop of data
int loopCounter = 0;
//loop thru wires and get max/min x/y
P.wires(W){
//get first data point
if( loopCounter == 0 ){
maxX = getDimInBoardUnits(W.x1);
minX = getDimInBoardUnits(W.x1);
maxY = getDimInBoardUnits(W.y1);
minY = getDimInBoardUnits(W.y1);
}
if (W.arc) {
//skip arcs for now
}
else {
//max/min checks
if( getDimInBoardUnits(W.x1) <= minX ){
minX = getDimInBoardUnits(W.x1);
}
if( getDimInBoardUnits(W.x1) >= maxX ){
maxX = getDimInBoardUnits(W.x1);
}
if( getDimInBoardUnits(W.y1) <= minY ){
minY = getDimInBoardUnits(W.y1);
}
if( getDimInBoardUnits(W.y1) >= maxY ){
maxY = getDimInBoardUnits(W.y1);
}
} //end if-else
loopCounter++;
} //end wires
//break out of loop since match found
break;
} //end if for package name match
} //end packages loop
} //end libraries loop
} //end board loop
//make sure found match. if not then put in default values
string temp;
if( foundPackage ){
//load to array
sprintf( temp, "%s\t%f\t%f\t%f\t%f", packageName, maxX, maxY, minX, minY );
}
else{
sprintf( temp, "%s\t%f\t%f\t%f\t%f", packageName, maxX, maxY, minX, minY );
} //end if-else for found package check
packageOutlines[ packageCounter ] = temp;
packageCounter++;
} //end if for lookup check
//generate outline data
string outline = footprint + " " + altname + " " + units;
//set default height based on units
if( units == "MM" ){
outline += " 1.00\n";
}
else if( units == "THOU" ){
outline += " 39.37\n";
}
else{
//treat as MM
outline += " 1.00\n";
} //end if-else
//map in max/min data
string maxX = lookup( packageOutlines, packageName, 1 );
string maxY = lookup( packageOutlines, packageName, 2 );
string minX = lookup( packageOutlines, packageName, 3 );
string minY = lookup( packageOutlines, packageName, 4 );
/*rectangle based on max/min values. start in upper left and move clockwise
0 minX maxY
0 maxX maxY
0 maxX minY
0 minX minY
0 minX maxY
*/
//if max/min are all zeros then put in 1x1 block
if( maxX == "0.000000" && maxY == "0.000000" && minX == "0.000000" && minX == "0.000000" ){
outline += "0 1.00 -1.00 0.0\n" +
"0 -1.00 -1.00 0.0\n" +
"0 -1.00 1.00 0.0\n" +
"0 1.00 1.00 0.0\n" +
"0 1.00 -1.00 0.0\n";
}
else if( maxX == minX || maxY == minY ){
outline += "0 1.00 -1.00 0.0\n" +
"0 -1.00 -1.00 0.0\n" +
"0 -1.00 1.00 0.0\n" +
"0 1.00 1.00 0.0\n" +
"0 1.00 -1.00 0.0\n";
}
else{
outline += "0 " + minX + " " + maxY + " 0.0\n" +
"0 " + maxX + " " + maxY + " 0.0\n" +
"0 " + maxX + " " + minY + " 0.0\n" +
"0 " + minX + " " + minY + " 0.0\n" +
"0 " + minX + " " + maxY + " 0.0\n";
} //end if-else
return outline;
} //end sub
//gets the dummy component outlines for emp file based on units.
string getComponentOutlineDummy( string footprint, string altname, string units ){
string outline = footprint + " " + altname + " " + units;
if( units == "MM" ){
outline += " 1.00\n" +
"0 1.00 -1.00 0.0\n" +
"0 -1.00 -1.00 0.0\n" +
"0 -1.00 1.00 0.0\n" +
"0 1.00 1.00 0.0\n" +
"0 1.00 -1.00 0.0\n";
}
else if( units == "THOU" ){
outline += " 39.37\n" +
"0 39.37 -39.37 0.0\n" +
"0 -39.37 -39.37 0.0\n" +
"0 -39.37 39.37 0.0\n" +
"0 39.37 39.37 0.0\n" +
"0 39.37 -39.37 0.0\n";
}
else{
//treat as MM
outline += " 1.00\n" +
"0 1.00 -1.00 0.0\n" +
"0 -1.00 -1.00 0.0\n" +
"0 -1.00 1.00 0.0\n" +
"0 1.00 1.00 0.0\n" +
"0 1.00 -1.00 0.0\n";
} //end if-else
return outline;
} //end sub
string getEmpHeader(){
/*
.HEADER
LIBRARY_FILE 3.0 "Commend International >generate_3d_data_v10-5_MJB.ulp V0.9<" 2012/03/21.12:23:09 1
.END_HEADER
*/
return ".HEADER\n" +
"LIBRARY_FILE 3.0 \"Eagle to 3D Version " + version + "\" " + getDateTime() + "\n" +
".END_HEADER\n" ;
} //end sub
string getEmpElectrical(){
/*
.ELECTRICAL
TSSOP16 NOREFDES MM 4876.80
0 -2.51 -2.28 0
0 2.51 -2.28 0
0 2.51 2.28 0
0 -2.51 2.28 0
0 -2.51 -2.28 0
.END_ELECTRICAL
*/
string electricalSection;
string footprint;
string altname;
string libraryLookup;
string components[];
string component;
//loop thru elements on board
board( BRD ){
int i = 0;
BRD.elements( E ){
/*
//get footpring
footprint = E.value;
if( footprint == "" ){
footprint = E.name + "_" + E.package.name ;
}
*/
//check if library in lookup
libraryLookup = lookup( libraries, strupr(E.package.library), 0 );
//debug
if( debug ){
dlgMessageBox( libraryLookup );
}
//set footprint and altname based on logic
if( libraryLookup != "" ){
footprint = E.package.name;
altname = E.package.name;
//add comment to emn for debuggin
//placementSection += "#Resistor or rcl library found\n";
}
else if( E.value != "" ){
altname = E.value;
footprint = E.package.name;
//add comment to emn for debuggin
//placementSection += "#E.value present\n";
}
else{
//if library is not in list and the E.value is blank then concat refid and package name
altname = E.name + "_" + E.package.name;
footprint = E.package.name;
//add comment to emn for debuggin
//placementSection += "#Fallback logic applied. Not res/rcl and E.value not found.\n";
}
//check if element has already been written out
//component = lookup( components, footprint, 0 ); - fix for emp missing values
component = lookup( components, footprint + "~" + altname, 0 );
//if component is empty then it has not been written out yet.
if( component == "" ){
//build section by call to getComponentOutlineDummy( string footprint, string altname, string units )
electricalSection += ".ELECTRICAL\n" +
//getComponentOutlineDummy( footprint, altname, "MM" ) +
getComponentOutline( footprint, altname, E.package.name, getBoardUnits() ) +
".END_ELECTRICAL\n";
//add component to components list
//components[ i ] = footprint; - fix for emp missing values
components[ i ] = footprint + "~" + altname;
i++;
} //end if
} //end loop thru elements
} //end loop thru board
return electricalSection;
} //end sub
string getEmpMechanical(){
return "";
} //end sub
//-----------------------------------------------------------------------------
// emn subroutines
//-----------------------------------------------------------------------------
string getEmnHeader(){
/*
.HEADER
BOARD_FILE 3.0 "Commend International >generate_3d_data_v10-5_MJB.ulp V0.9<" 2012/03/21.12:23:10 1
"untitled.brd" MM
.END_HEADER
*/
string boardName;
//get board name
board( BRD ){
boardName = filename(BRD.name);
}
return ".HEADER\n" +
"BOARD_FILE 3.0 \"Eagle to 3D Version " + version + "\" " + getDateTime() + "\n" +
"\"" + boardName + "\" " + getBoardUnits() + "\n" +
".END_HEADER\n";
} //end sub
string setUsedFlag( string pt ){
string fields[];
int fieldCount = strsplit( fields, pt, '\t');
return fields[0] + "\t" + fields[1] + "\t" + fields[2] + "\t" + fields[3] + "\ty\n";
}
int isUsedPoint( string pt ){
string fields[];
int fieldCount = strsplit( fields, pt, '\t');
if( fields[4] == "n\n" )
return 0;
else
return 1;
}
string isUsedPointDebug( string pt ){
string fields[];
int fieldCount = strsplit( fields, pt, '\t');
return fields[4];
}
/*
string swapPoints( string outlinePoints[], int toIndex, int fromIndex ){
//swapPoints( outlinePoints, (i+1), j );
string toPoints = outlinePoints[ toIndex ];
string fromPoints = outlinePoints[ fromIndex ];
//move toIndex to from position
outlinePoints[ fromIndex ] = toPoints;
outlinePoints[ toIndex ] = fromPoints;
return outlinePoints;
}
*/
string flipPoints( string line ){
string fields[];
int fieldCount = strsplit( fields, line, '\t');
return fields[2] + "\t" + fields[3] + "\t" + fields[0] + "\t" + fields[1] + "\t" + fields[4];
}
string getFieldFromPtString( string ptString, int index ){
string fields[];
// "pt 1\ttype\tx1\ty1\tx2\ty2\tsorted_flag"
int fieldCount = strsplit( fields, ptString, '\t');
if( fieldCount >= index ){
return fields[ index ];
}
else{
return "";
} //end if-else
} //end sub
real getX1FromPtString( string ptString ){
return strtod( getFieldFromPtString( ptString, 0 ) );
} //end sub
real getY1FromPtString( string ptString ){
return strtod( getFieldFromPtString( ptString, 1 ) );
} //end sub
real getX2FromPtString( string ptString ){
return strtod( getFieldFromPtString( ptString, 2 ) );
} //end sub
real getY2FromPtString( string ptString ){
return strtod( getFieldFromPtString( ptString, 3 ) );
} //end sub