forked from robertstarr/ulp_user
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aps.ulp
142 lines (128 loc) · 4.36 KB
/
aps.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
#usage "Simple autoplace ulp based upon component position in schematic<p>"
"this ULp was origianlly written by one of the CADSOFT team I believe<p>"
"apologies for lack of full reference and acknoledgement<p>"
"run the ULP in the sch window and run place.scr in BRD<p>"
"changing the scale parameter will produce tighter/looser grouping<p>"
"<author>J meech";
/*
* Dialogue added to set sheet, scale 7 X,Y offset for the sheet of choice. 31/01/2011 by J meech.
* .ini file added to store the last settings to aid interactive placement. 31/01/2011 by J meech.
*/
// Start of executable program.
// variables in ini file
real page;
real scale;
real y_ShOffset;
real x_ShOffset;
// variables not in ini file
int HasPins;
int IsSupplySymbol;
int Px;
int Py;
int xoffset;
int yoffset;
int ix;
int Result =1;
int GridDist = 50;
string fps[];
string flines[];
string c,cmd;
string fnam; //ini file name
string gnam; //generic files name
string name; //scratch object name string
project.schematic (sch) { //open the schematic
fnam = sch.name; //get initial output file name from schematic
}
gnam = filesetext (fnam, ""); //remove .SCH file name suffix
fnam = gnam + "_aps"; //add to base name to indicate parts list
fnam = filesetext (fnam, ".ini"); //change to .ini file type
// search for ini file
int fp = fileglob(fps,fnam);
if(fp==1){
fileread(flines,fnam);
page = strtod(flines[0]);
scale = strtod(flines[1]);
y_ShOffset = strtod(flines[2]);
x_ShOffset = strtod(flines[3]);
} // load values from ini file
else {
page = 1;
scale = 0.3;
y_ShOffset = 0;
x_ShOffset = 0;
} // else use default values
Result = dlgDialog("Sheet autoplace"){
dlgHBoxLayout {
dlgGridLayout {
dlgCell(0,0)dlgLabel("<b>Schematic Sheet<b>");
dlgCell(0,1)dlgLabel("<b>Scale 0-1<b>");
dlgCell(1,0) dlgRealEdit(page, 1, 99);
dlgCell(1,1) dlgRealEdit (scale,0,1);
dlgCell(2,0)dlgLabel("<b>X offset mil<b>");
dlgCell(2,1)dlgLabel("<b>Y offset mil<b>");
dlgCell(3,0) dlgRealEdit(x_ShOffset, -30000, 30000);
dlgCell(3,1) dlgRealEdit (y_ShOffset,-30000,30000);
}
dlgVBoxLayout {
dlgHBoxLayout {
dlgStretch(1);
dlgPushButton("+OK") dlgAccept();
dlgStretch(0);
}
dlgHBoxLayout {
dlgStretch(1);
dlgPushButton("-Cancel") dlgReject();
dlgStretch(0);
}
}
}
};
if (Result == 0) exit (0);
page = trunc(page);
y_ShOffset = trunc(y_ShOffset);
x_ShOffset = trunc(x_ShOffset);
output (fnam, "wt") { //open the output file for text write //open the output file for text write
printf("%f", page);
printf ("\n");
printf("%f", scale);
printf ("\n");
printf("%f",y_ShOffset );
printf ("\n");
printf("%f",x_ShOffset );
printf ("\n");
}
output("place.scr") {
if (schematic) schematic(SCH) {
cmd+= "board; \n";
sprintf(c, "Grid mil 50;\n");
cmd+= c;
SCH.sheets(S) {
S.parts(P) {
ix = 0;
P.instances(I) {
if (ix==0) {
Px = round(scale*(u2mil(I.x)) / GridDist) * GridDist;
Py = round(scale*(u2mil(I.y)) / GridDist) * GridDist;
}
HasPins = 0;
IsSupplySymbol = 0;
I.gate.symbol.pins(PIN) {
if ((PIN.direction == PIN_DIRECTION_SUP))
IsSupplySymbol = 1;
HasPins = 1;
}
ix++;
}
if (HasPins && !IsSupplySymbol) {
xoffset = x_ShOffset;
yoffset = y_ShOffset;
if (S.number == page) sprintf(c, "Move %s (%d %d);\n", P.name, Px+xoffset, Py+yoffset);
cmd+= c;
}
} // end parts
} // end sheets
printf("GRID LAST;\n");
printf("RATSNEST;\n");
}
}
exit(cmd);