📄 cmd-renumber.ulp
字号:
largest_number_prefix = number_prefix; // update largest_n..
number_prefix = 1;
}
}
if (dir == 1) {
sort (i_p_top, index_top, comp_x_abs_top, comp_y_abs_top, prefix_top, old_suffix_top, new_suffix_top) ;
j = 0 ;
do {
w = comp_x_abs_top[index_top[j]] + win;
for (i = j + 1; i < i_p_top; ++i) {
if (comp_x_abs_top[index_top[i]] > w) {
break ;
}
if (comp_y_abs_top[index_top[i]] < comp_y_abs_top[index_top[i - 1]]) {
tmp_real = comp_x_abs_top[index_top[i - 1]];
comp_x_abs_top[index_top[i - 1]] = comp_x_abs_top[index_top[i]];
comp_x_abs_top[index_top[i]] = tmp_real;
tmp_real = comp_y_abs_top[index_top[i - 1]];
comp_y_abs_top[index_top[i - 1]] = comp_y_abs_top[index_top[i]];
comp_y_abs_top[index_top[i]] = tmp_real;
tmp_string = prefix_top[index_top[i - 1]];
prefix_top[index_top[i - 1]] = prefix_top[index_top[i]];
prefix_top[index_top[i]] = tmp_string;
tmp_int = old_suffix_top[index_top[i - 1]];
old_suffix_top[index_top[i - 1]] = old_suffix_top[index_top[i]];
old_suffix_top[index_top[i]] = tmp_int;
tmp_int = new_suffix_top[index_top[i - 1]];
new_suffix_top[index_top[i - 1]] = new_suffix_top[index_top[i]];
new_suffix_top[index_top[i]] = tmp_int;
i = j ;
}
}
j = i ;
} while (j < i_p_top) ;
}
else {
sort (i_p_top, index_top, comp_y_abs_top, comp_x_abs_top, prefix_top, old_suffix_top, new_suffix_top) ;
j = 0 ;
do {
w = comp_y_abs_top[index_top[j]] + win;
for (i = j + 1; i < i_p_top; ++i) {
if (comp_y_abs_top[index_top[i]] > w) {
break ;
}
if (comp_x_abs_top[index_top[i]] < comp_x_abs_top[index_top[i - 1]]) {
tmp_real = comp_x_abs_top[index_top[i - 1]];
comp_x_abs_top[index_top[i - 1]] = comp_x_abs_top[index_top[i]];
comp_x_abs_top[index_top[i]] = tmp_real;
tmp_real = comp_y_abs_top[index_top[i - 1]];
comp_y_abs_top[index_top[i - 1]] = comp_y_abs_top[index_top[i]];
comp_y_abs_top[index_top[i]] = tmp_real;
tmp_string = prefix_top[index_top[i - 1]];
prefix_top[index_top[i - 1]] = prefix_top[index_top[i]];
prefix_top[index_top[i]] = tmp_string;
tmp_int = old_suffix_top[index_top[i - 1]];
old_suffix_top[index_top[i - 1]] = old_suffix_top[index_top[i]];
old_suffix_top[index_top[i]] = tmp_int;
tmp_int = new_suffix_top[index_top[i - 1]];
new_suffix_top[index_top[i - 1]] = new_suffix_top[index_top[i]];
new_suffix_top[index_top[i]] = tmp_int;
i = j ;
}
}
j = i ;
} while (j < i_p_top) ;
}
// Bottom side of board
board(B) {
B.elements(E) {
ref_name = E.name ;
if (!(strlen(ref_name)<=1 || isdigit(ref_name[0]))) { // exclude R, 04 etc.
length_of_name = strlen(ref_name) ;
prefix_bottom[i_p_bottom] = "" ;
new_suffix_bottom[i_p_bottom] = 0 ;
tmp_string = "" ;
if (isdigit(ref_name[length_of_name - 1]) && E.mirror == 1 ) {
for (i = strlen(ref_name) - 1; isdigit(ref_name[i]); --i); // find prefix
prefix_bottom[i_p_bottom] = strsub(ref_name, 0, i+1);
tmp_string = strsub(ref_name, i+1); // suffix
old_suffix_bottom[i_p_bottom] = strtol(tmp_string) ;
switch (c_bottom)
{
case 1: // Top-Right
{
comp_x_abs_bottom[i_p_bottom] = abs(u2inch(E.x) - pcb_max_x) ;
comp_y_abs_bottom[i_p_bottom] = abs(u2inch(E.y) - pcb_max_y) ;
break;
}
case 0: // Top-Left
{
comp_x_abs_bottom[i_p_bottom] = abs(u2inch(E.x) + abs(pcb_min_x)) ;
comp_y_abs_bottom[i_p_bottom] = abs(u2inch(E.y) - pcb_max_y) ;
break;
}
case 2: // Bottom-Left
{
comp_x_abs_bottom[i_p_bottom] = abs(u2inch(E.x) + abs(pcb_min_x)) ;
comp_y_abs_bottom[i_p_bottom] = abs(u2inch(E.y) + abs(pcb_min_y)) ;
break;
}
case 3: // Bottom-Right
{
comp_x_abs_bottom[i_p_bottom] = abs(u2inch(E.x) - pcb_max_x) ;
comp_y_abs_bottom[i_p_bottom] = abs(u2inch(E.y) + abs(pcb_min_y)) ;
break;
}
default: // default is Top-Right Corner for Bottom side.
{
comp_x_abs_bottom[i_p_bottom] = abs(u2inch(E.x) - pcb_max_x) ;
comp_y_abs_bottom[i_p_bottom] = abs(u2inch(E.y) - pcb_max_y) ;
}
}
++i_p_bottom ;
}
}
}
}
if (dir == 1) {
sort (i_p_bottom, index_bottom, comp_x_abs_bottom, comp_y_abs_bottom, prefix_bottom, old_suffix_bottom, new_suffix_bottom) ;
j = 0 ;
do {
w = comp_x_abs_bottom[index_bottom[j]] + win;
for (i = j + 1; i < i_p_bottom; ++i) {
if (comp_x_abs_bottom[index_bottom[i]] > w) {
break ;
}
if (comp_y_abs_bottom[index_bottom[i]] < comp_y_abs_bottom[index_bottom[i - 1]]) {
tmp_real = comp_x_abs_bottom[index_bottom[i - 1]];
comp_x_abs_bottom[index_bottom[i - 1]] = comp_x_abs_bottom[index_bottom[i]];
comp_x_abs_bottom[index_bottom[i]] = tmp_real;
tmp_real = comp_y_abs_bottom[index_bottom[i - 1]];
comp_y_abs_bottom[index_bottom[i - 1]] = comp_y_abs_bottom[index_bottom[i]];
comp_y_abs_bottom[index_bottom[i]] = tmp_real;
tmp_string = prefix_bottom[index_bottom[i - 1]];
prefix_bottom[index_bottom[i - 1]] = prefix_bottom[index_bottom[i]];
prefix_bottom[index_bottom[i]] = tmp_string;
tmp_int = old_suffix_bottom[index_bottom[i - 1]];
old_suffix_bottom[index_bottom[i - 1]] = old_suffix_bottom[index_bottom[i]];
old_suffix_bottom[index_bottom[i]] = tmp_int;
tmp_int = new_suffix_bottom[index_bottom[i - 1]];
new_suffix_bottom[index_bottom[i - 1]] = new_suffix_bottom[index_bottom[i]];
new_suffix_bottom[index_bottom[i]] = tmp_int;
i = j ;
}
}
j = i ;
} while (j < i_p_bottom) ;
}
else {
sort (i_p_bottom, index_bottom, comp_y_abs_bottom, comp_x_abs_bottom, prefix_bottom, old_suffix_bottom, new_suffix_bottom) ;
j = 0 ;
do {
w = comp_y_abs_bottom[index_bottom[j]] + win;
for (i = j + 1; i < i_p_bottom; ++i) {
if (comp_y_abs_bottom[index_bottom[i]] > w) {
break ;
}
if (comp_x_abs_bottom[index_bottom[i]] < comp_x_abs_bottom[index_bottom[i - 1]]) {
tmp_real = comp_x_abs_bottom[index_bottom[i - 1]];
comp_x_abs_bottom[index_bottom[i - 1]] = comp_x_abs_bottom[index_bottom[i]];
comp_x_abs_bottom[index_bottom[i]] = tmp_real;
tmp_real = comp_y_abs_bottom[index_bottom[i - 1]];
comp_y_abs_bottom[index_bottom[i - 1]] = comp_y_abs_bottom[index_bottom[i]];
comp_y_abs_bottom[index_bottom[i]] = tmp_real;
tmp_string = prefix_bottom[index_bottom[i - 1]];
prefix_bottom[index_bottom[i - 1]] = prefix_bottom[index_bottom[i]];
prefix_bottom[index_bottom[i]] = tmp_string;
tmp_int = old_suffix_bottom[index_bottom[i - 1]];
old_suffix_bottom[index_bottom[i - 1]] = old_suffix_bottom[index_bottom[i]];
old_suffix_bottom[index_bottom[i]] = tmp_int;
tmp_int = new_suffix_bottom[index_bottom[i - 1]];
new_suffix_bottom[index_bottom[i - 1]] = new_suffix_bottom[index_bottom[i]];
new_suffix_bottom[index_bottom[i]] = tmp_int;
i = j ;
}
}
j = i ;
} while (j < i_p_bottom) ;
}
i_p_both = 0;
for (i = 0; i < i_p_top; ++i) {
prefix_both[i_p_both] = prefix_top[index_top[i]];
old_suffix_both[i_p_both] = old_suffix_top[index_top[i]];
new_suffix_both[i_p_both] = new_suffix_top[index_top[i]];
++i_p_both;
}
for (i = 0; i < i_p_bottom; ++i) {
prefix_both[i_p_both] = prefix_bottom[index_bottom[i]];
old_suffix_both[i_p_both] = old_suffix_bottom[index_bottom[i]];
new_suffix_both[i_p_both] = new_suffix_bottom[index_bottom[i]];
++i_p_both;
}
}
//--------------------------------------------------------------------------------
// change names if necessary: R01 -> R100001 etc.
string correct_name(string s) {
string s1, s2;
int i, j;
if (strlen(s) < 2 || isdigit(s[0]))
return s; // single character or name starts with 0
if (!isdigit(s[strlen(s)-1])) // no suffix
return s;
for (i = 0; !isdigit(s[i]); ++i); // i points to first numeric character
for (j = strlen(s) - 1; isdigit(s[j]); --j); // j points to last non-numeric character
if ((i < strlen(s) -1) && s[i] == '0') {
s1 = strsub(s, 0, i);
s2 = strsub(s, i);
s = s1+"1000"+s2;
}
return s;
}
//--------------------------------------------------------------------------------
void view_names(void) {
board(B) {
B.elements(P) {
h= ""; sprintf(h, "%s\n", P.name);
cmd += h;
}
}
dlgDialog("Part names") {
dlgHBoxLayout {
dlgVBoxLayout dlgSpacing(300);
dlgTextView(cmd);
}
dlgHBoxLayout {
dlgStretch(1);
dlgPushButton("-Close") dlgReject();
}
};
}
//--------------------------------------------------------------------------------
void check_names(void) {
int name_changed = 0;
string corr_name;
cmd = ";\n";
board(B) { // replace R01 with R100001 etc.
B.elements(P) {
corr_name = correct_name(P.name);
if (corr_name != P.name) {
name_changed = 1;
h= ""; sprintf(h, "NAME '%s' '%s';\n", P.name, corr_name);
cmd += h;
}
}
}
if (name_changed) {
if (dlgMessageBox("Board contains packages with leading zero\nsuffixes (e.g. R01). Renumber cannot handle such names!\n\nChange automatically?",
"&OK", "&Quit") == 0) {
Result = dlgDialog("Changes") {
dlgHBoxLayout {
dlgVBoxLayout dlgSpacing(300);
dlgTextView(cmd);
}
dlgHBoxLayout {
dlgStretch(1);
dlgSpacing(40);
dlgPushButton("-OK") dlgAccept();
dlgPushButton("-Close") dlgReject();
}
};
if (!Result) exit(0);
cmd += "RUN "+get_progname();
exit(cmd);
}
else {
exit(0);
}
}
}
//--- main -----------------------------------------------------------------------
if (!board) {
dlgMessageBox(usage + "<hr><b>ERROR: No board!</b><p>\nThis program can only work in the board editor.");
exit(1);
}
dlgDialog("Renumber Components") {
dlgHBoxLayout {
dlgGroup("Unit") {
dlgRadioButton("&inch", unit);
dlgRadioButton("&mm", unit);
}
dlgGroup("Direction") {
dlgRadioButton("&Horizontal", dir);
dlgRadioButton("&Vertical", dir);
}
dlgGroup("Top Side: Start from") {
dlgGridLayout {
dlgCell(0, 0) dlgRadioButton("Top left", c_top);
dlgCell(0, 3) dlgRadioButton("Top right", c_top);
dlgCell(3, 0) dlgRadioButton("Bottom left ", c_top);
dlgCell(3, 3) dlgRadioButton("Bottom right", c_top);
}
}
dlgGroup("Bottom Side: Start from") {
dlgGridLayout {
dlgCell(0, 0) dlgRadioButton("Top left", c_bottom);
dlgCell(0, 3) dlgRadioButton("Top right", c_bottom);
dlgCell(3, 0) dlgRadioButton("Bottom left ", c_bottom);
dlgCell(3, 3) dlgRadioButton("Bottom right", c_bottom);
}
}
}
dlgHBoxLayout {
dlgRealEdit(window, 0.0, 99.0);
dlgLabel("Scan &window ");
dlgIntEdit(sequence_bottom, 0, 1000);
dlgLabel("Bottom suffix ");
dlgCheckBox("&Show scripts ", show_script);
dlgStretch(1);
}
dlgSpacing(30);
dlgHBoxLayout {
dlgStretch(1);
dlgPushButton("&View names") view_names();
dlgPushButton("+&Preview") { get_data();
check_names();
preview();
}
dlgPushButton("&Renumber") { get_data();
check_names();
renumber();
}
dlgPushButton("-&Quit") dlgReject();
dlgSpacing(30);
dlgPushButton("&Help") DisplayHelp();
}
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -