-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathmerge_lbr.ulp
1024 lines (979 loc) · 42.7 KB
/
merge_lbr.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>Library Merge</b><p>\n"
"This ULP will copy packages, symbols, and/or devices from one library to another. "
"The user must run this ULP with the destination library open. It will then copy "
"all of the symbols/packages/devices to a temporary file and then open the source "
"library. It will list all of the symbols/packages/devices in the source library "
"that don't have an identical name in the destination. The user can select any or "
"all of the devices and then hit copy. The ULP will then generate a export file of "
"those devices. It will re-open the destination library and import them. "
"<author>Jim Thurman [email protected] </author>"
string HelpText =
"This ULP will copy packages, symbols, and/or devices from one library to another. "
"The user must run this ULP with the destination library open. It will then copy "
"all of the symbols/packages/devices to a temporary file and then open the source "
"library. It will list all of the symbols/packages/devices in the source library "
"that don't have an identical name in the destination. The user can select any or "
"all of the devices and then hit copy. The ULP will then generate a export file of "
"those devices. It will re-open the destination library and import them. It checks "
"each device selected to be certain that symbols and packages that are a part of that "
"device are in the destination library or selected from the source. If not it gives "
"the user the opportunity to copy these symbol/packages as well. If you select the "
"same library for source as the one already open (destination) the list of "
"symbol/package/devices will be empty as they all match. If you terminate the ULP "
"by quiting the dialog box you will have the <b>source library open, not the original "
"destination.</b>"
"<\p>"
"This program can generate an export script of all or part of any library enabling "
"the possibility of selecting some symbol/package/devices from one or more libraries "
"to generate a completely new one. Not every possible object in a library is handled "
"at present but it does a good job of duplicating the libraries I tried. "
"<\p>"
"This program came from 'lbr_man_1_2.ulp' which seemed to want to do a similar thing "
"but didn't have the script export function done. Oppologies in advance if I find myself "
"without sufficient time to finish documenting the program and just upload it. "
"<\p>"
"NOTE: this program generates 1 temporary script file (Temp~1.scr) when the source library "
"is selected and another when the copy button is pushed (Temp~2.scr). Also the file "
"'DestLibData.tmp' which contains the names of the symbols, packages, and device sets in "
"the destination library."
;
int CurrentLayer; // last layer command written out so won't be duplicated in output
int CurrentStyle; // last line style written out
int CurrentFont; // last font
int CurrentRatio; // last ratio
real CurrentSize; // last text size
real CurrentDrill; // last drill size
int ListElement; // number of elements in display list
int DstPackageNum,DstSymbolNum,DstDeviceNum; // number of elements in destination symbol/package/device arrays
int SrcPackageNum,SrcSymbolNum,SrcDeviceNum; // number of elements in source symbol/package/device arrays
string DstPackage[],DstSymbol[],DstDevice[]; // destination library symbol/package/device names
string SrcPackage[],SrcSymbol[],SrcDevice[]; // source library symbol/package/device names
string List[]; // displayed list
//******************************************************************************************************
// writes out the help box
//******************************************************************************************************
void DisplayHelp(void) {
dlgDialog("Library Merge Help") {
dlgHBoxLayout dlgSpacing(400);
dlgHBoxLayout {
dlgVBoxLayout dlgSpacing(300);
dlgTextView(HelpText);
}
dlgHBoxLayout {
dlgStretch(1);
dlgPushButton("-Close") dlgReject();
}
};
}
//******************************************************************************************************
// get file path of any file open.
//******************************************************************************************************
string get_project_path() {
if (library) library(B) return(filedir(B.name));
if (board) board(B) return(filedir(B.name));
if (schematic) schematic(B) return(filedir(B.name));
}
//******************************************************************************************************
// right trim string of spaces
//******************************************************************************************************
string StrRTrim(string Str) {
int x;
x=strlen(Str)-1;
while ((x>=0) && (Str[x]==' ')) {
Str[x--]=0;
}
return(Str);
}
//**************************************************************************************************
// turn all last script output values off
//**************************************************************************************************
void ResetGlobals(void) {
CurrentLayer=-1; // no last layer sent
CurrentStyle=-1; // no last line style
CurrentSize=-1; // no last text size
CurrentFont=-1; // no last font
CurrentRatio=-1; // no last ratio
CurrentDrill=-1; // no last drill size
}
//**************************************************************************************************
// If new layer not the current one, then change.
//**************************************************************************************************
void ChangeLayer(int NewLayer) {
if (NewLayer!=CurrentLayer) {
CurrentLayer=NewLayer;
printf("Layer %d;\n",NewLayer);
}
}
//**************************************************************************************************
// If the new drill size is different then the current one then change.
//**************************************************************************************************
void ChangeDrill(real NewDrill) {
if (NewDrill!=CurrentDrill) {
CurrentDrill=NewDrill;
printf("Change Drill %f;\n",CurrentDrill);
}
}
//**************************************************************************************************
// The wire styles are stored as numbers by are written as text for scripts
//**************************************************************************************************
string WireStyleToText(int style) {
string str1;
switch (style) {
case WIRE_STYLE_CONTINUOUS: str1="continuous"; break;
case WIRE_STYLE_LONGDASH: str1="longdash"; break;
case WIRE_STYLE_SHORTDASH: str1="shortdash"; break;
case WIRE_STYLE_DASHDOT: str1="dashdot"; break;
default: str1="*INVALID"; break;
}
return(str1);
}
//**************************************************************************************************
// If the wire style is different then the current one then change
//**************************************************************************************************
void ChangeStyle(int NewStyle) {
if (NewStyle!=CurrentStyle) {
CurrentStyle=NewStyle;
printf("Change Style %s;\n",WireStyleToText(NewStyle));
}
}
//**************************************************************************************************
// If the new text size is different than the current one, change.
//**************************************************************************************************
void ChangeSize(real NewSize) {
if (NewSize!=CurrentSize) {
CurrentSize=NewSize;
printf("Change Size %f;\n",NewSize);
}
}
//**************************************************************************************************
// If the new text ratio is different than current, change.
//**************************************************************************************************
void CheckRatio(int NewRatio) {
if (NewRatio!=CurrentRatio) {
CurrentRatio=NewRatio;
printf("Change Ratio %d;\n",NewRatio);
}
}
//**************************************************************************************************
// Font codes are numberic internally but text in scripts
//**************************************************************************************************
string FontToText(int font) {
string str1;
switch(font) {
case FONT_VECTOR: str1="Vector"; break;
case FONT_PROPORTIONAL: str1="Proportional"; break;
case FONT_FIXED: str1="Fixed"; break;
}
return(str1);
}
//**************************************************************************************************
// if the new font is different than change it.
//**************************************************************************************************
void CheckFont(int NewFont) {
if (NewFont!=CurrentFont) {
CurrentFont=NewFont;
printf("Change Font %s;\n",FontToText(NewFont));
}
}
//**************************************************************************************************
// convert the numeric pad shape code to text
//**************************************************************************************************
string PadShapeToText(int PadShape) {
string str1;
switch(PadShape) {
case PAD_SHAPE_SQUARE: str1="Square"; break;
case PAD_SHAPE_ROUND: str1="Round"; break;
case PAD_SHAPE_OCTAGON: str1="Octagon"; break;
case PAD_SHAPE_LONG: str1="Long"; break;
case PAD_SHAPE_OFFSET: str1="Offset"; break;
case PAD_SHAPE_ANNULUS: str1="Annulus"; break; // (only if supply layers are used)
case PAD_SHAPE_THERMAL: str1="Thermal"; break; // (only if supply layers are used)
default: str1="INVALID"; break;
}
return(str1);
}
//**************************************************************************************************
// generate a text equivelent of the angle information
//**************************************************************************************************
string AngleToText(real f,int MirrorFlag,int SpinFlag) {
int i;
string str1,str2,str3;
i=f;
if (SpinFlag) str1="S";
else str1="";
if (MirrorFlag) str2="M";
else str2="";
sprintf(str3,"%s%sR%d",str1,str2,i);
return(str3);
}
//**************************************************************************************************
// print the script information related to a pad
//**************************************************************************************************
void PrintPad(UL_PAD Pad1,int layer1) {
real d,x,y,drill;
d=Pad1.diameter[layer1];
d=d/10000;
x=Pad1.x;
y=Pad1.y;
x=x/10000;
y=y/10000;
drill=Pad1.drill;
drill=drill/10000;
ChangeDrill(drill);
printf("Pad '%s' %s %f (%f %f);\n",Pad1.name,PadShapeToText(Pad1.shape[layer1]),d,x,y);
}
//**************************************************************************************************
// print the script information related for a smd
//**************************************************************************************************
void PrintSmd(UL_SMD Smd,int layer1) {
real dx,dy,x,y;
string flagstr;
dx=Smd.dx[Smd.layer];
dy=Smd.dy[Smd.layer];
dx=dx/10000;
dy=dy/10000;
x=Smd.x;
y=Smd.y;
x=x/10000;
y=y/10000;
flagstr="";
if ((Smd.flags & SMD_FLAG_STOP)==0) flagstr=flagstr+"NOSTOP ";
if ((Smd.flags & SMD_FLAG_THERMALS)==0) flagstr=flagstr+"NOTHERMALS ";
if ((Smd.flags & SMD_FLAG_CREAM)==0) flagstr=flagstr+"NOCREAM";
ChangeLayer(Smd.layer);
printf("Smd '%s' %f %f -%d R%f %s (%f %f);\n",Smd.name,dx,dy,Smd.roundness,Smd.angle,flagstr,x,y);
}
//**************************************************************************************************
// print the script information related for a contact which can be a pad or smd
//**************************************************************************************************
void PrintContact(UL_CONTACT Cont) {
if (Cont.pad) PrintPad(Cont.pad,LAYER_PADS);
if (Cont.smd) PrintSmd(Cont.smd,LAYER_TOP);
}
//**************************************************************************************************
// convert the direction code to script text
//**************************************************************************************************
string DirectionToText(int dir) {
string str1;
switch (dir) {
case PIN_DIRECTION_NC: str1="NC"; break;
case PIN_DIRECTION_IN: str1="In"; break;
case PIN_DIRECTION_OUT: str1="Out"; break;
case PIN_DIRECTION_IO: str1="I/O"; break;
case PIN_DIRECTION_OC: str1="OC"; break;
case PIN_DIRECTION_PWR: str1="Pwr"; break;
case PIN_DIRECTION_PAS: str1="Pas"; break;
case PIN_DIRECTION_HIZ: str1="Hiz"; break;
case PIN_DIRECTION_SUP: str1="Sup"; break;
}
return(str1);
}
//**************************************************************************************************
// convert the function code to text
//**************************************************************************************************
string FunctionToText(int fun) {
string str1;
switch (fun) {
case PIN_FUNCTION_FLAG_NONE: str1="None"; break;
case PIN_FUNCTION_FLAG_DOT: str1="Dot"; break;
case PIN_FUNCTION_FLAG_CLK: str1="Clk"; break;
}
return(str1);
}
//**************************************************************************************************
// convert pin length code to text
//**************************************************************************************************
string PinLengthToText(int fun) {
string str1;
switch (fun) {
case PIN_LENGTH_POINT: str1="Point"; break;
case PIN_LENGTH_SHORT: str1="Short"; break;
case PIN_LENGTH_MIDDLE: str1="Middle"; break;
case PIN_LENGTH_LONG: str1="Long"; break;
}
return(str1);
}
//**************************************************************************************************
// convert the pad/pin visible flags to text
//**************************************************************************************************
string PinVisibleToText(int PinVisibleFlag) {
string str1;
if (PinVisibleFlag & PIN_VISIBLE_FLAG_PAD) {
if (PinVisibleFlag & PIN_VISIBLE_FLAG_PIN) str1="Both";
else str1="Pad";
} else {
if (PinVisibleFlag & PIN_VISIBLE_FLAG_PIN) str1="Pin";
else str1="Off";
}
return(str1);
}
//**************************************************************************************************
// convert a name to a form that can be written out (no spaces or single quotes by themselves.
//**************************************************************************************************
string CheckName(string name) {
int x;
string str1;
str1=name;
x=0;
while (x>=0) {
x=strchr(str1,'\'',x);
if (x>=0) {
str1=strsub(str1,0,x+1)+"\'"+strsub(str1,x+1,strlen(str1)-x-1);
x=x+2;
if (x>=strlen(str1)) x=-1;
} else {
x=strchr(str1,' ',0);
if (x>=0) {
str1=strsub(str1,0,x)+"_*_"+strsub(str1,x+1,strlen(str1)-x);
x=x+4;
if (x>=strlen(str1)) x=-1;
}
}
}
return(str1);
}
//**************************************************************************************************
// remove carriage returns from string and replace with 'continute line'.
//**************************************************************************************************
string DescriptionToPrint(string desc) {
int x;
string str1;
str1=desc;
x=0;
while (x>=0) {
x=strchr(str1,'\n',x);
if (x>=0) {
str1=strsub(str1,0,x)+"\\"+strsub(str1,x,strlen(str1)-x);
x=x+2;
if (x>=strlen(str1)) x=-1;
}
}
return(str1);
}
//**************************************************************************************************
// replace carriage return or tab with space.
//**************************************************************************************************
string DescriptionToDisplay(string desc,int maxlen) {
int x;
string str1;
str1=desc;
if (strlen(str1)>maxlen) str1[maxlen-1]=0;
x=0;
while (x>=0) {
x=strchr(str1,'\n',x);
if (x>=0) {
str1[x]=' ';
}
x=strchr(str1,'\t',x);
if (x>=0) {
str1[x]=' ';
}
}
return(str1);
}
//**************************************************************************************************
// print the script command for pin generation
//**************************************************************************************************
void PrintPin(UL_PIN Pin) {
real x,y;
x=Pin.x;
y=Pin.y;
x=x/10000;
y=y/10000;
printf("Pin '%s' %s %s %s %s %s %d (%f %f);\n",CheckName(Pin.name),DirectionToText(Pin.direction),FunctionToText(Pin.function),
PinLengthToText(Pin.length),AngleToText(Pin.angle,0,0),PinVisibleToText(Pin.visible),Pin.swaplevel,x, y);
}
//**************************************************************************************************
// print the script information associated with a 'Area' data element
//**************************************************************************************************
void PrintArea(UL_AREA Area) {
printf("Area: (%d %d), (%d %d)\n",Area.x1, Area.y1, Area.x2, Area.y2);
}
//**************************************************************************************************
// print the script information associated with a 'Circle' data element
//**************************************************************************************************
void PrintCircles(UL_CIRCLE Circle) {
ChangeLayer(Circle.layer);
printf("Circle %d (%d %d) (%d 0);\n", Circle.width,Circle.x, Circle.y, Circle.radius);
}
//**************************************************************************************************
// print the script information associated with a 'Rectangle' data element
//**************************************************************************************************
void PrintRectangle(UL_RECTANGLE Rect) {
real x1,y1,x2,y2;
ChangeLayer(Rect.layer);
x1=Rect.x1;
y1=Rect.y1;
x2=Rect.x2;
y2=Rect.y2;
x1=x1/10000;
y1=y1/10000;
x2=x2/10000;
y2=y2/10000;
printf("Rect %s (%f %f) (%f %f);\n",AngleToText(Rect.angle,0,0),x1,y1,x2,y2);
}
//**************************************************************************************************
// convert arc cap code to text
//**************************************************************************************************
string CapToText(int cap) {
string str1;
switch (cap) {
case CAP_FLAT: str1="Flat"; break;
case CAP_ROUND: str1="Round"; break;
default: str1=""; break;
}
return(str1);
}
//**************************************************************************************************
// print script data related to an arc
//**************************************************************************************************
void PrintArc(UL_ARC Arc) {
ChangeLayer(Arc.layer);
printf("Arc: %f %f %s %d %d (%d %d) (%d %d) (%d %d)\n",Arc.angle1,Arc.angle2,CapToText(Arc.cap),Arc.radius,
Arc.width,Arc.x1,Arc.y1,Arc.x2,Arc.y2,Arc.xc,Arc.yc);
}
//**************************************************************************************************
// print script data related to a wire segment
//**************************************************************************************************
void PrintOneWire(UL_WIRE Wire) {
printf("Wire: %d %f %d %d %d (%d %d) (%d %d)\n",Wire.cap,Wire.curve,Wire.layer,Wire.style,Wire.width,
Wire.x1,Wire.y1,Wire.x2,Wire.y2);
// if (Wire.arc) PrintArc(Wire.arc);
}
//**************************************************************************************************
// print script data related to an wire
//**************************************************************************************************
void PrintWire(UL_WIRE Wire) {
string str1;
real f,x1,y1,x2,y2;
ChangeLayer(Wire.layer);
ChangeStyle(Wire.style);
f=Wire.width;
f=f/10000;
x1=Wire.x1;
y1=Wire.y1;
x2=Wire.x2;
y2=Wire.y2;
x1=x1/10000;
y1=y1/10000;
x2=x2/10000;
y2=y2/10000;
printf("Wire %f (%f %f) %s %+f (%f %f);\n",f,x1,y1,CapToText(Wire.cap),Wire.curve,x2,y2);
Wire.pieces(piece) {
}
}
//**************************************************************************************************
// print script data related to an polygon
//**************************************************************************************************
void PrintPolygon(UL_POLYGON Poly) {
real w;
w=Poly.width;
w=w/10000;
ChangeLayer(Poly.layer);
printf("Polygon %f;\n",w);
Poly.contours(Conts) {
PrintWire(Conts);
}
Poly.fillings(Fills) {
PrintWire(Fills);
}
Poly.wires(wires) {
PrintWire(wires);
}
}
//**************************************************************************************************
// print script data related to text
//**************************************************************************************************
void PrintText(UL_TEXT Text1) {
real f,x,y;
ChangeLayer(Text1.layer);
f=Text1.size;
f=f/10000;
ChangeSize(f);
CheckRatio(Text1.ratio);
CheckFont(Text1.font);
x=Text1.x;
y=Text1.y;
x=x/10000;
y=y/10000;
printf("Text '%s' %s (%f %f);\n",Text1.value,AngleToText(Text1.angle,Text1.mirror,Text1.spin),x,y);
}
//**************************************************************************************************
//**************************************************************************************************
void PrintCircle(UL_CIRCLE Circle) {
}
//**************************************************************************************************
// print script data related to a hole
//**************************************************************************************************
void PrintHole(UL_HOLE Hole,int layer) {
real drill;
drill=Hole.drill;
drill=drill/10000;
ChangeDrill(drill);
}
//**************************************************************************************************
// print all script data defining a package
//**************************************************************************************************
void PrintPackage(UL_PACKAGE Package) {
printf("Edit %s.pac;\n",CheckName(Package.name));
printf("Description '%s';\n",DescriptionToPrint(Package.description));
Package.holes(hole) {
PrintHole(hole,LAYER_TSTOP);
}
Package.circles(circle) {
PrintCircle(circle);
}
Package.contacts(contact) {
PrintContact(contact);
}
Package.polygons(polygon) {
PrintPolygon(polygon);
}
Package.rectangles(rectangle) {
PrintRectangle(rectangle);
}
Package.texts(text) {
PrintText(text);
}
Package.wires(wire) {
PrintWire(wire);
}
}
//**************************************************************************************************
// change layer number
//**************************************************************************************************
void PrintLayer(UL_LAYER Layer) {
printf("Layer %d %s;\n",Layer.number,Layer.name);
}
//**************************************************************************************************
// print all script data defining a sumbol
//**************************************************************************************************
void PrintSymbol(UL_SYMBOL Symbol) {
printf("Edit %s.sym;\n",CheckName(Symbol.name));
Symbol.circles(circle) {
PrintCircle(circle);
}
Symbol.rectangles(rect) {
PrintRectangle(rect);
}
Symbol.pins(pin) {
PrintPin(pin);
}
Symbol.polygons(poly) {
PrintPolygon(poly);
}
Symbol.texts(text) {
PrintText(text);
}
Symbol.wires(wire) {
PrintWire(wire);
}
}
//**************************************************************************************************
// convert add level code to text
//**************************************************************************************************
string AddLevelToText(int AddLevel) {
string str1;
switch(AddLevel) {
case GATE_ADDLEVEL_MUST: str1="Must"; break;
case GATE_ADDLEVEL_CAN: str1="Can"; break;
case GATE_ADDLEVEL_NEXT: str1="Next"; break;
case GATE_ADDLEVEL_REQUEST: str1="Request"; break;
case GATE_ADDLEVEL_ALWAYS: str1="Always"; break;
default: str1="INVALID"; break;
}
return(str1);
}
//**************************************************************************************************
// print script form of gate definition
//**************************************************************************************************
void PrintGate(UL_GATE Gate,string devname) {
real x,y;
x=Gate.x;
y=Gate.y;
x=x/10000;
y=y/10000;
printf("Add %s '%s' %s %d (%f %f);\n",devname,Gate.name,AddLevelToText(Gate.addlevel),Gate.swaplevel,x,y);
}
//**************************************************************************************************
// print all script data defining a device set
//**************************************************************************************************
void PrintDeviceSet(UL_DEVICESET DeviceSet) {
int GateNum,Variant;
real x,y;
GateNum=0;
printf("Edit %s.dev;\n",CheckName(DeviceSet.name));
printf("Prefix '%s';\n",DeviceSet.prefix);
printf("Description '%s';\n",DescriptionToPrint(DeviceSet.description));
printf("Value %s;\n",DeviceSet.value);
DeviceSet.devices(device) {
Variant++;
if (device.package) {
printf("Package '%s' '%s';\n",device.package.name,device.name);
printf("Technology %s;\n",device.technologies);
}
device.gates(gate) {
GateNum++;
x=gate.x;
y=gate.y;
x=x/10000;
y=y/10000;
if (Variant==1) {
printf("Add %s '%s' %s %d (%f %f);\n",CheckName(gate.symbol.name),CheckName(gate.name),AddLevelToText(gate.addlevel),gate.swaplevel,x,y);
}
gate.symbol.pins(pin) {
if (pin.contact) {
printf("Connect '%s.%s' '%s';\n",CheckName(gate.name),CheckName(pin.name),pin.contact.name);
}
}
}
}
}
//**************************************************************************************************
// convert the grid unit code to text
//**************************************************************************************************
string GridUnitToString(int GridUnit) {
string str1;
switch(GridUnit) {
case GRID_UNIT_MIC: str1="mic"; break;
case GRID_UNIT_MM: str1="mm"; break;
case GRID_UNIT_MIL: str1="mil"; break;
case GRID_UNIT_INCH: str1="inch"; break;
default: str1="INVALID"; break;
}
return(str1);
}
//**************************************************************************************************
// print grid. This is fixed information as the data returned from the library is wrong. Many
// dimensions are fixed in millimeters.
//**************************************************************************************************
void PrintGrid(UL_GRID Grid) {
printf("Grid mm;\n");
}
//**************************************************************************************************
// print all script data defining a library
//**************************************************************************************************
void PrintLibrary(UL_LIBRARY Library) {
string str1;
int Result;
status("Print Grid");
PrintGrid(Library.grid);
status(" Print Layers");
Library.layers(layer) {
PrintLayer(layer);
}
printf("Description '%s';\n",DescriptionToPrint(Library.description));
status(" Print Symbols");
Library.symbols(symbol1) {
ResetGlobals();
printf("\n");
PrintSymbol(symbol1);
}
status(" Print packages");
Library.packages(package1) {
ResetGlobals();
printf("\n");
PrintPackage(package1);
}
status("Print Device Sets");
Library.devicesets(device_set) {
printf("\n");
PrintDeviceSet(device_set);
}
}
//**************************************************************************************************
//**************************************************************************************************
void ToggleStatus(string ElementType) {
int x;
string TempAry[];
for (x=0;x<ListElement;x++) { // go through whole list
strsplit(TempAry,List[x],'\t'); // seperate elements
if ((TempAry[1]==ElementType) || (ElementType=="")) { // is this element one we are looking for?
if (strsub(TempAry[0],0,1)!=" ") { // yes, is it selected
List[x]=" "+strsub(List[x],1,strlen(List[x])-1); // yes, delselect
} else {
List[x]="*"+strsub(List[x],1,strlen(List[x])-1); // select
}
}
}
}
//**************************************************************************************************
// look at all selected devices to determine if all associated symbols and packages are in the destination
// library or selected to be copied from the source. If not, ask the operator if they want to copy
// the symbol or package from the source.
//**************************************************************************************************
void CheckDevice(string DeviceName) {
int EndLoop,x,y;
string Str1,TempAry[];
library(SourceLibrary) {
SourceLibrary.devicesets(devset) { // go through all devices sets in library
if (devset.name==DeviceName) { // the name of this one matches a selected device
devset.devices(device) { // go through all devices in this device set
if (device.package) { // this device has a valid package
y=0;
while ((y<DstPackageNum) && (device.package.name!=DstPackage[y])) y++; // search for a matching name in the destination library
if (device.package.name!=DstPackage[y]) { // package not found in destination library
y=0;
EndLoop=0;
while ((y<ListElement) && (EndLoop==0)) { // search through source list for name
strsplit(TempAry,List[y],'\t'); // break up source data line name and description
if ((TempAry[0]=="*") && (TempAry[1]=="Package")) { // check for selected package
if (TempAry[2]==device.package.name) EndLoop=1; // if this one has same name then package ok
}
y++;
}
if (EndLoop==0) { // this package isn't in destination library or selected in source
sprintf(Str1,"The package:%s attached to device:%s isn't in destination or selected from source. Copy from source?",device.package.name,devset.name);
if (dlgMessageBox(Str1,"&Yes", "&No")==0) { // if yes
y=0;
EndLoop=0;
while ((y<ListElement) && (EndLoop==0)) { // search through source list
strsplit(TempAry,List[y],'\t'); // break up source data line name and description
if ((TempAry[0]==" ") && (TempAry[1]=="Package")) { // This is a unselected package
if (TempAry[2]==device.package.name) EndLoop=1; // name matches
else y++;
} else y++;
}
if (EndLoop==1) { // we found the unselected item from the source library
List[y]="*"+strsub(List[y],1,strlen(List[y])-1); // indicate that it is now selected
} else {
dlgMessageBox("Couldn't find package for some reason"); // couldn't find package for some reason
}
}
}
}
}
device.gates(gate) { // search through all gates of this device
y=0;
while ((y<DstSymbolNum) && (gate.symbol.name!=DstSymbol[y])) y++; // search destination library
if (gate.symbol.name!=DstSymbol[y]) { // symbol not found in destination library
y=0;
EndLoop=0;
while ((y<ListElement) && (EndLoop==0)) { // search source list for selected name
strsplit(TempAry,List[y],'\t'); // break up source data line name and description
if ((TempAry[0]=="*") && (TempAry[1]=="Symbol")) { // selected symbol
if (TempAry[2]==gate.symbol.name) EndLoop=1; // if names match, exit
}
y++;
}
if (EndLoop==0) { // no symbol in destination or selected in source
sprintf(Str1,"The symbol:%s attached to device:%s isn't in destination or selected from source. Copy from source?",gate.symbol.name,devset.name);
if (dlgMessageBox(Str1,"&Yes", "&No")==0) { // yes - reselect symbol
y=0;
EndLoop=0;
while ((y<ListElement) && (EndLoop==0)) { // search through source list for unselected name
strsplit(TempAry,List[y],'\t'); // break up source data line name and description
if ((TempAry[0]==" ") && (TempAry[1]=="Symbol")) { // found symbol name
if (TempAry[2]==gate.symbol.name) EndLoop=1;
else y++;
} else y++;
}
if (EndLoop==1) { // unselected symbol name found, select
List[y]="*"+strsub(List[y],1,strlen(List[y])-1);
} else {
dlgMessageBox("Couldn't find symbol for some reason");
}
}
}
}
}
}
}
}
}
}
//**************************************************************************************************
// This program assumes that a library is open and it is the destination library. Since a ULP can't
// open and close libraries arbitraritly, the program uses the 'exit' function with a parameter of
// the next ULP to run. It creates temporary ULP's the open the source library and then activate the
// script it generates
//**************************************************************************************************
int NotFound;
string TempStr;
int x,y,n;
int Length;
int RunNum;
string ProgName;
string FileInData[];
string TempAry[];
string FirstArgument;
string Str1,Str2;
string EditName;
string SourceFileName;
string WorkPath;
//string SourcePath;
ProgName=argv[0]; // name of this program
WorkPath = get_project_path(); // path for temp file
x=strchr(WorkPath,':'); // get colon
if (x>0) WorkPath=strsub(WorkPath,0,x+2); // if there is a colon then this is just the drive and root '\'
FirstArgument="";
if (argc>0) FirstArgument=argv[1]; // run number argument, if any
RunNum=strtol(FirstArgument);
switch(RunNum) {
case 0: // first iteration
if (library) { // check to see if a library file is open
library(DestLibrary) { // assign a variable to this library
EditName=filename(DestLibrary.name); // name of loaded library w/o path
output(WorkPath+"DestLibData.tmp", "wt") { // create a temporary file of this library
DestLibrary.symbols(S) printf("S\t%s\n",StrRTrim(S.name)/*,StrRTrim(S.description)*/); // write out all symbol names
DestLibrary.packages(P) printf("P\t%s\n",StrRTrim(P.name)/*,StrRTrim(P.description)*/); // write out packages names
DestLibrary.devicesets(D) printf("D\t%s\n",StrRTrim(D.name)/*,StrRTrim(D.description)*/);// write out device names
}
};
SourceFileName = dlgFileOpen("Select source library", SourceFileName, "*.lbr"); // activate the dialog box to select the source library
if (SourceFileName != "") {
output(WorkPath+"Temp~1.scr", "wt") { // create/edit the script file to invoke this ULP with the destination library open
printf("OPEN \'%s\';\n",SourceFileName); // open the source library file
printf("RUN '%s' 1 '%s';\n",ProgName,EditName); // run this program with a '1' for the run number
};
sprintf(TempStr,"script %sTemp~1.scr",WorkPath); // script name to run on exit
exit(TempStr); // exit this interation and run the temporary script
}
} else {
dlgMessageBox("<b>ERROR</b><hr>This program can only work in the library editor.");
}
break;
case 1: // this is the second iteration of this ULP with the source library file open through script 'Temp~1'
library(SourceLibrary) { // assign a variable to library data
status("Loading Source File"); // indicate that we are loading the source file in the status box
Length=fileread(FileInData,WorkPath+"DestLibData.tmp"); // read in destination library data
DstSymbolNum=0; // number of symbols in destination library
DstPackageNum=0; // number of symbols in destination library
DstDeviceNum=0; // number of devices in destination library
for (x=0;x<Length;x++) { // store the destination library information in arrays
strsplit(TempAry,FileInData[x],'\t'); // break up source data line name and description
if (TempAry[0]=="S") DstSymbol[DstSymbolNum++]=StrRTrim(TempAry[1]); // name of a symbol in the destination library
else {
if (TempAry[0]=="P") DstPackage[DstPackageNum++]=StrRTrim(TempAry[1]); // name of a package in the destination library
else {
if (TempAry[0]=="D") DstDevice[DstDeviceNum++]=StrRTrim(TempAry[1]); // name of a device in the destination library
}
}
}
ListElement=0; // number of elements in the display list
SourceLibrary.symbols(S) { // go through the source library symbols looking for unique names
Str1=StrRTrim(S.name); // name of symbol
y=0;
NotFound=1;
while ((y<DstSymbolNum) && (NotFound)) { // check destination library for same name
if (DstSymbol[y]==Str1) NotFound=0; // name match, leave out of list
else y++;
}
if (NotFound) { // no name match, add this symbol to the display list
SrcSymbol[SrcSymbolNum++]=Str1; // save this package in the array as it isn't in the destination library
List[ListElement++]="*\tSymbol\t"+Str1+"\t"+DescriptionToDisplay(S.description,20); // add symbol to list
}
}
SourceLibrary.packages(P) { // go through all source packages
Str1=StrRTrim(P.name); // name of package
y=0;
NotFound=1;
while ((y<DstPackageNum) && (NotFound)) { // search for name match in destination library
if (DstPackage[y]==Str1) NotFound=0; // name match
else y++;
}
if (NotFound) { // no name matched, add this package to list
SrcPackage[SrcPackageNum++]=Str1; // save this package in the array as it isn't in the destination library
List[ListElement++]="*\tPackage\t"+Str1+"\t"+DescriptionToDisplay(P.description,20); // add package to display list
}
}
SourceLibrary.devicesets(D) { // go through source library device sets
Str1=StrRTrim(D.name); // name
y=0;
NotFound=1;
while ((y<DstDeviceNum) && (NotFound)) { // search through destination library for same device set
if (DstDevice[y]==Str1) NotFound=0; // same name found
else y++;
}
if (NotFound) { // no such device set found
SrcDevice[SrcDeviceNum++]=Str1; // save this package in the array as it isn't in the destination library
List[ListElement++]="*\tDevice Set\t"+Str1+"\t"+DescriptionToDisplay(D.description,20); // add this device set to list
}
}
}
dlgDialog("Copy unique elements from source library to destination library") { // start dialog box
dlgHBoxLayout {
dlgListView("Selected\tType\tName\tDescription",List,n) { // header for display list
if (strsub(List[n],0,1)!=" ") { // select toggles the select status
List[n]=" "+strsub(List[n],1,strlen(List[n])-1); // deselect if selected
} else {
List[n]="*"+strsub(List[n],1,strlen(List[n])-1); // select if not selected
}
};
};
dlgSpacing(10);
dlgHBoxLayout {
dlgPushButton("Toggle &All") { // this button flips switches all status's to other state
ToggleStatus(""); // toggle status of all
}
dlgPushButton("Toggle Symbols") {
ToggleStatus("Symbol"); // toggle status of Symbols
}
dlgPushButton("Toggle Packages") {
ToggleStatus("Package"); // toggle status of Packages
};
dlgPushButton("Toggle Devices") {
ToggleStatus("Device Set"); // toggle status of devices
}
};
dlgHBoxLayout {
dlgPushButton("Copy to Dest") { // create script of all selected elements
for (x=0;x<ListElement;x++) { // check devices to be copied to make sure packages and symbols are there
strsplit(TempAry,List[x],'\t');
if ((TempAry[0]=="*") && (TempAry[1]=="Device Set")) {
CheckDevice(TempAry[2]); // check devices symbols and packages to make sure they will be in destination
}
}
output(WorkPath+"Temp~2.scr", "wt") { // create second script file
printf("OPEN \'%s\';\n",argv[2]); // open destination library
library(SourceLibrary) { // append selected additions
PrintGrid(SourceLibrary.grid);
SourceLibrary.layers(layer) {
PrintLayer(layer);
}
for (x=0;x<ListElement;x++) {
strsplit(TempAry,List[x],'\t'); // break up source data line name and description
if (TempAry[0]=="*") { // This item is selected
if (TempAry[1]=="Symbol") { // its a symbol
SourceLibrary.symbols(sym) { // go through the symbols in the library
if (StrRTrim(sym.name)==TempAry[2]) { // the names match
printf("\n");
PrintSymbol(sym); // print this information as a script
}
};
} else {
if (TempAry[1]=="Package") { // this item is a package
SourceLibrary.packages(pack) { // go through the packages in the library
if (StrRTrim(pack.name)==TempAry[2]) { // names match
printf("\n");
PrintPackage(pack); // print the script information for the package
}
};
} else {
if (TempAry[1]=="Device Set") { // this item is a device set
SourceLibrary.devicesets(dev) { // go through all device sets in the library
if (StrRTrim(dev.name)==TempAry[2]) { // names match
printf("\n");