From: yu.dongliang <18588496441@163.com> Date: Sun, 9 Jul 2023 15:55:22 +0000 (+0800) Subject: layout X-Git-Url: http://baseworks.info/?a=commitdiff_plain;h=d49d70494e1a37eb274719b2ff01037fc16508bf;p=ses.git layout --- diff --git a/main.c b/main.c index d255c46..49e93de 100644 --- a/main.c +++ b/main.c @@ -46,7 +46,7 @@ int main(int argc, char* argv[]) ScfEboard* b = scf_eboard__unpack(NULL, len, pb); - ses_layout_board(b, 0, 0, 30, 160); + ses_layout_board(b, 0, 0, 25, 100); #if 0 size_t i; size_t j; diff --git a/ses_layout.c b/ses_layout.c index 1573ede..8b54228 100644 --- a/ses_layout.c +++ b/ses_layout.c @@ -39,16 +39,16 @@ int eline_cmp(const void* v0, const void* v1) const ScfEline* el0 = *(const ScfEline**)v0; const ScfEline* el1 = *(const ScfEline**)v1; - if (el0->n_pins < el1->n_pins) + if (el0->n_conns < el1->n_conns) return 1; - if (el0->n_pins > el1->n_pins) + if (el0->n_conns > el1->n_conns) return -1; - if (el0->n_conns < el1->n_conns) + if (el0->n_pins < el1->n_pins) return 1; - if (el0->n_conns > el1->n_conns) + if (el0->n_pins > el1->n_pins) return -1; return 0; @@ -249,53 +249,38 @@ int ses_layout_function(ScfEfunction* f, uint32_t d, uint32_t bx, uint32_t by, u f->x = bx; f->y = by; + f->w = 0; + f->h = 0; n = 0; for (i = 0; i < f->n_elines; i++) { el = f->elines[i]; w = el->n_pins * d; + m = (w + bw - 1) / bw; + h = (n + m) * d; - if (w <= bw) - n++; - else - n += (w + bw - 1) / bw; - } - - f->h = n * d; - - if (f->h > bh) { - scf_loge("board's height too small, f->n_elines: %ld, n: %ld, f->h: %d, bh: %d\n", f->n_elines, n, f->h, bh); - return -EINVAL; - } - - n = (n + 1) >> 1; - m = 0; - - for (i = 0; i < f->n_elines; i++) { - el = f->elines[i]; - - w = el->n_pins * d; - k = (w + bw - 1) / bw; - m += k; + if (h > bh) { + scf_loge("board's height too small, h: %d, bh: %d\n", h, bh); + return -EINVAL; + } - if (m < n) - h = (n - m % n) * d; - else - h = (n + m % n) * d; + if (f->w < w) + f->w = w; + f->h = h; - for (j = 0; j < k; j++) { + for (j = 0; j < m; j++) { - l = malloc(sizeof(ScfLine)); + l = malloc(sizeof(ScfLine)); if (!l) return -ENOMEM; l->x0 = bx; - l->y0 = by + h - j * d; + l->y0 = by + (n + j) * d; l->x1 = l->x0 + w; l->y1 = l->y0; - scf_logi("el i: %ld, j: %ld, h: %d y0: %d, w: %d, bw: %d\n", i, j, h, l->y0, w, bw); + scf_logi("i: %ld, el->id: %ld, j: %ld, n: %ld, y0: %d, w: %d\n", i, el->id, j, n, l->y0, w); if (scf_eline__add_line(el, l) < 0) { free(l); @@ -304,6 +289,8 @@ int ses_layout_function(ScfEfunction* f, uint32_t d, uint32_t bx, uint32_t by, u } printf("\n"); + + n += m; } return 0; @@ -354,7 +341,7 @@ int ses_layout_board(ScfEboard* b, uint32_t x, uint32_t y, uint32_t w, uint32_t ses_lines_same_components(f); - ses_layout_function(f, 5, x + 20, y + 20, w - 20, h - 20); + ses_layout_function(f, 5, x , y , w , h ); } // ses_layout_draw();