forked from lachlanA/eagle-to-kicad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eagle6xx-sch-to-kicad-sch.ulp
3661 lines (3157 loc) · 115 KB
/
eagle6xx-sch-to-kicad-sch.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>Eagle schematic exporting tool version 1.4 </b>\n"
"<p>"
"This ULP can convert an Eagle CAD schematic into KiCAD schematic."
"<p>"
"Load any schematic and execute the ULP in the eagle."
"<p>"
"<author>Author: juergen.messerer (at) freesurf.ch</author>"
#require 6.0000
//#require 5.0000
#include "eagle_to_kicad_include.inc"
/*
* CHANGELOG================================================
* 11-06-2016 Fix enableNetListLableFix label not being using.
* Thanks to https://github.com/pgroe for this nice fix !
* 12.02.2016 Disable display of KiCad footprint Field in schematic.
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 08.02.2016 Fix over bar, sch and lib ulps now convert ! (eagle over bar marker)
* ~ (KiCad's over bar marker )
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 08.02.2016 Re-size Text in Lib parts better match eagle.
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 08.02.2016 Fix up text export to kicad sch so does not ghost the same text
* on the lib part, i.e. we only included text for Reference and Value in SCH
* all other text is not put in as free text in sch.
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 16.10.2015: Log all conflicts.
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 16.10.2015: Ajust offset for sch postion, to fit sheet a bit better.
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 16.10.2015: Add check for name conflict on lib's package and symbols,
* and enable add libname prefix if there is.
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 13.10.2015: Fix Quoteing of lib name in ft_tables
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 31.07.2015: Add warning about Eagle lib's Ghost parts
* Add check/warning for wrong path to conversion scripts.
* Fix some spelling stuff.
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 28.07.2015: Remove debug printer
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 19.07.2015: Fix / slash problem, with device/part names
* Fix some of my really bad spelling mistake's !
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 27.02.2015: Add user info doc's
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 16.02.2015: Add upper case convert to .cmp output of footprint name, fix bug where
* libname was being added to part Reference name
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 10.02.2015: Start adding xxxxx.cmp output (part/foot print assignment)
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 06.02.2015: Add "eagle_to_kicad_include.ulp" include file to help manage eagle cfg settings between
* ulp programs.
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 05.10.2014: Try adding support for more than one sheets, and fix for netlist problem at the same time
* This is tricky.
* 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: Move some code to main(), bit easier to understand!
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 05.09.2014: Inc version to 1.1
* Thanks Lachlan lachlanusa (at) gmail.com
*
* 05.09.2014: Fixes for part name placement, and part rotation.
* Thanks Lachlan lachlanusa (at) gmail.com
*
* 13.08.2014: Add more support for multi parts
* Thanks Lachlan lachlanusa (at) gmail.com
*
* 08.08.2014: Bug fix, size conversion bug.
* Thanks Lachlan lachlanusa (at) gmail.com
*
* 03.08.2014: Bug fix, remove bank \n \r from output, as KiCad does not like bank lines in sch files
* Thanks Lachlan lachlanusa (at) gmail.com
*
* 10.07.2906: Bug fix, thank to Tom Morrison
* Add function write_kicad_dotted_segments()
*
* 19.06.2006: Init version
*/
/* ==========================================================================
* License: This file is released under the license of the GNU Public license
* Version 2.
* ==========================================================================*/
int debug = 0;
real VERSION = 1.9;
string Version = "1.9";
string myname;
int datetime;
real fontSize_PartPreFix_Ajust = 1.0;
string libNamePartNameSeperator = "_"; // This is part Name so libName "_" partName is DEF, and F0 field in KiCad
string libNamePartLibNameSeperator = "_"; // This is part Lib to foot print name i.e.: libName ":" footprintName this is F2 field in KiCad
string libNameAliasSeperator = ":"; // This is separator for KiCad's lib Alias name prefix which is added to the foot print, when enabled
int libNameAliasPrefixEnable = 0; // Add the KiCad tables Alias name to the footprint
string infoAddLibName = "<b>Eagle SCH/PCB will not show any characters after \'@\' in pin names<br>"+
"Checking this will delete any characters after and including the <b>'@'</b><br>so it won't show in KiCad</pre>";
string infoTargetDirectory = "<h3>Set the target directory for all the converted Eagle files.</h3>"+
"<b>Note this directory should be a clean directory"+
"With out any other file's, as the contents may be<center><font color=\"red\">OVER WRITTEN WITHOUT WARNING!</b></center>";
string infoHelp = "This ULP converts from Eagle SCH/PCB to KiCad sch/PCB<br>"+
"It consist of 3 different ULP's hack to work together<br>"+
" ";
string infoULPdir = "<b>Eagle ULP conversion script location</b>";
string infoPartNameConflict = "Eagle allows duplicate part name's in SCH/PCB if they come from different lib's<br>"+
"<b>IE:</b><br><i><b> libfred<b></i>:74LS00:,<br>"+
"<i><b> libnerd<b></i>:74LS00,<br><br>"+
"While KiCad does not allow duplication's in part name's<br>"+
"In most cases there is no conflict, but if there is a conflict.<br>"+
"You have 2 options:<br><br> 1: Rename the part in eagle's LIB/SCH/PCB. <i>If you have access to them</i><br> 2: Tick this option <b><i>Adding lib name to Part Name</b></i><br><br>"+
"Which allowing this program to add lib prefix to the part name. This also fixes the problem.<br>"+
"<br><b><font color=\"purple\">Note 1: This program automatically checks for conflicts and sets the option if needed<br><br></b>"+
"<b><font color=\"red\">Note 2: Eagle has some nasty bugs in their library management, which in some cases there will be ghost parts in the libs!<br>"+
"<b>i.e.: parts which you don't use in your SCH but are still output from the lib-export stage of this program, which will magically be used instead of the part you have designed with !<br>"+
"The only way to get this problem is to turn the <i>Adding lib name to Part Name: back on!" ;
string infoCombineLibNames = "Combine all the separate Eagle libs into one KiCad lib<br>"+
"This makes the conversion process easy and faster.<br>"+
"<b>But means that you may lose track of which parts<br>"+
"come from which Eagle lib</b><br>";
string infoNetLableFix = "<u><b><font color=\"red\">The problem:</font></b></u>"+
" KiCad, Eagle net labels work in two total different ways<br>"
" In Eagle SCH wire's can have net name, while KiCad wire's have<br>"
" no net label name."+
" You can assign a net label in KiCad, but it has to be exactly over the wire"+
" if you move the wire, you lose the netlist assignment in KiCad!"+
"<br><b><u>This is very nasty, as you lose the net label connection!</b></u><br>"+
" It gets even worse when you have multiple sheets and global labels!"+
"<br><b><u><font color=\"green\">How We Fix This:</font></u></b><br>"+
" We add a net label to the junction of each wire!</br>"+
" <b><i>Said it was bad!</b></i><br>"+
" We have two types of labels in KiCad, <br>LOCAL, (<i>only works inside the current sheet)</i><br>"+
" GLOBAL, <i>(works on all sheets)</i><br>"+
" The Eagle script first check to see if the net label is only on the current sheet, or on"+
" multiple sheets and then assigns a local or global KiCad net label at the wire/part juction<br>"+
" This fixes any problems with placement of net label name in Eagle.<br>"+
" And for KiCad, we have a option to set the net label name size, so it's not too much of a eyesore.<br>"+
" While this solution is a real hack it's the only way to get around the net label placement problems"+
" KiCad has";
string infoExportLibsFromEagle = "Extract libs from Eagle SCH/PCB for KiCad <i>lib module.</i><br>"+
"<b><i>NOTE:</b></i> If you <b><i><u>don't</b></i></u> use this option, you will need to find<br>"+
"the Eagle <i>.lbr(s)</i> library files and convert those across<br>"+
" one by one using the Eagle-lbr2kicad-1.0.ulp";
string dummyKiCadPcb = "(kicad_pcb (version 4) (host pcbnew \"(2015-10-05 BZR 6247)-product\")\n"+
"\n"+
" (general\n"+
" (links 0)\n"+
" (no_connects 0)\n"+
" (area 0 0 0 0)\n"+
" (thickness 1.6)\n"+
" (drawings 1)\n"+
" (tracks 0)\n"+
" (zones 0)\n"+
" (modules 0)\n"+
" (nets 1)\n"+
" )\n"+
"\n"+
" (page A4)\n"+
" (layers\n"+
" (0 F.Cu signal)\n"+
" (31 B.Cu signal)\n"+
" (32 B.Adhes user)\n"+
" (33 F.Adhes user)\n"+
" (34 B.Paste user)\n"+
" (35 F.Paste user)\n"+
" (36 B.SilkS user)\n"+
" (37 F.SilkS user)\n"+
" (38 B.Mask user)\n"+
" (39 F.Mask user)\n"+
" (40 Dwgs.User user)\n"+
" (41 Cmts.User user)\n"+
" (42 Eco1.User user)\n"+
" (43 Eco2.User user)\n"+
" (44 Edge.Cuts user)\n"+
" (45 Margin user)\n"+
" (46 B.CrtYd user)\n"+
" (47 F.CrtYd user)\n"+
" (48 B.Fab user)\n"+
" (49 F.Fab user)\n"+
" )\n"+
"\n"+
" (setup\n"+
" (last_trace_width 0.25)\n"+
" (trace_clearance 0.2)\n"+
" (zone_clearance 0.508)\n"+
" (zone_45_only no)\n"+
" (trace_min 0.2)\n"+
" (segment_width 0.2)\n"+
" (edge_width 0.15)\n"+
" (via_size 0.6)\n"+
" (via_drill 0.4)\n"+
" (via_min_size 0.4)\n"+
" (via_min_drill 0.3)\n"+
" (uvia_size 0.3)\n"+
" (uvia_drill 0.1)\n"+
" (uvias_allowed no)\n"+
" (uvia_min_size 0.2)\n"+
" (uvia_min_drill 0.1)\n"+
" (pcb_text_width 0.3)\n"+
" (pcb_text_size 1.5 1.5)\n"+
" (mod_edge_width 0.15)\n"+
" (mod_text_size 1 1)\n"+
" (mod_text_width 0.15)\n"+
" (pad_size 1.524 1.524)\n"+
" (pad_drill 0.762)\n"+
" (pad_to_mask_clearance 0.2)\n"+
" (aux_axis_origin 0 0)\n"+
" (visible_elements FFFFFF7F)\n"+
" (pcbplotparams\n"+
" (layerselection 0x00030_80000001)\n"+
" (usegerberextensions false)\n"+
" (excludeedgelayer true)\n"+
" (linewidth 0.100000)\n"+
" (plotframeref false)\n"+
" (viasonmask false)\n"+
" (mode 1)\n"+
" (useauxorigin false)\n"+
" (hpglpennumber 1)\n"+
" (hpglpenspeed 20)\n"+
" (hpglpendiameter 15)\n"+
" (hpglpenoverlay 2)\n"+
" (psnegative false)\n"+
" (psa4output false)\n"+
" (plotreference true)\n"+
" (plotvalue true)\n"+
" (plotinvisibletext false)\n"+
" (padsonsilk false)\n"+
" (subtractmaskfromsilk false)\n"+
" (outputformat 1)\n"+
" (mirror false)\n"+
" (drillshape 1)\n"+
" (scaleselection 1)\n"+
" (outputdirectory \"\"))\n"+
" )\n"+
"\n"+
" (net 0 \"\")\n"+
"\n"+
" (net_class Default \"This is the default net class.\"\n"+
" (clearance 0.2)\n"+
" (trace_width 0.25)\n"+
" (via_dia 0.6)\n"+
" (via_drill 0.4)\n"+
" (uvia_dia 0.3)\n"+
" (uvia_drill 0.1)\n"+
" )\n"+
"\n"+
" (gr_text \"*** THIS IS THE DUMMY SAVE FILE ***\\nIF YOU'RE READING THIS MESSAGE,\\nYOU HAVE NOT DONE A SAVE-AS IN PCBNEW\\nTO THIS FILE NAME, WHEN IMPORTING A EAGLE PCB FILE TO A KICAD PCB FILE!!\\n\" (at 145.5166 92.7608) (layer F.SilkS)\n"+
" (effects (font (size 7 4) (thickness 0.6)))\n"+
" )\n"+
"\n"+
")\n";
string g_comboBoxArray[] = { "A0 (1188mm x 840mm)", "A1 (840mm x 594mm)", "A2(594mm x 420mm)",
"A3 (420mm x 297mm)", "A4(297mm x 210mm)",
"A5(210mm x 148mm)", "A6(148mm x 105mm)",
"Letter (11 x 8,5)", "Legal (14 x 8.5)",
"Folio (13 x 8.5)", "Executive (10.5 x 7.25)",
"A (11 x 8)", "B (16 x 11)", "C (22 x 16)", "D (32 x 22)", "E (44 x 32)",
"User defined" };
string g_sheetSizeArray[] = { "A0", "A1", "A2", "A3", "A4", "A5", "A6",
"Letter", "Legal", "Folio", "Executive",
"A", "B", "C", "D", "E" };
string g_sheetSizes[] = { "46811 33110", "33070 23400", "23400 16535", "16535 11700", "11700 8267", "8267 5826", "5826 4133",
"11000 8500", "14000 8500", "13000 8500", "10500 7250",
"11000 8000", "16000 11000", "22000 16000", "32000 22000", "44000 32000" };
int g_selected = 0; // initially selects "A0"
int g_dimX = 16000;
int g_dimY = 11000;
string monthArray[] = { "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC" };
string g_strTitle = "";
string g_strDate = "";
string g_strRev = "";
string g_strComp = "";
string g_comment1 = "";
string g_comment2 = "";
string g_comment3 = "";
string g_comment4 = "";
string libsUsed = ""; // list of libs
int addLibPrefix = 1; // add lib prifix
real g_Fact = 254*32; // global uMeter to uInch conversion factor
int g_transX = 0; // Y-axis translation factor, depending on the sheet size
int g_transY = 0; // Y-axis translation factor, depending on the sheet size
// Default version of KiCad sch file
int outPutVersion = 2;
int outPutCombineFootPrints = 1; // Output part Name's and footprints which work with the combined footprint KiCad Library
// Note this is very tricky, we have to convert the Eagle lib to KiKad lib, and output a conflict
// list which this program can use to do the part number translation !
// arrays for holding net/wire info
real netlistsX1[]; // Start X/Y
real netlistsY1[];
real netlistsX2[]; // End X/Y
real netlistsY2[];
int netWireConnectForwood[];
int netWireConnectBack[];
int netWiresTotal;
int totalSheets = 0;
int sheetsizes[];
int globalNetListSize = 0;
string globalNetList[];
int old_time = 0;
int hack_time = 0;
//------------------------------------------------------
// Global mod_ and lib_name
//------------------------------------------------------
string sch_name[];
string outputPath = EAGLE_HOME + '/';
string myULP_HOME = EAGLE_HOME + '/';
string StmpS = "";
string multiGateList[];
int partGateCount;
string libsUsedList[];
string devLibsRefList[];
int devLibsRefListSize = 0;
string conflictPartsLibsList[];
int conflictPartsLibsListsize = 0;
string devices[]; // hold list of devices and libname of the device
int deviceSize = 0;
string symbols[]; // hold list of symbols and libname of the symbol
int symbolSize = 0;
string packages[]; // hold list of packages and libname of the package
int packageSize = 0;
int combineLibs = 1;
string combineLibsName = "";
int enableNetListLableFix = 1;
real NetListLableFixSize = 1.0;
real GlobalNetListLableFixSize = 1.0;
string cmpList[];
int cmpListSize = 0;
string project_liblist[];
string netlistfile;
int exportLibsFromEagle = 1;
string logfileName;
string logfile;
string polygon_messagex[];
int polygons_linesCt = 0;
string polygons_message_FileName;
string rootschname;
//------------------------------------------------------
//Returns the path of a path-filename.
//------------------------------------------------------
string extract_path(string pathfilename)
{
string tmpString[];
int nr = strsplit( tmpString, pathfilename, '/');
tmpString[ nr-1 ] = ""; // remove file name
return strjoin( tmpString, '/') + "/"; // Return path
}
//------------------------------------------------------
//Returns the file name path-filename.
//------------------------------------------------------
string extract_filename(string pathfilename)
{
string tmpString[];
int nr = strsplit( tmpString, pathfilename, '/');
return tmpString[ nr-1 ]; // Return filename
}
//------------------------------------------------------
//Replaces all occurrences of a substring found within a string.
//------------------------------------------------------
string xstr_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;
}
//------------------------------------------------------
//Replaces all occurrences of a substring found within a string.
//------------------------------------------------------
string str_replace(string search, string replace, string subject)
{
string tmpS;
if( search == "," && ( strlen( search ) == strlen( "," )) )
{
tmpS = xstr_replace( search, replace, subject);
return xstr_replace( "/", replace, subject);
}
return xstr_replace( search, replace, subject);
}
//
// Compare 2 strings,
// Strings must be same size
// returns 0 for fail, or none zero for compared good.
//
int stringCompare( string st1, string st2 )
{
int i;
int stL1 = strlen( st1 );
int stL2 = strlen( st2 );
if( ( stL1 == 0 ) || ( stL2 == 0))
return 0;
if( stL1 == stL2 )
for( i = 0; i < stL2; i++ )
{
if( st1[ i ] == st2[ i ] )
continue;
else
{
return 0;
}
}
else
return 0;
return i;
}
//--------------------------------------------------------------------------------
// compares string to first substring multiGateList[ partGateCount ]
// returns index + 1 if found
// or zero if not.
//
int compareStringToStringArray( string searchString )
{
int i;
int j;
string stemp[];
for( i = 0; i < partGateCount; i++ )
{
if( strsplit( stemp, multiGateList[ i ], ' ' ) == 0 )
continue;
if( stringCompare( stemp[0], searchString ))
return i + 1;
}
return 0;
}
//
//replace new line character with string '\n' as kicad can handle that, but not new line chareter
//
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;
}
//*******
// Strip Quote's beging and ending "" from string
//
string stripQutes( string source )
{
if( strlen( source ) == 0 )
return "";
return strsub( source, 1, strlen( source ) -2 );
}
//------------------------------------------------------
// 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;
}
//------------------------------------------------------
// find size of word
// returns size of seach text in bytes
//------------------------------------------------------
int strlenWord( string search, int offset )
{
int ct = 0;
int sl = strlen( search );
while( sl )
{
if( isspace( search[ offset] ) == 0 )
{ // Ok not space,cr,null,tab then
ct++;
offset++;
sl--;
continue;
}
return ct;
}
return ct;
}
//------------------------------------------------------
//Find string in the globalNetList string arrray
//------------------------------------------------------
int array_find(string search, int arraySize )
{
int ct1 = 0;
int ln = strlen( search );
// Check if there is any thing to replace
while( arraySize )
{
/* if( ln != strlenWord( globalNetList[ ct1 ], 0 )) // check the size of netname, first element */
/* return 0; */
if( strstr( globalNetList[ ct1 ], search ) != -1)
return 1; // return found
arraySize--;
ct1++;
}
return 0;
}
//------------------------------------------------------
//Find string in the globalNetList string arrray
//------------------------------------------------------
int array_find_poly_messagex( string search, int arraySize )
{
int ct1 = 0;
int ln = strlen( search );
// Check if there is any thing to replace
while( arraySize )
{
/* if( ln != strlenWord( polygon_messagex[ ct1 ], 0 )) */
/* return 0; */
if( strstr( polygon_messagex[ ct1 ], search ) != -1)
return 1; // return found
arraySize--;
ct1++;
}
return 0; // return not found
}
//--------------------
// check for existing file
// returns 1 if found
int check_for_exist_file(string FileName) {
string a[];
int n = fileglob(a, FileName);
if (n == 0) return 0;
else return 1;
}
// ***** Genrate KiCad Matrix
//
string angleToKiCadMatrix(int angle, int mirror )
{
switch(angle)
{
case 0: // 0 deg's
return ((mirror ? "-1" : "1") + " 0 0 -1");
break;
case 90: // 90 deg's
// return ("0 -1 " + (mirror ? "1" : "-1") + " 0");
return ("0 " + (mirror ? "1 -1" : "-1 -1") + " 0");
break;
case 180: // 180 Deg's
return ((mirror ? "1" : "-1") + " 0 0 1");
// return ("-1 0 0 " + (mirror ? "-1" : "1") );
break;
case 270: // -90 Deg's or 270 Degs
return ("0 " + (mirror ? "-1" : "1") + " 1 0");
// return ("0 1 " + (mirror ? "-1" : "1") + " 0");
break;
}
}
// *******************************************
//
// Output a string to a file.
// openOverWriteCrateAppendMode set's optin's
// openOverWriteCrateAppendMode = 0, Append to a existing file only, returns -2 if the file is not found.
// openOverWriteCrateAppendMode = 1, Append to a existing file or create a new file if it does exist.
// openOverWriteCrateAppendMode = 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 errror
// or -2 if no file found
// or output of fileerror, which I have no idea what it will be, just if 0, then write was ok.
//
int outputStringToFile( string fileName, string outputString, char openOverWriteCrateAppendMode, 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( openOverWriteCrateAppendMode )
{
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;
}
// Output the data to fileName
output( fileName, mode )
{
printf("%s", outputString );
n = fileerror();
}
return n;
}
//*****************************
// Current time hack for KiCad
//
int getCurrentTimeHack()
{
int i;
i = time();
if( old_time == i )
{
hack_time = hack_time + 100;
return old_time + hack_time;
}
else
{
old_time = i;
return i;
}
}
//
// Make list of all the lib's used.
//
int makeLibeList( UL_SCHEMATIC SCH )
{
int i = 0;
SCH.libraries(LIB)
{
string tmpString = "";
libsUsedList[ i ] = LIB.name + "\tNo" + "\tDate";
i++;
}
return i;
}
//***************
// Make list of all the device lib's refaces used.
// And seach for conflicts
// returns 0 if ok,
// or confict count
//
int makeDevLibRefList( UL_SCHEMATIC SCH )
{
int n = 0;
int k = 0;
int e = 0;
int i;
int cfCount = 0;
char found = 0;
string ts;
string tmpSA[];
string tmpSA2[];
string tmpSA3[];
string tmpS;
devLibsRefListSize = 0;
conflictPartsLibsListsize = 0;
SCH.libraries(L)
{
string c;
L.devices(D)
{
sprintf( c, "%s %s", D.name, L.name );
devices[ deviceSize++ ] = c;
}
L.symbols(S)
{
sprintf( c, "%s %s", S.name, L.name);
symbols[ symbolSize++ ] = c;
}
L.packages(P)
{
sprintf( c, "%s %s", P.name, L.name);
packages[ packageSize++] = c;
}
}
SCH.libraries(L)
{
string c;
i = 0;
string rs[];
L.devices(D)
{
for( i = 0; i < deviceSize; i++ )
{
strsplit( rs, devices[ i ], ' ' );
if( D.name == rs[0]) // Mach device name ?
if( L.name == rs[1] ) // Match lib name ?
continue; // All ok so continue
else
{ // Ok we have problem, device name conflict ! Docment it
conflictPartsLibsList[ conflictPartsLibsListsize++ ] = rs[0] + "\t" + rs[1] + "\t" + "DEVICE-NAME-CONFLICT" + "\tConflicts With\t" + D.name + "\t" + L.name + "\t" + "DEVICE-NAME-CONFLICT";
sprintf( c, "\nDevice Name Conflict: Device=%s from Internal SCH lib=%s With Device=%s from LIB=%s", D.name, L.name, rs[0], rs[1] );
logfile += c;
}
}
}
L.symbols(S)
{
string c;
for( i = 0; i < symbolSize; i++ )
{
strsplit( rs, symbols[ i ], ' ' );
if( S.name == rs[0]) // Mach package name ?
if( L.name == rs[1] ) // Match lib name ?
continue; // All ok so continue
else
{ // Ok we have problem, package name conflict ! Docment it
conflictPartsLibsList[ conflictPartsLibsListsize++ ] = rs[0] + "\t" + rs[1] + "\t" + "SYMBOL-NAME-CONFLICT" + "\tConflicts With\t" + S.name + "\t" + L.name + "\t" + "SYMBOL-NAME-CONFLICT";
sprintf( c, "\nSymbol Name Conflict: Symbol=%s from Internal SCH lib=%s With Symbol=%s from LIB=%s", S.name, L.name, rs[0], rs[1] );
logfile += c;
}
}
}
L.packages(P)
{
string c;
for( i = 0; i < packageSize; i++ )
{
strsplit( rs, packages[ i ], ' ' );
if( P.name == rs[0]) // Mach package name ?
if( L.name == rs[1] ) // Match lib name ?
continue; // All ok so continue
else
{ // Ok we have problem, package name conflict ! Docment it
conflictPartsLibsList[ conflictPartsLibsListsize++ ] = rs[0] + "\t" + rs[1] + "\t" + "PACKAGE-NAME-CONFLICT" + "\tConflicts With\t" + P.name + "\t" + L.name + "\t" + "PACKAGE-NAME-CONFLICT";
sprintf( c, "\nPackage Name Conflict: Package=%s from Internal SCH lib=%s With Package=%s from LIB=%s", P.name, L.name, rs[0], rs[1] );
logfile += c;
}
}
}
}
/* SCH.parts(P) */
/* { */
/* // first search for deivce name */
/* found = 0; */
/* // sprintf( ts, "%s %s %s\n", P.device.name, P.device.library, P.name ); */
/* // outputStringToFile( "./tXXX.txt", ts, 1, 't'); */
/* if( devLibsRefListSize ) */
/* { */
/* sprintf( tmpS, "%s \"%s\" %s", P.device.name, P.device.library, P.name ); */
/* for( e = 0; e < devLibsRefListSize; e++ ) */
/* { */
/* strsplit( tmpSA, devLibsRefList[ e ], ' ' ); */
/* if( P.device.name == tmpSA[ 0 ] ) // found device name match ? */
/* { */
/* if( P.device.library == stripQutes( tmpSA[ 1 ] )) // found devive libname match ? */
/* { */
/* tmpSA[ 2 ] = tmpSA[ 2 ] + "," + P.name; */
/* devLibsRefList[ e ] = strjoin( tmpSA, ' ' ); */
/* found = 1; */
/* break; */
/* } */
/* else */
/* { // Ok device name found but not the same lib name so make this with error and append first conflict refance to it. */
/* tmpS = tmpS + " " + tmpSA[ 2 ]; */
/* cfCount++; */
/* devLibsRefList[ devLibsRefListSize++ ] = tmpS; // And add to list. */
/* strsplit( tmpSA2, devLibsRefList[ e ], ' ' ); */
/* strsplit( tmpSA3, tmpSA2[2], ',' ); */
/* conflictPartsLibsList[ conflictPartsLibsListsize++ ] = tmpSA2[0] + "\t" + tmpSA2[1] + "\t" + tmpSA3[0] + "\tConflicts With\t" + P.device.name + "\t" + P.device.library + "\t" + P.name; */
/* found = 1; */
/* break; // Ok found, so make it so */
/* } */
/* } */
/* continue; // Keep searching */
/* } */
/* // sprintf( tmpS, "%s \"%s\" %s", P.device.name, P.device.library, P.name ); */
/* // none found so add to end of list */
/* if( found == 0 ) */
/* { */
/* devLibsRefList[ devLibsRefListSize++ ] = tmpS; // And add to list. */
/* } */
/* continue; //goto SCH.parts(P) */
/* } */
/* else */
/* { // empty list so insurt first one */
/* sprintf( tmpS, "%s \"%s\" %s", P.device.name, P.device.library, P.name ); */
/* devLibsRefList[ devLibsRefListSize++ ] = tmpS; // And add to list. */
/* } */
/* } */
return cfCount;
}
//********
// Work out placement
// and suggest a size
// returns -1 if it can't fit in any size !
//
string intToString( int value )
{
string tmpS;
sprintf( tmpS, "%d", value );
return tmpS;
}
//--------------------------------------------------------------------------------
// Work out placement
// and suggest a size
// returns -1 if it can't fit in any size !
//--------------------------------------------------------------------------------
int calculateTranslations(UL_AREA area, int paperSizeSelect ) {
// given the area of the sheet
// and size of the output sheet
// calculate offset to center sheet inside output
string pageDimension[];
int n = strsplit(pageDimension, g_sheetSizes[ paperSizeSelect ], ' ');
int width = strtol(pageDimension[0])-1000;
int height = strtol(pageDimension[1])-1000;
// calculate offset based on area width and height
int x1 = area.x1 / g_Fact;