[GRASS-SVN] r34292 - grass/branches/develbranch_6/vector/v.digit

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Nov 14 10:43:49 EST 2008


Author: marisn
Date: 2008-11-14 10:43:49 -0500 (Fri, 14 Nov 2008)
New Revision: 34292

Modified:
   grass/branches/develbranch_6/vector/v.digit/attr.c
   grass/branches/develbranch_6/vector/v.digit/line.c
   grass/branches/develbranch_6/vector/v.digit/proto.h
   grass/branches/develbranch_6/vector/v.digit/util.c
   grass/branches/develbranch_6/vector/v.digit/vertex.c
Log:
Use user provided snapping threshold also for vertex selection in editing tools; Add point support to move vertex tool

Modified: grass/branches/develbranch_6/vector/v.digit/attr.c
===================================================================
--- grass/branches/develbranch_6/vector/v.digit/attr.c	2008-11-14 15:42:10 UTC (rev 34291)
+++ grass/branches/develbranch_6/vector/v.digit/attr.c	2008-11-14 15:43:49 UTC (rev 34292)
@@ -190,8 +190,7 @@
     i_prompt("Display categories:");
     i_prompt_buttons("Select line", "", "Quit tool");
 
-    /* TODO: use some better threshold */
-    dc->thresh = fabs(D_d_to_u_col(10) - D_d_to_u_col(0));
+    dc->thresh = get_thresh();
     G_debug(2, "thresh = %f", dc->thresh);
 
     F_clear();
@@ -301,8 +300,7 @@
     i_prompt("Copy attributes:");
     i_prompt_buttons("Select source object", "", "Quit tool");
 
-    /* TODO: use some better threshold */
-    cc->thresh = fabs(D_d_to_u_col(10) - D_d_to_u_col(0));
+    cc->thresh = get_thresh();
     G_debug(2, "thresh = %f", cc->thresh);
 
     cc->src_line = 0;
@@ -463,8 +461,7 @@
     i_prompt("Display attributes:");
     i_prompt_buttons("Select line", "", "Quit tool");
 
-    /* TODO: use some better threshold */
-    da->thresh = fabs(D_d_to_u_col(10) - D_d_to_u_col(0));
+    da->thresh = get_thresh();
     G_debug(2, "thresh = %f", da->thresh);
 
     F_clear();

Modified: grass/branches/develbranch_6/vector/v.digit/line.c
===================================================================
--- grass/branches/develbranch_6/vector/v.digit/line.c	2008-11-14 15:42:10 UTC (rev 34291)
+++ grass/branches/develbranch_6/vector/v.digit/line.c	2008-11-14 15:43:49 UTC (rev 34292)
@@ -102,16 +102,8 @@
 
     G_debug(2, "snap(): x = %f, y = %f", *x, *y);
 
-    if (!var_geti(VAR_SNAP))
-	return 0;
+    thresh = get_thresh();
 
-    if (var_geti(VAR_SNAP_MODE) == SNAP_MAP) {
-	thresh = var_getd(VAR_SNAP_MAP);
-    }
-    else {
-	thresh = Scale * var_geti(VAR_SNAP_SCREEN);
-    }
-
     node = Vect_find_node(&Map, *x, *y, 0, thresh, 0);
 
     if (node > 0)
@@ -285,8 +277,7 @@
     i_prompt("Edit line or boundary:");
     i_prompt_buttons("Select", "", "Quit tool");
 
-    /* TODO: use some better threshold */
-    el->thresh = fabs(D_d_to_u_col(10) - D_d_to_u_col(0));
+    el->thresh = get_thresh();
     G_debug(2, "thresh = %f", el->thresh);
 
     el->phase = 1;
@@ -470,8 +461,7 @@
     i_prompt("Delete point, line, boundary, or centroid:");
     i_prompt_buttons("Select", "Unselect", "Quit tool");
 
-    /* TODO: use some better threshold */
-    dl->thresh = fabs(D_d_to_u_col(10) - D_d_to_u_col(0));
+    dl->thresh = get_thresh();
     G_debug(2, "thresh = %f", dl->thresh);
 
     dl->line = 0;
@@ -610,8 +600,7 @@
     i_prompt("Move point, line, boundary, or centroid:");
     i_prompt_buttons("Select", "", "Quit tool");
 
-    /* TODO: use some better threshold */
-    ml->thresh = fabs(D_d_to_u_col(10) - D_d_to_u_col(0));
+    ml->thresh = get_thresh();
     G_debug(2, "thresh = %f", ml->thresh);
 
     ml->last_line = 0;

