tmp
authoryu.dongliang <18588496441@163.com>
Thu, 13 Jul 2023 08:51:33 +0000 (16:51 +0800)
committeryu.dongliang <18588496441@163.com>
Thu, 13 Jul 2023 08:51:33 +0000 (16:51 +0800)
ses_layout.c

index cbed9b72e45ddcb9a650ad068f8251f21c9b57bd..5b560f03c3c5f92578cd39d96550625fb39c2f96 100644 (file)
@@ -346,105 +346,22 @@ int ses_lines_same_components(ScfEfunction* f)
        return 0;
 }
 
-int __ses_layout_function2(ScfEfunction* f, ScfEline* el, size_t* pn, uint32_t d, uint32_t bx, uint32_t by, uint32_t bw, uint32_t bh)
-{
-       ScfLine*  l;
-
-       uint32_t  w = (el->n_pins - 2) * d + 10;
-       size_t    m = (w + bw - 1) / bw;
-       size_t    n = *pn;
-       uint32_t  h = (n + m) * d;
-       size_t    j;
-
-       if (h > bh) {
-               scf_loge("board's height too small, h: %d, bh: %d\n", h, bh);
-               return -EINVAL;
-       }
-
-       if (f->w < w)
-               f->w = w;
-       f->h = h;
-
-       for (j = 0; j < m; j++) {
-
-               l = malloc(sizeof(ScfLine));
-               if (!l)
-                       return -ENOMEM;
-#if 0
-               if ((SCF_EDA_PIN_NEG | SCF_EDA_PIN_POS) & el->flags)
-                       l->x0 = bx;
-
-               else if ((SCF_EDA_PIN_IN | SCF_EDA_PIN_OUT) & el->flags)
-                       l->x0 = bx + d;
-               else
-                       l->x0 = bx + 1 * d;
-#endif
-               l->x0 = bx;
-               l->y0 = by + (n + j) * d;
-               l->y1 = l->y0;
-
-               if (w > bw) {
-                       l->x1 = l->x0 + bw;
-                       w -= bw;
-               } else
-                       l->x1 = l->x0 + w;
-
-               scf_logi("el->id: %ld, j: %ld, n: %ld, y0: %d, x1: %d\n", el->id, j, n, l->y0, l->x1);
-
-               if (scf_eline__add_line(el, l) < 0) {
-                       free(l);
-                       return -ENOMEM;
-               }
-       }
-
-       printf("\n");
-
-       *pn += m;
-       return 0;
-}
-
-int __ses_layout_function(ScfEfunction* f, ScfEline* el, size_t* pn, uint32_t d, uint32_t bx, uint32_t by, uint32_t bw, uint32_t bh)
+int ses_layout_function(ScfEfunction* f, uint32_t d, uint32_t bx, uint32_t by, uint32_t bw, uint32_t bh)
 {
-       ScfEline* el2;
-       ScfEconn* ec;
-
-       size_t    i;
-       size_t    j;
-
-       int ret = __ses_layout_function2(f, el, pn, d, bx, by, bw, bh);
-       if (ret < 0)
-               return ret;
-
-       for (i = 0; i < el->n_conns; i++) {
-               ec =        el->conns[i];
-
-               for (j = 0; j < f->n_elines; j++) {
-                       el2       = f->elines[j];
-
-                       if (el2->id == ec->lid && 0 == el2->n_lines) {
-
-                               ret = __ses_layout_function(f, el2, pn, d, bx, by, bw, bh);
-                               if (ret < 0)
-                                       return ret;
-
-                               break;
-                       }
-               }
-       }
+       ScfEcomponent* c;
+       ScfEline*      el0;
+       ScfEline*      el1;
+       ScfEline*      el2;
 
-       return 0;
-}
+       ScfEconn*      ec;
+       ScfLine*       l0;
+       ScfLine*       l1;
+       ScfLine*       l2;
 
