-
Notifications
You must be signed in to change notification settings - Fork 16
/
eagle-lbr2kicad-1.0.ulp
3029 lines (2616 loc) · 104 KB
/
eagle-lbr2kicad-1.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>KiCad library and module exporting tool, version 2.3</b>\n"
"<p>"
"This ULP exports Eagle Package and Symbol contents into KiCad library and module formats."
"<p>"
"Load any library and execute the ULP."
"<p>"
"<author>Author: Dmitri N. Sytov sdn (at) openhardware.ru</author>"
"<author>Author: juergen.messerer (at) freesurf.ch</author>"
"<author>Author: \"lachlanusa (at) gmail.com\"</author>"
//#require 6.0000
//#require 5.0000
#include "eagle_to_kicad_include.inc"
/*
* CHANGELOG=(dd.mm.yyyy)===============================================
*
* 20-04.2017 Fixes problems double "" not being escape in "T " string
* Inc version number to 3.0
*
* 07-04.2017 Inc version number to 2.9
* Fixes problems with converting circles, holes and text
* Thanks to Paul Andrews, https://github.com/judge2005
* Remove /022 from file, and do spelling fix's, Thanks to Nathan Seidle, https://github.com/nseidle
*
* 24.02.2017 Inc version number to 2.9
* remove required 6.000, see if that fixes problem with Eagle 8.0
* set the default to not combine footprint (eaglePartToKiCadPartConversion=1), as this gives too many problems
* Thanks to: Lachlan laudasusa (at) gmail.com
*
* 10.12.2016 Inc version number to 2.7
* Thanks to: Lachlan laudasusa (at) gmail.com
*
* 10.12.2016 Mike Tepper change layer LUT and default layer
* Thanks to: Mike Tepper
*
* 07.05.2016 Fix device with no package which has more than 1 pin
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 03.05.2016 Fix F1 field to match Def field, IE remove any illegal characters.
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 03.05.2016 Fix layers in text strings so will place correctly on the layers.
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 29.04.2016 Fix logging file name, and add user option to select logging directory.
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 08.02.2016 Change Default size of F0 and F1, Reference/value to 45
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 08.02.2016 Fix over bar, on pin labels, this changes Eagle ! to KiCad ~
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 15.10.2015: Always display report file, even if no errors
* Add spacing to make window wider, 1000px, for better report display
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 12.10.2015: Check for package before printing reporting on missing prefix.
*
* 09.10.2015: Add missing prefix report Dialog
*
* 27.08.2015: Fix Power symbol to correct for KiCad Power fills, change power supply to opposite of Eagle.
* Change pin to hide when power. supply system.
*
* 19.07.2015: Fix / slash in Eagle's lib and part names and device name
* Add faster string replace/substitute sub "string charstr_replace(string search, string replace, string subject)"
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 10.02.2015: Fix add lib prefix to footprint name
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 03.02.2015: Fix Alias name, and inc version.
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 25.09.2014: Add version required, to allow us to make 2 scripts. One for 6.0+ and one for 5.0
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 06.09.2014: Fix device alias, to put in zero size string in * place holder when
* '' is found in part Technology/alias name.
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 06.09.2014: Move some code to main(), bit easy to understand!
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 05.09.2014: Inc version number to 1.1
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 05.09.2014: Try a number of fixes for part name, and ALISA list, to work better with eagle2kicad_sch.ulp
* Note there are many problems here: badly named Eagle libs will make for lots of device name collisions!
* Which will make KiCad stop loading the lib/mod!
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 26.07.2014: Fix >NAME and >VALUE in module, so Eagle text is not lost, or confused with module prefix/value
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 26.07.2014: Fix text width in module, so module text uses Eagle's text width.
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 26.07.2014: Fix Square Pad size 0 problem in module
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 14.07.2014: Add option allows combining of devices into one KiCad lib part if the pin name/number match exactly.
* Note: Pin number/name IS the deciding factor! NOT package type or package pin count.
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 12.07.2014: Add option to allows adding $PACKAGE list to KiCad where parts share a common pin references.
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 21.06.2014: Fix bug where, >NAME and >VALUE were getting past through from Eagle to kicad libs
* because they were not in upper case.
* thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 20.06.2014: Add option to Remove Text after @, this works bit like the hide after @ in Eagle SCH
* thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 20.06.2014: Fix bug in str_replace(string search, string replace, string subject
* Bug was, it did not return the original string, if the search string was not
* found, but returned the replacement string !!
* thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 12.06.2014: Fix \r \n in value import, which Eagle allows but KiCad does not like.
* also remove any other charters which are not printable
* thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 14.02.2014: - Fix "Multiple contacts on pin, use contacts() instead" error in
* Eagle 6.0 (and later) when multiple pads are connected to same pin. (caspencer)
* - Fix issue with incorrect smd/pad angles
* thanks to: Jan Phillip Willmann (jantek.willmann at gmail.com)
*
* 28.12.2012: Fixed BUG: wrong scaling of elements
* Now compatible with Eagle 6.3 and KiCad Build 2012-01-19 by Wawszczak
*
* 02.01.2012: Fixed BUGS: (that it is compatible with the new KiCad versions)
* KiCad "undefined draw command"
* KiCad "unexpected end of file / module"
*
* 01.12.2006: Little changes on the script with DEV.package. Always check if
* DEV.package exist otherwise an error will occur.
*
* 22.08.2006: - Changes made by Sergiusz Urbaniak (mieszkoman (at) gmx.de)
* - Selection of export of Pin Names and Pin Numbers
* - Prefixing each module with the Eagle library name (easier to navigate in the netlist)
* - Support of multiple units
*
* 17.07.2006: The positions of the name and the prefix are fixed for multi part devices
*
* 17.07.2006: Now the script creates any devices without packages.
* When a device has more than one part then it uses the symbol name
* for the alias "F0, F1, .."
* When it has more than one package then it use the device name
*
* 19.06.2006: Bugfix, devices with more than one package will now generate
* a device for each package
*
* 14.06.2006: Add the translation feature for multipart devices
*
* 12.06.2006: Fixed the arc problem. There is still a text position problem
*
* 08.06.2006: Now it converts also the symbol from Eagle
*
* 14.11.2005: Fixed BUGS:
* - Invalid layers in $PAD section
* - Text fields has right coords but bad align
* - Polygonal areas draws twice
* Thanks to:
* Biglacko <biglacko (at) startolj.hu>
*/
/* ==========================================================================
* License: This file is released under the license of the GNU Public license
* Version 2.
* ==========================================================================
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
real VERSION = 3.1;
string Version = "3.1";
int add_libnamePrefixToPartName = 0;
int rect_conv = 1; // many QFP-like packages use rectangles as a pin contour (too much segments in the ki-format)
int poly_conv = 1;
int holes_conv = 1;
string g_lib_prefix ;
int writePins = 0;
int drawPinNumber = 1;
int drawPinName = 1;
int outPutAlias = 1;
int outPutFootPrint = 1; // Controls the output footprint in F2
int outPutFootPrints = 1; // Controls the output footprints in $FPLIST
string footPrintList = "";
string footPrintPreFix = ""; // Prefix for footprint note maybe blank
string undefinedPartPreFix = "M";
string aliasList = ""; // list of part aliases
int wildCardPrefix = 1; // 1 = pre add * wild card to $FPLIST footprint list names
int wildPostfix = 1; // 1 = post add * wild card to $FPLIST footprint list names
int eaglePartToKiCadPartConversion = 1; // controls if we combine footprints or not, 0 = combine, 1 = don't combine
int devicesetsCount = 0;
int devicesCount = 0;
int deleteTextArfterATsysbolInPinName = 1; //Eagle dos not show any text in pin names after the @ symbol.
int deleteNameTextSCH = 1; //Delete >Name from schematic
int deleteValueTextSCH = 1; //Delete >Value from schematic
string symbolicPrefix; /*list symbolic prefix(s)(comma seperated) not to show pins or pads or Part, or symbolic prefix for. Note list format is D, C, X, V, # */
int dontShowPin = 1; //Don't show pins from symbolicPrefix list
int dontShowPad = 1; //Don't show pads from symbolicPrefix list
int dontShowPartName = 1; //Dont show part name from symbolicPrefix list
int dontShowPartValue = 1; //Dont show part name from symbolicPrefix list
string pinNamePnumberList[]; // Holds array of pin number and name + padcount
string packageNameList[]; // Holds array of package names
string packageNameListMatch[]; // Holds array of package names
string NameSCH = ">Name";
string ValueSCH = ">Value";
int RECT_WIDTH = 26;
real linMaxWidth = 10.0;
real linMinWidth = 0.01;
int limitTextLineWidth = 0;
int minMaxUnitsSelect = 0;
int minMaxUnitsSelectOld = 0;
real eagleToKiCadUnitCoversionFactor1 = 808;
real eagleToKiCadUnitCoversionFactor2 = 404;
string partlist[];
int partlistSize = 0;
string conflictPartsLibsList[];
int conflictPartsLibsListsize = 0;
int MM = 0, INCH = 1, TOINCH = 2;
string logfileName;
string logfile;
string outputPath;
string infoDeviceConversion = "<pre>Allows combining of devices into one KiCad library part if the pin name and number match exactly.<br>"+
"Note the pin number and name (not package type or the number of pins) on the package is the deciding factor.<br>"+
"If not enabled conversion will make a new KiCad library part/module for every one of Eagle<br>devices/footprint. This "+
"makes for a very large KiCad library so this gives<br>the option of combining the Eagle parts where"+
" possible to make a Kicad library.<br>There is some risk to this <br>"+
"<b><br>so it's important you check the results when using this option!</pre>";
string infoTechnologies = "Make KiCad part Aliases from the <i>Eagle</i> technologies definition in Eagle devices";
string infoLibNamePartNamePrefix = "Prefix the library name to the part name. For example: LibCapacitors_PartName";
string infoDeleArfter = "<pre>Eagle SCH/PCB will not show any characters after \'@\' in pin names<br>"+
"Checking this box will delete any characters after and including the <b>'@'</b><br>so that it won't show in KiCad</pre>";
string infoPreFixSeach = "Add a wildcard prefix '*' to each footprint in the footprint list. This allows easy footprint searching in CvPCB.";
string infoPostFixSeach = "Add a wild card post-fix '*' to each footprint in the footprint list. This allows easy footprint searching in CvPCB.";
string infoNoPrefix = "If an Eagle library part has no prefix (for example: \"U\", \"R\", \"C\", etc) then we use this letter (or letters) for the schematic part prefix";
string infoFootPrintList = "KiCad uses the footprint list to help select from the list of PCB module/footprint(s) in KiCad's module library.<br>This option controls the output, and output format"+
" given to KiCad<br>Note: This is not the same as KiCad footprint";
string infoFootPrint = "<pre>You have 2 options for the footprint name in KiCad:<br>Use the Eagle device name for the footprint name in KiCad,<br>"+
"OR prefix the Eagle library name to the Eagle device name to create the the KiCad footprint name.<br>"+
"For example: \"eagleLbrName-eagleDeviceName\".<br>"+
"Note: This is not the same as the footprint list in KiCad<br>"+
"which is used to filter the module footprints displayed in KiCad's CvPcb program.</pre>";
string infoFootPrintPrefix = "You can override the default Eagle library name which is the prefix to the KiCad footprint name.<br>Note: This program always adds '_' between the prefix name and the footprint name.";
string infoTextMaxMinValue = "<pre>You can override the text font line width size in Eagle and use the Max and Min line width which KiCad uses to draw the text"+
"For example: Any text line width which is bigger than Max line will be replaced with Max width value.<br>"+
" Any text line width which is less than Min line will be replaced with Min width value.</pre>";
string infoProgramHowTo = "This program converts an Eagle library to a KiCad library and modulde library.<br>You have a number of options to how this conversion is done.<br>"+
"<b><br>WARNING: A perfect conversion is not possible!<br> You should check the results of the conversion.</b>"+
"<pre><b><font color=red>BUGS and Warnings:<br> 1: Text can appear on any layer in Eagle libraries, whereas KiCad only allows Text on the top layer<br>"+
" This will result in all text from Eagle appearing on the top silk screen layer,<br> and mirrored text will no longer be mirrored!</pre></font>"+
"<i>This version of eagle-to-kicad is hosted on <a href=\"http://github.com/lachlanA/eagle-to-kicad/\">https://github.com/lachlanA/eagle-to-kicad</a><br>"+
"Please check this site for latest version, bug reports, and to make suggestions and/or improvements<br><i>";
// Please edit this LUT if you have found mistakes,
// and send your corrections to sdn (at) openhardware.ru.
/*
LAYER_CMP_N 15
CMP_N 15
NB_COPPER_LAYERS (CMP_N+1)
FIRST_NO_COPPER_LAYER 16
ADHESIVE_N_CU 16
ADHESIVE_N_CMP 17
SOLDERPASTE_N_CU 18
SOLDERPASTE_N_CMP 19
SILKSCREEN_N_CU 20
SILKSCREEN_N_CMP 21
SOLDERMASK_N_CU 22
SOLDERMASK_N_CMP 23
DRAW_N 24
COMMENT_N 25
ECO1_N 26
ECO2_N 27
EDGE_N 28
*/
// Lookup table for shape layers
int layer_lut[] =
{
0,
15, //LAYER_TOP
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //inner layers
16, //LAYER_BOTTOM
16, //LAYER_PADS
16, //LAYER_VIAS
21, //LAYER_UNROUTED
21, //LAYER_DIMENSION
21, //LAYER_TPLACE
20, //LAYER_BPLACE
21, //LAYER_TORIGINS
20, //LAYER_BORIGINS
21, //LAYER_TNAMES
20, //LAYER_BNAMES
21, //LAYER_TVALUES
20, //LAYER_BVALUES
23, //LAYER_TSTOP
22, //LAYER_BSTOP
19, //LAYER_TCREAM
18, //LAYER_BCREAM
21, //LAYER_TFINISH
21, //LAYER_BFINISH
21, //LAYER_TGLUE
21, //LAYER_BGLUE
21, //LAYER_TTEST
21, //LAYER_BTEST
24, //LAYER_TKEEPOUT
24, //LAYER_BKEEPOUT
21, //LAYER_TRESTRICT
21, //LAYER_BRESTRICT
21, //LAYER_VRESTRICT
21, //LAYER_DRILLS
21, //LAYER_HOLES
21, //LAYER_MILLING
21, //LAYER_MEASURES
24, //LAYER_DOCUMENT
21, //LAYER_REFERENCE
24, //LAYER_TDOCU
24, //LAYER_BDOCU
21, //LAYER_NETS
21, //LAYER_BUSSES
21, //LAYER_PINS
21, //LAYER_SYMBOLS
21, //LAYER_NAMES
21 //LAYER_VALUES
};
// Lookup table for pad layers
//CUIVRE_LAYER 0x00000001
//CMP_LAYER 0x00008000
//ADHESIVE_LAYER_CU 0x00010000
//ADHESIVE_LAYER_CMP 0x00020000
//SOLDERPASTE_LAYER_CU 0x00040000
//SOLDERPASTE_LAYER_CMP 0x00080000
//SILKSCREEN_LAYER_CU 0x00100000
//SILKSCREEN_LAYER_CMP 0x00200000
//SOLDERMASK_LAYER_CU 0x00400000
//SOLDERMASK_LAYER_CMP 0x00800000
//DRAW_LAYER 0x01000000
//COMMENT_LAYER 0x02000000
//ECO1_LAYER 0x04000000
//ECO2_LAYER 0x08000000
//EDGE_LAYER 0x10000000
//intS_LAYER 0xE0000000
//ALL_LAYERS 0x1FFFFFFF
//ALL_NO_CU_LAYERS 0x1FFF0000
//ALL_CU_LAYERS 0x0000FFFF
//INTERNAL_LAYERS 0x00007FFE
//EXTERNAL_LAYERS 0x00008001
int pad_lut[] =
{
0,
0x00008000 | 0x00800000 | 0x00080000, //LAYER_TOP
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //inner layers
0x00000001 | 0x00400000, //LAYER_BOTTOM
0x0000FFFF | 0x00C00000 | 0x000C0000, //LAYER_PADS
0x00008001 | 0x00800000 | 0x00400000, //LAYER_VIAS
0, //LAYER_UNROUTED
0, //LAYER_DIMENSION
0, //LAYER_TPLACE
0, //LAYER_BPLACE
0, //LAYER_TORIGINS
0, //LAYER_BORIGINS
0, //LAYER_TNAMES
0, //LAYER_BNAMES
0, //LAYER_TVALUES
0, //LAYER_BVALUES
0, //LAYER_TSTOP
0, //LAYER_BSTOP
0, //LAYER_TCREAM
0, //LAYER_BCREAM
0, //LAYER_TFINISH
0, //LAYER_BFINISH
0, //LAYER_TGLUE
0, //LAYER_BGLUE
0, //LAYER_TTEST
0, //LAYER_BTEST
0, //LAYER_TKEEPOUT
0, //LAYER_BKEEPOUT
0, //LAYER_TRESTRICT
0, //LAYER_BRESTRICT
0, //LAYER_VRESTRICT
0x01000000, //LAYER_DRILLS
0x01000000, //LAYER_HOLES
0x01000000, //LAYER_MILLING
0, //LAYER_MEASURES
0, //LAYER_DOCUMENT
0, //LAYER_REFERENCE
0, //LAYER_TDOCU
0, //LAYER_BDOCU
0, //LAYER_NETS
0, //LAYER_BUSSES
0x00008001 | 0x00A00000 | 0x00080000, //LAYER_PINS
0, //LAYER_SYMBOLS
0, //LAYER_NAMES
0 //LAYER_VALUES
};
//------------------------------------------------------
// Global variables
//------------------------------------------------------
string g_mod_name ;
string g_lib_name ;
real g_Fact = 254 * 32; // global uMeter to uInch conversion factor
real LibTexPosionOffset = 0.770;
real textSizeCorrectionfactor = 0.8;
string missingPrefixLog[];
int g_missingPrefix = 0; // global indicator if an Eagle devices hasn't got a prefix
string errorLog[];
int warnings_count = 0;
int errors_count = 0;
/**
* @brief Replace new line charcter with string "\n" as kicad can handle that, but not newline character
* @param textString string with newline character '\n'
* @return string with "\n" in '\n' place
*/
string stripLfCrToEscCRLF( string textString )
{
string newString;
int idx = 0;
int idx2 = 0;
for ( idx = 0; textString[idx];)
{
if( ( isspace( textString[idx] )) || ( isprint( textString[idx] )))
{
if(( textString[idx] == '\n') || ( textString[idx] == '\r' ) )
{
newString = newString + "\\n";
idx++;
idx2 = idx2 + 2;
}
else
{
newString[idx2] = textString[idx];
idx++;
idx2++;
}
}
else
{ // Ok bad chart so replace with ~
newString[idx2] = '~';
idx++;
idx2++;
}
}
return newString;
}
/**
* @brief
* @param unitConvertTo convert to unit (MM,INCH,TOINCH)
* @param unitConvertFrom convert from unit (MM,INCH,TOINCH)
* @param inputValue unit to convert
* @return converted unid
*/
real unitConver(int unitConvertTo, int unitConvertFrom, real inputValue)
{
// 0 = MM, 1 = Inch, 2 = Thousands of inch
real converversionTable0[] = {1.0, 25.4, 0.0254};
real converversionTable1[] = {0.03937007874, 1.0, 0.001};
real converversionTable2[] = {39.37007874, 1000.0, 1.0};
switch(unitConvertTo)
{
case 0: // MM
return (inputValue * converversionTable0[ unitConvertFrom ]);
break;
case 1: // INCH
return (inputValue * converversionTable1[ unitConvertFrom ]);
break;
case 2: // TOINCH
return (inputValue * converversionTable2[ unitConvertFrom ]);
break;
}
}
/**
* @brief look to layer
* @param layer layer ID
* @return Return layer ID
*/
int layer_lookup(int layer)
{
if (layer > 42) return 24;
return layer_lut[layer];
}
/**
* @brief convert internal Eagle units in 1E4*inches
* @param units internal Eagle units
* @return 1E4*inches(internal Eagle units)
*/
int egl2ki(int units)
{
real inch = u2inch(units);
return int(inch * 10000);
}
/**
* @brief check for smd pads in package
* @param PAC package
* @return if package has smd pads return true, else false
*/
int issmd(UL_PACKAGE PAC)
{
int res = 0;
PAC.contacts(C)
{
res |= C.smd ? 1 : 0;
}
return res;
}
/**
* @brief replaces all occurrences of a charter in a string with a string
* @param search character to search
* @param replace character to replace
* @param subject original string
* @return return modified 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;
}
/**
* @brief replace all occurrences of a string
* @param search string to search
* @param replace string to replace
* @param subject original string
* @return return modified string
*/
string str_replace(string search, string replace, string subject)
{
int lastpos = 0;
int pos;
string before;
string after;
// Check if there is any thing to replace
if( strstr(subject, search, lastpos) == -1)
return subject; // No so just return input string
while (strstr(subject, search, lastpos) >= 0)
{
pos = strstr(subject, search, lastpos);
before = strsub(subject, 0, pos);
after = strsub(subject, pos + strlen(search), strlen(subject) - ( pos + strlen(search)) );
subject = before + replace + after;
lastpos = pos + strlen(replace);
}
return subject;
}
/**
* @brief replace escape quotes in string
* @param input original string
* @return return modified string
*/
string escape_quotes(string input)
{
return str_replace( "\"", "\\\"", input);
}
//****
// Truncates string, from delimiter character in string
// Return truncated string
/**
* @brief Splits a string and return the first one.
* @param name original string
* @param delimiter delimited character
* @param flag if 0, return original string, else return the split string
* @return split string
*/
string stripArfterAT(string name, char delimiter, int flag)
{
string a[];
int lastpos = 0;
if(flag == 0)
return name;
// Split, if more the 1 delimiter take only the first part, if not found return with no change
if( strsplit(a, name, delimiter) >= 1 )
return a[0];
else
return name;
}
/**
* @brief transform int to string
* @param value int value
* @return string with int value
*/
string intToString( int value )
{
string tmpS;
sprintf( tmpS, "%d", value );
return tmpS;
}
/**
* @brief search for conflicting part
* @param search search part in partList
* @param offset offset in partList
* @return return "-CONFLICTING-PART-" if there is a conflict, And add to conflictPartsLibsList[] list
* else return "" if all good
*/
string partlistSearchAdd( string search, int offset )
{
int n;
if( partlistSize == 0 )
{
partlist[ partlistSize++ ] = search;
return "";
}
for( n = 0; n < partlistSize; n++ )
{
// printf("\nsearch=%s partlist[%d]=%s", search, n, partlist[n]);
// printf("search=%s partlist[%d]=%s\n", search, n, partlist[n]);
if( (strlen( search ) == 0) ) // Null search ?
return "";
if( search == partlist[ n ] )
break;
else
{
if( (n + 1) >= partlistSize )
{
partlist[ partlistSize++ ] = search;
return "";
}
}
}
conflictPartsLibsList[ conflictPartsLibsListsize++ ] = search;
return "-CONFLICTING-PART-" + intToString( conflictPartsLibsListsize ) ;
}
/**
* @brief write index of modules
* @param LIB Library
*/
void write_kikad_mod_idx(UL_LIBRARY LIB)
{
// write INDEX start tag
printf("$INDEX\n");
// write index of modules
// LIB.packages(PAC)
// {
// if ( outPutFootPrint ) // Prefix libprefix in foot print name
// printf("%s-%s\n", escape_quotes(g_lib_prefix), escape_quotes(strupr(PAC.name)));
// else
// printf("%s\n", escape_quotes(strupr(PAC.name)));
// }
if( outPutFootPrint == 0 )
LIB.packages(PAC) // Don't add lib prefix
{
printf("%s\n", charstr_replace(",/", "_", escape_quotes(strupr(PAC.name))));
// printf("%s\n", str_replace( ",", "_", escape_quotes(strupr(PAC.name))));
}
else
LIB.packages(PAC) // Add lib prefix
{
printf("%s-%s\n", escape_quotes(g_lib_prefix), charstr_replace(",/", "_", escape_quotes(strupr(PAC.name))));
// printf("%s-%s\n", escape_quotes(g_lib_prefix), str_replace( ",", "_", escape_quotes(strupr(PAC.name))));
}
// write INDEX end tag
printf("$EndINDEX\n");
}
/**
* @brief pad conversion
* @param PAC Eagle package http://web.mit.edu/xavid/arch/i386_rhel4/help/181.htm
*/
void write_kikad_mod_pad(UL_PACKAGE PAC)
{
PAC.contacts(CN)
{
char shp = 'R';
string signal, type = "STD";
int angle = 0, dx, dy, drill, layset, xoff, yoff;
// write PAD start tag
printf("$PAD\n");
signal = CN.signal;
if (CN.smd)
{
type = "SMD";
if (CN.smd.roundness > 40)
{
if (CN.smd.dx == CN.smd.dy)
shp = 'C';
else
shp = 'O';
}
angle = CN.smd.angle;
dx = CN.smd.dx;
dy = CN.smd.dy;
layset = CN.smd.layer;
}
if (CN.pad)
{
type = "STD";
xoff = 0;
yoff = 0;
dx = CN.pad.diameter[LAYER_TOP];
if (CN.pad.shape[LAYER_TOP] == PAD_SHAPE_ROUND )
{
shp = 'C';
dy = CN.pad.diameter[LAYER_TOP];
}
if (CN.pad.shape[LAYER_TOP] == PAD_SHAPE_OCTAGON)
{
shp = 'C';
dy = CN.pad.diameter[LAYER_TOP] * 2;
}
if (CN.pad.shape[LAYER_TOP] == PAD_SHAPE_LONG )
{
shp = 'O';
angle = CN.pad.angle + 90;
dy = CN.pad.diameter[LAYER_TOP] * 2;
}
if (CN.pad.shape[LAYER_TOP] == PAD_SHAPE_OFFSET )
{
shp = 'O';
angle = CN.pad.angle + 90;
dy = CN.pad.diameter[LAYER_TOP] * 2;
yoff = dx/2;
}
if (CN.pad.shape[LAYER_TOP] == PAD_SHAPE_SQUARE )
{
shp = 'R';
dy = CN.pad.diameter[LAYER_TOP];
}
drill = CN.pad.drill;
layset = LAYER_PADS ;
}
// pad shape
printf("Sh \"%s\" %c %d %d %d %d %d\n", CN.name, shp, egl2ki(dx), egl2ki(dy), 0, 0, angle * 10);
printf("Dr %d %d %d \n", egl2ki(drill), egl2ki(xoff), egl2ki(yoff));
printf("At %s N %08X\n", type, pad_lut[layset]);
printf("Ne 0 \"%s\"\n", ""); // should always be a null not signal name !
printf("Po %d %d \n", egl2ki(CN.x), -egl2ki(CN.y));
// write PAD end tag
printf("$EndPAD\n");
}
if (holes_conv)
PAC.holes(H)
{
// write PAD start tag
printf("$PAD\n");
// pad shape
printf("Sh \"\" C %d %d 0 0 0\n", egl2ki(H.drill), egl2ki(H.drill));
printf("Dr %d %d %d \n", egl2ki(H.drill), 0, 0);
printf("At HOLE N 00C0FFFF\n");
printf("Ne 0 \"%s\"\n", ""); // should always be a null not signal name !
printf("Po %d %d \n", egl2ki(H.x), -egl2ki(H.y));
// write PAD end tag
printf("$EndPAD\n");
}
}
real rotatedRect[];
void rotateRectangle(UL_RECTANGLE r) {
real rad = r.angle * PI * 2.0 / 360.0;
real centerX = r.x1 + (r.x2 - r.x1) / 2;
real centerY = r.y1 + (r.y2 - r.y1) / 2;
/*
* newx = cos(angle) * oldx - sin(angle) * oldy ;
* newy = sin(angle) * oldx + cos(angle) * oldy ;
*/
rotatedRect[0] = (r.x1 - centerX) * cos(rad) - (r.y1 - centerY) * sin(rad) + centerX;
rotatedRect[1] = (r.x2 - centerX) * cos(rad) - (r.y2 - centerY) * sin(rad) + centerX;
rotatedRect[2] = (r.x1 - centerX) * sin(rad) + (r.y1 - centerY) * cos(rad) + centerY;
rotatedRect[3] = (r.x2 - centerX) * sin(rad) + (r.y2 - centerY) * cos(rad) + centerY;
}
//------------------------------------------------------
// shape conversion
//------------------------------------------------------
/**
* shape conversion
* @param PAC Eagle package http://web.mit.edu/xavid/arch/i386_rhel4/help/181.htm
*/
void write_kicad_mod_shapes(UL_PACKAGE PAC)
{
//writing shapes
//also we must convert inverted y-coordinates (take it with minus)
//
//segments (always from Eagle's rectangles,wires and optional polygons)
// converting rectangles -------------------------------------------------------------
int layer;
if (rect_conv)
PAC.rectangles(R)
{
layer = layer_lookup(R.layer);
rotateRectangle(R);
printf("DS %d %d %d %d %d %d\n",
egl2ki(rotatedRect[0]), -egl2ki(rotatedRect[2]), egl2ki(rotatedRect[1]), -egl2ki(rotatedRect[2]), RECT_WIDTH, layer);
printf("DS %d %d %d %d %d %d\n",
egl2ki(rotatedRect[1]), -egl2ki(rotatedRect[2]), egl2ki(rotatedRect[1]), -egl2ki(rotatedRect[3]), RECT_WIDTH, layer);
printf("DS %d %d %d %d %d %d\n",
egl2ki(rotatedRect[0]), -egl2ki(rotatedRect[3]), egl2ki(rotatedRect[1]), -egl2ki(rotatedRect[3]), RECT_WIDTH, layer);
printf("DS %d %d %d %d %d %d\n",
egl2ki(rotatedRect[0]), -egl2ki(rotatedRect[2]), egl2ki(rotatedRect[0]), -egl2ki(rotatedRect[3]), RECT_WIDTH, layer);
}
// converting wires---------------------------------------------------------------------
PAC.wires(W)
{
layer = layer_lookup(W.layer);
if (!W.arc)
printf("DS %d %d %d %d %d %d\n",
egl2ki(W.x1), -egl2ki(W.y1), egl2ki(W.x2), -egl2ki(W.y2), egl2ki(W.width), layer);
}
// polygons converting ------------------------------------------------------------------
if (poly_conv)
PAC.polygons(P)
{
int wireCount = 0;
int wireWidth = 1;
int layer = 21;
P.contours(CONT) {
wireCount++;
layer = layer_lookup(CONT.layer);
wireWidth = egl2ki(CONT.width);
}
wireCount++; // Want to repeat first vertex
printf("DP 0 0 0 0 %d %d %d\n", wireCount, wireWidth, layer);
int lastX = 0;
int lastY = 0;
P.contours(CONT)
{
lastX = CONT.x2;
lastY = CONT.y2;
printf("Dl %d %d\n", egl2ki(CONT.x1), -egl2ki(CONT.y1));
}
printf("Dl %d %d\n", egl2ki(lastX), -egl2ki(lastY));
}
//circles (always from Eagle's circles and optional from holes)
//converting circles --------------------------------------------------------------------
PAC.circles(C)
{
layer = layer_lookup(C.layer);
printf("DC %d %d %d %d %d %d\n",
egl2ki(C.x),
-egl2ki(C.y),
egl2ki(C.x),
-egl2ki(C.y) - egl2ki(C.radius),
egl2ki(C.width),
layer);
}
if (holes_conv)
PAC.holes(H)
{
/*
layer = 21;
printf("DC %d %d %d %d %d %d\n",
egl2ki(H.x), -egl2ki(H.y),
egl2ki(H.x),
-egl2ki(H.y) - egl2ki(H.drill / 2),
50, layer);
printf("DS %d %d %d %d %d %d\n",
egl2ki(H.x - (H.drill / 2)), -egl2ki(H.y),
egl2ki(H.x + (H.drill / 2)), -egl2ki(H.y), 50, layer);
printf("DS %d %d %d %d %d %d\n",
egl2ki(H.x), -egl2ki(H.y - (H.drill / 2)),
egl2ki(H.x), -egl2ki(H.y + (H.drill / 2)), 50, layer);
*/
}
//converting (always from wires)arcs ----------------------------------------------------
PAC.wires(W)
{
if (W.arc)