forked from lachlanA/eagle-to-kicad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfix_via_hack.ulp
executable file
·2570 lines (2179 loc) · 90.6 KB
/
fix_via_hack.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>fix via hack</b><p>"
"<author>Lachlan</author>"
//#require 6.0000
#include "eagle_to_kicad_include.inc"
// THIS PROGRAM IS PROVIDED AS IS AND WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED
string Version = "ULP Version 4.8.1";
/*
* CHANGELOG================================================
* 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"
*
* 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"
*
* 07.04.2017: Remove unused code, inc version number
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 25.02.2017: Comment out requires 6.0000, and Inc version
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 11.02.2016: Put new pads top/left corner of sch file, so not to over write other connections.
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 11.02.2016: Change ! to ~ for onver bard on KiCad
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 19.10.2015: Add reporting of fills over pads. And clean up other reports.
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 14.09.2015: Star adding reporting code for unconnected traces, and multi blind VIAs
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 09.09.2015: Add better plot of via pad change, Doc marker
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 18.08.2015: Add save command, so sch and pcb are update, save user having to rember
* to save the change's
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 27.02.2015: Programed moded to only add refance numbers
* to parts which have no refance numbers
* Thanks to: Lachlan "lachlanusa (at) gmail.com"
*
* 2006.08.23 alf@cadsoft.de
* correct counter if crossing page by same prefix
* 2008.01.30 alf@cadsoft.de
* renumber only the current sheet by start sheet-number * numerical_order
* 2012-06-21 - corrected sort by Weighting of emphasis in Y-direction
* alf@cadsoft.de
*/
int ViaEagleReportLayerTxt = 160; // which eagle layer reporting text should go too. ( Eco1_User)
int ViaEagleReportLayerTxtColor = 3;
int ViaEagleReportLayerDrawing = 161; // which eagle layer reporting Graphics should go too ( Eco2_User)
int WireEagleReportLayerTxt = 160; // which eagle layer reporting text should go too. ( Eco1_User)
int WireEagleReportLayerTxtColor = 4; // which eagle layer reporting text should go too. ( Eco1_User)
int WireEagleReportLayerDrawing = 161; // which eagle layer reporting Graphics should go too ( Eco2_User)
int PadEagleReportLayerText = 160;
int PadEagleReportLayerTextColor = 5;
int PadEagleReportLayerDrawing = 160;
int BlindEagleReportLayerTxt = 160;
int BlindEagleReportLayerTxtColor = 6;
int BlindEagleReportLayerDrawing = 161;
//int ViaEagleReportLayerTxtList[] = { 95, 96 };
//int ViaEagleReportLayerTxtListSizie = 2;
int display_error_layers = 1; // Display error layers only
string debugBuf[];
int debugIdex = 0;
int descy = 1; // set to 0 sorting ascending
int descx = 0; // set to 1 sorting descending
int numerical_order = 0; // sort from sheet 1, or sort by start counter for sheet
int emphases = 0; // weighting of emphases first X second Y or first Y second X
int actual_sheet = 0; // 2008.01.30
int only_actual_sheet = 0; // 2008.01.30
string sheet_info = "";
numeric string OldNames[], NewNames[], Prefix[];
int x[], y[], Index[], Sheet[];
int nrNames = 0;
numeric string SymNames[]; // Device-Name of Symbol
int symsh[];
int SymX[], SymY[];
int Snr = 0;
int Dnr = 0;
string Error = "";
string SymPrefix[]; // holds Reference/prefix - any trailing number
string DevPrefix[];
string DevName[]; // holds Reference/prefix with trailing number
string SymDevName[]; // holds Reference/prefix with trailing number
string NoPrefixRenumber = ""; // Prefix do not renumber testpoints
int ckx[], cky[], cksh[];
string ckname[];
string cmd; // Holds the script to renumbering in sch
string lib_cmd; // Holds script for building lib pads
string pcb_cmd; // Holds script for removing vias and adding pads in their place
string sch_cmd; // Holds script for sch pads add.
string c;
real Grid = 100; // in 100 Mil
string lbr[], dev[], sym[];
int maxRefNumber = 0; // Hold the maxium refance number on this schmatic
// this will be the start of the number parts which dont have a refance
// gobal table
int aX[];
int aY[];
int aIndex[]; //
char aType[]; // type is 0=PAD, 1=VIA, 2=wire_start, 3=wire_end.
string aNet[];
int aSl[]; // Start layer of pad/via or track,
int aFl[]; // End layer of pad/via if track is the same as start layer
int aDiameter[];// Hold Via/Pad Diameter for start layer
int aDrill[];
int aShape[];
int aViaP[]; // Points to Via index from track
int aPadP[]; // Points to Pad index
int aWireConnectionCt[]; // Holds the number of connections from wire to wire for each node
char aStatus[]; // the connection status, 0=NoConnected, 1=PadConnection.
char aFillPad[]; // Marks the pad as having possible fill
int wirenumber[]; // holds the wire number
int aindex[]; // order storted index of pad/traces/VIAs
int index_size; // Holds the table size
int table_error = 0; // Counts any errors in the connection table, should not happen!
char overLappingPads = 0; // flag for overlapping pads
string unconnected_vias[];
int unconnected_vias_Ct = 0;
string unconnected_wires[];
int unconnected_wires_Ct = 0;
int unc_vaX[];
int unc_vaY[];
int unc_vaSl[];
int unc_vaFl[];
string unc_vaNet[];
int unc_vaDiameter[];
int unc_vaDrill[];
int unc_vaShape[];
string unc_vNet[];
int unc_wXs[];
int unc_wYs[];
int unc_wXf[];
int unc_wYf[];
int unc_wLayer[];
string unc_wNet[];
int document_unconnected_wires = 1;
// Hold table of wires used when check for free wires.
// Note this looks a bit old, as we dont have an end X,Y
// but old/end is the marker.. IE index 10 is start, index of 11 is end of same track.
// layer start finish are, always the same value,
// so that same routine can check for connections for pads
// VIAs, wire's
int wire_X[];
int wire_Y[];
char wire_Sl[]; // layer start
char wire_Fl[]; // layer finish
string wire_netname[]; // net name
char wire_pad_connectFlag[]; // Marks the track as having connection to PAD, even if via a wire
int wire_counter;
int wire_index[];
int wire_indexS[];
int wire_indexF[];
// Holds table of wires pads smd pads
// with pads Sl and Fl
int via_X[];
int via_Y[];
char via_Sl[];
char via_Fl[];
string via_netname[];
char via_pad_connectFlag[]; // Marks the pad as having connection to PAD, even if via a wire or direct, via in pad.
int via_counter;
int via_index[];
// Holds table of pads
// for pads pad_Sl = 1 pad_Fl=16 ie all layers
int pad_X[];
int pad_Y[];
char pad_Sl[];
char pad_Fl[];
string pad_netname[];
int pad_counter;
int pad_index[];
// Pad buffer
int pad_size[]; // hold list of pads size
int pad_drill[]; // hold list of pad drill size
int pad_shape[]; // hold list of pad shapes
string pac_name[]; // Package name
string dev_name[]; // Device name
int pad_buffer_size;
int pad_count;
string pac_prefix = "VPAC";
string dev_prefix = "VPDEV";
int sch_pad_X = 0;
int sch_pad_Y = 0;
int sch_net_count = 0;
int sheetnumber = 0;
// stack for tracking connections
char stack_p_connection_status[];
int stack_p_index[];
int stack_p;
int enable_via_to_pad = 1;
int docment_via_to_pad = 1;
int docment_blind_via_to_pad = 1;
int docment_fill_over_pad = 1;
int libsetup = 0;
int total_vias = 0;
int total_wires = 0;
int wire_to_pad_connections = 0;
int via_to_padconnections = 0;
int wire_to_via_connections = 0;
int kk = 0;
int kp = 0;
int unc_wiresDispLayerList[];
int unc_wiresDispLayerListCt = 0;
string WorkPath;
string CurrentLbrName = "vpad";
string shapeTablePad[] = {"Square", "Round", "Octagon"};
string schname = "";
//string outputPath = EAGLE_HOME + '/';
//string myULP_HOME = EAGLE_HOME + '/';
string outputPath = "";
string myULP_HOME = "";
string infoTargetDirectory = "<b>Set the target directory for the KiCad/Eagle files.<br>"+
"<b>Note this directory should be a clean directory<br>"+
"with no other files. The directory contents <br><center><font color=\"red\">WILL BE OVER WRITTEN WITHOUT WARNING!</b></center>";
string infoConvertViaToPad = "<b>Eagle uses vias for connections to fills and power planes. This works well for Eagle<br>"+
"<b>but is not compatible with KiCad because KiCad does not retain netlist information for unconnected vias and traces.<br>"+
"<b>KiCad only retains net information when the via is connected to a pad using a track.<br>"+
"<b>By converting the unconnected vias to pads KiCad will keep the net information and allow fills and power planes to work like<br>"+
"<b>they do in Eagle. But there are some problems with this fix:<br><br>"+
"1: Blind vias won't work: Pads will go through all layers while blind vias only go through the configured layers so be sure to review any blind vias.<br>"+
"2: This ULP changes the Eagle SCH/PCB files by converting vias to pads. It does this by adding many 1-pin components to the schematic.<br>"+
" This is a messy hack. You will see x=0 y=0 number different nets and pads in the Eagle SCH file.<br>"+
" This newly modified Eagle file is saved to the subdirectory: $TARGETDIRECTOR/modified_eagle_files/";
string infoDocFillOverPad = "<b>SMD pads & normal pads can be covered with copper when the 'Thermals' option is Eagle is unchecked (turned off).<br>"+
"<b>When importing the Eagle PCB there is no control over which pads get thermals, only a global choice.<br>"+
"<b>This leads to the following problem: Thermal reliefs are generated for each via/pad conversion which is not what you need.<br>"+
"<b>The solution: In KiCad you have global control and individual pad control of thermal relief. So during import thermal relief is turned off<br>"+
"<b>and it is up to the user to manually turn each smd/pad thermal relief on as needed.<br>"+
" ";
string infoDocomentUnconnectVias = "<b>This option adds a \">\" to the via or converted pad<br>"+
"making it easy to find the changed vias/pads on the PCB.<br>"+
"Note: These will show up in a layer called eagleReportLayerTxt (tDocu) in the Eagle PCB and in Dwgs.User on KiCad pcbnew.<br>";
string infoDocomentUnconnectWires = "<b>This Option adds a \">\" to the via or converted pad<br>"+
"making it easy to find the changed vias/pads on the PCB.<br>"+
"Note: These will show up in a layer called eagleReportLayerTxt (tDocu) in the Eagle PCB and in Dwgs.User on KiCad pcbnew.<br>";
string infoULPdir = "<b>Eagle ULP conversion script location</b>";
int blindviaCt = 0;
string via_polygon_netname = ""; // holds the report on matching polygon and net names, so can apply gobal label when the via and polygon match and wire
string ULP_Path;
char bkslash = '/';
int pos = strrchr(argv[0], bkslash);
int passcount = 0;
string logfile = "#********** START OF fix_via_hack.ulp LOG **********#";
string logfileName;
string polygon_messagex;
int polygons_linesCt = 0;
string polygons_message_FileName;
int displaylayer[];
int displayCt = 0;
string Colors[] = {"Black", /* 0 */
"Blue", /* 1 */
"Green", /* 2 */
"Cyan", /* 3 */
"Red", /* 4 */
"Magenta", /* 5 */
"Brown", /* 6 */
"LGray", /* 7 */
"DGray", /* 8 */
"LBlue", /* 9 */
"LGreen",/* 10 */
"LCyan", /* 11 */
"LRed", /* 12 */
"LMagenta", /* 13 */
"Yellow", /* 14 */
"White" }; /* 15 */
//
//--------------------------------------------------------------------------------
string intoString( int i )
{
string s;
sprintf( s, "%d", i );
return s;
}
//logfile = filesetext(S.name, "_conversion_log.txt");
// *******************************************
//
// Output a string to a file.
// openOverWriteCrateAppendMode sets options
// 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 error
// or -2 if no file found
// or output of fileeror, 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;
}
//
// Find and add if not in array
// return zero if not found, or array+1 if found
// Note you need to adjust return value to use.. IE subtract one
int findIntInArray( int start, int value )
{ int i;
for( i = start; i < unc_wiresDispLayerListCt; i++ )
{
if( unc_wiresDispLayerList[i] == value )
return ++i;
else
continue;
}
unc_wiresDispLayerList[i] = value;
unc_wiresDispLayerListCt++;
return 0;
}
//--------------------------------------------------------------------------------
// debug buffer print
//
void debugprint()
{
int i;
for( i = 0; i < via_counter; i++ )
{
sprintf( debugBuf[ debugIdex++ ], "%d\t%d\t%d\t%d\t%s\t%c\t%c\t%d\t%d\t%f\t%f\t%d\t%d",
debugIdex, i, passcount, wirenumber[ i ], aNet[ i ], 48+(aType[ i ]), 48+(aStatus[ i ]), aSl[ i ], aFl[ i ], u2mic(aX[ i ]), u2mic(aY[ i ]), aViaP[i], aPadP[i]);
}
}
// put up window with buffer
void displayDebug()
{
int result;
int Selected = 0;
string x;
result = dlgDialog("Debug")
{
string c;
dlgListView("debugIdex\tPadWireViaIdex\tPassCount\twirenumber\taNet\taType\taStatus\taSl\taFl\tX\tY\taVia\taPad", debugBuf, Selected) dlgMessageBox("More info ");
int space = 10;
dlgVBoxLayout
{
dlgStretch(10);
dlgHBoxLayout
{
dlgStretch(1);
dlgPushButton("+OK")
{
dlgAccept();
};
dlgSpacing(space);
dlgPushButton("-Exit Program") dlgReject();
dlgStretch(0);
dlgSpacing(space);
}
dlgStretch(10);
}
};
if( !result )
exit(-1);
return;
}
//--------------------------------------------------------------------------------
//Returns 1, if EAGLE is running under Windows (0 for Linux/Mac)
//
int IsWindows()
{
if ((strsub(argv[0],0,1)=="/") && (strsub(argv[0],0,2)!="//"))
return 0;
return 1;
}
//--------------------
// 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;
}
//--------------------------------------------------------------------------------
// Returns the index of the first digit of the numeric part of Name
// -1 indicates there is no numeric part in Name
int GetNumberIndex(string Name)
{
int l = strlen(Name) - 1;
for (int Index = l; Index >= 0; --Index) {
if (!isdigit(Name[Index]))
return Index < l ? Index + 1 : -1;
}
return 0;
}
//--------------------------------------------------------------------------------
// return reference without trailing number
//
string prefix(string name) { // Prefix of Device
int num = GetNumberIndex(name);
if (num < 1)
return name;
else {
string pfx = name;
pfx[num] = 0; // put in 0 to terminate string
return pfx;
}
}
void DescendingY(void) {
for (int ny = 0; ny < nrNames ; ny++) {
y[ny] = 0 - y[ny];
}
return;
}
void DescendingX(void) {
for (int nx = 0; nx < nrNames ; nx++) {
x[nx] = 0 - x[nx];
}
return;
}
//------------------------------------------------------
//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 anything 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);
}
void SortElements(void) {
// Sorts the elements according to their location, first by ascending
// x coordinates, then by ascending y coordinates.
// If you prefer a different kind of sorting, you can implement this here.
// As a result, the integer array Index[] must contain the new sequence
// in which to renumber the elements.
// 2008-07-24 alf, weighting of emphases first X second Y or first Y second X
if (descy) DescendingY();
if (descx) DescendingX();
if(!numerical_order)
{
if (!emphases)
sort(nrNames, Index, NewNames, Sheet, x, y);
else
sort(nrNames, Index, NewNames, Sheet, y, x);
}
else {
if (!emphases) sort(nrNames, Index, Sheet, NewNames, x, y);
if (emphases) sort(nrNames, Index, Sheet, NewNames, y, x); // 2012-06-21 correct sort on emphases
}
if (descy) DescendingY();
if (descx) DescendingX();
return;
}
void CheckSameOrigin(int chk) { // eagle can not rename an element
// if another element is on the same coordinate
int index[];
string checklist, h;
sort(chk, index, cksh, ckx, cky);
for (int n = 0; n < nrNames; n++) {
if(ckx[index[n]] == ckx[index[n+1]] && cky[index[n]] == cky[index[n+1]] && cksh[index[n]] == cksh[index[n+1]]) {
sprintf(h, "%s & %s on same coordinate (%d %d) mil in sheet %d\n",
ckname[index[n]], ckname[index[n+1]],
ckx[index[n]],
cky[index[n]],
cksh[index[n]]);
checklist += h;
}
}
if (checklist) {
dlgDialog("Check coordinates") {
dlgLabel("Eagle can not rename elements that are placed at the same position!");
dlgHBoxLayout {
dlgSpacing(300);
}
dlgTextView(checklist);
dlgHBoxLayout {
dlgPushButton("Break") dlgAccept();
dlgStretch(1);
}
};
exit(0);
}
return;
}
//--------------------------------------------------------------------------------
// output script for renumber part
//--------------------------------------------------------------------------------
void Rename(int x, int y, string New) {
// Generates the EAGLE command necessary to change element name Old to New
sprintf(c, "Name '%s' (%d %d);#209\n", New, x, y);
cmd += c;
return;
}
//--------------------------------------------------------------------------------
// 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;
}
//--------------------------------------------------------------------------------
//
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));
}
//--------------------------------------------------------------------------------
// Generates an EAGLE script file that does the whole renumbering.
// The tricky part here is that we cannot rename an element to a name
// that already exists in the schematic (which, e.g. might be necessary if
// we had to swap the names of two elements). Therefore we have to
// use a ScratchName wherever this is necessary.
// If there is nothing to do, the resulting script file will be empty.
void GenerateScript(void)
{
string ScratchName;
int sch = 0;
int n;
for ( n = 0; n < nrNames; ++n) {
if (Sheet[Index[n]] != sch) {
sch = Sheet[Index[n]]; // *** change sheet
sprintf(c, "Edit .s%d;\n", sch);
cmd += c;
}
sprintf( ScratchName, "$%d_%d_$", sch, n);
Rename(x[Index[n]],y[Index[n]], ScratchName); // output script for renumber part
}
for ( n = 0; n < nrNames; ++n) {
if (Sheet[Index[n]] != sch) {
sch = Sheet[Index[n]]; // *** change sheet
sprintf(c, "Edit .s%d;\n", sch);
cmd += c;
}
Rename(x[Index[n]],y[Index[n]], NewNames[Index[n]]); // output script for renumber part
}
return;
}
//--------------------------------------------------------------------------------
// *** check collision before rename ***
//--------------------------------------------------------------------------------
string CheckNames(void) {
string new_name = ";";
string h;
for (int Dn = 0; Dn < Dnr; Dn++ ) {
for (int Sn = 0; Sn < Snr; Sn++) {
if (DevPrefix[Dn] == SymPrefix[Sn]) {
sprintf(h, "# Do not use Prefix %s on Device with Package (%s) and Device without Package (%s)\n",
SymPrefix[Sn], DevName[Dn], SymDevName[Sn]);
Error += h;
break;
}
}
}
for (int n = 0; n < nrNames - 1; ++n) { // make a long string
new_name += NewNames[n] + ";";
}
for (int xx = 0; xx < Snr - 1; xx++) {
string sd = SymNames[xx];
if(sd[0] == '$') { // if first character is a $ on Symbolname
Error += "# Do not use $ character at first position in device names\n";
sprintf(h, "# RENAME %s at (%.4f %.4f) - sheet %d before running this ULP again' (%.4f %.4f)\n",
SymNames[xx], SymX[xx] / 1000.0, SymY[xx] / 1000.0, symsh[xx], SymX[xx] / 1000.0, SymY[xx] / 1000.0);
Error += h;
}
int s;
int pos = strrstr(new_name, ";" + SymNames[xx] + ";");
if (pos > 0 ) {
for (s = 0; s < nrNames - 1; s++)
{
if(NewNames[s] == SymNames[xx])
{
break;
}
}
Error += "# Collision of symbol name and device name (eg. Frames, Supply ...)\n";
sprintf(h, "# Rename PREFIX of Device %s at (%.4f %.4f) - sheet %d before renaming %s at (%.4f %.4f) - sheet %d';\n",
SymNames[xx], SymX[xx] / 1000.0, SymY[xx] / 1000.0, symsh[xx],
OldNames[s], x[s] / 1000.0, y[s] / 1000.0, Sheet[s] );
Error += h;
}
}
return Error;
}
//--------------------------------------------------------------------------------
void setgridmil (void) {
sprintf(c, "GRID MIL 100 OFF;\n");
cmd += c;
// ## only display layer 94 (symbol) if placed a text
// ## at symbol origin. 15.06.2004 alf@cadsoft.de
sprintf(c, "DISPLAY NONE 94 -95 -96;\n");
cmd += c;
return;
}
//--------------------------------------------------------------------------------
void visible(UL_SCHEMATIC S) {
sprintf(c, "DISP NONE ");
cmd += c;
S.layers(L) {
if (L.visible) {
sprintf(c, "%d ", L.number);
cmd += c;
}
}
cmd += ";\n";
return;
}
//--------------------------------------------------------------------------------
// dialog box
//
void menue(void)
{
int result;
int rs = 0;
string tmpSX;
int space = 10;
int saveAsDefault = 1;
int saveAsDefaultULP_Path = 1;
string tmpS10 = "";
result = dlgDialog("Vias to Pads, and Trace Check. " + " BUILD DATE: " + BUILD_DATE )
{
dlgLabel("<b><font color=\"red\">This ULP will change unconnected vias to pads.</font></b><br>" +
"It will also document the unconnected vias and traces to layers specified by the user.<br>" +
"Click on any <i>Info</i> button for details.<br>"+
"<b>Note:</b> This hack modifies both the Eagle SCH and PCB files "+
"which are saved to the TARGET-DIRECTORY/modified_eagle_files/.");
/* "This is needed because KiCad does not support Net Names on unconected VIAs/Traces and blind Vias which have no Pad conecsion.!<br>"+ */
/* "while unconected VIAs can be automatic coveted to pads blind VIAs and unconnected traces need manual conversion</i>)<br>"+ */
/* "will lose net names, and will not connect to fills or power planes!<br>"+ */
/* "This hack will help out by converting all those unconnected VIAs to Pads<br>"+ */
/* "<i>Click on Info for more, information and problem's which is could fix/make!</i><br>"+ */
/* "<b>NOTE:<i> This hack modifies both the eagle sch and PCB file, which are saved in the TARGET-DIRECTORY/modified_eagle_files/</i>"); */
dlgHBoxLayout dlgSpacing(900);
dlgHBoxLayout
{
dlgStretch(0);
dlgSpacing(space);
if( strlen( tmpS10 ))
{
myULP_HOME = tmpS10;
}
else
{
tmpSX = cfgget( cfg_SCRIPT_ULP, myULP_HOME );
if( strlen(tmpSX ) )
myULP_HOME = tmpSX;
}
// dlgMessageBox( myULP_HOME + "/exp-lbrs.ulp");
if( !(check_for_exist_file( myULP_HOME + "exp-lbrs.ulp" ) && check_for_exist_file( myULP_HOME + "eagle-lbr2kicad-1.0.ulp") && check_for_exist_file( myULP_HOME + "run-me-first-from-eagle-sch.ulp" )) )
{
dlgLabel("<b><font color=\"red\">ULP conversion script file location not correct!");
tmpS10 = myULP_HOME;
rs = 1;
}
else
{
dlgLabel("<nobr>ULP conversion script file location</nobr>");
rs = 0;
tmpS10 = "";
}
dlgStringEdit( myULP_HOME );
dlgCheckBox("Save as default", saveAsDefaultULP_Path );
dlgPushButton("Edit") {
string xs;int it;
xs = dlgDirectory("Select directory containing conversion ULPs", "C:\\");
if( strlen(xs) )
tmpS10 = myULP_HOME = ( xs + '/');
}
dlgPushButton("Info") { if (dlgMessageBox( infoULPdir, "Ok") == 0); };
dlgStretch(0);
/* if( !(check_for_exist_file( myULP_HOME + "exp-lbrs.ulp" ) && check_for_exist_file( myULP_HOME + "eagle-lbr2kicad-1.0.ulp") && check_for_exist_file( myULP_HOME + "renum.ulp" ) )) */
/* { */
/* } */
}
dlgHBoxLayout
{
dlgStretch(0);
dlgSpacing(space);
dlgLabel("Target directory for KiCad files");
tmpSX = cfgget( cfg_TARGET_DIR, outputPath );
if( strlen(tmpSX ) )
outputPath = tmpSX;
dlgStringEdit( outputPath );
dlgCheckBox("Save as default", saveAsDefault );
dlgPushButton("Edit") {
string xs;int it;
xs = dlgDirectory("Select Targget directory", "C:\\");
if( strlen(xs) )
outputPath = xs + '/';
}
dlgPushButton("Info") { if (dlgMessageBox( infoTargetDirectory, "Ok") == 0); };
dlgStretch(0);
}
dlgHBoxLayout
{
dlgStretch(10);
dlgSpacing(space);
dlgLabel("Convert unconnected vias to pads");
dlgCheckBox("", enable_via_to_pad );
dlgPushButton("Info") { if (dlgMessageBox( infoConvertViaToPad, "Ok") == 0); };
dlgStretch(0);
}
dlgHBoxLayout
{
dlgStretch(10);
dlgSpacing(space);
dlgLabel("Document possible fills over pads");
dlgCheckBox("", docment_fill_over_pad );
dlgLabel("Layer");
dlgIntEdit( PadEagleReportLayerText, 16, 255);
dlgLabel("Layer Color");
dlgComboBox(Colors, PadEagleReportLayerTextColor);// dlgMessageBox("You have selected " + Colors[Selected]);
dlgPushButton("Info") { if (dlgMessageBox( infoDocFillOverPad, "Ok") == 0); };
dlgStretch(0);
}
dlgHBoxLayout
{
dlgStretch(10);
dlgSpacing(space);
dlgLabel("Document unconnected wires");
dlgCheckBox("", document_unconnected_wires );
dlgLabel("Text Layer");
dlgIntEdit( WireEagleReportLayerTxt, 100, 255);
dlgLabel("Arrow Layer");
dlgIntEdit( WireEagleReportLayerDrawing, 100, 255);
dlgLabel("Layer Color");
dlgComboBox(Colors, WireEagleReportLayerTxtColor );// dlgMessageBox("You have selected " + Colors[Selected]);
dlgPushButton("Info") { if (dlgMessageBox( infoDocomentUnconnectWires, "Ok") == 0); };
dlgStretch(0);
}
dlgHBoxLayout
{
dlgStretch(10);
dlgSpacing(space);
dlgLabel("Document unconnected vias");
dlgCheckBox("", docment_via_to_pad );
dlgLabel("Text Layer");
dlgIntEdit(ViaEagleReportLayerTxt, 100, 255);
dlgLabel("Arrow Layer");
dlgIntEdit(ViaEagleReportLayerDrawing, 100, 255);
dlgLabel("Layer Color");
dlgComboBox(Colors, ViaEagleReportLayerTxtColor);// dlgMessageBox("You have selected " + Colors[Selected]);
dlgPushButton("Info") { if (dlgMessageBox( infoDocomentUnconnectVias, "Ok") == 0); };
dlgStretch(0);
}
dlgHBoxLayout
{
dlgStretch(10);
dlgSpacing(space);
dlgLabel("Document unconnected blind vias");
dlgCheckBox("", docment_blind_via_to_pad );
dlgLabel("Text Layer");
dlgIntEdit( BlindEagleReportLayerTxt, 100, 255);
dlgLabel("Arrow Layer");
dlgIntEdit( BlindEagleReportLayerDrawing, 100, 255);
dlgLabel("Layer Color");
dlgComboBox(Colors, BlindEagleReportLayerTxtColor );// dlgMessageBox("You have selected " + Colors[Selected]);
dlgPushButton("Info") { if (dlgMessageBox( infoDocomentUnconnectVias, "Ok") == 0); };
dlgStretch(0);
}
dlgVBoxLayout
{
dlgStretch(10);
dlgHBoxLayout
{
dlgStretch(1);
dlgPushButton("+OK")
{
if( saveAsDefault )
cfgset( cfg_TARGET_DIR, outputPath );
/* else */
/* cfgset( cfg_TARGET_DIR, "" ); */
if( saveAsDefaultULP_Path )
cfgset( cfg_SCRIPT_ULP, myULP_HOME );
/* else */
/* cfgset(cfg_TARGET_DIR, "" ); */
dlgAccept();
};
dlgSpacing(space);
dlgPushButton("-Cancel") dlgReject();
dlgStretch(0);
dlgSpacing(space);
}
dlgStretch(10);
}
};
if (!result)
exit (0);
return ;
}
//--------------------------------------------------------------------------------
// find connected wire to via.
// return 0 if not found, else return 1 if found.
//
//
int findViaWire( int X, int Y, int base, int tablend )
{
int i;
for( i = base; i < tablend; i++ )
{
if(( X == aX[ i ]) && ( Y == aY[ i ]))