-int ses_layout_function(ScfEfunction* f, uint32_t d, uint32_t bx, uint32_t by, uint32_t bw, uint32_t bh)
-{
-       ScfEline* el;
-       ScfEline* el2;
-       ScfEconn* ec;
-       ScfLine*  l;
-       ScfLine*  l2;
+       ScfEpin*       p0;
+       ScfEpin*       p1;
+       ScfEpin*       p2;
 
-       uint32_t  w;
-       uint32_t  h;
        size_t    i;
        size_t    j;
        size_t    k;
@@ -455,56 +372,74 @@ int ses_layout_function(ScfEfunction* f, uint32_t d, uint32_t bx, uint32_t by, u
        f->y = by;
        f->w = 0;
        f->h = 0;
-       n    = 0;
 
        for (i = 0; i < f->n_elines; i++) {
-               el =        f->elines[i];
+               el0       = f->elines[i];
 
-               if (0 == el->n_lines) {
+               l0 = malloc(sizeof(ScfLine));
+               if (!l0)
+                       return -ENOMEM;
 
-                       int ret = __ses_layout_function2(f, el, &n, d, bx, by, bw, bh);
-                       if (ret < 0)
-                               return ret;
+               l0->x0 = bx;
+               l0->x1 = bx + d;
+               l0->y0 = by + i * d;
+               l0->y1 = l0->y0;
+
+               if (scf_eline__add_line(el0, l0) < 0) {
+                       free(l0);
+                       return -ENOMEM;
                }
+
+               if (f->h < l0->y0)
+                       f->h = l0->y0;
        }
-       scf_logi("f->x: %d, f->y: %d, f->w: %d, f->h: %d\n", f->x, f->y, f->w, f->h);
 
-       for (i = 0; i < f->n_elines; i++) {
-               el =        f->elines[i];
+       for (i = 0; i < f->n_elines - 1; i++) {
+               el0       = f->elines[i];
+               el1       = f->elines[i + 1];
 
-               for (j = 0; j + 1 < el->n_pins; j += 2) {
+               m = 0;
+               n = 0;
+               j = 0;
+               while (m + 1 < el0->n_pins && n + 1 < el1->n_pins) {
 
-                       uint64_t cid = el->pins[j];
-                       uint64_t pid = el->pins[j + 1];
+                       uint64_t c0 = el0->pins[m];
+                       uint64_t c1 = el1->pins[n];
 
-                       ScfEcomponent* c = f->components[cid];
-                       ScfEpin*       p = NULL;
+                       if (c0 < c1)
+                               m += 2;
+                       else if (c0 > c1)
+                               n += 2;
 
-                       assert(c->id == cid);
+                       else {
+                               c  = f->components[c0];
 
-                       for (k = 0; k < c->n_pins; k++) {
-                               p  =        c->pins[k];
+                               p0 = c->pins[el0->pins[m + 1]];
+                               p1 = c->pins[el1->pins[n + 1]];
 
-                               if (p->id == pid)
-                                       break;
-                               p = NULL;
-                       }
-                       assert(p);
+                               p0->x = el0->lines[0]->x1 + j * d;
+                               p0->y = el0->lines[0]->y0;
+
+                               p1->x = el1->lines[0]->x1 + j * d;
+                               p1->y = el1->lines[0]->y0;
+
+                               el0->lines[0]->x1 += j * d;
+                               el1->lines[0]->x1 += j * d;
 
-                       m = j * d / f->w;
-                       assert(m < el->n_lines);
+                               if (f->w < el0->lines[0]->x1 - f->x)
+                                       f->w = el0->lines[0]->x1 - f->x;
 
-                       l = el->lines[m];
-                       m = j * d % f->w;
-                       assert(m < l->x1);
+                               if (f->w < el1->lines[0]->x1 - f->x)
+                                       f->w = el1->lines[0]->x1 - f->x;
 
-                       p->x = l->x0 + m + rand() % 5;
-                       p->y = l->y0;
+                               m += 2;
+                               n += 2;
+                               j++;
+                       }
                }
        }
 
-       ScfEcomponent* c;
-       ScfEpin*       p;
+       scf_loge("f->x: %d, y: %d, w: %d, h: %d\n", f->x, f->y, f->w, f->h);
 
        for (i = 0; i < f->n_components; i++) {
                c  =        f->components[i];
@@ -512,29 +447,11 @@ int ses_layout_function(ScfEfunction* f, uint32_t d, uint32_t bx, uint32_t by, u
                uint32_t cx = 0;
                uint32_t cy = 0;
 
-               switch (c->type) {
-
-                       case SCF_EDA_Battery:
-                               break;
-
-                       case SCF_EDA_Resistor:
-                               break;
-
-                       case SCF_EDA_Diode:
-                               break;
-
-                       case SCF_EDA_Transistor:
-                               break;
-
-                       default:
-                               break;
-               };
-
                for (j = 0; j < c->n_pins; j++) {
-                       p  =        c->pins[j];
+                       p0 =        c->pins[j];
 
-                       cx += p->x;
-                       cy += p->y;
+                       cx += p0->x;
+                       cy += p0->y;
                }
 
                c->x = cx / c->n_pins;