-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathexp-lbrs.ulp
executable file
·1282 lines (1125 loc) · 39.3 KB
/
exp-lbrs.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 "en:<b>Export of libraries from a drawing.</b><p>\n"
"This can be used to make individual changes to components in a project. "
"Just load schematic, board or both, use this ULP to generate one or several libraries "
"containing the used components. Make your changes in the library/libraries and use the "
"UPDATE command to introduce the changes to schematic and/or board.<p>"
"See Help for further details.<p>",
"de:<b>Export von Bibliotheken aus einer Zeichnungsdatei.</b><p>\n"
"Damit können Sie individuelle Änderungen an Komponenten in einem Projekt machen. "
"Laden Sie dazu Schaltplan, Board oder beides, verwenden Sie dieses ULP, um eine oder mehrere Bibliotheken "
"mit den verwendeten Komponenten zu generieren. Machen Sie Ihre Änderungen in der/den Bibliothek(en) "
"und verwenden Sie den UPDATE-Befehl, um die Änderungen in Schaltplan und/oder Board zu bringen.<p>"
"Siehe Hilfe für weitere Details.<p>"
/**/
//--------------------------------------------------------------------------------
// Change log.
// Date: Note:
// 26.02.2019: Change ulp script check name from renumber-sheet.ulp to run-me-first-from-eagle-sch.ulp
// Inc version.
// Thanks to: Lachlan "lachlanusa (at) gmail.com"
// 25-Feb-2017 Inc Version number. L. A, and comment out requires 6.0301
// 23-Feb-2017 Inc Version number. L. A
// 09-Oct-2015 Fix layers for limted version of Eagle L. A.
// 25-Aug-2015 Fix space in Path problem, for windows by adding ' ' L. A.
// 31-Jul-2015 Fix some spelling mistakes. L. A.
// 28-Jul-2015 Fix a number of problems where, Pin and pads over lap, and add error reporting log file.
// 13-Mar-2015 Add more help to info boxs. L. A.
// 10-Feb-2015 Change hooks to work the other conversion programs. L. A.
//
//#require 6.0301
#include "eagle_to_kicad_include.inc"
//
string Version = "6.81";
int TEMP_HOLD_FOR_OVER_LAPPING_PIN = 19180; // Temporary of the symbol editor when we have overlapping pins to deal with
int TEMP_HOLD_FOR_OVER_LAPPING_SMD_PAD = 19180; // Temporary of the symbol editor when we have overlapping hole/smd pads to deal with
string infoCombineLibNames = "Combine all the separate Eagle libraries into one KiCad library<br>"+
"This makes the conversion proccess easy and faster,<br>"+
"<b>but means that you lose tack of which parts<br>"+
"come from which Eagle library</b><br>";
string infoLibNameToSymbolPackageDevice = "When combining libraries it is helpful to add the library name<br>"+
"to Part/Device/Footprint to reduce the name conflict if more than<br>"+
"one part has the same name from different libraries";
//
//
// Language:
//----------
// Please keep to alphabetic sorting for maintainability !
string Dictionary[] = {
"en\v"
"de\v",
"Back\v"
"Zurück\v",
"Cancel\v"
"Abbrechen\v",
"Creation mode\v"
"Erzeugungsmodus\v",
"&Browse\v"
"&Durchsuchen\v",
"Export EAGLE libraries - Help\v"
"Export von EAGLE-Bibliotheken - Hilfe\v",
"Export EAGLE libraries from drawing\v"
"Export von EAGLE-Bibliotheken aus der Zeichnung\v",
"Export original libraries\v"
"Original-Bibliotheken exportieren\v",
"File \v"
"Datei \v",
"Help\v"
"Hilfe\v",
"Load\v"
"Laden\v",
"Merge to one library, \v"
"In eine Bibliothek integrieren, \v",
"original library names as prefix for symbol, package and device names\v"
"Original-Bibliotheksnamen als Präfix für Symbol-, Package- und Devicenamen verwenden\v",
"Path\v"
"Pfad\v",
"Please start from schematic or board editor!\v"
"Bitte starten Sie vom Schaltplan- oder Board-Editor!\v",
"Start\v"
"Start\v",
"unchanged symbol, package and device names\v"
"Symbol-, Package- und Devicenamen unverändert\v"
};
string DlgLang = language();
if (DlgLang != "de") DlgLang = "en";
int LangIdx = strstr(Dictionary[0], DlgLang) / 3;
// Translate, based on dictionary
string TR(string s) {
string t = lookup(Dictionary, s, LangIdx, '\v');
return t ? t : s;
}
//-----------------------------------------------------------------------------
// Used in DrawText
string AlignName[];
AlignName[ALIGN_BOTTOM_LEFT] = "BOTTOM LEFT";
AlignName[ALIGN_BOTTOM_CENTER] = "BOTTOM CENTER";
AlignName[ALIGN_BOTTOM_RIGHT] = "BOTTOM RIGHT";
AlignName[ALIGN_CENTER_LEFT] = "CENTER LEFT";
AlignName[ALIGN_CENTER] = "CENTER CENTER";
AlignName[ALIGN_CENTER_RIGHT] = "CENTER RIGHT";
AlignName[ALIGN_TOP_LEFT] = "TOP LEFT";
AlignName[ALIGN_TOP_CENTER] = "TOP CENTER";
AlignName[ALIGN_TOP_RIGHT] = "TOP RIGHT";
string Croute[];
Croute[CONTACT_ROUTE_ALL] = "ALL";
Croute[CONTACT_ROUTE_ANY] = "ANY"; // 2012-09-26
// Used in DrawDimension
string DimType[];
DimType[DIMENSION_PARALLEL] = "PARALLEL";
DimType[DIMENSION_HORIZONTAL] = "HORIZONTAL";
DimType[DIMENSION_VERTICAL] = "VERTICAL";
DimType[DIMENSION_RADIUS] = "RADIUS";
DimType[DIMENSION_DIAMETER] = "DIAMETER";
DimType[DIMENSION_ANGLE] = "ANGLE";
DimType[DIMENSION_LEADER] = "LEADER";
string UnitName[];
UnitName[GRID_UNIT_MIC] = "MIC";
UnitName[GRID_UNIT_MM] = "MM";
UnitName[GRID_UNIT_MIL] = "MIL";
UnitName[GRID_UNIT_INCH] = "INCH";
string x[] = { " " };
string CurrentLbrName = "";
string EditName = "";
string h, cmd = "";
string ScriptName, PureScriptName;
string WorkPath;
string Status = "";
int n;
int NameIndex = 0;
int Merge = 0;
int AddLibPrefix = 0;
int ConflictPartsCount = 0;
//int OverWrieNoWarning = 0;
//string myULP_HOME = EAGLE_HOME + '/';
string myULP_HOME = "";
char ascii127[] = { 181, 196, 214, 220, 223, 0 }; // not allowed character 2010-05-12
// www: In 8859-1 these chars are { µ ,Ä ,Ö, Ãœ, ß } and therefore actually allowed as object names.
// Change this if requested ! What's also allowed but deprecated is { ä, ö, ü }. Should be replaced
// by { Ä, Ö, Ü }. All other chars allowed for file names are allwoed also for object names.
// Lower case is automatically converted to upper case (except the umlauts).
string Newascii127[] = { "U", "AE", "OE", "UE", "SS", "" }; // change to allowed character
string HelpText[] = {
"The library export collects the devices or packages from a schematic or board and stores them back "
"into one or several libraries."
"<p>"
"By default all contained libraries are exported with their original name into the drawing path."
"Thus you can edit symbols and/or packages in these libraries and "
"use the UPDATE command to change all respective parts in schematic or board."
"<p>"
"Alternatively all objects can be merged into a single library with the name of the schematic or board."
"You can choose between using the names of the original libraries as prefix for package, symbol and device names or not."
"Not using these prefixes can lead to ambiguities and therefore is not recommended."
"<p>"
"The export path can be adjusted by 'Browse' to select a directory."
"If one of the library files to be created already exists, you will be prompted if "
"the existing file may be deleted."
,
"Der Bibliotheks-Export sammelt Devices und Packages eines Schaltplans oder Boards und speichert "
"sie in eine oder mehrere Bibliotheken."
"<p>"
"Standardmässig werden alle enthaltenen Bibliotheken mit ihrem Orignialnamen in den Pfad der Zeichnungsdatei(en) "
"exportiert. So können Sie Symbole und/oder Packages editieren und mit dem UPDATE-Befehl alle entsprechenden "
"Bauteile in Schaltplan und Board aktualisieren."
"<p>"
"Alternativ können alle Objekte in eine einzige Bibliothek mit Schaltplan- bzw. Boardnamen integriert werden. "
"Sie können wählen, ob Sie die Namen der Original-Bibliotheken als Präfix für die Package-, Symbol- und Devicenamen verwenden "
"oder nicht. Diese Präfixe nicht zu verwenden kann zu Mehrdeutigkeit führen und wird daher nicht empfohlen."
"<p>"
"Der Export-Pfad kann mit 'Durchsuchen' eingestellt werden. "
"Wenn eines der Bibliotheken bereits existiert, werden Sie gefragt, ob die bestehende Datei gelöscht werden darf."
};
int PinX[]; // space for checking over lapping x/y
int PinY[];
string Pname[]; // Name of the overlap
int overLappingPinErrorCount = 0;
int waring_count = 0;
int error_count = 0;
string logfile; // log file
string logfileName;
string checkFor_bad = "";
string checkFor_badPostion = "";
//------------------------------------------------------
// Replaces all occurrences of a character in a string with a string
//------------------------------------------------------
string charstr_replace(string search, string replace, string subject)
{
int lastpos = 0;
int pos = 0;
string before;
string after;
for( pos = 0; pos < strlen(search); pos++ )
{
lastpos = 0;
while( (( lastpos = strchr( subject, search[ pos ], lastpos)) != -1 ))
{
before = strsub(subject, 0, lastpos); // get the before string
after = strsub(subject, lastpos + 1, strlen(subject) - lastpos );
subject = before + replace + after;
lastpos = strlen(before) + strlen( replace ); //
}
}
return subject;
}
// Check for Bad Characters
// Return int count of bad characters.
// and set
// string checkFor_bad: list of bad characters"";
// string checkFor_badPostion: postion of bad character;
//
int checkForBadCharstr( string search, string subject)
{
int lastpos = 0;
int pos = 0;
int badcount = 0;
checkFor_badPostion = subject;
checkFor_bad = "";
// space fill string
for( pos = 0; pos < strlen( subject ); pos++ )
checkFor_badPostion[pos] = ' ';
for( pos = 0; pos < strlen(search); pos++ )
{
lastpos = 0;
while( (( lastpos = strchr( subject, search[ pos ], lastpos)) != -1 ))
{
checkFor_badPostion[ lastpos ] = search[ pos ];
checkFor_bad += search[ pos ];
badcount++;
if ( ++lastpos > strlen(subject))
return badcount;
}
}
return badcount;
}
// *******************************************
//
// Output a string to a file.
// openOverWriteCreateAppendMode sets options
// openOverWriteCreateAppendMode = 0, Append to a existing file only, returns -2 if the file is not found.
// openOverWriteCreateAppendMode = 1, Append to a existing file or create a new file if it does exist.
// openOverWriteCreateAppendMode = 2, Over write a existing file or create a new file if it does exist.
// binaryText ='B' or 'b' for output binary mode
// binaryText ='T' or 't' for output binary text mode
// returns -1 if input error
// or -2 if no file found
// or output of file error, which I have no idea what it will be, just if 0, then write was ok.
//
int outputStringToFile( string fileName, string outputString, char openOverWriteCreateAppendMode, char binaryText )
{
string fa[];
int n;
string mode = "Ft";
fileerror();
switch( binaryText )
{
case 't':
case 'T':
mode = "Ft";
break;
case 'b':
case 'B':
mode = "Fb";
break;
default:
return -1;
}
switch( openOverWriteCreateAppendMode )
{
case 0:
if( fileglob( fa, fileName ) == 0 )
return -2;
mode += "a";
break;
case 1:
mode += "a";
break;
case 2:
mode += "w";
break;
default:
return -1;
}
// Out put the data to fileName
output( fileName, mode )
{
printf("%s", outputString );
n = fileerror();
}
return n;
}
// **************
// check for overlapping pins
//
int check_overlap( UL_PIN P, int pincount )
{
int i;
PinX[ pincount ] = P.x;
PinY[ pincount ] = P.y;
Pname[ pincount ] = P.name;
for( i = 0; i < pincount; i++ )
{
if( ( PinX[ i ] == P.x ) && ( PinY[ i ] == P.y ))
{
overLappingPinErrorCount++;
return i+1;
}
}
return 0;
}
//
// Wright log file.
//
void wright_log_to_disk( string logdata )
{
// logfile = filesetext(EditName, "");
logfileName = WorkPath + filesetext( EditName, "_conversion_log.txt");
output( logfileName, "at")
printf("%s", logdata );
}
// Wright comand file -----------
void show_save_script_file(string cm) {
ScriptName = WorkPath+PureScriptName;
output(ScriptName, "wtD") printf("%s", cm);
return;
}
void DisplayHelp() {
dlgDialog(TR("Export EAGLE libraries - Help")) {
dlgHBoxLayout dlgSpacing(400);
dlgTextView(HelpText[LangIdx]);
dlgHBoxLayout {
dlgStretch(1);
dlgPushButton("+" + TR("Back")) dlgReject();
dlgStretch(1);
}
};
}
string get_project_path() {
if (board) board(B) return(filedir(B.name));
if (schematic) schematic(B) return(filedir(B.name));
if (library) library(B) return(filedir(B.name));
}
string replacenewline(string nl) {
string a[];
int n = strsplit(a, nl, '\n');
if (n > 0) {
nl = "";
for (int x = 0; x < n - 1; x++) {
nl += a[x] + "\\n";
}
nl += a[x];
}
return nl;
}
// Da der ganze String in ' eingeschlossen wird,
// müssen die Apostrophen verdoppelt werden.
string addApostroph(string name) { // 2012-03-23
string t[];
int cnt = strsplit(t, name, '\''); // check Apostroph
if (cnt > 1) {
name = "";
for (int i = 0; i < cnt; i++) {
if (i == 0) {
if (t[i]) name += t[i];
}
else if (i) name += "''" + t[i];
}
}
return name;
}
string replaceascii127(string s, int n, string newascii) {
if (n == strlen(s)) return strsub(s, 0, n) + newascii;
else return strsub(s, 0, n) + newascii + strsub(s, n+1);
}
string check_ascii127(string s) { // 2009-02-02
int n = 0;
int pos;
do {
pos = strchr(s, ascii127[n]);
if (pos > -1)
s = replaceascii127(s, pos, Newascii127[n]);
if (pos < 0) n++; // 2012-02-08
} while (ascii127[n]);
return s;
}
// Remove this as soon as the "@-problem" is solved !
string ReplaceAt(string s) {
for (int i = 0; i < strlen(s); i++)
if (s[i]=='@') s[i]='$'; // Creates problems when name is used in ADD and other commands
return s;
}
string ReplaceInvalidCharsForObjNames(string s) {
for (int i = 0; i < strlen(s); i++)
if (s[i]==' ') s[i]='-'; // No '_' to distinguish from prefix ending !
return ReplaceAt(s);
}
string LbrPrefix(string s) {
s = check_ascii127(s);
return ReplaceInvalidCharsForObjNames(s) + "_";
}
//
// check for existing file
// Returns 1 if found.
//
int exist_file(string FileName)
{
string a[];
int n = fileglob(a, FileName);
if (n == 0) return 0;
else return 1;
}
void CreateLBRdescription(string project_name) {
// !!! Wird nicht vorherige Description überschrieben ?
sprintf(h, "DESCRIPTION 'Generated from <b>%s</b><p>\\n\\\nby %s';\n", filename(project_name), filename(argv[0]));
cmd += h;
return;
}
//******
void CreateHeader(UL_LIBRARY LBR) {
int layerCt = 1;
LBR.layers(L) {
if( (layerCt < 2) || (layerCt > 15 ) ) // ok funny biz for limited free version of eagle
{
sprintf(h, "Layer %d %s;\n", L.number, L.name);
cmd += h;
}
layerCt++;
}
sprintf(h, "Set Wire_bend 2;\nSet Select_factor 0;\nSet Undo_log off;\n"); cmd += h;
sprintf(h, "Grid mic 1;\n"); cmd += h;
sprintf(h, "Display All;\n"); cmd += h;
cmd += "DESCRIPTION '" + addApostroph(replacenewline(LBR.description)) + "';\n";
}
void CreateTrailer(void) {
sprintf(h, "Set Undo_log On;\nSet Select_factor 0.02;\nGrid last;\n"); cmd += h;
}
void PrintValidLayer(int LNr) {
sprintf(h, "Layer %d;\n", LNr); cmd += h;
}
void DrawDimension(UL_DIMENSION D) { // 2011-12-06
sprintf(h, "CHANGE LAYER %d;\n", D.layer); cmd += h;
sprintf(h, "CHANGE SIZE %f;\n", u2mic(D.size)); cmd += h;
sprintf(h, "CHANGE RATIO %d;\n", D.ratio); cmd += h;
sprintf(h, "CHANGE DUNIT %s %s %d;\n", UnitName[D.unit], (D.visible==0) ? "off" : "on", D.precision); cmd += h;
sprintf(h, "CHANGE DLINE %f %f %f %f;\n", u2mic(D.width), u2mic(D.extwidth), u2mic(D.extlength), u2mic(D.extoffset)); cmd += h;
sprintf(h, "DIMENSION %s (C%f %f) (%f %f) (%f %f);\n", // Warum das C ?
DimType[D.dtype],
u2mic(D.x1), u2mic(D.y1),
u2mic(D.x2), u2mic(D.y2),
u2mic(D.x3), u2mic(D.y3) );
cmd += h;
return;
}
void DrawFrame(UL_FRAME F) {
PrintValidLayer(F.layer);
string FBorder = "";
if (F.border & 1) FBorder += " BOTTOM";
if (F.border & 2) FBorder += " RIGHT";
if (F.border & 4) FBorder += " TOP";
if (F.border & 8) FBorder += " LEFT";
sprintf(h, "FRAME %d %d %s (%f %f) (%f %f);\n",
F.columns, F.rows,
FBorder,
u2mic(F.x1), u2mic(F.y1),
u2mic(F.x2), u2mic(F.y2) );
cmd += h;
return;
}
void DrawCircle(UL_CIRCLE C) {
PrintValidLayer(C.layer);
sprintf(h, "Circle %f (%f %f) (%f %f);\n",
u2mic(C.width),
u2mic(C.x), u2mic(C.y),
u2mic(C.x + C.radius), u2mic(C.y));
cmd += h;
return;
}
void DrawWire(UL_WIRE W) {
PrintValidLayer(W.layer);
if (W.arc) { // 2008-09-11
sprintf(h, "WIRE %f %s (%f %f) %+f (%.f %.f);\n",
u2mic(W.width),
W.cap == CAP_ROUND ? "ROUND" : "FLAT", // 2011-09-07
u2mic(W.x1), u2mic(W.y1),
W.curve,
u2mic(W.x2), u2mic(W.y2));
cmd += h;
}
else {
sprintf(h, "Wire %f (%f %f) (%f %f);\n",
u2mic(W.width), u2mic(W.x1), u2mic(W.y1), u2mic(W.x2), u2mic(W.y2));
cmd += h;
}
}
void DrawRectangle(UL_RECTANGLE R) {
PrintValidLayer(R.layer);
sprintf(h, "Rect R%.1f (%f %f) (%f %f);\n",
R.angle,
u2mic(R.x1), u2mic(R.y1),
u2mic(R.x2), u2mic(R.y2));
cmd += h;
}
//
// Draw contact and SMD pad
//
void DrawContact(UL_CONTACT C) {
string ShapeString;
string ShapeFlag;
if (C.pad) {
switch(C.pad.shape[17]) { //!!!
case PAD_SHAPE_SQUARE : ShapeString = "Square"; break;
case PAD_SHAPE_ROUND : ShapeString = "Round"; break;
case PAD_SHAPE_OCTAGON : ShapeString = "Octagon"; break;
case PAD_SHAPE_LONG : ShapeString = "Long"; break;
case PAD_SHAPE_OFFSET : ShapeString = "Offset"; break;
}
if (!(C.pad.flags & PAD_FLAG_STOP) ) ShapeFlag = "NOSTOP ";
if (!(C.pad.flags & PAD_FLAG_THERMALS) ) ShapeFlag += "NOTHERMALS ";
if ((C.pad.flags & PAD_FLAG_FIRST) ) ShapeFlag += "FIRST "; // 22.11.2004 support@cadsoft
//
// PAD [diameter] [shape] [orientation] [flags] ['name'] *..
//
sprintf(h, "Change Drill %f;\n", u2mic(C.pad.drill)); cmd += h;
sprintf(h, "Pad %f %s R%.1f %s '%s' (%f %f);\n",
u2mic(C.pad.diameter[17]),
ShapeString,
C.pad.angle,
ShapeFlag,
addApostroph(C.pad.name), // 2012-03-29
u2mic(C.pad.x), u2mic(C.pad.y));
cmd += h;
}
else if (C.smd) {
if (!(C.smd.flags & PAD_FLAG_STOP) ) ShapeFlag = "NOSTOP ";
if (!(C.smd.flags & SMD_FLAG_THERMALS) ) ShapeFlag += "NOTHERMALS ";
if (!(C.smd.flags & SMD_FLAG_CREAM) ) ShapeFlag += "NOCREAM ";
PrintValidLayer(C.smd.layer);
sprintf(h, "CHANGE Roundness %d;\n", C.smd.roundness); cmd += h;
//
// SMD [x_width y_width] [-roundness] [orientation] [flags] ['name'] *..
//
// sprintf(h, "SMD %f %f -%d R%.1f %s '%s' (%f %f);\n", u2mic(C.smd.dx), u2mic(C.smd.dy), C.smd.roundness, C.smd.angle, ShapeFlag, addApostroph(C.smd.name), u2mic(C.smd.x), u2mic(C.smd.y));
sprintf(h, "SMD %f %f -%d R%.1f %s '%s' (%f %f);\n", u2mic(C.smd.dx), u2mic(C.smd.dy), C.smd.roundness, C.smd.angle, ShapeFlag, addApostroph(C.smd.name), u2mic( TEMP_HOLD_FOR_OVER_LAPPING_SMD_PAD ), u2mic( TEMP_HOLD_FOR_OVER_LAPPING_SMD_PAD ));
cmd += h;
sprintf(h, "move (%f %f)(%f %f);\n", u2mic( TEMP_HOLD_FOR_OVER_LAPPING_SMD_PAD ), u2mic( TEMP_HOLD_FOR_OVER_LAPPING_SMD_PAD ), u2mic( C.smd.x ), u2mic( C.smd.y ));
cmd += h;
}
}
void DrawText(UL_TEXT T) {
PrintValidLayer(T.layer);
switch(T.font) {
case FONT_VECTOR : sprintf(h, "CHANGE FONT VECTOR;\n");
cmd += h;
break;
case FONT_PROPORTIONAL : sprintf(h, "CHANGE FONT PROPORTIONAL;\n");
cmd += h;
break;
case FONT_FIXED : sprintf(h, "CHANGE FONT FIXED;\n");
cmd += h;
break;
}
string Spin = "";
string Mirror = "";
if (T.spin) Spin = "S";
if (T.mirror) Mirror = "M";
sprintf(h, "Change Size %f;\n", u2mic(T.size));
cmd += h;
sprintf(h, "Change Ratio %d;\n", T.ratio);
cmd += h;
sprintf(h, "Change Align %s;\n", AlignName[T.align]);
cmd += h;
sprintf(h, "Change Linedistance %d;\n", T.linedistance);
cmd += h;
sprintf(h, "Text %s%sR%.1f '%s' (%f %f);\n",
Spin, Mirror, T.angle, addApostroph(T.value), u2mic(T.x), u2mic(T.y) // AddApostroph ?
);
cmd += h;
}
void DrawHole(UL_HOLE H) {
sprintf(h, "Change Drill %f;\n", u2mic(H.drill)); cmd += h;
sprintf(h, "Hole (%f %f);\n", u2mic(H.x), u2mic(H.y)); cmd += h;
}
void DrawPolygon(UL_POLYGON PL) {
PrintValidLayer(PL.layer);
//sprintf(h, "Change Isolate %f;\n", u2mic(PL.isolate)); cmd += h; exist only in board
sprintf(h, "Change Spacing %f;\n", u2mic(PL.spacing)); cmd += h;
if (PL.pour == POLYGON_POUR_SOLID) {
sprintf(h, "Change Pour Solid;\n"); cmd += h;
}
else {
sprintf(h, "Change Pour Hatch;\n"); cmd += h;
}
sprintf(h, "Polygon %f ", u2mic(PL.width)); cmd += h;
PL.wires(W) {
sprintf(h, "(%f %f) ", u2mic(W.x1), u2mic(W.y1)); cmd += h; /*start coord.*/
break;
}
PL.wires(W) {
sprintf(h, " %+f (%f %f) ", W.curve, u2mic(W.x2), u2mic(W.y2)); cmd += h;
}
sprintf(h, ";\n"); cmd += h;
}
//
// Draw pin command
int DrawPin(UL_PIN P, int printhead, int error, string symbol_name )
{
string DIR = "", FUNC = "", LEN = "", VIS = "", ANGLE = "R0";
if (P.angle == 90) (ANGLE = "R90");
if (P.angle == 180) (ANGLE = "R180");
if (P.angle == 270) (ANGLE = "R270");
if (P.function == PIN_FUNCTION_FLAG_NONE) (FUNC = "None");
if (P.function == PIN_FUNCTION_FLAG_DOT) (FUNC = "Dot");
if (P.function == PIN_FUNCTION_FLAG_CLK) (FUNC = "Clk");
if (P.function == (PIN_FUNCTION_FLAG_DOT | PIN_FUNCTION_FLAG_CLK))
(FUNC = "DotClk");
if (P.visible == PIN_VISIBLE_FLAG_OFF) (VIS = "Off");
if (P.visible == PIN_VISIBLE_FLAG_PIN) (VIS = "Pin");
if (P.visible == PIN_VISIBLE_FLAG_PAD) (VIS = "Pad");
if (P.visible == (PIN_VISIBLE_FLAG_PIN | PIN_VISIBLE_FLAG_PAD))
(VIS = "Both");
switch(P.direction) {
case PIN_DIRECTION_NC : DIR = "NC"; break;
case PIN_DIRECTION_IN : DIR = "In"; break;
case PIN_DIRECTION_OUT : DIR = "Out"; break;
case PIN_DIRECTION_IO : DIR = "IO"; break; // 2011-10-10
case PIN_DIRECTION_OC : DIR = "OC"; break;
case PIN_DIRECTION_PWR : DIR = "Pwr"; break;
case PIN_DIRECTION_PAS : DIR = "Pas"; break;
case PIN_DIRECTION_HIZ : DIR = "Hiz"; break;
case PIN_DIRECTION_SUP : DIR = "Sup";
}
switch(P.length) {
case PIN_LENGTH_POINT : LEN = "Point"; break;
case PIN_LENGTH_SHORT : LEN = "Short"; break;
case PIN_LENGTH_MIDDLE : LEN = "Middle"; break;
case PIN_LENGTH_LONG : LEN = "Long";
}
if( error )
{
string xt;
sprintf(h, "Pin '%s' %s %s %s %s %s %d (%f %f);\n", addApostroph( P.name ), DIR, FUNC, LEN, ANGLE, VIS, P.swaplevel, u2mic( TEMP_HOLD_FOR_OVER_LAPPING_PIN ), u2mic( TEMP_HOLD_FOR_OVER_LAPPING_PIN ));
cmd += h;
sprintf(h, "move (%f %f)(%f %f);\n", u2mic( TEMP_HOLD_FOR_OVER_LAPPING_PIN ), u2mic( TEMP_HOLD_FOR_OVER_LAPPING_PIN ), u2mic(P.x), u2mic(P.y));
cmd += h;
if( !printhead )
{
sprintf(xt, "\nWARNING: Over lapping Pin(s) on SYMBOL:%s", symbol_name );
logfile += xt;
}
sprintf(xt, "\n Pin =%s", addApostroph( P.name ));
logfile += xt;
printhead = 1;
return 1;
// outputStringToFile( logfile, "\nWORNING OVER LAPPING PIN: " + xt, 1, 't');
}
else
sprintf(h, "Pin '%s' %s %s %s %s %s %d (%f %f);\n", addApostroph( P.name ), DIR, FUNC, LEN, ANGLE, VIS, P.swaplevel, u2mic(P.x), u2mic(P.y));
cmd += h;
return printhead;
}
void DrawSymbol(UL_SYMBOL S) {
int pinCount = 0;
int error_ofsetX = 1;
int error_ofsetY = 1;
int ofsetX;
int ofsetY;
int printheader = 0;
S.circles(C)
DrawCircle(C);
printheader = 0;
S.rectangles(R)
DrawRectangle(R);
printheader = 0;
S.wires(W)
DrawWire(W);
pinCount = 0;
printheader = 0;
S.pins(P)
{
if( check_overlap( P, pinCount ))
{
printheader = DrawPin(P, printheader, 1, S.name );
}
else
DrawPin(P, printheader, 0, "" );
pinCount++;
}
printheader = 0;
S.texts(T) DrawText(T);
S.polygons(PL) DrawPolygon(PL);
S.frames(F) DrawFrame(F);
S.dimensions(D) DrawDimension(D);
cmd += "DESCRIPTION '" + addApostroph(replacenewline(S.description)) + "';\n";
}
void DrawPackage(UL_PACKAGE P) {
sprintf(h, "GRID mic;\n"); cmd+=h; // 2011-04-11
P.circles(C)
DrawCircle(C);
P.wires(W)
DrawWire(W);
P.rectangles(R)
DrawRectangle(R);
P.contacts(C)
DrawContact(C);
P.texts(T)
DrawText(T);
P.holes(H)
DrawHole(H);
P.polygons(PL)
DrawPolygon(PL);
P.frames(F)
DrawFrame(F);
P.dimensions(D)
DrawDimension(D);
cmd += "DESCRIPTION '" + addApostroph(replacenewline(P.description)) + "';\n";
}
// ************************************************
// see also *** export-schematic_mil-board_mm-script.ulp ***
// ************************************************
void DrawDevice(UL_DEVICESET D, UL_LIBRARY LBR) {
cmd += "DESCRIPTION '" + addApostroph(replacenewline(D.description)) + "';\n";
cmd += "PREFIX '" + D.prefix + "';\n";
cmd += "VALUE " + D.value + ";\n";
D.gates(G)
{
string GateAddlevel;
switch (G.addlevel) {
case GATE_ADDLEVEL_NEXT : GateAddlevel = "Next"; break;
case GATE_ADDLEVEL_MUST : GateAddlevel = "Must"; break;
case GATE_ADDLEVEL_CAN : GateAddlevel = "Can"; break;
case GATE_ADDLEVEL_REQUEST : GateAddlevel = "Request"; break;
case GATE_ADDLEVEL_ALWAYS : GateAddlevel = "Always";
};
sprintf(h, "CHANGE Addlevel %s;\n", GateAddlevel); cmd += h;
sprintf(h, "CHANGE Swaplevel %d;\n", G.swaplevel); cmd += h;
string symname = G.symbol.name; // No problem with @...
if( AddLibPrefix == 1) // if (Merge == 1)
symname = LbrPrefix(LBR.name) + symname;
sprintf(h, "ADD '%s' '%s' (%f %f);\n", addApostroph(symname), addApostroph(G.name), u2mic(G.x), u2mic(G.y)); // 2012-02-07
cmd += h;
}
D.devices(DV)
{
int result;
string tmpS;
if (DV.package) {
string pacname = ReplaceAt(DV.package.name); // !!!
if( AddLibPrefix == 1) //if (Merge == 1)
pacname = LbrPrefix(LBR.name) + pacname;
if( result = checkForBadCharstr( "()", DV.name ))
{
error_count++;
sprintf( tmpS, "\n%s%s%s", "ERROR: package name:", pacname," Has Bad/illegal charter in it's package Alisa name!\n");
logfile += tmpS;
sprintf( tmpS, "\n%s%s", " Package Alaise Name:", DV.name);
logfile += tmpS;
sprintf( tmpS, "\n%s%s", " Error Postion & Char:", checkFor_badPostion );
logfile += tmpS;
sprintf( tmpS, "\n%s", " Bad charter(s) have been replaced with '_' This MAY FIX OR, CAUSE MORE ERROR'S! Plese fix the Alias!\n");
logfile += tmpS;
cmd += ("PACKAGE '" + addApostroph(pacname) + "' " + charstr_replace("()", "_", DV.name ) + ";\n"); // addApostroph here problematic !
}
else
cmd += "PACKAGE '" + addApostroph(pacname) + "' " + DV.name + ";\n"; // addApostroph here problematic !
}
DV.gates(G) {
if (DV.package) {
G.symbol.pins(P) {
string cont = "";
P.contacts(C) { // 2011-12-06
if (!cont) sprintf(h, "%s", addApostroph(C.name)); // 2012-03-29
else sprintf(h, " %s", addApostroph(C.name)); // 2012-003-29
cont += h;
}
if (cont) {
sprintf(h, "CONNECT %s '%s.%s' '%s';\n", // //2012-03-23 problem with # in pin name
Croute[P.route],
addApostroph(G.name), // 2012-03-29
addApostroph(P.name), // 2012-03-29
cont
);
cmd += h;
}
}
}
}
string t[];
int n = strsplit(t, DV.technologies, ' ');
for (int i = 0; i < n; i++) {
sprintf(h,"TECHNOLOGY '%s';\n", addApostroph(t[i])); // 2012-03-23
cmd += h;
DV.attributes(A, t[i]) {
string const = "";
if (A.constant) const = " CONSTANT";
sprintf(h,"ATTRIBUTE '%s' '%s' %s\n", A.name, addApostroph(A.value), const); // 2010-10-14
cmd += h;
}
}
}
return;
}
//----------------
int is_new(void) { // n = nr of entries
int i;
if (n == 0) return 1;
for (i = 0; i < n; i++) {
if (x[n] == x[i]) {
return(0);
}
}
return 1;
}
// ---------
void CreateOneLibHeader(UL_LIBRARY LBR, string project_name) {
if (exist_file(WorkPath+CurrentLbrName+".lbr")) {
sprintf(h, "REMOVE '%s';\n", WorkPath+CurrentLbrName+".lbr"); cmd += h; // delete existing lbr
}
sprintf(h, "OPEN '~dummy~.lbr';\nCLOSE;\nOPEN '%s.lbr';\n", WorkPath+CurrentLbrName); // 2012-02-07 to close an opened library first
cmd += h;
CreateHeader(LBR);
CreateLBRdescription(project_name);
}
// ---------
void OutputPackages(UL_LIBRARY LBR) {
LBR.packages(P) {
string pacname = ReplaceAt(P.name);
if( AddLibPrefix == 1) // if ( Merge == 1)
pacname = LbrPrefix(LBR.name) + pacname;
n++;
x[n] = pacname;
if (is_new()) {
Status = " PAC: " + P.name; dlgRedisplay();
sprintf(h, "\nEdit '%s.PAC';\n", addApostroph(pacname)); cmd += h;
DrawPackage(P);
}
}
}
void OutputSymbols(UL_LIBRARY LBR) {
LBR.symbols(S) {
string symname = S.name;
if( AddLibPrefix == 1) // if (Merge == 1)
symname = LbrPrefix(LBR.name) + symname;
n++;
x[n] = symname;
if (is_new()) {
Status = " SYM: " + S.name; dlgRedisplay();
sprintf(h, "\nEdit '%s.SYM';\n", addApostroph(symname)); cmd += h;
DrawSymbol(S);
}
}
}
void OutputDevices(UL_LIBRARY LBR) {
LBR.devicesets(D) {
string dname = D.name;
if( AddLibPrefix == 1) // if (Merge == 1)
dname = LbrPrefix(LBR.name) + dname;
n++;
x[n] = dname;
if (is_new()) {
Status = " DEV: " + D.name; dlgRedisplay();
NameIndex = 0;
sprintf(h, "\nEdit '%s.DEV';\n", addApostroph(dname)); cmd += h;
DrawDevice(D, LBR);
}
}
}
//----------------------------------
// Make one lib file script command
void CreateLbr(UL_LIBRARY LBR) {
if (exist_file(WorkPath+CurrentLbrName+".lbr")) {
sprintf(h, "REMOVE '%s.lbr';\n", WorkPath+CurrentLbrName);
cmd += h; // delete existing lbr
}
sprintf(h, "OPEN '~dummy~.lbr';\nCLOSE;\nOPEN '%s.lbr';\n", WorkPath+CurrentLbrName); // 2012-02-07 to close a opened library first
cmd += h;
CreateHeader(LBR);
}
//-------------------------------
// Make seprate libs
//
void make_lbr(void) {
// dlgMessageBox("got here 1");
if (board) board(B)
{
int first = 1;
B.libraries(LBR)
{
CurrentLbrName = LBR.name;
if( (Merge == 1 ) && first) // Only output lib once if merged lib
{