Modified: grass/branches/develbranch_6/vector/v.digit/proto.h
===================================================================
--- grass/branches/develbranch_6/vector/v.digit/proto.h	2008-11-14 15:42:10 UTC (rev 34291)
+++ grass/branches/develbranch_6/vector/v.digit/proto.h	2008-11-14 15:43:49 UTC (rev 34292)
@@ -135,6 +135,8 @@
 void cancel_tool(void);
 int c_update_tool(ClientData, Tcl_Interp *, int, char **);
 
+double get_thresh();
+
 /* form */
 int reset_values(ClientData, Tcl_Interp *, int, char **);
 int set_value(ClientData, Tcl_Interp *, int, char **);

Modified: grass/branches/develbranch_6/vector/v.digit/util.c
===================================================================
--- grass/branches/develbranch_6/vector/v.digit/util.c	2008-11-14 15:42:10 UTC (rev 34291)
+++ grass/branches/develbranch_6/vector/v.digit/util.c	2008-11-14 15:43:49 UTC (rev 34292)
@@ -1,8 +1,10 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <math.h>
 #include <grass/gis.h>
 #include <grass/raster.h>
+#include <grass/display.h>
 #include "global.h"
 #include "proto.h"
 
@@ -144,3 +146,17 @@
 
     Tcl_Eval(Toolbox, ".screen.canvas configure -cursor crosshair");
 }
+
+/* Get snapping/selection threshold from GUI */
+double get_thresh() {
+    /* If not found, fall back to old calculation method */
+    if (!var_geti(VAR_SNAP))
+        return fabs(D_d_to_u_col(10) - D_d_to_u_col(0));
+
+    if (var_geti(VAR_SNAP_MODE) == SNAP_MAP) {
+        return fabs(var_getd(VAR_SNAP_MAP));
+    }
+    else {
+        return fabs(Scale * var_geti(VAR_SNAP_SCREEN));
+    }
+}

Modified: grass/branches/develbranch_6/vector/v.digit/vertex.c
===================================================================
--- grass/branches/develbranch_6/vector/v.digit/vertex.c	2008-11-14 15:42:10 UTC (rev 34291)
+++ grass/branches/develbranch_6/vector/v.digit/vertex.c	2008-11-14 15:43:49 UTC (rev 34292)
@@ -34,8 +34,7 @@
     i_prompt("Split line:");
     i_prompt_buttons("Select", "", "Quit tool");
 
-    /* TODO: use some better threshold */
-    sl->thresh = fabs(D_d_to_u_col(10) - D_d_to_u_col(0));
+    sl->thresh = get_thresh();
     G_debug(2, "thresh = %f", sl->thresh);
 
     sl->last_line = 0;
@@ -199,8 +198,7 @@
     i_prompt("Remove vertex:");
     i_prompt_buttons("Select vertex", "", "Quit tool");
 
-    /* TODO: use some better threshold */
-    rv->thresh = fabs(D_d_to_u_col(10) - D_d_to_u_col(0));
+    rv->thresh = get_thresh();
     G_debug(2, "thresh = %f", rv->thresh);
 
     rv->last_line = 0;
@@ -364,8 +362,7 @@
     i_prompt("Add vertex:");
     i_prompt_buttons("Select", "", "Quit tool");
 
-    /* TODO: use some better threshold */
-    av->thresh = fabs(D_d_to_u_col(10) - D_d_to_u_col(0));
+    av->thresh = get_thresh();
     G_debug(2, "thresh = %f", av->thresh);
 
     av->last_line = 0;
@@ -562,8 +559,7 @@
     i_prompt("Move vertex:");
     i_prompt_buttons("Select", "", "Quit tool");
 
-    /* TODO: use some better threshold */
-    mv->thresh = fabs(D_d_to_u_col(10) - D_d_to_u_col(0));
+    mv->thresh = get_thresh();
     G_debug(2, "thresh = %f", mv->thresh);
 
     mv->last_line = 0;
@@ -591,7 +587,7 @@
 
     if (button == 1) {		/* Select / new location */
 	if (mv->last_line == 0) {	/* Select line */
-	    int line = Vect_find_line(&Map, x, y, 0, GV_LINE | GV_BOUNDARY,
+	    int line = Vect_find_line(&Map, x, y, 0, GV_POINT | GV_LINE | GV_BOUNDARY,
 				      mv->thresh, 0, 0);
 
 	    G_debug(2, "line found = %d", line);



More information about the grass-commit mailing list