ses_step_simplify.c
authoryu.dongliang <18588496441@163.com>
Tue, 14 Nov 2023 02:47:25 +0000 (10:47 +0800)
committeryu.dongliang <18588496441@163.com>
Tue, 14 Nov 2023 02:47:25 +0000 (10:47 +0800)
main.c
ses_layout.c
ses_step_simplify.c

diff --git a/main.c b/main.c
index 60d29107fa0acf8c887646489acd45ffe06e75c5..dc466e422e6e98ca721e6096923f1be9a1b090c2 100644 (file)
--- a/main.c
+++ b/main.c
@@ -15,6 +15,40 @@ char* component_types[SCF_EDA_Components_NB] =
        "PNP",
 };
 
+static void print_board(ScfEboard* b)
+{
+       ScfEcomponent* c;
+       ScfEfunction*  f;
+       ScfEpin*       p;
+
+       size_t i;
+       size_t j;
+       size_t k;
+       size_t m;
+
+       for (i = 0; i < b->n_functions; i++) {
+               f  =        b->functions[i];
+
+               printf("f: %s\n", f->name);
+
+               for (j = 0; j < f->n_components; j++) {
+                       c  =        f->components[j];
+
+                       printf("c: %ld, type: %s\n", c->id, component_types[c->type]);
+
+                       for (k = 0; k < c->n_pins; k++) {
+                               p  =        c->pins[k];
+
+                               printf("cid: %ld, pid: %ld, flags: %#lx, r: %lg, uf: %lg, uh: %lg\n", p->cid, p->id, p->flags, p->r, p->uf, p->uh);
+
+                               for (m = 0; m + 1 < p->n_tos; m += 2)
+                                       printf("to cid: %ld, pid: %ld\n", p->tos[m], p->tos[m + 1]);
+                       }
+                       printf("\n");
+               }
+       }
+}
+
 int main(int argc, char* argv[])
 {
        if (argc < 2) {
@@ -54,39 +88,21 @@ int main(int argc, char* argv[])
 
        ScfEcomponent* c;
        ScfEfunction*  f;
-       ScfEpin*       p;
-
-       ScfEboard* b = scf_eboard__unpack(NULL, len, pb);
+       ScfEboard*     b = scf_eboard__unpack(NULL, len, pb);
 
        ses_layout_board(b);
-#if 0
+
        size_t i;
-       size_t j;
-       size_t k;
-       size_t m;
 
        for (i = 0; i < b->n_functions; i++) {
                f  =        b->functions[i];
 
                printf("f: %s\n", f->name);
 
-               for (j = 0; j < f->n_components; j++) {
-                       c  =        f->components[j];
-
-                       printf("c: %ld, type: %s\n", c->id, component_types[c->type]);
-
-                       for (k = 0; k < c->n_pins; k++) {
-                               p  =        c->pins[k];
-
-                               printf("cid: %ld, pid: %ld, flags: %#lx, r: %lg, uf: %lg, uh: %lg\n", p->cid, p->id, p->flags, p->r, p->uf, p->uh);
-
-                               for (m = 0; m + 1 < p->n_tos; m += 2)
-                                       printf("to cid: %ld, pid: %ld\n", p->tos[m], p->tos[m + 1]);
-                       }
-                       printf("\n");
-               }
+               ses_steps_analyse(f, 5, 1);
        }
-#endif
+
+//     print_board(b);
 
 //     scf_eboard__free_unpacked(b, NULL);
        return 0;
index 2f18ed6bd3cb7edfef1d50afec93c046e577d12a..21a22442af0078bb7818cde0ff0d55276ea876fa 100644 (file)
@@ -2,6 +2,8 @@
 #include"ses_core.h"
 #include"ses_graph.h"
 
+void __ses_function_draw(ScfEfunction* f, cairo_t* cr);
+
 int epin_cmp(const void* v0, const void* v1)
 {
        const uint64_t* t0 = v0;
@@ -1758,191 +1760,7 @@ int ses_layout_draw(ScfEboard* b, uint32_t bx, uint32_t by, uint32_t bw, uint32_
        for (i = 0; i < b->n_functions; i++) {
                f  =        b->functions[i];
 
-               for (j = 0; j < f->n_components; j++) {
-                       c  =        f->components[j];
-
-                       uint8_t text[64];
-                       snprintf(text, sizeof(text) - 1, "%ld", c->id);
-
-                       cairo_set_source_rgb  (cr, 0, 0, 0);
-                       cairo_select_font_face(cr, "Georgia", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
-                       cairo_set_font_size   (cr, 20);
-                       cairo_move_to         (cr, c->x + 10, c->y - 5);
-                       cairo_show_text       (cr, text);
-                       cairo_stroke(cr);
-
-                       cairo_set_source_rgb(cr, 0.6, 0.6, 0.0);
-
-                       for (k = 0; k < c->n_pins; k++) {
-                               p  =        c->pins[k];
-
-                               cairo_arc (cr, p->x, p->y, 4, 0, 2 * M_PI);
-                               cairo_fill(cr);
-                       }
-                       cairo_stroke(cr);
-
-                       int dx0;
-                       int dy0;
-
-                       int dx1;
-                       int dy1;
-                       int dx2;
-                       int dy2;
-
-                       int dx3;
-                       int dy3;
-                       int dx4;
-                       int dy4;
-
-                       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 - 8, c->y - 5);
-                                               cairo_line_to(cr, c->x + 8, c->y - 5);
-
-                                               cairo_move_to(cr, c->x, c->y - 5);
-                                               cairo_line_to(cr, p->x, p->y);
-
-                                               cairo_move_to(cr, c->x - 5, c->y + 5);
-                                               cairo_line_to(cr, c->x + 5, c->y + 5);
-
-                                               p = c->pins[SCF_EDA_Battery_NEG];
-                                               cairo_move_to(cr, c->x, c->y + 5);
-                                               cairo_line_to(cr, p->x, p->y);
-
-                                       } else {
-                                               cairo_move_to(cr, c->x - 8, c->y + 5);
-                                               cairo_line_to(cr, c->x + 8, c->y + 5);
-
-                                               cairo_move_to(cr, c->x, c->y + 5);
-                                               cairo_line_to(cr, p->x, p->y);
-
-                                               cairo_move_to(cr, c->x - 5, c->y - 5);
-                                               cairo_line_to(cr, c->x + 5, c->y - 5);
-
-                                               p = c->pins[SCF_EDA_Battery_NEG];
-                                               cairo_move_to(cr, c->x, c->y - 5);
-                                               cairo_line_to(cr, p->x, p->y);
-                                       }
-
-                                       cairo_stroke(cr);
-                                       break;
-
-                               case SCF_EDA_Resistor:
-                                       p = c->pins[0];
-
-                                       vertical(&dx0, &dy0, c->x - p->x, c->y - p->y, 3);
-                                       forward (&dx1, &dy1, c->x - p->x, c->y - p->y, 6);
-
-                                       cairo_move_to    (cr,  p->x,       p->y);
-                                       cairo_line_to    (cr,  c->x - dx1, c->y - dy1);
-
-                                       cairo_rel_move_to(cr,  dx0,        dy0);
-                                       cairo_rel_line_to(cr, -dx0 * 2,   -dy0 * 2);
-                                       cairo_rel_line_to(cr,  dx1 * 2,    dy1 * 2);
-                                       cairo_rel_line_to(cr,  dx0 * 2,    dy0 * 2);
-                                       cairo_rel_line_to(cr, -dx1 * 2,   -dy1 * 2);
-
-                                       p = c->pins[1];
-                                       cairo_move_to    (cr,  p->x,       p->y);
-                                       cairo_line_to    (cr,  c->x + dx1, c->y + dy1);
-
-                                       cairo_stroke(cr);
-                                       break;
-
-                               case SCF_EDA_Diode:
-                                       p = c->pins[SCF_EDA_Diode_POS];
-
-                                       vertical(&dx0, &dy0, c->x - p->x, c->y - p->y,  6);
-                                       forward (&dx1, &dy1, c->x - p->x, c->y - p->y,  6);
-
-                                       cairo_move_to(cr, p->x,       p->y);
-                                       cairo_line_to(cr, c->x - dx1, c->y - dy1);
-
-                                       cairo_rel_move_to(cr,  dx0,              dy0);
-                                       cairo_rel_line_to(cr, -dx0 * 2,         -dy0 * 2);
-                                       cairo_line_to    (cr,  c->x + dx1,       c->y + dy1);
-                                       cairo_line_to    (cr,  c->x + dx0 - dx1, c->y + dy0 - dy1);
-
-                                       p = c->pins[SCF_EDA_Diode_NEG];
-
-                                       cairo_move_to    (cr,  p->x,        p->y);
-                                       cairo_line_to    (cr,  c->x + dx1,  c->y + dy1);
-                                       cairo_rel_move_to(cr,  dx0,         dy0);
-                                       cairo_rel_line_to(cr, -dx0 * 2,    -dy0 * 2);
-
-                                       cairo_stroke(cr);
-                                       break;
-
-                               case SCF_EDA_NPN:
-                                       pb = c->pins[SCF_EDA_NPN_B];
-                                       pc = c->pins[SCF_EDA_NPN_C];
-                                       pe = c->pins[SCF_EDA_NPN_E];
-
-                                       vertical(&dx0, &dy0, c->x - pb->x, c->y - pb->y,  8);
-                                       forward (&dx3, &dy3, c->x - pb->x, c->y - pb->y,  8);
-
-                                       cairo_arc(cr, c->x - dx3 / 2, c->y - dy3 / 2, 12, 0, 2 * M_PI);
-
-                                       cairo_move_to    (cr,  pb->x,       pb->y);
-                                       cairo_line_to    (cr,  c->x - dx3,  c->y - dy3);
-                                       cairo_rel_move_to(cr,  dx0,         dy0);
-                                       cairo_rel_line_to(cr, -dx0 * 2,    -dy0 * 2);
-                                       cairo_stroke(cr);
-
-                                       if ((c->x + dx3 + dx0 > c->x + dx3 - dx0 && pe->x > pc->x)
-                                        || (c->x + dx3 + dx0 < c->x + dx3 - dx0 && pe->x < pc->x)) {
-
-                                               cairo_set_source_rgb(cr, 0.6, 0.6, 0.0);
-
-                                               cairo_move_to(cr, c->x - dx3,       c->y - dy3);
-                                               cairo_line_to(cr, c->x + dx3 + dx0, c->y + dy3 + dy0);
-                                               cairo_line_to(cr, pe->x, pe->y);
-
-                                               vertical(&dx1, &dy1, dx3 * 2 + dx0, dy3 * 2 + dy0, 3);
-                                               forward (&dx4, &dy4, dx3 * 2 + dx0, dy3 * 2 + dy0, 8);
-
-                                               cairo_move_to(cr, c->x - dx3 + dx4 + dx1,  c->y - dy3 + dy4 + dy1);
-                                               cairo_line_to(cr, c->x + dx3 + dx0,        c->y + dy3 + dy0);
-                                               cairo_line_to(cr, c->x - dx3 + dx4 - dx1,  c->y - dy3 + dy4 - dy1);
-                                               cairo_stroke(cr);
-
-                                               cairo_set_source_rgb(cr, 0.0, 0.6, 0.0);
-                                               cairo_move_to(cr, c->x - dx3,        c->y - dy3);
-                                               cairo_line_to(cr, c->x + dx3 - dx0,  c->y + dy3 - dy0);
-                                               cairo_line_to(cr, pc->x, pc->y);
-                                               cairo_stroke(cr);
-
-                                       } else {
-                                               cairo_set_source_rgb(cr, 0.0, 0.6, 0.0);
-                                               cairo_move_to(cr, c->x - dx3,       c->y - dy3);
-                                               cairo_line_to(cr, c->x + dx3 + dx0, c->y + dy3 + dy0);
-                                               cairo_line_to(cr, pc->x, pc->y);
-                                               cairo_stroke(cr);
-
-                                               cairo_set_source_rgb(cr, 0.6, 0.6, 0.0);
-
-                                               cairo_move_to(cr, c->x - dx3,        c->y - dy3);
-                                               cairo_line_to(cr, c->x + dx3 - dx0,  c->y + dy3 - dy0);
-                                               cairo_line_to(cr, pe->x, pe->y);
-
-                                               vertical(&dx1, &dy1, dx3 * 2 - dx0, dy3 * 2 - dy0, 3);
-                                               forward (&dx4, &dy4, dx3 * 2 - dx0, dy3 * 2 - dy0, 8);
-
-                                               cairo_move_to(cr, c->x - dx3 + dx4 + dx1,  c->y - dy3 + dy4 + dy1);
-                                               cairo_line_to(cr, c->x + dx3 - dx0,        c->y + dy3 - dy0);
-                                               cairo_line_to(cr, c->x - dx3 + dx4 - dx1,  c->y - dy3 + dy4 - dy1);
-
-                                               cairo_stroke(cr);
-                                       }
-                                       break;
-                               default:
-                                       break;
-                       };
-               }
+               __ses_function_draw(f, cr);
        }
 
        cairo_surface_write_to_png(surface, "./2.png");
@@ -1981,8 +1799,6 @@ int ses_layout_board(ScfEboard* b)
                        return ret;
                }
 
-               ses_steps_analyse(f, 5, 1);
-
                x = f->x;
                y = f->y;
                w = f->w;
index 507e08aa136fe0698565ae6ba6712d99f716a4ed..850690ef925f4992a562e4429d8a8c08212820ba 100644 (file)
 #include<cairo/cairo.h>
 #include"ses_core.h"
 
-static int _simplify_draw(ScfEfunction* f, uint32_t bx, uint32_t by, uint32_t bw, uint32_t bh)
+void __ses_function_draw(ScfEfunction* f, cairo_t* cr)
 {
-       ScfEcomponent*   B;
        ScfEcomponent*   c;
-       ScfEline*        el;
        ScfEpin*         p;
        ScfEpin*         pb;
        ScfEpin*         pc;
        ScfEpin*         pe;
-       ScfLine*         l;
-
-       cairo_surface_t* surface;
-       cairo_t*         cr;
-
-       surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, bx + bw, by + bh);
-       cr      = cairo_create (surface);
-
-       cairo_set_line_width(cr, 2);
-       cairo_set_source_rgb(cr, 1, 1, 1);
-       cairo_rectangle     (cr, 0, 0, bx + bw, by + bh);
-       cairo_fill(cr);
-       cairo_stroke(cr);
 
-       size_t i;
        size_t j;
        size_t k;
 
-       B = f->components[0];
-
-       for (j = 0; j < f->n_elines; j++) {
-               el =        f->elines[j];
-
-               cairo_set_line_width(cr, 2);
-
-               if (SCF_EDA_PIN_POS & el->flags)
-                       cairo_set_source_rgb(cr, 1, 0, 0);
-
-               else if (SCF_EDA_PIN_NEG & el->flags)
-                       cairo_set_source_rgb(cr, 0, 0, 1);
-
-               else if (SCF_EDA_PIN_OUT & el->flags)
-                       cairo_set_source_rgb(cr, 1, 0, 1);
-
-               else if (el->v == B->pins[SCF_EDA_Battery_POS]->v)
-                       cairo_set_source_rgb(cr, 0.8, 0, 0);
-
-               else if (el->v == B->pins[SCF_EDA_Battery_NEG]->v)
-                       cairo_set_source_rgb(cr, 0, 0, 0.8);
-
-               else if (SCF_EDA_PIN_IN & el->flags)
-                       cairo_set_source_rgb(cr, 0, 1, 0);
-
-               else if (SCF_EDA_PIN_CF & el->flags)
-                       cairo_set_source_rgb(cr, 0.8, 0, 1.0);
-               else
-                       cairo_set_source_rgb(cr, 1, 0.5, 0.1);
-
-               uint8_t text[64];
-
-               cairo_select_font_face(cr, "Georgia", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
-               cairo_set_font_size   (cr, 28);
-
-               ScfLine* prev = NULL;
-
-               for (k = 0; k < el->n_lines; k++) {
-                       l  =        el->lines[k];
-
-                       if (l->x0 > l->x1)
-                               continue;
-
-                       if (!prev) {
-                               snprintf(text, sizeof(text) - 1, "%ld", el->id);
-
-                               cairo_move_to  (cr, l->x0 - 30, l->y0 + 5);
-                               cairo_show_text(cr, text);
-                               cairo_stroke(cr);
-
-                               if (el->v < SCF_EDA_V_MIN)
-                                       snprintf(text, sizeof(text) - 1, "%lg", B->pins[SCF_EDA_Battery_NEG]->v);
-                               else if (el->v > SCF_EDA_V_MAX)
-                                       snprintf(text, sizeof(text) - 1, "%lg", B->pins[SCF_EDA_Battery_POS]->v);
-
-                               else if (el->v > 1e-3 || el->v < -1e-3)
-                                       snprintf(text, sizeof(text) - 1, "%lgv", (int)(el->v * 1000) / 1000.0);
-
-                               else if (el->v > 1e-6 || el->v < -1e-6)
-                                       snprintf(text, sizeof(text) - 1, "%lgmV", (int)(el->v * 1000000) / 1000.0);
-                               else
-                                       snprintf(text, sizeof(text) - 1, "%lguV", (int)(el->v * 1000000) / 1000000.0);
-
-                               cairo_set_font_size(cr, 20);
-
-                               cairo_move_to  (cr, (l->x0 + l->x1) / 2 - 24, l->y0 + 24);
-                               cairo_show_text(cr, text);
-                               cairo_stroke(cr);
-                       }
-
-                       cairo_set_line_width(cr, 4);
-                       cairo_move_to(cr, l->x0, l->y0);
-                       cairo_line_to(cr, l->x1, l->y1);
-                       cairo_stroke(cr);
-
-                       if (prev) {
-                               if (!(el->flags & SCF_EDA_PIN_BORDER))
-                                       cairo_set_line_width(cr, 1);
-
-                               cairo_move_to(cr, prev->x0, prev->y0);
-                               cairo_line_to(cr, l->x0,    l->y0);
-                               cairo_stroke(cr);
-                       }
-
-                       prev = l;
-               }
-       }
-
        for (j = 0; j < f->n_components; j++) {
                c  =        f->components[j];
 
@@ -299,6 +195,124 @@ static int _simplify_draw(ScfEfunction* f, uint32_t bx, uint32_t by, uint32_t bw
                                break;
                };
        }
+}
+
+static int _simplify_draw(ScfEfunction* f, uint32_t bx, uint32_t by, uint32_t bw, uint32_t bh)
+{
+       ScfEcomponent*   B;
+       ScfEcomponent*   c;
+       ScfEline*        el;
+       ScfEpin*         p;
+       ScfEpin*         pb;
+       ScfEpin*         pc;
+       ScfEpin*         pe;
+       ScfLine*         l;
+
+       cairo_surface_t* surface;
+       cairo_t*         cr;
+
+       surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, bx + bw, by + bh);
+       cr      = cairo_create (surface);
+
+       cairo_set_line_width(cr, 2);
+       cairo_set_source_rgb(cr, 1, 1, 1);
+       cairo_rectangle     (cr, 0, 0, bx + bw, by + bh);
+       cairo_fill(cr);
+       cairo_stroke(cr);
+
+       size_t i;
+       size_t j;
+       size_t k;
+
+       B = f->components[0];
+
+       for (j = 0; j < f->n_elines; j++) {
+               el =        f->elines[j];
+
+               cairo_set_line_width(cr, 2);
+
+               if (SCF_EDA_PIN_POS & el->flags)
+                       cairo_set_source_rgb(cr, 1, 0, 0);
+
+               else if (SCF_EDA_PIN_NEG & el->flags)
+                       cairo_set_source_rgb(cr, 0, 0, 1);
+
+               else if (SCF_EDA_PIN_OUT & el->flags)
+                       cairo_set_source_rgb(cr, 1, 0, 1);
+
+               else if (el->v == B->pins[SCF_EDA_Battery_POS]->v)
+                       cairo_set_source_rgb(cr, 0.8, 0, 0);
+
+               else if (el->v == B->pins[SCF_EDA_Battery_NEG]->v)
+                       cairo_set_source_rgb(cr, 0, 0, 0.8);
+
+               else if (SCF_EDA_PIN_IN & el->flags)
+                       cairo_set_source_rgb(cr, 0, 1, 0);
+
+               else if (SCF_EDA_PIN_CF & el->flags)
+                       cairo_set_source_rgb(cr, 0.8, 0, 1.0);
+               else
+                       cairo_set_source_rgb(cr, 1, 0.5, 0.1);
+
+               uint8_t text[64];
+
+               cairo_select_font_face(cr, "Georgia", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
+               cairo_set_font_size   (cr, 28);
+
+               ScfLine* prev = NULL;
+
+               for (k = 0; k < el->n_lines; k++) {
+                       l  =        el->lines[k];
+
+                       if (l->x0 > l->x1)
+                               continue;
+
+                       if (!prev) {
+                               snprintf(text, sizeof(text) - 1, "%ld", el->id);
+
+                               cairo_move_to  (cr, l->x0 - 30, l->y0 + 5);
+                               cairo_show_text(cr, text);
+                               cairo_stroke(cr);
+
+                               if (el->v < SCF_EDA_V_MIN)
+                                       snprintf(text, sizeof(text) - 1, "%lg", B->pins[SCF_EDA_Battery_NEG]->v);
+                               else if (el->v > SCF_EDA_V_MAX)
+                                       snprintf(text, sizeof(text) - 1, "%lg", B->pins[SCF_EDA_Battery_POS]->v);
+
+                               else if (el->v > 1e-3 || el->v < -1e-3)
+                                       snprintf(text, sizeof(text) - 1, "%lgv", (int)(el->v * 1000) / 1000.0);
+
+                               else if (el->v > 1e-6 || el->v < -1e-6)
+                                       snprintf(text, sizeof(text) - 1, "%lgmV", (int)(el->v * 1000000) / 1000.0);
+                               else
+                                       snprintf(text, sizeof(text) - 1, "%lguV", (int)(el->v * 1000000) / 1000000.0);
+
+                               cairo_set_font_size(cr, 20);
+
+                               cairo_move_to  (cr, (l->x0 + l->x1) / 2 - 24, l->y0 + 24);
+                               cairo_show_text(cr, text);
+                               cairo_stroke(cr);
+                       }
+
+                       cairo_set_line_width(cr, 4);
+                       cairo_move_to(cr, l->x0, l->y0);
+                       cairo_line_to(cr, l->x1, l->y1);
+                       cairo_stroke(cr);
+
+                       if (prev) {
+                               if (!(el->flags & SCF_EDA_PIN_BORDER))
+                                       cairo_set_line_width(cr, 1);
+
+                               cairo_move_to(cr, prev->x0, prev->y0);
+                               cairo_line_to(cr, l->x0,    l->y0);
+                               cairo_stroke(cr);
+                       }
+
+                       prev = l;
+               }
+       }
+
+       __ses_function_draw(f, cr);
 
        cairo_surface_write_to_png(surface, "./simplify.png");