draw
authoryu.dongliang <18588496441@163.com>
Mon, 10 Jul 2023 16:54:14 +0000 (00:54 +0800)
committeryu.dongliang <18588496441@163.com>
Mon, 10 Jul 2023 16:54:14 +0000 (00:54 +0800)
ses_layout.c

index 14b2e20ebb0bdfb461a920575b4228b25935b402..0f36a07932cf54f7fcbbd90247067545dbf63dcf 100644 (file)
@@ -303,7 +303,7 @@ int __ses_layout_function(ScfEfunction* f, ScfEline* el, size_t* pn, uint32_t d,
 
                        if (el2->id == ec->lid && 0 == el2->n_lines) {
 
-                               int diff = 5 + rand() % 10;
+                               int diff = 10 + rand() % 20;
 
                                bx += diff;
                                bw -= diff;
@@ -359,7 +359,7 @@ int ses_layout_function(ScfEfunction* f, uint32_t d, uint32_t bx, uint32_t by, u
                        if (ret < 0)
                                return ret;
 
-                       int diff = 5 + rand() % 10;
+                       int diff = 10 + rand() % 20;
 
                        bx += diff;
                        bw -= diff;
@@ -375,8 +375,6 @@ int ses_layout_function(ScfEfunction* f, uint32_t d, uint32_t bx, uint32_t by, u
                        uint64_t cid = el->pins[j];
                        uint64_t pid = el->pins[j + 1];
 
-                       scf_logi("j: %ld, cid: %ld, pid: %ld\n", j, cid, pid);
-
                        ScfEcomponent* c = f->components[cid];
                        ScfEpin*       p = NULL;
 
@@ -403,6 +401,26 @@ int ses_layout_function(ScfEfunction* f, uint32_t d, uint32_t bx, uint32_t by, u
                }
        }
 
+       ScfEcomponent* c;
+       ScfEpin*       p;
+
+       for (i = 0; i < f->n_components; i++) {
+               c  =        f->components[i];
+
+               uint32_t cx = 0;
+               uint32_t cy = 0;
+
+               for (j = 0; j < c->n_pins; j++) {
+                       p  =        c->pins[j];
+
+                       cx += p->x;
+                       cy += p->y;
+               }
+
+               c->x = cx / c->n_pins;
+               c->y = cy / c->n_pins;
+       }
+
        return 0;
 }
 
@@ -483,24 +501,13 @@ int ses_layout_draw(ScfEboard* b, uint32_t bx, uint32_t by, uint32_t bw, uint32_
                }
        }
 
-       double ccolors[3][3] =
-       {
-               {1, 0, 0},
-               {0, 1, 0},
-               {0, 0, 1},
-       };
-
        for (i = 0; i < b->n_functions; i++) {
                f  =        b->functions[i];
 
                for (j = 0; j < f->n_components; j++) {
                        c  =        f->components[j];
                
-                       double red   = ccolors[j % 3][0];
-                       double green = ccolors[j % 3][1];
-                       double blue  = ccolors[j % 3][2];
-
-                       cairo_set_source_rgb(cr, red, green, blue);
+                       cairo_set_source_rgb(cr, 0.5, 0.5, 0.0);
 
                        scf_logw("j: %ld, c->id: %ld, n_pins: %ld, ", j, c->id, c->n_pins);
 
@@ -514,9 +521,53 @@ int ses_layout_draw(ScfEboard* b, uint32_t bx, uint32_t by, uint32_t bw, uint32_
                                else
                                        cairo_line_to(cr, p->x, p->y);
                        }
+
+                       switch (c->type) {
+
+                               case SCF_EDA_Battery:
+                                       p = c->pins[SCF_EDA_Battery_POS];
+
+                                       if (p->y < c->y) {
+                                               cairo_move_to(cr, c->x - 7, c->y - 5);
+                                               cairo_line_to(cr, c->x + 7, c->y - 5);
+
+                                               cairo_move_to(cr, c->x - 5, c->y + 5);
+                                               cairo_line_to(cr, c->x + 5, c->y + 5);
+                                       } else {
+                                               cairo_move_to(cr, c->x - 5, c->y - 5);
+                                               cairo_line_to(cr, c->x + 5, c->y - 5);
+
+                                               cairo_move_to(cr, c->x - 7, c->y + 5);
+                                               cairo_line_to(cr, c->x + 7, c->y + 5);
+                                       }
+                                       break;
+
+                               case SCF_EDA_Resistor:
+                                       cairo_rectangle(cr, c->x - 5, c->y - 5, 10, 10);
+                                       break;
+
+                               case SCF_EDA_Diode:
+                                       p = c->pins[SCF_EDA_Diode_POS];
+
+                                       if (p->y < c->y) {
+                                               cairo_move_to(cr, c->x - 5, c->y - 5);
+                                               cairo_line_to(cr, c->x + 5, c->y - 5);
+                                               cairo_line_to(cr, c->x,     c->y + 3);
+                                               cairo_line_to(cr, c->x - 5, c->y - 5);
+                                       } else {
+                                               cairo_move_to(cr, c->x - 5, c->y + 5);
+                                               cairo_line_to(cr, c->x + 5, c->y + 5);
+                                               cairo_line_to(cr, c->x,     c->y - 3);
+                                               cairo_line_to(cr, c->x + 5, c->y + 5);
+                                       }
+                                       break;
+                               default:
+                                       break;
+                       };
+                       cairo_stroke(cr);
+
                        printf("\n");
                }
-               cairo_stroke(cr);
        }
 
        cairo_surface_write_to_png(surface, "./a.png");