From ea7428c29fb36f29b50f2668e7bcb9211bdb0e92 Mon Sep 17 00:00:00 2001 From: "yu.dongliang" <18588496441@163.com> Date: Mon, 10 Jul 2023 16:42:15 +0800 Subject: [PATCH] ses layout --- main.c | 2 +- ses_layout.c | 82 +++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 66 insertions(+), 18 deletions(-) diff --git a/main.c b/main.c index fd2d2bf..2c881dc 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, 20, 100); + ses_layout_board(b, 0, 0, 200, 200); #if 0 size_t i; size_t j; diff --git a/ses_layout.c b/ses_layout.c index 05b772e..7065a10 100644 --- a/ses_layout.c +++ b/ses_layout.c @@ -304,6 +304,18 @@ int __ses_layout_function(ScfEfunction* f, ScfEline* el, size_t* pn, uint32_t d, ret = __ses_layout_function(f, el2, pn, d, bx, by, bw, bh); if (ret < 0) return ret; + + if (j == el->n_conns / 2 + && el ->n_lines > 0 + && el2->n_lines > 0) { + + uint32_t tmp = el ->lines[0]->y0; + el ->lines[0]->y0 = el2->lines[0]->y0; + el2->lines[0]->y0 = tmp; + + el ->lines[0]->y1 = el ->lines[0]->y0; + el2->lines[0]->y1 = el2->lines[0]->y0; + } break; } } @@ -392,22 +404,62 @@ int ses_layout_function(ScfEfunction* f, uint32_t d, uint32_t bx, uint32_t by, u return 0; } -int ses_layout_draw() +int ses_layout_draw(ScfEboard* b, uint32_t bx, uint32_t by, uint32_t bw, uint32_t bh) { - cairo_surface_t *surface; - cairo_t *cr; + ScfEfunction* f; + ScfEline* el; + ScfLine* l; - surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1280, 720); - cr = cairo_create (surface); + cairo_surface_t* surface; + cairo_t* cr; - cairo_set_line_width (cr, 4); - cairo_set_source_rgb (cr, 1, 1, 1); - cairo_rectangle (cr, 0, 0, 1280, 720); + 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; + + double colors[7][3] = + { + {1, 0, 0}, + {0, 1, 0}, + {0, 0, 1}, + + {1, 0, 1}, + {1, 1, 0}, + {0, 1, 1}, + + {1, 0.5, 0.5}, + }; + + for (i = 0; i < b->n_functions; i++) { + f = b->functions[i]; + + for (j = 0; j < f->n_elines; j++) { + el = f->elines[j]; + + double red = colors[j % 7][0]; + double green = colors[j % 7][1]; + double blue = colors[j % 7][2]; + + cairo_set_source_rgb(cr, red, green, blue); + + for (k = 0; k < el->n_lines; k++) { + l = el->lines[k]; - cairo_set_source_rgb (cr, 1, 0, 0); - cairo_rectangle (cr, 100, 100, 720, 360); - cairo_stroke (cr); + cairo_move_to(cr, l->x0, l->y0); + cairo_line_to(cr, l->x1, l->y1); + } + cairo_stroke(cr); + } + } cairo_surface_write_to_png(surface, "./a.png"); @@ -418,16 +470,12 @@ int ses_layout_draw() int ses_layout_board(ScfEboard* b, uint32_t x, uint32_t y, uint32_t w, uint32_t h) { - ScfEcomponent* c; ScfEfunction* f; - ScfEline* l; - ScfEpin* p; size_t i; size_t j; size_t k; - for (i = 0; i < b->n_functions; i++) { f = b->functions[i]; @@ -437,10 +485,10 @@ 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 , y , w , h ); + ses_layout_function(f, 5, x + 20, y + 20, w - 20, h - 20); } -// ses_layout_draw(); + ses_layout_draw(b, x, y, w, h); return 0; } -- 2.25.1