r5755 - trunk/eda/fped

werner at docs.openmoko.org werner at docs.openmoko.org
Tue Dec 15 20:33:16 CET 2009


Author: werner
Date: 2009-12-15 20:33:15 +0100 (Tue, 15 Dec 2009)
New Revision: 5755

Modified:
   trunk/eda/fped/coord.c
   trunk/eda/fped/coord.h
   trunk/eda/fped/gui_canvas.c
   trunk/eda/fped/gui_status.c
   trunk/eda/fped/gui_status.h
   trunk/eda/fped/inst.c
Log:
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



Modified: trunk/eda/fped/coord.c
===================================================================
--- trunk/eda/fped/coord.c	2009-12-11 00:48:10 UTC (rev 5754)
+++ trunk/eda/fped/coord.c	2009-12-15 19:33:15 UTC (rev 5755)
@@ -131,17 +131,25 @@
 }
 
 
-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 ----------------------------------------------- */
 
 

Modified: trunk/eda/fped/coord.h
===================================================================
--- trunk/eda/fped/coord.h	2009-12-11 00:48:10 UTC (rev 5754)
+++ trunk/eda/fped/coord.h	2009-12-15 19:33:15 UTC (rev 5755)
@@ -84,6 +84,7 @@
 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);

Modified: trunk/eda/fped/gui_canvas.c
===================================================================
--- trunk/eda/fped/gui_canvas.c	2009-12-11 00:48:10 UTC (rev 5754)
+++ trunk/eda/fped/gui_canvas.c	2009-12-15 19:33:15 UTC (rev 5755)
@@ -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_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));
 }
 
 

Modified: trunk/eda/fped/gui_status.c
===================================================================
--- trunk/eda/fped/gui_status.c	2009-12-11 00:48:10 UTC (rev 5754)
+++ trunk/eda/fped/gui_status.c	2009-12-15 19:33:15 UTC (rev 5755)
@@ -155,6 +155,16 @@
 }
 
 
+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;

Modified: trunk/eda/fped/gui_status.h
===================================================================
--- trunk/eda/fped/gui_status.h	2009-12-11 00:48:10 UTC (rev 5754)
+++ trunk/eda/fped/gui_status.h	2009-12-15 19:33:15 UTC (rev 5755)
@@ -85,6 +85,7 @@
     __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);
 

Modified: trunk/eda/fped/inst.c
===================================================================
--- trunk/eda/fped/inst.c	2009-12-11 00:48:10 UTC (rev 5754)
+++ trunk/eda/fped/inst.c	2009-12-15 19:33:15 UTC (rev 5755)
@@ -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 @@
 	status_set_angle("");
 	selected_inst = NULL;
 	edit_nothing();
+	refresh_pos();
 }
 
 
@@ -449,15 +451,14 @@
     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;




More information about the commitlog mailing list