This repository was archived by the owner on Oct 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathalign_objects.ulp
More file actions
172 lines (146 loc) · 5.73 KB
/
align_objects.ulp
File metadata and controls
172 lines (146 loc) · 5.73 KB
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
#usage "en: <b>An ULP to align the selected objects in a particular manner</b>"
"<p>"
"An ULP to align the selected objects to be aligned to a straight line either horizontally or vertically."
"It also can order the selected object to have equal gaps vertically or horizontally."
"</p>"
"<p>"
"The following section should be added to the .eaglerc, and the text command should be set to visible in both the schematic and layout editor:"
"</p>"
"<i>"
"Sch.MenuText.01 = \"[align.png] Align selected objects { [format-justify-top.png] Align to top: Run align_objects.ulp vtop; | [format-justify-bot.png] Align to bottom: Run align_objects.ulp vbot; | [format-justify-left.png] Align left: Run align_objects.ulp hleft; | [format-justify-right.png] Align right : Run align_objects.ulp hright;}\""
"<br>"
"Brd.MenuText.01 = \"[align.png] Align selected objects { [format-justify-top.png] Align to top: Run align_objects.ulp vtop; | [format-justify-center_v.png] Align center vertically: Run align_objects.ulp vcenter; | [format-justify-bot.png] Align to bottom: Run align_objects.ulp vbot; | [format-justify-left.png] Align left: Run align_objects.ulp hleft; | [format-justify-center.png] Align center horizontally: Run align_objects.ulp hcenter; | [format-justify-right.png] Align right : Run align_objects.ulp hright;}\""
"</i>"
"<p>The latest version can be obtained from the <a href=https://github.com/martonmiklos/ulps_for_eagle>GitHub</a></p>"
"<p><author>Author: <a href=mailto:martonmiklosqdev@gmail_dot_com>Miklos Marton </author></a><p>"
enum {
Horizontal_Left,
Horizontal_Center,
Horizontal_Right,
Horizontal_Equal_Gaps,
Vertical_Top,
Vertical_Center,
Vertical_Bottom
};
int alignMode = Horizontal_Left;
UL_ELEMENT elements[];
UL_INSTANCE instances[];
real minX = REAL_MAX, minY = REAL_MAX;
real maxX = REAL_MIN, maxY = REAL_MIN;
int selectedItemsCount = 0;
string retCommand = "";
if (argv[1] == "hleft")
alignMode = Horizontal_Left;
if (argv[1] == "hcenter")
alignMode = Horizontal_Center;
if (argv[1] == "hright")
alignMode = Horizontal_Right;
if (argv[1] == "vtop")
alignMode = Vertical_Top;
if (argv[1] == "vcenter")
alignMode = Vertical_Center;
if (argv[1] == "vbottom" || argv[1] == "vbot")
alignMode = Vertical_Bottom;
if (board) {
board(B) {
B.elements(E) {
if (ingroup(E)) {
elements[selectedItemsCount] = E;
if (E.x < minX)
minX = u2mil(E.x);
if (E.x > maxX)
maxX = u2mil(E.x);
if (E.y < minY)
minY = u2mil(E.y);
if (E.y > maxY)
maxY = u2mil(E.y);
selectedItemsCount++;
}
}
}
if (selectedItemsCount == 0) {
dlgMessageBox("No objects selected", "&Ok");
} else {
for (int i = 0; i<selectedItemsCount; i++) {
switch (alignMode) {
case Horizontal_Left:
sprintf(retCommand, "%sMOVE %s (%fmil %fmil);\n", retCommand, elements[i].name, minX, u2mil(elements[i].y));
break;
case Horizontal_Center:
sprintf(retCommand, "%sMOVE %s (%fmil %fmil);\n", retCommand, elements[i].name, (maxX - minX)/2 + minX, u2mil(elements[i].y));
break;
case Horizontal_Right:
sprintf(retCommand, "%sMOVE %s (%fmil %fmil);\n", retCommand, elements[i].name, maxX, u2mil(elements[i].y));
break;
case Vertical_Top:
sprintf(retCommand, "%sMOVE %s (%fmil %fmil);\n", retCommand, elements[i].name, u2mil(elements[i].x), maxY);
break;
case Vertical_Center:
sprintf(retCommand, "%sMOVE %s (%fmil %fmil);\n", retCommand, elements[i].name, u2mil(elements[i].x), (maxY - minY)/2 + minY);
break;
case Vertical_Bottom:
sprintf(retCommand, "%sMOVE %s (%fmil %fmil);\n", retCommand, elements[i].name, u2mil(elements[i].x), minY);
break;
default:
dlgMessageBox("Invalid align mode argument: "+argv[1], "&Ok");
break;
}
}
}
} /*else if (schematic) {
schematic(SCH) {
char selectionFound = 0;
SCH.sheets(S) {
S.instances(I) {
if (ingroup(I)) {
selectionFound = 1;
instances[selectedItemsCount] = I;
if (I.x < minX)
minX = u2mil(I.x);
if (I.x > maxX)
maxX = u2mil(I.x);
if (I.y < minY)
minY = u2mil(I.y);
if (I.y > maxY)
maxY = u2mil(I.y);
selectedItemsCount++;
}
}
// quit the sheet loop if found a selected part
// I have no idea how can be selection on multiple sheets, but if it could be that would mess up the
// result of the script
if (selectionFound)
break;
}
}
if (selectedItemsCount == 0) {
dlgMessageBox("No objects selected", "&Ok");
} else {
for (int i = 0; i<selectedItemsCount; i++) {
switch (alignMode) {
case Horizontal_Left:
sprintf(retCommand, "%sMOVE %s (%fmil %fmil);\n", retCommand, instances[i].name, minX, u2mil(instances[i].y));
break;
case Horizontal_Center:
sprintf(retCommand, "%sMOVE %s (%fmil %fmil);\n", retCommand, instances[i].name, (maxX - minX)/2 + minX, u2mil(instances[i].y));
break;
case Horizontal_Right:
sprintf(retCommand, "%sMOVE %s (%fmil %fmil);\n", retCommand, instances[i].name, maxX, u2mil(instances[i].y));
break;
case Vertical_Top:
sprintf(retCommand, "%sMOVE %s (%fmil %fmil);\n", retCommand, instances[i].name, u2mil(instances[i].x), maxY);
break;
case Vertical_Center:
sprintf(retCommand, "%sMOVE %s (%fmil %fmil);\n", retCommand, instances[i].name, u2mil(instances[i].x), (maxY - minY)/2 + minY);
break;
case Vertical_Bottom:
sprintf(retCommand, "%sMOVE %s (%fmil %fmil);\n", retCommand, instances[i].name, u2mil(instances[i].x), minY);
break;
default:
dlgMessageBox("Invalid align mode argument: "+argv[1], "&Ok");
break;
}
}
}
}*/
exit(retCommand);