[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
gEDA-cvs: pcb.git: branch: master updated (2029c9de01e48335a6c4649642748307293979bd)
The branch, master has been updated
via 2029c9de01e48335a6c4649642748307293979bd (commit)
via bf782a822f9102176de00ec16e77d48fd02584d5 (commit)
via fdc36bf8a0aef329504ec0250dcec05e280ce413 (commit)
via 09913663d0ad5c89bb0baff87a329ab29f973011 (commit)
from fa9ae1f6b1eabaab961795ce7be53afe46eaa735 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
=========
Summary
=========
src/hid/gtk/gtkhid-main.c | 8 +-
src/hid/gtk/gui-dialog-size.c | 3 +-
src/hid/gtk/gui-misc.c | 171 +++++++++++---------------------------
src/hid/gtk/gui-top-window.c | 11 ++-
src/hid/lesstif/dialogs.c | 11 +--
src/hid/lesstif/main.c | 184 ++++++++++++++++++-----------------------
src/hid/lesstif/menu.c | 6 +-
src/pcb-printf.c | 12 ++-
8 files changed, 162 insertions(+), 244 deletions(-)
=================
Commit Messages
=================
commit 2029c9de01e48335a6c4649642748307293979bd
Author: Andrew Poelstra <asp11@xxxxxx>
Commit: Andrew Poelstra <asp11@xxxxxx>
Convert lesstif hid to use pcb-printf
Should be no user-visible changes, except this bug:
Closes-bug: lp-805273
:100644 100644 ffe99eb... 8d606ae... M src/hid/lesstif/dialogs.c
:100644 100644 f4d0001... 811ac26... M src/hid/lesstif/main.c
:100644 100644 481bba5... 09bf74b... M src/hid/lesstif/menu.c
commit bf782a822f9102176de00ec16e77d48fd02584d5
Author: Andrew Poelstra <asp11@xxxxxx>
Commit: Andrew Poelstra <asp11@xxxxxx>
Add support for + and .* subspecifiers in pcb-printf
:100644 100644 2c1f912... 9f6734b... M src/pcb-printf.c
commit fdc36bf8a0aef329504ec0250dcec05e280ce413
Author: Andrew Poelstra <asp11@xxxxxx>
Commit: Andrew Poelstra <asp11@xxxxxx>
Clean up coords_to_widget() in lesstif/main.c
The coords_to_widget() function is used in exactly two places, for
different purposes. To differentiate between the two uses, the ``state''
parameter is set to -1.
The parameter is confusing enough without overloading it in this way.
Therefore I have split the function into two:
mark_delta_to_widget
cursor_pos_to_widget
Further, I have converted the code inside the functions to use
g_printf_strdup instead of a fixed buffer. The functions should both
be easier to read now than the original.
There is one small change to user-visible output, which I think is
justified: if you have a very small metric grid (<= 5um), the
mark_delta output now uses .3f for both cartesian and radial
display. Before it would use .3f for cartesian, .2f for radial.
:100644 100644 f41c4ce... f4d0001... M src/hid/lesstif/main.c
commit 09913663d0ad5c89bb0baff87a329ab29f973011
Author: Andrew Poelstra <asp11@xxxxxx>
Commit: Andrew Poelstra <asp11@xxxxxx>
Convert gtk gui to use pcb-printf
There should be no user-visible changes.
Note that as long as base units are cmils, the .9999 bug
in the cursor status is back. This is not a problem with
smaller base units (I am using 17nm and all is okay.)
Note also that the report dialogs are entirely based on
report.c, so that is not part of this commit.
:100644 100644 b5e36d5... 2fcb37b... M src/hid/gtk/gtkhid-main.c
:100644 100644 a5b5888... 0c0f8ef... M src/hid/gtk/gui-dialog-size.c
:100644 100644 21c8161... 730db5e... M src/hid/gtk/gui-misc.c
:100644 100644 23d6401... 44ad43a... M src/hid/gtk/gui-top-window.c
=========
Changes
=========
commit 2029c9de01e48335a6c4649642748307293979bd
Author: Andrew Poelstra <asp11@xxxxxx>
Commit: Andrew Poelstra <asp11@xxxxxx>
Convert lesstif hid to use pcb-printf
Should be no user-visible changes, except this bug:
Closes-bug: lp-805273
diff --git a/src/hid/lesstif/dialogs.c b/src/hid/lesstif/dialogs.c
index ffe99eb..8d606ae 100644
--- a/src/hid/lesstif/dialogs.c
+++ b/src/hid/lesstif/dialogs.c
@@ -16,6 +16,7 @@
#include "data.h"
#include "crosshair.h"
#include "misc.h"
+#include "pcb-printf.h"
#include "hid.h"
#include "../hidint.h"
@@ -1146,20 +1147,18 @@ sz_str2val (Widget w, int pcbu)
}
static void
-sz_val2str (Widget w, int u, int pcbu)
+sz_val2str (Widget w, BDimension u, int pcbu)
{
- double d;
static char buf[40];
if (pcbu)
{
if (Settings.grid_units_mm)
- d = COORD_TO_MM (u);
+ pcb_sprintf (buf, "%.2mm", u);
else
- d = COORD_TO_MIL (u);
- sprintf (buf, "%.2f", d + 0.002);
+ pcb_sprintf (buf, "%.2ml", u);
}
else
- sprintf (buf, "%d %%", u);
+ pcb_sprintf (buf, "%#mS %%", u);
XmTextSetString (w, buf);
}
diff --git a/src/hid/lesstif/main.c b/src/hid/lesstif/main.c
index f4d0001..811ac26 100644
--- a/src/hid/lesstif/main.c
+++ b/src/hid/lesstif/main.c
@@ -22,6 +22,7 @@
#include "crosshair.h"
#include "mymem.h"
#include "misc.h"
+#include "pcb-printf.h"
#include "resource.h"
#include "clip.h"
#include "error.h"
@@ -47,6 +48,7 @@ RCSID ("$Id$");
/* How big the viewport can be relative to the pcb size. */
#define MAX_ZOOM_SCALE 10
+#define UUNIT (Settings.grid_units_mm ? ALLOW_MM : ALLOW_MIL)
typedef struct hid_gc_struct
{
@@ -347,7 +349,7 @@ PCBChanged (int argc, char **argv, int x, int y)
{
if (work_area == 0)
return 0;
- /*printf("PCB Changed! %d x %d\n", PCB->MaxWidth, PCB->MaxHeight); */
+ /*pcb_printf("PCB Changed! %$mD\n", PCB->MaxWidth, PCB->MaxHeight); */
n = 0;
stdarg (XmNminimum, 0);
stdarg (XmNvalue, 0);
@@ -1413,7 +1415,7 @@ work_area_input (Widget w, XtPointer v, XEvent * e, Boolean * ctd)
#else
alt_pressed = (keys_buttons & Mod1Mask);
#endif
- /*printf("m %d %d\n", Px(e->xmotion.x), Py(e->xmotion.y)); */
+ /*pcb_printf("m %#mS %#mS\n", Px(e->xmotion.x), Py(e->xmotion.y)); */
crosshair_in_window = 1;
in_move_event = 1;
if (panning)
@@ -2299,44 +2301,29 @@ draw_grid ()
}
static void
-mark_delta_to_widget (BDimension x, BDimension y, Widget w)
+mark_delta_to_widget (BDimension dx, BDimension dy, Widget w)
{
char *buf;
- double dx, dy, g;
+ double g = Settings.grid_units_mm ? COORD_TO_MM (PCB->Grid) : COORD_TO_MIL (PCB->Grid);
int prec;
- bool int_grid;
XmString ms;
- if (Settings.grid_units_mm)
- {
- dx = COORD_TO_MM (x);
- dy = COORD_TO_MM (y);
- g = COORD_TO_MM (PCB->Grid);
- }
- else
- {
- dx = COORD_TO_MIL (x);
- dy = COORD_TO_MIL (y);
- g = COORD_TO_MIL (PCB->Grid);
- }
-
- int_grid = (((int) (g * 10000 + 0.5) % 10000) == 0);
-
- if (int_grid)
+ /* Integer-sized grid? */
+ if (((int) (g * 10000 + 0.5) % 10000) == 0)
prec = 0;
else if (Settings.grid_units_mm && g <= 0.005)
prec = 3;
else
prec = 2;
- if (x == 0 && y == 0)
- buf = g_strdup_printf ("%+.*f, %+.*f", prec, dx, prec, dy);
+ if (dx == 0 && dy == 0)
+ buf = pcb_g_strdup_printf ("%m+%+.*mS, %+.*mS", UUNIT, prec, dx, prec, dy);
else
{
int angle = atan2 (dy, -dx) * 180 / M_PI;
- double dist = Distance (0, dx, 0, dy);
+ BDimension dist = Distance (0, dx, 0, dy);
- buf = g_strdup_printf ("%+.*f, %+.*f (%.*f, %d\260)",
+ buf = pcb_g_strdup_printf ("%m+%+.*mS, %+.*mS (%.*mS, %d\260)", UUNIT,
prec, dx, prec, dy, prec, dist, angle);
}
@@ -2348,35 +2335,17 @@ mark_delta_to_widget (BDimension x, BDimension y, Widget w)
}
static int
-cursor_pos_to_widget (int x, int y, Widget w, int prev_state)
+cursor_pos_to_widget (BDimension x, BDimension y, Widget w, int prev_state)
{
int this_state = prev_state;
static char *buf;
- double dx, dy, g;
+ double g = Settings.grid_units_mm ? COORD_TO_MM (PCB->Grid) : COORD_TO_MIL (PCB->Grid);
XmString ms;
int prec;
- bool int_grid;
-
- if (Settings.grid_units_mm)
- {
- /* MM */
- dx = COORD_TO_MM (x);
- dy = COORD_TO_MM (y);
- g = COORD_TO_MM (PCB->Grid);
- }
- else
- {
- /* Mils */
- dx = COORD_TO_MIL (x);
- dy = COORD_TO_MIL (y);
- g = COORD_TO_MIL (PCB->Grid);
- }
-
- int_grid = (((int) (g * 10000 + 0.5) % 10000) == 0);
/* Determine necessary precision (and state) based
* on the user's grid setting */
- if (int_grid)
+ if (((int) (g * 10000 + 0.5) % 10000) == 0)
{
prec = 0;
this_state = 2 + Settings.grid_units_mm;
@@ -2395,7 +2364,7 @@ cursor_pos_to_widget (int x, int y, Widget w, int prev_state)
if (x < 0)
buf = g_strdup ("");
else
- buf = g_strdup_printf ("%.*f, %.*f", prec, dx, prec, dy);
+ buf = pcb_g_strdup_printf ("%m+%.*mS, %.*mS", UUNIT, prec, x, prec, y);
ms = XmStringCreateLocalized (buf);
n = 0;
@@ -2405,59 +2374,38 @@ cursor_pos_to_widget (int x, int y, Widget w, int prev_state)
return this_state;
}
-static char *
-pcb2str (int pcbval)
-{
- static char buf[20][20];
- static int bufp = 0;
- double d;
-
- bufp = (bufp + 1) % 20;
- if (Settings.grid_units_mm)
- d = COORD_TO_MM (pcbval);
- else
- d = COORD_TO_MIL (pcbval);
-
- if ((int) (d * 100 + 0.5) == (int) (d + 0.005) * 100)
- sprintf (buf[bufp], "%d", (int) d);
- else
- sprintf (buf[bufp], "%.2f", d);
- return buf[bufp];
-}
-
-#define u(x) pcb2str(x)
#define S Settings
void
lesstif_update_status_line ()
{
- char buf[100];
+ char *buf = NULL;
char *s45 = cur_clip ();
XmString xs;
- buf[0] = 0;
switch (Settings.Mode)
{
case VIA_MODE:
- sprintf (buf, "%s/%s \370=%s", u (S.ViaThickness),
- u (S.Keepaway), u (S.ViaDrillingHole));
+ buf = pcb_g_strdup_printf ("%m+%.2mS/%.2mS \370=%.2mS", UUNIT,
+ S.ViaThickness, S.Keepaway, S.ViaDrillingHole);
break;
case LINE_MODE:
case ARC_MODE:
- sprintf (buf, "%s/%s %s", u (S.LineThickness), u (S.Keepaway), s45);
+ buf = pcb_g_strdup_printf ("%m+%.2mS/%.2mS %s", UUNIT,
+ S.LineThickness, S.Keepaway, s45);
break;
case RECTANGLE_MODE:
case POLYGON_MODE:
- sprintf (buf, "%s %s", u (S.Keepaway), s45);
+ buf = pcb_g_strdup_printf ("%m+%.2mS %s", UUNIT, S.Keepaway, s45);
break;
case TEXT_MODE:
- sprintf (buf, "%s", u (S.TextScale));
+ buf = g_strdup_printf ("%d %%", S.TextScale);
break;
case MOVE_MODE:
case COPY_MODE:
case INSERTPOINT_MODE:
case RUBBERBANDMOVE_MODE:
- sprintf (buf, "%s", s45);
+ buf = g_strdup_printf ("%s", s45);
break;
case NO_MODE:
case PASTEBUFFER_MODE:
@@ -2466,6 +2414,8 @@ lesstif_update_status_line ()
case THERMAL_MODE:
case ARROW_MODE:
case LOCK_MODE:
+ default:
+ buf = g_strdup("");
break;
}
@@ -2473,9 +2423,9 @@ lesstif_update_status_line ()
n = 0;
stdarg (XmNlabelString, xs);
XtSetValues (m_status, args, n);
+ g_free (buf);
}
-#undef u
#undef S
static int idle_proc_set = 0;
@@ -2656,15 +2606,13 @@ idle_proc (XtPointer dummy)
{
static double old_grid = -1;
- static int old_gx, old_gy, old_mm;
- XmString ms;
+ static BDimension old_gx, old_gy, old_mm;
+ XmString ms;
if (PCB->Grid != old_grid
|| PCB->GridOffsetX != old_gx
|| PCB->GridOffsetY != old_gy || Settings.grid_units_mm != old_mm)
{
static char buf[100];
- double g, x, y;
- char *u;
old_grid = PCB->Grid;
old_gx = PCB->GridOffsetX;
old_gy = PCB->GridOffsetY;
@@ -2675,24 +2623,10 @@ idle_proc (XtPointer dummy)
}
else
{
- if (Settings.grid_units_mm)
- {
- g = COORD_TO_MM (old_grid);
- x = COORD_TO_MM (old_gx);
- y = COORD_TO_MM (old_gy);
- u = "mm";
- }
- else
- {
- g = COORD_TO_MIL (old_grid);
- x = COORD_TO_MIL (old_gx);
- y = COORD_TO_MIL (old_gy);
- u = "mil";
- }
- if (x || y)
- sprintf (buf, "%g %s @%g,%g", g, u, x, y);
+ if (old_gx || old_gy)
+ pcb_sprintf (buf, "%m+%$mS @%mS,%mS", UUNIT, (BDimension) old_grid, old_gx, old_gy);
else
- sprintf (buf, "%g %s", g, u);
+ pcb_sprintf (buf, "%m+%$mS", UUNIT, (BDimension) old_grid);
}
ms = XmStringCreateLocalized (buf);
n = 0;
@@ -3201,7 +3135,7 @@ set_gc (hidGC gc)
abort ();
}
#if 0
- printf ("set_gc c%s %08lx w%d c%d x%d e%d\n",
+ pcb_printf ("set_gc c%s %08lx w%#mS c%d x%d e%d\n",
gc->colorname, gc->color, gc->width, gc->cap, gc->xor_set, gc->erase);
#endif
switch (gc->cap)
@@ -3283,14 +3217,14 @@ lesstif_draw_line (hidGC gc, int x1, int y1, int x2, int y2)
if ((pinout || TEST_FLAG (THINDRAWFLAG, PCB) || TEST_FLAG(THINDRAWPOLYFLAG, PCB)) && gc->erase)
return;
#if 0
- printf ("draw_line %d,%d %d,%d @%d", x1, y1, x2, y2, gc->width);
+ pcb_printf ("draw_line %#mD-%#mD @%#mS", x1, y1, x2, y2, gc->width);
#endif
dx1 = Vx (x1);
dy1 = Vy (y1);
dx2 = Vx (x2);
dy2 = Vy (y2);
#if 0
- printf (" = %d,%d %d,%d %s\n", x1, y1, x2, y2, gc->colorname);
+ pcb_printf (" = %#mD-%#mD %s\n", x1, y1, x2, y2, gc->colorname);
#endif
#if 1
@@ -3328,7 +3262,7 @@ lesstif_draw_arc (hidGC gc, int cx, int cy, int width, int height,
if ((pinout || TEST_FLAG (THINDRAWFLAG, PCB)) && gc->erase)
return;
#if 0
- printf ("draw_arc %d,%d %dx%d s %d d %d", cx, cy, width, height, start_angle, delta_angle);
+ pcb_printf ("draw_arc %#mD %#mSx%#mS s %d d %d", cx, cy, width, height, start_angle, delta_angle);
#endif
width = Vz (width);
height = Vz (height);
@@ -3346,7 +3280,7 @@ lesstif_draw_arc (hidGC gc, int cx, int cy, int width, int height,
}
start_angle = (start_angle + 360 + 180) % 360 - 180;
#if 0
- printf (" = %d,%d %dx%d %d %s\n", cx, cy, width, height, gc->width,
+ pcb_printf (" = %#mD %#mSx%#mS %d %s\n", cx, cy, width, height, gc->width,
gc->colorname);
#endif
set_gc (gc);
@@ -3410,7 +3344,7 @@ lesstif_fill_circle (hidGC gc, int cx, int cy, int radius)
if ((TEST_FLAG (THINDRAWFLAG, PCB) || TEST_FLAG(THINDRAWPOLYFLAG, PCB)) && gc->erase)
return;
#if 0
- printf ("fill_circle %d,%d %d", cx, cy, radius);
+ pcb_printf ("fill_circle %#mD %#mS", cx, cy, radius);
#endif
radius = Vz (radius);
cx = Vx (cx) - radius;
@@ -3420,7 +3354,7 @@ lesstif_fill_circle (hidGC gc, int cx, int cy, int radius)
if (cy < -2 * radius || cy > view_height)
return;
#if 0
- printf (" = %d,%d %d %lx %s\n", cx, cy, radius, gc->color, gc->colorname);
+ pcb_printf (" = %#mD %#mS %lx %s\n", cx, cy, radius, gc->color, gc->colorname);
#endif
set_gc (gc);
XFillArc (display, pixmap, my_gc, cx, cy,
diff --git a/src/hid/lesstif/menu.c b/src/hid/lesstif/menu.c
index 481bba5..09bf74b 100644
--- a/src/hid/lesstif/menu.c
+++ b/src/hid/lesstif/menu.c
@@ -92,13 +92,13 @@ on one.
%end-doc */
static int
-Debug (int argc, char **argv, int x, int y)
+Debug (int argc, char **argv, BDimension x, BDimension y)
{
int i;
printf ("Debug:");
for (i = 0; i < argc; i++)
printf (" [%d] `%s'", i, argv[i]);
- printf (" x,y %d,%d\n", x, y);
+ pcb_printf (" x,y %$mD\n", x, y);
return 0;
}
@@ -836,7 +836,7 @@ callback (Widget w, Resource * node, XmPushButtonCallbackStruct * pbcs)
if (p == aw)
have_xy = 1;
}
- //printf("have xy from %s: %d %d\n", XtName(aw), action_x, action_y);
+ //pcb_printf("have xy from %s: %$mD\n", XtName(aw), action_x, action_y);
}
lesstif_need_idle_proc ();
commit bf782a822f9102176de00ec16e77d48fd02584d5
Author: Andrew Poelstra <asp11@xxxxxx>
Commit: Andrew Poelstra <asp11@xxxxxx>
Add support for + and .* subspecifiers in pcb-printf
diff --git a/src/pcb-printf.c b/src/pcb-printf.c
index 2c1f912..9f6734b 100644
--- a/src/pcb-printf.c
+++ b/src/pcb-printf.c
@@ -245,8 +245,16 @@ static gchar *pcb_vprintf(const char *fmt, va_list args)
g_string_append_c (spec, *fmt++);
while(isdigit(*fmt) || *fmt == '.' || *fmt == ' ' || *fmt == '*'
|| *fmt == '#' || *fmt == 'l' || *fmt == 'L'
- || *fmt == 'h' || *fmt == '-')
- g_string_append_c (spec, *fmt++);
+ || *fmt == 'h' || *fmt == '+' || *fmt == '-')
+ {
+ if (*fmt == '*')
+ {
+ g_string_append_printf (spec, "%d", va_arg (args, int));
+ fmt++;
+ }
+ else
+ g_string_append_c (spec, *fmt++);
+ }
/* Get our sub-specifiers */
if(*fmt == '#')
{
commit fdc36bf8a0aef329504ec0250dcec05e280ce413
Author: Andrew Poelstra <asp11@xxxxxx>
Commit: Andrew Poelstra <asp11@xxxxxx>
Clean up coords_to_widget() in lesstif/main.c
The coords_to_widget() function is used in exactly two places, for
different purposes. To differentiate between the two uses, the ``state''
parameter is set to -1.
The parameter is confusing enough without overloading it in this way.
Therefore I have split the function into two:
mark_delta_to_widget
cursor_pos_to_widget
Further, I have converted the code inside the functions to use
g_printf_strdup instead of a fixed buffer. The functions should both
be easier to read now than the original.
There is one small change to user-visible output, which I think is
justified: if you have a very small metric grid (<= 5um), the
mark_delta output now uses .3f for both cartesian and radial
display. Before it would use .3f for cartesian, .2f for radial.
diff --git a/src/hid/lesstif/main.c b/src/hid/lesstif/main.c
index f41c4ce..f4d0001 100644
--- a/src/hid/lesstif/main.c
+++ b/src/hid/lesstif/main.c
@@ -2298,14 +2298,64 @@ draw_grid ()
}
}
+static void
+mark_delta_to_widget (BDimension x, BDimension y, Widget w)
+{
+ char *buf;
+ double dx, dy, g;
+ int prec;
+ bool int_grid;
+ XmString ms;
+
+ if (Settings.grid_units_mm)
+ {
+ dx = COORD_TO_MM (x);
+ dy = COORD_TO_MM (y);
+ g = COORD_TO_MM (PCB->Grid);
+ }
+ else
+ {
+ dx = COORD_TO_MIL (x);
+ dy = COORD_TO_MIL (y);
+ g = COORD_TO_MIL (PCB->Grid);
+ }
+
+ int_grid = (((int) (g * 10000 + 0.5) % 10000) == 0);
+
+ if (int_grid)
+ prec = 0;
+ else if (Settings.grid_units_mm && g <= 0.005)
+ prec = 3;
+ else
+ prec = 2;
+
+ if (x == 0 && y == 0)
+ buf = g_strdup_printf ("%+.*f, %+.*f", prec, dx, prec, dy);
+ else
+ {
+ int angle = atan2 (dy, -dx) * 180 / M_PI;
+ double dist = Distance (0, dx, 0, dy);
+
+ buf = g_strdup_printf ("%+.*f, %+.*f (%.*f, %d\260)",
+ prec, dx, prec, dy, prec, dist, angle);
+ }
+
+ ms = XmStringCreateLocalized (buf);
+ n = 0;
+ stdarg (XmNlabelString, ms);
+ XtSetValues (w, args, n);
+ g_free (buf);
+}
+
static int
-coords_to_widget (int x, int y, Widget w, int prev_state)
+cursor_pos_to_widget (int x, int y, Widget w, int prev_state)
{
int this_state = prev_state;
- static char buf[60];
+ static char *buf;
double dx, dy, g;
- int frac = 0;
XmString ms;
+ int prec;
+ bool int_grid;
if (Settings.grid_units_mm)
{
@@ -2321,43 +2371,37 @@ coords_to_widget (int x, int y, Widget w, int prev_state)
dy = COORD_TO_MIL (y);
g = COORD_TO_MIL (PCB->Grid);
}
- if (x < 0 && prev_state >= 0)
- buf[0] = 0;
- else if (((int) (g * 10000 + 0.5) % 10000) == 0)
+
+ int_grid = (((int) (g * 10000 + 0.5) % 10000) == 0);
+
+ /* Determine necessary precision (and state) based
+ * on the user's grid setting */
+ if (int_grid)
{
- const char *fmt = prev_state < 0 ? "%+d, %+d" : "%d, %d";
- sprintf (buf, fmt, (int) (dx + 0.5), (int) (dy + 0.5));
+ prec = 0;
this_state = 2 + Settings.grid_units_mm;
- frac = 0;
}
- else if (PCB->Grid <= 20 && Settings.grid_units_mm)
+ else if (Settings.grid_units_mm && g <= 0.005)
{
- const char *fmt = prev_state < 0 ? "%+.3f, %+.3f" : "%.3f, %.3f";
- sprintf (buf, fmt, dx, dy);
+ prec = 3;
this_state = 4 + Settings.grid_units_mm;
- frac = 1;
}
else
{
- const char *fmt = prev_state < 0 ? "%+.2f, %+.2f" : "%.2f, %.2f";
- sprintf (buf, fmt, dx, dy);
+ prec = 2;
this_state = 4 + Settings.grid_units_mm;
- frac = 1;
- }
- if (prev_state < 0 && (x || y))
- {
- int angle = atan2 (dy, -dx) * 180 / M_PI;
- double dist = sqrt (dx * dx + dy * dy);
- if (frac)
- sprintf (buf + strlen (buf), " (%.2f", dist);
- else
- sprintf (buf + strlen (buf), " (%d", (int) (dist + 0.5));
- sprintf (buf + strlen (buf), ", %d\260)", angle);
}
+
+ if (x < 0)
+ buf = g_strdup ("");
+ else
+ buf = g_strdup_printf ("%.*f, %.*f", prec, dx, prec, dy);
+
ms = XmStringCreateLocalized (buf);
n = 0;
stdarg (XmNlabelString, ms);
XtSetValues (w, args, n);
+ g_free (buf);
return this_state;
}
@@ -2552,11 +2596,11 @@ idle_proc (XtPointer dummy)
c_y = crosshair_y;
this_state =
- coords_to_widget (crosshair_x, crosshair_y, m_crosshair,
+ cursor_pos_to_widget (crosshair_x, crosshair_y, m_crosshair,
this_state);
if (Marked.status)
- coords_to_widget (crosshair_x - Marked.X, crosshair_y - Marked.Y,
- m_mark, -1);
+ mark_delta_to_widget (crosshair_x - Marked.X, crosshair_y - Marked.Y,
+ m_mark);
if (Marked.status != saved_mark.status)
{
commit 09913663d0ad5c89bb0baff87a329ab29f973011
Author: Andrew Poelstra <asp11@xxxxxx>
Commit: Andrew Poelstra <asp11@xxxxxx>
Convert gtk gui to use pcb-printf
There should be no user-visible changes.
Note that as long as base units are cmils, the .9999 bug
in the cursor status is back. This is not a problem with
smaller base units (I am using 17nm and all is okay.)
Note also that the report dialogs are entirely based on
report.c, so that is not part of this commit.
diff --git a/src/hid/gtk/gtkhid-main.c b/src/hid/gtk/gtkhid-main.c
index b5e36d5..2fcb37b 100644
--- a/src/hid/gtk/gtkhid-main.c
+++ b/src/hid/gtk/gtkhid-main.c
@@ -196,7 +196,7 @@ zoom_to (double new_zoom, int x, int y)
*/
#ifdef DEBUG
- printf ("\nzoom_to( %g, %d, %d)\n", new_zoom, x, y);
+ pcb_printf ("\nzoom_to( %g, %#mS, %#mS)\n", new_zoom, x, y);
#endif
xfrac = (double) x / (double) gport->view_width;
@@ -236,8 +236,8 @@ zoom_to (double new_zoom, int x, int y)
cy = gport->view_y0 + gport->view_height * yfrac * gport->zoom;
#ifdef DEBUG
- printf ("zoom_to(): x0 = %d, cx = %d\n", gport->view_x0, cx);
- printf ("zoom_to(): y0 = %d, cy = %d\n", gport->view_y0, cy);
+ pcb_printf ("zoom_to(): x0 = %#mS, cx = %#mS\n", gport->view_x0, cx);
+ pcb_printf ("zoom_to(): y0 = %#mS, cy = %#mS\n", gport->view_y0, cy);
#endif
if (gport->zoom != new_zoom)
@@ -281,7 +281,7 @@ void
zoom_by (double factor, int x, int y)
{
#ifdef DEBUG
- printf ("\nzoom_by( %g, %d, %d). old gport->zoom = %g\n",
+ pcb_printf ("\nzoom_by( %g, %#mS, %#mS). old gport->zoom = %g\n",
factor, x, y, gport->zoom);
#endif
zoom_to (gport->zoom * factor, x, y);
diff --git a/src/hid/gtk/gui-dialog-size.c b/src/hid/gtk/gui-dialog-size.c
index a5b5888..0c0f8ef 100644
--- a/src/hid/gtk/gui-dialog-size.c
+++ b/src/hid/gtk/gui-dialog-size.c
@@ -43,6 +43,7 @@
#include "error.h"
#include "misc.h"
#include "set.h"
+#include "pcb-printf.h"
#include "gui.h"
@@ -78,7 +79,7 @@ make_route_string(RouteStyleType * rs)
str = g_strdup("");
for (i = 0; i < NUM_STYLES; ++i, ++rs)
{
- s = g_strdup_printf ("%s,%d,%d,%d,%d", rs->Name,
+ s = pcb_g_strdup_printf ("%s,%mc,%mc,%mc,%mc", rs->Name,
rs->Thick, rs->Diameter, rs->Hole, rs->Keepaway);
colon = (i == NUM_STYLES - 1) ? NULL : (gchar *)":";
t = str;
diff --git a/src/hid/gtk/gui-misc.c b/src/hid/gtk/gui-misc.c
index 21c8161..730db5e 100644
--- a/src/hid/gtk/gui-misc.c
+++ b/src/hid/gtk/gui-misc.c
@@ -34,6 +34,7 @@
#include "misc.h"
#include "action.h"
#include "set.h"
+#include "pcb-printf.h"
#include "gui.h"
#include <gdk/gdkkeysyms.h>
@@ -496,114 +497,44 @@ ghid_get_pointer (int *x, int *y)
void
ghid_set_status_line_label (void)
{
- gchar text[512];
-
- if (!Settings.grid_units_mm)
- snprintf (text, sizeof (text),
- _("<b>view</b>=%s "
- "<b>grid</b>=%.1f:%i "
- "%s%s "
- "<b>line</b>=%.1f "
- "<b>via</b>=%.1f(%.1f) %s"
- "<b>clearance</b>=%.1f "
- "<b>text</b>=%i%% "
- "<b>buffer</b>=#%i"),
- Settings.ShowSolderSide ? _("solder") : _("component"),
- COORD_TO_MIL(PCB->Grid),
- (int) Settings.GridFactor,
- TEST_FLAG (ALLDIRECTIONFLAG, PCB) ? "all" :
- (PCB->Clipping == 0 ? "45" :
- (PCB->Clipping == 1 ? "45_/" : "45\\_")),
- TEST_FLAG (RUBBERBANDFLAG, PCB) ? ",R " : " ",
- COORD_TO_MIL(Settings.LineThickness),
- COORD_TO_MIL(Settings.ViaThickness),
- COORD_TO_MIL(Settings.ViaDrillingHole),
- ghidgui->compact_horizontal ? "\n" : "",
- COORD_TO_MIL(Settings.Keepaway),
- Settings.TextScale, Settings.BufferNumber + 1);
- else
- snprintf (text, sizeof (text),
- _("<b>view</b>=%s "
- "<b>grid</b>=%5.3f:%i "
- "%s%s "
- "<b>line</b>=%5.3f "
- "<b>via</b>=%5.3f(%5.3f) %s"
- "<b>clearance</b>=%5.3f "
- "<b>text</b>=%i%% "
- "<b>buffer</b>=#%i"),
- Settings.ShowSolderSide ? _("solder") : _("component"),
- COORD_TO_MM(PCB->Grid), (int) Settings.GridFactor,
- TEST_FLAG (ALLDIRECTIONFLAG, PCB) ? "all" :
- (PCB->Clipping == 0 ? "45" :
- (PCB->Clipping == 1 ? "45_/" : "45\\_")),
- TEST_FLAG (RUBBERBANDFLAG, PCB) ? ",R " : " ",
- COORD_TO_MM(Settings.LineThickness),
- COORD_TO_MM(Settings.ViaThickness),
- COORD_TO_MM(Settings.ViaDrillingHole),
- ghidgui->compact_horizontal ? "\n" : "",
- COORD_TO_MM(Settings.Keepaway),
- Settings.TextScale, Settings.BufferNumber + 1);
+ gchar *flag = TEST_FLAG (ALLDIRECTIONFLAG, PCB)
+ ? "all"
+ : (PCB->Clipping == 0
+ ? "45"
+ : (PCB->Clipping == 1
+ ? "45_/"
+ : "45\\_"));
+ gchar *text = pcb_g_strdup_printf (
+ Settings.grid_units_mm
+ ? _("<b>view</b>=%s "
+ "<b>grid</b>=%5.3mm:%i "
+ "%s%s "
+ "<b>line</b>=%5.3mm "
+ "<b>via</b>=%5.3mm(%5.3mm) %s"
+ "<b>clearance</b>=%5.3mm "
+ "<b>text</b>=%i%% "
+ "<b>buffer</b>=#%i")
+ : _("<b>view</b>=%s "
+ "<b>grid</b>=%.1ml:%i "
+ "%s%s "
+ "<b>line</b>=%.1ml "
+ "<b>via</b>=%.1ml(%.1ml) %s"
+ "<b>clearance</b>=%.1ml "
+ "<b>text</b>=%i%% "
+ "<b>buffer</b>=#%i"),
+ Settings.ShowSolderSide ? _("solder") : _("component"),
+ (BDimension) PCB->Grid,
+ (int) Settings.GridFactor,
+ flag, TEST_FLAG (RUBBERBANDFLAG, PCB) ? ",R " : " ",
+ Settings.LineThickness,
+ Settings.ViaThickness,
+ Settings.ViaDrillingHole,
+ ghidgui->compact_horizontal ? "\n" : "",
+ Settings.Keepaway,
+ Settings.TextScale, Settings.BufferNumber + 1);
ghid_status_line_set_text (text);
-}
-
-/* returns an auxiliary value needed to adjust mm grid.
- the adjustment is needed to prevent ..99 tails in position labels.
-
- All these are a workaround to precision lost
- because of double->integer transform
- while fitting Crosshair to grid in crosshair.c
-
- There is another workaround: report mm dimensions with %.2f, like
- in the Lesstif hid; but this reduces the information */
-static double
-ghid_get_grid_factor(void)
-{
- /* when grid units are mm, they shall be an integer of
- 1 mm / grid_scale */
- const int grid_scale = 10000; /* metric grid step is .1 um */
- double factor, rounded_factor;
-
- /* adjustment is not needed for inches
- probably because x/100 is always 'integer' enough */
- if (!Settings.grid_units_mm)
- return -1;
-
- factor = COORD_TO_MM(PCB->Grid) * grid_scale;
- rounded_factor = floor (factor + .5);
-
- /* check whether the grid is actually metric
- (as of Feb 2011, Settings.grid_units_mm may indicate just that
- the _displayed_ units are mm) */
- if (fabs (factor - rounded_factor) > 1e-3)
- return -1;
-
- return rounded_factor / grid_scale;
-}
-/* transforms a pcb coordinate to selected units
- adjusted to the nearest grid point for mm grid */
-static double
-ghid_grid_pcb_to_units (double x, double grid_factor)
-{
- double x_scaled = (Settings.grid_units_mm ? COORD_TO_MM(1): COORD_TO_MIL(1)) * x;
- double nearest_gridpoint;
-
- if (grid_factor < 0)
- return x_scaled;
-
- x = COORD_TO_MM(x);
-
- nearest_gridpoint = floor (x / grid_factor + .5);
- /* honour snapping to an unaligned object */
- if (fabs (nearest_gridpoint * grid_factor - x) > COORD_TO_MM(1))
- return x_scaled;
- /* without mm-adjusted grid_factor
- (return floor (x / PCB->Grid + .5) * COORD_TO_MM(PCB->Grid)),
- the round-off errors redintroduce the bug for 0.1 or 0.05 mm grid
- at coordinates more than 1500 mm.
- grid_factor makes the stuff work at least up to 254 m,
- which is 100 times more than default maximum board size as of Feb 2011. */
- return nearest_gridpoint * grid_factor;
+ g_free (text);
}
/* ---------------------------------------------------------------------------
@@ -612,28 +543,28 @@ ghid_grid_pcb_to_units (double x, double grid_factor)
void
ghid_set_cursor_position_labels (void)
{
- gchar text[128];
- int prec = Settings.grid_units_mm ? 4: 2;
- double grid_factor = ghid_get_grid_factor();
+ gchar *text;
if (Marked.status)
{
- double dx, dy, r, a;
-
- dx = ghid_grid_pcb_to_units (Crosshair.X - Marked.X, grid_factor);
- dy = ghid_grid_pcb_to_units (Crosshair.Y - Marked.Y, grid_factor);
- r = sqrt (dx * dx + dy * dy);
- a = atan2 (dy, dx) * RAD_TO_DEG;
- snprintf (text, sizeof (text), "r %-.*f; phi %-.1f; %-.*f %-.*f",
- prec, r, a, prec, dx, prec, dy);
+ BDimension dx = Crosshair.X - Marked.X;
+ BDimension dy = Crosshair.Y - Marked.Y;
+ BDimension r = Distance (Crosshair.X, Crosshair.Y, Marked.X, Marked.Y);
+ double a = atan2 (dy, dx) * RAD_TO_DEG;
+
+ text = pcb_g_strdup_printf ("%m+r %-mS; phi %-.1f; %-mS %-mS",
+ Settings.grid_units_mm ? ALLOW_MM : ALLOW_MIL,
+ r, a, dx, dy);
ghid_cursor_position_relative_label_set_text (text);
+ g_free (text);
}
else
ghid_cursor_position_relative_label_set_text ("r __.__; phi __._; __.__ __.__");
- snprintf (text, sizeof (text), "%-.*f %-.*f",
- prec, ghid_grid_pcb_to_units (Crosshair.X, grid_factor),
- prec, ghid_grid_pcb_to_units (Crosshair.Y, grid_factor));
+ text = pcb_g_strdup_printf ("%m+%-mS %-mS",
+ Settings.grid_units_mm ? ALLOW_MM : ALLOW_MIL,
+ Crosshair.X, Crosshair.Y);
ghid_cursor_position_label_set_text (text);
+ g_free (text);
}
diff --git a/src/hid/gtk/gui-top-window.c b/src/hid/gtk/gui-top-window.c
index 23d6401..44ad43a 100644
--- a/src/hid/gtk/gui-top-window.c
+++ b/src/hid/gtk/gui-top-window.c
@@ -107,6 +107,7 @@ a zoom in/out.
#include "mymem.h"
#include "misc.h"
#include "move.h"
+#include "pcb-printf.h"
#include "polygon.h"
#include "rats.h"
#include "remove.h"
@@ -688,7 +689,7 @@ handle_grid_units_change (gboolean active)
ghid_grid_setting_update_menu_actions ();
- grid = g_strdup_printf ("%f", PCB->Grid);
+ grid = pcb_g_strdup_printf ("%$ms", (BDimension) PCB->Grid);
hid_actionl ("SetValue", "Grid", grid, "", NULL);
g_free (grid);
@@ -700,7 +701,7 @@ handle_grid_units_change (gboolean active)
static void
radio_grid_mil_setting_cb (GtkAction * action, GtkRadioAction * current)
{
- gdouble value;
+ BDimension value;
gchar *grid;
gint index;
@@ -709,7 +710,7 @@ radio_grid_mil_setting_cb (GtkAction * action, GtkRadioAction * current)
return;
index = gtk_radio_action_get_current_value (current);
value = grid_mil_values[index];
- grid = g_strdup_printf ("%f", value);
+ grid = pcb_g_strdup_printf ("%$ms", value);
hid_actionl ("SetValue", "Grid", grid, "", NULL);
g_free (grid);
ghid_set_status_line_label ();
@@ -718,7 +719,7 @@ radio_grid_mil_setting_cb (GtkAction * action, GtkRadioAction * current)
static void
radio_grid_mm_setting_cb (GtkAction * action, GtkRadioAction * current)
{
- gdouble value;
+ BDimension value;
gchar *grid;
gint index;
@@ -727,7 +728,7 @@ radio_grid_mm_setting_cb (GtkAction * action, GtkRadioAction * current)
return;
index = gtk_radio_action_get_current_value (current);
value = grid_mm_values[index];
- grid = g_strdup_printf ("%f", value);
+ grid = pcb_g_strdup_printf ("%$ms", value);
hid_actionl ("SetValue", "Grid", grid, "", NULL);
g_free (grid);
ghid_set_status_line_label ();
_______________________________________________
geda-cvs mailing list
geda-cvs@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-cvs