draw r
authoryu.dongliang <18588496441@163.com>
Tue, 11 Jul 2023 09:55:23 +0000 (17:55 +0800)
committeryu.dongliang <18588496441@163.com>
Tue, 11 Jul 2023 09:55:23 +0000 (17:55 +0800)
Makefile
ses_layout.c

index 9cd579c1c6c0cd2b631637bf14723abfa49bb959..24429856d9b7b0deee0ec756e49c3ff176868dd3 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -6,6 +6,7 @@ CFILES += ses_layout.c
 CFLAGS += -g
 CFLAGS += -I./
 
+LDFLAGS += -lm
 LDFLAGS += -lprotobuf-c
 LDFLAGS += -lcairo
 
index 4542ab4aaf181e5ce4ac024c58572fff2ef793d9..4d6909cff601d4ed93af5fec2874688d15dfe3f7 100644 (file)
@@ -444,6 +444,27 @@ int ses_layout_function(ScfEfunction* f, uint32_t d, uint32_t bx, uint32_t by, u
        return 0;
 }
 
+static void vertical(int* px, int* py, int dx, int dy, int d)
+{
+       /*
+          [cos90, -sin90] [0 -1] x
+          [sin90,  cos90] [1  0] y
+        */
+
+       double R = sqrt(dx * dx + dy * dy);
+
+       *px = -dy * d / R;
+       *py =  dx * d / R;
+}
+
+static void forward(int* px, int* py, int dx, int dy, int d)
+{
+       double R = sqrt(dx * dx + dy * dy);
+
+       *px = dx * d / R;
+       *py = dy * d / R;
+}
+
 int ses_layout_draw(ScfEboard* b, uint32_t bx, uint32_t by, uint32_t bw, uint32_t bh)
 {
        ScfEcomponent*   c;
@@ -530,6 +551,18 @@ int ses_layout_draw(ScfEboard* b, uint32_t bx, uint32_t by, uint32_t bw, uint32_
                        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);
+                       int dx0;
+                       int dy0;
+
+                       int dx1;
+                       int dy1;
+                       int dx2;
+                       int dy2;
+
+                       int dx3;
+                       int dy3;
+                       int dx4;
+                       int dy4;
 
                        switch (c->type) {
 
@@ -537,31 +570,59 @@ int ses_layout_draw(ScfEboard* b, uint32_t bx, uint32_t by, uint32_t bw, uint32_
                                        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 - 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 - 7, c->y + 5);
+                                               cairo_line_to(cr, c->x + 7, 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);
 
-                                               cairo_move_to(cr, c->x - 7, c->y + 5);
-                                               cairo_line_to(cr, c->x + 7, 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_move_to(cr, c->x, c->y);
-                                       cairo_line_to(cr, p->x, p->y);
-
-                                       p = c->pins[SCF_EDA_Battery_NEG];
-                                       cairo_move_to(cr, c->x, c->y);
-                                       cairo_line_to(cr, p->x, p->y);
                                        break;
 
                                case SCF_EDA_Resistor:
-                                       cairo_rectangle(cr, c->x - 5, c->y - 5, 10, 10);
-
                                        p = c->pins[0];
+
+                                       vertical(&dx0, &dy0, c->x - p->x, c->y - p->y,  4);
+                                       vertical(&dx1, &dy1, c->x - p->x, c->y - p->y, -8);
+                                       vertical(&dx2, &dy2, c->x - p->x, c->y - p->y,  8);
+
+                                       forward (&dx3, &dy3, c->x - p->x, c->y - p->y, -16);
+                                       forward (&dx4, &dy4, c->x - p->x, c->y - p->y,  16);
+
+                                       scf_logw("dx0: %d, dy0: %d\n", dx0, dy0);
+                                       scf_logw("dx1: %d, dy1: %d\n", dx1, dy1);
+                                       scf_logw("dx2: %d, dy2: %d\n", dx2, dy2);
+                                       scf_logw("dx3: %d, dy3: %d\n", dx3, dy3);
+                                       scf_logw("dx4: %d, dy4: %d\n", dx4, dy4);
+
+                                       cairo_move_to    (cr, c->x, c->y);
+                                       cairo_rel_move_to(cr, dx0,  dy0);
+                                       cairo_rel_line_to(cr, dx1,  dy1);
+                                       cairo_rel_line_to(cr, dx4,  dy4);
+                                       cairo_rel_line_to(cr, dx2,  dy2);
+                                       cairo_rel_line_to(cr, dx3,  dy3);
+
                                        cairo_move_to(cr, c->x, c->y);
                                        cairo_line_to(cr, p->x, p->y);