[GRASS-SVN] r29746 - in grass/trunk/gui/wxpython: gui_modules vdigit

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jan 18 09:56:05 EST 2008


Author: martinl
Date: 2008-01-18 09:56:05 -0500 (Fri, 18 Jan 2008)
New Revision: 29746

Modified:
   grass/trunk/gui/wxpython/gui_modules/digit.py
   grass/trunk/gui/wxpython/vdigit/line.cpp
Log:
wxGUI/vdigit: fix snapping (also for background map)

Modified: grass/trunk/gui/wxpython/gui_modules/digit.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/digit.py	2008-01-18 14:45:44 UTC (rev 29745)
+++ grass/trunk/gui/wxpython/gui_modules/digit.py	2008-01-18 14:56:05 UTC (rev 29746)
@@ -730,13 +730,13 @@
 
         if z:
             ret = self.digit.AddLine(type, [x, y, z], layer, cat,
-                                     self.settings["backgroundMap"], snap, thresh)
+                                     str(self.settings["backgroundMap"]), snap, thresh)
         else:
             ret = self.digit.AddLine(type, [x, y], layer, cat,
-                                     self.settings["backgroundMap"], snap, thresh)
+                                     str(self.settings["backgroundMap"]), snap, thresh)
 
         if ret == -1:
-            raise DigitError, _("Adding new feature to vector map <%s> failed") % map
+            raise DigitError, _("Adding new feature to vector map <%s> failed.") % map
         
     def AddLine (self, map, line, coords):
         """Add line/boundary
@@ -764,10 +764,10 @@
         snap, thresh = self.__getSnapThreshold()
 
         ret = self.digit.AddLine(type, listCoords, layer, cat,
-                                 self.settings["backgroundMap"], snap, thresh)
+                                 str(self.settings["backgroundMap"]), snap, thresh)
 
         if ret == -1:
-            raise DigitError, _("Adding new feature to vector map <%s> failed") % map
+            raise DigitError, _("Adding new feature to vector map <%s> failed.") % map
 
 
     def DeleteSelectedLines(self):

Modified: grass/trunk/gui/wxpython/vdigit/line.cpp
===================================================================
--- grass/trunk/gui/wxpython/vdigit/line.cpp	2008-01-18 14:45:44 UTC (rev 29745)
+++ grass/trunk/gui/wxpython/vdigit/line.cpp	2008-01-18 14:56:05 UTC (rev 29746)
@@ -31,7 +31,7 @@
    \param snap   snapping mode (see vedit.h)
    \param thresh threshold value for snapping
 
-   \return 1 on success
+   \return 0 on success
    \return -1 on failure
 */
 int Digit::AddLine(int type, std::vector<double> coords, int layer, int cat,
@@ -68,18 +68,28 @@
     }
 
     BgMap = NULL;
+    nbgmaps = 0;
 
-    if (bgmap) {
-	const char *mapset;
-	mapset = G_find_vector2 (bgmap, ""); 
-	if (mapset) {
-	    if (strcmp(G_fully_qualified_name((const char*) display->mapInfo->name, (const char*) G_mapset()),
-		       G_fully_qualified_name((const char*) bgmap, (const char*) mapset))) {
-		nbgmaps = 1;
-		BgMap = (struct Map_info**) G_realloc ((void *) BgMap, nbgmaps * sizeof(struct Map_info*));
-		BgMap[nbgmaps-1] = (struct Map_info *) G_malloc (sizeof(struct Map_info));
-		
-		Vect_open_old(BgMap[nbgmaps-1], (char *) bgmap, (char*) mapset);
+    if (bgmap && strlen(bgmap) > 0) {
+	char name[GNAME_MAX];
+	char mapset[GMAPSET_MAX];
+	if (G_find_vector2 (bgmap, "") == NULL) {
+	    return -1;
+	}
+
+	G__name_is_fully_qualified(bgmap, name, mapset);
+	if (strcmp(G_fully_qualified_name((const char*) display->mapInfo->name, (const char*) G_mapset()),
+		   G_fully_qualified_name((const char*) bgmap, (const char*) mapset))) {
+	    nbgmaps = 1;
+	    BgMap = (struct Map_info**) G_malloc (nbgmaps * sizeof(struct Map_info*));
+	    BgMap[nbgmaps-1] = (struct Map_info *) G_malloc (sizeof(struct Map_info));
+	    
+	    // avoid GUI crash
+	    Vect_set_fatal_error(GV_FATAL_PRINT);
+
+	    if (Vect_open_old(BgMap[nbgmaps-1], name, mapset) == -1) {
+		G_free ((void *) BgMap[nbgmaps-1]);
+		return -1;
 	    }
 	}
     }
@@ -117,16 +127,16 @@
 	}
     }
 
-    newline = Vect_write_line(display->mapInfo, type, Points, Cats);
-
-    if (snap != NO_SNAP) { /* apply snapping */
-      /*
+    if (snap != NO_SNAP) { /* apply snapping (node or vertex) */
 	Vedit_snap_line(display->mapInfo, BgMap, nbgmaps,
-			newline,
+			-1, Points,
 			threshold, (SNAP) ? 0 : 1); 
-      */
     }
 
+    if (Vect_write_line(display->mapInfo, type, Points, Cats) < 0) {
+	return -1;
+    }
+
     Vect_destroy_line_struct(Points);
     Vect_destroy_cats_struct(Cats);
 
@@ -136,7 +146,7 @@
 
     G_debug(2, "wxDigit.AddLine(): line=%d written", newline);
 
-    return 1;
+    return 0;
 }
 
 /**



More information about the grass-commit mailing list