From a830226830474b83a2f43e090d327da5c7fd1d88 Mon Sep 17 00:00:00 2001 From: werner Date: Tue, 15 Dec 2009 19:33:15 +0000 Subject: [PATCH] When no instance is selected, show the polar coordinates of the current pointer position relative to the user origin in the radius/angle fields. This helps to make quick manual measurements, e.g., of clearances. This also fixes the following bug: - gui_canvas.c (refresh_pos): showed canvas coordinates instead of model coordinates git-svn-id: http://svn.openmoko.org/trunk/eda/fped@5755 99fdad57-331a-0410-800a-d7fa5415bdb3 --- coord.c | 12 ++++++++++-- coord.h | 1 + gui_canvas.c | 20 ++++++++++++++++---- gui_status.c | 10 ++++++++++ gui_status.h | 1 + inst.c | 7 ++++--- 6 files changed, 42 insertions(+), 9 deletions(-) diff --git a/coord.c b/coord.c index 76cfe47..b9ee3e2 100644 --- a/coord.c +++ b/coord.c @@ -131,17 +131,25 @@ struct coord rotate_r(struct coord c, unit_type r, double angle) } -double theta(struct coord c, struct coord p) +double theta_vec(struct coord v) { double a; - a = atan2(p.y-c.y, p.x-c.x)/M_PI*180.0; + a = atan2(v.y, v.x)/M_PI*180.0; if (a < 0) a += 360.0; return a; } +double theta(struct coord c, struct coord p) +{ + p.x -= c.x; + p.y -= c.y; + return theta_vec(p); +} + + /* ----- sorting coordinates ----------------------------------------------- */ diff --git a/coord.h b/coord.h index 9dd0679..6955160 100644 --- a/coord.h +++ b/coord.h @@ -84,6 +84,7 @@ struct coord sub_vec(struct coord a, struct coord b); struct coord neg_vec(struct coord v); struct coord rotate_r(struct coord c, unit_type r, double angle); +double theta_vec(struct coord v); double theta(struct coord c, struct coord p); void swap_coord(unit_type *a, unit_type *b); diff --git a/gui_canvas.c b/gui_canvas.c index 8949f77..d618f04 100644 --- a/gui_canvas.c +++ b/gui_canvas.c @@ -36,7 +36,7 @@ void (*highlight)(void) = NULL; -static struct coord curr_pos; +static struct coord curr_pos; /* canvas coordinates ! */ static struct coord user_origin = { 0, 0 }; static int dragging = 0; @@ -55,16 +55,28 @@ static void update_zoom(void) static void update_pos(struct coord pos) { + struct coord user; + unit_type diag; + set_with_units(status_set_sys_x, "X ", pos.x); set_with_units(status_set_sys_y, "Y ", pos.y); - set_with_units(status_set_user_x, "x ", pos.x-user_origin.x); - set_with_units(status_set_user_y, "y ", pos.y-user_origin.y); + + user.x = pos.x-user_origin.x; + user.y = pos.y-user_origin.y; + set_with_units(status_set_user_x, "x ", user.x); + set_with_units(status_set_user_y, "y ", user.y); + + if (!selected_inst) { + diag = hypot(user.x, user.y); + set_with_units(status_set_r, "r = ", diag); + status_set_angle_xy(user); + } } void refresh_pos(void) { - update_pos(curr_pos); + update_pos(canvas_to_coord(curr_pos.x, curr_pos.y)); } diff --git a/gui_status.c b/gui_status.c index 90e17d6..d6da674 100644 --- a/gui_status.c +++ b/gui_status.c @@ -155,6 +155,16 @@ void status_set_xy(struct coord coord) } +void status_set_angle_xy(struct coord v) +{ + if (!v.x && !v.y) + status_set_angle("a = 0 deg"); + else + status_set_angle("a = %3.1f deg", theta_vec(v)); + +} + + static void entry_color(GtkWidget *widget, const char *color) { GdkColor col; diff --git a/gui_status.h b/gui_status.h index 2d86496..e137b77 100644 --- a/gui_status.h +++ b/gui_status.h @@ -85,6 +85,7 @@ void status_set_unit(const char *fmt, ...) __attribute__((format(printf, 1, 2))); void status_set_xy(struct coord coord); +void status_set_angle_xy(struct coord v); void status_begin_reporting(void); diff --git a/inst.c b/inst.c index c4c9ffc..6fa992e 100644 --- a/inst.c +++ b/inst.c @@ -23,6 +23,7 @@ #include "delete.h" #include "gui_util.h" #include "gui_status.h" +#include "gui_canvas.h" #include "gui_tool.h" #include "gui_meas.h" #include "gui_inst.h" @@ -394,6 +395,7 @@ void inst_deselect(void) status_set_angle(""); selected_inst = NULL; edit_nothing(); + refresh_pos(); } @@ -449,15 +451,14 @@ static void rect_status(struct coord a, struct coord b, unit_type width, int rounded) { struct coord d = sub_vec(b, a); - double angle, r; + double r; unit_type diag; status_set_xy(d); if (!d.x && !d.y) status_set_angle("a = 0 deg"); else { - angle = theta(a, b); - status_set_angle("a = %3.1f deg", angle); + status_set_angle("a = %3.1f deg", theta(a, b)); } if (d.x < 0) d.x = -d.x;