-
Notifications
You must be signed in to change notification settings - Fork 0
/
eagleJSONexporter_v1_0.ulp
4399 lines (3903 loc) · 195 KB
/
eagleJSONexporter_v1_0.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 from CADSoft Eagle</b><p>\n"
"Run ULP on board file to generate IDF 4 files for import to CAD tools.<BR>"
"Version: 0.1 - Initial release - 04-27-2018<br/>"
"</p>"
"<author>Author: [email protected]</author>"
#require 5.1000
string version = "1.0"; //ulp version
//vars used for the text dialog
string TextMessageDialog; //used to store text shown to user
string HeightHtmlTable = "";
string BoardThickness = "1.6"; //mm
string WireLayer = "20";
string status_msg="<font color='green'>...</font>";
string PackageOutlines[]; //used to hold outlines of packages
string Part_Name_array[];
int parts_Count=0;
int PackageCounter = 0; //keeps track of how many entries in packages outline array
string NULL_HEIGHT = "0.000000"; //used for null heights
int silkscreen=1;
//debug flags
int Debug = 1; //general Debug flag
int startElementID = 2500; //change it if you want. Best will be to randomize it.
int elementNumber = 0;
int Elec_Part_Insts=0;
int Elec_Part_Defs = 0;
//-----------------------------------------------------------------------------
// subroutines
//-----------------------------------------------------------------------------
void updateStatus(string message,string color,int isbold,int italics)
{
status_msg = "<font color='"+color+"'>";
if(isbold!=0)
status_msg+="<b>";
if(italics!=0)
status_msg+="<i>";
status_msg+=message;
if(italics!=0)
status_msg+="</i>";
if(isbold!=0)
status_msg+="</b>";
status_msg+="</font>";
}
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 IsInt(string str) {
//returns 1 if int. 0 if not string
//first check to make sure its not "0" which Is the fail mode for the cast
if (str == "0") {
return 1;
} else if (strtol(str) != 0) {
return 1;
} else {
return 0;
}
} //end IsInt
int IsReal(string str) {
//returns 1 if int. 0 if not string
//first check to make sure its not "0.0" which Is the fail mode for the cast
if (str == "0.0") {
return 1;
} else if (strtod(str) != 0.0) {
return 1;
} else {
return 0;
}
} //end IsInt
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() {
//make sure there Is value for board thickness
if (BoardThickness == "") {
BoardThickness = "1.6";
}
//check if first char Is decimal and if it Is then add 0
char dec = '.';
int pos = strchr(BoardThickness, dec);
if (pos == 0) {
BoardThickness = "0" + BoardThickness;
}
//return form value
return BoardThickness;
} //end func
string GenerateID()
{
elementNumber = elementNumber + 1;
return itos(startElementID + elementNumber);
}
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();
}
string PadBRs( int count ){
string padding = "";
for( int i; i < count; i++ ){
padding += "<BR>";
}
return padding;
}
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
int IsMac(){
if( (strsub( OS_SIGNATURE, 0, 3 ) == "Mac") || (strsub( OS_SIGNATURE, 0, 3 ) == "MAC") )
return 1;
return 0;
}
void LaunchBrowser( string url ){
string launchCmd = "";
if( IsWindows() ){
launchCmd = "explorer \"" + url + "\"";
}
else if( IsMac() ){
launchCmd = "open \"" + url + "\"";
}
else{
//assume all others linux
//if you are on linux then change this line if the buttons dont work
launchCmd = "xdg-open " + url;
}
//run system command
system( launchCmd );
} //end launch browser
string GetFileSeperator() {
if (IsWindows()) {
return "\\";
} else {
return "/";
}
}
// 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
string CleanString(string dirtyString) {
dirtyString = strupr(dirtyString);
string cleanedString;
for (int i = 0; dirtyString[i]; ++i) {
if (dirtyString[i] == '0' || dirtyString[i] == '1'
|| dirtyString[i] == '2' || dirtyString[i] == '3'
|| dirtyString[i] == '4' || dirtyString[i] == '5'
|| dirtyString[i] == '6' || dirtyString[i] == '7'
|| dirtyString[i] == '8' || dirtyString[i] == '9'
|| dirtyString[i] == 'A' || dirtyString[i] == 'B'
|| dirtyString[i] == 'C' || dirtyString[i] == 'D'
|| dirtyString[i] == 'E' || dirtyString[i] == 'F'
|| dirtyString[i] == 'G' || dirtyString[i] == 'H'
|| dirtyString[i] == 'I' || dirtyString[i] == 'J'
|| dirtyString[i] == 'K' || dirtyString[i] == 'L'
|| dirtyString[i] == 'M' || dirtyString[i] == 'N'
|| dirtyString[i] == 'O' || dirtyString[i] == 'P'
|| dirtyString[i] == 'Q' || dirtyString[i] == 'R'
|| dirtyString[i] == 'S' || dirtyString[i] == 'T'
|| dirtyString[i] == 'U' || dirtyString[i] == 'V'
|| dirtyString[i] == 'W' || dirtyString[i] == 'X'
|| dirtyString[i] == 'Y' || dirtyString[i] == 'Z'
|| dirtyString[i] == '_' || dirtyString[i] == '-'
|| dirtyString[i] == ' ') {
cleanedString += dirtyString[i];
} else {
cleanedString += "_";
} //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
// 0-9, letters, dashes, and underscores are always safe.
// 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
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);
}
} //end sub
string GetElementHeightAttr( UL_ELEMENT E ){
/* checks for attribute named HEIGHT.
* casts height string to real to handle any invalid values. sets to 0 if not value.
* returns height
*/
string height = NULL_HEIGHT;
//check for element height
E.attributes(A)
{
if (strupr(A.name) == "HEIGHT") {
if ( strtod(A.value) <= 0.0) {
height = NULL_HEIGHT;
} else {
height = rtos( strtod( A.value ) );
} //end if-else
} //end if
} //end loop thru attributes
return height;
} //end sub
//-----------------------------------------------------------------------------
// 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;
}
string GetComponentOutline(string footprint1 , string altname , string packageName , string units , string height)
{
//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 = 0;
//loop thru all Libraries to find packagename
board(B)
{
//go into library
B.libraries(LBR)
{
//loop thru packages in library
LBR.packages(P)
{
//if package name matches the one we are looking for then process it
if (P.name == packageName) {
//check min/ax for each of
//circles() UL_CIRCLE - C.x, C.y, C.radius, C.width)
//holes() UL_HOLE
//polygons() UL_POLYGON -> wires()
//rectangles() UL_RECTANGLE - R.x1, R.y1, R.x2, R.y2);
//wires() UL_WIRE
//set found package flag
foundPackage = 1;
//used to capture first loop of data
int loopCounter = 0;
real w2; //holds 1/2 of width
//loop thru wires and Get max/min x/y
//do wires first to take care of loopCounter == 0 case
P.wires(W)
{
//get first data point
if (loopCounter == 0) {
w2 = W.width / 2;
minX = GetDimInBoardUnits(
min(W.x1 - w2, W.x2 - w2));
minY = GetDimInBoardUnits(
min(W.y1 - w2, W.y2 - w2));
maxX = GetDimInBoardUnits(
max(W.x1 + w2, W.x2 + w2));
maxY = GetDimInBoardUnits(
max(W.y1 + w2, W.y2 + w2));
}
if (W.arc) {
w2 = W.width / 2;
if (W.arc.angle2 > 360)
maxX = max(maxX,
GetDimInBoardUnits(
W.arc.xc + W.arc.radius));
else if (((W.arc.angle1 < 90)
&& (W.arc.angle2 > 90))
|| (W.arc.angle2 > 450))
maxY = max(maxY,
GetDimInBoardUnits(
W.arc.yc + W.arc.radius
+ w2));
else if (((W.arc.angle1 < 180)
&& (W.arc.angle2 > 180))
|| (W.arc.angle2 > 540))
minX = min(minX,
GetDimInBoardUnits(
W.arc.xc - W.arc.radius
- w2));
else if (((W.arc.angle1 < 270)
&& (W.arc.angle2 > 270))
|| (W.arc.angle2 > 630))
minY = min(minY,
GetDimInBoardUnits(
W.arc.yc - W.arc.radius
- w2));
}
else {
//handle non arc wires
minX = min(minX, GetDimInBoardUnits(W.x1));
minY = min(minY, GetDimInBoardUnits(W.y1));
maxX = max(maxX, GetDimInBoardUnits(W.x1));
maxY = max(maxY, GetDimInBoardUnits(W.y1));
} //end if-else
loopCounter++;
} //end wires
//UpdateBBoxBox(C.x - C.radius - w2, C.y - C.radius - w2, C.x + C.radius + w2, C.y + C.radius + w2);
// xmin, ymin, xmax, ymax
P.circles(C)
{
w2 = C.width / 2;
minX = min(minX,
GetDimInBoardUnits(C.x - C.radius - w2));
minY = min(minY,
GetDimInBoardUnits(C.y - C.radius - w2));
maxX = max(maxX,
GetDimInBoardUnits(C.x + C.radius + w2));
maxY = max(maxY,
GetDimInBoardUnits(C.y + C.radius + w2));
loopCounter++;
} //end circles
//P.holes(){} - Not required. These are solder masks
P.polygons(POLY)
{
POLY.wires(PW)
{
minX = min(minX, GetDimInBoardUnits(PW.x1));
minY = min(minY, GetDimInBoardUnits(PW.y1));
maxX = max(maxX, GetDimInBoardUnits(PW.x1));
maxY = max(maxY, GetDimInBoardUnits(PW.y1));
loopCounter++;
} //end wires in polygon
} //end polgons
P.rectangles(R)
{
minX = min(minX,
min(GetDimInBoardUnits(R.x1),
GetDimInBoardUnits(R.x2)));
minY = min(minY,
min(GetDimInBoardUnits(R.y1),
GetDimInBoardUnits(R.y2)));
maxX = max(maxX,
max(GetDimInBoardUnits(R.x1),
GetDimInBoardUnits(R.x2)));
maxY = max(maxY,
max(GetDimInBoardUnits(R.y1),
GetDimInBoardUnits(R.y2)));
loopCounter++;
} //end rectangles
//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
//add data to package outline so it can be reused in future
PackageOutlines[PackageCounter] = temp;
PackageCounter++;
} //end if for lookup check
//generate outline data. first line is footpring, name, and units
string temp_height;
string outline = "\n\t\t{\n\t\t\"Entity_ID\":\""+ GenerateID() +"\",\n\t\t\"Part_Name\":\""+footprint1+"\",\n\t\t\"Units\":\"Global\",\n\t\t\"Type\":\"Unspecified\",\n\t\t\"Shape\":\n\t\t\t{\n\t\t\t\"Extrusion\":\n\t\t\t\t{\n\t\t\t\t\"Entity_ID\":\"#"+ GenerateID() +"\",";
//set default height based on units
if (units == "MM") {
temp_height = height ;
//check if height set. if not set to 1.0
/*if (height == "1.0") {
outline += " 1.00\n";
}
else {
outline += " " + height + "\n";
}*/
}
/*else if (units == "THOU") {
//check if
if (height == "0.0") {
outline += " 39.37\n";
}
else {
outline += " " + height + "\n";
}
}
*/
else {
//treat as MM
//check if
if (height == "1.0") {
temp_height= "1.00";
} else {
temp_height= height;
}
} //end if-else
outline += "\n\t\t\t\t\"Top_Height\":"+temp_height+",\n\t\t\t\t\"Bot_Height\":0,\n\t\t\t\t\"Outline\":\n\t\t\t\t\t{\n\t\t\t\t\t\"Polycurve_Area\":\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\"Entity_ID\":\"#"+GenerateID()+"\",\n\t\t\t\t\t\t\"Line_Font \":\"Solid\",\n\t\t\t\t\t\t\"Line_Color\":[0.0, 0.0, 0.0],\n\t\t\t\t\t\t\"Fill_Color\":[0.0, 0.0, 0.0],\n\t\t\t\t\t\t\"Vertices\":\n\t\t\t\t\t\t\t[\n";
//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 += "\t\t\t\t\t\t\t[1.00, -1.00, 0.0],\n\t\t\t\t\t\t\t[-1.0, -1.0, 0],\n\t\t\t\t\t\t\t[-1.0, 1.0, 0],\n\t\t\t\t\t\t\t[1.0, 1.0, 0],\n\t\t\t\t\t\t\t[1.00, -1.00, 0.0]\n";
}
//if they are all the same they also set in 1x1 block so that something is shown
else if (maxX == minX || maxY == minY) {
outline += "\t\t\t\t\t\t\t[1.00, -1.00, 0.0],\n\t\t\t\t\t\t\t[-1.0, -1.0, 0],\n\t\t\t\t\t\t\t[-1.0, 1.0, 0],\n\t\t\t\t\t\t\t[1.0, 1.0, 0],\n\t\t\t\t\t\t\t[1.00, -1.00, 0.0]\n";
}
//otherwise actual coords provided. use those in output
else {
outline += "\t\t\t\t\t\t\t[" + minX + ", " + maxY + ", 0.0],\n\t\t\t\t\t\t\t[" + maxX + ", " + maxY + ", 0],\n\t\t\t\t\t\t\t[" + maxX + ", " + minY + ", 0],\n\t\t\t\t\t\t\t[" + minX + ", " + minY + ", 0],\n\t\t\t\t\t\t\t["+minX+", " + maxY + ", 0.0]\n";
} //end if-else
outline += "\t\t\t\t\t\t\t]\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t\"Properties\":{\"Part_Number\":\""+altname+"\"}\n\t\t},";
return outline;
} //end sub
int searchPartsArray(string data)
{
for(int i=0;i<parts_Count;i++)
{
if(Part_Name_array[i]==data)
{
return 1;
break;
}
}
return 0;
}
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 footprint1;
string altname;
string height = NULL_HEIGHT;
string LibraryLookup;
string components[];
string component;
//loop thru elements on board
board(BRD)
{
int i = 0;
electricalSection = "\t\"Electrical_Part\":\n\t\t[";
BRD.elements(E)
{
height = NULL_HEIGHT;
//check if library in lookup
// LibraryLookup = lookup(Libraries, strupr(E.package.library), 0);
// //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;
footprint1 = 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;
footprint1 = E.package.name;
//add comment to emn for debuggin
//placementSection += "#Fallback logic applied. Not res/rcl and E.value not found.\n";
}
altname = CleanString(altname);
footprint1 = CleanString(footprint1);
//check if height set for element. if not set then set to NULL_HEIGHT
height = GetElementHeightAttr( E );
//add component to height lookup table
HeightHtmlTable = HeightHtmlTable + "<tr><td>" + E.name
+ "</td><td>" + altname + "</td><td>" + E.package.name
+ "</td>";
//if height is not set then set to default
if (height == NULL_HEIGHT) {
height = "1.0"; //set to value of 1.0
HeightHtmlTable = HeightHtmlTable + "<td bgcolor=\"yellow\">" + height + "</td></tr>";
} else {
HeightHtmlTable = HeightHtmlTable + "<td>" + height + "</td></tr>";
} //if-else for height value
component = lookup(components, footprint1 + "~" + altname, 0);
//if component Is empty then it has not been written out yet.
if (component == "")
{
if(searchPartsArray(footprint1)==0)
{
Elec_Part_Defs = Elec_Part_Defs + 1;
//build section by call to GetComponentOutlineDummy( string footprint1, string altname, string units )
electricalSection += GetComponentOutline(footprint1, altname, E.package.name, GetBoardUnits(), height);
//add component to components list.
//components[i] = footprint1 + "~" + altname; - Fix for multi comp and heights
components[i] = footprint1 + "~" + altname;
i++;
Part_Name_array[parts_Count]=footprint1;
parts_Count++;
}
} //end if
} //end loop thru elements
} //end loop thru board
electricalSection[strlen(electricalSection)-1] = '\0';
electricalSection += "\n\t\t]";
return electricalSection;
} //end sub
string GetEmpMechanical() {
return "";
} //end sub
//-----------------------------------------------------------------------------
// emn subroutines
//-----------------------------------------------------------------------------
string GetEmnHeader(int Elec_Part_Insts, int Elec_Part_Defs) {
/*
.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 "\"IDF_Header\"\n\t:{\n\t\"Version\" :\"V4.0\",\n\t\"Creation_Date_Time\" :\"" + GetDateTime() + "\",\n\t\"Owner_Name\" :\"None\",\n\t\"Owner_Phone\" :\"\",\n\t\"Owner_EMail\" :\"\",\n\t\"Source_App_Type\" :\"ECAD\",\n\t\"Source_App_Vendor\":\"Autodesk\",\n\t\"Source_App_Name\":\"Eagle CAD\",\n\t\"Source_App_Version\":\"V" + version
+ "\",\n\t\"Source_Tx_Name\":\"Eagle JSON Export\",\n\t\"Source_Tx_Version\":\"V" + version
+ "\",\n\t\n\t\"Entity_Count\"\n\t\t:{\n\t\t\"Elec_Part_Defs\" :\""+ itos(Elec_Part_Defs) +"\",\n\t\t\"Elec_Part_Insts\" :\""+ itos(Elec_Part_Insts) +"\",\n\t\t\"Mech_Part_Defs\" : \"0\",\n\t\t\"Mech_Part_Insts\" : \"0\",\n\t\t\"Board_Part_Defs\" : \"1\",\n\t\t\"Board_Part_Insts\" : \"1\",\n\t\t\"Board_Assy_Defs\" : \"0\",\n\t\t\"Board_Assy_Insts\" : \"0\",\n\t\t\"Panel_Part_Defs\" : \"0\",\n\t\t\"Panel_Part_Insts\" : \"0\",\n\t\t\"Panel_Assy_Defs\" : \"0\",\n\t\t\"Panel_Assy_Insts\":\"0\"\n\t\t},\n\t\t\n\t\"Comp_Part\"\n\t\t:[\n\t\t\"Annotation\",\n\t\t\"Cavity\",\n\t\t\"Circle\",\n\t\t\"Circular_Arc\",\n\t\t\"Cutout\",\n\t\t\"Electrical_Part\",\n\t\t\"Extrusion\",\n\t\t\"Leader\",\n\t\t\"Material\",\n\t\t\"Mechanical_Part\",\n\t\t\"Pin\",\n\t\t\"Polycurve\",\n\t\t\"Polycurve_Area\",\n\t\t\"Polygon\",\n\t\t\"Polyline\",\n\t\t\"Text\",\n\t\t\"Thermal_Model\",\n\t\t\"Thermal_CV\",\n\t\t\"Thermal_RV\"\n\t\t],\n\t\t\n\t\"Board_Part\"\n\t\t:[\n\t\t\"Annotation\",\n\t\t\"Board_Part\",\n\t\t\"Cavity\",\n\t\t\"Circle\",\n\t\t\"Cutout\",\n\t\t\"Extrusion\",\n\t\t\"Figure\",\n\t\t\"Filled_Area\",\n\t\t\"Footprint\",\n\t\t\"Graphic\",\n\t\t\"Hole\",\n\t\t\"Keepin\",\n\t\t\"Keepout\",\n\t\t\"Leader\",\n\t\t\"Pad\",\n\t\t\"Physical_Layer\",\n\t\t\"Polycurve_Area\",\n\t\t\"Polygon\",\n\t\t\"Polyline\",\n\t\t\"Text\",\n\t\t\"Trace\"\n\t\t],\n\t\t\n\t\"Board_Assy\"\n\t\t:[\n\t\t\"Board_Assembly\",\n\t\t\"Board_Part_Instance\",\n\t\t\"Electrical_Part_Instance\",\n\t\t\"Mechanical_Part_Instance\",\n\t\t\"Sublayout\"\n\t\t],\n\t\t\n\t\"Default_Units\":\"" + GetBoardUnits() + "\",\n\t\"Min_Res\":\"0\",\n\t\"Notes\":\"\"\n\t}\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 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
real GetWidthFromPtString(string ptString) {
return strtod(GetFieldFromPtString(ptString, 4));
} //end sub
int LayerNumInUse(int layerNum) {
//returns true=1 if layer Is being used. returns 0 if layer Is not used.
int layerUsed = 0;
board(B)
{
B.layers(L)
{
if (L.number == layerNum) {
layerUsed = 1;
} //end if
} //layers loop
} //board loop
return layerUsed;
}
int LayerIsIDFDebug(int layerNum) {
board(B)
{
B.layers(L)
{
if (L.number == layerNum && L.name == "IDFDebug") {
return 1;
} //end if
} //layers loop
} //board loop
return 0;
}
string GetIDFDebugLayerAvailNum() {
//loop thru layers and check for name IDFDebug
int startSearchNumber = 100;
int layerAvail = -1;
for (int i = startSearchNumber; i < 256; ++i) {
//if layer Is not in use then use it. also have to check if layer Is in use but Is already idf debug
if (!LayerNumInUse(i)) {