[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: gEDA-user: Please test new grids for GTK PCB
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.kosciuszkiewicz@xxxxxxxxx>
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 (d<0) {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 (i<0) {i=0;}
- if (i==1) {i=2;}
- if (i>100) {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,
+ MAX_USER_GRIDS-1);
+ GtkTreeIter iter;
+ int i = CLAMP (atoi (text), 0, 100);
+
+ if (i==1) i=2;
+ PCB->GridStep[gridNum] = i;
+ if (gridNum == PCB->CurrentGrid)
+ {
+ if (Settings.DrawGrid)
+ UpdateAll ();
+ // ghid_set_status_line_label();
+ }
+
+ gtk_tree_model_get_iter (model, &iter, treePath);
+ gtk_list_store_set (GTK_LIST_STORE (model), &iter, COL_GRIDSTEP, i, -1);
+ gtk_tree_model_row_changed (model, treePath, &iter);
+ gtk_tree_path_free (treePath);
}
void dummy (void) {
- printf("dummy\n");
+ printf("dummy\n");
}
@@ -1437,27 +1466,26 @@ static GtkWidget *create_grid_treeview (void) {
GtkTreeIter iter;
GtkTreeSelection *select;
int i;
- char /*yyyyy[256],*/yyyyy2[256]; /* FIXME remove this ugly stuff */
store = gtk_list_store_new (NUM_COLS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_BOOLEAN);
for (i=0; i<MAX_USER_GRIDS; i++) {
-// strcpy(yyyyy, c_dtostr((PCB->Grid[i])*COOR_TO_MM));
- strcpy(yyyyy2, c_dtostr((PCB->Grid[i]*COOR_TO_MIL)));
gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter,
- COL_GRID_MM, c_dtostr((PCB->Grid[i])*COOR_TO_MM),
-// COL_GRID_MIL, c_dtostr((PCB->Grid[i])*COOR_TO_MIL), - not work! :(
- COL_GRID_MIL, yyyyy2, // work but ugly...
- COL_GRIDSTEP, PCB->GridStep[i],
- COL_GRIDCURRENT, (i == PCB->CurrentGrid) ? TRUE : FALSE,
- -1);
+ // two calls because c_dtostr() uses static buffer for result
+ gtk_list_store_set (store, &iter,
+ COL_GRID_MM, c_dtostr((PCB->Grid[i])*COOR_TO_MM),
+ COL_GRIDSTEP, PCB->GridStep[i],
+ COL_GRIDCURRENT, (i == PCB->CurrentGrid) ? TRUE : FALSE,
+ -1);
+ gtk_list_store_set (store, &iter,
+ COL_GRID_MIL, c_dtostr((PCB->Grid[i])*COOR_TO_MIL),
+ -1);
}
treeview = GTK_TREE_VIEW (gtk_tree_view_new_with_model (GTK_TREE_MODEL(store)));
g_object_unref (store);
renderer = gtk_cell_renderer_toggle_new ();
- gtk_cell_renderer_toggle_set_radio(renderer, true);
- gtk_cell_renderer_toggle_set_activatable(renderer, true);
+ gtk_cell_renderer_toggle_set_radio (GTK_CELL_RENDERER_TOGGLE (renderer), true);
+ gtk_cell_renderer_toggle_set_activatable (GTK_CELL_RENDERER_TOGGLE (renderer), true);
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview), -1, "Current?", renderer, "active", COL_GRIDCURRENT, NULL);
g_signal_connect(renderer, "toggled", (GCallback) cb_toggled_active, treeview);
--
1.7.1
_______________________________________________
geda-user mailing list
geda-user@xxxxxxxxxxxxxx
http://www.seul.org/cgi-bin/mailman/listinfo/geda-user