Please check the attached patch - now everything in the model is updated
correctly.
--
Krzysztof Kościuszkiewicz
Simplicity is the ultimate sophistication -- Leonardo da Vinci
From 9e58163f910c9e24ecd6400b2dc81e158c86152b Mon Sep 17 00:00:00 2001
From: Krzysztof Kosciuszkiewicz k.kosciuszkiew...@gmail.com
Date: Fri, 4 Mar 2011 02:14:53 +0100
Subject: [PATCH 2/2] hid/gtk: further improvements to new grid config
---
src/const.h |4 +-
src/hid/gtk/gtkhid-gdk.c |2 +
src/hid/gtk/gui-config.c | 116 -
3 files changed, 76 insertions(+), 46 deletions(-)
diff --git a/src/const.h b/src/const.h
index 7b952f8..8062569 100644
--- a/src/const.h
+++ b/src/const.h
@@ -71,8 +71,8 @@
#define COOR_TO_MM 0.000254000
#define MM_TO_COOR 3937.007874
-#define COOR_TO_MIL 1. / 100 //added 02.02.2011 for uniformity
-#define MIL_TO_COOR 100. / 1
+#define COOR_TO_MIL 0.01 //added 02.02.2011 for uniformity
+#define MIL_TO_COOR 100.0
enum// Currently not used except mil and mm, but i will
{ // become happy if at least microns can be added.
MIL = 0, // Major code changes in some places need for this, though.
diff --git a/src/hid/gtk/gtkhid-gdk.c b/src/hid/gtk/gtkhid-gdk.c
index 55951e4..c78d1e8 100644
--- a/src/hid/gtk/gtkhid-gdk.c
+++ b/src/hid/gtk/gtkhid-gdk.c
@@ -132,6 +132,8 @@ ghid_draw_grid (void)
if (d==0) { // static grid without any check to min distance, zooming, etc,
// made by request
+if (g == 0)
+ return;
gridmode = 1;
pcbgrid = g;
} else {
diff --git a/src/hid/gtk/gui-config.c b/src/hid/gtk/gui-config.c
index e864da1..1cb82ae 100644
--- a/src/hid/gtk/gui-config.c
+++ b/src/hid/gtk/gui-config.c
@@ -1352,45 +1352,74 @@ enum
NUM_COLS
} ;
-void cb_edited_mm_or_mil(GtkCellRendererText *cell, gchar *path, gchar *text,
- GtkTreeView *treeview) {
- double d;
- GtkListStore *store;
- GtkTreeIter iter;
- int units;
- store = GTK_LIST_STORE (gtk_tree_view_get_model (treeview));
- gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (store), iter, path);
- units = (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cell), column)) == 0) ? MM : MIL;
-printf(%d\n,units);
- d = c_strtod(text);
- if (d0) {d=0;}
- PCB-Grid[PCB-CurrentGrid] = (units) ? (d * MM_TO_COOR) : (d * MIL_TO_COOR);
- if (Settings.DrawGrid) UpdateAll ();
- ghid_set_status_line_label();
- gtk_list_store_set (store, iter, COL_GRID_MM, (units) ? (c_dtostr(d)) : (c_dtostr(d*MIL_TO_MM)), -1);
- gtk_list_store_set (store, iter, COL_GRID_MIL, (units) ? (c_dtostr(d*MM_TO_MIL)) : (c_dtostr(d)), -1);
-}
-
-
-void cb_edited_step(GtkCellRendererText *cell, gchar *path, gchar *text, GtkTreeView *treeview) {
- int i;
- GtkListStore *store;
- GtkTreeIter iter;
- store = GTK_LIST_STORE (gtk_tree_view_get_model (treeview));
- gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (store), iter, path);
- i=(int)c_strtod(text);
- if (i0) {i=0;}
-if (i==1) {i=2;}
- if (i100) {i=100;}
- PCB-GridStep[PCB-CurrentGrid] = i;
- if (Settings.DrawGrid) UpdateAll ();
-// ghid_set_status_line_label();
- gtk_list_store_set (store, iter, COL_GRIDSTEP, i, -1);
+void cb_edited_mm_or_mil (GtkCellRendererText *cell,
+ gchar *path,
+ gchar *text,
+ GtkTreeView *treeview)
+{
+ GtkTreeModel *model = gtk_tree_view_get_model (treeview);
+ GtkTreePath *treePath = gtk_tree_path_new_from_string (path);
+ int gridNum = CLAMP (gtk_tree_path_get_indices (treePath)[0],
+ 0,
+ MAX_USER_GRIDS-1);
+ gboolean unitsMm;
+ GtkTreeIter iter;
+ double d;
+
+ unitsMm = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cell), column)) == COL_GRID_MM;
+ d = MAX (0, c_strtod(text));
+ PCB-Grid[gridNum] = (unitsMm) ? (d * MM_TO_COOR) : (d * MIL_TO_COOR);
+
+ if (gridNum == PCB-CurrentGrid) {
+if (Settings.DrawGrid)
+ UpdateAll ();
+ghid_set_status_line_label();
+ }
+
+ gtk_tree_model_get_iter (model, iter, treePath);
+ /* two separate calls because c_dtostr() uses static buffer */
+ gtk_list_store_set (GTK_LIST_STORE (model), iter,
+ COL_GRID_MM, unitsMm ? c_dtostr(d) : c_dtostr(d*MIL_TO_MM),
+ -1);
+ gtk_list_store_set (GTK_LIST_STORE (model), iter,
+ COL_GRID_MIL, unitsMm ? c_dtostr(d*MM_TO_MIL) : c_dtostr(d),
+ -1);
+ gtk_tree_model_row_changed (model, treePath, iter);
+ gtk_tree_path_free (treePath);
+}
+
+
+void cb_edited_step (GtkCellRendererText *cell,
+ gchar *path,
+ gchar *text,
+ GtkTreeView *treeview)
+{
+ GtkTreeModel *model = gtk_tree_view_get_model (treeview);
+ GtkTreePath *treePath = gtk_tree_path_new_from_string (path);
+ int gridNum = CLAMP (gtk_tree_path_get_indices (treePath)[0],
+ 0,
+